This repository has been archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.php
85 lines (79 loc) · 2.19 KB
/
json.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
<?php
/**
* SMUtility
*
* @package Core
* @subpackage JSON
*/
/**
* Shorthand for DIRECTORY_SEPARATOR
* @package Core
* @subpackage JSON
*/
define('DS', DIRECTORY_SEPARATOR);
/**
* Location of the root of the script
* @package Core
* @subpackage JSON
*/
define('ROOT', '.' . DS);
require_once ROOT . 'display.php';
require_once ROOT . 'functions.php';
/* first check for info command. If found, load meta from script */
if (isset($_GET['info']) && isset($_GET['script']) && !empty($_GET['script'])) {
if ($_GET['script'] == 'core') {
$meta = $systemMeta;
$context = false;
} else {
try {
$meta = Load::meta($_GET['script']);
} catch (Exception $e) {
JSON::display('Error', $e->getMessage());
exit();
}
$context = true;
}
ksort($meta);
JSON::display($meta['name'] . ' Info', $meta);
exit();
}
/* second check if a plugin has been specified, if so, load it and run the current view */
if (isset($_GET['script']) && !empty($_GET['script'])) {
try {
$obj = Load::plugin($_GET['script']);
$meta = Load::meta($_GET['script']);
} catch (Exception $e) {
JSON::display('Error', $e->getMessage());
exit();
}
if (isset($_GET['do'])) {
$pluginValues = array();
foreach ($_POST as $key => $value) {
if (strpos($key, $meta['ID']) !== false) {
$pluginValues[str_replace($meta['ID'] . '_', "", $key)] = $value;
}
}
try {
$content = JSON::generateResult($obj, $pluginValues);
} catch (Exception $e) {
JSON::display('Error', $e->getMessage());
exit();
}
} else {
$content = JSON::generateForm($obj, $meta['ID']);
}
JSON::display($meta['name'], $content);
exit();
}
/* nothing matched so display list of plugins */
$content = array();
foreach (scandir(ROOT . 'plugins') as $item) {
try {
$meta = Load::meta($item);
$content[] = $meta;
} catch (Exception $e) {
// An exception signifies that the directory is not a plugin.
// We skip that directory
}
}
JSON::display('Script List', $content);