-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncdown.php
More file actions
3510 lines (2943 loc) · 119 KB
/
funcdown.php
File metadata and controls
3510 lines (2943 loc) · 119 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php /// Funcdown Standalone ("multispace") variant
declare (strict_types = 1);
/*:Licence -> https://hngts.com/?mkp=licence~fncd
^: ~ See https://hngts.com/?mkp=fncd~manual for more details.
*/
namespace {
///
new class (E: 'UTF-8') {
///
public function __construct (string $E) {
/*: Mandatory Charset Encoding Setup
Defines few very handy constants;
Sets charset to utf-8 wherever known.
The stuff with charset might become obsoleted.
*/
foreach ([
0 => 'default_charset',
1 => 'mb_internal_encoding',
2 => 'mb_http_output',
'EOL' => PHP_EOL,
'NSP' => "\134",
'DSP' => DIRECTORY_SEPARATOR,
'PSP' => PATH_SEPARATOR,
'CFG' => '.conf.d',
'_' => str_repeat ('_', 4)
] as $index => $value):
((is_int ($index))
? (($index === 0)
? ((ini_get ($value) === $E) or ini_set ($value, $E))
: (($value() === $E) or $value ($E)))
: (!defined ($index) and define ($index, $value))
); unset ($value, $index);
endforeach;
}
};
function e (&$a, mixed $b, bool $c = false, mixed $d = null): bool {
/*: .. and or equals with whatever you put!
This little function can change the way You looked and wrote
code so far. Pay attention to its usage below. And not only that.
As much simple as it is, it will tell You which variables You should
never put to reference.
*/ $a = $b; return ((!$c) ? ($a === $b) : ($a === $d));
}
}
namespace H\Root {
///
use \SplFileObject as SFobject; ///
use \SplTempFileObject as STFobject; ///
use \FilesystemIterator as FSiterator; ///
use \H\OctalPunctuation as P; ///
trait replacement_compressor {
/// Hardcoder's crud_engine foundation implementation.
protected const RPL_SET = [
/// Major replacement holder
'_' => // HTML Raw/xml representation of risky (user/guest provided) characters
[
0 => [ // Real chars
0 => P::C['amp'], // '&',
1 => P::C['lt'], // '<',
2 => P::C['gt'], // '>',
3 => P::C['qt'], // '"',
4 => P::C['ap'], // "'",
5 => P::C['bl'], // '(',
6 => P::C['br'], // ')',
7 => P::C['c'], // ':',
8 => P::C['eq'], // '=',
9 => P::C['qm'], // '?',
10 => P::C['a'], // '@',
11 => P::C['sl'], // '[',
12 => P::C['sr'], // ']',
13 => P::C['bt'], // '`',
14 => P::C['cl'], // '{',
15 => P::C['b'], // '|',
16 => P::C['cr'], // '}',
17 => P::C['ss'], // '/'
18 => P::C['cm'], // ','
19 => P::C['esc'],// '\'
20 => P::C['ps'], // '+'
21 => P::C['p'] // '%'
],
1 => [ // XML decimal entities
0 => '&',
1 => '<',
2 => '>',
3 => '"',
4 => ''',
5 => '(',
6 => ')',
7 => ':',
8 => '=',
9 => '?',
10 => '@',
11 => '[',
12 => ']',
13 => '`',
14 => '{',
15 => '|',
16 => '}',
17 => '/',
18 => ',',
19 => '\',
20 => '+',
21 => '%',
],
2 => [ // Special, !HALF-printable and non-standard!, unique char-replacements
0 => "\360\237\231\265\363\240\200\246",
1 => "\363\240\200\274\360\223\200\200",
2 => "\363\240\200\276\360\223\200\240",
3 => "\363\240\200\242\360\222\221\242",
4 => "\363\240\200\247\360\220\240\232",
5 => "\363\240\200\250\357\270\265",
6 => "\363\240\200\251\357\270\266",
7 => "\363\240\200\272\357\270\266",
8 => "\363\240\200\275\352\240\265",
9 => "\363\240\200\277\352\230\217",
10 => "\363\240\201\200\341\242\206",
11 => "\363\240\201\233\342\201\205",
12 => "\363\240\201\235\342\201\206",
13 => "\363\240\201\240\340\245\223",
14 => "\363\240\201\273\342\216\261",
15 => "\342\224\213\363\240\201\274",
16 => "\363\240\201\275\357\270\270",
17 => "\363\240\200\257\360\237\231\274",
18 => "\342\271\201\363\240\200\254",
19 => "\363\240\201\234\360\237\231\275",
20 => "\363\240\200\253\357\254\251",
21 => "\363\240\200\245\360\226\254\273",
]],
'ns' => [ // Bypass major punct chars in ctype_*'s
P::C['esc'],P::C['ss'],P::C['c'],P::C['s'],P::C['bt'],P::C['amp'],
P::C['qm'],P::C['sl'],P::C['sr'],P::C['bl'],P::C['br'],P::C['cl'],
P::C['cr'],P::C['eq'],P::C['ps'],P::C['as'],P::C['e'],P::C['a'],
P::C['b'],P::C['t'],P::C['cm'],P::C['qt'],P::C['ap'],
'.','#','%','$','€','£','^'
],
'bs' => [ // Sealed/unsealed base64_
[ '=','/','+', '-','_','.', '*'
],[ "\342\244\272","\342\232\233","\342\214\230",
"\342\236\253","\342\236\264","\342\234\226", "\342\232\231"
]],
'cy' => [ // Cyrillic (Српски) base64 encode/decode
'qwertyuiopasdfghjklzxcvbnm=',
'љњертзуиопасдфгхјклжџцвбнмђ'
]
];
protected function transform_encode ($i, string $s):string {
/// Custom sanitize and unsanitize of special chars
// No integer = No result = No panic.
if (!is_int ($i)) return $s;
$x = ['',''];
switch ($i) {
case 1: // Sanitize (htmlentities() alike)
$x = [ self::RPL_SET['_'][0],
self::RPL_SET['_'][$i]
]; break;
case 2: // Unsanitize (html_entity_decode() alike)
$x = [ self::RPL_SET['_'][1],
self::RPL_SET['_'][0]
]; break;
case 3: // Bypass major punct chars in ctype_*'s
$x = [self::RPL_SET['ns'],['']]; break;
case 4: // Just like htmlspecialchars()
$x = [ array_slice (self::RPL_SET['_'][0], 0, 5),
array_slice (self::RPL_SET['_'][1], 0, 5)
]; break;
case 5: // Just like htmlspecialchars_decode()
$x = [ array_slice (self::RPL_SET['_'][1], 0, 5),
array_slice (self::RPL_SET['_'][0], 0, 5)
]; break;
case 6: // Sealed base64_
$x = [ self::RPL_SET['bs'][0],
self::RPL_SET['bs'][1]
]; break;
case 7: // Unsealed base64_
$x = [ self::RPL_SET['bs'][1],
self::RPL_SET['bs'][0]
]; break;
case 8: // Hard_seal
$s = $this-> {__FUNCTION__} (2, $s); // Make sure it's not encoded.
$s = $this-> {__FUNCTION__} (9, $s); // Make sure it's risky.
$x = [ self::RPL_SET['_'][0], self::RPL_SET['_'][2] ];
break;
case 9: // Hard_UNseal-to-risky
$x = [ self::RPL_SET['_'][2],
self::RPL_SET['_'][0]
]; break;
case 10: // Hard_UNseal-to-safe
return $this-> {__FUNCTION__} (1,
$this-> {__FUNCTION__} (9, $s));
break;
case 11:
// Ideal for javascript takeover of textnodes
return htmlentities ($s, ENT_HTML5);
break;
case 12: case 13: // base64_cyrlic_fashion
$x = [
mb_str_split ( self::RPL_SET['cy'][0]
. mb_strtoupper (self::RPL_SET['cy'][0])
),
mb_str_split ( self::RPL_SET['cy'][1]
. mb_strtoupper (self::RPL_SET['cy'][1])
)
];
if ($i === 12) // cyEnCode
return $this-> string_reverse (str_replace
($x[0], $x[1], base64_encode ($s)));
else if ($i === 13) // cyDeCode
return base64_decode (str_replace
($x[1], $x[0], $this-> string_reverse ($s)));
break;
default: break;
}
return
str_replace ($x[0], $x[1], $s);
}
protected function _compress (mixed $x, int $level = 42, int $gz = 0): mixed {
/// Serialize, compress, encode and seal data
/// $gz: 0 = *compress; 1 = deflate; 2 = encode
${ __FUNCTION__ } = (@($this-> gzmatch (__FUNCTION__, $gz)) ((NSP . 'serialize') ($x), 9));
$fn = [ NSP . 'base64_encode', NSP . 'bin2hex' ]; return match ($level) {
0 => $this-> transform_encode (6, ($fn[0]($_compress))), // HardSeal over base64
1 => $fn[0]($_compress), // Compression-> encode
2 => $fn[1]($_compress), // Compression-> bin2hex
42 => $_compress, // Compressed-> Serialized
default => $x // No change
};
}
protected function _decompress (string $x, int $level = 42, int $gz = 0):mixed {
/// Unseal, decode, deserialize than decompress data
/// $gz: 0 = *decompress; 1 = inflate; 2 = decode
$f = [ NSP . 'unserialize', $this-> gzmatch (__FUNCTION__, $gz),
NSP . 'base64_decode', NSP . 'hex2bin']; return match ($level) {
0 => $f[0] (@$f[1] ($f[2] ($this-> transform_encode (7, $x)))), // HardUNSeal over base64
1 => $f[0] (@$f[1] ($f[2] ($x))), // decompression-> from_encoded-> from_serialized
2 => $f[0] (@$f[1] ($f[3] ($x))), // decompression-> from_hex-> from_serialized
42 => $f[0] (@$f[1] ($x)), // Basic decompression-> from_serialized
default => $x // No change
};
}
private function gzmatch (string $caller, int $match = 0): string {
/// Returns proper gz compression method
return NSP . 'gz' . (match ($match) {
1 => [ 'deflate', 'inflate' ],
2 => [ 'encode', 'decode' ],
default => ['compress', 'uncompress']
})[(($caller === '_compress') ? 0 : 1)];
}
}
trait application_class_obstructor {
///
use replacement_compressor; ///
public function string_reverse ($string): string {
/// Multibyte String Reverse
return implode (array_reverse (mb_str_split ($string)));
}
public function enc (int $i, string $s): string {
/// Public sanitize and unsanitize
return $this-> transform_encode ($i, $s);
}
public function cdc (string $_, mixed $data, int $level = 42, int $gz = 0): mixed {
/// compress/encode/deflate|decompress/decode/inflate data
return match ($_) {
'c' => @$this-> _compress ($data, $level, $gz)
, 'dc' => @$this-> _decompress ($data, $level, $gz)
, default => $data
};
}
public function string_filter_rule (string $string, array $PunctBypass): bool {
/// Detect valid XML tag naming rule and eventually emit bad signal
if (!ctype_print ($string)) return false;
else
{
$a = mb_str_split ($string);
foreach ($a as $b => $c)
{
if ($b === 0 && !ctype_alpha ($c)) {
$a[$b] = null;
break;
}
else if (ctype_punct ($c)
&& !in_array ($c, $PunctBypass)) {
$a[$b] = null;
break;
}
unset ($c, $b);
}
$a = trim (implode ($a));
return ($a === trim ($string));
}
}
public function no_unix_control_chars (string $a): string {
/// Remove unix/shell control characters
return preg_replace ('~[^\P{Cc}\r\n\t]+~u', self::U['ea'], $a);
}
public function no_comments (string $x = "\057\057", string $a = '', array $merge = []): string {
/// Remove '$x+? ' line comments from strings
$a = explode (EOL, $a);
if (count ($a) >= 1) {
$diff = null;
$merged = array_merge (["\176", "\134", ' '], $merge);
foreach ($a as $int => $b) {
foreach ($merged as $sample) {
$p = mb_strpos ($b, "$x$sample");
if ($p !== false) {
$a[$int] = mb_substr ($b, 0, $p);
$diff = $int;
break;
} unset ($p, $sample);
}
if (is_int ($diff) && trim ($a[$diff]) === '') {
unset ($a[$diff]); $diff = null;
} unset ($b, $int);
}
}
return implode (EOL, $a);
}
public function no_block_comments (string $a, string $r = ' '): string {
/// Remove C-style block comments from strings
return preg_replace ('!/\*.*?\*/!s', $r, $a);
}
public function one_line (string $a, bool $TooUgly = false): string {
/// Entire string to one line - ugly or uglier.
return preg_replace ('/\s+/',
((!$TooUgly) ? ' ' : ""),
(($TooUgly) ? $a : trim ($a))
);
}
public function dirOr (
string $dp,
int $p = 0755,
bool $recursive = true,
mixed $context = null
): bool {
/// Check if directory exists, eventually makes one, confims the outcome.
if (!is_dir ($dp)) mkdir ($dp, $p, $recursive, $context);
return is_dir ($dp);
}
public function joinDsp (...$fragments): string {
/// This method exists only because of windblows "OS"-es.
return implode (DSP, $fragments);
}
public function flatten (string $suspect, int $mb = 0): string {
/*: Trim and (mb_)strtolower suspect.
Any other $mb than 1 will not be multibyte.
*/ return trim (((($mb === 1) ? '\\mb_' : '')
. 'strtolower') ($suspect));
}
public function getConstant (string $constant, $class = null): mixed {
/// Return UPPERCASED named constant value if any found.
$datClass = ($class ?? $this); $constant = mb_strtoupper ($constant);
return @(new \ReflectionClass ($datClass))-> {__FUNCTION__} ($constant);
}
public function filesystem_temp_point (string $appname): string {
/// Creates unique proposal place for storing vital data from various extensions
return implode ('-', [ $appname, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'] ]);
}
public function highlight_string (
string $valid_php_code = ''
, string $Php = 'None'
, bool $NoPreWrap = true
, bool $enl = false
, bool $space = true
, bool $custom = true
): string {
/*: For documentation purposes.
Before usage of this function,
alongside appropriate css afterwards,
something like this is needed.
- Once!:
foreach ([ "bg", "comment", "default", "html", "keyword", "string" ]
as $value): \ini_set ("highlight.{$value}", "highlight-{$value}");
unset ($value);
endforeach;
*/
if (e ($Q, explode (' ', "\074\077php \077\076"))) {
e ($el, (($enl) ? EOL : ''));
!str_starts_with (ltrim ($valid_php_code), $Q[0]) and e (
// So that one doesn't need to write php open tags at all
$valid_php_code, $Q[0] . $el . (($space) ? ' ' : '')
. ltrim ($valid_php_code)
);
!str_ends_with (rtrim ($valid_php_code), $Q[1]) and e (
// So that one doesn't need to write php close tags at all
$valid_php_code, rtrim ($valid_php_code) . "{$el} {$Q[1]}"
);
e ($code, (NSP . __FUNCTION__) (
Funcdown-> lintercept ($valid_php_code), true
)) and e ($valid_php_code, null);
}
$custom and e ($code
, str_replace ([
'<code style="color: ',
'<span style="color: ',
'<span class="highlight-html">'. EOL,
'</span>' . EOL . '</span>'. EOL . '</code>',
'</span>'. EOL . '</code>',
'<br />', ' '
], [
'<code class="',
'<span class="',
'<span class="highlight-html">',
'</span></span></code>',
'</span></code>',
EOL, ' '
],
$code));
$NoPreWrap and (
(str_starts_with ($code, '<pre>')
&& str_ends_with ($code, '</pre>'))
and e ($code, mb_substr ($code, 5, -6))
);
e ($PhpTags, [
0 => '<span class="highlight-default">?></span>',
1 => '<span class="highlight-default">?>'. EOL .'</span>'
, '<?php '
, '?>' . EOL
, '?>'
, '<?php'
]);
return str_replace ((match ($Php) {
'Open' => $PhpTags[0], // Just open php tag
'None' => $PhpTags, // Just php source without php tags
default => '' // As is.
}
), '', $code);
}
public function fsIterator (string $directory): FSiterator {
/// Why would anyone use scandir or similar ?
return new FSiterator ($directory, FSiterator::SKIP_DOTS);
}
public function stfObject (
string $filename = '',
string $mode = "r",
bool $useIncludePath = false,
mixed $context = null,
int $maxMemory = -1
): STFobject|SFobject {
/*: Wrapper for built-in SplTempFileObject
Manipulate with files and directories in detailed way,
using memory wrapper if needed, as this Spl part will provide
parent::SplFileInfo - Details about file/dir/link ...
for:
SplFileObject - Treat file as an object.
SplTempFileObject - use memory wrapper for temp files.
*/
return (trim ($filename) === '') ? new STFobject ($maxMemory)
: new SFobject ($filename, $mode, $useIncludePath, $context);
}
public function memory_put_contents (
?STFobject &$stfo,
string &$data,
?int &$bytesIn = -1,
bool $flyCalc = false
): bool {
/*: Similar to file_put_contents only uses direct
php://memory|temp instead of file:// ..
Generates $stfo Object, $bytesIn integer and destroys "$data" !
@stfo = Dynamic SplTempFileObject Instance
@data = String to put into memory
@bytesIn - -1 means as much as allowed. No memory limit
@flyCalc - if false, uses bytesIn or infinity as limit;
- if true, calculates memory limit off the data length;
*/
e ($stfo, $this-> stfObject (maxMemory:(($flyCalc)
? mb_strlen ($data) : ($bytesIn ?? -1))))
and $stfo-> ftruncate(0);
foreach (explode (EOL, $data) as $line => $content) {
$stfo-> fwrite ($content . EOL);
unset ($content, $line);
} $data = null;
e ($bytesIn, $stfo-> ftell()) and $stfo-> rewind();
return is_int ($bytesIn);
}
public function memory_get_contents (
STFobject $Mem, int $from = 0,
?int $to = null
): string {
/// Retrieves either whole contents or
/// offset ($From <> $to))portion from memory.
$new = ''; foreach ($Mem as $line) $new .= $line; unset ($line);
$Mem-> rewind(); return mb_substr ($new, $from, $to);
}
//~ Statics
public static function generate_eval_string (
?string &$check = null,
bool $NullCheck = true
): string {
/*: Generates supposedly safe string for later-on eval('uation').
This method expects that string ( preasumably 'file_get_contents')
is mix of php code and anything else!
*/
$EvIal = null; //~ C-Octal below.
$Q = "\074\077"; //~ LessThan + QuestionMark
$Ack = "\342\220\206:"; //~ Standard PHP tags found
$Spit = "\342\220\202:"; //~ Short Echo tags found
$Mark = "\342\220\232\342\220\233";
//~ ^^^^^ .. forces Bomb to explode
/* <- prepend one '/'
var_dump ($Ack, $Spit, $Mark)&exit;
// Break string into array */
$Bomb = array_filter (explode ($Mark,
str_replace (
[ "{$Q}php", "{$Q}\075", "\077\076" ],
[ "$Mark$Ack", "$Mark$Spit", $Mark ],
$check)));
//~ $check is referenced.
//~ Will be wasted - if!.
if ($NullCheck) $check = $EvIal;
foreach ($Bomb as $n => $str) {
$Test = trim ($str); $EvIal .= match (true) {
default => 'echo '. var_export ($str, true) . ';'
//~ ^^ This is any other than PHP code text.
, (str_starts_with ($Test, $Ack)) => str_replace ($Ack, '', $str)
//~ ^^ This is for string in between regular php tags.
, (str_starts_with ($Test, $Spit)) => 'echo '. str_replace ($Spit, '', $str) . ';'
//~ ^^ This is for string in between 'short-echo' tags.
} . EOL; unset ($Bomb[$n], $n, $str, $Test);
} unset ($Bomb); //~ Destroy Bomb. Just because.
return $EvIal;
}
public static function opcache_invalidate (string $File, bool $del = false): void {
/// Removes dead temp file and invalidate it from opcode_cache if cached.
(function_exists ('opcache_get_status') && is_array (opcache_get_status())
&& opcache_is_script_cached ($File)) and opcache_invalidate ($File, true);
$del and (!file_exists ($File) or unlink ($File));
}
}
}
namespace H {
///
interface OctalPunctuation {
/// Hardcoder's foundation stones.
/// Programming control characters.
const C = [ /// All important, backend punct. chars in C-octal escaped fashion.
'e' => "\041", // Exclamation !
'qt' => "\042", // Quotation "
'amp' => "\046", // Ampersand &
'ap' => "\047", // Apostrophe '
'bl' => "\050", // Brace parenthesis Left (
'br' => "\051", // Brace parenthesis Right )
'as' => "\052", // Asterisk *
'ps' => "\053", // Plus sign +
'cm' => "\054", // Comma ,
'hm' => "\055", // Hypen-minus -
'ss' => "\057", // Solidus /
'c' => "\072", // Colon :
's' => "\073", // Semicolon ;
'lt' => "\074", // Less than <
'eq' => "\075", // Equals sign =
'gt' => "\076", // Greater than >
'qm' => "\077", // Question Mark ?
'a' => "\100", // AT @
'sl' => "\133", // Square Bracket Left [
'esc' => "\134", // \ <- REAL ESCAPE
'sr' => "\135", // Square Bracket Right ]
'bt' => "\140", // Grave accent; BackTick `
'cl' => "\173", // Curly Bracket Left {
'b' => "\174", // Bar |
'cr' => "\175", // Curly Bracket Right }
't' => "\176", // Tilde ~
'p' => "\045", // Percent %
];
const U = [ /// Some specific System Characters - in C-octal escaped fashion.
'tm' => "\342\204\242", // TRADEMARK ™
'sea' => "\342\206\230", // SOUTH EAST ARROW ↘
'lw' => "\342\254\220", // LEFTWARDS ARROW WITH TIP DOWNWARDS ⬐
'ea' => "\342\245\261", // EQUALS SIGN ABOVE RIGHTWARDS ARROW ⥱
'l' => "\302\253", // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK «
'tnode_start' => "\313\273", // RUNIC LETTER LONG-BRANCH-OSS O ˻
'tnode_end' => "\313\271", // RUNIC LETTER OE ˹
];
const MINUTE = 60; ///
const HOUR = (self::MINUTE * 60); ///
}
class Application extends \StdClass implements OctalPunctuation {
/*:*/ use \H\Root\application_class_obstructor; /*:*/
}
}
/*
The above three namespace blocks are dependancy part of Hng-ToolSet.
*/
namespace H\bag\funcdown {
/// Library for the Funcdown Extension
use \H\OctalPunctuation as P; ///
trait Workers {
/// Funcdown parser compound
private function death_signature (string $sig_text): string {
/// Dashed signature for the (have plain text mode in mind) main message.
return $sig_text . EOL . str_repeat ('-', mb_strlen ($sig_text)) . EOL;
}
private function e_code_not_false (string $suspect): never {
///
$this-> strict_rules();
if (!$this-> silent_errors)
print_r ($suspect);
exit;
}
private function strict_rules (string $suspect = 'martyr', string|null $identifier = null): void {
/// Display categorized error/warning messages with custom text (if any).
$addition = $this-> $suspect;
if (is_array ($addition)) $addition = implode (' ', $addition);
$this-> log_identifier = ((is_string ($identifier)) ? $identifier : 'funcdown extension');
$traceslice_debug = $this-> traceslice_debug (debug_backtrace(), $addition);
$this-> log_destruct();
if (!$this-> silent_errors) {
header ('X-Powered-By: Syntax Watcher for PHP-Funcdown');
header ('Content-Type: text/plain; charset=utf-8')&die (
$this-> death_signature (
'** Death of this request is caused by [ '. __METHOD__ .' ]'
) . $traceslice_debug);
}
}
private function traceslice_debug (array $debug_backtrace, $addition = null): string {
/// DEATH messenger's second hand.
$draw = []; array_shift ($debug_backtrace);
$debug_backtrace = array_reverse ($debug_backtrace);
for ($c = 0; $c < count ($debug_backtrace); $c++)
foreach ($debug_backtrace[$c] as $index => $item)
{
if (!is_scalar ($item)) unset ($debug_backtrace[$c][$index]);
else
{
$n = (count ($draw) + 1);
$file = $debug_backtrace[$c]['file'];
$line = $debug_backtrace[$c]['line'];
$type = ($debug_backtrace[$c]['type'] ?? '');
$function = $debug_backtrace[$c]['function'];
$class = ($debug_backtrace[$c]['class'] ?? '');
$proc_type = (($index === 'type'
&& $type !== '') ? 'function' : 'method'
);
$$proc_type = ("$class{$type}$function");
if (!array_key_exists ($file, $draw))
{
$draw[$file] = (" file_$n :" . P::U['ea'] ." $file".
EOL . ' ' . P::U['sea'] . EOL);
}
else
{
$ptn = (" {$proc_type}_name"); // procedure_type_name
$draw[$file] .= " $ptn: {$$proc_type} @ LINE: $line". EOL;
break;
}
}
unset ($item, $index);
}
unset ($c, $debug_backtrace);
$draw = EOL . implode (EOL, array_values ($draw));
$mssgtxt = $addition . EOL .' '. P::U['sea'] . EOL .
' '. self::PROPERTY['e_mssg'][$this-> e_code];
if ($this-> error_logging && property_exists ($this, 'log_identifier')) {
$ServerCoreTest = ((!class_exists ('\\H\\NextGenerationToolset')) ? false : \H\Api::do()-> read ('server_core'));
$logfile_basedir = ((!is_array ($ServerCoreTest)) ? [ 'appool' => $this-> temp_path ] : $this-> cdc ('dc', $ServerCoreTest, 2));
$this-> log_identifier = [
'logfile' => "{$logfile_basedir['appool']}/application_log/hng_funcdown_errors",
'lfcontent'=> ("[" . FUNCDOWN_ATOM_REQUEST . "] problem detected by {$this-> log_identifier}; ".
$addition . EOL . $draw . EOL )
];
}
return ($mssgtxt . (($this-> null_expose) ? '' : EOL . EOL
. EOL . "{$this-> death_signature ('trace_calls:')} {$draw}"));
}
private function log_destruct(): void {
/// Appends error message to php log file. Destroys message afterwards.
if ($this-> error_logging && property_exists ($this, 'log_identifier')
&& is_array ($this-> log_identifier) && (count ($this-> log_identifier) === 2)) {
e ($dname, dirname ($this-> log_identifier['logfile']))
and $this-> dirOr ($dname); unset ($dname);
if (file_put_contents ($this-> log_identifier['logfile'],
$this-> no_unix_control_chars ($this-> log_identifier['lfcontent'])
, FILE_APPEND | LOCK_EX)) unset ($this-> log_identifier);
}
}
private function selective_defaults(): void {
/// Resets all heavy properties, and counters as well
/// (Memory consumption + raw backend processed data) = taken care of.
/// Content is outputted when trigger becomes `release`(d).
is_null (self::$microint) or e (self::$microint, null);
is_null (self::$mcd_transport) or e (self::$mcd_transport, null);
foreach (self::PROPERTY as $pname => $value) {
(property_exists ($this, "$pname") && !in_array (
$pname, [ 'dtd_check', 'tab_depth' ], true
)) and e ($this-> $pname, $value);
unset ($value, $pname);
}
}
private function alter_linter_counter (string $input): void {
/// Three-major + Bar counter
foreach (array_combine
(array_keys ($this-> linter_count),
[ P::C['b'],
[ 'l' => P::C['bl'], 'r' => P::C['br'] ],
[ 'l' => P::C['cl'], 'r' => P::C['cr'] ],
[ 'l' => P::C['sl'], 'r' => P::C['sr'] ]
]) as $lc_index => $char)
$this-> linter_count[$lc_index] = (
(is_array ($char)) ? [
'l' => mb_substr_count ($input, $char['l']),
'r' => mb_substr_count ($input, $char['r'])
] : mb_substr_count ($input, $char)
); unset ($char, $lc_index);
}
private function linter_signal_spark(): void {
/// Seeks for bad signs in one shot via linter_count property
$blank = []; $bar = ($this-> linter_count['bar'] > 0);
$check_test = \array_slice (\array_keys ($this-> linter_count), 1);
foreach ($check_test as $type)
{
$brace_type = [
'l' => ($this-> linter_count[$type]['l'] > 0),
'r' => ($this-> linter_count[$type]['r'] > 0),
'identical' => ($this-> linter_count[$type]['l'] === $this-> linter_count[$type]['r'])
];
if (!$brace_type['identical']) {
$this-> e_code = 'equals_not';
$this-> martyr = 'BRACKET ' . P::U['ea'] . " `$type` unequal.";
break;
}
else {
if (!$brace_type['l'] && !$brace_type['r'])
$blank[$type] = true;
}
unset ($brace_type, $type);
}
if ($this-> e_code === 'equals_not')
return;
$cblank = count ($blank);
if (!$bar && $cblank === 3) {
$this-> e_code = 'no_funcdown';
$cause = ((mb_strpos ($this-> martyr, DSP) !== false) ? 'INVALID FILEPATH' : 'PROVIDED INPUT');
$this-> martyr = "{$cause} " . P::U['ea'] . " {$this-> martyr}";
return;
}
}
private function blueprint_populate(): void {
/// Fill the nasty array with reckognized tags and their values and roles.
$bp = [];
$lc4 = [ P::C['b'], P::C['cr'], P::U['tnode_start'], P::U['tnode_end']]; # 4 allowed last punct chars
$chars = [P::C['bl'], P::C['br'], P::C['cl'], $lc4[1] ];
foreach ($this-> valid_structure as $nt => $food)
{
[$n, $tab] = explode(':', $nt);
$fc = mb_substr ($food, 0, 1);
$lc = mb_substr ($food, -1);
if (!$this-> clean_blueprint ($n, $fc, $lc, $food, $lc4))
{
$this-> e_code = 'fncd_invalid';
$bp = $food; break;
}
else
{
[ $role, $shrink ] = match ($lc) { // Let's see what last character has to say ..
$lc4[1] => [ 'STRING', null ],
$lc4[2] => [ 'PARENT', -1 ],
$lc4[0] => [ 'SELF', -1 ],
$lc4[3] => [ 'END', -1 ]
};
if (!is_null ($shrink)) $food = mb_substr ($food, 0, $shrink);
$nat = array_values (array_filter (explode (' ', trim (str_replace ($chars, ' ', $food)))));
if (!$this-> string_filter_rule ($nat[0], ['.',':','-','_']))
{
if (mb_strlen ($nat[0]) !== 1)
{
$this-> e_code = 'fncd_invalid';
$bp = "{$n}:{$food}";
break;
}
}
$cnat = count ($nat); // Name, Attributes, Text - that is - max 3 entries per array.
if ($cnat <= 3)
{
$bp[$n] = self::XML_BLUEPRINT;
$bp[$n]['tabs'] = $this-> tab_setter ($tab);
$bp[$n]['role'] = $role; $bp[$n]['type'] = (
($nat[0] === P::C['t']) ? 'TEXT' : (($nat[0] === P::C['as'])
? 'DTD' : (($nat[0] === P::C['e']) ? 'COMMENT' : 'TAG' ))
);
$bp[$n]['name'] = (($this-> tags_expand)
? (self::N_EXPAND[$nat[0]] ?? $nat[0])
: $nat[0]
);
if ($bp[$n]['role'] !== 'END')
{
switch ($cnat)
{
default: case 1: break;
case 2: $bp[$n][((in_array ($bp[$n]['role'],
['PARENT', 'SELF' ], true)) ? 'attr':'text')] = $nat[1]; break;
case 3: $bp[$n]['attr'] = $nat[1]; $bp[$n]['text'] = $nat[2]; break;
}
}
}
else
{
$this-> e_code = 'fncd_invalid';
$bp = "{$n}:{$food}";
break;
}
}
unset ($n,$tab,$fc,$lc,$tcbp,$nt,$food);
}
if (!is_array ($bp) && $this-> e_code !== false) {
$rlineT = 'RAW ENCODED BUGGY SPOT';
$slineT = 'SUSPECT TAG';
$bp = explode (P::C['c'], $bp);
if (isset($bp[1])) {
$uc = 'SYNTAX ERROR';
$a = $slineT;
$a1 = $rlineT;
$b = $bp[1];
}
else {
$uc = 'GEORGE BUSH ERROR';
$a = $rlineT;
$a1 = $slineT;
$b = 'unknown';
}
$this-> martyr = "$uc " . P::U['ea']
. " $a: {$bp[0]}; $a1: {$b}";
return;
}
else {
$this-> structure_info = $bp;
}
unset ($bp);
}
private function clean_blueprint ($line, $first_char, $last_char, $tag_content, $lc4): bool {
/// Dismisses/handles all remaining errors before tag details format occurs
$length = mb_strlen ($tag_content);
if ($length < 2) return false; // This `length` scenario is totally inacceptible.
else if ($length === 2) // This scenario is for single-letter tags acting like END role type, without arguments.
return (ctype_alpha ($first_char) && in_array ($last_char, array_slice ($lc4, -2), true));
else if ($length > 2 ) // This is where things get a bit more interesting.
{
if (ctype_alpha ($first_char) && in_array ($last_char, $lc4, true))
{ // If first and last characters are compliant
$this-> alter_linter_counter ($tag_content); // Re-Populate linter counter for each line
$bar = $this-> linter_count['bar']; // How many of these `|` .. ?
$lcc = ( $this-> linter_count['curly']['l'] + $this-> linter_count['curly']['r'] ); // Sum total number of { and } found
$lcp = ( $this-> linter_count['parenthesis']['l'] + $this-> linter_count['parenthesis']['r'] ); // Sum total number of ( and ) found
if ($bar > 0 && $bar !== 1) return false; // There can be only one self-closed tag per line
foreach ([$lcc, $lcp] as $pctcount): if($pctcount > 0 && $pctcount !== 2 && $pctcount < 2):
// There can be only one pair of parenthesis w/out only one pair of curly braces - per line.
$retval_abort = false; break; endif;
endforeach; return ($retval_abort ?? true);
}
else // First and last characters are not compliant .. ?
{
// If first char isn't one of three ~!* abort.
if (!in_array ($first_char, [P::C['t'], P::C['e'], P::C['as']], true))
return false;
else // Abort if the second and the last char aren't correct ones.
return (mb_substr ($tag_content,1,1) === P::C['cl'] && $last_char === $lc4[1]);
}
}
}