X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplatalpage.php;h=f3661d72c8ad0f59323084e92b0c496de8f37a6c;hb=30c895bee78befef50a6b99a585b5cec52cc0ede;hp=1dd77ca085ee018774716cdc8f989e452d025c2e;hpb=e654517d5e6106ae4056ff4068437358a68f7268;p=platal.git diff --git a/classes/platalpage.php b/classes/platalpage.php index 1dd77ca..f3661d7 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->changeTpl($tpl, $type); $this->_errors = array(); + $this->_jsonVars = array(); $this->_failure = false; + if ($globals->mode != 'rw') { + $this->_errors[] = "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'); } // }}} @@ -59,9 +65,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); } // }}} @@ -85,11 +91,16 @@ class PlatalPage extends Smarty $this->register_prefilter('trimwhitespace'); $this->register_prefilter('form_force_encodings'); - $this->addJsLink('xorg.js'); + $this->register_prefilter('wiki_include'); + $this->register_prefilter('if_has_perms'); $this->assign('xorg_errors', $this->_errors); $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') { @@ -100,7 +111,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; @@ -108,12 +121,17 @@ 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')) { + header("Content-Type: text/xml; charset=utf-8"); + } if (!$globals->debug) { error_reporting(0); @@ -121,19 +139,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); @@ -155,6 +179,8 @@ class PlatalPage extends Smarty exit; } + abstract public function run(); + // }}} // {{{ function nb_errs() @@ -207,7 +233,7 @@ class PlatalPage extends Smarty { if (!empty($css)) { $this->append('xorg_inline_css', $css); - } + } } // }}} @@ -219,13 +245,49 @@ class PlatalPage extends Smarty } // }}} + // {{{ function jsonDisplay + protected function jsonDisplay() + { + header("Content-type: text/javascript; charset=utf-8"); + 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 (is_a($item, 'XOrgDBIterator')) { + $expanded = array(); + while ($a = $item->next()) { + $expanded[] = $a; + } + $item = $expanded; + } } // {{{ function escape_html () /** * default smarty plugin, used to auto-escape dangerous html. - * + * * < --> < * > --> > * " --> " @@ -234,10 +296,9 @@ class PlatalPage extends Smarty 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; } } @@ -281,7 +342,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); } // }}} @@ -302,11 +386,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