X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2Fplatalpage.php;h=f3bb2fa760d3225c9af81d673484f937d4bce242;hb=92c3f9e5a1c480d9c25dd98aff56e792c378d0fe;hp=b0a561bb4990e6ee36c163ead3f364026cc3c132;hpb=90ccb0625d5bdeafaf852ab5c9fb25ef230778b2;p=platal.git diff --git a/classes/platalpage.php b/classes/platalpage.php index b0a561b..f3bb2fa 100644 --- a/classes/platalpage.php +++ b/classes/platalpage.php @@ -1,6 +1,6 @@ compile_check = !empty($globals->debug); - $this->_page_type = $type; - $this->_tpl = $tpl; - $this->_errors = array(); + $this->changeTpl($tpl, $type); + $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 sont" + . " actuellement désactivée, en particuliers aucune donnée ne sera sauvegardée"); + } $this->register_prefilter('at_to_globals'); $this->addJsLink('xorg.js'); + $this->addJsLink('jquery.js'); } // }}} @@ -62,9 +66,9 @@ class PlatalPage extends Smarty public function changeTpl($tpl, $type = SKINNED) { - $this->_tpl = $tpl; - $this->_page_type = $type; - $this->assign('xorg_tpl', $tpl); + $this->_tpl = $tpl; + $this->_page_type = $type; + $this->assign('xorg_tpl', $tpl); } // }}} @@ -88,14 +92,17 @@ class PlatalPage extends Smarty $this->register_prefilter('trimwhitespace'); $this->register_prefilter('form_force_encodings'); - $this->assign('xorg_errors', $this->_errors); + $this->register_prefilter('wiki_include'); + $this->register_prefilter('if_has_perms'); + $this->assign('xorg_triggers', $this->_errors); + $this->assign('xorg_errors', $this->nb_errs()); $this->assign('xorg_failure', $this->_failure); $this->assign('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') { @@ -106,7 +113,9 @@ class PlatalPage extends Smarty switch ($this->_page_type) { case NO_SKIN: - error_reporting(0); + if (!($globals->debug & DEBUG_SMARTY)) { + error_reporting(0); + } $this->display($this->_tpl); exit; @@ -114,10 +123,12 @@ class PlatalPage extends Smarty $this->assign('simple', true); case SKINNED: - $this->register_modifier('escape_html', 'escape_html'); - $this->default_modifiers = Array('@escape_html'); + $this->register_modifier('escape_html', 'escape_html'); + $this->default_modifiers = Array('@escape_html'); + } + if (S::i('auth') <= AUTH_PUBLIC) { + $this->register_outputfilter('hide_emails'); } - $this->register_outputfilter('hide_emails'); $this->addJsLink('wiki.js'); header("Accept-Charset: utf-8"); if (Env::v('forceXml')) { @@ -130,19 +141,25 @@ class PlatalPage extends Smarty exit; } - if ($globals->debug & 1) { + $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('skin/common.backtrace.tpl'), $result); + } else { + $result = str_replace('@@BACKTRACE@@', '', $result); } - $this->assign('validate', true); - error_reporting(0); - $result = $this->fetch($skin); - $ttime = sprintf('Temps total: %.02fs - Mémoire totale : %dKo
', microtime(true) - $TIME_BEGIN - , memory_get_peak_usage(true) / 1024); $replc = "VALIDATION HTML INACTIVE
"; - - if ($globals->debug & 2) { + if ($globals->debug & DEBUG_VALID) { $fd = fopen($this->compile_dir."/valid.html","w"); fwrite($fd, $result); fclose($fd); @@ -164,20 +181,40 @@ class PlatalPage extends Smarty exit; } + abstract public function run(); + // }}} // {{{ function nb_errs() public function nb_errs() { - return count($this->_errors); + return count($this->_errors['errors']); } // }}} // {{{ function trig() - public function trig($msg) + 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->_errors[] = $msg; + $this->trig($msg, 'warnings'); + } + + public function trigSuccess($msg) + { + $this->trig($msg, 'success'); } // }}} @@ -188,7 +225,7 @@ class PlatalPage extends Smarty global $platal; $this->assign('platal', $platal); - $this->trig($msg); + $this->trigError($msg); $this->_failure = true; $this->run(); } @@ -216,7 +253,7 @@ class PlatalPage extends Smarty { if (!empty($css)) { $this->append('xorg_inline_css', $css); - } + } } // }}} @@ -270,7 +307,7 @@ function escape_xorgDB(&$item, $key) /** * default smarty plugin, used to auto-escape dangerous html. - * + * * < --> < * > --> > * " --> " @@ -279,10 +316,9 @@ function escape_xorgDB(&$item, $key) function escape_html($string) { if (is_string($string)) { - $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); - return strtr($string, $transtbl); + return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); } else { - return $string; + return $string; } } @@ -326,7 +362,30 @@ function trimwhitespace($source, &$smarty) $source = preg_replace('/((?)\n)[\s]+/m', '\1', $source); $source = preg_replace("!&&&tags&&&!e", 'array_shift($tagsmatches[0])', $source); - return $source; + return $source; +} + +// }}} +// {{{ function wiki_include + +function wiki_include($source, &$smarty) +{ + return preg_replace('/\{include( [^}]*)? wiki=([^} ]+)(.*?)\}/ui', + '{include\1 file="../spool/wiki.d/cache_\2.tpl"\3 included=1}', + $source); +} + +// }}} +//{{{ function hasPerm + +function if_has_perms($source, &$smarty) +{ + $source = preg_replace('/\{if([^}]*) (\!?)hasPerms\(([^)]+)\)([^}]*)\}/', + '{if\1 \2$smarty.session.perms->hasFlagCombination(\3)\4}', + $source); + return preg_replace('/\{if([^}]*) (\!?)hasPerm\(([^)]+)\)([^}]*)\}/', + '{if\1 \2($smarty.session.perms && $smarty.session.perms->hasFlag(\3))\4}', + $source); } // }}} @@ -347,11 +406,15 @@ function _hide_email($source) $source = str_replace("\n", '', $source); return ''; + '//]]>'; } function hide_emails($source, &$smarty) { + if (!strpos($source, '@')) { + return $source; + } + //prevent email replacement in