aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-03 03:11:49 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-03 03:11:49 +0000
commit4b10b550a2449827c643c896424eb0277c43b049 (patch)
treea0b563666d98f3e32f2b502c2d6474afa3d17d86 /engine/lib
parent4ad5937e6077a60ecc7ee7828fb8975af7491862 (diff)
downloadelgg-4b10b550a2449827c643c896424eb0277c43b049.tar.gz
elgg-4b10b550a2449827c643c896424eb0277c43b049.tar.bz2
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
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/plugins.php81
1 files changed, 81 insertions, 0 deletions
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
@@ -306,6 +306,87 @@ function check_plugin_compatibility($manifest_elgg_version_string) {
}
/**
+ * 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.
*
* @param string $plugin_name Optional plugin name, if not specified