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
| <?php
function smile($bericht) {
$bericht = str_replace(':)', '[img]images/smileys/smile.gif[/img]', $bericht);
$bericht = str_replace(':(', '[img]images/smileys/sadface.gif[/img]', $bericht);
$bericht = str_replace(":=(", "[img]images/smileys/cry.gif[/img]", $bericht);
$bericht = str_replace('*)', '[img]images/smileys/dazed.gif[/img]', $bericht);
$bericht = str_replace('>:', '[img]images/smileys/evilgrin.gif[/img]', $bericht);
$bericht = str_replace(':FU', '[img]images/smileys/finger.gif[/img]', $bericht);
$bericht = str_replace(':r', '[img]images/smileys/kotzen.gif[/img]', $bericht);
$bericht = str_replace('&)', '[img]images/smileys/nirvana.gif[/img]', $bericht);
$bericht = str_replace(':foei', '[img]images/smileys/nono.gif[/img]', $bericht);
$bericht = str_replace(':P', '[img]images/smileys/tongue.gif[/img]', $bericht);
$bericht = str_replace(':p', '[img]images/smileys/tongue.gif[/img]', $bericht);
$bericht = str_replace(':dead', '[img]images/smileys/toomuch.gif[/img]', $bericht);
$bericht = str_replace(';)', '[img]images/smileys/wink.gif[/img]', $bericht);
$bericht = str_replace(':|', '[img]images/smileys/wrygrin.gif[/img]', $bericht);
$bericht = str_replace(':D', '[img]images/smileys/yellowgrin.gif[/img]', $bericht);
$bericht = str_replace(':deal', '[img]images/smileys/deal.gif[/img]', $bericht);
return $bericht;
}
function bbencode($bericht) {
$bericht = " " . $bericht;
if (! (strpos($bericht, "[") && strpos($bericht, "]")) )
{
// Remove padding, return.
$bericht = substr($bericht, 1);
return $bericht;
}
// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$bericht = bbencode_quote($bericht);
// [b] and [/b] for bolding text.
$bericht = preg_replace("/\\[b\](.*?)\\[\/b\]/si", "<B>\\1</B>", $bericht);
// [i] and [/i] for italicizing text.
$bericht = preg_replace("/\\[i\](.*?)\\[\/i\]/si", "<I>\\1</I>", $bericht);
// [img]image_url_here[/img] code..
$bericht = preg_replace("/\\[img\](.*?)\\[\/img\]/si", "[img]\"\\1\"[/img]", $bericht);
// Patterns and replacements for URL and email tags..
$patterns = array();
$replacements = array();
// [url]xxxx://www.phpbb.com[/url] code..
$patterns[0] = "#\\[url\]([a-z]+?://){1}(.*?)\\[/url\]#si";
$replacements[0] = '<A HREF="\1\2" TARGET="_blank">\1\2</A>';
// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
$patterns[1] = "#\\[url\](.*?)\\[/url\]#si";
$replacements[1] = '<A HREF="http://\1" TARGET="_blank">\1</A>';
// [url=xxxx://www.phpbb.com]phpBB[/url] code..
$patterns[2] = "#\\[url=([a-z]+?://){1}(.*?)\](.*?)\\[/url\]#si";
$replacements[2] = '<A HREF="\1\2" TARGET="_blank">\3</A>';
// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
$patterns[3] = "#\[url=(.*?)\](.*?)\\[/url\]#si";
$replacements[3] = '<A HREF="http://\1" TARGET="_blank">\2</A>';
// [email]user@domain.tld[/email] code..
$patterns[4] = "#\\[email\](.*?)\\[/email\]#si";
$replacements[4] = '<A HREF="mailto:\1">\1</A>';
$bericht = preg_replace($patterns, $replacements, $bericht);
// Remove our padding from the string..
$bericht = substr($bericht, 1);
return $bericht;
}
function bbcode_array_push(&$stack, $value) {
$stack[] = $value;
return(sizeof($stack));
}
function bbcode_array_pop(&$stack) {
$arrSize = count($stack);
$x = 1;
while(list($key, $val) = each($stack)) {
if($x < count($stack)) {
$tmpArr[] = $val;
}
else {
$return_val = $val;
}
$x++;
}
$stack = $tmpArr;
return($return_val);
}
function bbencode_quote($bericht)
{
// First things first: If there aren't any "[quote]" strings in the bericht, we don't
// need to process it at all.
if (!strpos(strtolower($bericht), "[quote]"))
{
return $bericht;
}
$stack = Array();
$curr_pos = 1;
while ($curr_pos && ($curr_pos < strlen($bericht)))
{
$curr_pos = strpos($bericht, "[", $curr_pos);
// If not found, $curr_pos will be 0, and the loop will end.
if ($curr_pos)
{
// We found a [. It starts at $curr_pos.
// check if it's a starting or ending quote tag.
$possible_start = substr($bericht, $curr_pos, 7);
$possible_end = substr($bericht, $curr_pos, 8);
if (strcasecmp("[quote]", $possible_start) == 0)
{
// We have a starting quote tag.
// Push its position on to the stack, and then keep going to the right.
bbcode_array_push($stack, $curr_pos);
++$curr_pos;
}
else if (strcasecmp("[/quote]", $possible_end) == 0)
{
// We have an ending quote tag.
// Check if we've already found a matching starting tag.
if (sizeof($stack) > 0)
{
// There exists a starting tag.
// We need to do 2 replacements now.
$start_index = bbcode_array_pop($stack);
// everything before the [quote] tag.
$before_start_tag = substr($bericht, 0, $start_index);
// everything after the [quote] tag, but before the [/quote] tag.
$between_tags = substr($bericht, $start_index + 7, $curr_pos - $start_index - 7);
// everything after the [/quote] tag.
$after_end_tag = substr($bericht, $curr_pos + 8);
$bericht = $before_start_tag . "<TABLE BORDER=0 ALIGN=CENTER WIDTH=95%><TR><TD><i>";
$bericht .= $between_tags . "</i></BLOCKQUOTE></FONT></TD></TR><TR><TD></TD></TR></TABLE>";
$bericht .= $after_end_tag;
// Now.. we've screwed up the indices by changing the length of the string.
// So, if there's anything in the stack, we want to resume searching just after it.
// otherwise, we go back to the start.
if (sizeof($stack) > 0)
{
$curr_pos = bbcode_array_pop($stack);
bbcode_array_push($stack, $curr_pos);
++$curr_pos;
}
else
{
$curr_pos = 1;
}
}
else
{
// No matching start tag found. Increment pos, keep going.
++$curr_pos;
}
}
else
{
// No starting tag or ending tag.. Increment pos, keep looping.,
++$curr_pos;
}
}
}
return $bericht;
}
?> |