aboutsummaryrefslogtreecommitdiff
path: root/endpoints/rest.php
blob: 1478998657d1ffa09d730511176b5968ec265b28 (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
<?php
	/**
	 * Rest endpoint.
	 * The API REST endpoint.
	 * 
	 * @package Elgg
	 * @subpackage API
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Marcus Povey <marcus@dushka.co.uk>
	 * @copyright Curverider Ltd 2008
	 * @link http://elgg.org/
	 */

	// Include required files
	require_once('../engine/start.php');
	global $CONFIG;
	
	$CONFIG->debug = true;

	// Register the error handler
	error_reporting(E_ALL); 
	set_error_handler('__php_api_error_handler');
	
	// Register a default exception handler
	set_exception_handler('__php_api_exception_handler'); 
	
	// Check to see if the api is available
	if ((isset($CONFIG->disable_api)) && ($CONFIG->disable_api == true))
		throw new ConfigurationException("Sorry, API access has been disabled by the administrator.");

	// Register some default PAM methods, plugins can add their own
	register_api_pam_handler('pam_auth_session');
	register_api_pam_handler('pam_auth_hmac');
	
	// Get parameter variables
	$format = get_input('format', 'php');
	$method = get_input('method');
	$result = null;
	
	// Authenticate session
	if (api_pam_authenticate())
	{
		// Authenticated somehow, now execute.
		$token = "";
		$params = $_REQUEST;
		if (isset($params['auth_token'])) $token = $params['auth_token'];

		// TODO EXECUTE
	}
	
	// Finally output
	if (!($result instanceof GenericResult))
		throw new APIException("API Result is of an unknown type, this should never happen.");

	// Output the result
	echo output_result($result, $format);
	
?>