Example #1
0
 /**
  * Constructor
  * 
  * @param string $tpl_name, Name of Template for rendering
  */
 public function __construct($tpl_name)
 {
     $this->tpl_driver_class = Config::get('env.tplclass', 'Smarty');
     $this->tpl_postfix = Config::get('env.tplpostfix', '.htm');
     $this->tpl_name = $this->tpl_realpath($tpl_name);
     $this->modroot = SimPHP::$gConfig['modroot'];
     $tpl_config = array('caching' => Config::get('env.tplcache', 0), 'cache_lifetime' => Config::get('env.tplcache_expires', 300), 'compile_check' => Config::get('env.tplcompile_check', 1), 'force_compile' => Config::get('env.tplforce_compile', 0), 'debugging' => Config::get('env.tpldebug', 0));
     $tpldir = Config::get('env.sitetheme', 'default');
     if ($this->modroot != 'modules') {
         $tpldir = $this->modroot;
     }
     $template_dir = SIMPHP_ROOT . "/themes/{$tpldir}";
     $compiled_dir = SIMPHP_ROOT . Config::get('env.tplcachedir') . "/{$tpldir}/compiled";
     $cached_dir = SIMPHP_ROOT . Config::get('env.tplcachedir') . "/{$tpldir}/cached";
     $tpl_config['template_dir'] = $template_dir;
     $tpl_config['compile_dir'] = $compiled_dir;
     $tpl_config['cache_dir'] = $cached_dir;
     try {
         if (!is_dir($compiled_dir) && !mkdirs($compiled_dir) && !is_writable($compiled_dir)) {
             throw new DirWritableException($compiled_dir);
         }
         if (Config::get('env.tplcache') && !is_dir($cached_dir) && !mkdirs($cached_dir) && !is_writable($cached_dir)) {
             throw new DirWritableException($cached_dir);
         }
     } catch (DirWritableException $e) {
         trigger_error($e->getMessage(), E_USER_ERROR);
     }
     $this->tpl = Template::I(array('driverClass' => $this->tpl_driver_class, 'driverConfig' => $tpl_config));
     $this->assign('contextpath', Config::get('env.contextpath', '/'));
     $this->assign_by_ref('user', $GLOBALS['user']);
     //add default output filter
     $this->add_output_filter(array($this, 'filter_output'));
 }