X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplatalpage.php;h=e3cf01f3c518d0d4179e42c4d31a4c1e99f1b078;hb=5b21237dd71df96849421c33d87298f15709d0d9;hp=eac986a03530661319c36e3c3866960c3058b42f;hpb=9b2e77ded6d273098cd207588fccd85240c96d55;p=platal.git diff --git a/classes/platalpage.php b/classes/platalpage.php index eac986a..e3cf01f 100644 --- a/classes/platalpage.php +++ b/classes/platalpage.php @@ -23,24 +23,23 @@ require_once 'smarty/libs/Smarty.class.php'; class PlatalPage extends Smarty { - var $_page_type; - var $_tpl; - var $_errors; - var $_failure; - - // defaults - var $caching = false; - var $config_overwrite = false; - var $use_sub_dirs = false; + private $_page_type; + private $_tpl; + private $_errors; + private $_failure; + private $_jsonVars; // {{{ function PlatalPage() - function PlatalPage($tpl, $type = SKINNED) + public function __construct($tpl, $type = SKINNED) { - global $globals; + parent::Smarty(); - $this->Smarty(); + global $globals; + $this->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."/plugins/"); @@ -51,18 +50,16 @@ class PlatalPage extends Smarty $this->_page_type = $type; $this->_tpl = $tpl; $this->_errors = array(); + $this->_jsonVars = array(); $this->_failure = false; $this->register_prefilter('at_to_globals'); - $this->register_prefilter('trimwhitespace'); - $this->register_prefilter('form_force_encodings'); - $this->addJsLink('xorg.js'); } // }}} // {{{ function changeTpl() - function changeTpl($tpl, $type = SKINNED) + public function changeTpl($tpl, $type = SKINNED) { $this->_tpl = $tpl; $this->_page_type = $type; @@ -70,18 +67,35 @@ class PlatalPage extends Smarty } // }}} + // {{{ function raw() + + public function raw() + { + global $globals; + $this->assign('globals', $globals); + return $this->fetch($this->_tpl); + } + + // }}} // {{{ function _run() - function _run($skin) + protected function _run($skin) { global $globals, $TIME_BEGIN; session_write_close(); + $this->register_prefilter('trimwhitespace'); + $this->register_prefilter('form_force_encodings'); + $this->addJsLink('xorg.js'); $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') { @@ -106,6 +120,9 @@ class PlatalPage extends Smarty $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); @@ -150,7 +167,7 @@ class PlatalPage extends Smarty // }}} // {{{ function nb_errs() - function nb_errs() + public function nb_errs() { return count($this->_errors); } @@ -158,7 +175,7 @@ class PlatalPage extends Smarty // }}} // {{{ function trig() - function trig($msg) + public function trig($msg) { $this->_errors[] = $msg; } @@ -166,7 +183,7 @@ class PlatalPage extends Smarty // }}} // {{{ function kill() - function kill($msg) + public function kill($msg) { global $platal; @@ -179,7 +196,7 @@ class PlatalPage extends Smarty // }}} // {{{ function addJsLink - function addJsLink($path) + public function addJsLink($path) { $this->append('xorg_js', $path); } @@ -187,7 +204,7 @@ class PlatalPage extends Smarty // }}} // {{{ function addCssLink - function addCssLink($path) + public function addCssLink($path) { $this->append('xorg_css', $path); } @@ -195,7 +212,7 @@ class PlatalPage extends Smarty // }}} // {{{ function addCssInline - function addCssInline($css) + public function addCssInline($css) { if (!empty($css)) { $this->append('xorg_inline_css', $css); @@ -205,12 +222,46 @@ class PlatalPage extends Smarty // }}} // {{{ function setRssLink - function setRssLink($title, $path) + public function setRssLink($title, $path) { $this->assign('xorg_rss', array('title' => $title, 'href' => $path)); } // }}} + // {{{ 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 () @@ -226,10 +277,10 @@ class PlatalPage extends Smarty function escape_html($string) { if (is_string($string)) { - $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); - return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl)); + $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); + return strtr($string, $transtbl); } else { - return $string; + return $string; } } @@ -265,8 +316,8 @@ function at_to_globals($tpl_source, &$smarty) function trimwhitespace($source, &$smarty) { $tags = '(script|pre|textarea)'; - preg_match_all("!<$tags.*?>.*?!ius", $source, $tagsmatches); - $source = preg_replace("!<$tags.*?>.*?!ius", "&&&tags&&&", $source); + preg_match_all("!<$tags.*?>.*?!ius", $source, $tagsmatches); + $source = preg_replace("!<$tags.*?>.*?!ius", "&&&tags&&&", $source); // remove all leading spaces, tabs and carriage returns NOT // preceeded by a php close tag. @@ -301,19 +352,19 @@ function hide_emails($source, &$smarty) { //prevent email replacement in