aboutsummaryrefslogtreecommitdiff
path: root/mod/apiadmin/start.php
blob: 5c9d4cce229200f6feddd4702038918765b8f126 (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
79
<?php
	/**
	 * Elgg API Admin
	 * 
	 * @package ElggAPIAdmin
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Curverider Ltd
	 * @copyright Curverider Ltd 2008-2009
	 * @link http://elgg.com/
	 */

	/**
	 * Initialise the API Admin tool
	 *
	 * @param unknown_type $event
	 * @param unknown_type $object_type
	 * @param unknown_type $object
	 */
	function apiadmin_init($event, $object_type, $object = null) {
		
		global $CONFIG;
		
		// Register a page handler, so we can have nice URLs
		register_page_handler('apiadmin','apiadmin_page_handler');
		
		// Register some actions
		register_action("apiadmin/revokekey",false, $CONFIG->pluginspath . "apiadmin/actions/revokekey.php", true);
		register_action("apiadmin/generate",false, $CONFIG->pluginspath . "apiadmin/actions/generate.php", true);
	}
	
	/**
	 * Page setup. Adds admin controls to the admin panel.
	 *
	 */
	function apiadmin_pagesetup()
	{
		if (get_context() == 'admin' && isadminloggedin()) {
			global $CONFIG;
			add_submenu_item(elgg_echo('apiadmin'), $CONFIG->wwwroot . 'pg/apiadmin/');
		}
	}
	
	
	function apiadmin_page_handler($page) 
	{
		global $CONFIG;
		
		if ($page[0])
		{
			switch ($page[0])
			{
				default : include($CONFIG->pluginspath . "apiadmin/index.php"); 
			}
		}
		else
			include($CONFIG->pluginspath . "apiadmin/index.php"); 
	}
	
	function apiadmin_delete_key($event, $object_type, $object = null)
	{
		global $CONFIG;
		
		if (($object) && ($object->subtype == get_subtype_id('object', 'api_key')))
		{
			// Delete 
			return remove_api_user($CONFIG->site_id, $object->public);
		}
		
		return true;
	}
	
	
	// Make sure test_init is called on initialisation
	register_elgg_event_handler('init','system','apiadmin_init');
	register_elgg_event_handler('pagesetup','system','apiadmin_pagesetup');
	
	// Hook into delete to revoke secret keys
	register_elgg_event_handler('delete','object','apiadmin_delete_key');
?>