aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--engine/lib/metadata.php2
-rw-r--r--engine/lib/plugins.php87
2 files changed, 88 insertions, 1 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index d01ce0985..610288f90 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -399,7 +399,7 @@
if ($meta_value!="")
$where[] = "m.value_id='$meta_v'";
if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
+ $where[] = "m.entity_guid = {$site_guid}";
$query = "SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where";
foreach ($where as $w)
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.