From e663d523186a12a41aca0541c996a6a0022912d8 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 16 Oct 2008 16:57:39 +0000 Subject: You can now reorder plugins. git-svn-id: https://code.elgg.org/elgg/trunk@2274 36083f99-b078-4883-b0ff-0f9b5a30f544 --- actions/admin/plugins/reorder.php | 51 ++++++++ admin/plugins/index.php | 5 +- engine/lib/plugins.php | 181 +++++++++++++++++++++++------ languages/en.php | 5 + views/default/admin/plugins.php | 7 +- views/default/admin/plugins_opt/plugin.php | 20 +++- 6 files changed, 228 insertions(+), 41 deletions(-) create mode 100644 actions/admin/plugins/reorder.php diff --git a/actions/admin/plugins/reorder.php b/actions/admin/plugins/reorder.php new file mode 100644 index 000000000..e1a45f368 --- /dev/null +++ b/actions/admin/plugins/reorder.php @@ -0,0 +1,51 @@ + \ No newline at end of file diff --git a/admin/plugins/index.php b/admin/plugins/index.php index 717e9bde0..10ab3f51b 100644 --- a/admin/plugins/index.php +++ b/admin/plugins/index.php @@ -19,7 +19,10 @@ admin_gatekeeper(); // Set admin user for user block - set_page_owner($_SESSION['guid']); + set_page_owner($_SESSION['guid']); + + // Regenerate plugin list + regenerate_plugin_list(); // Display main admin menu page_draw(elgg_echo("admin:plugins"),elgg_view_layout("two_column_left_sidebar", '', elgg_view_title(elgg_echo('admin:plugins')) . elgg_view("admin/plugins", array('installed_plugins' => get_installed_plugins())))); 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 diff --git a/languages/en.php b/languages/en.php index aecefe9ed..b02f5d905 100644 --- a/languages/en.php +++ b/languages/en.php @@ -573,6 +573,11 @@ To remove a widget drag it back to the Widget gallery.", 'disable' => "Disable", 'request' => "Request", 'complete' => "Complete", + + 'up' => 'Up', + 'down' => 'Down', + 'top' => 'Top', + 'bottom' => 'Bottom', 'invite' => "Invite", diff --git a/views/default/admin/plugins.php b/views/default/admin/plugins.php index 449c86d11..cc96b40f8 100644 --- a/views/default/admin/plugins.php +++ b/views/default/admin/plugins.php @@ -21,13 +21,18 @@ // Get the installed plugins $installed_plugins = $vars['installed_plugins']; $count = count($installed_plugins); + + $plugin_list = get_plugin_list(); + $max = 0; + foreach($plugin_list as $key => $foo) + if ($key > $max) $max = $key; // Display list of plugins $n = 0; foreach ($installed_plugins as $plugin => $data) { //if (($n>=$offset) && ($n < $offset+$limit)) - echo elgg_view("admin/plugins_opt/plugin", array('plugin' => $plugin, 'details' => $data)); + echo elgg_view("admin/plugins_opt/plugin", array('plugin' => $plugin, 'details' => $data, 'maxorder' => $max, 'order' => array_search($plugin, $plugin_list))); $n++; } diff --git a/views/default/admin/plugins_opt/plugin.php b/views/default/admin/plugins_opt/plugin.php index 21032b33d..b74d9bc25 100644 --- a/views/default/admin/plugins_opt/plugin.php +++ b/views/default/admin/plugins_opt/plugin.php @@ -23,7 +23,25 @@ $ts = time(); $token = generate_action_token($ts); ?> -
"> +
"> +
+ 10) { +?> + + + + + + + +
-- cgit v1.2.3