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
|
<?php /* $Id: functions.inc.php,v 1.10 2002/12/30 21:29:00 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.
==============================================
*/
class Template { function Template($szTemplateName) { if( !file_exists($szTemplateName) ) { $this->Halt("unable to load template file: '" . $szTemplateName . "' does not exist."); } $this->szTemplateData = @implode('', (@file($szTemplateName))); $this->szTemplateData = str_replace('"', '\"', $this->szTemplateData); }
function GetTemplate($szVarname = "") { if( $szVarname ) { return ('$' . $szVarname . ' .= "' . $this->szTemplateData . '";'); } else { return ('compress_page("' . $this->szTemplateData . '");'); } }
function Halt($szErrorMsg) { echo "<pre>Template error:\n " . $szErrorMsg . "</pre>"; exit; } }
/* permission class */ class Permission { var $a_group; var $a_groupboard; var $boardid;
function Permission($groupids, $boardid = -1) { global $pref; if( $groupids === '' ) $groupids = '-1'; $this->a_group = array(); $r_group = thwb_query("SELECT groupid, accessmask FROM $pref"."group WHERE groupid IN(".$groupids.")"); while( $group = mysql_fetch_array($r_group) ) { $this->a_group[$group['groupid']] = $group['accessmask']; } mysql_free_result($r_group);
$this->a_groupboard = array(); if( $boardid == -1 ) $r_groupboard = thwb_query("SELECT groupid, boardid, accessmask FROM $pref"."groupboard WHERE groupid IN (".$groupids.")"); else $r_groupboard = thwb_query("SELECT groupid, boardid, accessmask FROM $pref"."groupboard WHERE boardid='$boardid' AND groupid IN (".$groupids.")"); while( $groupboard = mysql_fetch_array($r_groupboard) ) { $this->a_groupboard[ $groupboard['boardid'] ][ $groupboard['groupid'] ] = $groupboard['accessmask']; } mysql_free_result($r_groupboard); $this->set_boardid($boardid); }
function set_boardid($boardid) { $this->boardid = $boardid; } function has_permission($perm) { $mask = 0; reset($this->a_group); reset($this->a_groupboard);
while( list($groupid, $accessmask) = each($this->a_group) ) { if( isset($this->a_groupboard[$this->boardid][$groupid]) ) $mask |= $this->a_groupboard[$this->boardid][$groupid]; else $mask |= $accessmask; }
return ($mask & $perm); } }
function requires_permission($perm) { global $g_user, $pref, $style, $config, $options, $P, $HTTP_SERVER_VARS;
if( $P->has_permission($perm) ) return;
global $board;
if( $g_user['styleid'] ) { $board['styleid'] = $g_user['styleid']; }
if( $board['styleid'] == 0 ) { $r_style = thwb_query("SELECT styletemplate, colorbg, color1, CellA, CellB, color4, colorbgfont, col_he_fo_font, color_err, col_link, col_link_v, col_link_hover, stdfont, boardimage, newtopicimage, border_col FROM ".$pref."style WHERE styleisdefault=1"); } else { $r_style = thwb_query("SELECT styletemplate, colorbg, color1, CellA, CellB, color4, colorbgfont, col_he_fo_font, color_err, col_link, col_link_v, col_link_hover, stdfont, boardimage, newtopicimage, border_col FROM ".$pref."style WHERE styleid='".intval($board['styleid'])."'"); } $style = mysql_fetch_array($r_style);
$style['smallfont'] = '<font face="' . $style['stdfont'] . '" size="1">'; $style['smallfontend'] = '</font>'; $style['stdfont'] = '<font face="' . $style['stdfont'] . '" size="2">'; $style['stdfontend'] = '</font>';
if( !$navpath ) { $navpath = '<a class="bglink" href="index.php">'.$config['board_name'].'</a> » Zugriff verweigert'; }
$Tframe = new Template("templates/" . $style['styletemplate'] . "/frame.html"); $Tnopermission = new Template("templates/" . $style['styletemplate'] . "/nopermission.html"); if( !$g_user['userid'] ) { $Tnoperm_login = new Template("templates/" . $style['styletemplate'] . "/noperm_login.html"); $source = urlencode(basename($HTTP_SERVER_VARS['REQUEST_URI'])); eval($Tnoperm_login->GetTemplate('t_loginform')); } else { $t_loginform = ''; }
eval($Tnopermission->GetTemplate("CONTENT")); eval($Tframe->GetTemplate());
exit; }
function highlight_words($text, $a_word) { $a_color = array('#ffff66', '#A0FFFF', '#99ff99', '#ff9999', '#ff66ff'); $i = 0;
while( list(, $word) = each($a_word) ) { if( strlen($word) >= 3 ) { $text = preg_replace('/'.$word.'/i', '<b style="color:black;background-color:'.$a_color[$i % count($a_color)].'">'.$word.'</b>', $text); $i++; } }
return $text; }
define('INVALID_CHAR', 1); define('INVALID_LENGTH', 2); define('NAME_TAKEN', 3); define('NAME_BANNED', 4);
function verify_username($username) { global $config, $pref; $legalchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 [|](){}.-_äöüÄÖÜß";
for( $i = 0; $i < strlen($username); $i++ ) { if( !strstr($legalchars, $username[$i]) ) { return INVALID_CHAR; } }
while( list(, $bannedname) = @each($config['bannednames']) ) { if( $bannedname && stristr($username, $bannedname) ) { return NAME_BANNED; } } if( strlen($username) > $config['max_usernamelength'] || strlen($username) < $config['min_usernamelength'] ) { return INVALID_LENGTH; } $r_user = thwb_query("SELECT userid FROM $pref"."user WHERE username='".addslashes($username)."'"); if( mysql_num_rows($r_user) ) { return NAME_TAKEN; } return 0; }
//called by register, reply, newtopic function check_username($username) { switch( verify_username($username) ) { case NAME_TAKEN: message('Fehler', 'Der Benutzername existiert leider schon!'); break; case INVALID_CHAR: message('Fehler', 'Ihr gewünschter Benutzername enthält ungültige Zeichen!'); break; case NAME_BANNED: message('Fehler', 'Der ausgewählte Benutzername kann leider nicht verwendet werden.'); break; case INVALID_LENGTH: message('Fehler', 'Die Länge des Benutzernamens ist ungültig'); break; default: } return; }
//called by register, editprofile function check_email($email) { return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email); }
//ttt: check whether user is allowed to get a member's email address function get_email( $user, $short = false ) { global $g_user, $style; if( $g_user['userid'] == 0 ) return '- (Versteckt)'; $retstring = '<a href="mailto:'. $user['useremail'] .'">' .($short ? chopstring($user['useremail'],20) : $user['useremail'] ) .'</a>'; if( !$user['userhideemail'] || ($user['userid'] == $g_user['userid']) ) { return $retstring; } else { if( !$g_user['userisadmin'] ) { return '- (Versteckt)'; } else { if( $short ) return $retstring; else return '- (Versteckt) '.$style['smallfont'].' [Admin: '. $retstring .' ]'.$style['smallfontend']; } } }
function message($title, $msg, $opt_back = 1, $opt_index = 1) { global $style, $config, $g_user, $options, $JUMP_MENU, $navpath, $pref;
if( !$style ) { global $board;
if( $g_user['styleid'] ) { $board['styleid'] = $g_user['styleid']; }
if( $board['styleid'] == 0 ) { $r_style = thwb_query("SELECT styletemplate, colorbg, color1, CellA, CellB, color4, colorbgfont, col_he_fo_font, color_err, col_link, col_link_v, col_link_hover, stdfont, boardimage, newtopicimage, border_col FROM ".$pref."style WHERE styleisdefault=1"); } else { $r_style = thwb_query("SELECT styletemplate, colorbg, color1, CellA, CellB, color4, colorbgfont, col_he_fo_font, color_err, col_link, col_link_v, col_link_hover, stdfont, boardimage, newtopicimage, border_col FROM ".$pref."style WHERE styleid='".intval($board['styleid'])."'"); } $style = mysql_fetch_array($r_style);
$style['smallfont'] = '<font face="' . $style['stdfont'] . '" size="1">'; $style['smallfontend'] = '</font>'; $style['stdfont'] = '<font face="' . $style['stdfont'] . '" size="2">'; $style['stdfontend'] = '</font>'; }
if( !$navpath ) { $navpath = "<a class=\"bglink\" href=\"index.php\">$config[board_name]</a>"; }
$messageoptions = " "; $opt_back ? $messageoptions .= "[ <a class=\"hefo\" href=\"javascript:history.back(0)\">Zurück</a> ] " : ""; $opt_index ? $messageoptions .= "[ <a class=\"hefo\" href=\"index.php\">Index</a> ]" : ""; $Tframe = new Template("templates/" . $style['styletemplate'] . "/frame.html"); $Tmessage = new Template("templates/" . $style['styletemplate'] . "/message.html");
eval($Tmessage->GetTemplate("CONTENT")); eval($Tframe->GetTemplate()); exit; }
function message_redirect($msg, $url) { global $style;
$TRedirect = new Template('templates/' . $style['styletemplate'] . '/redirect.html'); eval($TRedirect->GetTemplate()); exit; }
function form_date($time, $verbose = 1) { global $config; if( $time < (60 * 60 * 24) ) { return "N/A"; }
$time += $config['timeoffset'] * 3600;
if( date("d.m.Y", (time() + $config['timeoffset'] * 3600) ) == date('d.m.Y', $time) && $verbose ) { return "<b>Heute</b>, " . date("H:i", $time) . " Uhr"; } else { return date("d.m.Y, H:i", $time) . " Uhr"; } }
function r_stripslashes(&$array) { while( list($k, $v) = each($array) ) { if( $k != 'argc' && $k != 'argv' && (strtoupper($k) != $k || ''.intval($k) == "$k") ) { if( is_string($v) ) { $array[$k] = stripslashes($v); } if( is_array($v) ) { $array[$k] = r_stripslashes($v); } } } return $array; }
function jumpmenu($currentboard = 1) { global $pref, $g_user;
$P = new Permission($g_user['groupids']);
// precache boards $a_board = array(); $r_board = thwb_query("SELECT boardid, boardname, categoryid FROM ".$pref."board WHERE boarddisabled = 0 ORDER BY boardorder ASC"); while( $board = mysql_fetch_array($r_board) ) { $P->set_boardid($board['boardid']); if( $P->has_permission( P_VIEW ) ) $a_board[$board['categoryid']][] = $board; } // category $r_category = thwb_query("SELECT categoryid, categoryname FROM ".$pref."category ".$where."ORDER BY categoryorder ASC"); $JUMP_MENU = '<select class="tbselect" name="board[boardid]">'; while( $category = mysql_fetch_array($r_category) ) { if( $a_board[$category['categoryid']] ) { $JUMP_MENU .= '<option value="-'.$category['categoryid'].'">'.$category['categoryname'].'</option>'; while( list(, $board) = each($a_board[$category['categoryid']]) ) { $JUMP_MENU .= '<option value="'.$board['boardid'].'"'.($board['boardid'] == $currentboard ? ' selected' : '') . '>- '.$board['boardname'].'</option>'; } } }
$JUMP_MENU .= '</select> <input class="tbbutton" type="submit" name="Submit" value="Jump">';
return $JUMP_MENU; }
function thwb_array_reverse($array) { if( function_exists('array_reverse') ) { return array_reverse($array); } else { $a_new = array(); for( $i = count($array) - 1; $i >= 0; $i--) { $a_new[] = $array[$i]; } return $a_new; } } //$DEBUG = "<pre>";
function thwb_query($query) { global $DEBUG, $g_user; global $config; global $all_t; $start = microtime();
$result = mysql_query($query);
$end = microtime(); if( !$result ) { print '<pre><b>ThWboard Error</b><br>MySQL: ' . mysql_error() . ' Query: ' . $query . '</pre>'; exit; } if ( $g_user['userisadmin'] && $config['debugmode'] ) { // Extended DEBUG Mody By Andy $start_t = explode(" ", $start); $end_t = explode(" ", $end);
$start_t = $start_t[0] + $start_t[1]; $end_t = $end_t[0] + $end_t[1]; $full_t = $end_t - $start_t; $all_t = $all_t + $full_t; if( !$all_t ) { $all_t = 0; }
$DEBUG .= "</center><pre><font color=\"black\">$query\n\n<b>Zeit vor der Abfrage: $start_t\n Zeit nach der Abfrage: $end_t\n Abfragezeit: $full_t\n</b>"; $DEBUG .= "<pre><b>Bisherige gesamte Abfragedauer: <font color=\"red\">$all_t</font>, in Sekunden: <font color=\"red\">"; $DEBUG .= substr($all_t, 0, 4); $DEBUG .= "</b></PRE><BR><BR>"; $sql_time += ($end_t - $start_t); }
return $result; }
function chopstring($string, $maxchars) { if( strlen($string) > $maxchars ) $string = substr($string, 0, ($maxchars - 3)) . '...'; return $string; }
function killshout($string) { if( $string ) { $caps = $noncaps = 0; for( $i = 0; $i < strlen($string); $i++ ) { if( $string[$i] > 'A' && $string[$i] < 'Z' ) $caps++; } $ratio = $caps / strlen($string); if( $ratio > 0.3 ) { $words = @explode(' ', $string); while( list(, $word) = each($string) ) { if( strlen($word) > 1 ) { $word = substr($word, 0, 1) . strtolower($word, 1); } } return @implode(' ', $word); } } return $string; }
function updateboard($boardid) { global $pref; // updates last posttime/thread/author of a board .. $r_thread = thwb_query("SELECT threadid, threadtopic, threadtime, threadlastreplyby FROM ".$pref."thread WHERE boardid='".intval($boardid)."' ORDER BY threadtime DESC LIMIT 1");
if( mysql_num_rows($r_thread) < 1 ) { thwb_query("UPDATE ".$pref."board SET boardlastpost='0', boardthreadid='0', boardthreadtopic='', boardlastpostby='' WHERE boardid='".intval($boardid)."'"); } else { $thread = mysql_fetch_array($r_thread); thwb_query("UPDATE ".$pref."board SET boardlastpost='$thread[threadtime]', boardthreadid='$thread[threadid]', boardthreadtopic='" . addslashes($thread['threadtopic']) . "', boardlastpostby='" . addslashes($thread['threadlastreplyby']) . "' WHERE boardid='".intval($boardid)."'"); } }
function updatethread($threadid) { global $pref; // update thread stuff when deleting posts $r_post = thwb_query("SELECT posttime, userid, postguestname FROM ".$pref."post WHERE threadid='".intval($threadid)."' ORDER BY posttime DESC LIMIT 1"); $post = mysql_fetch_array($r_post);
if( $post['userid'] != 0 ) { $r_user = thwb_query("SELECT username FROM ".$pref."user WHERE userid=$post[userid]"); $user = mysql_fetch_array($r_user); $author = $user['username']; } else { $author = $post['postguestname']; }
thwb_query("UPDATE ".$pref."thread SET threadtime=$post[posttime], threadlastreplyby='" . addslashes($author) . "' WHERE threadid='".intval($threadid)."'"); }
function checksize($ic_avatar) { global $err_msg, $config; if ( $ic_avatarsize = @GetImageSize($ic_avatar) ) { if ( $ic_avatarsize[0] > $config['avatarwidth'] ) { $err_msg .= 'Das Avatar-Bild ist zu breit.<br>'; } if ( $ic_avatarsize[1] > $config['avatarheight'] ) { $err_msg .= 'Das Avatar-Bild ist zu hoch.<br>'; } if ( $ic_avatarsize[2] > 3 ) { $err_msg .= 'Das Avatar-Bild hat ein ungültiges Format.<br>'; } } else { $err_msg .= 'Das Avatar-Bild konnte nicht geladen werden.<br>'; } }
// Funktion zur Ersetzung von gebannten Wörtern (groß/klein egal) function check_banned($text) { global $pref; $r_bwords = thwb_query("SELECT banword, modword FROM $pref"."bannedwords"); if( mysql_num_rows($r_bwords) != 0 ) { $bwords = array(); $mwords = array(); while( list($bword, $mword) = mysql_fetch_row($r_bwords) ) { $bwords[] = "/([a-z])*(" . $bword . ")([a-z])*/i"; $mwords[] = $mword; } mysql_free_result($r_bwords); $text = preg_replace($bwords, $mwords, $text); }
return $text; }
function compress_page($output) { global $HTTP_SERVER_VARS, $config;
if( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzcompress') && $config['compression'] ) { $output .= '<!-- gzcompress()ed -->'; // http://www.p hp.net/manual/en/function.gzcompress.p hp -- comments header('Content-Encoding: gzip'); $size = strlen($output); $crc = crc32($output); $output = gzcompress($output, 1);
print "\x1f\x8b\x08\x00\x00\x00\x00\x00"; print substr($output, 0, strlen($output) - 4); print pack('V', $crc); print pack('V', $size); } else { print $output; } }
?>
|