aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/admin.php
blob: 47704a4be07723fd2061542fcfc1e089326d4c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
	/**
	 * Elgg admin functions.
	 * Functions for adding and manipulating options on the admin panel.
	 * 
	 * @package Elgg
	 * @subpackage Core
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Marcus Povey 
	 * @copyright Curverider Ltd 2008
	 * @link http://elgg.org/
	 */

	
	/**
	 * Register an admin page with the admin panel.
	 * This function extends the view "admin/main" with the provided view. This view should provide a description
	 * and either a control or a link to.
	 * 
	 * Usage:
	 * 	- To add a control to the main admin panel then extend admin/main
	 *  - To add a control to a new page create a page which renders a view admin/subpage (where subpage is your new page - 
	 *    nb. some pages already exist that you can extend), extend the main view to point to it, and add controls to your 
	 * 	  new view.
	 * 
	 * At the moment this is essentially a wrapper around extend_view.
	 * 
	 * @param string $new_admin_view The view associated with the control you're adding  
	 * @param string $view The view to extend, by default this is 'admin/main'.
	 * @param int $priority Optional priority to govern the appearance in the list.
	 */
	function extend_elgg_admin_page( $new_admin_view, $view = 'admin/main', $priority = 500)
	{
		return extend_view($view, $new_admin_view, $priority);
	}
	
	/**
	 * Initialise the admin page.
	 */
	function admin_init()
	{
		// Add plugin main menu option (last)
		extend_elgg_admin_page('admin/main_opt/statistics', 'admin/main');
		extend_elgg_admin_page('admin/main_opt/site', 'admin/main'); 
		extend_elgg_admin_page('admin/main_opt/user', 'admin/main'); 
		extend_elgg_admin_page('admin/main_opt/plugins', 'admin/main', 999); // Always last

		register_action('admin/user/ban', false, "", true);
		register_action('admin/user/delete', false, "", true);
		register_action('admin/user/resetpassword', false, "", true);
		
		// Register some actions
		register_action('admin/site/update_basic', false, "", true); // Register basic site admin action
	}

	/**
	 * Admin permissions system
	 *
	 * @return true|null True if the current user is an admin.
	 */
	function admin_permissions($hook, $type, $returnval, $params) {
		
		if (is_array($params) && !empty($params['user']) && $params['user'] instanceof ElggUser) {
			$admin = $params['user']->admin;
			if ($admin) {
				return true;
			}
		}
		
	}
	
	/// Register init function
	register_elgg_event_handler('init','system','admin_init');
	
	// Register a plugin hook for permissions
	register_plugin_hook('permissions_check','all','admin_permissions');
	
?>