From: <pdo...@us...> - 2007-02-05 06:06:41
|
Revision: 12221 http://squirrelmail.svn.sourceforge.net/squirrelmail/?rev=12221&view=rev Author: pdontthink Date: 2007-02-04 22:06:40 -0800 (Sun, 04 Feb 2007) Log Message: ----------- New get_plugin_version() function, and a couple places to use it. Modified Paths: -------------- trunk/squirrelmail/functions/plugin.php trunk/squirrelmail/plugins/bug_report/system_specs.php trunk/squirrelmail/src/configtest.php Modified: trunk/squirrelmail/functions/plugin.php =================================================================== --- trunk/squirrelmail/functions/plugin.php 2007-02-05 03:43:56 UTC (rev 12220) +++ trunk/squirrelmail/functions/plugin.php 2007-02-05 06:06:40 UTC (rev 12221) @@ -272,6 +272,71 @@ } /** + * 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. * * Returns TRUE if the given plugin is installed, @@ -324,34 +389,7 @@ $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; Modified: trunk/squirrelmail/plugins/bug_report/system_specs.php =================================================================== --- trunk/squirrelmail/plugins/bug_report/system_specs.php 2007-02-05 03:43:56 UTC (rev 12220) +++ trunk/squirrelmail/plugins/bug_report/system_specs.php 2007-02-05 06:06:40 UTC (rev 12221) @@ -57,39 +57,13 @@ 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 == '') { Modified: trunk/squirrelmail/src/configtest.php =================================================================== --- trunk/squirrelmail/src/configtest.php 2007-02-05 03:43:56 UTC (rev 12220) +++ trunk/squirrelmail/src/configtest.php 2007-02-05 06:06:40 UTC (rev 12221) @@ -354,15 +354,12 @@ * Print plugin versions */ /* DISABLED FOR NOW: takes a lot of screen real estate and not all plugins currently - support the <plugin>_info() function + support the <plugin>_info() or <plugin>_version() functions echo $IND . "Plugin versions...<br />\n"; foreach ($plugins as $name) { - $function = $name . '_info'; - if (function_exists($function)) { - $info = $function(); - if (!empty($info['version'])) - echo $IND . $IND . $name . ' ' . $info['version'] . "<br />\n"; - } + $plugin_version = get_plugin_version($name); + if (!empty($plugin_version)) + echo $IND . $IND . $name . ' ' . $plugin_version . "<br />\n"; } */ /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |