From: garvinhicking Date: Thu, 19 May 2005 14:39:21 +0000 (+0000) Subject: fix some evil error that cause x additional SQL query per page per plugin. X-Git-Tag: 0.9~454 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=99bf32263f27739fe19d1adf8886ef93e34276ec;p=s9y.git 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. --- diff --git a/docs/NEWS b/docs/NEWS index 1a0e5fb..324bb0a 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -43,6 +43,9 @@ Version 0.9 () 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 f6cbd10..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;