diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-16 16:57:39 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-16 16:57:39 +0000 |
commit | e663d523186a12a41aca0541c996a6a0022912d8 (patch) | |
tree | 9c080159e9e3d702e85b5d4be80f70837a919416 /engine | |
parent | 6609ac6ad0990f4b08d9a6783ff85a03a1daf7f3 (diff) | |
download | elgg-e663d523186a12a41aca0541c996a6a0022912d8.tar.gz elgg-e663d523186a12a41aca0541c996a6a0022912d8.tar.bz2 |
You can now reorder plugins.
git-svn-id: https://code.elgg.org/elgg/trunk@2274 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/plugins.php | 181 |
1 files changed, 143 insertions, 38 deletions
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index a71b6ecad..83a81a81b 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -44,7 +44,126 @@ { parent::__construct($guid); } - } + }
+
+ /**
+ * Returns a list of plugins to load, in the order that they should be loaded.
+ *
+ * @return array List of plugins
+ */
+ function get_plugin_list() {
+
+ global $CONFIG;
+
+ if (!empty($CONFIG->pluginlistcache))
+ return $CONFIG->pluginlistcache;
+
+ if ($site = get_entity($CONFIG->site_guid)) {
+
+ $pluginorder = $site->pluginorder;
+ if (!empty($pluginorder)) {
+
+ $plugins = unserialize($pluginorder);
+
+ $CONFIG->pluginlistcache = $plugins;
+ return $plugins;
+
+ } else {
+
+ $plugins = array();
+
+ if ($handle = opendir($CONFIG->pluginspath)) {
+ while ($mod = readdir($handle)) {
+ if (!in_array($mod,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . "/" . $mod)) {
+ $plugins[] = $mod;
+ }
+ }
+ }
+
+ sort($plugins);
+
+ $CONFIG->pluginlistcache = $plugins;
+ return $plugins;
+
+ }
+
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Regenerates the list of known plugins and saves it to the current site
+ *
+ * @param array $pluginorder Optionally, a list of existing plugins and their orders
+ * @return array The new list of plugins and their orders
+ */
+ function regenerate_plugin_list($pluginorder = false) {
+
+ global $CONFIG;
+
+ $CONFIG->pluginlistcache = null;
+
+ if ($site = get_entity($CONFIG->site_guid)) {
+
+ if (empty($pluginorder)) {
+ $pluginorder = $site->pluginorder;
+ $pluginorder = unserialize($pluginorder);
+ } else {
+ ksort($pluginorder);
+ }
+
+ if (empty($pluginorder)) {
+ $pluginorder = array();
+ }
+
+ $max = 0;
+ if (sizeof($pluginorder))
+ foreach($pluginorder as $key => $plugin) {
+ if (is_dir($CONFIG->pluginspath . "/" . $plugin)) {
+ if ($key > $max)
+ $max = $key;
+ } else {
+ unset($pluginorder[$key]);
+ }
+ }
+
+ // Add new plugins to the end
+ if ($handle = opendir($CONFIG->pluginspath)) {
+ while ($mod = readdir($handle)) {
+ if (!in_array($mod,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . "/" . $mod)) {
+ if (!in_array($mod, $pluginorder)) {
+ $max = $max + 10;
+ $pluginorder[$max] = $mod;
+ }
+ }
+ }
+ }
+
+ ksort($pluginorder);
+
+ // Now reorder the keys ..
+ $key = 10;
+ $plugins = array();
+ if (sizeof($pluginorder))
+ foreach($pluginorder as $plugin) {
+ $plugins[$key] = $plugin;
+ $key = $key + 10;
+ }
+
+ $plugins = serialize($plugins);
+
+ $site->pluginorder = $plugins;
+
+ return $plugins;
+
+ }
+
+ return false;
+
+ }
+ /**
* For now, loads plugins directly
@@ -58,34 +177,21 @@ global $CONFIG;
if (!empty($CONFIG->pluginspath)) {
- $plugins = array();
+ $plugins = get_plugin_list();
- 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)) {
-
- $plugins[] = $mod;
-
+ if (sizeof($plugins))
+ foreach($plugins as $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")) {
+ autoregister_views("",$CONFIG->pluginspath . $mod . "/views/default",$CONFIG->pluginspath . $mod . "/views/");
+ }
+ if (is_dir($CONFIG->pluginspath . $mod . "/languages")) {
+ register_translations($CONFIG->pluginspath . $mod . "/languages/");
}
}
}
-
- sort($plugins);
-
- if (sizeof($plugins))
- foreach($plugins as $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")) {
- autoregister_views("",$CONFIG->pluginspath . $mod . "/views/default",$CONFIG->pluginspath . $mod . "/views/");
- }
- if (is_dir($CONFIG->pluginspath . $mod . "/languages")) {
- register_translations($CONFIG->pluginspath . $mod . "/languages/");
- }
- } -
- }
}
@@ -358,19 +464,15 @@ $installed_plugins = array(); if (!empty($CONFIG->pluginspath)) { +
+ $plugins = get_plugin_list();
+
+ foreach($plugins as $mod) {
+ $installed_plugins[$mod] = array();
+ $installed_plugins[$mod]['active'] = is_plugin_enabled($mod);
+ $installed_plugins[$mod]['manifest'] = load_plugin_manifest($mod);
+ }
- 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; @@ -496,7 +598,10 @@ register_action("plugins/usersettings/save"); register_action('admin/plugins/enable', false, "", true); // Enable - register_action('admin/plugins/disable', false, "", true); // Disable + register_action('admin/plugins/disable', false, "", true); // Disable
+
+ register_action('admin/plugins/reorder', false, "", true); // Disable
+ } // Register a startup event |