/framework/core/gui/GuiSmarty2.php

http://zoop.googlecode.com/ · PHP · 105 lines · 60 code · 19 blank · 26 comment · 3 complexity · d4a4737b259952f678b22039ba10a1e9 MD5 · raw file

  1. <?php
  2. /**
  3. * Object extends the Smarty templating system to allow easy separation of business and
  4. * presentation logic
  5. *
  6. */
  7. class GuiSmarty2 extends Smarty2
  8. {
  9. private $layout;
  10. function __construct()
  11. {
  12. $config = GuiModule::sGetConfig();
  13. $tmpPath = Zoop::getTmpDir();
  14. // call the parent contructor
  15. $this->Smarty();
  16. $this->template_dir = array();
  17. // set the default for the base template dir
  18. // this should be using the new config stuff, not defines
  19. if(!defined("gui_template_dir") )
  20. define("gui_template_dir", app_dir . "/templates");
  21. // set the standard template directory and any others registerd with zoop
  22. $this->addTemplateDir(gui_template_dir);
  23. // set the compile directory
  24. $modTmpDir = $tmpPath . '/smarty2';
  25. if(!is_dir($modTmpDir))
  26. mkdir($modTmpDir);
  27. $this->setCompileDir($modTmpDir);
  28. // set the cache_dir directory
  29. // what does this even do? I'm pretty sure that is not set up
  30. $this->setCacheDir($tmpPath . "/guicache");
  31. // set the config directory
  32. // what does this even do? I'm pretty sure that is not set up
  33. $this->setConfigDir(app_dir . "/guiconfig");
  34. // set the plugin directories
  35. $this->addPluginDir(zoop_dir . '/vendor/smarty2/plugins'); // one for plugins added into gui
  36. $this->addPluginDir(app_dir . "/guiplugins"); // one or plugins specific to the app
  37. // we shouldn't use the blanket app_status define any more, we should use specific varabiles
  38. // for each behavior, and it should use the new config system
  39. // $smarty->debugging = defined('app_status') && app_status == 'dev' ? true : false;
  40. // $smarty->compile_check = defined('app_status') && app_status == 'dev' ? true : false;
  41. // we want to run this filter on every single smarty script that we execute
  42. // it finds all places where we echo out a simple variable and escapes the html
  43. //
  44. // unfortunately this filters everything. The entire contents if the template. I think it is escaping include.
  45. // If we can get it to not do that then we can put this back in.
  46. //
  47. //$this->autoload_filters = array('pre' => array("strip_html"));
  48. }
  49. function setTemplateDir($inDir)
  50. {
  51. $this->template_dir = $inDir;
  52. }
  53. function addTemplateDir($inDir)
  54. {
  55. $this->template_dir[] = $inDir;
  56. }
  57. function setCompileDir($inDir)
  58. {
  59. $this->compile_dir = $inDir;
  60. }
  61. function setCacheDir($inDir)
  62. {
  63. $this->cache_dir = $inDir;
  64. }
  65. function setConfigDir($inDir)
  66. {
  67. $this->config_dir = $inDir;
  68. }
  69. function addPluginDir($inDir)
  70. {
  71. $this->plugins_dir[] = $inDir;
  72. }
  73. public function setLayout($layout)
  74. {
  75. $this->layout = $layout;
  76. }
  77. function fetch($tpl_file, $cache_id = null, $compile_id = null, $display = false)
  78. {
  79. if($this->layout)
  80. {
  81. $this->assign("TEMPLATE_CONTENT", $tpl_file);
  82. return parent::fetch("layouts/{$this->layout}.tpl", $cache_id, $compile_id, $display);
  83. }
  84. return parent::fetch($tpl_file, $cache_id, $compile_id, $display);
  85. }
  86. }