From b73dd8bb1ea4a6b2bb1c5e2ba3b3888efb05f70b Mon Sep 17 00:00:00 2001 From: onli Date: Tue, 23 Aug 2016 00:21:35 +0200 Subject: [PATCH] Introduce getFile to the plugin api Useful to get files (like smiley graphics) from the fallback chain --- include/plugin_api.inc.php | 21 ++++++++++- .../serendipity_event_emoticate.php | 36 +++++++++---------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/include/plugin_api.inc.php b/include/plugin_api.inc.php index 5b3ac0b7..994df340 100644 --- a/include/plugin_api.inc.php +++ b/include/plugin_api.inc.php @@ -1635,7 +1635,6 @@ class serendipity_plugin * * @access public * @param string template filename (no directory!) - * @param bool Called by a plugin (defaults true), since we do not have a theme using it yet * @return string Parsed Smarty return */ function &parseTemplate($filename) @@ -1651,6 +1650,26 @@ class serendipity_plugin return $serendipity['smarty']->fetch('file:'. $tfile); } + /** + * Get full path for a filename. Will first look into themes and then in the plugins directory + * @param string relative path to file + * @param string The path selector that tells whether to return a HTTP or realpath + * @return string The full path+filename to the requested file + * */ + function &getFile($filename, $key = 'serendipityPath') + { + global $serendipity; + + $path = serendipity_getTemplateFile($filename, $key, true); + if (!$path) { + if (file_exists(dirname($this->pluginFile) . '/' . $filename)) { + return $serendipity[$key] . 'plugins/' . basename(dirname($this->pluginFile)) . '/' . $filename; + } + } + + return $path; + } + } /** diff --git a/plugins/serendipity_event_emoticate/serendipity_event_emoticate.php b/plugins/serendipity_event_emoticate/serendipity_event_emoticate.php index b0690586..d46521df 100644 --- a/plugins/serendipity_event_emoticate/serendipity_event_emoticate.php +++ b/plugins/serendipity_event_emoticate/serendipity_event_emoticate.php @@ -80,12 +80,8 @@ class serendipity_event_emoticate extends serendipity_event } /* Hijack global variable $serendipity['custom_emoticons'] if it exists */ - if ($serendipity['version'][0] > 1) { - // called in backend too, but uses frontend fallback. Advise to use the Plugin simple approach 4th parameter! - $hijack_file = serendipity_getTemplateFile('emoticons.inc.php', 'serendipityPath', true, true); - } else { - $hijack_file = serendipity_getTemplateFile('emoticons.inc.php', 'serendipityPath', true); - } + $hijack_file = serendipity_getTemplateFile('emoticons.inc.php', 'serendipityPath', true); + if (@file_exists($hijack_file)) { @include $hijack_file; // This file contains $serendipity['custom_emoticons'] and maybe $serendipity['custom_emoticons_regexp'] if (isset($serendipity['custom_emoticons']) && is_array($serendipity['custom_emoticons'])) { @@ -102,23 +98,23 @@ class serendipity_event_emoticate extends serendipity_event if (!isset($this->smilies)) { $ext = $this->get_config('extension', 'png'); $this->smilies = array( - "\:'\(" => serendipity_getTemplateFile('img/emoticons/cry.'.$ext, 'serendipityHTTPPath', true), + "\:'\(" => $this->getFile('img/emoticons/cry.'.$ext, 'serendipityHTTPPath'), - '\:\-?\)' => serendipity_getTemplateFile('img/emoticons/smile.'.$ext, 'serendipityHTTPPath', true), + '\:\-?\)' => $this->getFile('img/emoticons/smile.'.$ext, 'serendipityHTTPPath'), - '\:\-?\|' => serendipity_getTemplateFile('img/emoticons/normal.'.$ext, 'serendipityHTTPPath', true), + '\:\-?\|' => $this->getFile('img/emoticons/normal.'.$ext, 'serendipityHTTPPath'), - '\:\-?O' => serendipity_getTemplateFile('img/emoticons/eek.'.$ext, 'serendipityHTTPPath', true), + '\:\-?O' => $this->getFile('img/emoticons/eek.'.$ext, 'serendipityHTTPPath'), - '\:\-?\(' => serendipity_getTemplateFile('img/emoticons/sad.'.$ext, 'serendipityHTTPPath', true), - - '8\-?\)' => serendipity_getTemplateFile('img/emoticons/cool.'.$ext, 'serendipityHTTPPath', true), - - '\:\-?D' => serendipity_getTemplateFile('img/emoticons/laugh.'.$ext, 'serendipityHTTPPath', true), - - '\:\-?P' => serendipity_getTemplateFile('img/emoticons/tongue.'.$ext, 'serendipityHTTPPath', true), - - ';\-?\)' => serendipity_getTemplateFile('img/emoticons/wink.'.$ext, 'serendipityHTTPPath', true), + '\:\-?\(' => $this->getFile('img/emoticons/sad.'.$ext, 'serendipityHTTPPath'), + + '8\-?\)' => $this->getFile('img/emoticons/cool.'.$ext, 'serendipityHTTPPath'), + + '\:\-?D' => $this->getFile('img/emoticons/laugh.'.$ext, 'serendipityHTTPPath'), + + '\:\-?P' => $this->getFile('img/emoticons/tongue.'.$ext, 'serendipityHTTPPath'), + + ';\-?\)' => $this->getFile('img/emoticons/wink.'.$ext, 'serendipityHTTPPath'), ); } @@ -248,4 +244,4 @@ class serendipity_event_emoticate extends serendipity_event } /* vim: set sts=4 ts=4 expandtab : */ -?> +?> \ No newline at end of file