}
}
+/**
+ * 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.
*
$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;
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 == '') {
* 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";
}
*/
/**