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 | |
| 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
| -rw-r--r-- | actions/admin/plugins/reorder.php | 51 | ||||
| -rw-r--r-- | admin/plugins/index.php | 5 | ||||
| -rw-r--r-- | engine/lib/plugins.php | 181 | ||||
| -rw-r--r-- | languages/en.php | 5 | ||||
| -rw-r--r-- | views/default/admin/plugins.php | 7 | ||||
| -rw-r--r-- | views/default/admin/plugins_opt/plugin.php | 20 | 
6 files changed, 228 insertions, 41 deletions
| 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 @@ +<?php
 +	/**
 +	 * Reorder plugin action.
 +	 * 
 +	 * @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/
 +	 */
 +
 +	require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php");
 +	
 +	// block non-admin users
 +	admin_gatekeeper();
 +	
 +	// Validate the action
 +	action_gatekeeper();
 +	
 +	// Get the plugin 
 +	$mod = get_input('plugin');
 +	$mod = str_replace('.','',$mod);
 +	$mod = str_replace('/','',$mod);
 +	
 +	// Get the new order
 +	$order = (int) get_input('order');
 +	
 +	// Get the current plugin list
 +	$plugins = get_plugin_list();
 +
 +	// Inject the plugin order back into the list
 +	if ($key = array_search($mod, $plugins)) {
 +		
 +		unset($plugins[$key]);
 +		while (isset($plugins[$order])) {
 +			$order++;
 +		}
 +		
 +		$plugins[$order] = $mod;
 +	}
 +	
 +	// Disable
 +	if (regenerate_plugin_list($plugins))
 +		system_message(sprintf(elgg_echo('admin:plugins:reorder:yes'), $plugin));
 +	else
 +		register_error(sprintf(elgg_echo('admin:plugins:reorder:no'), $plugin));		
 +		
 +	forward($_SERVER['HTTP_REFERER']);
 +
 +?>
\ 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 <b>Widget gallery</b>.",  			'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);  ?> -<div class="plugin_details <?php if ($active) echo "active"; else echo "not-active" ?>">  +<div class="plugin_details <?php if ($active) echo "active"; else echo "not-active" ?>">
 +	<div class="admin_plugin_reorder">
 +		<?php
 +			if ($vars['order'] > 10) {
 +?>
 +			<a href="<?php echo $vars['url']; ?>actions/admin/plugins/reorder?plugin=<?php echo $plugin; ?>&order=1&__elgg_token=<?php echo $token; ?>&__elgg_ts=<?php echo $ts; ?>"><?php echo elgg_echo("top"); ?></a>
 +			<a href="<?php echo $vars['url']; ?>actions/admin/plugins/reorder?plugin=<?php echo $plugin; ?>&order=<?php echo $vars['order'] - 11; ?>&__elgg_token=<?php echo $token; ?>&__elgg_ts=<?php echo $ts; ?>"><?php echo elgg_echo("up"); ?></a>
 +<?php
 +			}
 +		?> 
 +		<?php
 +			if ($vars['order'] < $vars['maxorder']) {
 +?>
 +			<a href="<?php echo $vars['url']; ?>actions/admin/plugins/reorder?plugin=<?php echo $plugin; ?>&order=<?php echo $vars['order'] + 11; ?>&__elgg_token=<?php echo $token; ?>&__elgg_ts=<?php echo $ts; ?>"><?php echo elgg_echo("down"); ?></a>
 +			<a href="<?php echo $vars['url']; ?>actions/admin/plugins/reorder?plugin=<?php echo $plugin; ?>&order=<?php echo $vars['maxorder'] + 11; ?>&__elgg_token=<?php echo $token; ?>&__elgg_ts=<?php echo $ts; ?>"><?php echo elgg_echo("bottom"); ?></a>
 +<?php
 +			}
 +		?> 
 +	</div>  	<div class="admin_plugin_enable_disable">  		<?php if ($active) { ?>  			<a href="<?php echo $vars['url']; ?>actions/admin/plugins/disable?plugin=<?php echo $plugin; ?>&__elgg_token=<?php echo $token; ?>&__elgg_ts=<?php echo $ts; ?>"><?php echo elgg_echo("disable"); ?></a> | 
