| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: |
|
| 12: | class Smarty_Internal_Method_CompileAllTemplates
|
| 13: | {
|
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | public $objMap = 1;
|
| 20: |
|
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: |
|
| 34: | public function compileAllTemplates(
|
| 35: | Smarty $smarty,
|
| 36: | $extension = '.tpl',
|
| 37: | $force_compile = false,
|
| 38: | $time_limit = 0,
|
| 39: | $max_errors = null
|
| 40: | ) {
|
| 41: | return $this->compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors);
|
| 42: | }
|
| 43: |
|
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: |
|
| 56: | protected function compileAll(
|
| 57: | Smarty $smarty,
|
| 58: | $extension,
|
| 59: | $force_compile,
|
| 60: | $time_limit,
|
| 61: | $max_errors,
|
| 62: | $isConfig = false
|
| 63: | ) {
|
| 64: |
|
| 65: | if (function_exists('set_time_limit')) {
|
| 66: | @set_time_limit($time_limit);
|
| 67: | }
|
| 68: | $_count = 0;
|
| 69: | $_error_count = 0;
|
| 70: | $sourceDir = $isConfig ? $smarty->getConfigDir() : $smarty->getTemplateDir();
|
| 71: |
|
| 72: | foreach ($sourceDir as $_dir) {
|
| 73: | $_dir_1 = new RecursiveDirectoryIterator(
|
| 74: | $_dir,
|
| 75: | defined('FilesystemIterator::FOLLOW_SYMLINKS') ?
|
| 76: | FilesystemIterator::FOLLOW_SYMLINKS : 0
|
| 77: | );
|
| 78: | $_dir_2 = new RecursiveIteratorIterator($_dir_1);
|
| 79: | foreach ($_dir_2 as $_fileinfo) {
|
| 80: | $_file = $_fileinfo->getFilename();
|
| 81: | if (substr(basename($_fileinfo->getPathname()), 0, 1) === '.' || strpos($_file, '.svn') !== false) {
|
| 82: | continue;
|
| 83: | }
|
| 84: | if (substr_compare($_file, $extension, -strlen($extension)) !== 0) {
|
| 85: | continue;
|
| 86: | }
|
| 87: | if ($_fileinfo->getPath() !== substr($_dir, 0, -1)) {
|
| 88: | $_file = substr($_fileinfo->getPath(), strlen($_dir)) . DIRECTORY_SEPARATOR . $_file;
|
| 89: | }
|
| 90: | echo "\n<br>", $_dir, '---', $_file;
|
| 91: | flush();
|
| 92: | $_start_time = microtime(true);
|
| 93: | $_smarty = clone $smarty;
|
| 94: |
|
| 95: | $_smarty->_cache = array();
|
| 96: | $_smarty->ext = new Smarty_Internal_Extension_Handler();
|
| 97: | $_smarty->ext->objType = $_smarty->_objType;
|
| 98: | $_smarty->force_compile = $force_compile;
|
| 99: | try {
|
| 100: |
|
| 101: | $_tpl = new $smarty->template_class($_file, $_smarty);
|
| 102: | $_tpl->caching = Smarty::CACHING_OFF;
|
| 103: | $_tpl->source =
|
| 104: | $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl);
|
| 105: | if ($_tpl->mustCompile()) {
|
| 106: | $_tpl->compileTemplateSource();
|
| 107: | $_count++;
|
| 108: | echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
|
| 109: | flush();
|
| 110: | } else {
|
| 111: | echo ' is up to date';
|
| 112: | flush();
|
| 113: | }
|
| 114: | } catch (Exception $e) {
|
| 115: | echo "\n<br> ------>Error: ", $e->getMessage(), "<br><br>\n";
|
| 116: | $_error_count++;
|
| 117: | }
|
| 118: |
|
| 119: | unset($_tpl);
|
| 120: | $_smarty->_clearTemplateCache();
|
| 121: | if ($max_errors !== null && $_error_count === $max_errors) {
|
| 122: | echo "\n<br><br>too many errors\n";
|
| 123: | exit(1);
|
| 124: | }
|
| 125: | }
|
| 126: | }
|
| 127: | echo "\n<br>";
|
| 128: | return $_count;
|
| 129: | }
|
| 130: | }
|
| 131: | |