Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty shared plugin
Chris PeBenito 696b41
 * @package Smarty
Chris PeBenito 696b41
 * @subpackage plugins
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Function: smarty_make_timestamp
Chris PeBenito 696b41
 * Purpose:  used by other smarty functions to make a timestamp
Chris PeBenito 696b41
 *           from a string.
Chris PeBenito 696b41
 * @param string
Chris PeBenito 696b41
 * @return string
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
function smarty_make_timestamp($string)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
    if(empty($string)) {
Chris PeBenito 696b41
        $string = "now";
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
    $time = strtotime($string);
Chris PeBenito 696b41
    if (is_numeric($time) && $time != -1)
Chris PeBenito 696b41
        return $time;
Chris PeBenito 696b41
Chris PeBenito 696b41
    // is mysql timestamp format of YYYYMMDDHHMMSS?
Chris PeBenito 696b41
    if (preg_match('/^\d{14}$/', $string)) {
Chris PeBenito 696b41
        $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
Chris PeBenito 696b41
               substr($string,4,2),substr($string,6,2),substr($string,0,4));
Chris PeBenito 696b41
Chris PeBenito 696b41
        return $time;
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
Chris PeBenito 696b41
    // couldn't recognize it, try to return a time
Chris PeBenito 696b41
    $time = (int) $string;
Chris PeBenito 696b41
    if ($time > 0)
Chris PeBenito 696b41
        return $time;
Chris PeBenito 696b41
    else
Chris PeBenito 696b41
        return time();
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>