]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_compilealltemplates.php
Update composer.json
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_compilealltemplates.php
1 <?php
2
3 /**
4  * Smarty Method CompileAllTemplates
5  *
6  * Smarty::compileAllTemplates() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_CompileAllTemplates
13 {
14     /**
15      * Valid for Smarty object
16      *
17      * @var int
18      */
19     public $objMap = 1;
20
21     /**
22      * Compile all template files
23      *
24      * @api  Smarty::compileAllTemplates()
25      *
26      * @param \Smarty $smarty        passed smarty object
27      * @param  string $extension     file extension
28      * @param  bool   $force_compile force all to recompile
29      * @param  int    $time_limit
30      * @param  int    $max_errors
31      *
32      * @return integer number of template files recompiled
33      */
34     public function compileAllTemplates(Smarty $smarty, $extension = '.tpl', $force_compile = false, $time_limit = 0,
35                                         $max_errors = null)
36     {
37         return $this->compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors);
38     }
39
40     /**
41      * Compile all template or config files
42      *
43      * @param \Smarty $smarty
44      * @param  string $extension     template file name extension
45      * @param  bool   $force_compile force all to recompile
46      * @param  int    $time_limit    set maximum execution time
47      * @param  int    $max_errors    set maximum allowed errors
48      * @param bool    $isConfig      flag true if called for config files
49      *
50      * @return int number of template files compiled
51      */
52     protected function compileAll(Smarty $smarty, $extension, $force_compile, $time_limit, $max_errors,
53                                   $isConfig = false)
54     {
55         // switch off time limit
56         if (function_exists('set_time_limit')) {
57             @set_time_limit($time_limit);
58         }
59         $_count = 0;
60         $_error_count = 0;
61         $sourceDir = $isConfig ? $smarty->getConfigDir() : $smarty->getTemplateDir();
62         // loop over array of source directories
63         foreach ($sourceDir as $_dir) {
64             $_dir_1 = new RecursiveDirectoryIterator($_dir, defined('FilesystemIterator::FOLLOW_SYMLINKS') ?
65                 FilesystemIterator::FOLLOW_SYMLINKS : 0);
66             $_dir_2 = new RecursiveIteratorIterator($_dir_1);
67             foreach ($_dir_2 as $_fileinfo) {
68                 $_file = $_fileinfo->getFilename();
69                 if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
70                     continue;
71                 }
72                 if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
73                     continue;
74                 }
75                 if ($_fileinfo->getPath() !== substr($_dir, 0, - 1)) {
76                     $_file = substr($_fileinfo->getPath(), strlen($_dir)) . $smarty->ds . $_file;
77                 }
78                 echo "\n<br>", $_dir, '---', $_file;
79                 flush();
80                 $_start_time = microtime(true);
81                 $_smarty = clone $smarty;
82                 // 
83                 $_smarty->_cache = array();
84                 $_smarty->ext = new Smarty_Internal_Extension_Handler();
85                 $_smarty->ext->objType = $_smarty->_objType;
86                 $_smarty->force_compile = $force_compile;
87                 try {
88                     /* @var Smarty_Internal_Template $_tpl */
89                     $_tpl = new $smarty->template_class($_file, $_smarty);
90                     $_tpl->caching = Smarty::CACHING_OFF;
91                     $_tpl->source =
92                         $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl);
93                     if ($_tpl->mustCompile()) {
94                         $_tpl->compileTemplateSource();
95                         $_count ++;
96                         echo ' compiled in  ', microtime(true) - $_start_time, ' seconds';
97                         flush();
98                     } else {
99                         echo ' is up to date';
100                         flush();
101                     }
102                 }
103                 catch (Exception $e) {
104                     echo "\n<br>        ------>Error: ", $e->getMessage(), "<br><br>\n";
105                     $_error_count ++;
106                 }
107                 // free memory
108                 unset($_tpl);
109                 $_smarty->_clearTemplateCache();
110                 if ($max_errors !== null && $_error_count == $max_errors) {
111                     echo "\n<br><br>too many errors\n";
112                     exit();
113                 }
114             }
115         }
116         echo "\n<br>";
117         return $_count;
118     }
119 }