+ // make sure everything is in order...
+ //
+ if (!empty($plugin_dependencies))
+ {
+
+ $new_plugin_dependencies = array();
+ foreach ($plugin_dependencies as $plugin_name => $plugin_requirements)
+ {
+
+ // if $plugin_requirements isn't an array, this is old-style,
+ // where only the version number was given...
+ //
+ if (is_string($plugin_requirements))
+ $plugin_requirements = array('version' => $plugin_requirements,
+ 'activate' => FALSE);
+
+
+ // trap badly formatted requirements arrays that don't have
+ // needed info
+ //
+ if (!is_array($plugin_requirements)
+ || !isset($plugin_requirements['version']))
+ continue;
+ if (!isset($plugin_requirements['activate']))
+ $plugin_requirements['activate'] = FALSE;
+
+
+ // parse version into something we understand?
+ //
+ if ($do_parse && $plugin_requirements['version'] != SQ_INCOMPATIBLE)
+ {
+
+ // massage version number into something we understand
+ //
+ // the first regexp strips everything and anything that follows
+ // the first occurance of a non-digit (or non decimal point), so
+ // beware that putting letters in the middle of a version string
+ // will effectively truncate the version string right there (but
+ // this also just helps remove the SquirrelMail version part off
+ // of versions such as "1.2.3-1.4.4")
+ //
+ // the second regexp just strips out non-digits/non-decimal points
+ // (and might be redundant(?))
+ //
+ // the regexps are wrapped in a trim that makes sure the version
+ // does not start or end with a decimal point
+ //
+ 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']),
+ '.');
+
+ }
+
+ $new_plugin_dependencies[$plugin_name] = $plugin_requirements;
+
+ }
+
+ $plugin_dependencies = $new_plugin_dependencies;
+
+ }
+
+ return $plugin_dependencies;
+
+}
+
+/**
+ * Check a plugin's other plugin dependencies.
+ *
+ * Determines whether or not all of the given
+ * plugin's required plugins are installed and
+ * up to the proper version, and if they are
+ * activated if required.
+ *
+ * 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 dependency 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 if a plugin does not report whether or
+ * not it has other plugin dependencies, this function
+ * will return TRUE, although that is possibly incorrect
+ * or misleading.
+ *
+ * @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 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
+ * keyed by plugin name where 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 (in printable, non-
+ * parsed format) or the constant SQ_INCOMPATIBLE,
+ * which indicates that the plugin is actually
+ * incompatible (not required), '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.
+ *
+ */
+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)
+ {
+
+ // 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]);
+ if (isset($version[1])) $version[1] = intval($version[1]);
+ else $version[1] = 0;
+ if (isset($version[2])) $version[2] = intval($version[2]);
+ else $version[2] = 0;
+
+ if (!check_sm_version($version[0], $version[1], $version[2]))
+ $missing_or_bad[$depend_name] = $depend_requirements;
+ }
+
+ continue;
+
+ }
+
+ // if the plugin is actually incompatible; check that it
+ // is not activated
+ //
+ if ($depend_requirements['version'] == SQ_INCOMPATIBLE)
+ {
+
+ if (is_plugin_enabled($depend_name))
+ $missing_or_bad[$depend_name] = $depend_requirements;
+
+ continue;
+
+ }
+
+ // check for normal plugins
+ //
+ $version = explode('.', $depend_requirements['version'], 3);
+ $version[0] = intval($version[0]);
+ if (isset($version[1])) $version[1] = intval($version[1]);
+ else $version[1] = 0;
+ if (isset($version[2])) $version[2] = intval($version[2]);
+ else $version[2] = 0;
+
+ $force_dependency_inclusion = !$depend_requirements['activate'];
+
+ if (!check_plugin_version($depend_name, $version[0], $version[1],
+ $version[2], $force_dependency_inclusion))
+ $missing_or_bad[$depend_name] = $depend_requirements;
+ }
+
+ if (empty($missing_or_bad)) return TRUE;
+
+
+ // get non-parsed required versions
+ //
+ $non_parsed_dependencies = get_plugin_dependencies($plugin_name,
+ $force_inclusion,
+ FALSE);
+ $return_array = array();
+ foreach ($missing_or_bad as $depend_name => $ignore)
+ $return_array[$depend_name] = $non_parsed_dependencies[$depend_name];
+
+ return $return_array;