init
[garradin.git] / include / libs / template_lite / plugins / modifier.date_format.php
1 <?php
2
3 /*
4 * Template Lite plugin converted from Smarty
5 * -------------------------------------------------------------
6 * Type: modifier
7 * Name: date_format
8 * Purpose: format datestamps via strftime
9 * Input: string: input date string
10 * format: strftime format for output
11 * default_date: default date if $string is empty
12 * -------------------------------------------------------------
13 */
14
15 function tpl_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
16 {
17 if($string != '')
18 {
19 return strftime($format, tpl_make_timestamp($string));
20 }
21 elseif (isset($default_date) && $default_date != '')
22 {
23 return strftime($format, tpl_make_timestamp($default_date));
24 }
25 else
26 {
27 return;
28 }
29 }
30
31 if(!function_exists('tpl_make_timestamp'))
32 {
33 function tpl_make_timestamp($string)
34 {
35 if(empty($string))
36 {
37 $string = "now";
38 }
39 $time = strtotime($string);
40 if (is_numeric($time) && $time != -1)
41 {
42 return $time;
43 }
44
45 // is mysql timestamp format of YYYYMMDDHHMMSS?
46 if (is_numeric($string) && strlen($string) == 14)
47 {
48 $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),substr($string,4,2),substr($string,6,2),substr($string,0,4));
49 return $time;
50 }
51
52 // couldn't recognize it, try to return a time
53 $time = (int) $string;
54 if ($time > 0)
55 {
56 return $time;
57 }
58 else
59 {
60 return time();
61 }
62 }
63 }
64 ?>