summaryrefslogtreecommitdiff
path: root/plugins/data.clock.php
blob: 9f2e55a8825ce7ba97ec2fed25a4da2dd97df48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
// $id: data.example.php,v 1.4.2.9 2005/07/14 09:03:36 starrider Exp $
/**
 * assigned_modules
 *
 * @author     xing
 * @version    $Revision: 1.5 $
 * @package    liberty
 * @subpackage plugins_data
 * @copyright  Copyright (c) 2004, bitweaver.org
 */

/**
 * Setup Code
 */
define( 'PLUGIN_GUID_DATACLOCK', 'dataclock' );
global $gLibertySystem;
$pluginParams = array ( 
	'tag' => 'CLOCK',
	'auto_activate' => FALSE,
	'requires_pair' => FALSE,
	'load_function' => 'data_clock',
	'title' => 'Clock',
	'help_page' => 'DataPluginClock',
	'description' => "This plugin allows you to insert flexible date/time strings into your pages.",
	'help_function' => 'data_clock_help',
	'syntax' => "{clock format='%c'}",
	'plugin_type' => DATA_PLUGIN
);
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATACLOCK, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATACLOCK );

function data_clock_help() {
	$help =
		'<table class="data help">'
			.'<tr>'
				.'<th>' . tra( "Key" ) . '</th>'
				.'<th>' . tra( "Type" ) . '</th>'
				.'<th>' . tra( "Comments" ) . '</th>'
			.'</tr>'
			.'<tr class="odd">'
				.'<td>' . tra( "format" ) . '</td>'
				.'<td>' . tra( "string") . '<br />' . tra( "(optional)" ) . '</td>'
				.'<td>' . tra( "strftime-style format for clock display (default:  '%c')") . '</td>'
			.'</tr>'
			.'<tr class="even">'
				.'<td>' . tra( "timestamp" ) . '</td>'
				.'<td>' . tra( "string") . '<br />' . tra( "(optional)" ) . '</td>'
				.'<td>' . tra( "Any date/time expression PHP can recognize (default:  current time)") . '</td>'
			.'</tr>'
			.'<tr class="odd">'
				.'<td>' . tra( "timezone" ) . '</td>'
				.'<td>' . tra( "string") . '<br />' . tra( "(optional)" ) . '</td>'
				.'<td>' . tra( "POSIX timezone name or GMT offset (default:  current timezone)") . '</td>'
			.'</tr>'
 		.'</table>'
		. tra( "Example: " ) . "{CLOCK format='%a, %d %b %Y, %H:%M:%S %Z' timestamp='2005-07-01 03:00:30'}";
	return $help;
}

function data_clock( $data, $params ) {
	global $gBitSystem;
	$save_tz = getenv('TZ');

	if ($params['format']) {
		$format = $params['format'];
	} else {
		$format = '%c';
	}
	if ($params['timestamp']) {
		$ts = strtotime($params['timestamp']);
	} else {
		$ts = time();
	}
	if ($params['timezone']) {
		$_ENV['TZ'] = $params['timezone'];
		putenv("TZ=$_ENV[TZ]");
    }

	$result = strftime($format, $ts);
	$_ENV['TZ'] = $save_tz;
	putenv("TZ=$save_tz");

	return "<span class=\"clock\">$result</span>";
}
?>