Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
<?php
2
 
3
/***************************************************************************
4
 *   Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in)  	   		   *
5
 *   sendtogeo@gmail.com   												   *
6
 *                                                                         *
7
 *   This program is free software; you can redistribute it and/or modify  *
8
 *   it under the terms of the GNU General Public License as published by  *
9
 *   the Free Software Foundation; either version 2 of the License, or     *
10
 *   (at your option) any later version.                                   *
11
 *                                                                         *
12
 *   This program is distributed in the hope that it will be useful,       *
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 *   GNU General Public License for more details.                          *
16
 *                                                                         *
17
 *   You should have received a copy of the GNU General Public License     *
18
 *   along with this program; if not, write to the                         *
19
 *   Free Software Foundation, Inc.,                                       *
20
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21
 ***************************************************************************/
22
 
23
include_once("../includes/sp-load.php");
24
include_once(SP_CTRLPATH."/api.ctrl.php");
25
include_once(SP_CTRLPATH."/settings.ctrl.php");
26
include(SP_ABSPATH . "/api/api.functions.php");
27
$controller = New APIController();
28
 
29
$inputInfo = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : $_GET;
30
 
31
// sp demo enabled
32
if (SP_DEMO) {
33
	$returnInfo['response'] = 'Error';
34
	$returnInfo['error_msg'] = "API will not work in demo mode!";
35
} else if ($controller->verifyAPICredentials($inputInfo)) {
36
 
37
	$category = strtolower($inputInfo['category']);
38
	$action = $inputInfo['action'];
39
 
40
	// check for category and action values
41
	if (!empty($category) && !empty($action)) {
42
 
43
		// call api class with the action
44
		if (include(SP_ABSPATH . "/api/" . $category . ".api.php")) {
45
			$categortClassName = ucfirst($category) . "API";
46
 
47
			// check for class exists or not
48
			if (class_exists($categortClassName)) {
49
				$apiObj = new $categortClassName();
50
 
51
				// check action exists or not
52
				if (method_exists($apiObj, $action)) {
53
					$returnInfo = $apiObj->$action($inputInfo);
54
				} else {
55
					$returnInfo['response'] = 'Error';
56
					$returnInfo['error_msg'] = "Action is not supported!";
57
				}
58
 
59
			} else {
60
				$returnInfo['response'] = 'Error';
61
				$returnInfo['error_msg'] = "Category is not supported!";
62
			}
63
 
64
		} else {
65
			$returnInfo['response'] = 'Error';
66
			$returnInfo['error_msg'] = "Invalid category passed!";
67
		}
68
 
69
	} else {
70
		$returnInfo['response'] = 'Error';
71
		$returnInfo['error_msg'] = "Invalid category or action!";
72
	}
73
 
74
} else {
75
	$returnInfo['response'] = 'Error';
76
	$returnInfo['error_msg'] = "API Authentication failed. Please provide valid API key and secret!";
77
}
78
 
79
// for debugging added below line
80
// debugVar($returnInfo);exit;
81
 
82
// encode as json and print
83
$out = json_encode($returnInfo);
84
print $out;
85
?>