| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty plugin | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * @subpackage PluginsModifier | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty date_format modifier plugin | 
					
						
							|  |  |  |  * Type:     modifier<br> | 
					
						
							|  |  |  |  * Name:     date_format<br> | 
					
						
							|  |  |  |  * Purpose:  format datestamps via strftime<br> | 
					
						
							|  |  |  |  * Input:<br> | 
					
						
							|  |  |  |  *          - string: input date string | 
					
						
							|  |  |  |  *          - format: strftime format for output | 
					
						
							|  |  |  |  *          - default_date: default date if $string is empty | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @link   http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual) | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * @author Monte Ohrt <monte at ohrt dot com> | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @param string $string       input date string | 
					
						
							|  |  |  |  * @param string $format       strftime format for output | 
					
						
							|  |  |  |  * @param string $default_date default date if $string is empty | 
					
						
							|  |  |  |  * @param string $formatter    either 'strftime' or 'auto' | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * @return string |void | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @uses   smarty_make_timestamp() | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  | function smarty_modifier_date_format($string, $format = null, $default_date = '', $formatter = 'auto') | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-18 18:20:09 +00:00
										 |  |  |     if ($format === null) { | 
					
						
							|  |  |  |         $format = Smarty::$_DATE_FORMAT; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-01-07 16:45:33 +01:00
										 |  |  |      * require_once the {@link shared.make_timestamp.php} plugin | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |     require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); | 
					
						
							| 
									
										
										
										
											2012-06-07 13:01:58 +00:00
										 |  |  |     if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $timestamp = smarty_make_timestamp($string); | 
					
						
							|  |  |  |     } elseif ($default_date != '') { | 
					
						
							|  |  |  |         $timestamp = smarty_make_timestamp($default_date); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) { | 
					
						
							| 
									
										
										
										
											2009-12-05 05:30:20 +00:00
										 |  |  |         if (DS == '\\') { | 
					
						
							|  |  |  |             $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); | 
					
						
							|  |  |  |             $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); | 
					
						
							|  |  |  |             if (strpos($format, '%e') !== false) { | 
					
						
							|  |  |  |                 $_win_from[] = '%e'; | 
					
						
							|  |  |  |                 $_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-12-05 05:30:20 +00:00
										 |  |  |             if (strpos($format, '%l') !== false) { | 
					
						
							|  |  |  |                 $_win_from[] = '%l'; | 
					
						
							|  |  |  |                 $_win_to[] = sprintf('%\' 2d', date('h', $timestamp)); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-12-05 05:30:20 +00:00
										 |  |  |             $format = str_replace($_win_from, $_win_to, $format); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-05 05:30:20 +00:00
										 |  |  |         return strftime($format, $timestamp); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return date($format, $timestamp); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | } |