@@ -99,9 +99,11 @@ public function __construct($template, &$data, &$owner = '')
9999
100100 if (strpos ($ res , '{# ' )) {
101101 //second pass
102+ startMeasure ('secondpass ' );
102103 $ res = str_replace ('{# ' , '[# ' , $ res );
103104 $ res = str_replace ('#} ' , '#] ' , $ res );
104105 $ res = $ this ->parse ($ res , $ this ->data , $ root );
106+ endMeasure ('secondpass ' );
105107 }
106108
107109 if (isset ($ this ->ajax ) && $ this ->ajax ) {
@@ -158,30 +160,40 @@ public function parse($res, &$hash, $dir)
158160
159161 // ARRAYS
160162 if (is_integer (strpos ($ res , '[#begin ' ))) {
163+ //startMeasure('parsingArrays'.$this->template);
161164 $ this ->parseArrays ($ res , $ hash , $ dir );
165+ //endMeasure('parsingArrays'.$this->template);
162166 }
163167
164168 // HASHES
165169 $ this ->parseHashes ($ res , $ hash );
166170
167171 // CONDITIONS
168172 if (is_integer (strpos ($ res , '[#if ' ))) {
173+ //startMeasure('parsingIfs'.$this->template);
169174 $ this ->parseIf ($ res , $ hash );
175+ //endMeasure('parsingIfs'.$this->template);
170176 }
171177
172178 // MODULES
173179 if (is_integer (strpos ($ res , '[#module ' ))) {
180+ //startMeasure('parsingModules'.$this->template);
174181 $ this ->parseModules ($ res , $ hash , $ dir );
182+ //endMeasure('parsingModules'.$this->template);
175183 }
176184
177185 // INCLUDE FILES
178186 if (is_integer (strpos ($ res , '[#inc ' ))) {
187+ //startMeasure('parsingIncludes'.$this->template);
179188 $ this ->parseIncludes ($ res , $ hash , $ dir );
189+ //endMeasure('parsingIncludes'.$this->template);
180190 }
181191
182192 // VARIABLES
183193 if (is_integer (strpos ($ res , '[# ' ))) {
194+ //startMeasure('parsingVariables'.$this->template);
184195 $ this ->parseVariables ($ res , $ hash );
196+ //endMeasure('parsingVariables'.$this->template);
185197 }
186198
187199 return $ res ;
@@ -332,7 +344,7 @@ public function parseGlobals(&$res, &$hash)
332344 if (defined ($ matches [1 ][$ i ])) {
333345 $ res = str_replace ($ matches [0 ][$ i ], constant ($ matches [1 ][$ i ]), $ res );
334346 } else {
335- if (!isset ($ hash [$ matches [1 ][$ i ]])) $ hash [$ matches [1 ][$ i ]]= null ;
347+ if (!isset ($ hash [$ matches [1 ][$ i ]])) $ hash [$ matches [1 ][$ i ]] = null ;
336348 $ res = str_replace ($ matches [0 ][$ i ], $ hash [$ matches [1 ][$ i ]], $ res );
337349 }
338350 }
@@ -355,7 +367,7 @@ public function parseArrays(&$res, &$hash, $dir)
355367 $ count_matches_0 = count ($ matches [0 ]);
356368
357369 for ($ i = 0 ; $ i < $ count_matches_0 ; $ i ++) {
358- if (!isset ($ hash [$ matches [1 ][$ i ]])) $ hash [$ matches [1 ][$ i ]]= null ;
370+ if (!isset ($ hash [$ matches [1 ][$ i ]])) $ hash [$ matches [1 ][$ i ]] = null ;
359371 $ var = $ hash [$ matches [1 ][$ i ]];
360372 $ line1 = $ matches [2 ][$ i ];
361373 $ res1 = "" ;
@@ -456,7 +468,7 @@ public function parseHashes(&$res, &$hash)
456468 if (preg_match_all ('/<#(\w+?)\.(\w+?)#>/ ' , $ res , $ matches , PREG_PATTERN_ORDER )) {
457469 $ count_matches_1 = count ($ matches [1 ]);
458470 for ($ i = 0 ; $ i < $ count_matches_1 ; $ i ++) {
459- if (!isset ($ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]])) $ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]]= null ;
471+ if (!isset ($ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]])) $ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]] = null ;
460472 $ res = str_replace ($ matches [0 ][$ i ], $ this ->templateSafe ($ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]]), $ res );
461473 }
462474 }
@@ -724,19 +736,43 @@ public function parseIncludes(&$res, &$hash, $dir)
724736 if (!file_exists ($ file_name )) {
725737 $ res = str_replace ($ matches [0 ][$ i ], "<!-- Cannot find file $ file_name --> " , $ res );
726738 } else {
739+ startMeasure ('including ' .$ file_name );
740+ $ old_template = $ this ->template ;
741+ $ this ->template = $ file_name ;
742+
727743 if ((defined ("DEBUG_MODE " )) && !is_integer (strpos ($ file_name , ".js " ))) {
728744 $ id = "block " . (int )rand (0 , 100000 );
729-
730745 /*
731746 $replaceStr = "<!-- begin of file $file_name -->";
732747 $replaceStr .= $this->parse($this->loadfile($file_name) . "<!-- end of file $file_name -->", $new_hash, $new_root);
733748 $res = str_replace($matches[0][$i], $replaceStr, $res);
734749 */
735-
736- $ res = str_replace ($ matches [0 ][$ i ], "" . $ this ->parse ($ this ->loadfile ($ file_name ) . "" , $ new_hash , $ new_root ), $ res );
750+ if (preg_match ('/\.tpl$/ ' , $ file_name )) {
751+ require_once ROOT . 'lib/smarty/Smarty.class.php ' ;
752+ $ smarty = new Smarty ;
753+ $ smarty ->setCacheDir (ROOT . 'cms/cached/template_c ' );
754+ $ smarty ->setTemplateDir (ROOT . './templates ' )
755+ ->setCompileDir (ROOT . './cms/cached/templates_c ' )
756+ ->setCacheDir (ROOT . './cms/cached ' );
757+ $ smarty ->debugging = false ;
758+ $ smarty ->caching = true ;
759+ $ smarty ->setCaching (120 );
760+ foreach ($ new_hash as $ k => $ v ) {
761+ $ smarty ->assign ($ k , $ v );
762+ }
763+ $ res = str_replace ($ matches [0 ][$ i ], "" . $ smarty ->fetch ($ file_name ), $ res );
764+ } else {
765+ $ res = str_replace ($ matches [0 ][$ i ], "" . $ this ->parse ($ this ->loadfile ($ file_name ) . "" , $ new_hash , $ new_root ), $ res );
766+ }
737767 } else {
738- $ res = str_replace ($ matches [0 ][$ i ], $ this ->parse ($ this ->loadfile ($ file_name ), $ new_hash , $ new_root ), $ res );
768+ if (preg_match ('/\.tpl$/ ' , $ file_name )) {
769+ dprint ($ new_hash );
770+ } else {
771+ $ res = str_replace ($ matches [0 ][$ i ], $ this ->parse ($ this ->loadfile ($ file_name ), $ new_hash , $ new_root ), $ res );
772+ }
739773 }
774+ $ this ->template = $ old_template ;
775+ endMeasure ('including ' .$ file_name );
740776 }
741777 }
742778 }
@@ -756,7 +792,7 @@ public function parseVariables(&$res, &$hash)
756792 if (preg_match_all ('/\[#(\w+?)#\]/ ' , $ res , $ matches , PREG_PATTERN_ORDER )) {
757793 $ count_matches_1 = count ($ matches [1 ]);
758794 for ($ i = 0 ; $ i < $ count_matches_1 ; $ i ++) {
759- if (!isset ($ hash [$ matches [1 ][$ i ]])) $ hash [$ matches [1 ][$ i ]]= '' ;
795+ if (!isset ($ hash [$ matches [1 ][$ i ]])) $ hash [$ matches [1 ][$ i ]] = '' ;
760796 $ res = str_replace ($ matches [0 ][$ i ], $ this ->templateSafe ($ hash [$ matches [1 ][$ i ]]), $ res );
761797 }
762798 }
@@ -765,7 +801,7 @@ public function parseVariables(&$res, &$hash)
765801 if (preg_match_all ('/\[#(\w+?)\.(\w+?)#\]/ ' , $ res , $ matches , PREG_PATTERN_ORDER )) {
766802 $ count_matches_1 = count ($ matches [1 ]);
767803 for ($ i = 0 ; $ i < $ count_matches_1 ; $ i ++) {
768- if (!isset ($ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]])) $ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]]= '' ;
804+ if (!isset ($ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]])) $ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]] = '' ;
769805 $ res = str_replace ($ matches [0 ][$ i ], $ this ->templateSafe ($ hash [$ matches [1 ][$ i ]][$ matches [2 ][$ i ]]), $ res );
770806 }
771807 }
@@ -788,7 +824,6 @@ public function templateSafe($val)
788824 $ res = str_replace ('#} ' , '#} ' , $ res );
789825 $ res = str_replace ('<# ' , '<# ' , $ res );
790826 $ res = str_replace ('#> ' , '#> ' , $ res );
791-
792827 return $ res ;
793828 }
794829
0 commit comments