|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (!function_exists("pr")) { |
|
4
|
|
|
|
|
5
|
|
|
function pr($mixed) |
|
6
|
|
|
{ |
|
7
|
|
|
echo "<pre>"; |
|
8
|
|
|
print_r($mixed); |
|
9
|
|
|
echo "</pre>"; |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
function encode_url($input) |
|
15
|
|
|
{ |
|
16
|
|
|
$chars = array( |
|
17
|
|
|
'Ă' => 'a', |
|
18
|
|
|
'ă' => 'a', |
|
19
|
|
|
'Â' => 'A', |
|
20
|
|
|
'â' => 'a', |
|
21
|
|
|
'Î' => 'I', |
|
22
|
|
|
'î' => 'i', |
|
23
|
|
|
'Ș' => 'S', |
|
24
|
|
|
'ș' => 's', |
|
25
|
|
|
'Ş' => 'S', |
|
26
|
|
|
'ş' => 's', |
|
27
|
|
|
'Ț' => 'T', |
|
28
|
|
|
'ț' => 't', |
|
29
|
|
|
'Ţ' => 'T', |
|
30
|
|
|
'ţ' => 't', |
|
31
|
|
|
''' => '', |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
foreach ($chars as $i => $v) { |
|
35
|
|
|
$chars[html_entity_decode($i, ENT_QUOTES, 'UTF-8')] = $v; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$input = strtr($input, $chars); |
|
39
|
|
|
|
|
40
|
|
|
preg_match_all("/[a-z0-9]+/i", $input, $chunks); |
|
41
|
|
|
$return_ = strtolower(implode("-", $chunks[0])); |
|
42
|
|
|
|
|
43
|
|
|
return $return_; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
function current_url() |
|
50
|
|
|
{ |
|
51
|
1 |
|
return defined('CURRENT_URL') ? CURRENT_URL : null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Transforms a date's string representation into $format |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $format |
|
58
|
|
|
* @param string|int $datetime |
|
59
|
|
|
* @return string/bool |
|
|
|
|
|
|
60
|
|
|
*/ |
|
61
|
|
|
function _date($datetime, $format = false) |
|
62
|
|
|
{ |
|
63
|
|
|
$format = $format ? $format : Nip\locale()->getOption(['time', 'dateFormat']); |
|
64
|
|
|
$time = is_numeric($datetime) ? $datetime : strtotime($datetime); |
|
65
|
|
|
|
|
66
|
|
|
return $time ? date($format, $time) : false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Transforms a date's string representation into $format |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $format |
|
73
|
|
|
* @param string|int $datetime |
|
|
|
|
|
|
74
|
|
|
* @return string/bool |
|
|
|
|
|
|
75
|
|
|
*/ |
|
76
|
|
|
function _strtotime($date, $format = false) |
|
77
|
|
|
{ |
|
78
|
|
|
$format = $format ? $format : Nip\locale()->getOption(['time', 'dateStringFormat']); |
|
79
|
|
|
$dateArray = strptime($date, $format); |
|
80
|
|
|
|
|
81
|
|
|
return mktime($dateArray['tm_hour'], $dateArray['tm_min'], $dateArray['tm_sec'], 1 + $dateArray['tm_mon'], |
|
82
|
|
|
$dateArray['tm_mday'], 1900 + $dateArray['tm_year']); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Transforms a date's string representation into $format |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $format |
|
89
|
|
|
* @param string|int $datetime |
|
90
|
|
|
* @return string/bool |
|
|
|
|
|
|
91
|
|
|
*/ |
|
92
|
|
|
function _strftime($datetime, $format = false) |
|
93
|
|
|
{ |
|
94
|
|
|
if ($datetime && strpos($datetime, '0000-00-00') === false) { |
|
95
|
|
|
$format = $format ? $format : Nip\locale()->getOption(['time', 'dateStringFormat']); |
|
96
|
|
|
if (is_numeric($datetime)) { |
|
97
|
|
|
$time = $datetime; |
|
98
|
|
|
} else { |
|
99
|
|
|
$time = strtotime($datetime); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if ($time !== false && $time !== -1) { |
|
103
|
|
|
return iconv("ISO-8859-2", "ASCII//TRANSLIT", strftime($format, $time)); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return false; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
if (!function_exists("pluck")) { |
|
112
|
|
|
|
|
113
|
|
|
function pluck($array, $property) |
|
114
|
|
|
{ |
|
115
|
|
|
return \Nip\HelperBroker::get('Arrays')->pluck($array, $property); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
function max_upload() |
|
121
|
|
|
{ |
|
122
|
|
|
$post_max_size = ini_get('post_max_size'); |
|
123
|
|
|
$upload_max_filesize = ini_get('upload_max_filesize'); |
|
124
|
|
|
|
|
125
|
|
|
$unit = strtoupper(substr($post_max_size, -1)); |
|
126
|
|
|
$multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1))); |
|
127
|
|
|
$post_max_size = ((int)$post_max_size) * $multiplier; |
|
128
|
|
|
|
|
129
|
|
|
$unit = strtoupper(substr($upload_max_filesize, -1)); |
|
130
|
|
|
$multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1))); |
|
131
|
|
|
$upload_max_filesize = ((int)$upload_max_filesize) * $multiplier; |
|
132
|
|
|
|
|
133
|
|
|
return round((min($post_max_size, $upload_max_filesize) / 1048576), 2) . 'MB'; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
function valid_url($input) |
|
137
|
|
|
{ |
|
138
|
|
|
return preg_match("|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i", $input); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
function valid_email($email) |
|
143
|
|
|
{ |
|
144
|
|
|
$isValid = true; |
|
145
|
|
|
$atIndex = strrpos($email, "@"); |
|
146
|
|
|
if (is_bool($atIndex) && !$atIndex) { |
|
147
|
|
|
$isValid = false; |
|
148
|
|
|
} else { |
|
149
|
|
|
$domain = substr($email, $atIndex + 1); |
|
150
|
|
|
$local = substr($email, 0, $atIndex); |
|
151
|
|
|
$localLen = strlen($local); |
|
152
|
|
|
$domainLen = strlen($domain); |
|
153
|
|
|
if ($localLen < 1 || $localLen > 64) { |
|
154
|
|
|
// local part length exceeded |
|
155
|
|
|
$isValid = false; |
|
156
|
|
|
} else { |
|
157
|
|
|
if ($domainLen < 1 || $domainLen > 255) { |
|
158
|
|
|
// domain part length exceeded |
|
159
|
|
|
$isValid = false; |
|
160
|
|
|
} else { |
|
161
|
|
|
if ($local[0] == '.' || $local[$localLen - 1] == '.') { |
|
162
|
|
|
// local part starts or ends with '.' |
|
163
|
|
|
$isValid = false; |
|
164
|
|
|
} else { |
|
165
|
|
|
if (preg_match('/\.\./', $local)) { |
|
166
|
|
|
// local part has two consecutive dots |
|
167
|
|
|
$isValid = false; |
|
168
|
|
|
} else { |
|
169
|
|
|
if (!preg_match('/^[A-Za-z0-9\-\.]+$/', $domain)) { |
|
170
|
|
|
// character not valid in domain part |
|
171
|
|
|
$isValid = false; |
|
172
|
|
|
} else { |
|
173
|
|
|
if (preg_match('/\.\./', $domain)) { |
|
174
|
|
|
// domain part has two consecutive dots |
|
175
|
|
|
$isValid = false; |
|
176
|
|
|
} else { |
|
177
|
|
|
if (!preg_match('/^(\.|[A-Za-z0-9!#%&`_=\/$\'*+?^{}|~.-])+$/', |
|
178
|
|
|
str_replace("\\", "", $local)) |
|
179
|
|
|
) { |
|
180
|
|
|
// character not valid in local part unless |
|
181
|
|
|
// local part is quoted |
|
182
|
|
|
if (!preg_match('/^"(\"|[^"])+"$/', str_replace("\\", "", $local))) { |
|
183
|
|
|
$isValid = false; |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain, "A"))) { |
|
193
|
|
|
// domain not found in DNS |
|
194
|
|
|
$isValid = false; |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
return $isValid; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
function valid_cc_number($cc_number) |
|
202
|
|
|
{ |
|
203
|
|
|
/* Validate; return value is card type if valid. */ |
|
204
|
|
|
$card_type = ""; |
|
205
|
|
|
$card_regexes = array( |
|
206
|
|
|
"/^4\d{12}(\d\d\d){0,1}$/" => "visa", |
|
207
|
|
|
"/^5[12345]\d{14}$/" => "mastercard", |
|
208
|
|
|
"/^3[47]\d{13}$/" => "amex", |
|
209
|
|
|
"/^6011\d{12}$/" => "discover", |
|
210
|
|
|
"/^30[012345]\d{11}$/" => "diners", |
|
211
|
|
|
"/^3[68]\d{12}$/" => "diners", |
|
212
|
|
|
); |
|
213
|
|
|
|
|
214
|
|
|
foreach ($card_regexes as $regex => $type) { |
|
215
|
|
|
if (preg_match($regex, $cc_number)) { |
|
216
|
|
|
$card_type = $type; |
|
217
|
|
|
break; |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
if (!$card_type) { |
|
222
|
|
|
return false; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/* mod 10 checksum algorithm */ |
|
226
|
|
|
$revcode = strrev($cc_number); |
|
227
|
|
|
$checksum = 0; |
|
228
|
|
|
|
|
229
|
|
|
for ($i = 0; $i < strlen($revcode); $i++) { |
|
230
|
|
|
$current_num = intval($revcode[$i]); |
|
231
|
|
|
if ($i & 1) { /* Odd position */ |
|
232
|
|
|
$current_num *= 2; |
|
233
|
|
|
} |
|
234
|
|
|
/* Split digits and add. */ |
|
235
|
|
|
$checksum += $current_num % 10; |
|
236
|
|
|
if |
|
237
|
|
|
($current_num > 9 |
|
238
|
|
|
) { |
|
239
|
|
|
$checksum += 1; |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
if ($checksum % 10 == 0) { |
|
244
|
|
|
return $card_type; |
|
245
|
|
|
} else { |
|
246
|
|
|
return false; |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
function valid_cnp($cnp) |
|
251
|
|
|
{ |
|
252
|
|
|
$const = '279146358279'; |
|
253
|
|
|
$cnp = trim($cnp); |
|
254
|
|
|
|
|
255
|
|
|
preg_match("|^([1256])(\d{2})(\d{2})(\d{2})(\d{6})$|ims", $cnp, $results); |
|
256
|
|
|
if (count($results) < 1) { |
|
257
|
|
|
return false; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
$mf = $results[1] + 0; |
|
261
|
|
|
if ($mf == 5 || $mf == 6) { |
|
262
|
|
|
$year_add = 2000; |
|
263
|
|
|
} else { |
|
264
|
|
|
$year_add = 1900; |
|
265
|
|
|
} |
|
266
|
|
|
$year = $year_add + $results[2]; |
|
267
|
|
|
$month = $results[3] + 0; |
|
268
|
|
|
$day = $results[4] + 0; |
|
269
|
|
|
|
|
270
|
|
|
if (!checkdate($month, $day, $year)) { |
|
271
|
|
|
return false; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
$suma = 0; |
|
275
|
|
|
for ($i = 0; $i < 12; $i++) { |
|
276
|
|
|
$suma += $const[$i] * $cnp[$i]; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
$rest = $suma % 11; |
|
280
|
|
|
|
|
281
|
|
|
$c13 = $cnp[12] + 0; |
|
282
|
|
|
|
|
283
|
|
|
if (!(($rest < 10 && $rest == $c13) || ($rest == 10 && $c13 == 1))) { |
|
284
|
|
|
return false; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
return true; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
if (!function_exists("money_format")) { |
|
291
|
|
|
function money_format($format, $number) |
|
292
|
|
|
{ |
|
293
|
|
|
$regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?' . |
|
294
|
|
|
'(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/'; |
|
295
|
|
|
if (setlocale(LC_MONETARY, 0) == 'C') { |
|
296
|
|
|
setlocale(LC_MONETARY, ''); |
|
297
|
|
|
} |
|
298
|
|
|
$locale = localeconv(); |
|
299
|
|
|
preg_match_all($regex, $format, $matches, PREG_SET_ORDER); |
|
300
|
|
|
foreach ($matches as $fmatch) { |
|
|
|
|
|
|
301
|
|
|
$value = floatval($number); |
|
302
|
|
|
$flags = array( |
|
303
|
|
|
'fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ? |
|
304
|
|
|
$match[1] : ' ', |
|
305
|
|
|
'nogroup' => preg_match('/\^/', $fmatch[1]) > 0, |
|
306
|
|
|
'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ? |
|
307
|
|
|
$match[0] : '+', |
|
308
|
|
|
'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0, |
|
309
|
|
|
'isleft' => preg_match('/\-/', $fmatch[1]) > 0, |
|
310
|
|
|
); |
|
311
|
|
|
$width = trim($fmatch[2]) ? (int)$fmatch[2] : 0; |
|
312
|
|
|
$left = trim($fmatch[3]) ? (int)$fmatch[3] : 0; |
|
313
|
|
|
$right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits']; |
|
314
|
|
|
$conversion = $fmatch[5]; |
|
315
|
|
|
|
|
316
|
|
|
$positive = true; |
|
317
|
|
|
if ($value < 0) { |
|
318
|
|
|
$positive = false; |
|
319
|
|
|
$value *= -1; |
|
320
|
|
|
} |
|
321
|
|
|
$letter = $positive ? 'p' : 'n'; |
|
322
|
|
|
|
|
323
|
|
|
$prefix = $suffix = $cprefix = $csuffix = $signal = ''; |
|
|
|
|
|
|
324
|
|
|
|
|
325
|
|
|
$signal = $positive ? $locale['positive_sign'] : $locale['negative_sign']; |
|
326
|
|
|
switch (true) { |
|
327
|
|
View Code Duplication |
case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+': |
|
|
|
|
|
|
328
|
|
|
$prefix = $signal; |
|
329
|
|
|
break; |
|
330
|
|
View Code Duplication |
case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+': |
|
|
|
|
|
|
331
|
|
|
$suffix = $signal; |
|
332
|
|
|
break; |
|
333
|
|
View Code Duplication |
case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+': |
|
|
|
|
|
|
334
|
|
|
$cprefix = $signal; |
|
335
|
|
|
break; |
|
336
|
|
View Code Duplication |
case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+': |
|
|
|
|
|
|
337
|
|
|
$csuffix = $signal; |
|
338
|
|
|
break; |
|
339
|
|
|
case $flags['usesignal'] == '(': |
|
340
|
|
|
case $locale["{$letter}_sign_posn"] == 0: |
|
341
|
|
|
$prefix = '('; |
|
342
|
|
|
$suffix = ')'; |
|
343
|
|
|
break; |
|
344
|
|
|
} |
|
345
|
|
|
if (!$flags['nosimbol']) { |
|
346
|
|
|
$currency = $cprefix . |
|
347
|
|
|
($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . |
|
348
|
|
|
$csuffix; |
|
349
|
|
|
} else { |
|
350
|
|
|
$currency = ''; |
|
351
|
|
|
} |
|
352
|
|
|
$space = $locale["{$letter}_sep_by_space"] ? ' ' : ''; |
|
353
|
|
|
|
|
354
|
|
|
$value = number_format($value, $right, $locale['mon_decimal_point'], |
|
355
|
|
|
$flags['nogroup'] ? '' : $locale['mon_thousands_sep']); |
|
356
|
|
|
$value = @explode($locale['mon_decimal_point'], $value); |
|
357
|
|
|
|
|
358
|
|
|
$n = strlen($prefix) + strlen($currency) + strlen($value[0]); |
|
359
|
|
|
if ($left > 0 && $left > $n) { |
|
360
|
|
|
$value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0]; |
|
361
|
|
|
} |
|
362
|
|
|
$value = implode($locale['mon_decimal_point'], $value); |
|
363
|
|
|
if ($locale["{$letter}_cs_precedes"]) { |
|
364
|
|
|
$value = $prefix . $currency . $space . $value . $suffix; |
|
365
|
|
|
} else { |
|
366
|
|
|
$value = $prefix . $value . $space . $currency . $suffix; |
|
367
|
|
|
} |
|
368
|
|
|
if ($width > 0) { |
|
369
|
|
|
$value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? |
|
370
|
|
|
STR_PAD_RIGHT : STR_PAD_LEFT); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
$format = str_replace($fmatch[0], $value, $format); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
return $format; |
|
377
|
|
|
} |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
if (!function_exists("json_decode")) { |
|
381
|
|
|
|
|
382
|
|
|
function json_decode( |
|
383
|
|
|
$json, |
|
384
|
|
|
$assoc = false, /* emu_args */ |
|
385
|
|
|
$n = 0, |
|
386
|
|
|
$state = 0, |
|
387
|
|
|
$waitfor = 0 |
|
388
|
|
|
) |
|
389
|
|
|
{ |
|
390
|
|
|
|
|
391
|
|
|
#-- result var |
|
392
|
|
|
$val = null; |
|
393
|
|
|
static $lang_eq = array("true" => true, "false" => false, "null" => null); |
|
394
|
|
|
static $str_eq = array( |
|
395
|
|
|
"n" => "\012", |
|
396
|
|
|
"r" => "\015", |
|
397
|
|
|
"\\" => "\\", |
|
398
|
|
|
'"' => '"', |
|
399
|
|
|
"f" => "\f", |
|
400
|
|
|
"b" => "\b", |
|
401
|
|
|
"t" => "\t", |
|
402
|
|
|
"/" => "/", |
|
403
|
|
|
); |
|
404
|
|
|
|
|
405
|
|
|
#-- flat char-wise parsing |
|
406
|
|
|
for (/* n */; $n < strlen($json); /* n */) { |
|
407
|
|
|
$c = $json[$n]; |
|
408
|
|
|
|
|
409
|
|
|
#-= in-string |
|
410
|
|
|
if ($state === '"') { |
|
411
|
|
|
|
|
412
|
|
|
if ($c == '\\') { |
|
413
|
|
|
$c = $json[++$n]; |
|
414
|
|
|
// simple C escapes |
|
415
|
|
|
if (isset($str_eq[$c])) { |
|
416
|
|
|
$val .= $str_eq[$c]; |
|
417
|
|
|
} // here we transform \uXXXX Unicode (always 4 nibbles) references to UTF-8 |
|
418
|
|
|
elseif ($c == "u") { |
|
419
|
|
|
// read just 16bit (therefore value can't be negative) |
|
420
|
|
|
$hex = hexdec(substr($json, $n + 1, 4)); |
|
421
|
|
|
$n += 4; |
|
422
|
|
|
// Unicode ranges |
|
423
|
|
|
if ($hex < 0x80) { // plain ASCII character |
|
424
|
|
|
$val .= chr($hex); |
|
425
|
|
|
} elseif ($hex < 0x800) { // 110xxxxx 10xxxxxx |
|
426
|
|
|
$val .= chr(0xC0 + $hex >> 6) . chr(0x80 + $hex & 63); |
|
427
|
|
|
} elseif ($hex <= 0xFFFF) { // 1110xxxx 10xxxxxx 10xxxxxx |
|
428
|
|
|
$val .= chr(0xE0 + $hex >> 12) . chr(0x80 + ($hex >> 6) & 63) . chr(0x80 + $hex & 63); |
|
429
|
|
|
} |
|
430
|
|
|
// other ranges, like 0x1FFFFF=0xF0, 0x3FFFFFF=0xF8 and 0x7FFFFFFF=0xFC do not apply |
|
|
|
|
|
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
// no escape, just a redundant backslash |
|
434
|
|
|
//@COMPAT: we could throw an exception here |
|
435
|
|
|
else { |
|
436
|
|
|
$val .= "\\" . $c; |
|
437
|
|
|
} |
|
438
|
|
|
} // end of string |
|
439
|
|
|
elseif ($c == '"') { |
|
440
|
|
|
$state = 0; |
|
441
|
|
|
} // yeeha! a single character found!!!!1! |
|
|
|
|
|
|
442
|
|
|
else/* if (ord($c) >= 32) */ { //@COMPAT: specialchars check - but native json doesn't do it? |
|
|
|
|
|
|
443
|
|
|
$val .= $c; |
|
444
|
|
|
} |
|
445
|
|
|
} #-> end of sub-call (array/object) |
|
446
|
|
|
elseif ($waitfor && (strpos($waitfor, $c) !== false)) { |
|
447
|
|
|
return array($val, $n); // return current value and state |
|
448
|
|
|
} #-= in-array |
|
449
|
|
|
elseif ($state === ']') { |
|
450
|
|
|
list($v, $n) = json_decode($json, 0, $n, 0, ",]"); |
|
|
|
|
|
|
451
|
|
|
$val[] = $v; |
|
452
|
|
|
if ($json[$n] == "]") { |
|
453
|
|
|
return array($val, $n); |
|
454
|
|
|
} |
|
455
|
|
|
} #-= in-object |
|
456
|
|
|
elseif ($state === '}') { |
|
457
|
|
|
list($i, $n) = json_decode($json, 0, $n, 0, ":"); // this allowed non-string indicies |
|
|
|
|
|
|
458
|
|
|
list($v, $n) = json_decode($json, 0, $n + 1, 0, ",}"); |
|
|
|
|
|
|
459
|
|
|
$val[$i] = $v; |
|
460
|
|
|
if ($json[$n] == "}") { |
|
461
|
|
|
return array($val, $n); |
|
462
|
|
|
} |
|
463
|
|
|
} #-- looking for next item (0) |
|
464
|
|
|
else { |
|
465
|
|
|
|
|
466
|
|
|
#-> whitespace |
|
467
|
|
|
if (preg_match("/\s/", $c)) { |
|
|
|
|
|
|
468
|
|
|
// skip |
|
469
|
|
|
} #-> string begin |
|
470
|
|
|
elseif ($c == '"') { |
|
471
|
|
|
$state = '"'; |
|
472
|
|
|
} #-> object |
|
473
|
|
|
elseif ($c == "{") { |
|
474
|
|
|
list($val, $n) = json_decode($json, $assoc, $n + 1, '}', "}"); |
|
475
|
|
|
if ($val && $n && !$assoc) { |
|
476
|
|
|
$obj = new stdClass(); |
|
477
|
|
|
foreach ($val as $i => $v) { |
|
478
|
|
|
$obj->{$i} = $v; |
|
479
|
|
|
} |
|
480
|
|
|
$val = $obj; |
|
481
|
|
|
unset($obj); |
|
482
|
|
|
} |
|
483
|
|
|
} #-> array |
|
484
|
|
|
elseif ($c == "[") { |
|
485
|
|
|
list($val, $n) = json_decode($json, $assoc, $n + 1, ']', "]"); |
|
486
|
|
|
} #-> comment |
|
487
|
|
|
elseif (($c == "/") && ($json[$n + 1] == "*")) { |
|
488
|
|
|
// just find end, skip over |
|
489
|
|
|
($n = strpos($json, "*/", $n + 1)) or ($n = strlen($json)); |
|
|
|
|
|
|
490
|
|
|
} #-> numbers |
|
491
|
|
|
elseif (preg_match("#^(-?\d+(?:\.\d+)?)(?:[eE]([-+]?\d+))?#", substr($json, $n), $uu)) { |
|
492
|
|
|
$val = $uu[1]; |
|
493
|
|
|
$n += strlen($uu[0]) - 1; |
|
494
|
|
|
if (strpos($val, ".")) { // float |
|
495
|
|
|
$val = (float)$val; |
|
496
|
|
|
} elseif ($val[0] == "0") { // oct |
|
497
|
|
|
$val = octdec($val); |
|
498
|
|
|
} else { |
|
499
|
|
|
$val = (int)$val; |
|
500
|
|
|
} |
|
501
|
|
|
// exponent? |
|
502
|
|
|
if (isset($uu[2])) { |
|
503
|
|
|
$val *= pow(10, (int)$uu[2]); |
|
504
|
|
|
} |
|
505
|
|
|
} #-> boolean or null |
|
|
|
|
|
|
506
|
|
|
elseif (preg_match("#^(true|false|null)\b#", substr($json, $n), $uu)) { |
|
507
|
|
|
$val = $lang_eq[$uu[1]]; |
|
508
|
|
|
$n += strlen($uu[1]) - 1; |
|
509
|
|
|
} #-- parsing error |
|
510
|
|
|
else { |
|
511
|
|
|
// PHPs native json_decode() breaks here usually and QUIETLY |
|
512
|
|
|
trigger_error("json_decode: error parsing '$c' at position $n", E_USER_WARNING); |
|
513
|
|
|
|
|
514
|
|
|
return $waitfor ? array(null, 1 << 30) : null; |
|
515
|
|
|
} |
|
516
|
|
|
}//state |
|
517
|
|
|
#-- next char |
|
518
|
|
|
if ($n === null) { |
|
519
|
|
|
return null; |
|
520
|
|
|
} |
|
521
|
|
|
$n++; |
|
522
|
|
|
}//for |
|
523
|
|
|
#-- final result |
|
524
|
|
|
return ($val); |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
|
|
function _htmlDistance($distance) |
|
530
|
|
|
{ |
|
531
|
|
|
$integer = intval($distance); |
|
|
|
|
|
|
532
|
|
|
$decimalPosition = strrpos($distance, '.'); |
|
533
|
|
|
$decimal = $decimalPosition === false ? false : substr($distance, $decimalPosition); |
|
534
|
|
|
|
|
535
|
|
|
return intval($distance) . ($decimal ? '<small>' . $decimal . '</small>' : ''); |
|
536
|
|
|
} |
|
537
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.