/**
 * 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
 *
 * @param string $string       input
 * @param string $format       type of the format
 * @param string $default_date default date value
 *
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
 * @uses   smarty_make_timestamp()
 *
 * @return string|void
 */
function smarty_modifier_date_format($string, $format = SMARTY_RESOURCE_DATE_FORMAT, $default_date = '', $formatter = 'auto')
{
    /**
     * Include the {@link shared.make_timestamp.php} plugin
     */
    require_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return '';
    }
    if ($formatter == 'strftime' || $formatter == 'auto' && strpos($format, '%') !== false) {
        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));
            }
            if (strpos($format, '%l') !== false) {
                $_win_from[] = '%l';
                $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
            }
            $format = str_replace($_win_from, $_win_to, $format);
        }
        return strftime($format, $timestamp);
    } else {
        return date($format, $timestamp);
    }
}
/**
 * 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
 * @link   http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
 * @author Monte Ohrt <monte at ohrt dot com>
 * @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'
 * @return string |void
 * @uses   smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = NULL, $default_date = '', $formatter = 'auto')
{
    if ($format === NULL) {
        $format = Smarty::$_DATE_FORMAT;
    }
    /**
     * require_once the {@link shared.make_timestamp.php} plugin
     */
    require_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if ($formatter == 'strftime' || $formatter == 'auto' && strpos($format, '%') !== FALSE) {
        if (DS == '\\') {
            $_win_from = ['%D', '%h', '%n', '%r', '%R', '%t', '%T'];
            $_win_to = ['%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));
            }
            if (strpos($format, '%l') !== FALSE) {
                $_win_from[] = '%l';
                $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
            }
            $format = str_replace($_win_from, $_win_to, $format);
        }
        return strftime($format, $timestamp);
    } else {
        return date($format, $timestamp);
    }
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = NULL, $default_date = '')
{
    if (!$format) {
        $format = config('date_format');
        return date($format, strtotime($string));
    }
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if (DIRECTORY_SEPARATOR == '\\') {
        $_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));
        }
        if (strpos($format, '%l') !== false) {
            $_win_from[] = '%l';
            $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
        }
        $format = str_replace($_win_from, $_win_to, $format);
    }
    return strftime($format, $timestamp);
}
function smarty_modifier_zengo_date_long($string, $formatter = 'auto')
{
    $format = '%d %b, %Y %H:%M';
    /**
     * Include the {@link shared.make_timestamp.php} plugin
     */
    require_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
        $timestamp = smarty_make_timestamp($string);
    } else {
        return;
    }
    if ($formatter == 'strftime' || $formatter == 'auto' && strpos($format, '%') !== false) {
        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));
            }
            if (strpos($format, '%l') !== false) {
                $_win_from[] = '%l';
                $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
            }
            $format = str_replace($_win_from, $_win_to, $format);
        }
        return strftime($format, $timestamp);
    } else {
        return date($format, $timestamp);
    }
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format_daily($string, $format = '%b %e, %Y', $default_date = '')
{
    global $THEME_CURRENT_DAY;
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if (DIRECTORY_SEPARATOR == '\\') {
        $_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));
        }
        if (strpos($format, '%l') !== false) {
            $_win_from[] = '%l';
            $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
        }
        $format = str_replace($_win_from, $_win_to, $format);
    }
    $current_day = strftime($format, $timestamp);
    if (!isset($THEME_CURRENT_DAY) || $THEME_CURRENT_DAY != $current_day) {
        $THEME_CURRENT_DAY = $current_day;
        return $current_day;
    }
    return '';
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')
{
    if (substr(PHP_OS, 0, 3) == 'WIN') {
        $_win_from = array('%e', '%T', '%D');
        $_win_to = array('%#d', '%H:%M:%S', '%m/%d/%y');
        $format = str_replace($_win_from, $_win_to, $format);
    }
    $arrTemp = array('年', '月', '日', '时', '分', '秒', '時');
    foreach ($arrTemp as $v) {
        if (strpos($format, $v)) {
            $strFormat = str_replace('%', '', $format);
        }
    }
    if ($string != '') {
        if (!empty($strFormat)) {
            return date($strFormat, smarty_make_timestamp($string));
        } else {
            return strftime($format, smarty_make_timestamp($string));
        }
    } elseif (isset($default_date) && $default_date != '') {
        if (!empty($strFormat)) {
            return date($strFormat, smarty_make_timestamp($default_date));
        } else {
            return strftime($format, smarty_make_timestamp($default_date));
        }
    } else {
        return;
    }
}
Beispiel #7
0
/**
 * Use words instead of dates where it makes sense (today, tomorrow, yesterday).
 *
 * @package FeM\sPof\template\smartyPlugins
 * @author dangerground
 * @since 1.0
 *
 * @api
 *
 * @param string $string
 * @param string $default_date (optional)
 * @param bool $time (optional)
 *
 * @return string
 */
