packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/smarty/plugins/modifier.date_format.php
changeset 0 3906ca745819
equal deleted inserted replaced
-1:000000000000 0:3906ca745819
       
     1 <?php
       
     2 /**
       
     3  * Smarty plugin
       
     4  * 
       
     5  * @package Smarty
       
     6  * @subpackage PluginsModifier
       
     7  */
       
     8 
       
     9 /**
       
    10  * Smarty date_format modifier plugin
       
    11  * 
       
    12  * Type:     modifier<br>
       
    13  * Name:     date_format<br>
       
    14  * Purpose:  format datestamps via strftime<br>
       
    15  * Input:<br>
       
    16  *          - string: input date string
       
    17  *          - format: strftime format for output
       
    18  *          - default_date: default date if $string is empty
       
    19  * 
       
    20  * @link http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
       
    21  * @author Monte Ohrt <monte at ohrt dot com> 
       
    22  * @param string $string       input date string
       
    23  * @param string $format       strftime format for output
       
    24  * @param string $default_date default date if $string is empty
       
    25  * @param string $formatter    either 'strftime' or 'auto'
       
    26  * @return string |void
       
    27  * @uses smarty_make_timestamp()
       
    28  */
       
    29 function smarty_modifier_date_format($string, $format=null, $default_date='', $formatter='auto')
       
    30 {
       
    31     if ($format === null) {
       
    32         $format = Smarty::$_DATE_FORMAT;
       
    33     }
       
    34     /**
       
    35     * Include the {@link shared.make_timestamp.php} plugin
       
    36     */
       
    37     require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
       
    38     if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
       
    39         $timestamp = smarty_make_timestamp($string);
       
    40     } elseif ($default_date != '') {
       
    41         $timestamp = smarty_make_timestamp($default_date);
       
    42     } else {
       
    43         return;
       
    44     } 
       
    45     if($formatter=='strftime'||($formatter=='auto'&&strpos($format,'%')!==false)) {
       
    46         if (DS == '\\') {
       
    47             $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
       
    48             $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
       
    49             if (strpos($format, '%e') !== false) {
       
    50                 $_win_from[] = '%e';
       
    51                 $_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
       
    52             } 
       
    53             if (strpos($format, '%l') !== false) {
       
    54                 $_win_from[] = '%l';
       
    55                 $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
       
    56             } 
       
    57             $format = str_replace($_win_from, $_win_to, $format);
       
    58         } 
       
    59         return strftime($format, $timestamp);
       
    60     } else {
       
    61         return date($format, $timestamp);
       
    62     }
       
    63 } 
       
    64 
       
    65 ?>