From dedf5feaa2cf3072e90ac2bf2ef3885facd2e1a6 Mon Sep 17 00:00:00 2001 From: Florian Schaal <florian@schaal-24.de> Date: Sun, 20 Dec 2015 04:39:34 -0500 Subject: [PATCH] Merge branch 'master' of http://git.ispconfig.org/ispconfig/ispconfig3 --- server/lib/classes/tpl.inc.php | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 40 insertions(+), 8 deletions(-) diff --git a/server/lib/classes/tpl.inc.php b/server/lib/classes/tpl.inc.php index 34df2a9..5e595f6 100644 --- a/server/lib/classes/tpl.inc.php +++ b/server/lib/classes/tpl.inc.php @@ -839,28 +839,34 @@ * @access private * @return mixed data/string or boolean */ - private function _getData ($tmplfile, $do_eval=false) + private function _getData ($tmplfile, $do_eval=false, $tmpl_from_string = false) { //* check the current file depth if ($this->_includedepth > $this->OPTIONS['MAX_INCLUDES'] || $tmplfile == false) { return; } else { if ($this->_debug){ - array_push($this->_debugIncludedfiles, $tmplfile); + if($tmpl_from_string) array_push($this->_debugIncludedfiles, 'String: ' . substr($tmplfile, 0, 25) . '...'); + else array_push($this->_debugIncludedfiles, $tmplfile); } if ($do_eval) { - array_push($this->_currentincludedir, dirname($tmplfile)); + if($tmpl_from_string == true) array_push($this->_currentincludedir, end($this->_currentincludedir)); + else array_push($this->_currentincludedir, dirname($tmplfile)); $this->_includedepth++; } } - if($this->_cache && $this->_checkCache($tmplfile)) { //* cache exists so lets use it + if($this->_cache && $this->_checkCache($tmplfile, $tmpl_from_string)) { //* cache exists so lets use it $data = fread($fp = fopen($this->_cachefile, 'r'), filesize($this->_cachefile)); fclose($fp); } else { //* no cache lets parse the file - $data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile)); - fclose($fp); + if($tmpl_from_string == true) { + $data = $tmplfile; + } else { + $data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile)); + fclose($fp); + } $regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s*'; $regex.= 'tmpl_([\w]+)\s*'; @@ -884,7 +890,7 @@ } //* now we must parse the $data and check for any <tmpl_include>'s - if ($this->_debug) $this->doDebugWarnings(file($tmplfile), $tmplfile); + if ($this->_debug && $tmpl_from_string == false) $this->doDebugWarnings(file($tmplfile), $tmplfile); if ($do_eval) { $success = @eval('?>'.$data.'<?php return 1;'); @@ -1061,6 +1067,29 @@ } } + /** + * returns a string containing hook data + * @param string $type + * @param string $name + * @return string hook data + */ + private function _parseHook ($name) + { + global $app; + + $namespace = ''; + if(strpos($name, ':') !== false) list($namespace, $name) = explode(':', $name, 2); + + $result = $app->plugins->raiseAction('on_template_content_hook', array( + 'name' => $name, + 'namespace' => $namespace, + 'vars' => $this->_vars + ), true); + if(!$result) $result = ''; + else $result = $this->_getData($result, false, true); + + return $result; + } /** * returns a string used for parsing in tmpl_loop statements. @@ -1254,7 +1283,10 @@ if ($this->OPTIONS['ENABLE_PHPINCLUDE']) { return '<?php include(\''.$file.'\'); ?>'; } - + + case 'hook': + return $this->_parseHook(@$var); + case 'include': return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>'; -- Gitblit v1.9.1