Add ability to turn off edit list delete checkbox
[squirrelmail.git] / functions / plugin.php
index 7dbda95f283d85d46e8b26e6ac578fb280695862..7dc3f4b043133fccdf3d7458f8c97fd378c46153 100644 (file)
@@ -562,8 +562,11 @@ function check_plugin_version($plugin_name,
   *
   * @return mixed NULL is returned if the plugin could not be 
   *               found or does not include the given requirement,
-  *               otherwise the value of the requirement is returned,
-  *               whatever that may be (varies per requirement type).
+  *               the constant SQ_INCOMPATIBLE is returned if the
+  *               given plugin is entirely incompatible with the
+  *               current SquirrelMail version, otherwise the 
+  *               value of the requirement is returned, whatever 
+  *               that may be (varies per requirement type).
   *
   */
 function get_plugin_requirement($plugin_name, $requirement, 
@@ -657,29 +660,33 @@ function get_plugin_requirement($plugin_name, $requirement,
       foreach ($plugin_info['per_version_requirements'] as $version => $requirement_overrides)
       {
 
-          $version_array = explode('.', $version);
-          if (sizeof($version_array) != 3) continue;
-
-          $a = $version_array[0];
-          $b = $version_array[1];
-          $c = $version_array[2];
-
-          if (check_sm_version($a, $b, $c) 
-           && isset($requirement_overrides[$requirement])
-           && !is_null($requirement_overrides[$requirement]))
-          {
-
-             if (empty($highest_version_array)
-              || $highest_version_array[0] < $a
-              || ($highest_version_array[0] == $a
-              && $highest_version_array[1] < $b)
-              || ($highest_version_array[0] == $a 
-              && $highest_version_array[1] == $b 
-              && $highest_version_array[2] < $c))
-             {
-                $highest_version_array = $version_array;
-                $requirement_value_override = $requirement_overrides[$requirement];
-             }
+         $version_array = explode('.', $version);
+         if (sizeof($version_array) != 3) continue;
+
+         $a = $version_array[0];
+         $b = $version_array[1];
+         $c = $version_array[2];
+
+         if (check_sm_version($a, $b, $c) 
+          && ( !empty($requirement_overrides[SQ_INCOMPATIBLE]) 
+          || (isset($requirement_overrides[$requirement])
+          && !is_null($requirement_overrides[$requirement]))))
+         {
+
+            if (empty($highest_version_array)
+             || $highest_version_array[0] < $a
+             || ($highest_version_array[0] == $a
+             && $highest_version_array[1] < $b)
+             || ($highest_version_array[0] == $a 
+             && $highest_version_array[1] == $b 
+             && $highest_version_array[2] < $c))
+            {
+               $highest_version_array = $version_array;
+               if (!empty($requirement_overrides[SQ_INCOMPATIBLE]))
+                  $requirement_value_override = SQ_INCOMPATIBLE;
+               else
+                  $requirement_value_override = $requirement_overrides[$requirement];
+            }
 
          }
 
@@ -739,20 +746,26 @@ function get_plugin_requirement($plugin_name, $requirement,
   * @return mixed Boolean FALSE is returned if the plugin
   *               could not be found or does not indicate
   *               whether it has other plugin dependencies, 
+  *               the constant SQ_INCOMPATIBLE is returned if 
+  *               the given plugin is entirely incompatible 
+  *               with the current SquirrelMail version, 
   *               otherwise an array is returned where keys 
-  *               are the names of required plugin dependencies,
-  *               and values are arrays again, where at least
-  *               the following keys (and corresponding values)
-  *               will be available: 'version' - value is the
-  *               minimum version required for that plugin (the
-  *               format of which might vary per the value of
-  *               $do_parse), 'activate' - value is boolean: 
-  *               TRUE indicates that the plugin must also be 
-  *               activated, FALSE means that it only needs to 
-  *               be present, but does not need to be activated.  
-  *               Note that the return value might be an empty 
-  *               array, indicating that the plugin has no 
-  *               dependencies.
+  *               are the names of required plugin 
+  *               dependencies, and values are arrays again, 
+  *               where at least the following keys (and 
+  *               corresponding values) will be available: 
+  *               'version' - value is the minimum version 
+  *               required for that plugin (the format of 
+  *               which might vary per the value of $do_parse
+  *               as well as if the plugin requires a SquirrelMail
+  *               core plugin, in which case it is "CORE" or
+  *               "CORE:1.5.2" or similar), 'activate' - value is
+  *               boolean: TRUE indicates that the plugin must
+  *               also be activated, FALSE means that it only
+  *               needs to be present, but does not need to be
+  *               activated.  Note that the return value might
+  *               be an empty array, indicating that the plugin
+  *               has no dependencies.
   *
   */
 function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE, 
@@ -763,6 +776,11 @@ function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE,
                                                  'required_plugins', 
                                                  $force_inclusion);
 
+   // the plugin is simply incompatible, no need to continue here
+   //
+   if ($plugin_dependencies === SQ_INCOMPATIBLE)
+      return $plugin_dependencies;
+
 
    // not an array of requirements?  wrong format, just return FALSE
    //
@@ -817,10 +835,21 @@ function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE,
             // the regexps are wrapped in a trim that makes sure the version
             // does not start or end with a decimal point
             //
-            $plugin_requirements['version']
-               = trim(preg_replace(array('/[^0-9.]+.*$/', '/[^0-9.]/'), 
-                                   '', $plugin_requirements['version']), 
-                                   '.');
+            if (strpos(strtoupper($plugin_requirements['version']), 'CORE') === 0)
+            {
+               if (strpos($plugin_requirements['version'], ':') === FALSE)
+                  $plugin_requirements['version'] = 'CORE';
+               else
+                  $plugin_requirements['version']
+                     = 'CORE:' . trim(preg_replace(array('/[^0-9.]+.*$/', '/[^0-9.]/'), 
+                                         '', substr($plugin_requirements['version'], strpos($plugin_requirements['version'], ':') + 1)), 
+                                         '.');
+            }
+            else
+               $plugin_requirements['version']
+                  = trim(preg_replace(array('/[^0-9.]+.*$/', '/[^0-9.]/'), 
+                                      '', $plugin_requirements['version']), 
+                                      '.');
 
          }
 
@@ -871,6 +900,9 @@ function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE,
   *
   * @return mixed Boolean TRUE if all of the plugin's 
   *               required plugins are correctly installed,
+  *               the constant SQ_INCOMPATIBLE is returned if 
+  *               the given plugin is entirely incompatible 
+  *               with the current SquirrelMail version, 
   *               otherwise an array of the required plugins
   *               that are either not installed or not up to
   *               the minimum required version.  The array is
@@ -890,11 +922,52 @@ function check_plugin_dependencies($plugin_name, $force_inclusion = FALSE)
 
    $dependencies = get_plugin_dependencies($plugin_name, $force_inclusion);
    if (!$dependencies) return TRUE;
+   if ($dependencies === SQ_INCOMPATIBLE) return $dependencies;
    $missing_or_bad = array();
 
    foreach ($dependencies as $depend_name => $depend_requirements)
    {
-      $version = preg_split('/\./', $depend_requirements['version'], 3);
+
+      // check for core plugins first
+      //
+      if (strpos(strtoupper($depend_requirements['version']), 'CORE') === 0)
+      {
+
+         // see if the plugin is in the core (just check if the directory exists)
+         //
+         if (!file_exists(SM_PATH . 'plugins/' . $depend_name))
+            $missing_or_bad[$depend_name] = $depend_requirements;
+
+
+         // check if it is activated if need be
+         //
+         else if ($depend_requirements['activate'] && !is_plugin_enabled($depend_name))
+            $missing_or_bad[$depend_name] = $depend_requirements;
+
+
+         // check if this is the right core version if one is given
+         // (note this is pretty useless - a plugin should specify
+         // whether or not it itself is compatible with this version
+         // of SM in the first place)
+         //
+         else if (strpos($depend_requirements['version'], ':') !== FALSE)
+         {
+            $version = explode('.', substr($depend_requirements['version'], strpos($depend_requirements['version'], ':') + 1), 3);
+            $version[0] = intval($version[0]);
+            $version[1] = intval($version[1]);
+            $version[2] = intval($version[2]);
+
+            if (!check_sm_version($version[0], $version[1], $version[2]))
+               $missing_or_bad[$depend_name] = $depend_requirements;
+         }
+
+         continue;
+
+      }
+
+      // check for normal plugins
+      //
+      $version = explode('.', $depend_requirements['version'], 3);
       $version[0] = intval($version[0]);
       $version[1] = intval($version[1]);
       $version[2] = intval($version[2]);