1 : <?php
2 : /**
3 : * Smarty plugin
4 : *
5 : * @package Smarty
6 : * @subpackage PluginsModifier
7 : */
8 :
9 : /**
10 : * Smarty date_format modifier plugin
11 : *
12 : * Type: modifier<br>
13 : * Name: date_format<br>
14 : * Purpose: format datestamps via strftime<br>
15 : * Input:<br>
16 : * - string: input date string
17 : * - format: strftime format for output
18 : * - default_date: default date if $string is empty
19 : *
20 : * @link http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
21 : * @author Monte Ohrt <monte at ohrt dot com>
22 : * @param string $string input date string
23 : * @param string $format strftime format for output
24 : * @param string $default_date default date if $string is empty
25 : * @param string $formatter either 'strftime' or 'auto'
26 : * @return string |void
27 : * @uses smarty_make_timestamp()
28 : */
29 0 : function smarty_modifier_date_format($string, $format = SMARTY_RESOURCE_DATE_FORMAT, $default_date = '',$formatter='auto')
30 : {
31 : /**
32 : * Include the {@link shared.make_timestamp.php} plugin
33 : */
34 0 : require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
35 0 : if ($string != '') {
36 0 : $timestamp = smarty_make_timestamp($string);
37 0 : } elseif ($default_date != '') {
38 0 : $timestamp = smarty_make_timestamp($default_date);
39 0 : } else {
40 0 : return;
41 : }
42 0 : if($formatter=='strftime'||($formatter=='auto'&&strpos($format,'%')!==false)) {
43 0 : if (DS == '\\') {
44 0 : $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
45 0 : $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
46 0 : if (strpos($format, '%e') !== false) {
47 0 : $_win_from[] = '%e';
48 0 : $_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
49 0 : }
50 0 : if (strpos($format, '%l') !== false) {
51 0 : $_win_from[] = '%l';
52 0 : $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
53 0 : }
54 0 : $format = str_replace($_win_from, $_win_to, $format);
55 0 : }
56 0 : return strftime($format, $timestamp);
57 : } else {
58 0 : return date($format, $timestamp);
59 : }
60 : }
61 :
|