From: pdontthink Date: Mon, 5 Feb 2007 06:06:40 +0000 (+0000) Subject: New get_plugin_version() function, and a couple places to use it. X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=d95b10b37612d4ccb3712a90a3f9be85fd92910f New get_plugin_version() function, and a couple places to use it. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12221 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/plugin.php b/functions/plugin.php index ff91deba..3b011743 100644 --- a/functions/plugin.php +++ b/functions/plugin.php @@ -271,6 +271,71 @@ function is_plugin_enabled($plugin_name) { } } +/** + * Get a plugin's version. + * + * Determines and returns a plugin's version. + * + * By default, the desired plugin must be currently + * activated, and if it is not, this function will + * return FALSE. By overriding the default value + * of $force_inclusion, this function will attempt + * to grab versioning information from the given + * plugin even if it is not activated (plugin still + * has to be unpackaged and set in place in the + * plugins directory). Use with care - some plugins + * might break SquirrelMail when this is used. + * + * @since 1.5.2 + * + * @param string plugin_name name of the plugin to + * check; must precisely + * match the plugin + * directory name + * @param bool force_inclusion try to get version info + * for plugins not activated? + * (default FALSE) + * + * @return mixed The plugin version string if found, otherwise, + * boolean FALSE is returned indicating that no + * version information could be found for the plugin. + * + */ +function get_plugin_version($plugin_name, $force_inclusion = FALSE) +{ + + $info_function = $plugin_name . '_info'; + $version_function = $plugin_name . '_version'; + $plugin_info = array(); + $plugin_version = FALSE; + + + // first attempt to find the plugin info function, wherein + // the plugin version should be available + // + if (function_exists($info_function)) + $plugin_info = $info_function(); + else if ($force_inclusion + && file_exists(SM_PATH . 'plugins/' . $plugin_name . '/setup.php')) + { + include_once(SM_PATH . 'plugins/' . $plugin_name . '/setup.php'); + if (function_exists($info_function)) + $plugin_info = $info_function(); + } + if (!empty($plugin_info['version'])) + $plugin_version = $plugin_info['version']; + + + // otherwise, look for older version function + // + if (!$plugin_version && function_exists($version_function)) + $plugin_version = $version_function(); + + + return $plugin_version; + +} + /** * Check a plugin's version. * @@ -324,34 +389,7 @@ function check_plugin_version($plugin_name, $force_inclusion = FALSE) { - $info_function = $plugin_name . '_info'; - $version_function = $plugin_name . '_version'; - $plugin_info = array(); - $plugin_version = FALSE; - - - // first attempt to find the plugin info function, wherein - // the plugin version should be available - // - if (function_exists($info_function)) - $plugin_info = $info_function(); - else if ($force_inclusion - && file_exists(SM_PATH . 'plugins/' . $plugin_name . '/setup.php')) - { - include_once(SM_PATH . 'plugins/' . $plugin_name . '/setup.php'); - if (function_exists($info_function)) - $plugin_info = $info_function(); - } - if (!empty($plugin_info['version'])) - $plugin_version = $plugin_info['version']; - - - // otherwise, look for older version function - // - if (!$plugin_version && function_exists($version_function)) - $plugin_version = $version_function(); - - + $plugin_version = get_plugin_version($plugin_name, $force_inclusion); if (!$plugin_version) return FALSE; diff --git a/plugins/bug_report/system_specs.php b/plugins/bug_report/system_specs.php index 8a46a45e..d3fbe135 100644 --- a/plugins/bug_report/system_specs.php +++ b/plugins/bug_report/system_specs.php @@ -57,39 +57,13 @@ function br_show_plugins() { if (is_array($plugins) && $plugins!=array()) { foreach ($plugins as $key => $value) { if ($key != 0 || $value != '') { - $str .= " * $key = $value"; - // add plugin version - $version_found = FALSE; - if (function_exists($value . '_info')) { - $info = call_user_func($value . '_info'); - if (!empty($info['version'])) { - $str .= ' ' . $info['version']; - $version_found = TRUE; - } - } - if (!$version_found && function_exists($value . '_version')) { - $str.= ' ' . call_user_func($value . '_version'); - } - $str.="\n"; + $str .= " * $key = $value " . get_plugin_version($value, TRUE) . "\n"; } } - // compatibility plugin can be used without need to enable it in sm config + // compatibility plugin can be used without needing to enable it in sm config if (file_exists(SM_PATH . 'plugins/compatibility/setup.php') && ! in_array('compatibility',$plugins)) { - $str.= ' * compatibility'; - include_once(SM_PATH . 'plugins/compatibility/setup.php'); - $version_found = FALSE; - if (function_exists('compatibility_info')) { - $info = compatibility_info(); - if (!empty($info['version'])) { - $str .= ' ' . $info['version']; - $version_found = TRUE; - } - } - if (!$version_found && function_exists('compatibility_version')) { - $str.= ' ' . compatibility_version(); - } - $str.="\n"; + $str.= ' * compatibility ' . get_plugin_version('compatibility', TRUE) . "\n"; } } if ($str == '') { diff --git a/src/configtest.php b/src/configtest.php index 0cca2bfc..33096746 100644 --- a/src/configtest.php +++ b/src/configtest.php @@ -354,15 +354,12 @@ if (isset($plugins[0])) { * Print plugin versions */ /* DISABLED FOR NOW: takes a lot of screen real estate and not all plugins currently - support the _info() function + support the _info() or _version() functions echo $IND . "Plugin versions...
\n"; foreach ($plugins as $name) { - $function = $name . '_info'; - if (function_exists($function)) { - $info = $function(); - if (!empty($info['version'])) - echo $IND . $IND . $name . ' ' . $info['version'] . "
\n"; - } + $plugin_version = get_plugin_version($name); + if (!empty($plugin_version)) + echo $IND . $IND . $name . ' ' . $plugin_version . "
\n"; } */ /**