diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-20 09:45:55 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-20 09:45:55 +0000 |
commit | 5e010074580898b22d5080cfc22f94869133657d (patch) | |
tree | f4b0002d9eb39a259dacb0252a62999306cd9cda /engine/lib | |
parent | c25dcd4533ec98c7e58c647e4b2c08169c6b7dc4 (diff) | |
download | elgg-5e010074580898b22d5080cfc22f94869133657d.tar.gz elgg-5e010074580898b22d5080cfc22f94869133657d.tar.bz2 |
Closes #61: Enable plugins to store site specific configurations
git-svn-id: https://code.elgg.org/elgg/trunk@1012 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/plugins.php | 186 |
1 files changed, 149 insertions, 37 deletions
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 @@ <?php
- /**
- * Elgg plugins library
- * Contains functions for managing plugins
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
+ /**
+ * Elgg plugins library
+ * Contains functions for managing plugins
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */
+ + /** + * PluginException + * + * A plugin Exception, thrown when an Exception occurs relating to the plugin mechanism. Subclass for specific plugin Exceptions. + * + * @package Elgg + * @subpackage Exceptions + */ + class PluginException extends Exception {} + + /** + * @class ElggPlugin Object representing a plugin's settings for a given site. + * This class is currently a stub, allowing a plugin to saving settings in an object's metadata for each site. + * @author Marcus Povey + */ + class ElggPlugin extends ElggObject + { + protected function initialise_attributes() + { + parent::initialise_attributes(); + + $this->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 |