aboutsummaryrefslogtreecommitdiffstats
path: root/library/Smarty/libs/sysplugins/smarty_internal_runtime_tplfunc.php
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-12-06 14:22:55 -0800
committerredmatrix <redmatrix@redmatrix.me>2015-12-06 14:22:55 -0800
commita88ec1b1af954a447a666d3ff66b1d1df0a645db (patch)
tree7ccfe6a03923ad118910202e21a605e13127192c /library/Smarty/libs/sysplugins/smarty_internal_runtime_tplfunc.php
parent553b3a5c6c2ba6b93ad1193ec044ee92cf7690aa (diff)
parenta6cb25020bb5200cc3c00ecc941ddb751644fbcc (diff)
downloadvolse-hubzilla-a88ec1b1af954a447a666d3ff66b1d1df0a645db.tar.gz
volse-hubzilla-a88ec1b1af954a447a666d3ff66b1d1df0a645db.tar.bz2
volse-hubzilla-a88ec1b1af954a447a666d3ff66b1d1df0a645db.zip
Merge https://github.com/redmatrix/hubzilla into pending_merge
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_internal_runtime_tplfunc.php')
-rw-r--r--library/Smarty/libs/sysplugins/smarty_internal_runtime_tplfunc.php97
1 files changed, 97 insertions, 0 deletions
diff --git a/library/Smarty/libs/sysplugins/smarty_internal_runtime_tplfunc.php b/library/Smarty/libs/sysplugins/smarty_internal_runtime_tplfunc.php
new file mode 100644
index 000000000..ec9d8da6b
--- /dev/null
+++ b/library/Smarty/libs/sysplugins/smarty_internal_runtime_tplfunc.php
@@ -0,0 +1,97 @@
+<?php
+
+/**
+ * Tplfunc Runtime Methods callTemplateFunction
+ *
+ * @package Smarty
+ * @subpackage PluginsInternal
+ * @author Uwe Tews
+ *
+ **/
+class Smarty_Internal_Runtime_Tplfunc
+{
+ /**
+ * Call template function
+ *
+ * @param \Smarty_Internal_Template $tpl template object
+ * @param string $name template function name
+ * @param array $params parameter array
+ * @param bool $nocache true if called nocache
+ *
+ * @throws \SmartyException
+ */
+ public function callTemplateFunction(\Smarty_Internal_Template $tpl, $name, $params, $nocache)
+ {
+ if (isset($tpl->tpl_function[$name])) {
+ if (!$tpl->caching || ($tpl->caching && $nocache)) {
+ $function = $tpl->tpl_function[$name]['call_name'];
+ } else {
+ if (isset($tpl->tpl_function[$name]['call_name_caching'])) {
+ $function = $tpl->tpl_function[$name]['call_name_caching'];
+ } else {
+ $function = $tpl->tpl_function[$name]['call_name'];
+ }
+ }
+ if (function_exists($function)) {
+ $function ($tpl, $params);
+ return;
+ }
+ // try to load template function dynamically
+ if ($this->addTplFuncToCache($tpl, $name, $function)) {
+ $function ($tpl, $params);
+ return;
+ }
+ }
+ throw new SmartyException("Unable to find template function '{$name}'");
+ }
+
+ /**
+ *
+ * Add template function to cache file for nocache calls
+ *
+ * @param Smarty_Internal_Template $tpl
+ * @param string $_name template function name
+ * @param string $_function PHP function name
+ *
+ * @return bool
+ */
+ public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_function)
+ {
+ $funcParam = $tpl->tpl_function[$_name];
+ if (is_file($funcParam['compiled_filepath'])) {
+ // read compiled file
+ $code = file_get_contents($funcParam['compiled_filepath']);
+ // grab template function
+ if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) {
+ // grab source info from file dependency
+ preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1);
+ unset($code);
+ // make PHP function known
+ eval($match[0]);
+ if (function_exists($_function)) {
+ // search cache file template
+ $tplPtr = $tpl;
+ while (!isset($tplPtr->cached) && isset($tplPtr->parent)) {
+ $tplPtr = $tplPtr->parent;
+ }
+ // add template function code to cache file
+ if (isset($tplPtr->cached)) {
+ $cache = $tplPtr->cached;
+ $content = $cache->read($tplPtr);
+ if ($content) {
+ // check if we must update file dependency
+ if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) {
+ $content = preg_replace("/('file_dependency'(.*?)\()/", "\\1{$match1[0]}", $content);
+ }
+ $cache->write($tplPtr, preg_replace('/\s*\?>\s*$/', "\n", $content) . "\n" .
+ preg_replace(array('/^\s*<\?php\s+/', '/\s*\?>\s*$/'), "\n",
+ $match[0]));
+ }
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}