function smarty_modifier_prettydate($string, $default_date = '', $time = true)
{
    require_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return '';
    }
    // prepare time
    $pdate = date('Ymd', $timestamp);
    if ($pdate == date('Ymd')) {
        // Today
        return '<strong>' . _s('Heute') . '</strong>' . ($time ? ', ' . date('H:i', $timestamp) : '');
    } elseif ($pdate == date('Ymd', strtotime('+1 day'))) {
        // Tomorrow
        return _s('Morgen') . ($time ? ', ' . date('H:i', $timestamp) : '');
    } elseif ($pdate == date('Ymd', strtotime('-1 day'))) {
        // Yesterday
        return _s('Gestern') . ($time ? ', ' . date('H:i', $timestamp) : '');
    } else {
        // any other day
        return date('d.m.Y' . ($time ? ' H:i' : ''), $timestamp);
    }
}
/**
 * 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
 *
 * @link   http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
 * @author Monte Ohrt <monte at ohrt dot com>
 * @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'
 * @return string |void
 * @uses   smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = null, $default_date = '', $formatter = 'auto')
{
    if ($format === null) {
        $format = \Box\Brainy\Brainy::$_DATE_FORMAT;
    }
    /**
     * Include the {@link shared.make_timestamp.php} plugin
     */
    include_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if ($formatter == 'strftime' || $formatter == 'auto' && strpos($format, '%') !== false) {
        if (DIRECTORY_SEPARATOR == '\\') {
            $_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));
            }
            if (strpos($format, '%l') !== false) {
                $_win_from[] = '%l';
                $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
            }
            $format = str_replace($_win_from, $_win_to, $format);
        }
        return strftime($format, $timestamp);
    } else {
        return date($format, $timestamp);
    }
}
/**
 * Smarty date_time_format modifier plugin
 *
 * Type:     modifier<br>
 * Name:     date_time_format<br>
 * Purpose:  format datestamps via strftime<br>
 * Input:<br>
 *         - string: input date string
 *         - format: strftime format for output
 *         - mode: XXX
 *         - default_date: default date if $string is empty
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_time_format($string, $format = '%b %e, %Y', $mode = 'all', $default_date = '')
{
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if (DIRECTORY_SEPARATOR == '\\') {
        $_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));
        }
        if (strpos($format, '%l') !== false) {
            $_win_from[] = '%l';
            $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
        }
        $format = str_replace($_win_from, $_win_to, $format);
    }
    // 仅显示日期
    if ($mode == 'date') {
        $format = array_shift(explode(' ', $format, 2));
        // 仅显示时间
    } elseif ($mode == 'time') {
        $format = array_pop(explode(' ', $format, 2));
    }
    return strftime($format, $timestamp);
}
function smarty_modifier_timestamp($string)
{
    require_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    }
    return $timestamp;
}
/**
 * Smarty phpdate_format modifier plugin
 *
 * Type:     modifier<br>
 * Name:     date_format<br>
 * Purpose:  format datestamps via date()<br>
 * Input:<br>
 *         - string: input date string
 *         - format: strftime format for output
 *         - default_date: default date if $string is empty
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_phpdate_format($string, $format = "Y/m/d H:i:s", $default_date = null)
{
    /*  if (substr(PHP_OS,0,3) == 'WIN') {
    		   $_win_from = array ('%e',  '%T',       '%D');
    		   $_win_to   = array ('%#d', '%H:%M:%S', '%m/%d/%y');
    		   $format = str_replace($_win_from, $_win_to, $format);
    	}*/
    if (substr($format, 0, 5) == 'DATE_') {
        switch ($format) {
            case 'DATE_ATOM':
                $nformat = DATE_ATOM;
                break;
            case 'DATE_COOKIE':
                $nformat = DATE_COOKIE;
                break;
            case 'DATE_ISO8601':
                $nformat = DATE_ISO8601;
                break;
            case 'DATE_RFC822':
                $nformat = "D, d M y H:i:s O";
                break;
                //The php constant is not quite right - as the time-zone comes out with invalid values like "UTC"...
            //The php constant is not quite right - as the time-zone comes out with invalid values like "UTC"...
            case 'DATE_RFC850':
                $nformat = DATE_RFC850;
                break;
            case 'DATE_RFC1036':
                $nformat = DATE_RFC1036;
                break;
            case 'DATE_RFC1123':
                $nformat = DATE_RFC1123;
                break;
            case 'DATE_RFC2822':
                $nformat = DATE_RFC2822;
                break;
            case 'DATE_RFC3339':
                $nformat = DATE_RFC3339;
                break;
            case 'DATE_RSS':
                $nformat = "D, d M Y H:i:s O";
                break;
                //as rfc822 ...
            //as rfc822 ...
            case 'DATE_W3C':
                $nformat = DATE_W3C;
                break;
        }
    } else {
        $nformat = $format;
    }
    if ($string != '') {
        return date($nformat, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
        return date($nformat, smarty_make_timestamp($default_date));
    } else {
        return;
    }
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = "M n, Y", $default_date = null)
{
    if (!empty($string)) {
        return date($format, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
        return date($format, smarty_make_timestamp($default_date));
    } else {
        return;
    }
}
function smarty_modifier_date_format($string, $format = "%b %e, %Y", $default_date = null)
{
    if ($string != '') {
        return strftime($format, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
        return strftime($format, smarty_make_timestamp($default_date));
    } else {
        return;
    }
}
/**
 * Campsite camp_date_format modifier plugin
 *
 * Type:     modifier
 * Name:     camp_date_format
 * Purpose:  format datestamps via MySQL date and time functions
 *
 * @param string
 *     $p_unixtime the date in unixtime format from $smarty.now
 * @param string
 *     $p_format the date format wanted
 *
 * @return
 *     string the formatted date
 *     null in case a non-valid format was passed
 */
function smarty_modifier_camp_date_format($p_unixtime, $p_format = null, $p_onlyEnglish = false)
{
    static $attributes = array('year'=>'%Y', 'mon'=>'%c', 'mday'=>'%e', 'yday'=>'%j',
                        'wday'=>'%w', 'hour'=>'%H', 'min'=>'%i', 'sec'=>'%S',
                        'mon_name'=>'%M', 'wday_name'=>'%W');
    static $specifiersMap = array('%h'=>'%I', '%i'=>'%M', '%s'=>'%S');
    static $conversionMap = array('%M'=>'__month_name__', '%W'=>'__weekday_name__',
                                  '%c'=>'__month__', '%e'=>'__day_of_the_month__',
                                  '%D'=>'__day_of_the_month_suffix__', '%l'=>'__hour_12_clock__');
    static $numberSuffix = array(0=>'th', 1=>'st', 2=>'nd', 3=>'rd', 4=>'th', 5=>'th', 6=>'th',
                                 7=>'th', 8=>'th', 9=>'th');

    if (array_key_exists(trim(strtolower($p_format)), $attributes)) {
        $p_format = $attributes[trim(strtolower($p_format))];
    }

    // gets the context variable
    $campsite = CampTemplate::singleton()->get_template_vars('gimme');

    // makes sure $p_unixtime is unixtime stamp
    $p_unixtime = smarty_make_timestamp($p_unixtime);

    if (is_null($p_format) || empty($p_format)) {
    	return strftime('%D %T', $p_unixtime);
    }

    $p_replaceCount = 0;
    $p_format = str_replace(array_keys($conversionMap), array_values($conversionMap),
    $p_format, $p_replaceCount);

    $p_format = str_replace(array_keys($specifiersMap), array_values($specifiersMap), $p_format);

    $formattedDate = strftime($p_format, $p_unixtime);
    if ($p_replaceCount > 0) {
    	$languageObj = new Language($campsite->language->number);
        if (!$languageObj->exists()) {
            $languageObj = new Language(1);
        }
        $timeArray = getdate($p_unixtime);
        $suffixNo = $timeArray['mday'] % 10;
        $hour = $timeArray['hours'] % 12;
        if ($hour == 0) {
        	$hour = 12;
        }
        $replaceValues = array($languageObj->getProperty('Month'.$timeArray['mon']),
                               $languageObj->getProperty('WDay'.(1+$timeArray['wday'])),
                               $timeArray['mon'],
                               $timeArray['mday'],
                               $timeArray['mday'].$numberSuffix[$suffixNo],
                               $hour);
        $formattedDate = str_replace(array_values($conversionMap), $replaceValues, $formattedDate);
    }
    return $formattedDate;
} // fn smarty_modifier_camp_date_format
Beispiel #15
0
function smarty_modifier_idate($string, $format = 'Y-m-d H:i:s', $default_date = '')
{
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    return Core_Fun::date($format, $timestamp);
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = "%b %e, %Y", $default_date = null)
{
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif (isset($default_date) && $default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        $timestamp = TIME;
    }
    return fn_date_format($timestamp, $format);
}
/**
 * Formata uma data com os mesmos parametros de date()
 *
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_datef($string, $format = 'd/m/y', $default_date = '')
{
    if ($string != '') {
        $timestamp = new DateTime(smarty_make_timestamp($string));
    } elseif ($default_date != '') {
        $timestamp = new DateTime(smarty_make_timestamp($default_date));
    } else {
        return;
    }
    return $timestamp->format($format);
}
function smarty_modifier_month_declination($dt)
{
    require_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($dt != '' && $dt != '0000-00-00' && $dt != '0000-00-00 00:00:00' && $dt) {
        $timestamp = smarty_make_timestamp($dt);
    } else {
        return '';
    }
    $str = smarty_modifier_date_format($timestamp, "%B");
    $month = intval(date("m", $timestamp));
    $str = $month == 3 || $month == 8 ? $str . 'а' : mb_substr($str, 0, mb_strlen($str) - 1) . 'я';
    return $str;
}
/**
* 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
* 
* @link http://smarty.php.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> 
* @param string $ 
* @param string $ 
* @param string $ 
* @return string |void
* @uses smarty_make_timestamp()
*/
function smarty_modifier_date_format($string, $format = SMARTY_RESOURCE_DATE_FORMAT, $default_date = '',$formatter='auto')
{
    /**
    * Include the {@link shared.make_timestamp.php} plugin
    */
    require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    } 
    if($formatter=='strftime'||($formatter=='auto'&&strpos($format,'%')!==false)) {
        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));
            } 
            if (strpos($format, '%l') !== false) {
                $_win_from[] = '%l';
                $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
            } 
            $format = str_replace($_win_from, $_win_to, $format);
        } 
        return strftime($format, $timestamp);
    } elseif (strpos($format, '_') !== false) {
        $months = array('pad',
            t('January'),
            t('February'),
            t('March'),
            t('April'),
            t('May'),
            t('June'),
            t('July'),
            t('August'),
            t('September'),
            t('October'),
            t('November'),
            t('December')
        );
        if ($format == '_month')
        {
            return $months[(int)$string];
        } 
    } else {
        return date($format, $timestamp);
    }
} 
function smarty_modifier_pc_date_format($string, $format = null, $default_date = null)
{
    setlocale(LC_TIME, _PC_LOCALE);
    if (empty($format)) {
        $format = _SETTING_DATE_FORMAT;
    }
    if ($string != '') {
        return strftime($format, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
        return strftime($format, smarty_make_timestamp($default_date));
    } else {
        return;
    }
}
/**
* Create new Smarty object
* @return double Smarty to newly created Smarty object
*
*/
function smarty_modifier_amember_date_format($string, $format = null)
{
    if ($string == MAX_SQL_DATE) {
        return _COMMON_LIFETIME;
    }
    if ($string == RECURRING_SQL_DATE) {
        return _COMMON_RECURRING;
    }
    if ($format == null) {
        $format = $GLOBALS['config']['date_format'];
    }
    if ($string != '') {
        return strftime($format, smarty_make_timestamp($string));
    }
}
function smarty_function_pc_date_format($args)
{
    extract($args);
    unset($args);
    setlocale(LC_TIME, _PC_LOCALE);
    if (!isset($format)) {
        $format = _SETTING_DATE_FORMAT;
    }
    if (isset($date)) {
        list($y, $m, $d) = explode('-', $date);
        echo strftime($format, smarty_make_timestamp($date));
    } else {
        echo strftime($format, time());
    }
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = "%b %e, %Y", $default_date = null)
{
    /**
     * Include the {@link shared.make_timestamp.php} plugin
     */
    require_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif (isset($default_date) && $default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        $timestamp = TIME;
    }
    return fn_date_format($timestamp, $format);
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = "%b %e, %Y", $default_date = null)
{
    if (substr(PHP_OS, 0, 3) == 'WIN') {
        $_win_from = array('%e', '%T', '%D');
        $_win_to = array('%#d', '%H:%M:%S', '%m/%d/%y');
        $format = str_replace($_win_from, $_win_to, $format);
    }
    if ($string != '') {
        return strftime($format, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
        return strftime($format, smarty_make_timestamp($default_date));
    } else {
        return;
    }
}
 /**
  Renvoie différentes infos chiffrées d'un blog, dans un tableau
 */
 public function getStats($id_blog)
 {
     $dao = _dao('blog|blogarticle');
     $res = array();
     $arData = $dao->getAllArticlesFromBlog($id_blog, NULL);
     $nbArticles = count($arData);
     $res['nbArticles'] = array('name' => CopixI18N::get('blog|blog.stats.nbArticles', array($nbArticles)), 'value' => $nbArticles);
     //print_r($arData);
     if ($nbArticles > 0) {
         $date = BDToDateTime($arData[0]->date_bact, $arData[0]->time_bact, 'mysql');
         $mktime = smarty_make_timestamp($date);
         $date = CopixDateTime::mktimeToDatetime($mktime);
         $res['lastUpdate'] = array('name' => CopixI18N::get('blog|blog.stats.lastUpdate', array($date)), 'value_order' => $mktime);
     }
     //print_r($res);
     return $res;
 }
function smarty_modifier_custom_date_format($string, $default_date = null)
{
    $timestamp = smarty_make_timestamp($string);
    $year = date("Y", $timestamp);
    $month = date("n", $timestamp);
    $day = date("j", $timestamp);
    switch ($month) {
        case 1:
            $month_name = "Января";
            break;
        case 2:
            $month_name = "Февраля";
            break;
        case 3:
            $month_name = "Марта";
            break;
        case 4:
            $month_name = "Апреля";
            break;
        case 5:
            $month_name = "Мая";
            break;
        case 6:
            $month_name = "Июня";
            break;
        case 7:
            $month_name = "Июля";
            break;
        case 8:
            $month_name = "Августа";
            break;
        case 9:
            $month_name = "Сентября";
            break;
        case 10:
            $month_name = "Октября";
            break;
        case 11:
            $month_name = "Ноября";
            break;
        case 12:
            $month_name = "Декабря";
            break;
    }
    return $day . " " . $month_name . " " . $year;
}
/**
 * Smarty date_format_pretty modifier plugin
 * 
 * Type:     modifier<br>
 * Name:     date_format_pretty<br>
 * Purpose:  pretty-print file modification times<br>
 * Input:<br>
 *         - string: input date string
 *         - lang: Locale to use (de_DE,en_US, etc. null for default)
 *         - default_date: default date if $string is empty
 * @author Patrick Prasse <*****@*****.**>
 * @version $Revision: 1.3 $
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format_pretty($string, $showtime = true, $default_date = null)
{
    if ($string != '' && $string != '0000-00-00') {
        $date = smarty_make_timestamp($string);
    } elseif (isset($default_date) && $default_date != '') {
        $date = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if ($showtime) {
        if ($date > strtotime('today 00:00:00')) {
            $d = "Today, " . strftime('%H:%M', $date);
        } elseif ($date > strtotime('yesterday 00:00:00')) {
            $d = "Yesterday, " . strftime('%H:%M', $date);
        } elseif ($date > strtotime('-2 days 00:00:00')) {
            // only for de_* locales
            $d = "2 Days Ago, " . strftime('%H:%M', $date);
        } elseif ($date > strtotime('-1 week 00:00:00')) {
            $d = strftime('%A, %H:%M', $date);
        } elseif ($date > strtotime('-1 year 00:00:00')) {
            $d = strftime('%d %B, %H:%M', $date);
        } else {
            $d = strftime('%d %B %Y, %H:%M', $date);
        }
    } else {
        if ($date > strtotime('today 00:00:00')) {
            $d = "Today";
        } elseif ($date > strtotime('yesterday 00:00:00')) {
            $d = "Yesterday";
        } elseif ($date > strtotime('-2 days 00:00:00')) {
            // only for de_* locales
            $d = "2 Days Ago, " . strftime('%H:%M', $date);
        } elseif ($date > strtotime('-1 week 00:00:00')) {
            $d = strftime('%A', $date);
        } elseif ($date > strtotime('-1 year 00:00:00')) {
            $d = strftime('%d %B', $date);
        } else {
            $d = strftime('%d %B %Y', $date);
        }
    }
    if (isset($lang)) {
        setlocale(LC_TIME, $save_lang);
    }
    return $d;
}
/**
 * Plugin smarty type modifier
 * Purpose:  format a date given by its timestamp (YYYMMDD) to a date according
 *   to the current languages settings
 * if an incorrect date is given, returns the string without any modification
 * Input: YYYYMMDD
 * Output: (french) DD/MM/YYYY, (english) MM/DD/YYYY
 * Output plain text date if text is given as an extra parameter
 *
 * Example:  {$date|datei18n}
 *           {$date|datei18n:text}
 *
 * @return string
 */
function smarty_modifier_datei18n($string, $format = "")
{
    // COPIX 3
    /*
       if ($format == ""){
     return (($date = CopixDateTime::yyyymmddToDate ($string)) !== false) ? $date : $string;
       }elseif ($format == "text"){
     return (($date = CopixDateTime::yyyymmddToText ($string)) !== false) ? $date : $string;
       }
    */
    require_once COPIX_UTILS_PATH . 'CopixDateTime.class.php';
    // COPIX 2
    if ($format == "") {
        return ($date = CopixDateTime::yyyymmddToDate($string)) !== false ? $date : $string;
    } elseif ($format == "text") {
        return ($date = CopixDateTime::yyyymmddToText($string)) !== false ? $date : $string;
    } elseif ($format == "date_short") {
        // JJ/MM/AAAA (fr)
        //var_dump($string);
        //return CopixDateTime::yyyymmddToDate($string);
        $mktime = smarty_make_timestamp($string);
        //var_dump($mktime.'/'.date('d/m/Y',$mktime));
        $yyyymmdd = CopixDateTime::timestampToyyyymmdd($mktime);
        $res = CopixDateTime::yyyymmddToDate($yyyymmdd);
        return $res;
        /*
        return Kernel::ymd2dmy($string);
        
        $mktime = smarty_make_timestamp($string);
        $timestamp = date("Ymd", $mktime);
              //return (($date = CopixDateTime::timestampToDate ($timestamp)) !== false) ? $date : $string;
        $timestamp2 = CopixDateTime::dateToTimestamp ($string);
        
        var_dump($string);
        
        return (($timestamp==$timestamp2) ? CopixDateTime::timestampToDate ($timestamp) : $string);
        */
    } elseif ($format == "date_short_time") {
        // JJ/MM/AAAA HHhMM (fr)
        $mktime = smarty_make_timestamp($string);
        return ($date = CopixDateTime::mktimeToDatetime($mktime)) !== false ? $date : $string;
    }
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')
{
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if (DIRECTORY_SEPARATOR == '\\' || DIRECTORY_SEPARATOR == '/') {
        $_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));
        }
        if (strpos($format, '%m') !== false) {
            $_win_from[] = '%m';
            $_win_to[] = sprintf('%\' 2d', date('n', $timestamp));
        }
        if (strpos($format, '%l') !== false) {
            $_win_from[] = '%l';
            $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
        }
        // slovenske nazvy mesiacov
        if (strpos($format, '%F') !== false) {
            $months = DobraKrajinaPageTime::$months;
            $_win_from[] = '%F';
            $_win_to[] = sprintf('%\' s', $months[date('m', $timestamp) - 1]);
        }
        // slovenske nazvy dni
        if (strpos($format, '%N') !== false) {
            $days = DobraKrajinaPageTime::$weekDays;
            $_win_from[] = '%N';
            $_win_to[] = sprintf('%\' s', $days[date('N', $timestamp) - 1]);
        }
        $format = str_replace($_win_from, $_win_to, $format);
    }
    return strftime($format, $timestamp);
}
/**
 * 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
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_date_format2($string, $format = '%b %e, %Y', $default_date = '')
{
    if ($string != '') {
        $timestamp = smarty_make_timestamp($string);
    } elseif ($default_date != '') {
        $timestamp = smarty_make_timestamp($default_date);
    } else {
        return;
    }
    if (DIRECTORY_SEPARATOR == '\\') {
        $_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));
        }
        if (strpos($format, '%l') !== false) {
            $_win_from[] = '%l';
            $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
        }
        $format = str_replace($_win_from, $_win_to, $format);
    }
    // Ordinal
    $ordinal = "th";
    $day = date("d", $timestamp);
    $day_1 = substr($day, -1);
    $day_2 = substr($day, -2);
    if ($day_1 == 1 and $day_2 != 11) {
        $ordinal = "st";
    }
    if ($day_1 == 2 and $day_2 != 12) {
        $ordinal = "nd";
    }
    if ($day_1 == 3 and $day_2 != 13) {
        $ordinal = "rd";
    }
    $format = str_replace("%o", $ordinal, $format);
    return strftime($format, $timestamp);
}