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