require_once 'smarty/libs/Smarty.class.php';
-class PlatalPage extends Smarty
+abstract class PlatalPage extends Smarty
{
private $_page_type;
private $_tpl;
private $_errors;
private $_failure;
+ private $_jsonVars;
// {{{ function PlatalPage()
$this->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;
$this->register_prefilter('at_to_globals');
- $this->register_prefilter('trimwhitespace');
- $this->register_prefilter('form_force_encodings');
$this->addJsLink('xorg.js');
}
}
// }}}
+ // {{{ function raw()
+
+ public function raw()
+ {
+ global $globals;
+ $this->assign('globals', $globals);
+ return $this->fetch($this->_tpl);
+ }
+
+ // }}}
// {{{ function _run()
protected function _run($skin)
session_write_close();
+ $this->register_prefilter('trimwhitespace');
+ $this->register_prefilter('form_force_encodings');
$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') {
$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);
exit;
}
+ abstract public function run();
+
// }}}
// {{{ function nb_errs()
}
// }}}
+ // {{{ 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 ()
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;
}
}