/**
  * Compile all template or config files
  *
  * @param \Smarty $smarty
  * @param  string $extension     template file name extension
  * @param  bool   $force_compile force all to recompile
  * @param  int    $time_limit    set maximum execution time
  * @param  int    $max_errors    set maximum allowed errors
  * @param bool    $isConfig      flag true if called for config files
  *
  * @return int number of template files compiled
  */
 protected function compileAll(Smarty $smarty, $extension, $force_compile, $time_limit, $max_errors, $isConfig = false)
 {
     // switch off time limit
     if (function_exists('set_time_limit')) {
         @set_time_limit($time_limit);
     }
     $_count = 0;
     $_error_count = 0;
     $sourceDir = $isConfig ? $smarty->getConfigDir() : $smarty->getTemplateDir();
     // loop over array of source directories
     foreach ($sourceDir as $_dir) {
         $_dir_1 = new RecursiveDirectoryIterator($_dir);
         $_dir_2 = new RecursiveIteratorIterator($_dir_1);
         foreach ($_dir_2 as $_fileinfo) {
             $_file = $_fileinfo->getFilename();
             if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
                 continue;
             }
             if (!substr_compare($_file, $extension, -strlen($extension)) == 0) {
                 continue;
             }
             if ($_fileinfo->getPath() !== substr($_dir, 0, -1)) {
                 $_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
             }
             echo "\n<br>", $_dir, '---', $_file;
             flush();
             $_start_time = microtime(true);
             $_smarty = clone $smarty;
             $_smarty->force_compile = $force_compile;
             try {
                 /* @var Smarty_Internal_Template $_tpl */
                 $_tpl = new $smarty->template_class($_file, $_smarty);
                 $_tpl->caching = Smarty::CACHING_OFF;
                 $_tpl->source = $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl);
                 if ($_tpl->mustCompile()) {
                     $_tpl->compileTemplateSource();
                     $_count++;
                     echo ' compiled in  ', microtime(true) - $_start_time, ' seconds';
                     flush();
                 } else {
                     echo ' is up to date';
                     flush();
                 }
             } catch (Exception $e) {
                 echo "\n<br>        ------>Error: ", $e->getMessage(), "<br><br>\n";
                 $_error_count++;
             }
             // free memory
             unset($_tpl);
             $_smarty->_clearTemplateCache();
             if ($max_errors !== null && $_error_count == $max_errors) {
                 echo "\n<br><br>too many errors\n";
                 exit;
             }
         }
     }
     echo "\n<br>";
     return $_count;
 }
 /**
  * load a config file, optionally load just selected sections
  *
  * @api  Smarty::configLoad()
  * @link http://www.smarty.net/docs/en/api.config.load.tpl
  *
  * @param \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template $data
  * @param  string                                                 $config_file filename
  * @param  mixed                                                  $sections    array of section names, single
  *                                                                             section or null
  * @param int                                                     $scope       scope into which config variables
  *                                                                             shall be loaded
  *
  * @return \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template
  * @throws \SmartyException
  */
 public function _loadConfigFile(Smarty_Internal_Data $data, $config_file, $sections = null, $scope = 0)
 {
     /* @var \Smarty $smarty */
     $smarty = isset($data->smarty) ? $data->smarty : $data;
     /* @var \Smarty_Internal_Template $confObj */
     $confObj = new Smarty_Internal_Template($config_file, $smarty, $data);
     $confObj->caching = Smarty::CACHING_OFF;
     $confObj->source = Smarty_Template_Config::load($confObj);
     $confObj->source->config_sections = $sections;
     $confObj->source->scope = $scope;
     $confObj->compiled = Smarty_Template_Compiled::load($confObj);
     $confObj->compiled->render($confObj);
     if ($data->_objType == 2) {
         $data->compiled->file_dependency[$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
     }
 }
 /**
  * @param        $obj
  * @param        $config_file
  * @param null   $sections
  * @param string $scope
  */
 static function configLoad($obj, $config_file, $sections = null, $scope = 'local')
 {
     $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
     $confObj = new $smarty->template_class($config_file, $smarty, $obj);
     $confObj->caching = Smarty::CACHING_OFF;
     $confObj->source = Smarty_Template_Config::load($confObj);
     $confObj->source->config_sections = $sections;
     $confObj->source->scope = $scope;
     $confObj->compiled = Smarty_Template_Compiled::load($confObj);
     if ($confObj->smarty->debugging) {
         Smarty_Internal_Debug::start_render($confObj);
     }
     $confObj->compiled->render($confObj);
     if ($confObj->smarty->debugging) {
         Smarty_Internal_Debug::end_render($confObj);
     }
     if ($obj instanceof Smarty_Internal_Template) {
         $obj->properties['file_dependency'][$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->timestamp, $confObj->source->type);
     }
 }
 /**
  * @param                         $obj
  * @param                         $config_file
  * @param null                    $sections
  * @param string                  $scope
  *
  * @throws \SmartyException
  */
 static function configLoad($obj, $config_file, $sections = null, $scope = 'local')
 {
     $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
     $confObj = new $smarty->template_class($config_file, $smarty, $obj);
     $confObj->context = new Smarty_Internal_Context();
     $confObj->caching = Smarty::CACHING_OFF;
     $confObj->source = Smarty_Template_Config::load($confObj);
     $confObj->source->config_sections = $sections;
     $confObj->source->scope = $scope;
     $confObj->compiled = Smarty_Template_Compiled::load($confObj);
     if ($confObj->smarty->debugging) {
         Smarty_Internal_Debug::start_render($confObj);
     }
     $confObj->compiled->render($confObj);
     $confObj->context = null;
     if ($confObj->smarty->debugging) {
         Smarty_Internal_Debug::end_render($confObj);
     }
     if ($obj instanceof Smarty_Internal_Template && isset($obj->context)) {
         $obj->context->resourceInfo[$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->timestamp, $confObj->source->type);
     } else {
         // TODO   config file dependency if loaded in Smarty, Data or Template object
     }
 }
예제 #5
0
 /**
  * Create template data object
  * Some of the global Smarty settings copied to template scope
  * It load the required template resources and caching plugins
  *
  * @param string                                                       $template_resource template resource string
  * @param Smarty                                                       $smarty            Smarty instance
  * @param null|\Smarty_Internal_Template|\Smarty|\Smarty_Internal_Data $_parent           back pointer to parent object
  *                                                                                        with variables or null
  * @param mixed                                                        $_cache_id         cache   id or null
  * @param mixed                                                        $_compile_id       compile id or null
  * @param bool|int|null                                                $_caching          use caching?
  * @param int|null                                                     $_cache_lifetime   cache life-time in seconds
  * @param bool                                                         $_isConfig
  *
  * @throws \SmartyException
  */
 public function __construct($template_resource, Smarty $smarty, Smarty_Internal_Data $_parent = null, $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null, $_isConfig = false)
 {
     $this->smarty = $smarty;
     // Smarty parameter
     $this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
     $this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
     $this->caching = $_caching === null ? $this->smarty->caching : $_caching;
     if ($this->caching === true) {
         $this->caching = Smarty::CACHING_LIFETIME_CURRENT;
     }
     $this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
     $this->parent = $_parent;
     // Template resource
     $this->template_resource = $template_resource;
     $this->source = $_isConfig ? Smarty_Template_Config::load($this) : Smarty_Template_Source::load($this);
     parent::__construct();
     if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) {
         $smarty->security_policy->registerCallBacks($this);
     }
 }
 /**
  * Compile all config files
  *
  * @param  string $extension     config file name extension
  * @param  bool   $force_compile force all to recompile
  * @param  int    $time_limit    set maximum execution time
  * @param  int    $max_errors    set maximum allowed errors
  * @param  Smarty $smarty        Smarty instance
  *
  * @return integer number of config files compiled
  */
 public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
 {
     // switch off time limit
     if (function_exists('set_time_limit')) {
         @set_time_limit($time_limit);
     }
     $smarty->force_compile = $force_compile;
     $_count = 0;
     $_error_count = 0;
     // loop over array of template directories
     foreach ($smarty->getConfigDir() as $_dir) {
         $_compileDirs = new RecursiveDirectoryIterator($_dir);
         $_compile = new RecursiveIteratorIterator($_compileDirs);
         foreach ($_compile as $_fileinfo) {
             $_file = $_fileinfo->getFilename();
             if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
                 continue;
             }
             if (!substr_compare($_file, $extension, -strlen($extension)) == 0) {
                 continue;
             }
             if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
                 $_config_file = $_file;
             } else {
                 $_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
             }
             echo '<br>', $_dir, '---', $_config_file;
             flush();
             $_start_time = microtime(true);
             try {
                 $confObj = new $smarty->template_class($_config_file, $smarty);
                 $confObj->caching = Smarty::CACHING_OFF;
                 $confObj->source = Smarty_Template_Config::load($confObj);
                 if ($confObj->mustCompile()) {
                     $confObj->compileTemplateSource();
                     $_count++;
                     echo ' compiled in  ', microtime(true) - $_start_time, ' seconds';
                     flush();
                 } else {
                     echo ' is up to date';
                     flush();
                 }
             } catch (Exception $e) {
                 echo 'Error: ', $e->getMessage(), "<br><br>";
                 $_error_count++;
             }
             if ($max_errors !== null && $_error_count == $max_errors) {
                 echo '<br><br>too many errors';
                 exit;
             }
         }
     }
     return $_count;
 }