-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathCode2.php
More file actions
90 lines (73 loc) · 1.78 KB
/
Copy pathCode2.php
File metadata and controls
90 lines (73 loc) · 1.78 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
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2025 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 4
*/
declare(strict_types=1);
namespace SMF\BBCode;
use SMF\Parser;
/**
* Represents the unparsed_equals_content version of the code BBCode.
*/
class Code2 extends BBCode
{
/*******************
* Public properties
*******************/
/**
*
*/
public string $tag = 'code';
/**
*
*/
public ?string $type = BBCode::TYPE_UNPARSED_EQUALS_CONTENT;
/**
*
*/
public ?string $content = '<div class="codeheader">{txt_code} ($2)</div><pre data-select-txt="{txt_code_select}" data-shrink-txt="{txt_code_shrink}" data-expand-txt="{txt_code_expand}" class="bbc_code"><code>$1</code></pre>';
/**
*
*/
public ?string $disabled_content = '<div>$1</div>';
/**
*
*/
public bool $block_level = true;
/****************
* Public methods
****************/
/**
*
*/
public function validate(BBCodeInterface &$bbc, array|string &$data, array $disabled, array $params): void
{
if (!isset($disabled['code'])) {
$code = \is_array($data) ? $data[0] : $data;
$parts = preg_split('~(<\?php|\?>)~', $code, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $n = count($parts); $i < $n; $i++) {
// Do PHP code coloring?
if ($parts[$i] != '<?php') {
continue;
}
$string = '';
while ($i + 1 < $n && $parts[$i] != '?>') {
$string .= $parts[$i];
$parts[$i++] = '';
}
$parts[$i] = Parser::highlightPhpCode($string . $parts[$i]);
}
if (is_array($data)) {
$data[0] = implode('', $parts);
} else {
$data = implode('', $parts);
}
}
}
}