-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
86 lines (70 loc) · 2.31 KB
/
api.php
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
80
81
82
83
84
85
86
<?php
// The output return
$output = array(
'status'=>null,
'say'=>null,
'console'=>null
);
try {
require_once('./core/coreLoader.php');
/*******************************************************************************
* Check the TARGET
*/
// Mandatory vars
$target = CoreUtils::TARGET_T_HOME;
$fullModule = null;
$module = null;
$subModule = null;
$say = null;
$prefix = null;
Console::setDebug(isset($_GET['debugMode']));
Console::d('Debug status', Console::isDebug() ? 'enable' : 'disable');
if (!Setup::isOk())
throw new Exception('Please run the Setup in config/setup Menu');
if (!empty($_GET)) {
if (isset($_GET[CoreUtils::TARGET_T_PLAY])) {
$target = CoreUtils::TARGET_T_PLAY;
}
else if (isset($_GET[CoreUtils::TARGET_T_CONFIG])) {
$target = CoreUtils::TARGET_T_CONFIG;
}
else {
throw new Exception('Unknow target');
}
$fullModule = $_GET[$target];
$exTargetV = explode('_', $fullModule);
$module = $exTargetV[0];
$subModule = count($exTargetV) > 1 ? $exTargetV[1] : substr($target, 0, 1) . 'Main';
}
/*******************************************************************************
* Check the MODULE + SUB MODULE
*/
if (!Config::getInstance()->isValidModule($target, $module, $subModule))
throw new Exception('Unknow module or submodule');
if (!Setup::isOk()) {
throw new Exception('Please run the Setup in config/setup Menu');
}
/*******************************************************************************
* Run API
*/
include("./core/{$target}API.php");
Console::getInstance()->toLogFile();
/*******************************************************************************
* Global Catch
*/
} catch (Exception $e) {
$say = '?';
Console::w('api', 'target' , $_GET);
Console::w('api', 'module' , $module);
Console::w('api', 'subModule' , $subModule);
Console::e('api', 'Exeption', $e);
}
/*******************************************************************************
* Respond with Json
*/
$indicator = Console::getInstance()->indicator();
header('Content-type: application/json; charset=utf-8');
$output['status'] = $indicator;
$output['say'] = $say;
$output['console'] = Console::getInstance()->getArrayConsole();
echo json_encode($output, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);