You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
4.0 KiB
PHTML
105 lines
4.0 KiB
PHTML
15 years ago
|
<?php
|
||
9 years ago
|
|
||
|
require_once(dirname(__FILE__) . '/smarty/libs/Autoloader.php');
|
||
|
Smarty_Autoloader::register();
|
||
15 years ago
|
|
||
15 years ago
|
/**
|
||
|
* Turn on sanitisation of all data by default so it's not possible for XSS flaws to occur in PFA
|
||
|
*/
|
||
14 years ago
|
class PFASmarty {
|
||
|
protected $template = null;
|
||
|
public function __construct() {
|
||
11 years ago
|
$this->template = new Smarty();
|
||
14 years ago
|
|
||
14 years ago
|
//$this->template->debugging = true;
|
||
7 years ago
|
$this->template->setTemplateDir(dirname(__FILE__) . '/../templates');
|
||
8 years ago
|
|
||
|
// if it's not present or writeable, smarty should just not cache.
|
||
7 years ago
|
$templates_c = dirname(__FILE__) . '/../templates_c';
|
||
7 years ago
|
if (is_dir($templates_c) && is_writeable($templates_c)) {
|
||
8 years ago
|
$this->template->setCompileDir($templates_c);
|
||
7 years ago
|
} else {
|
||
8 years ago
|
# unfortunately there's no sane way to just disable compiling of templates
|
||
7 years ago
|
clearstatcache(); // just incase someone just fixed it; on their next refresh it should work.
|
||
8 years ago
|
error_log("ERROR: directory $templates_c doesn't exist or isn't writeable for the webserver");
|
||
|
die("ERROR: the templates_c directory doesn't exist or isn't writeable for the webserver");
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
$this->template->setConfigDir(dirname(__FILE__) . '/../configs');
|
||
14 years ago
|
}
|
||
|
|
||
15 years ago
|
public function assign($key, $value, $sanitise = true) {
|
||
10 years ago
|
$this->template->assign("RAW_$key", $value);
|
||
7 years ago
|
if ($sanitise == false) {
|
||
14 years ago
|
return $this->template->assign($key, $value);
|
||
15 years ago
|
}
|
||
|
$clean = $this->sanitise($value);
|
||
|
/* we won't run the key through sanitise() here... some might argue we should */
|
||
14 years ago
|
return $this->template->assign($key, $clean);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
public function display($template) {
|
||
7 years ago
|
header("Expires: Sun, 16 Mar 2003 05:00:00 GMT");
|
||
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
||
|
header("Pragma: no-cache");
|
||
|
header("Content-Type: text/html; charset=UTF-8");
|
||
11 years ago
|
|
||
14 years ago
|
$this->template->display($template);
|
||
14 years ago
|
unset($_SESSION['flash']); # cleanup flash messages
|
||
14 years ago
|
}
|
||
15 years ago
|
/**
|
||
7 years ago
|
* Recursive cleaning of data, using htmlentities - this assumes we only ever output to HTML and we're outputting in UTF-8 charset
|
||
15 years ago
|
*
|
||
|
* @param mixed $data - array or primitive type; objects not supported.
|
||
|
* @return mixed $data
|
||
|
* */
|
||
|
public function sanitise($data) {
|
||
7 years ago
|
if (!is_array($data)) {
|
||
14 years ago
|
return htmlentities($data, ENT_QUOTES, 'UTF-8', false);
|
||
15 years ago
|
}
|
||
7 years ago
|
if (is_array($data)) {
|
||
15 years ago
|
$clean = array();
|
||
7 years ago
|
foreach ($data as $key => $value) {
|
||
15 years ago
|
/* as this is a nested data structure it's more likely we'll output the key too (at least in my opinion, so we'll sanitise it too */
|
||
|
$clean[$this->sanitise($key)] = $this->sanitise($value);
|
||
|
}
|
||
|
return $clean;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$smarty = new PFASmarty();
|
||
15 years ago
|
|
||
7 years ago
|
if (!isset($rel_path)) {
|
||
|
$rel_path = '';
|
||
|
} # users/* sets this to '../'
|
||
13 years ago
|
|
||
|
$CONF['theme_css'] = $rel_path . htmlentities($CONF['theme_css']);
|
||
7 years ago
|
if (!empty($CONF['theme_custom_css'])) {
|
||
|
$CONF['theme_custom_css'] = $rel_path . htmlentities($CONF['theme_custom_css']);
|
||
|
}
|
||
13 years ago
|
$CONF['theme_logo'] = $rel_path . htmlentities($CONF['theme_logo']);
|
||
15 years ago
|
|
||
7 years ago
|
$smarty->assign('CONF', $CONF);
|
||
|
$smarty->assign('PALANG', $PALANG);
|
||
14 years ago
|
$smarty->assign('url_domain', '');
|
||
15 years ago
|
//*** footer.tpl
|
||
7 years ago
|
$smarty->assign('version', $version);
|
||
15 years ago
|
|
||
|
//*** menu.tpl
|
||
7 years ago
|
$smarty->assign('boolconf_alias_domain', Config::bool('alias_domain'));
|
||
|
$smarty->assign('authentication_has_role', array('global_admin' => authentication_has_role('global-admin'), 'admin' => authentication_has_role('admin'), 'user' => authentication_has_role('user')));
|
||
15 years ago
|
|
||
7 years ago
|
function eval_size($aSize) {
|
||
|
if ($aSize == 0) {
|
||
|
$ret_val = Config::Lang('pOverview_unlimited');
|
||
|
} elseif ($aSize < 0) {
|
||
|
$ret_val = Config::Lang('pOverview_disabled');
|
||
|
} else {
|
||
|
$ret_val = $aSize;
|
||
|
}
|
||
|
return $ret_val;
|
||
15 years ago
|
}
|
||
14 years ago
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|