From: Paul L. <pdo...@us...> - 2006-09-07 16:54:03
|
Update of /cvsroot/squirrelmail/squirrelmail/functions In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv25166/functions Modified Files: plugin.php Log Message: New helper function for checking plugin version numbers check_plugin_version() Index: plugin.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/plugin.php,v retrieving revision 1.51 retrieving revision 1.52 diff -u -w -r1.51 -r1.52 --- plugin.php 15 Jul 2006 12:00:45 -0000 1.51 +++ plugin.php 7 Sep 2006 16:53:57 -0000 1.52 @@ -206,3 +206,100 @@ return false; } } + +/** + * Check a plugin's version. + * + * Returns TRUE if the given plugin is installed, + * activated and is at minimum version $a.$b.$c. + * If any one of those conditions fails, FALSE + * will be returned (careful of plugins that are + * sufficiently versioned but are not activated). + * + * 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. + * + * Note that this function assumes plugin + * versioning is consistently applied in the same + * fashion that SquirrelMail versions are, with the + * exception that an applicable SquirrelMail + * version may be appended to the version number + * (which will be ignored herein). That is, plugin + * version number schemes are expected in the following + * format: 1.2.3, or 1.2.3-1.4.0. + * + * Any characters after the third number are discarded, + * so formats such as the following will also work, + * although extra information about beta versions can + * possibly confuse the desired results of the version + * check: 1.2.3-beta4, 1.2.3.RC2, and so forth. + * + * @since 1.5.1 + * + * @param string plugin_name name of the plugin to + * check; must precisely + * match the plugin + * directory name + * @param int a major version number + * @param int b minor version number + * @param int c release number + * @param bool force_inclusion try to get version info + * for plugins not activated? + * (default FALSE) + * + * @return bool + * + */ +function check_plugin_version($plugin_name, + $a = 0, $b = 0, $c = 0, + $force_inclusion = FALSE) +{ + + $version_function = $plugin_name . '_version'; + $plugin_version = FALSE; + + + // attempt to find version function and get version from plugin + // + if (function_exists($version_function)) + $plugin_version = $version_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($version_function)) + $plugin_version = $version_function(); + } + + if (!$plugin_version) return FALSE; + + + // now massage version number into something we understand + // + $plugin_version = trim(preg_replace(array('/[^0-9.]+.*$/', '/[^0-9.]/'), + '', $plugin_version), + '.'); + $plugin_version = explode('.', $plugin_version); + if (!isset($plugin_version[0])) $plugin_version[0] = 0; + if (!isset($plugin_version[1])) $plugin_version[1] = 0; + if (!isset($plugin_version[2])) $plugin_version[2] = 0; +// sm_print_r($plugin_version); + + + // now test the version number + // + if ($plugin_version[0] < $a || + ($plugin_version[0] == $a && $plugin_version[1] < $b) || + ($plugin_version[0] == $a && $plugin_version[1] == $b && $plugin_version[2] < $c)) + return FALSE; + + + return TRUE; + +} + |