-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·233 lines (222 loc) · 7.29 KB
/
index.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/**
* Chronolabs Entitiesing Repository Services REST API API
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Chronolabs Cooperative http://syd.au.snails.email
* @license ACADEMIC APL 2 (https://sourceforge.net/u/chronolabscoop/wiki/Academic%20Public%20License%2C%20version%202.0/)
* @license GNU GPL 3 (http://www.gnu.org/licenses/gpl.html)
* @package emails-api
* @since 2.2.1
* @author Dr. Simon Antony Roberts <simon@snails.email>
* @version 2.2.8
* @description A REST API for the storage and management of entities + persons + beingness collaterated!
* @link http://internetfounder.wordpress.com
* @link https://github.com/Chronolabs-Cooperative/Emails-API-PHP
* @link https://sourceforge.net/p/chronolabs-cooperative
* @link https://facebook.com/ChronolabsCoop
* @link https://twitter.com/ChronolabsCoop
*/
require_once __DIR__ . DIRECTORY_SEPARATOR . 'header.php';
/**
* URI Path Finding of API URL Source Locality
* @var unknown_type
*/
$odds = $inner = array();
foreach($_GET as $key => $values) {
if (!isset($inner[$key])) {
$inner[$key] = $values;
} elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) {
if (is_array($values)) {
$odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values;
} else {
$odds[$key][$inner[$key] = $values] = "$values--$key";
}
}
}
foreach($_POST as $key => $values) {
if (!isset($inner[$key])) {
$inner[$key] = $values;
} elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) {
if (is_array($values)) {
$odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values;
} else {
$odds[$key][$inner[$key] = $values] = "$values--$key";
}
}
}
foreach(parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'], '?')?'&':'?').$_SERVER['QUERY_STRING'], PHP_URL_QUERY) as $key => $values) {
if (!isset($inner[$key])) {
$inner[$key] = $values;
} elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) {
if (is_array($values)) {
$odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values;
} else {
$odds[$key][$inner[$key] = $values] = "$values--$key";
}
}
}
$help=true;
if (isset($inner['output']) || !empty($inner['output'])) {
$version = isset($inner['version'])?(string)$inner['version']:'v2';
$output = isset($inner['output'])?(string)$inner['output']:'';
$name = isset($inner['name'])?(string)$inner['name']:'';
$clause = isset($inner['clause'])?(string)$inner['clause']:'';
$callback = isset($_REQUEST['callback'])?(string)$_REQUEST['callback']:'';
$mode = isset($inner['mode'])?(string)$inner['mode']:'';
$state = isset($inner['state'])?(string)$inner['state']:'';
switch($output)
{
default:
if (!in_array($output, file(__DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'entities-supported.diz')))
$help=true;
elseif (in_array($mode, array('entities')) && strlen($clause) == 32)
$help=false;
break;
case "raw":
case "html":
case "serial":
case "json":
case "xml":
if (in_array($mode, array('nodes', 'entities')))
$help=false;
break;
case "forms":
if (in_array($mode, array('uploads','edit')))
{
$help=false;
if (empty($clause) && isset($_POST['return']))
$clause = $_POST['return'];
}
break;
case "profile":
if (in_array($mode, array('sites')) && in_array($clause, array('create', 'forgotten', 'edit')))
$help=false;
break;
case "css":
if (in_array($mode, array('entities', 'entities', 'random')) && !empty($clause))
{
$help=false;
if ($mode == 'random' && empty($state))
$help=true;
}
break;
case "preview":
if (in_array($mode, array('entities', 'entities', 'random')) && !empty($clause))
{
$help=false;
if ($mode == 'random' && empty($state))
$help=true;
}
break;
}
} else {
$help=true;
}
if ($help==true) {
if (function_exists('http_response_code'))
http_response_code(201);
include dirname(__FILE__).'/help.php';
exit;
}
/*
session_start();
if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) {
if (isset($_SESSION['reset']) && $_SESSION['reset']<microtime(true))
$_SESSION['hits'] = 0;
if ($_SESSION['hits']<=MAXIMUM_QUERIES) {
if (!isset($_SESSION['hits']) || $_SESSION['hits'] = 0)
$_SESSION['reset'] = microtime(true) + 3600;
$_SESSION['hits']++;
} else {
header("HTTP/1.0 404 Not Found");
exit;
}
}
*/
switch($output)
{
default:
$data = getEntitiesRawData($mode, $clause, $output, $version);
break;
case "raw":
case "html":
case "serial":
case "json":
case "xml":
switch ($mode)
{
case "nodes":
$data = getNodesListArray($clause, $output);
break;
case "entities":
$data = getEntitiesListArray($clause, $output);
break;
}
break;
case "profile":
$data = '';
break;
case "css":
$data = getCSSListArray($mode, $clause, $state, $name, $output, $version);
break;
case "preview":
if (function_exists('http_response_code'))
http_response_code(400);
$data = getPreviewHTML($mode, $clause, $state, $name, $output, $version);
break;
case "forms":
if (function_exists('http_response_code'))
http_response_code(201);
die(getHTMLForm($mode, $clause, $callback, $output, $version));
break;
}
if (function_exists('http_response_code'))
http_response_code(200);
switch ($output) {
default:
echo $data;
break;
case 'html':
echo '<h1>' . $country . ' - ' . $place . ' (Places data)</h1>';
echo '<pre style="entities-family: \'Courier New\', Courier, Terminal; entities-size: 0.77em;">';
echo implode("\n", $data);
echo '</pre>';
break;
case 'raw':
header('Content-type: application/x-httpd-php');
echo ('<?php'."\n\n".'return ' . var_export($data, true) . ";\n\n?>");
break;
case 'json':
header('Content-type: application/json');
echo json_encode($data);
break;
case 'serial':
header('Content-type: text/text');
echo serialize($data);
break;
case 'xml':
header('Content-type: application/xml');
$dom = new XmlDomConstruct('1.0', 'utf-8');
$dom->fromMixed(array('root'=>$data));
echo $dom->saveXML();
break;
case "css":
header('Content-type: text/css');
echo implode("\n\n", $data);
break;
case "preview":
header('Content-type: text/html');
echo $data;
break;
break;
}
// Checks Cache for Cleaning
@cleanResourcesCache();
?>