aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-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.