From 733f4f5e7ccf742f596ac79ac2425a5f6a198405 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Fri, 31 Aug 2007 10:39:55 +0000 Subject: [PATCH] * New plugin API method "parseTemplate($filename)" to allow a sidebar- or event-plugin to fetch+display a smarty template. (garvinhicking) --- docs/NEWS | 4 ++++ include/plugin_api.inc.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/docs/NEWS b/docs/NEWS index d7de3de..1578b44 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,10 @@ Version 1.3 () ------------------------------------------------------------------------ + * New plugin API method "parseTemplate($filename)" to allow a + sidebar- or event-plugin to fetch+display a smarty template. + (garvinhicking) + * Made short-urls index.php?serendipity[id]=X or index.php?p=X properly show a single entry view (garvinhicking) diff --git a/include/plugin_api.inc.php b/include/plugin_api.inc.php index 69bbc67..5350256 100644 --- a/include/plugin_api.inc.php +++ b/include/plugin_api.inc.php @@ -567,6 +567,9 @@ class serendipity_plugin_api $p->serendipity_owner = $owner[0]; } } + + $p->pluginPath = $pluginPath; + $p->pluginFile = $pluginFile; return $p; } @@ -1141,6 +1144,9 @@ class serendipity_plugin var $title_class = 'serendipitySideBarTitle'; var $content_class = 'serendipitySideBarContent'; var $title = null; + var $pluginPath = null; + var $pluginFile = null; + var $serendipity_owner = null; /** * The constructor of a plugin @@ -1474,6 +1480,31 @@ class serendipity_plugin return true; } + + /** + * Parses a smarty template file (which can be stored in either the plugin directory, the user template directory + * or the default template directory, and return the parsed output. + * + * @access public + * @param string template filename (no directory!) + * @return string Parsed Smarty return + */ + function &parseTemplate($filename) { + global $serendipity; + + $filename = basename($filename); + $tfile = serendipity_getTemplateFile($filename, 'serendipityPath'); + if (!$tfile || $tfile == $filename) { + $tfile = dirname($this->pluginFile) . '/' . $filename; + } + $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY]; + $serendipity['smarty']->security_settings[INCLUDE_ANY] = true; + $content = $serendipity['smarty']->fetch('file:'. $tfile, null, null, false); + $serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion; + + return $content; + } + } /** -- 2.39.5