Пример #1
0
 public function fetch($filename, $cacheId = null, $compileId = null, $display = false)
 {
     $this->setCacheDir($this->cache_dir);
     $this->setCompileDir($this->compile_dir);
     if ($this->security) {
         $policy = new Policy();
         $policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS']));
         $phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling;
         if ($this->security_settings['PHP_TAGS']) {
             $phpTags = SMARTY_PHP_ALLOW;
         }
         switch ($phpTags) {
             case SMARTY_PHP_ALLOW:
             case SMARTY_PHP_PASSTHRU:
                 $phpTags = Policy::PHP_ALLOW;
                 break;
             case SMARTY_PHP_QUOTE:
                 $phpTags = Policy::PHP_ENCODE;
                 break;
             case SMARTY_PHP_REMOVE:
             default:
                 $phpTags = Policy::PHP_REMOVE;
                 break;
         }
         $policy->setPhpHandling($phpTags);
         $policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']);
         if ($this->security_settings['INCLUDE_ANY']) {
             $policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__));
         } else {
             $policy->allowDirectory($this->secure_dir);
         }
         $this->setSecurityPolicy($policy);
     }
     if (!empty($this->plugins_dir)) {
         foreach ($this->plugins_dir as $dir) {
             $this->getLoader()->addDirectory(rtrim($dir, '\\/'));
         }
     }
     $tpl = $this->makeTemplate($filename, $cacheId, $compileId);
     if ($this->force_compile) {
         $tpl->forceCompilation();
     }
     if ($this->caching > 0) {
         $this->cacheTime = $this->cache_lifetime;
     } else {
         $this->cacheTime = 0;
     }
     if ($this->compiler_class !== null) {
         if ($this->compiler_file !== null && !class_exists($this->compiler_class)) {
             include $this->compiler_file;
         }
         $this->compiler = new $this->compiler_class();
     } else {
         $this->compiler->addPreProcessor('smarty_compat', true);
         $this->compiler->setLooseOpeningHandling(true);
     }
     $this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
     return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true);
 }