/**
 * 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: YYYYMMDDHHIISS
 * Output: (french) DD/MM/YYYY HH:II:SS, (english) MM/DD/YYYY HH:II:SS
 * Example:  {$date|datetimei18n}
 * @return string
 */
function smarty_modifier_datetimei18n($string, $format = "")
{
    if ($format == "") {
        return ($date = CopixDateTime::yyyymmddhhiissToDateTime($string)) !== false ? $date : $string;
    }
    return ($date = CopixDateTime::yyyymmddhhiissToText($string)) !== false ? $date : $string;
}
 public function testToDateTime()
 {
     CopixI18N::setLang('fr');
     $this->assertEquals('25/12/1976', CopixDateTime::timestampToDate(220316400));
     $this->assertEquals('25/12/1976', CopixDateTime::yyyymmddToDate('19761225'));
     $this->assertEquals('25/12/1976 15:00:00', CopixDateTime::yyyymmddhhiissToDateTime('19761225150000'));
     CopixI18N::setLang('en');
     $this->assertEquals('12/25/1976', CopixDateTime::YYYYMMDDToDate('19761225'));
     $this->assertNull(null);
     $this->assertFalse(CopixDateTime::YYYYMMDDToDate('1123761225'));
     $this->assertEquals('12/25/1976', CopixDateTime::timestampToDate(220316400));
     $this->assertEquals('12/25/1976 15:00:00', CopixDateTime::yyyymmddhhiissToDateTime('19761225150000'));
     $this->assertEquals('12/25/1976 10:00:00', CopixDateTime::yyyymmddhhiissToDateTime('19761225100000'));
 }
 public function beforeDisplay(&$display)
 {
     $jscode = array();
     $logs = array();
     foreach (CopixConfig::instance()->copixlog_getRegistered() as $profil) {
         $name = CopixConfig::instance()->copixlog_getProfile($profil);
         $name = $name['strategy'];
         if (strtoupper($name) == "FIREBUG") {
             $logs[] = CopixLog::getLog($profil);
         }
     }
     //merge last logs to new logs
     if (CopixSession::get('plugin|firebug|log') !== null) {
         $logs = array_merge(CopixSession::get('plugin|firebug|log'), $logs);
         CopixSession::set('plugin|firebug|log', null);
     }
     $logs = array_reverse($logs);
     foreach ($logs as $arlog) {
         foreach ($arlog as $log) {
             foreach (array('message', 'file', 'line', 'level', 'classname', 'functionname', 'type') as $var) {
                 if (isset($log->{$var})) {
                     ${$var} = $log->{$var};
                     unset($log->{$var});
                 } else {
                     ${$var} = null;
                 }
             }
             $log->date = CopixDateTime::yyyymmddhhiissToDateTime($log->date);
             $log->location = "{$file}:{$line}";
             $log->function = ($classname ? "{$classname}::" : "") . $functionname;
             switch ($level) {
                 case CopixLog::INFORMATION:
                     $type = "info";
                     break;
                 case CopixLog::WARNING:
                 case CopixLog::NOTICE:
                     $type = "warn";
                     break;
                 case CopixLog::EXCEPTION:
                 case CopixLog::ERROR:
                 case CopixLog::FATAL_ERROR:
                     $type = "error";
                     break;
                 default:
                     $type = "log";
             }
             unset($log->level);
             $jscode[] = sprintf('_l(%s,%s,%s,%s);', CopixJSON::encode($type), CopixJSON::encode($message), CopixJSON::encode($log->location), CopixJSON::encode($log));
         }
     }
     foreach (CopixConfig::instance()->copixlog_getRegistered() as $profil) {
         $name = CopixConfig::instance()->copixlog_getProfile($profil);
         $name = $name['strategy'];
         if (strtoupper($name) == "FIREBUG") {
             CopixLog::deleteProfile($profil);
         }
     }
     if (count($jscode) > 0) {
         $jscode[] = "if(window.console && console.firebug){var _l=function(t,m,l,e){console.group('[COPIX] - '+t+' - '+l);console[t](m);console.dir(e);console.groupEnd();}";
         $jscode = array_reverse($jscode);
         $jscode[] = "}";
         CopixHTMLHeader::addJSCode(implode("\n", $jscode));
     }
 }