Редакция 2 | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 235 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * Smarty plugin
|
3 | * Smarty plugin
|
4 | * @package Smarty
|
4 | * @package Smarty
|
5 | * @subpackage plugins
|
5 | * @subpackage plugins
|
6 | */
|
6 | */
|
7 | 7 | ||
8 | /**
|
8 | /**
|
9 | * Include the {@link shared.make_timestamp.php} plugin
|
9 | * Include the {@link shared.make_timestamp.php} plugin
|
10 | */
|
10 | */
|
11 | require_once $smarty->_get_plugin_filepath('shared', 'make_timestamp'); |
11 | require_once $smarty->_get_plugin_filepath('shared', 'make_timestamp'); |
12 | /**
|
12 | /**
|
13 | * Smarty date_format modifier plugin
|
13 | * Smarty date_format modifier plugin
|
14 | *
|
14 | *
|
15 | * Type: modifier<br>
|
15 | * Type: modifier<br>
|
16 | * Name: date_format<br>
|
16 | * Name: date_format<br>
|
17 | * Purpose: format datestamps via strftime<br>
|
17 | * Purpose: format datestamps via strftime<br>
|
18 | * Input:<br>
|
18 | * Input:<br>
|
19 | * - string: input date string
|
19 | * - string: input date string
|
20 | * - format: strftime format for output
|
20 | * - format: strftime format for output
|
21 | * - default_date: default date if $string is empty
|
21 | * - default_date: default date if $string is empty
|
22 | * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
|
22 | * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
|
23 | * date_format (Smarty online manual)
|
23 | * date_format (Smarty online manual)
|
24 | * @author Monte Ohrt <monte at ohrt dot com>
|
24 | * @author Monte Ohrt <monte at ohrt dot com>
|
25 | * @param string
|
25 | * @param string
|
26 | * @param string
|
26 | * @param string
|
27 | * @param string
|
27 | * @param string
|
28 | * @return string|void
|
28 | * @return string|void
|
29 | * @uses smarty_make_timestamp()
|
29 | * @uses smarty_make_timestamp()
|
30 | */
|
30 | */
|
31 | function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '') |
31 | function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '') |
32 | {
|
32 | {
|
33 | if ($string != '') { |
33 | if ($string != '') { |
34 | $timestamp = smarty_make_timestamp($string); |
34 | $timestamp = smarty_make_timestamp($string); |
35 | } elseif ($default_date != '') { |
35 | } elseif ($default_date != '') { |
36 | $timestamp = smarty_make_timestamp($default_date); |
36 | $timestamp = smarty_make_timestamp($default_date); |
37 | } else { |
37 | } else { |
38 | return; |
38 | return; |
39 | }
|
39 | }
|
40 | if (DIRECTORY_SEPARATOR == '\\') { |
40 | if (DIRECTORY_SEPARATOR == '\\') { |
41 | $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); |
41 | $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); |
42 | $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); |
42 | $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); |
43 | if (strpos($format, '%e') !== false) { |
43 | if (strpos($format, '%e') !== false) { |
44 | $_win_from[] = '%e'; |
44 | $_win_from[] = '%e'; |
45 | $_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); |
45 | $_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); |
46 | }
|
46 | }
|
47 | if (strpos($format, '%l') !== false) { |
47 | if (strpos($format, '%l') !== false) { |
48 | $_win_from[] = '%l'; |
48 | $_win_from[] = '%l'; |
49 | $_win_to[] = sprintf('%\' 2d', date('h', $timestamp)); |
49 | $_win_to[] = sprintf('%\' 2d', date('h', $timestamp)); |
50 | }
|
50 | }
|
51 | $format = str_replace($_win_from, $_win_to, $format); |
51 | $format = str_replace($_win_from, $_win_to, $format); |
52 | }
|
52 | }
|
53 | return strftime($format, $timestamp); |
53 | return strftime($format, $timestamp); |
54 | }
|
54 | }
|
55 | 55 | ||
56 | /* vim: set expandtab: */
|
56 | /* vim: set expandtab: */
|
57 | 57 | ||
58 | ?>
|
58 | ?>
|
59 | 59 |