New get_plugin_version() function, and a couple places to use it.
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 5 Feb 2007 06:06:40 +0000 (06:06 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 5 Feb 2007 06:06:40 +0000 (06:06 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12221 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/plugin.php
plugins/bug_report/system_specs.php
src/configtest.php

index ff91deba7c593a402c1bb54bc0b0fc567d6429a7..3b011743dd195c42eee5bb34cf466c4c786abc85 100644 (file)
@@ -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;
 
 
index 8a46a45e084c5eafb305b87ff3972b0661894d2d..d3fbe13563f9f6fe8b20d32feaec22c653263edf 100644 (file)
@@ -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 == '') {
index 0cca2bfca1fdae78b098e5c8e7a2cb1d3563df7c..33096746b38d808eb249f772f80d30adee203777 100644 (file)
@@ -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 <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";
     }
 */
     /**