| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty shared plugin | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |  * @package Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsShared | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Function: smarty_make_timestamp<br> | 
					
						
							|  |  |  |  * Purpose:  used by other smarty functions to make a timestamp | 
					
						
							|  |  |  |  *           from a string. | 
					
						
							|  |  |  |  * @author   Monte Ohrt <monte at ohrt dot com> | 
					
						
							|  |  |  |  * @param string $string | 
					
						
							|  |  |  |  * @return string | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | function smarty_make_timestamp($string) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if(empty($string)) { | 
					
						
							|  |  |  |         // use "now":
 | 
					
						
							| 
									
										
										
										
											2010-07-13 22:57:47 +00:00
										 |  |  |         return time(); | 
					
						
							| 
									
										
										
										
											2010-07-14 22:47:37 +00:00
										 |  |  |     } elseif ($string instanceof DateTime) { | 
					
						
							| 
									
										
										
										
											2010-07-13 22:57:47 +00:00
										 |  |  |         return $string->getTimestamp(); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } elseif (preg_match('/^\d{14}$/', $string)) { | 
					
						
							|  |  |  |         // it is mysql timestamp format of YYYYMMDDHHMMSS?            
 | 
					
						
							| 
									
										
										
										
											2010-07-13 22:57:47 +00:00
										 |  |  |         return mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                        substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4)); | 
					
						
							|  |  |  |     } elseif (is_numeric($string)) { | 
					
						
							|  |  |  |         // it is a numeric string, we handle it as timestamp
 | 
					
						
							| 
									
										
										
										
											2010-07-13 22:57:47 +00:00
										 |  |  |         return (int)$string; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         // strtotime should handle it
 | 
					
						
							|  |  |  |         $time = strtotime($string); | 
					
						
							|  |  |  |         if ($time == -1 || $time === false) { | 
					
						
							|  |  |  |             // strtotime() was not able to parse $string, use "now":
 | 
					
						
							| 
									
										
										
										
											2010-07-13 22:57:47 +00:00
										 |  |  |             return time(); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-07-13 22:57:47 +00:00
										 |  |  |         return $time; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 22:47:37 +00:00
										 |  |  | ?>
 |