From 2003687319985fd3a4a970084650d20e040ae858 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Thu, 19 May 2005 14:39:47 +0000 Subject: [PATCH] fix some evil error that cause x additional SQL query per page per plugin. That sucks, we'll need to release 0.8.2 soon then. --- docs/NEWS | 5 ++++- include/plugin_api.inc.php | 46 ++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index 8738491..7589581 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,8 +1,11 @@ -# $Id$ +svn di# $Id$ Version 0.8.2 () ------------------------------------------------------------------------ + * Fix Plugin API call performing too many unneeded SQL queries + (garvinhicking) + * Fix missing authorname when previewing entry. Thanks to winkiller, aquatic, thomas, wurstprinz and hansi for fixing this! diff --git a/include/plugin_api.inc.php b/include/plugin_api.inc.php index 9b66da4..b6a75b5 100644 --- a/include/plugin_api.inc.php +++ b/include/plugin_api.inc.php @@ -295,6 +295,17 @@ class serendipity_plugin_api { return 0; } + function includePlugin($name, $pluginPath = '') { + global $serendipity; + + // First try the local path, and then (if existing) a shared library repository ... + if (file_exists($serendipity['serendipityPath'] . 'plugins/' . $pluginPath . '/' . $name . '.php')) { + include $serendipity['serendipityPath'] . 'plugins/' . $pluginPath . '/' . $name . '.php'; + } elseif (file_exists(S9Y_INCLUDE_PATH . 'plugins/' . $pluginPath . '/' . $name . '.php')) { + include S9Y_INCLUDE_PATH . 'plugins/' . $pluginPath . '/' . $name . '.php'; + } + } + /* Creates an instance of a named plugin */ function &load_plugin($instance_id, $authorid = null, $pluginPath = '') { @@ -307,29 +318,23 @@ class serendipity_plugin_api { $class_name = substr($name, 1); } else { /* plugin from the plugins/ dir */ - if (!class_exists($name)) { - if (empty($pluginPath)) { - $sql = "SELECT path from {$serendipity['dbPrefix']}plugins WHERE name = '" . $instance_id . "'"; - $plugdata = serendipity_db_query($sql, true, 'both', false, false, false, true); - if (is_array($plugdata) && isset($plugdata[0])) { - $pluginPath = $plugdata[0]; - } - - if (empty($pluginPath)) { - $pluginPath = $name; - } + serendipity_plugin_api::includePlugin($name, $pluginPath); + if (!class_exists($name) && empty($pluginPath)) { + $sql = "SELECT path from {$serendipity['dbPrefix']}plugins WHERE name = '" . $instance_id . "'"; + $plugdata = serendipity_db_query($sql, true, 'both', false, false, false, true); + if (is_array($plugdata) && isset($plugdata[0])) { + $pluginPath = $plugdata[0]; } - // First try the local path, and then (if existing) a shared library repository ... - if (file_exists($serendipity['serendipityPath'] . 'plugins/' . $pluginPath . '/' . $name . '.php')) { - include $serendipity['serendipityPath'] . 'plugins/' . $pluginPath . '/' . $name . '.php'; - } elseif (file_exists(S9Y_INCLUDE_PATH . 'plugins/' . $pluginPath . '/' . $name . '.php')) { - include S9Y_INCLUDE_PATH . 'plugins/' . $pluginPath . '/' . $name . '.php'; + if (empty($pluginPath)) { + $pluginPath = $name; } + + serendipity_plugin_api::includePlugin($name, $pluginPath); + } - if (!class_exists($name)) { - return false; - } + if (!class_exists($name)) { + return false; } $class_name =& $name; @@ -408,6 +413,9 @@ class serendipity_plugin_api { } $pluginData = array(); + $addData = func_get_args(); + serendipity_plugin_api::hook_event('frontend_generate_plugins', $plugins, $addData); + foreach ($plugins as $plugin_data) { $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid'], $plugin_data['path']); if (is_object($plugin)) { -- 2.39.5