From 5e010074580898b22d5080cfc22f94869133657d Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 20 Jun 2008 09:45:55 +0000 Subject: Closes #61: Enable plugins to store site specific configurations git-svn-id: https://code.elgg.org/elgg/trunk@1012 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/plugins.php | 186 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 149 insertions(+), 37 deletions(-) (limited to 'engine') diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index b3c5169a3..46b42f929 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -1,25 +1,55 @@ attributes['subtype'] = "plugin"; + } + + public function __construct($guid = null) + { + parent::__construct($guid); + } + } - /** - * For now, loads plugins directly - * - * @todo Add proper plugin handler that launches plugins in an admin-defined order and activates them on admin request - * @package Elgg - * @subpackage Core - */ + /** + * For now, loads plugins directly + * + * @todo Add proper plugin handler that launches plugins in an admin-defined order and activates them on admin request + * @package Elgg + * @subpackage Core + */ function load_plugins() { global $CONFIG; @@ -44,14 +74,14 @@ } - /** - * Get the name of the most recent plugin to be called in the call stack (or the plugin that owns the current page, if any). - * - * i.e., if the last plugin was in /mod/foobar/, get_plugin_name would return foo_bar. - * - * @param boolean $mainfilename If set to true, this will instead determine the context from the main script filename called by the browser. Default = false. - * @return string|false Plugin name, or false if no plugin name was called - */ + /** + * Get the name of the most recent plugin to be called in the call stack (or the plugin that owns the current page, if any). + * + * i.e., if the last plugin was in /mod/foobar/, get_plugin_name would return foo_bar. + * + * @param boolean $mainfilename If set to true, this will instead determine the context from the main script filename called by the browser. Default = false. + * @return string|false Plugin name, or false if no plugin name was called + */ function get_plugin_name($mainfilename = false) { if (!$mainfilename) { if ($backtrace = debug_backtrace()) { @@ -120,16 +150,98 @@ 'website' => $website, 'copyright' => $copyright )); - } - /** - * PluginException - * - * A plugin Exception, thrown when an Exception occurs relating to the plugin mechanism. Subclass for specific plugin Exceptions. - * - * @package Elgg - * @subpackage Exceptions - */ + } + + /** + * Shorthand function for finding the plugin settings. + */ + function find_plugin_settings() + { + $plugins = get_entities('object', 'plugin'); + $plugin_name = get_plugin_name(); + + if ($plugins) + { + foreach ($plugins as $plugins) + if (strcmp($plugin->title, $plugin_name)==0) + return $plugin; + } + + return false; + } + + /** + * Set a setting for a plugin. + * + * @param string $name The name - note, can't be "title". + * @param mixed $value The value. + */ + function set_plugin_setting($name, $value) + { + $plugin = find_plugin_settings(); + + if (!$plugin) + $plugin = new ElggPlugin(); + + if ($name!='title') + { + $plugin->$name = $value; + + $plugin->save(); + } + + return false; + } + + /** + * Get setting for a plugin. + * + * @param string $name The name. + */ + function get_plugin_setting($name) + { + $plugin = find_plugin_settings(); + + if ($plugin) + return $plugin->$name; + + return false; + } + + /** + * Clear a plugin setting. + * + * @param string $name The name. + */ + function clear_plugin_setting($name) + { + $plugin = find_plugin_settings(); + + if ($plugin) + return $plugin->clearMetaData($name); + + return false; + } - class PluginException extends Exception {} - + /** + * Run once and only once. + */ + function plugin_run_once() + { + // Register a class + add_subtype("object", "plugin", "ElggPlugin"); + } + + /** + * Initialise the file modules. + * Listens to system boot and registers any appropriate file types and classes + */ + function plugin_init() + { + // Now run this stuff, but only once + run_function_once("plugin_run_once"); + } + + // Register a startup event + register_elgg_event_handler('init','system','plugin_init'); ?> \ No newline at end of file -- cgit v1.2.3