From 4b10b550a2449827c643c896424eb0277c43b049 Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 3 Dec 2010 03:11:49 +0000 Subject: Refs #1986 #2170 #2225. Added semantic manifest.xml support and unit tests. Also added plugin dependencies system. See engine/tests/test_files/plugin_18/manifest.xml for examples. Not closing tickets pending discussion. git-svn-id: http://code.elgg.org/elgg/trunk@7512 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/plugins.php | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'engine/lib') diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 7624b1768..1c91a7776 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -305,6 +305,87 @@ function check_plugin_compatibility($manifest_elgg_version_string) { return false; } +/** + * Returns an array of all provides from all active plugins. + * + * Array in the form array( + * 'provide_type' => array( + * 'provided_name' => array( + * 'version' => '1.8', + * 'provided_by' => 'provider_plugin_id' + * ) + * ) + * ) + * + * @param string $type The type of provides to return + * @param string $name A specific provided name to return. Requires $provide_type. + * + * @return array + */ +function elgg_get_plugins_provides($type = null, $name = null) { + static $provides = null; + $active_plugins = get_installed_plugins('enabled'); + + if (!isset($provides)) { + $provides = array(); + + foreach ($active_plugins as $plugin_id => $plugin_info) { + // @todo remove this when fully converted to ElggPluginPackage. + $package = new ElggPluginPackage($plugin_id); + + if ($plugin_provides = $package->getManifest()->getProvides()) { + foreach ($plugin_provides as $provided) { + $provides[$provided['type']][$provided['name']] = array( + 'version' => $provided['version'], + 'provided_by' => $plugin_id + ); + } + } + } + } + + if ($type && $name) { + if (isset($provides[$type][$name])) { + return $provides[$type][$name]; + } else { + return false; + } + } elseif ($type) { + if (isset($provides[$type])) { + return $provides[$type]; + } else { + return false; + } + } + + return $provides; +} + +/** + * Checks if a plugin is currently providing $type and $name, and optionally + * checking a version. + * + * @param string $type The type of the provide + * @param string $name The name of the provide + * @param string $version A version to check against + * @param string $comparison The comparison operator to use in version_compare() + * + * @return bool + */ +function elgg_check_plugins_provides($type, $name, $version = null, $comparison = 'ge') { + if (!$provided = elgg_get_plugins_provides($type, $name)) { + return false; + } + + if ($provided) { + if ($version) { + return version_compare($provided['version'], $version, $comparison); + } else { + return true; + } + } +} + /** * Shorthand function for finding the plugin settings. * -- cgit v1.2.3