X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplatalpage.php;h=e3cf01f3c518d0d4179e42c4d31a4c1e99f1b078;hb=5b21237dd71df96849421c33d87298f15709d0d9;hp=0fe8ec6411af16d98b01bf50bc36e704485c4f48;hpb=abe7e055f16e6f6e9605c2965164169babbf9b7f;p=platal.git diff --git a/classes/platalpage.php b/classes/platalpage.php index 0fe8ec6..e3cf01f 100644 --- a/classes/platalpage.php +++ b/classes/platalpage.php @@ -27,6 +27,7 @@ class PlatalPage extends Smarty private $_tpl; private $_errors; private $_failure; + private $_jsonVars; // {{{ function PlatalPage() @@ -49,12 +50,10 @@ 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'); } // }}} @@ -68,6 +67,16 @@ class PlatalPage extends Smarty } // }}} + // {{{ function raw() + + public function raw() + { + global $globals; + $this->assign('globals', $globals); + return $this->fetch($this->_tpl); + } + + // }}} // {{{ function _run() protected function _run($skin) @@ -76,10 +85,17 @@ class PlatalPage extends Smarty 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') { @@ -104,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); @@ -209,6 +228,40 @@ 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 () @@ -224,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};)/u", "&", strtr(pl_entities($string), $transtbl)); + $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); + return strtr($string, $transtbl); } else { - return $string; + return $string; } }