C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RTL8YJG\inc\thwbcode.inc.php


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
<?php
/* $Id: thwbcode.inc.php,v 1.11 2003/01/08 14:37:33 pbaecher Exp $ */
/*
          ThWboard - PHP/MySQL Bulletin Board System
        ==============================================
            (c) 2000, 2001 by
               Paul Baecher         <paul@thewall.de>
               Felix Gonschorek   <funner@thewall.de>

          download the latest version:
            http://www.thwboard.de

          This  program is  free  software;  you can
          redistribute it and/or modify it under the
          terms of the GNU General Public License as
          published by the Free Software Foundation;
          either  version 2 of  the License,  or (at
          your option) any later version.

        ==============================================

*/

define('SEARCH'0);
define('REPLACE'1);

$a_thwbcode = array();
$a_smilies = array();

function 
get_smilies()
{
    
$a_smilies = array(
        
':)'     => 'smile',
        
'&gt;:(' => 'angry',
        
':('    => 'frown',
        
':D'    => 'biggrin',
        
';)'    => 'wink',
        
':?'    => 'question',
        
':|'    => 'strange',
        
':\\'    => 'prefect',
        
'=)'    => 'gumble',
        
':oah:'    => 'oah',
        
':rolleyes:' => 'rolleyes'
    
);

    
define'THWB_SMILIES'true );
        
    return 
$a_smilies;
}


function 
get_thwb_tags()
{
    global 
$style;
    
    
//ttt: please keep an eye on the order the tags appear;
    //       e.g. noparse /must/ come after [php] and [code]
    
    // [php]
    
$a_thwbcode[SEARCH][] = '/\[php\](.*)\[\/php\]/Uesi';
    
$a_thwbcode[REPLACE][] = 'format_phpsource(\'\1\')';
    
// [code]
    
$a_thwbcode[SEARCH][] = '/\[code\](.*)\[\/code\]/Uesi';
    
$a_thwbcode[REPLACE][] = 'format_source(\'\1\')';
    
// [noparse] - these are extracted before further parsing
    
$a_thwbcode[SEARCH][] = '/\[noparse\](.*)\[\/noparse\]/Uesi';
    
$a_thwbcode[REPLACE][] = 'noparse(\'\1\')';
    
// http://www.thwboard.de
    
$a_thwbcode[SEARCH][] = "/(^|[ \n])([a-zA-Z]+):\/\/([^ ,\"\n]+)/";
    
$a_thwbcode[REPLACE][] = '\1<a href="\2://\3" target="_blank">\2://\3</a>';
    
// www.thwboard.de
    
$a_thwbcode[SEARCH][] = "/(^|[ \n])www\.([^ ,\"\n]+)/i";
    
$a_thwbcode[REPLACE][] = '\1<a href="http://www.\2" target="_blank">www.\2</a>';
    
// [mail]
    
$a_thwbcode[SEARCH][] = '/\[mail\]([._0-9a-zA-Z-]+)@([._0-9a-zA-Z-]+)\[\/mail\]/Ui';
    
$a_thwbcode[REPLACE][] = '<a href="mailto:\1@\2">\1@\2</a>';
    
// [mail=""]
    
$a_thwbcode[SEARCH][] = '/\[mail="([._0-9a-zA-Z-]+)@([._0-9a-zA-Z-]+)"\](.*)\[\/mail\]/Ui';
    
$a_thwbcode[REPLACE][] = '<a href="mailto:\1@\2">\3</a>';
    
// [color]
    
$a_thwbcode[SEARCH][] = '/\[color="([a-zA-Z0-9# ]+)"\](.*)\[\/color\]/Uis';
    
$a_thwbcode[REPLACE][] = '<font color="\1">\2</font>';
    
// [b]
    
$a_thwbcode[SEARCH][] = '/\[b\](.*)\[\/b\]/Uis';
    
$a_thwbcode[REPLACE][] = '<b>\1</b>';
    
// [i]
    
$a_thwbcode[SEARCH][] = '/\[i\](.*)\[\/i\]/Uis';
    
$a_thwbcode[REPLACE][] = '<i>\1</i>';
    
// [u]
    
$a_thwbcode[SEARCH][] = '/\[u\](.*)\[\/u\]/Uis';
    
$a_thwbcode[REPLACE][] = '<u>\1</u>';
    
// [-]
    
$a_thwbcode[SEARCH][] = '/\[-\](.*)\[\/-\]/Uis';
    
$a_thwbcode[REPLACE][] = '<s>\1</s>';
    
// [quote]
    
$a_thwbcode[SEARCH][] = '/\[quote\]/Ui';
    
$a_thwbcode[REPLACE][] = '<br><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1" bgcolor="' $style['border_col'] . '"><tr><td>' $style['smallfont'] . '<b>Zitat:</b>' $style['smallfontend'] . '</td></tr><tr><td bgcolor="' $style['CellA'] . '"><font size="2">' '\1';
    
// [/quote]
    
$a_thwbcode[SEARCH][] = '/\[\/quote\]/Ui';
    
$a_thwbcode[REPLACE][] = '</font></td></tr></table><br>';
    
// [url]www.thwboard.de[/url]
    
$a_thwbcode[SEARCH][] = "/\[url\]www\.([^ ,\"\n]+)\[\/url\]/Ui";
    
$a_thwbcode[REPLACE][] = '<a href="http://www.\1" target="_blank">www.\1</a>';
    
// [url]http://www.thwboard.de[/url]
    
$a_thwbcode[SEARCH][] = "/\[url\]([a-zA-Z]+):\/\/([^ ,\"\n]+)\[\/url\]/Ui";
    
$a_thwbcode[REPLACE][] = '<a href="\1://\2" target="_blank">\1://\2</a>';
    
// [url=""]
    
$a_thwbcode[SEARCH][] = "/\[url=\"([a-zA-Z]+):\/\/([^ ,\"\n]+)\"\](.*)\[\/url\]/Usi";
    
$a_thwbcode[REPLACE][] = '<a href="\1://\2" target="_blank">\3</a>';
    
    
define'THWB_TAGS'true );
    
    return 
