|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Include file if exists. |
|
5
|
|
|
* |
|
6
|
|
|
* @return include|false |
|
|
|
|
|
|
7
|
|
|
*/ |
|
8
|
|
|
function inc(string $file) |
|
9
|
|
|
{ |
|
10
|
|
|
return file_exists($file) ? include $file : false; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Sort array key ascending multidimensional supported. |
|
15
|
|
|
* |
|
16
|
|
|
* @return array |
|
17
|
|
|
*/ |
|
18
|
|
|
function sort_iterable(array $arrayObj) |
|
19
|
|
|
{ |
|
20
|
|
|
$arrayObj = array_map(function ($object) { |
|
21
|
|
|
if (\ArrayHelper\helper::is_iterable($object)) { |
|
22
|
|
|
$object = sort_iterable($object); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
return $object; |
|
26
|
|
|
}, $arrayObj); |
|
27
|
|
|
ksort($arrayObj); |
|
28
|
|
|
|
|
29
|
|
|
return $arrayObj; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Exit var_dump with text/plain header. |
|
34
|
|
|
* |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
function ev() |
|
38
|
|
|
{ |
|
39
|
|
|
$args = func_get_args(); |
|
40
|
|
|
if (1 == count($args)) { |
|
41
|
|
|
$args = $args[0]; |
|
42
|
|
|
} |
|
43
|
|
|
if (!headers_sent()) { |
|
44
|
|
|
header('Content-Type: text/plain; charset=utf-8'); |
|
45
|
|
|
} |
|
46
|
|
|
exit(var_dump($args)); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Var Dump with removing all previous obstacles. |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
|
function vd() |
|
55
|
|
|
{ |
|
56
|
|
|
$args = func_get_args(); |
|
57
|
|
|
if (1 == count($args)) { |
|
58
|
|
|
$args = $args[0]; |
|
59
|
|
|
} |
|
60
|
|
|
if (ob_get_level()) { |
|
61
|
|
|
ob_end_clean(); |
|
62
|
|
|
} |
|
63
|
|
|
var_dump($args); |
|
|
|
|
|
|
64
|
|
|
exit; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Exit var_dump with JSON header. |
|
69
|
|
|
* |
|
70
|
|
|
* @param [type] ...$a |
|
|
|
|
|
|
71
|
|
|
* |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
function evj(...$a) |
|
75
|
|
|
{ |
|
76
|
|
|
\JSON\json::json($a); |
|
77
|
|
|
exit; |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Fastest Unique ID Generator. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $length default 5 |
|
84
|
|
|
*/ |
|
85
|
|
|
function uid(int $length = 5) |
|
86
|
|
|
{ |
|
87
|
|
|
return bin2hex(openssl_random_pseudo_bytes($length / 2)); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Clean string from multiple whitespaces. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $string |
|
94
|
|
|
* |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
function clean_string($string) |
|
98
|
|
|
{ |
|
99
|
|
|
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. |
|
100
|
|
|
|
|
101
|
|
|
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Local path to url path conversion. |
|
106
|
|
|
* |
|
107
|
|
|
* @param string|array $locations |
|
108
|
|
|
*/ |
|
109
|
|
|
function get_urlpath($locations) |
|
110
|
|
|
{ |
|
111
|
|
|
/** |
|
112
|
|
|
* @var string|null $get |
|
113
|
|
|
*/ |
|
114
|
|
|
$get = function (string $location) { |
|
115
|
|
|
if (file_exists($location)) { |
|
116
|
|
|
return \MVC\helper::get_url_path($location, true); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return null; |
|
120
|
|
|
}; |
|
121
|
|
|
if (is_string($locations)) { |
|
122
|
|
|
return $get($locations); |
|
123
|
|
|
} elseif (\ArrayHelper\helper::is_iterable($locations)) { |
|
124
|
|
|
foreach ($locations as $location) { |
|
125
|
|
|
$result = $get($location); |
|
126
|
|
|
if ($result) { |
|
127
|
|
|
return $result; |
|
128
|
|
|
break; |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return null; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Include asset with fallback and callback. |
|
138
|
|
|
* * if found automatically call include(). |
|
139
|
|
|
* |
|
140
|
|
|
* @author Dimas Lanjaka <[email protected]> |
|
141
|
|
|
* |
|
142
|
|
|
* @param string $fn first file to check |
|
143
|
|
|
* @param string $fn2 fallback file to check |
|
144
|
|
|
* @param function|null $callback if not exists both, shoul we calling the callback |
|
|
|
|
|
|
145
|
|
|
* |
|
146
|
|
|
* @return void always void |
|
147
|
|
|
*/ |
|
148
|
|
|
function include_asset($fn, $fn2 = null, $callback = null) |
|
149
|
|
|
{ |
|
150
|
|
|
if (file_exists($fn)) { |
|
151
|
|
|
include $fn; |
|
152
|
|
|
} elseif ($fn2 && file_exists($fn2)) { |
|
153
|
|
|
include $fn2; |
|
154
|
|
|
} elseif (is_callable($callback)) { |
|
155
|
|
|
call_user_func($callback, $fn); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Create <pre/> element from array. |
|
161
|
|
|
* |
|
162
|
|
|
* @return void |
|
163
|
|
|
*/ |
|
164
|
|
|
function pre() |
|
165
|
|
|
{ |
|
166
|
|
|
$obj = func_get_args(); |
|
167
|
|
|
echo '<pre style="word-wrap: break-word;">'; |
|
168
|
|
|
if (count($obj) > 1) { |
|
169
|
|
|
foreach ($obj as $objek) { |
|
170
|
|
|
\JSON\json::json($objek, false, true); |
|
171
|
|
|
} |
|
172
|
|
|
} else { |
|
173
|
|
|
\JSON\json::json($obj[0], false, true); |
|
174
|
|
|
} |
|
175
|
|
|
echo '</pre>'; |
|
176
|
|
|
} |
|
177
|
|
|
/** |
|
178
|
|
|
* var_dump in <pre/>. |
|
179
|
|
|
* |
|
180
|
|
|
* @return void |
|
181
|
|
|
*/ |
|
182
|
|
|
function predump() |
|
183
|
|
|
{ |
|
184
|
|
|
$obj = func_get_args(); |
|
185
|
|
|
echo '<pre style="word-wrap: break-word;">'; |
|
186
|
|
|
if (count($obj) > 1) { |
|
187
|
|
|
foreach ($obj as $objek) { |
|
188
|
|
|
var_dump($objek); |
|
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
} else { |
|
191
|
|
|
var_dump($obj[0]); |
|
192
|
|
|
} |
|
193
|
|
|
echo '</pre>'; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Exit JSON. |
|
198
|
|
|
* |
|
199
|
|
|
* @param mixed $result |
|
200
|
|
|
* |
|
201
|
|
|
* @return void |
|
202
|
|
|
*/ |
|
203
|
|
|
function e() |
|
204
|
|
|
{ |
|
205
|
|
|
$results = func_get_args(); |
|
206
|
|
|
if (count($results) > 1) { |
|
207
|
|
|
foreach ($results as $check) { |
|
208
|
|
|
if (is_string($check) && \JSON\json::is_json($check)) { |
|
209
|
|
|
$check = json_decode($check); |
|
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
} else { |
|
213
|
|
|
$results = $results[0]; |
|
214
|
|
|
} |
|
215
|
|
|
\JSON\json::json($results); |
|
216
|
|
|
exit; |
|
|
|
|
|
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
if (!function_exists('is_json')) { |
|
220
|
|
|
/** |
|
221
|
|
|
* Check is json string. |
|
222
|
|
|
* |
|
223
|
|
|
* @return bool |
|
224
|
|
|
*/ |
|
225
|
|
|
function is_json(string $string) |
|
226
|
|
|
{ |
|
227
|
|
|
return \JSON\json::is_json($string); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Header redirect. |
|
233
|
|
|
*/ |
|
234
|
|
|
function redirect(string $url, bool $exit = true) |
|
235
|
|
|
{ |
|
236
|
|
|
header("Location: $url"); |
|
237
|
|
|
if ($exit) { |
|
238
|
|
|
exit; |
|
|
|
|
|
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Header redirect advance. |
|
244
|
|
|
*/ |
|
245
|
|
|
function safe_redirect(string $url, bool $exit = true) |
|
246
|
|
|
{ |
|
247
|
|
|
if (!headers_sent()) { |
|
248
|
|
|
return redirect($url, $exit); |
|
|
|
|
|
|
249
|
|
|
} else { |
|
250
|
|
|
echo '<script>location.href = `' . $url . '`;</script>'; |
|
251
|
|
|
} |
|
252
|
|
|
if ($exit) { |
|
253
|
|
|
exit; |
|
|
|
|
|
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Get latest file from folder. |
|
259
|
|
|
* |
|
260
|
|
|
* @param array $path Folder path array list |
|
261
|
|
|
* @param bool $return_timestamp false return filename |
|
262
|
|
|
* ```php |
|
263
|
|
|
* latestFile([__DIR__ . '/src/MVC/', __DIR__ . '/libs/', __DIR__ . '/views/']) |
|
264
|
|
|
* ``` |
|
265
|
|
|
*/ |
|
266
|
|
|
function latestFile(array $path, bool $return_timestamp = true) |
|
267
|
|
|
{ |
|
268
|
|
|
$timestamp = 0; |
|
269
|
|
|
$file = ''; |
|
270
|
|
|
|
|
271
|
|
|
foreach ($path as $str_path) { |
|
272
|
|
|
if (!is_dir($str_path)) { |
|
273
|
|
|
continue; |
|
274
|
|
|
} |
|
275
|
|
|
$cls_rii = new \RecursiveIteratorIterator( |
|
276
|
|
|
new \RecursiveDirectoryIterator($str_path), |
|
277
|
|
|
\RecursiveIteratorIterator::CHILD_FIRST |
|
278
|
|
|
); |
|
279
|
|
|
|
|
280
|
|
|
$ary_files = []; |
|
281
|
|
|
|
|
282
|
|
|
foreach ($cls_rii as $str_fullfilename => $cls_spl) { |
|
283
|
|
|
if ($cls_spl->isFile()) { |
|
284
|
|
|
$ary_files[] = $str_fullfilename; |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
$ary_files = array_combine( |
|
289
|
|
|
$ary_files, |
|
290
|
|
|
array_map('filemtime', $ary_files) |
|
291
|
|
|
); |
|
292
|
|
|
|
|
293
|
|
|
arsort($ary_files); |
|
|
|
|
|
|
294
|
|
|
$time = $ary_files[key($ary_files)]; |
|
295
|
|
|
if ($time > $timestamp) { |
|
296
|
|
|
$file = key($ary_files); |
|
297
|
|
|
$timestamp = $time; |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
if ($return_timestamp) { |
|
301
|
|
|
return $timestamp; |
|
302
|
|
|
} else { |
|
303
|
|
|
return $file; |
|
304
|
|
|
} |
|
305
|
|
|
//echo "file:" . $file . "\n"; |
|
306
|
|
|
//echo "time:" . $time; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Disable direct access static php. |
|
311
|
|
|
*/ |
|
312
|
|
|
function disable_direct_access_php(string $file) |
|
313
|
|
|
{ |
|
314
|
|
|
if (!file_exists(dirname($file) . '/.htaccess')) { |
|
315
|
|
|
\Filemanager\file::file(dirname($file) . '/.htaccess', 'RewriteEngine On |
|
|
|
|
|
|
316
|
|
|
RewriteRule ^.*\.php$ - [F,L,NC] |
|
317
|
|
|
<Files (file|class)\.php> |
|
318
|
|
|
order allow,deny |
|
319
|
|
|
deny from all |
|
320
|
|
|
allow from 127.0.0.1 |
|
321
|
|
|
allow from 192.168.0.1 |
|
322
|
|
|
</Files>', true); |
|
323
|
|
|
} |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* Create nested folder recursively. |
|
328
|
|
|
* |
|
329
|
|
|
* @return string $dir |
|
330
|
|
|
*/ |
|
331
|
|
|
function resolve_dir(string $dir) |
|
332
|
|
|
{ |
|
333
|
|
|
$dir = normalize_path($dir); |
|
334
|
|
|
recursive_mkdir($dir); |
|
335
|
|
|
|
|
336
|
|
|
return $dir; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* Disable output buffering. |
|
341
|
|
|
* |
|
342
|
|
|
* @return void |
|
343
|
|
|
*/ |
|
344
|
|
|
function disable_buffering() |
|
345
|
|
|
{ |
|
346
|
|
|
// Turn off output buffering |
|
347
|
|
|
ini_set('output_buffering', 'off'); |
|
348
|
|
|
// Turn off PHP output compression |
|
349
|
|
|
ini_set('zlib.output_compression', false); |
|
|
|
|
|
|
350
|
|
|
|
|
351
|
|
|
//Flush (send) the output buffer and turn off output buffering |
|
352
|
|
|
while (@ob_end_flush()); |
|
353
|
|
|
|
|
354
|
|
|
// Implicitly flush the buffer(s) |
|
355
|
|
|
ini_set('implicit_flush', true); |
|
|
|
|
|
|
356
|
|
|
ob_implicit_flush(true); |
|
|
|
|
|
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* Disable user abort. |
|
361
|
|
|
* |
|
362
|
|
|
* @return ignore_user_abort|null |
|
|
|
|
|
|
363
|
|
|
*/ |
|
364
|
|
|
function disable_abort(bool $abort = false) |
|
365
|
|
|
{ |
|
366
|
|
|
if (function_exists('ignore_user_abort')) { |
|
367
|
|
|
return ignore_user_abort($abort); |
|
|
|
|
|
|
368
|
|
|
} |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
function is_aborted() |
|
372
|
|
|
{ |
|
373
|
|
|
return CONNECTION_NORMAL != connection_status(); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
/** |
|
377
|
|
|
* set Limit execution. |
|
378
|
|
|
* |
|
379
|
|
|
* @return set_time_limit|null |
|
|
|
|
|
|
380
|
|
|
*/ |
|
381
|
|
|
function set_limit(int $secs = 0) |
|
382
|
|
|
{ |
|
383
|
|
|
if (function_exists('set_time_limit')) { |
|
384
|
|
|
return set_time_limit($secs); |
|
|
|
|
|
|
385
|
|
|
} |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* Create dir recursively. |
|
390
|
|
|
* |
|
391
|
|
|
* @param int $permissions |
|
392
|
|
|
* @param bool $recursive |
|
393
|
|
|
*/ |
|
394
|
|
|
function recursive_mkdir(string $dest, $permissions = 0755, $recursive = true) |
|
395
|
|
|
{ |
|
396
|
|
|
if (!is_dir(dirname($dest))) { |
|
397
|
|
|
recursive_mkdir(dirname($dest), $permissions, $recursive); |
|
398
|
|
|
} |
|
399
|
|
|
if (!file_exists($dest)) { |
|
400
|
|
|
try { |
|
401
|
|
|
mkdir($dest, $permissions, $recursive); |
|
402
|
|
|
|
|
403
|
|
|
return true; |
|
404
|
|
|
} catch (\Throwable $th) { |
|
405
|
|
|
return false; |
|
406
|
|
|
} |
|
407
|
|
|
} else { |
|
408
|
|
|
return true; |
|
409
|
|
|
} |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
function resolve_file(string $file, string $content = '') |
|
413
|
|
|
{ |
|
414
|
|
|
if (!is_dir(dirname($file))) { |
|
415
|
|
|
resolve_dir(dirname($file)); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
if (!file_exists($file)) { |
|
419
|
|
|
file_put_contents($file, $content); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
return $file; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* Convert Windows path to UNIX path. |
|
427
|
|
|
* |
|
428
|
|
|
* @return string |
|
429
|
|
|
*/ |
|
430
|
|
|
function normalize_path(string $path) |
|
431
|
|
|
{ |
|
432
|
|
|
$path = str_replace('\\', '/', $path); |
|
433
|
|
|
$path = preg_replace('|(?<=.)/+|', '/', $path); |
|
434
|
|
|
$path = preg_replace('/\/{2,99}/s', '/', $path); |
|
435
|
|
|
if (':' === substr($path, 1, 1)) { |
|
436
|
|
|
$path = ucfirst($path); |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
return $path; |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* Remove root from path. |
|
444
|
|
|
*/ |
|
445
|
|
|
function remove_root(string $path) |
|
446
|
|
|
{ |
|
447
|
|
|
$path = normalize_path($path); |
|
448
|
|
|
$path = str_replace(normalize_path(ROOT), '', $path); |
|
449
|
|
|
|
|
450
|
|
|
return $path; |
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
|
|
/** |
|
454
|
|
|
* Shell runner. |
|
455
|
|
|
* |
|
456
|
|
|
* @return string|null |
|
457
|
|
|
*/ |
|
458
|
|
|
function shell(string $command) |
|
459
|
|
|
{ |
|
460
|
|
|
$output = null; |
|
461
|
|
|
if (function_exists('shell_exec')) { |
|
462
|
|
|
$output = shell_exec($command); |
|
463
|
|
|
} elseif (function_exists('exec')) { |
|
464
|
|
|
exec($command, $output); |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
return \ArrayHelper\helper::is_iterable($output) ? \JSON\json::json($output, false, false) : $output; |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* Check shell can be executed. |
|
472
|
|
|
* |
|
473
|
|
|
* @return string|null |
|
474
|
|
|
*/ |
|
475
|
|
|
function shell_check() |
|
476
|
|
|
{ |
|
477
|
|
|
if (function_exists('shell_exec')) { |
|
478
|
|
|
return 'shell_exec'; |
|
479
|
|
|
} elseif (function_exists('exec')) { |
|
480
|
|
|
return 'exec'; |
|
481
|
|
|
} else { |
|
482
|
|
|
return null; |
|
483
|
|
|
} |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
function shell_required($callback) |
|
|
|
|
|
|
487
|
|
|
{ |
|
488
|
|
|
$result = []; |
|
489
|
|
|
if ('string' != gettype(shell_check()) || !\MVC\helper::env('dev')) { |
|
490
|
|
|
$result = ['error' => true, 'message' => 'Cannot execute command here environtment(' . \MVC\helper::env('dev') . ') command(' . gettype(shell_check()) . ')', 'title' => 'Cannot Access This Page']; |
|
491
|
|
|
} |
|
492
|
|
|
if (!empty($result)) { |
|
493
|
|
|
if (headers_sent()) { |
|
494
|
|
|
exit('<div class="alert alert-danger"> |
|
|
|
|
|
|
495
|
|
|
<span class="alert-title"> ' . $result['title'] . ' </span> |
|
496
|
|
|
</div>'); |
|
497
|
|
|
} |
|
498
|
|
|
} |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
/** |
|
502
|
|
|
* ```php |
|
503
|
|
|
* // callback if function |
|
504
|
|
|
* call_user_func($callback, $path) |
|
505
|
|
|
* ``` |
|
506
|
|
|
* Read file contents. |
|
507
|
|
|
* |
|
508
|
|
|
* @author Dimas Lanjaka <[email protected]> |
|
509
|
|
|
* |
|
510
|
|
|
* @param mixed $callback if null not exist return this callback |
|
511
|
|
|
* |
|
512
|
|
|
* @return string|null NULL if not exists |
|
513
|
|
|
*/ |
|
514
|
|
|
function read_file(string $path, $callback = null) |
|
515
|
|
|
{ |
|
516
|
|
|
if (file_exists($path) && is_readable($path)) { |
|
517
|
|
|
if (function_exists('file_get_contents')) { |
|
518
|
|
|
return file_get_contents($path); |
|
519
|
|
|
} else { |
|
520
|
|
|
$handle = fopen($path, 'r'); |
|
521
|
|
|
$contents = fread($handle, filesize($path)); |
|
|
|
|
|
|
522
|
|
|
fclose($handle); |
|
|
|
|
|
|
523
|
|
|
|
|
524
|
|
|
return $contents; |
|
525
|
|
|
} |
|
526
|
|
|
} |
|
527
|
|
|
if (is_callable($callback)) { |
|
528
|
|
|
return call_user_func($callback, $path); |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
return $callback; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
function write_file(string $path, $content, bool $force = false) |
|
535
|
|
|
{ |
|
536
|
|
|
resolve_dir(dirname($path)); |
|
537
|
|
|
if (\ArrayHelper\helper::is_iterable($content)) { |
|
538
|
|
|
$content = json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
539
|
|
|
} |
|
540
|
|
|
if ($force || !file_exists($path)) { |
|
541
|
|
|
if (!function_exists('file_put_contents')) { |
|
542
|
|
|
$fh = fopen($path, 'wa+'); |
|
543
|
|
|
fwrite($path, $content); |
|
|
|
|
|
|
544
|
|
|
fclose($fh); |
|
|
|
|
|
|
545
|
|
|
} else { |
|
546
|
|
|
file_put_contents($path, $content); |
|
547
|
|
|
} |
|
548
|
|
|
} |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
function htmlcomment() |
|
552
|
|
|
{ |
|
553
|
|
|
return '<comment style="display:none"> ' . json_encode(func_get_args(), JSON_PRETTY_PRINT) . ' </comment>'; |
|
554
|
|
|
} |
|
555
|
|
|
|
|
556
|
|
|
function parse_newline(string $str) |
|
557
|
|
|
{ |
|
558
|
|
|
$str = str_replace("\r", '', $str); |
|
559
|
|
|
$parsed = explode("\n", $str); |
|
560
|
|
|
if ($parsed) { |
|
|
|
|
|
|
561
|
|
|
return $parsed; |
|
562
|
|
|
} |
|
563
|
|
|
|
|
564
|
|
|
return []; |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
/** |
|
568
|
|
|
* Get Output Buffer Content And Re-construct current output buffer. |
|
569
|
|
|
* |
|
570
|
|
|
* @return string|false |
|
571
|
|
|
*/ |
|
572
|
|
|
function ob_get() |
|
573
|
|
|
{ |
|
574
|
|
|
$content = ob_get_clean(); |
|
575
|
|
|
ob_end_clean(); |
|
576
|
|
|
ob_start(); |
|
577
|
|
|
|
|
578
|
|
|
return $content; |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
$imageCache = null; |
|
582
|
|
|
function imgCDN(string $url) |
|
583
|
|
|
{ |
|
584
|
|
|
global $imageCache; |
|
585
|
|
|
if (!$imageCache) { |
|
586
|
|
|
$imageCache = new \img\cache(); |
|
587
|
|
|
} |
|
588
|
|
|
$imageCache->url2cache($url); |
|
589
|
|
|
} |
|
590
|
|
|
|
|
591
|
|
|
/** |
|
592
|
|
|
* htaccess generator. |
|
593
|
|
|
* |
|
594
|
|
|
* @param bool $deny default deny access. default (true) |
|
595
|
|
|
* @param bool $DirectPHP allow direct php access. default (false) |
|
596
|
|
|
* @param bool $allowStatic allow static files access. default (true) |
|
597
|
|
|
*/ |
|
598
|
|
|
function htaccess($deny = true, $DirectPHP = false, $allowStatic = true) |
|
599
|
|
|
{ |
|
600
|
|
|
$ht = ''; |
|
601
|
|
|
if ($deny) { |
|
602
|
|
|
$ht .= 'deny from all'; |
|
603
|
|
|
} |
|
604
|
|
|
if (!$DirectPHP) { |
|
605
|
|
|
$ht .= 'RewriteEngine On |
|
606
|
|
|
RewriteRule ^.*\.php$ - [F,L,NC] |
|
607
|
|
|
<Files (file|class)\.php> |
|
608
|
|
|
order allow,deny |
|
609
|
|
|
deny from all |
|
610
|
|
|
allow from 127.0.0.1 |
|
611
|
|
|
allow from 192.168.0.1 |
|
612
|
|
|
</Files>'; |
|
613
|
|
|
} |
|
614
|
|
|
if ($allowStatic) { |
|
615
|
|
|
$ht .= '<Files ~ "\.(css|js|png|jpg|svg|jpeg|ico|gif)$"> |
|
616
|
|
|
Allow from all |
|
617
|
|
|
</Files>'; |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
return $ht; |
|
621
|
|
|
} |
|
622
|
|
|
|
|
623
|
|
|
/** |
|
624
|
|
|
* Is valid email ? |
|
625
|
|
|
* |
|
626
|
|
|
* @param string $email |
|
627
|
|
|
* |
|
628
|
|
|
* @return bool |
|
629
|
|
|
*/ |
|
630
|
|
|
function is_email($email) |
|
631
|
|
|
{ |
|
632
|
|
|
return filter_var($email, FILTER_VALIDATE_EMAIL); |
|
633
|
|
|
} |
|
634
|
|
|
|
|
635
|
|
|
/** |
|
636
|
|
|
* Is valid url ? |
|
637
|
|
|
* |
|
638
|
|
|
* @param string $url |
|
639
|
|
|
* |
|
640
|
|
|
* @return bool |
|
641
|
|
|
*/ |
|
642
|
|
|
function is_url($url) |
|
643
|
|
|
{ |
|
644
|
|
|
return filter_var($url, FILTER_VALIDATE_URL); |
|
645
|
|
|
} |
|
646
|
|
|
|
|
647
|
|
|
include __DIR__ . '/../MVC/themes/assets/partial/fab.php'; |
|
648
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths