-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
executable file
·285 lines (257 loc) · 7.74 KB
/
functions.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
/**
* Chronolabs IP Lookup's REST API File
*
* 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://labs.coop
* @license General Public License version 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html)
* @package lookups
* @since 1.1.2
* @author Simon Roberts <[email protected]>
* @version $Id: index.php 1000 2013-06-07 01:20:22Z mynamesnot $
* @subpackage api
* @description Internet Protocol Address Information API Service REST
*/
define('_PATH_ROOT', dirname(__FILE__));
define('_PATH_CACHE', dirname(_PATH_ROOT) . DIRECTORY_SEPARATOR . 'cache');
require_once _PATH_ROOT . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'file' . DIRECTORY_SEPARATOR . 'lifefile.php';
require_once _PATH_ROOT . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'lifecache.php';
require_once _PATH_ROOT . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'simplehtmldom' . DIRECTORY_SEPARATOR . 'simple_html_dom.php';
require_once _PATH_ROOT . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'radio.php';
/**
*
* @param string $source
* @param string $mode
* @param string $basis
* @return Ambigous <Ambigous, multitype:, unknown, multitype:Ambigous <Ambigous, mixed, NULL, boolean, multitype:unknown > , mixed, NULL, boolean>|multitype:
*/
function getAPIData($source = 'radio', $mode = 'random', $basis = '')
{
switch ($source)
{
case 'radio':
case 'audio':
case 'sound':
default:
return getRadioAPIData($mode, $basis);
break;
}
return array();
}
/**
*
* @param string $mode
* @param string $basis
* @return Ambigous <Ambigous, multitype:, unknown>|Ambigous <Ambigous, multitype:Ambigous <Ambigous, multitype:unknown , mixed, NULL, boolean, unknown> >|Ambigous <Ambigous, mixed, NULL, boolean, unknown>|multitype:
*/
function getRadioAPIData($mode = 'random', $basis = '')
{
switch ($mode)
{
case 'genres':
switch ($basis)
{
case 'primary':
return lifeRadio::getGenres(true, 'format', '');
break;
case 'all':
return lifeRadio::getGenres(false, 'format', '');
break;
default:
return lifeRadio::getGenres(false, 'format', $basis);
break;
}
break;
case 'station':
return lifeRadio::getStreamsFromStationID($basis);
break;
default:
return lifeRadio::getStationsFromAPI($mode, $basis);
break;
}
return array();
}
/**
*
* @param string $mode
* @param string $basis
* @return Ambigous <Ambigous, multitype:, unknown>|Ambigous <Ambigous, multitype:Ambigous <Ambigous, multitype:unknown , mixed, NULL, boolean, unknown> >|Ambigous <Ambigous, mixed, NULL, boolean, unknown>|multitype:
*/
function getRandomGenre($primary = true)
{
$list = array();
foreach(lifeRadio::getGenres($primary, 'format', '') as $primary => $genres)
{
if ($primary==false) {
$list[] = $primary;
foreach($genres as $genre) {
$list[] = $genre;
}
} else {
$list[] = $genres;
}
}
return $list[mt_rand(0, count($list))];
}
/**
* xml_encode()
* Encodes XML with DOMDocument Objectivity
*
* @param mixed $mixed Mixed Data
* @param object $domElement DOM Element
* @param object $DOMDocument DOM Document Object
* @return array
*/
if (!function_exists("whitelistGetIP")) {
/* function whitelistGetIPAddy()
*
* provides an associative array of whitelisted IP Addresses
* @author Simon Roberts (Chronolabs) [email protected]
*
* @return array
*/
function whitelistGetIPAddy() {
return array_merge(whitelistGetNetBIOSIP(), file(dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'whitelist.txt'));
}
}
if (!function_exists("whitelistGetNetBIOSIP")) {
/* function whitelistGetNetBIOSIP()
*
* provides an associative array of whitelisted IP Addresses base on TLD and NetBIOS Addresses
* @author Simon Roberts (Chronolabs) [email protected]
*
* @return array
*/
function whitelistGetNetBIOSIP() {
$ret = array();
foreach(file(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'whitelist-domains.txt') as $domain) {
$ip = gethostbyname($domain);
$ret[$ip] = $ip;
}
return $ret;
}
}
if (!function_exists("whitelistGetIP")) {
/* function whitelistGetIP()
*
* get the True IPv4/IPv6 address of the client using the API
* @author Simon Roberts (Chronolabs) [email protected]
*
* @param $asString boolean Whether to return an address or network long integer
*
* @return mixed
*/
function whitelistGetIP($asString = true){
// Gets the proxy ip sent by the user
$proxy_ip = '';
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else
if (!empty($_SERVER['HTTP_X_FORWARDED'])) {
$proxy_ip = $_SERVER['HTTP_X_FORWARDED'];
} else
if (! empty($_SERVER['HTTP_FORWARDED_FOR'])) {
$proxy_ip = $_SERVER['HTTP_FORWARDED_FOR'];
} else
if (!empty($_SERVER['HTTP_FORWARDED'])) {
$proxy_ip = $_SERVER['HTTP_FORWARDED'];
} else
if (!empty($_SERVER['HTTP_VIA'])) {
$proxy_ip = $_SERVER['HTTP_VIA'];
} else
if (!empty($_SERVER['HTTP_X_COMING_FROM'])) {
$proxy_ip = $_SERVER['HTTP_X_COMING_FROM'];
} else
if (!empty($_SERVER['HTTP_COMING_FROM'])) {
$proxy_ip = $_SERVER['HTTP_COMING_FROM'];
}
if (!empty($proxy_ip) && $is_ip = preg_match('/^([0-9]{1,3}.){3,3}[0-9]{1,3}/', $proxy_ip, $regs) && count($regs) > 0) {
$the_IP = $regs[0];
} else {
$the_IP = $_SERVER['REMOTE_ADDR'];
}
$the_IP = ($asString) ? $the_IP : ip2long($the_IP);
return $the_IP;
}
}
if (!class_exists("XmlDomConstruct")) {
/**
* class XmlDomConstruct
*
* Extends the DOMDocument to implement personal (utility) methods.
*
* @author Simon Roberts (Chronolabs) [email protected]
*/
class XmlDomConstruct extends DOMDocument {
/**
* Constructs elements and texts from an array or string.
* The array can contain an element's name in the index part
* and an element's text in the value part.
*
* It can also creates an xml with the same element tagName on the same
* level.
*
* ex:
* <nodes>
* <node>text</node>
* <node>
* <field>hello</field>
* <field>world</field>
* </node>
* </nodes>
*
* Array should then look like:
*
* Array (
* "nodes" => Array (
* "node" => Array (
* 0 => "text"
* 1 => Array (
* "field" => Array (
* 0 => "hello"
* 1 => "world"
* )
* )
* )
* )
* )
*
* @param mixed $mixed An array or string.
*
* @param DOMElement[optional] $domElement Then element
* from where the array will be construct to.
*
* @author Simon Roberts (Chronolabs) [email protected]
*
*/
public function fromMixed($mixed, DOMElement $domElement = null) {
$domElement = is_null($domElement) ? $this : $domElement;
if (is_array($mixed)) {
foreach( $mixed as $index => $mixedElement ) {
if ( is_int($index) ) {
if ( $index == 0 ) {
$node = $domElement;
} else {
$node = $this->createElement($domElement->tagName);
$domElement->parentNode->appendChild($node);
}
}
else {
$node = $this->createElement($index);
$domElement->appendChild($node);
}
$this->fromMixed($mixedElement, $node);
}
} else {
$domElement->appendChild($this->createTextNode($mixed));
}
}
}
}
?>