aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/plugins.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-20 11:43:39 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-20 11:43:39 +0000
commit9b47cfa886a391296641dad6509f92c17fdc572d (patch)
treed87edd195853f043650c6c138b5fb809460578b4 /engine/lib/plugins.php
parentd7e5e1063bc705d7783933a7c7490a795e5dd8cb (diff)
downloadelgg-9b47cfa886a391296641dad6509f92c17fdc572d.tar.gz
elgg-9b47cfa886a391296641dad6509f92c17fdc572d.tar.bz2
Closes #60: Enable/disable plugins on a site by site basis
git-svn-id: https://code.elgg.org/elgg/trunk@1017 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/plugins.php')
-rw-r--r--engine/lib/plugins.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index 0d19bc049..8ead863a1 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -230,6 +230,93 @@
return false;
}
+
+ /**
+ * Enable a plugin for a site (default current site)
+ *
+ * @param string $plugin The plugin name.
+ * @param int $site_guid The site id, if not specified then this is detected.
+ */
+ function enable_plugin($plugin, $site_guid = 0)
+ {
+ global $CONFIG;
+
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $site = get_entity($site_guid);
+ if (!($site instanceof ElggSite))
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite"));
+
+ $enabled = $site->getMetaData('enabled_plugins');
+ $new_enabled = array();
+ if ($enabled)
+ {
+ if (!is_array($enabled))
+ $new_enabled[] = $enabled;
+ else
+ $new_enabled = $enabled;
+ }
+ $new_enabled[] = $plugin;
+ $new_enabled = array_unique($new_enabled);
+
+ return $site->setMetaData('enabled_plugins', $new_enabled);
+ }
+
+ /**
+ * Disable a plugin for a site (default current site)
+ *
+ * @param string $plugin The plugin name.
+ * @param int $site_guid The site id, if not specified then this is detected.
+ */
+ function disable_plugin($plugin, $site_guid = 0)
+ {
+ global $CONFIG;
+
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $site = get_entity($site_guid);
+ if (!($site instanceof ElggSite))
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite"));
+
+ $enabled = $site->getMetaData('enabled_plugins');
+ $new_enabled = array();
+
+ foreach ($enabled as $plug)
+ if ($plugin != $plug)
+ $new_enabled[] = $plug;
+
+ return $site->setMetaData('enabled_plugins', $new_enabled);
+ }
+
+ /**
+ * Return whether a plugin is enabled or not.
+ *
+ * @param string $plugin The plugin name.
+ * @param int $site_guid The site id, if not specified then this is detected.
+ * @return bool
+ */
+ function is_plugin_enabled($plugin, $site_guid = 0)
+ {
+ global $CONFIG;
+
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $site = get_entity($site_guid);
+ if (!($site instanceof ElggSite))
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite"));
+
+ $enabled = find_metadata("enabled_plugins", $plugin, "site", "", 10, 0, "", $site_guid);
+ if ($enabled)
+ return true;
+
+ return false;
+ }
/**
* Run once and only once.