You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty.inc.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. require_once(dirname(__FILE__) . '/smarty/libs/Autoloader.php');
  3. Smarty_Autoloader::register();
  4. /**
  5. * Turn on sanitisation of all data by default so it's not possible for XSS flaws to occur in PFA
  6. */
  7. class PFASmarty {
  8. protected $template = null;
  9. public function __construct() {
  10. $this->template = new Smarty();
  11. //$this->template->debugging = true;
  12. $this->template->setTemplateDir(dirname(__FILE__) . '/../templates');
  13. // if it's not present or writeable, smarty should just not cache.
  14. $templates_c = dirname(__FILE__) . '/../templates_c';
  15. if (is_dir($templates_c) && is_writeable($templates_c)) {
  16. $this->template->setCompileDir($templates_c);
  17. } else {
  18. # unfortunately there's no sane way to just disable compiling of templates
  19. clearstatcache(); // just incase someone just fixed it; on their next refresh it should work.
  20. error_log("ERROR: directory $templates_c doesn't exist or isn't writeable for the webserver");
  21. die("ERROR: the templates_c directory doesn't exist or isn't writeable for the webserver");
  22. }
  23. $this->template->setConfigDir(dirname(__FILE__) . '/../configs');
  24. }
  25. public function assign($key, $value, $sanitise = true) {
  26. $this->template->assign("RAW_$key", $value);
  27. if ($sanitise == false) {
  28. return $this->template->assign($key, $value);
  29. }
  30. $clean = $this->sanitise($value);
  31. /* we won't run the key through sanitise() here... some might argue we should */
  32. return $this->template->assign($key, $clean);
  33. }
  34. public function display($template) {
  35. header("Expires: Sun, 16 Mar 2003 05:00:00 GMT");
  36. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  37. header("Cache-Control: no-store, no-cache, must-revalidate");
  38. header("Cache-Control: post-check=0, pre-check=0", false);
  39. header("Pragma: no-cache");
  40. header("Content-Type: text/html; charset=UTF-8");
  41. $this->template->display($template);
  42. unset($_SESSION['flash']); # cleanup flash messages
  43. }
  44. /**
  45. * Recursive cleaning of data, using htmlentities - this assumes we only ever output to HTML and we're outputting in UTF-8 charset
  46. *
  47. * @param mixed $data - array or primitive type; objects not supported.
  48. * @return mixed $data
  49. * */
  50. public function sanitise($data) {
  51. if (!is_array($data)) {
  52. return htmlentities($data, ENT_QUOTES, 'UTF-8', false);
  53. }
  54. if (is_array($data)) {
  55. $clean = array();
  56. foreach ($data as $key => $value) {
  57. /* 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 */
  58. $clean[$this->sanitise($key)] = $this->sanitise($value);
  59. }
  60. return $clean;
  61. }
  62. }
  63. }
  64. $smarty = new PFASmarty();
  65. if (!isset($rel_path)) {
  66. $rel_path = '';
  67. } # users/* sets this to '../'
  68. $CONF['theme_css'] = $rel_path . htmlentities($CONF['theme_css']);
  69. if (!empty($CONF['theme_custom_css'])) {
  70. $CONF['theme_custom_css'] = $rel_path . htmlentities($CONF['theme_custom_css']);
  71. }
  72. $CONF['theme_logo'] = $rel_path . htmlentities($CONF['theme_logo']);
  73. $smarty->assign('CONF', $CONF);
  74. $smarty->assign('PALANG', $PALANG);
  75. $smarty->assign('url_domain', '');
  76. //*** footer.tpl
  77. $smarty->assign('version', $version);
  78. //*** menu.tpl
  79. $smarty->assign('boolconf_alias_domain', Config::bool('alias_domain'));
  80. $smarty->assign('authentication_has_role', array('global_admin' => authentication_has_role('global-admin'), 'admin' => authentication_has_role('admin'), 'user' => authentication_has_role('user')));
  81. function eval_size($aSize) {
  82. if ($aSize == 0) {
  83. $ret_val = Config::Lang('pOverview_unlimited');
  84. } elseif ($aSize < 0) {
  85. $ret_val = Config::Lang('pOverview_disabled');
  86. } else {
  87. $ret_val = $aSize;
  88. }
  89. return $ret_val;
  90. }
  91. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */