Page 1 of 1

Date bug in older smarty included in 1.1b5

Posted: Sat Nov 19, 2005 8:41 am
by Gizmo
Just a heads up. I just spend the last 2 hours tracking this down, but there's a bug in the version of Smarty currently packaged with CMS 1.1b5 in the smarty_make_timestamp() function that is used in the html_select_date() function and date_format modifier. This affects the news module in particular, causing the date selection mechanism to be out of whack. This bug may or may not affect you. It's been fixed in the 1.5.2 Changelog. If you encounter this bug, simply download the latest version of Smarty and replace the file shared.make_timestamp.php in the CMS distribution.

From the smarty NEWS file:

Version 1.5.2
-------------
    - added Smarty object as fifth argument for template resource functions.
      (Monte)
    - fixed a bug with incorrectly combined cache and compile id in
      clear_cache(). (Andrei)
    - fixed bug in smarty_make_timestamp introduced in PHP 4.1.0. (Monte)
    - fixed bug with cached insert debug timing. (Monte)
    - added 'script' attribute to {insert..} which specifies the script that
      the insert function can be found in. (Andrei)
    - added default template function handler. (Monte)

Re: Date bug in older smarty included in 1.1b5

Posted: Sat Nov 19, 2005 11:06 am
by Piratos
??? i don't understand this.

Smarty latest version is 2.6.10

CMS delivered version is 2.6.9


Version 1.5.2 is something of the arche noha

Re: Date bug in older smarty included in 1.1b5

Posted: Sun Nov 20, 2005 5:46 am
by Gizmo
It's included in smarty as part of a plugin, so while the core was upgraded this may have been overlooked.

If you check the included shared.make_timestamp.php file with CMS 1.1b5, it's considerably different from the latest version included with Smarty. Likely it's the old, buggy pre-1.5.2 version.

This is probably something that needs to be fixed in CVS

Old file (included in CMS 1.1b5)

* Purpose:  used by other smarty functions to make a timestamp
*          from a string.
* @param string
* @return string
*/
function smarty_make_timestamp($string)
{
    if(empty($string)) {
        $string = "now";
    }
    $time = strtotime($string);
    if (is_numeric($time) && $time != -1)
        return $time;

    // is mysql timestamp format of YYYYMMDDHHMMSS?
    if (preg_match('/^\d{14}$/', $string)) {
        $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
              substr($string,4,2),substr($string,6,2),substr($string,0,4));

        return $time;
    }

    // couldn't recognize it, try to return a time
    $time = (int) $string;
    if ($time > 0)
        return $time;
    else
        return time();
}

/* vim: set expandtab: */

?>
New file (included in latest Smarty):

* Purpose:  used by other smarty functions to make a timestamp
*          from a string.
* @param string
* @return string
*/
function smarty_make_timestamp($string)
{
    if(empty($string)) {
        // use "now":
        $time = time();

    } elseif (preg_match('/^\d{14}$/', $string)) {
        // it is mysql timestamp format of YYYYMMDDHHMMSS?           
        $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
                      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
        $time = (int)$string;
       
    } else {
        // strtotime should handle it
        $time = strtotime($string);
        if ($time == -1 || $time === false) {
            // strtotime() was not able to parse $string, use "now":
            $time = time();
        }
    }
    return $time;

}

/* vim: set expandtab: */

?>

Re: Date bug in older smarty included in 1.1b5

Posted: Sun Nov 20, 2005 10:06 am
by Piratos
Ahhh i see !