$a_thwbcode;
}


class 
CStack {
    var 
$tos;
    var 
$stack;
    
    function 
CStack()
    {
        
$this->stack = array();
        
$this->tos 0;
        
$this->stack[$this->tos] = 0// simplifies things a bit =)
    
}
    function 
push$var ) {    $this->stack[++$this->tos] = $var; }
    function 
peek()    { return $this->stack[$this->tos]; }
    function 
pop()
    {
        if( 
$this->tos )
            return 
$this->stack[$this->tos--];
        else
            return 
0;
    }
    
    
//ttt: now supports regexps
    
function search$var$preg=)
    {
        for( 
$i $this->tos$i 0$i-- )
        {
            if( 
$preg )
            {
                if( 
preg_match$this->stack[$i], $var ) )
                    return 
1;
            }
            else
            {
                
//echo "Stack:". $this->tos." $var\n";
                
if( !strcmp($this->stack[$i], $var) )
                    return 
1;
            }
        }
        return 
0;
    }
}


function 
close_tags( &$tags, &$s_pos, &$string$curtag='' )
{    
    if( 
strlen($curtag) > )
    {
        if( !
$tags->search($curtag) )
        {
            
//echo "removing $curtag";
            // no corresponding start tag, remove this tag
            
$string substr($string0$s_pos 1) . substr($string$s_pos strlen($curtag)+2);
            
$s_pos -= strlen($curtag)+3//HACK: keep string positioning consistent
            
return;
        }
    }
    else
    {
        
$curtag "###"// just a dummy
    
}
    
    
$oldtag $tags->peek();
    while( 
$oldtag && ($oldtag != $curtag)  )
    {
        
//echo "inserting /$curtag";
        // missing end tag, just insert one
        
$string substr($string0$s_pos-1) .'[/'$tags->pop() .']'substr($string$s_pos-1);
        
$s_pos += strlen($oldtag) + 3// skip over [/$oldtag]
        
$oldtag $tags->peek();
        
        
//echo "\n\n ---- $string ---- \n\n";
    
}
    
$tags->pop();
}


function 
fixup_quotes$string )
{
    
// skip the whole thing when there are no quotes
    
if( !(strchr($string,'[quote]') || strchr($string,'[/quote]')) )
        return 
$string;

    
$tmp $string;
    
$s_pos 0// $s_pos is position in $string
    
$t_pos 0// $t_pos is position in $tmp
    
$tags = new CStack();
    
    while( 
is_integer($t_pos strpos($tmp'[')) )
    {
        
$s_pos += $t_pos+1;
        
$tmp substr$tmp$t_pos+);
        
        
$endpos strpos$tmp']' );
        if( 
is_integer($endpos) ) {
            
$curtag substr$tmp0$endpos );
            
//$curtag = substr( $tmp, strpos($tmp, '/'), $endpos );
            //echo "$curtag\n";
            
switch( $curtag )
            {
                case 
'quote':
                    
$tags->push($curtag);
                    
//echo "PStack:". $tags->tos."\n";
                    
break;
                case 
'/quote':
                    
//echo "Stack:". $tags->tos."\n";
                    
close_tags$tags$s_pos$stringsubstr($curtag1) );
                    break;
                default:
                    
//ttt: don't be fooled by [[quote] stuff
                    
$endpos = -1;
                    break;
            }
            
$s_pos += $endpos+1;
            
$tmp substr$string$s_pos );
        }
    }

    
// if there are still some endtags missing, add them at the end
    
$s_pos strlen$string ) +1// normally this should be -1, but close_tags moves back 2 chars
    
