Completed
Pull Request — gcconnex (#1540)
by Nick
16:17
created

start.php ➔ apiadmin_init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 3
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Elgg API Admin
4
 * Upgraded to Elgg 1.8 (tested on 1.8.8) and added rename and regenerate actions
5
 * 
6
 * @package ElggAPIAdmin
7
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
8
 * 
9
 * @author Curverider Ltd
10
 * @copyright Curverider Ltd 2011
11
 * @link http://www.elgg.org
12
*/
13
14
elgg_register_event_handler('init','system','apiadmin_init');
15
16
/**
17
 * Initialise the API Admin tool on init,system
18
 *
19
 * @param unknown_type $event
20
 * @param unknown_type $object_type
21
 * @param unknown_type $object
22
*/
23
function apiadmin_init($event, $object_type, $object = null) {
24
	// Add a page to the admin area
25
	elgg_register_admin_menu_item('administer', 'apiadmin', 'administer_utilities');
26
27
	// Hook into delete to revoke secret keys
28
	elgg_register_event_handler('delete', 'object', 'apiadmin_delete_key');
29
30
	// Register some actions
31
	$plugindir = dirname(__FILE__);
32
	elgg_register_action('apiadmin/revokekey', $plugindir . '/actions/apiadmin/revokekey.php', 'admin');
33
	elgg_register_action('apiadmin/generate', $plugindir . '/actions/apiadmin/generate.php', 'admin');
34
	elgg_register_action('apiadmin/renamekey', $plugindir . '/actions/apiadmin/renamekey.php', 'admin');
35
	elgg_register_action('apiadmin/regenerate', $plugindir . '/actions/apiadmin/regenerate.php', 'admin');
36
}
37
38
/**
39
 * Event handler for when an API key is deleted
40
 * 
41
 * @param unknown_type $event
42
 * @param unknown_type $object_type
43
 * @param unknown_type $object
44
 */
45
function apiadmin_delete_key($event, $object_type, $object = null) {
46
	global $CONFIG;
47
48
	if ( ($object) && ($object->subtype === get_subtype_id('object', 'api_key')) ) {
49
		// Delete secret key
50
		return remove_api_user($CONFIG->site_id, $object->public);
51
	}
52
53
	return true;
54
}
55