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
|
<?php
"
WARNING: THIS CODE CONTAINS SECURITY LEAKS (XSS)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Don't use it without modification!
"
define('UBBC_MARK', md5(uniqid(microtime())));
function ubbc($text) {
if (is_array($text)) {
foreach ($text as $key=>$val) {
$text[$key] = ubbc($val);
}
return $text;
}
$code_sections = array();
while (preg_match('=\[code\].*?\[/code\]=s', $text)) {
$text = preg_replace('=\[code\](.*?)\[/code\]=se', 'ubbc_save_code_sections("code", \'$1\', $code_sections)', $text);
}
while (preg_match('=\[fixed\].*?\[/fixed\]=s', $text)) {
$text = preg_replace('=\[fixed\](.*?)\[/fixed\]=se', 'ubbc_save_code_sections("code", \'$1\', $code_sections)', $text);
}
while (preg_match('=<\?php.*?\?>=s', $text)) {
$text = preg_replace('=<\?php(.*?)\?>=se', 'ubbc_save_code_sections("php", \'$1\', $code_sections)', $text);
}
$text = htmlentities($text);
$text = preg_replace("=\[b\](.*?)\[/b\]=is", '<b>\1</b>', $text);
$text = preg_replace("=\[i\](.*?)\[/i\]=is", '<i>\1</i>', $text);
$text = preg_replace("=\[u\](.*?)\[/u\]=is", '<u>\1</u>', $text);
$text = preg_replace("=\[s\](.*?)\[/s\]=is", '<s>\1</s>', $text);
$text = preg_replace("=\[sup\](.*?)\[/sup\]=is", '<sup>\1</sup>', $text);
$text = preg_replace("=\[sub\](.*?)\[/sub\]=is", '<sub>\1</sub>', $text);
$text = preg_replace("=\[left\](.*?)\[/left\]=is", '<left>\1</left>', $text);
$text = preg_replace("=\[center\](.*?)\[/center\]=is", '<center>\1</center>', $text);
$text = preg_replace("=\[right\](.*?)\[/right\]=is", '<right>\1</right>', $text);
$text = preg_replace("=\[tt\](.*?)\[/tt\]=is", '<tt>\1</tt>', $text);
$text = preg_replace('=\[url\]\s*(.*?)\s*\[/url\]=ie', '"<a href=\"$1\" target=\"" . gettarget("$1") . "\">$1</a>"', $text);
$text = preg_replace('=\[url\s*\=\s*(.*?)\s*\]\s*(.*?)\s*\[/url\]=ie', '"<a href=\"$1\" target=\"" . gettarget("$1") . "\">$2</a>"', $text);
$text = preg_replace('=\[ftp\]\s*(.*?)\s*\[/ftp\]=ie', '"<a href=\"ftp://$1\" target=\"" . gettarget("$1") . "\">$1</a>"', $text);
$text = preg_replace('=\[email\]\s*(.*?)\s*\[/email\]=i', '<a href="mailto:$1">$1</a>', $text);
$text = preg_replace('=\[email\s*\=\s*(.*?)\s*\]\s*(.*?)\s*\[/email\]=i', '<a href="mailto:$1">$2</a>', $text);
$text = preg_replace('=\[img\]\s*(.*?)\s*\[/img\]=i', '<img src="$1" />', $text);
$text = preg_replace('=\[color\s*\=\s*(#[0-9a-f]{6}|[a-z]+)\s*\]\s*(.*?)\s*\[/color\]=si', '<span style="color:$1">$2</span>', $text);
$text = preg_replace('=\[size\s*\=\s*([0-9]+)\s*(pt)?\s*\]\s*(.*?)\s*\[/size\]=si', '<span style="font-size:$1$2">$3</span>', $text);
$text = preg_replace('=\[font\s*\=\s*([a-z ]+)\s*\]\s*(.*?)\s*\[/font\]=si', '<span style="font-family:$1">$2</span>', $text);
$text = preg_replace('=(\s|^)((ftp|gopher|https?|irc|mailto|news):(//)?((.*:)?.*@)?[a-z0-9\-._~/%&\?\=#;]+)(\s|$)=ie', '"$1<a href=\"$2\" target=\"" . gettarget("$2") . "\">$2</a>$7"', $text);
$text = preg_replace('=(\s|^)(((.*:)?.*@)?www\.[a-z0-9\-._~/%&\?\=#;]+)(\s|$)=ie', '"$1<a href=\"http://$2\" target=\"" . gettarget("http://$2") . "\">$2</a>$5"', $text);
$text = nl2br($text);
$text = preg_replace("=\[move\](.*?)\[/move\]=is", '<marquee>\1</marquee>', $text);
$text = preg_replace("=\[(.*?)\](.*?)\[\/(.*?)\]=is", '\2', $text);
$text = preg_replace('=' . UBBC_MARK . '-php-([0-9]+)=e', 'get_highlight_string("<?php\n" . trim($code_sections[$1]) . "\n?>")', $text);
$text = preg_replace('=' . UBBC_MARK . '-code-([0-9]+)=e' , '"<code>" . nl2br(htmlentities(trim($code_sections[$1]))) . "</code>"', $text);
return $text;
}
function ubbc_save_code_sections($tag, $string, &$code_sections)
{
static $n = 0;
$code_sections[] = stripslashes($string);
return UBBC_MARK . "-$tag-" . ($n++);
}
function get_highlight_string($string)
{
ob_start();
highlight_string($string);
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
function gettarget($uri)
{
return (!strstr($uri, ':') or stristr($uri, $_SERVER['SERVER_NAME'])) ? '_self' : '_blank';
}
?>
|