close_tags$tags$s_pos$string );
    
    return 
$string;
}


function 
noparse($string$insert 0)
{
    static    
$rpc$a_replace;

    if( !
$insert )
    {
        
$string str_replace('\"''"'$string);
        
$a_replace[++$rpc] = $string;
        return 
"<noparse $rpc>";
    }
    else
    {
        return 
$a_replace[$insert];
    }
}


function 
format_source($string)
{
    global 
$style;

    
$string str_replace('\"''"'$string);
    
$string str_replace('  ''&nbsp;&nbsp;'$string);
    
$string str_replace("\n"'<br>'$string);
    
    return 
'<br><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1" bgcolor="' $style['border_col'] . '"><tr><td><font size="1"><b>Quellcode:</b></font></td></tr><tr><td bgcolor="' $style['CellA'] . '"><code>[noparse]' $string '[/noparse]</code></td></tr></table><br>';
}


function 
format_phpsource($string)
{
    global 
$style;

    
$string trim($string);
    
$string str_replace('\"''"'$string);
    
    if( (float)(
phpversion()) >= 4.2 )
    {
        
$string str_replace("<br>""\n"$string);    
        
$string str_replace('&lt;''<'$string);
        
$string str_replace('&gt;''>'$string);
            
        
//ttt: automatically insert < ?php if necessary
        
if( !preg_match'/^\<\?(php)?/s'$string ) )
            
$string "<?php\n"$string;
        
        if( !
preg_match'/\?\>$/s'$string ) )
            
$string .= "\n?>";
        
        
$string highlight_string($stringTRUE);
    }

    return 
'<br><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1" bgcolor="' $style['border_col'] . '"><tr><td><font size="1"><b>PHP-Quellcode:</b></font></td></tr><tr><td bgcolor="' $style['CellA'] . '"><code>[noparse]' $string '[/noparse]</code></td></tr></table><br>';
}


function 
preparse_code($string)
{
    
$string trim($string);
    
$string str_replace("\r"''$string);
    
$string str_replace(chr(160), ''$string);

    
$string str_replace("con\\con"''$string);
    
$string str_replace("con/con"''$string);

    
// [code] tags.
    
$string str_replace("\t"'    '$string);

    
$string ereg_replace("\[code\]([ \n]*)"'[code]'$string); 
    
$string ereg_replace("\[/code\]([ \n]*)"'[/code]'$string); 
    
$string ereg_replace("\[php\]([ \n]*)"'[php]'$string); 
    
$string ereg_replace("\[/php\]([ \n]*)"'[/php]'$string); 
    
$string ereg_replace("\[quote\]([ \n]*)"'[quote]'$string); 
    
$string ereg_replace("\[/quote\]([ \n]*)"'[/quote]'$string); 
    
    return 
$string;
}


function 
parse_code($string$do_br 0$do_img 0$do_code 0$do_smilies 0)
{
    global 
$config$style;
    static 
$smilies_fixed 0;

    
// HTML-Security
    
$string str_replace('&''&amp;'$string);
    
$string str_replace('<''&lt;'$string);
    
$string str_replace('>''&gt;'$string);
    
    if( 
$do_code )
    {
        global 
$a_thwbcode;
        
        if( !
defined('THWB_TAGS') )
            
$a_thwbcode get_thwb_tags();
        
        
//echo "<pre style=\"font-size:8pt\">";
        // nested [quote] fixup
        
$string fixup_quotes($string);
        
//echo "$string</pre>";
        
$string preg_replace($a_thwbcode[SEARCH], $a_thwbcode[REPLACE], $string );
    }

    if( 
$do_img && ($config['imageslevel'] != 2) )
        
$string preg_replace('/\[img\]([a-zA-Z]+):\/\/([^ ,\"\n]+)\.(jpg|jpeg|png|gif)\[\/img\]/Usi''<img src="\1://\2.\3" alt="" border="0">'$string);

    if( 
$do_smilies && $config['smilies'] )
    {
        global 
$a_smilies;
        
        if( !
defined('THWB_SMILIES') )
            
$a_smilies get_smilies();
        
        if( !
$smilies_fixed )
        {    
            
reset($a_smilies);
            
$url_prepend '<img src="templates/'.$style['styletemplate'].'/images/icon/';
            while( 
current$a_smilies ) )
            {
                
$a_smilies[key($a_smilies)] = $url_prepend.current($a_smilies).'_new.gif" border="0">';
                
next$a_smilies );
            }
            
$smilies_fixed 1;
        }

        
$string strtr$string$a_smilies );
    }

    
// reinsert extracted parts
    
$string preg_replace'/\<noparse ([0-9]+)\>/e''noparse("",\1)'$string );
    
    if( 
$do_br )
        
$string str_replace("\n"'<br>'$string);
    else
        
$string str_replace("\n"''$string);

    return 
$string;
}
?>