caching = false;
$this->config_overwrite = false;
$this->use_sub_dirs = false;
$this->template_dir = $globals->spoolroot . '/templates/';
$this->compile_dir = $globals->spoolroot . '/spool/templates_c/';
array_unshift($this->plugins_dir,
$globals->spoolroot . '/core/plugins/',
$globals->spoolroot . '/plugins/');
$this->config_dir = $globals->spoolroot . '/configs/';
$this->compile_check = !empty($globals->debug) || $globals->smarty_autocompile;
$this->_errors = array('errors' => array());
$this->_jsonVars = array();
$this->_failure = false;
if ($globals->mode != 'rw') {
$this->trigError("En raison d'une maintenance, une partie des fonctionnalités du site est"
. " actuellement désactivée, en particulier aucune donnée ne sera sauvegardée");
}
$this->register_prefilter('at_to_globals');
}
// }}}
// {{{ function changeTpl()
public function changeTpl($tpl, $type = SKINNED)
{
$this->_tpl = $tpl;
$this->_page_type = $type;
$this->assign('pl_tpl', $tpl);
}
// }}}
// {{{ function getCoreTpl()
public static function getCoreTpl($tpl)
{
global $globals;
return $globals->spoolroot . '/core/templates/' . $tpl;
}
// }}}
// {{{ function coreTpl()
/** Use a template from the core.
*/
public function coreTpl($tpl, $type = SKINNED)
{
global $globals;
$this->changeTpl(self::getCoreTpl($tpl), $type);
}
// }}}
// {{{ function raw()
public function raw()
{
global $globals;
$this->assign('globals', $globals);
return $this->fetch($this->_tpl);
}
// }}}
// {{{ function _run()
protected function _run($skin)
{
global $globals, $platal, $TIME_BEGIN;
Platal::session()->close();
$this->register_prefilter('trimwhitespace');
$this->register_prefilter('form_force_encodings');
$this->register_prefilter('wiki_include');
$this->register_prefilter('core_include');
$this->register_prefilter('if_rewrites');
$this->assign('pl_triggers', $this->_errors);
$this->assign('pl_errors', $this->nb_errs());
$this->assign('pl_failure', $this->_failure);
$this->assign_by_ref('platal', $platal);
$this->assign_by_ref('globals', $globals);
if (Env::has('json') && count($this->_jsonVars)) {
return $this->jsonDisplay();
}
if (Env::v('display') == 'light') {
$this->_page_type = SIMPLE;
} elseif (Env::v('display') == 'raw') {
$this->_page_type = NO_SKIN;
} elseif (Env::v('display') == 'full') {
$this->_page_typ = SKINNED;
}
switch ($this->_page_type) {
case NO_SKIN:
if (!($globals->debug & DEBUG_SMARTY)) {
error_reporting(0);
}
$this->display($this->_tpl);
exit;
case SIMPLE:
$this->assign('simple', true);
case SKINNED:
$this->register_modifier('escape_html', 'escape_html');
$this->default_modifiers = Array('@escape_html');
}
if (S::i('auth') <= AUTH_PUBLIC) {
$this->register_outputfilter('hide_emails');
}
header("Accept-Charset: utf-8");
if (Env::v('forceXml')) {
pl_content_headers("text/xml");
}
if (!$globals->debug) {
error_reporting(0);
$this->display($skin);
exit;
}
$this->assign('validate', true);
if (!($globals->debug & DEBUG_SMARTY)) {
error_reporting(0);
}
$START_SMARTY = microtime(true);
$result = $this->fetch($skin);
$ttime = sprintf('Temps total: %.02fs (Smarty %.02fs) - Mémoire totale : %dKo
',
microtime(true) - $TIME_BEGIN, microtime(true) - $START_SMARTY,
memory_get_peak_usage(true) / 1024);
if ($globals->debug & DEBUG_BT) {
PlBacktrace::clean();
$this->assign_by_ref('backtraces', PlBacktrace::$bt);
$result = str_replace('@@BACKTRACE@@',
$this->fetch(self::getCoreTpl('backtrace.tpl')),
$result);
} else {
$result = str_replace('@@BACKTRACE@@', '', $result);
}
$replc = "VALIDATION HTML INACTIVE
";
if ($globals->debug & DEBUG_VALID) {
$fd = fopen($this->compile_dir."/valid.html","w");
fwrite($fd, $result);
fclose($fd);
exec($globals->spoolroot."/bin/devel/xhtml.validate.pl ".$this->compile_dir."/valid.html", $val);
foreach ($val as $h) {
if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) {
$replc = 'HTML OK
';
if ($m[1]) {
$replc = "{$m[1]} ERREUR(S) !!!
";
}
break;
}
}
}
echo str_replace("@HOOK@", $ttime.$replc, $result);
exit;
}
abstract public function run();
// }}}
// {{{ function nb_errs()
public function nb_errs()
{
return count($this->_errors['errors']);
}
// }}}
// {{{ function trig()
private function trig($msg, $type = 'errors')
{
if (!isset($this->_errors[$type])) {
$this->_errors[$type] = array();
}
$this->_errors[$type][] = $msg;
}
public function trigError($msg)
{
$this->trig($msg, 'errors');
}
public function trigWarning($msg)
{
$this->trig($msg, 'warnings');
}
public function trigSuccess($msg)
{
$this->trig($msg, 'success');
}
// }}}
// {{{ function kill()
public function kill($msg, $type = 'errors')
{
// PHP is used on command line... do not run the whole page stuff.
if (php_sapi_name() == 'cli') {
echo $msg . "\n";
exit(-1);
}
global $platal;
$this->trig($msg, $type);
$this->_failure = true;
$this->run();
}
public function killError($msg)
{
$this->kill($msg, 'errors');
}
public function killWarning($msg)
{
$this->kill($msg, 'warnings');
}
public function killSuccess($msg)
{
$this->kill($msg, 'success');
}
// }}}
// {{{ function setTitle
public function setTitle($title)
{
global $globals;
if (isset($globals->core->sitename)) {
$title = $globals->core->sitename . ' :: ' . $title;
}
$this->assign('pl_title', $title);
}
// }}}
// {{{ function addJsLink
public function addJsLink($filename, $static_content = true)
{
if ($static_content) {
$this->append('pl_js', pl_static_content_path("javascript/", $filename));
} else {
$this->append('pl_js', "javascript/$filename");
}
}
// }}}
// {{{ function addCssLink
public function addCssLink($path)
{
$this->append('pl_css', $path);
}
// }}}
// {{{ function addLink
public function addLink($rel, $path)
{
$this->append('pl_link', array('rel' => $rel, 'href' => $path));
}
// }}}
// {{{ function addCssInline
public function addCssInline($css)
{
if (!empty($css)) {
$this->append('pl_inline_css', $css);
}
}
// }}}
// {{{ function setRssLink
public function setRssLink($title, $path)
{
$this->assign('pl_rss', array('title' => $title, 'href' => $path));
}
// }}}
// {{{ function jsonDisplay
protected function jsonDisplay()
{
pl_content_headers("text/javascript");
array_walk_recursive($this->_jsonVars, "escape_xorgDB");
$jsonbegin = Env::v('jsonBegin');
$jsonend = Env::v('jsonEnd');
if (Env::has('jsonVar')) {
$jsonbegin = Env::v('jsonVar').' = ';
$jsonend = ';';
} elseif (Env::has('jsonFunc')) {
$jsonbegin = Env::v('jsonFunc').'(';
$jsonend = ');';
}
echo $jsonbegin, json_encode($this->_jsonVars), $jsonend;
exit;
}
// }}}
// {{{ function jsonAssign
public function jsonAssign($var, $value)
{
$this->_jsonVars[$var] = $value;
}
// }}}
}
function escape_xorgDB(&$item, $key)
{
if ($item instanceof XOrgDBIterator) {
$expanded = array();
while ($a = $item->next()) {
$expanded[] = $a;
}
$item = $expanded;
}
}
// {{{ function escape_html ()
/**
* default smarty plugin, used to auto-escape dangerous html.
*
* < --> <
* > --> >
* " --> "
* & not followed by some entity --> &
*/
function escape_html($string)
{
if (is_string($string)) {
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
} else {
return $string;
}
}
// }}}
// {{{ function at_to_globals()
/**
* helper
*/
function _to_globals($s) {
global $globals;
$t = explode('.',$s);
if (count($t) == 1) {
return var_export($globals->$t[0],true);
} else {
return var_export($globals->$t[0]->$t[1],true);
}
}
/**
* compilation plugin used to import $globals confing through #globals.foo.bar# directives
*/
function at_to_globals($tpl_source, &$smarty)
{
return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source);
}
// }}}
// {{{ function trimwhitespace
function trimwhitespace($source, &$smarty)
{
$tags = '(script|pre|textarea)';
preg_match_all("!<$tags.*?>.*?(\\1)>!ius", $source, $tagsmatches);
$source = preg_replace("!<$tags.*?>.*?(\\1)>!ius", "&&&tags&&&", $source);
// remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag.
$source = preg_replace('/((?)\n)[\s]+/m', '\1', $source);
$source = preg_replace("!&&&tags&&&!e", 'array_shift($tagsmatches[0])', $source);
return $source;
}
// }}}
// {{{ function wiki_include
function wiki_include($source, &$smarty)
{
global $globals;
return preg_replace('/\{include( [^}]*)? wiki=([^} ]+)(.*?)\}/ui',
'{include\1 file="' . $globals->spoolroot . '/spool/wiki.d/cache_\2.tpl"\3 included=1}',
$source);
}
function core_include($source, &$smarty)
{
global $globals;
return preg_replace('/\{include( [^}]*)? core=([^} ]+)(.*?)\}/ui',
'{include\1 file="' . $globals->spoolroot . '/core/templates/\2"\3}',
$source);
}
// }}}
//{{{ function hasPerm
function if_rewrites($source, &$smarty)
{
$perms = 'isset($smarty.session.perms|smarty:nodefaults) && $smarty.session.perms|smarty:nodefaults && $smarty.session.perms';
return preg_replace(array('/\{if([^}]*) (\!?)hasPerms\(([^)]+)\)([^}]*)\}/',
'/\{if([^}]*) (\!?)hasPerm\(([^)]+)\)([^}]*)\}/',
'/\{if([^}]*) (\!?)t\(([^)]+)\)([^}]*)\}/'),
array('{if\1 \2(' . $perms . '->hasFlagCombination(\3))\4}',
'{if\1 \2(' . $perms . '->hasFlag(\3))\4}',
'{if\1 \2(isset(\3|smarty:nodefaults) && (\3|smarty:nodefaults))\4}'),
$source);
}
// }}}
// {{{
function form_force_encodings($source, &$smarty)
{
return preg_replace('/