Редакция 2 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 3 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * Smarty shared plugin
|
3 | * Smarty shared plugin
|
4 | * @package Smarty
|
4 | * @package Smarty
|
5 | * @subpackage plugins
|
5 | * @subpackage plugins
|
6 | */
|
6 | */
|
7 | 7 | ||
8 | 8 | ||
9 | /**
|
9 | /**
|
10 | * Function: smarty_make_timestamp<br>
|
10 | * Function: smarty_make_timestamp<br>
|
11 | * Purpose: used by other smarty functions to make a timestamp
|
11 | * Purpose: used by other smarty functions to make a timestamp
|
12 | * from a string.
|
12 | * from a string.
|
13 | * @author Monte Ohrt <monte at ohrt dot com>
|
13 | * @author Monte Ohrt <monte at ohrt dot com>
|
14 | * @param string
|
14 | * @param string
|
15 | * @return string
|
15 | * @return string
|
16 | */
|
16 | */
|
17 | function smarty_make_timestamp($string) |
17 | function smarty_make_timestamp($string) |
18 | {
|
18 | {
|
19 | if(empty($string)) { |
19 | if(empty($string)) { |
20 | // use "now":
|
20 | // use "now":
|
21 | $time = time(); |
21 | $time = time(); |
22 | 22 | ||
23 | } elseif (preg_match('/^\d{14}$/', $string)) { |
23 | } elseif (preg_match('/^\d{14}$/', $string)) { |
24 | // it is mysql timestamp format of YYYYMMDDHHMMSS?
|
24 | // it is mysql timestamp format of YYYYMMDDHHMMSS?
|
25 | $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), |
25 | $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), |
26 | substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4)); |
26 | substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4)); |
27 | 27 | ||
28 | } elseif (is_numeric($string)) { |
28 | } elseif (is_numeric($string)) { |
29 | // it is a numeric string, we handle it as timestamp
|
29 | // it is a numeric string, we handle it as timestamp
|
30 | $time = (int)$string; |
30 | $time = (int)$string; |
31 | 31 | ||
32 | } else { |
32 | } else { |
33 | // strtotime should handle it
|
33 | // strtotime should handle it
|
34 | $time = strtotime($string); |
34 | $time = strtotime($string); |
35 | if ($time == -1 || $time === false) { |
35 | if ($time == -1 || $time === false) { |
36 | // strtotime() was not able to parse $string, use "now":
|
36 | // strtotime() was not able to parse $string, use "now":
|
37 | $time = time(); |
37 | $time = time(); |
38 | }
|
38 | }
|
39 | }
|
39 | }
|
40 | return $time; |
40 | return $time; |
41 | 41 | ||
42 | }
|
42 | }
|
43 | 43 | ||
44 | /* vim: set expandtab: */
|
44 | /* vim: set expandtab: */
|
45 | 45 | ||
46 | ?>
|
46 | ?>
|
47 | 47 |