From 28826aff64178c7422e6424c81c1771d9dfdc7dd Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 20 Jun 2008 13:42:37 +0000 Subject: Further fixes #59 git-svn-id: https://code.elgg.org/elgg/trunk@1024 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/plugins.php | 99 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 39 deletions(-) (limited to 'engine') diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index a38fc2434..dd9a75e20 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -58,8 +58,8 @@ if ($handle = opendir($CONFIG->pluginspath)) { while ($mod = readdir($handle)) { if (!in_array($mod,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . "/" . $mod)) { - //if (is_plugin_enabled($mod)) - //{ + if (is_plugin_enabled($mod)) + { if (!@include($CONFIG->pluginspath . $mod . "/start.php")) throw new PluginException(sprintf(elgg_echo('PluginException:MisconfiguredPlugin'), $mod)); if (is_dir($CONFIG->pluginspath . $mod . "/views/default")) { @@ -68,7 +68,7 @@ if (is_dir($CONFIG->pluginspath . $mod . "/languages")) { register_translations($CONFIG->pluginspath . $mod . "/languages/"); } - //} + } } } } @@ -106,53 +106,46 @@ } } return false; - } + } /** - * Register a plugin with a manifest. - * - * It is passed an associated array of values. Currently the following fields are recognised: + * Load and parse a plugin manifest from a plugin XML file. * - * 'author', 'description', 'version', 'website' & 'copyright'. + * Example file: * - * @param array $manifest An associative array representing the manifest. + * + * + * + * + * + * + * + * + * @param string $plugin Plugin name. + * @return array of values */ - function register_plugin_manifest(array $manifest) + function load_plugin_manifest($plugin) { global $CONFIG; - if (!is_array($CONFIG->plugin_manifests)) - $CONFIG->plugin_manifests = array(); - - $plugin_name = get_plugin_name(); + $xml = xml_2_object(file_get_contents($CONFIG->pluginspath . $plugin. "/manifest.xml")); - if ($plugin_name) + if ($xml) { - $CONFIG->plugin_manifests[$plugin_name] = $manifest; + $elements = array(); + + foreach ($xml->children as $element) + { + $key = $element->attributes['key']; + $value = $element->attributes['value']; + + $elements[$key] = $value; + } + + return $elements; } - else - throw new PluginException(elgg_echo('PluginException:NoPluginName')); - } - - /** - * Register a basic plugin manifest. - * - * @param string $author The author. - * @param string $description A description of the plugin (don't forget to internationalise this string!) - * @param string $version The version - * @param string $website A link to the plugin's website - * @param string $copyright Copyright information - * @return bool - */ - function register_plugin_manifest_basic($author, $description, $version, $website = "", $copyright = "") - { - return register_plugin_manifest(array( - 'version' => $version, - 'author' => $author, - 'description' => $description, - 'website' => $website, - 'copyright' => $copyright - )); + + return false; } /** @@ -234,6 +227,34 @@ return false; } + /** + * Return an array of installed plugins. + */ + function get_installed_plugins() + { + global $CONFIG; + + $installed_plugins = array(); + + if (!empty($CONFIG->pluginspath)) { + + if ($handle = opendir($CONFIG->pluginspath)) { + + while ($mod = readdir($handle)) { + + if (!in_array($mod,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . "/" . $mod)) { + + $installed_plugins[$mod] = array(); + $installed_plugins[$mod]['active'] = is_plugin_enabled($mod); + $installed_plugins[$mod]['manifest'] = load_plugin_manifest($mod); + } + } + } + } + + return $installed_plugins; + } + /** * Enable a plugin for a site (default current site) * -- cgit v1.2.3