@@ -839,28 +839,34 @@ public function __construct($tmplfile = null, $options = null)
839839 * @access private
840840 * @return mixed data/string or boolean
841841 */
842- private function _getData ($ tmplfile , $ do_eval =false )
842+ private function _getData ($ tmplfile , $ do_eval =false , $ tmpl_from_string = false )
843843 {
844844 //* check the current file depth
845845 if ($ this ->_includedepth > $ this ->OPTIONS ['MAX_INCLUDES ' ] || $ tmplfile == false ) {
846846 return ;
847847 } else {
848848 if ($ this ->_debug ){
849- array_push ($ this ->_debugIncludedfiles , $ tmplfile );
849+ if ($ tmpl_from_string ) array_push ($ this ->_debugIncludedfiles , 'String: ' . substr ($ tmplfile , 0 , 25 ) . '... ' );
850+ else array_push ($ this ->_debugIncludedfiles , $ tmplfile );
850851 }
851852 if ($ do_eval ) {
852- array_push ($ this ->_currentincludedir , dirname ($ tmplfile ));
853+ if ($ tmpl_from_string == true ) array_push ($ this ->_currentincludedir , end ($ this ->_currentincludedir ));
854+ else array_push ($ this ->_currentincludedir , dirname ($ tmplfile ));
853855 $ this ->_includedepth ++;
854856 }
855857 }
856858
857859
858- if ($ this ->_cache && $ this ->_checkCache ($ tmplfile )) { //* cache exists so lets use it
860+ if ($ this ->_cache && $ this ->_checkCache ($ tmplfile, $ tmpl_from_string )) { //* cache exists so lets use it
859861 $ data = fread ($ fp = fopen ($ this ->_cachefile , 'r ' ), filesize ($ this ->_cachefile ));
860862 fclose ($ fp );
861863 } else { //* no cache lets parse the file
862- $ data = fread ($ fp = fopen ($ tmplfile , 'r ' ), filesize ($ tmplfile ));
863- fclose ($ fp );
864+ if ($ tmpl_from_string == true ) {
865+ $ data = $ tmplfile ;
866+ } else {
867+ $ data = fread ($ fp = fopen ($ tmplfile , 'r ' ), filesize ($ tmplfile ));
868+ fclose ($ fp );
869+ }
864870
865871 $ regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s* ' ;
866872 $ regex .= 'tmpl_([\w]+)\s* ' ;
@@ -884,7 +890,7 @@ private function _getData ($tmplfile, $do_eval=false)
884890 }
885891
886892 //* now we must parse the $data and check for any <tmpl_include>'s
887- if ($ this ->_debug ) $ this ->doDebugWarnings (file ($ tmplfile ), $ tmplfile );
893+ if ($ this ->_debug && $ tmpl_from_string == false ) $ this ->doDebugWarnings (file ($ tmplfile ), $ tmplfile );
888894
889895 if ($ do_eval ) {
890896 $ success = @eval ('?> ' .$ data .'<?php return 1; ' );
@@ -1061,6 +1067,29 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10611067 }
10621068 }
10631069
1070+ /**
1071+ * returns a string containing hook data
1072+ * @param string $type
1073+ * @param string $name
1074+ * @return string hook data
1075+ */
1076+ private function _parseHook ($ name )
1077+ {
1078+ global $ app ;
1079+
1080+ $ namespace = '' ;
1081+ if (strpos ($ name , ': ' ) !== false ) list ($ namespace , $ name ) = explode (': ' , $ name , 2 );
1082+
1083+ $ result = $ app ->plugins ->raiseAction ('on_template_content_hook ' , array (
1084+ 'name ' => $ name ,
1085+ 'namespace ' => $ namespace ,
1086+ 'vars ' => $ this ->_vars
1087+ ), true );
1088+ if (!$ result ) $ result = '' ;
1089+ else $ result = $ this ->_getData ($ result , false , true );
1090+
1091+ return $ result ;
1092+ }
10641093
10651094 /**
10661095 * returns a string used for parsing in tmpl_loop statements.
@@ -1254,7 +1283,10 @@ private function _parseTag ($args)
12541283 if ($ this ->OPTIONS ['ENABLE_PHPINCLUDE ' ]) {
12551284 return '<?php include( \'' .$ file .'\'); ?> ' ;
12561285 }
1257-
1286+
1287+ case 'hook ' :
1288+ return $ this ->_parseHook (@$ var );
1289+
12581290 case 'include ' :
12591291 return '<?php $this->_getData($this->_fileSearch( \'' .$ file .'\'), 1); ?> ' ;
12601292
0 commit comments