/** * Plugin smarty type fonction * Purpose: Génère une valeur JSON. * * Input: assign=variable où la sortie sera assignée * data=valeur à convertir * data_*=le pr * * = tout autre paramètre sera passé encodé * * @param array $params les paramètres passés au tag * @param Smarty $me l'objet Smarty en cours d'exécution */ function smarty_function_json($params, &$me) { // Paramètre 'assign' if (isset($params['assign'])) { $assign = $params['assign']; unset($params['assign']); } else { $assign = null; } // Paramètre 'data' if (isset($params['data'])) { $data = $params['data']; unset($params['data']); } else { $data = array(); } // Paramètres 'data_*' et '*' foreach ($params as $k => $v) { if (stripos($k, 'data_') === 0) { $data[substr($k, 5)] = $v; } else { $data[$k] = $v; } } // Génération $toReturn = CopixJSON::encode($data); // Assigne ou retourne if ($assign) { $me->assign($assign, $toReturn); return ''; } else { return $toReturn; } }
/** * Demande le chargement de Mootools. * * @param array $pPlugins Liste de plugins à charger. */ public static function addJSFramework($pPlugins = null) { // Charge le noyau if (!isset(self::$_JSFrameworkAdded['*core*'])) { self::$_JSFrameworkAdded['*core*'] = true; // Initialise Mootools et l'identifiant de session if (!CopixAJAX::isAJAXRequest()) { // Ajoute MooTools et FirebugLite if (CopixConfig::instance()->getMode() == CopixConfig::DEVEL) { // MooTools non compressé et FirebugLite normal self::addJSLink(_resource('js/firebuglite/firebug.js'), array('id' => 'firebug_js')); self::addJSLink(_resource('js/mootools/mootools-devel.js'), array('id' => 'mootools_core_js')); } else { // MooTools compressé et FirebugLite qui ne fait rien. self::addJSLink(_resource('js/firebuglite/firebugx.js'), array('id' => 'firebug_js')); self::addJSLink(_resource('js/mootools/mootools.js'), array('id' => 'mootools_core_js')); } // Ajoute le framework JS spécifique de Copix self::addJSLink(_resource('js/copix.js'), array('id' => 'copix_js', 'charset' => 'UTF-8')); // Ajoute le code d'initialisation $urlBase = CopixUrl::get(); self::addJSCode(sprintf('Copix = new CopixClass(%s);', CopixJSON::encode(array('ajaxSessionId' => CopixAJAX::getSessionId(), 'module' => CopixContext::get(), 'urlBase' => $urlBase, 'resourceUrlBase' => CopixResource::getResourceBaseUrl($urlBase, CopixTpl::getTheme(), CopixI18N::getLang(), CopixI18N::getCountry())))), 'copixajax_init', CopixHTMLHeader::DOMREADY_ALWAYS); } } // Charge les plugins if (is_array($pPlugins)) { foreach ($pPlugins as $pluginName) { if (!isset(self::$_JSFrameworkAdded[$pluginName])) { self::$_JSFrameworkAdded[$pluginName] = true; $pluginId = 'mootools_plugin_' . $pluginName; $scriptId = $pluginId . '_js'; $stylesheetId = $pluginId . '_css'; if (file_exists(CopixUrl::getResourcePath($path = 'js/mootools/plugins/' . $pluginName . '.js'))) { self::addJSLink(_resource($path), array("id" => $scriptId)); } elseif (file_exists(CopixUrl::getResourcePath($path = 'js/mootools/plugins/' . $pluginName . '.js.php'))) { self::addJSLink(_resource($path), array("id" => $scriptId)); } else { throw new CopixException('[Mootools] Plugin ' . $pluginName . ' not found in ' . $pluginPath); } if (file_exists(CopixUrl::getResourcePath($path = 'js/mootools/css/' . $pluginName . '.css'))) { self::addCssLink(_resource($path), array("id" => $stylesheetId)); } } } } }
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)); } }
/** * Plugin smarty type modifier * Purpose: encode a value using JSON. * @return string */ function smarty_modifier_json($value) { return CopixJSON::encode($value); }