Verzeichnisstruktur phpBB-1.0.0
- Veröffentlicht
- 15.12.2000
So funktioniert es
|
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
functions.php
001 <?php
002 /***************************************************************************
003 functions.php - description
004 -------------------
005 begin : Sat June 17 2000
006 copyright : (C) 2000 by James Atkinson
007 email : james@totalgeek.org
008
009 $Id: functions.php,v 1.58 2000/12/09 20:19:09 thefinn Exp $
010
011 ***************************************************************************/
012
013 /***************************************************************************
014 *
015 * This program is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU General Public License as published by
017 * the Free Software Foundation; either version 2 of the License, or
018 * (at your option) any later version.
019 *
020 ***************************************************************************/
021
022 /**
023 * Start session-management functions - Nathan Codding, July 21, 2000.
024 */
025
026 /**
027 * new_session()
028 * Adds a new session to the database for the given userid.
029 * Returns the new session ID.
030 * Also deletes all expired sessions from the database, based on the given session lifespan.
031 */
032 function new_session($userid, $remote_ip, $lifespan, $db) {
033
034 mt_srand((double)microtime()*1000000);
035 $sessid = mt_rand();
036
037 $currtime = (string) (time());
038 $expirytime = (string) (time() - $lifespan);
039
040 $deleteSQL = "DELETE FROM sessions WHERE (start_time < $expirytime)";
041 $delresult = mysql_query($deleteSQL, $db);
042
043 if (!$delresult) {
044 die("Delete failed in new_session()");
045 }
046
047 $sql = "INSERT INTO sessions (sess_id, user_id, start_time, remote_ip) VALUES ($sessid, $userid, $currtime, '$remote_ip')";
048
049 $result = mysql_query($sql, $db);
050
051 if ($result) {
052 return $sessid;
053 } else {
054 echo mysql_errno().": ".mysql_error()."<BR>";
055 die("Insert failed in new_session()");
056 } // if/else
057
058 } // new_session()
059
060 /**
061 * Sets the sessID cookie for the given session ID. the $cookietime parameter
062 * is no longer used, but just hasn't been removed yet. It'll break all the modules
063 * (just login) that call this code when it gets removed.
064 * Sets a cookie with no specified expiry time. This makes the cookie last until the
065 * user's browser is closed. (at last that's the case in IE5 and NS4.7.. Haven't tried
066 * it with anything else.)
067 */
068 function set_session_cookie($sessid, $cookietime, $cookiename, $cookiepath, $cookiedomain, $cookiesecure) {
069
070 // This sets a cookie that will persist until the user closes their browser window.
071 // since session expiry is handled on the server-side, cookie expiry time isn't a big deal.
072 setcookie($cookiename,$sessid,'',$cookiepath,$cookiedomain,$cookiesecure);
073
074 } // set_session_cookie()
075
076
077 /**
078 * Returns the userID associated with the given session, based on
079 * the given session lifespan $cookietime and the given remote IP
080 * address. If no match found, returns 0.
081 */
082 function get_userid_from_session($sessid, $cookietime, $remote_ip, $db) {
083
084 $mintime = time() - $cookietime;
085 $sql = "SELECT user_id FROM sessions WHERE (sess_id = $sessid) AND (start_time > $mintime) AND (remote_ip = '$remote_ip')";
086 $result = mysql_query($sql, $db);
087 if (!$result) {
088 echo mysql_error() . "<br>\n";
089 die("Error doing DB query in get_userid_from_session()");
090 }
091 $row = mysql_fetch_array($result);
092
093 if (!$row) {
094 return 0;
095 } else {
096 return $row[user_id];
097 }
098
099 } // get_userid_from_session()
100
101 /**
102 * Refresh the start_time of the given session in the database.
103 * This is called whenever a page is hit by a user with a valid session.
104 */
105 function update_session_time($sessid, $db) {
106
107 $newtime = (string) time();
108 $sql = "UPDATE sessions SET start_time=$newtime WHERE (sess_id = $sessid)";
109 $result = mysql_query($sql, $db);
110 if (!$result) {
111 echo mysql_error() . "<br>\n";
112 die("Error doing DB update in update_session_time()");
113 }
114 return 1;
115
116 } // update_session_time()
117
118 /**
119 * Delete the given session from the database. Used by the logout page.
120 */
121 function end_user_session($userid, $db) {
122
123 $sql = "DELETE FROM sessions WHERE (user_id = $userid)";
124 $result = mysql_query($sql, $db);
125 if (!$result) {
126 echo mysql_error() . "<br>\n";
127 die("Delete failed in end_user_session()");
128 }
129 return 1;
130
131 } // end_session()
132
133 /**
134 * Prints either "logged in as [username]. Log out." or
135 * "Not logged in. Log in.", depending on the value of
136 * $user_logged_in.
137 */
138 function print_login_status($user_logged_in, $username, $url_phpbb) {
139 global $phpEx;
140 if($user_logged_in) {
141 echo "<b>Logged in as $username. <a href=\"$url_phpbb/logout.$phpEx\">Log out.</a></b><br>\n";
142 } else {
143 echo "<b>Not logged in. <a href=\"$url_phpbb/login.$phpEx\">Log in.</a></b><br>\n";
144 }
145 } // print_login_status()
146
147 /**
148 * Prints a link to either login.php or logout.php, depending
149 * on whether the user's logged in or not.
150 */
151 function make_login_logout_link($user_logged_in, $url_phpbb) {
152 global $phpEx;
153 if ($user_logged_in) {
154 $link = "<a href=\"$url_phpbb/logout.$phpEx\">Logout</a>";
155 } else {
156 $link = "<a href=\"$url_phpbb/login.$phpEx\">Login</a>";
157 }
158 return $link;
159 } // make_login_logout_link()
160
161 /**
162 * End session-management functions
163 */
164
165 /*
166 * Gets the total number of topics in a form
167 */
168 function get_total_topics($forum_id, $db) {
169 $sql = "SELECT count(*) AS total FROM topics WHERE forum_id = '$forum_id'";
170 if(!$result = mysql_query($sql, $db))
171 return("ERROR");
172 if(!$myrow = mysql_fetch_array($result))
173 return("ERROR");
174
175 return($myrow[total]);
176 }
177 /*
178 * Shows the 'header' data from the header/meta/footer table
179 */
180 function showheader($db) {
181 $sql = "SELECT header FROM headermetafooter";
182 if($result = mysql_query($sql, $db)) {
183 if($header = mysql_fetch_array($result)) {
184 echo stripslashes($header[header]);
185 }
186 }
187 }
188 /*
189 * Shows the meta information from the header/meta/footer table
190 */
191 function showmeta($db) {
192 $sql = "SELECT meta FROM headermetafooter";
193 if($result = mysql_query($sql, $db)) {
194 if($meta = mysql_fetch_array($result)) {
195 echo stripslashes($meta[meta]);
196 }
197 }
198 }
199 /*
200 * Show the footer from the header/meta/footer table
201 */
202 function showfooter($db) {
203 $sql = "SELECT footer FROM headermetafooter";
204 if($result = mysql_query($sql, $db)) {
205 if($footer = mysql_fetch_array($result)) {
206 echo stripslashes($footer[footer]);
207 }
208 }
209 }
210
211 /*
212 * Used to keep track of all the people viewing the forum at this time
213 * Anyone who's been on the board within the last 300 seconds will be
214 * returned. Any data older then 300 seconds will be removed
215 */
216 function get_whosonline($IP, $username, $forum, $db) {
217 if($username == '')
218 $username = "Guest";
219
220 $time= explode( " ", microtime());
221 $userusec= (double)$time[0];
222 $usersec= (double)$time[1];
223 $deleteuser= mysql_query( "delete from whosonline where date < $usersec - 300", $db);
224 $userlog= mysql_fetch_row(MYSQL_QUERY( "SELECT * FROM whosonline where IP = '$IP'", $db));
225 if($userlog == false) {
226 $ok= @mysql_query( "insert INTO whosonline (ID,IP,DATE,username,forum) VALUES('$User_Id','$IP','$usersec', '$username', '$forum')", $db)or die( "Unable to query db!");
227 }
228 $resultlogtab = mysql_query("SELECT Count(*) as total FROM whosonline", $db);
229 $numberlogtab = mysql_fetch_array($resultlogtab);
230 return($numberlogtab[total]);
231
232 }
233
234 /*
235 * Returns the total number of posts in the whole system, a forum, or a topic
236 * Also can return the number of users on the system.
237 */
238 function get_total_posts($id, $db, $type) {
239 switch($type) {
240 case 'users':
241 $sql = "SELECT count(*) AS total FROM users WHERE user_id != -1";
242 break;
243 case 'all':
244 $sql = "SELECT count(*) AS total FROM posts";
245 break;
246 case 'forum':
247 $sql = "SELECT count(*) AS total FROM posts WHERE forum_id = '$id'";
248 break;
249 case 'topic':
250 $sql = "SELECT count(*) AS total FROM posts WHERE topic_id = '$id'";
251 break;
252 // Old, we should never get this.
253 case 'user':
254 die("Should be using the users.user_posts column for this.");
255 }
256 if(!$result = mysql_query($sql, $db))
257 return("ERROR");
258 if(!$myrow = mysql_fetch_array($result))
259 return("0");
260
261 return($myrow[total]);
262
263 }
264
265 /*
266 * Returns the most recent post in a forum, or a topic
267 */
268 function get_last_post($id, $db, $type) {
269 switch($type) {
270 case 'forum':
271 $sql = "SELECT p.post_time, p.poster_id, u.username FROM posts p, users u WHERE p.forum_id = '$id' AND p.poster_id = u.user_id ORDER BY post_time DESC";
272 break;
273 case 'topic':
274 $sql = "SELECT p.post_time, u.username FROM posts p, users u WHERE p.topic_id = '$id' AND p.poster_id = u.user_id ORDER BY post_time DESC";
275 break;
276 case 'user':
277 $sql = "SELECT p.post_time FROM posts p WHERE p.poster_id = '$id'";
278 break;
279 }
280 if(!$result = mysql_query($sql, $db))
281 return("ERROR");
282
283 if(!$myrow = mysql_fetch_array($result))
284 return("No posts");
285 if($type != "user")
286 $val = sprintf("%s <br> by %s", $myrow[post_time], $myrow[username]);
287 else
288 $val = $myrow[post_time];
289
290 return($val);
291 }
292
293 /*
294 * Returns an array of all the moderators of a forum
295 */
296 function get_moderators($forum_id, $db) {
297 $sql = "SELECT u.user_id, u.username FROM users u, forum_mods f WHERE f.forum_id = '$forum_id' and f.user_id = u.user_id";
298 if(!$result = mysql_query($sql, $db))
299 return("-1");
300 if(!$myrow = mysql_fetch_array($result))
301 return("-1");
302 do {
303 $array[] = array("$myrow[user_id]" => "$myrow[username]");
304 } while($myrow = mysql_fetch_array($result));
305 return($array);
306 }
307
308 /*
309 * Checks if a user (user_id) is a moderator of a perticular forum (forum_id)
310 * Retruns 1 if TRUE, 0 if FALSE or Error
311 */
312 function is_moderator($forum_id, $user_id, $db) {
313 $sql = "SELECT user_id FROM forum_mods WHERE forum_id = '$forum_id' AND user_id = '$user_id'";
314 if(!$result = mysql_query($sql, $db))
315 return("0");
316 if(!$myrow = mysql_fetch_array($result))
317 return("0");
318 if($myrow[user_id] != '')
319 return("1");
320 else
321 return("0");
322 }
323
324 /**
325 * Nathan Codding - July 19, 2000
326 * Checks the given password against the DB for the given username. Returns true if good, false if not.
327 */
328 function check_user_pw($username, $password, $db) {
329 $password = md5($password);
330 $sql = "SELECT user_id FROM users WHERE (username = '$username') AND (user_password = '$password')";
331 $resultID = mysql_query($sql, $db);
332 if (!$resultID) {
333 echo mysql_error() . "<br>";
334 die("Error doing DB query in check_user_pw()");
335 }
336 return mysql_num_rows($resultID);
337 } // check_user_pw()
338
339
340 /**
341 * Nathan Codding - July 19, 2000
342 * Returns a count of the given userid's private messages.
343 */
344 function get_pmsg_count($user_id, $db) {
345 $sql = "SELECT msg_id FROM priv_msgs WHERE (to_userid = $user_id)";
346 $resultID = mysql_query($sql);
347 if (!$resultID) {
348 echo mysql_error() . "<br>";
349 die("Error doing DB query in get_pmsg_count");
350 }
351 return mysql_num_rows($resultID);
352 } // get_pmsg_count()
353
354
355 /**
356 * Nathan Codding - July 19, 2000
357 * Checks if a given username exists in the DB. Returns true if so, false if not.
358 */
359 function check_username($username, $db) {
360 $sql = "SELECT user_id FROM users WHERE (username = '$username') AND (user_level != '-1')";
361 $resultID = mysql_query($sql);
362 if (!$resultID) {
363 echo mysql_error() . "<br>";
364 die("Error doing DB query in check_username()");
365 }
366 return mysql_num_rows($resultID);
367 } // check_username()
368
369
370 /**
371 * Nathan Codding, July 19/2000
372 * Get a user's data, given their user ID.
373 */
374
375 function get_userdata_from_id($userid, $db) {
376
377 $sql = "SELECT * FROM users WHERE user_id = $userid";
378 if(!$result = mysql_query($sql, $db)) {
379 $userdata = array("error" => "1");
380 return ($userdata);
381 }
382 if(!$myrow = mysql_fetch_array($result)) {
383 $userdata = array("error" => "1");
384 return ($userdata);
385 }
386
387 return($myrow);
388 }
389
390 /*
391 * Gets user's data based on their username
392 */
393 function get_userdata($username, $db) {
394 $sql = "SELECT * FROM users WHERE username = '$username' AND user_level != -1";
395 if(!$result = mysql_query($sql, $db))
396 $userdata = array("error" => "1");
397 if(!$myrow = mysql_fetch_array($result))
398 $userdata = array("error" => "1");
399
400 return($myrow);
401 }
402
403 /*
404 * Returns all the rows in the themes table
405 */
406 function setuptheme($theme, $db) {
407 $sql = "SELECT * FROM themes WHERE theme_id = '$theme'";
408 if(!$result = mysql_query($sql, $db))
409 return(0);
410 if(!$myrow = mysql_fetch_array($result))
411 return(0);
412 return($myrow);
413 }
414
415 /*
416 * Checks if a forum or a topic exists in the database. Used to prevent
417 * users from simply editing the URL to post to a non-existant forum or topic
418 */
419 function does_exists($id, $db, $type) {
420 switch($type) {
421 case 'forum':
422 $sql = "SELECT forum_id FROM forums WHERE forum_id = '$id'";
423 break;
424 case 'topic':
425 $sql = "SELECT topic_id FROM topics WHERE topic_id = '$id'";
426 break;
427 }
428 if(!$result = mysql_query($sql, $db))
429 return(0);
430 if(!$myrow = mysql_fetch_array($result))
431 return(0);
432 return(1);
433 }
434
435 /*
436 * Checks if a topic is locked
437 */
438 function is_locked($topic, $db) {
439 $sql = "SELECT topic_status FROM topics WHERE topic_id = '$topic'";
440 if(!$r = mysql_query($sql, $db))
441 return(FALSE);
442 if(!$m = mysql_fetch_array($r))
443 return(FALSE);
444 if($m[topic_status] == 1)
445 return(TRUE);
446 else
447 return(FALSE);
448 }
449
450 /*
451 * Changes :) to an <IMG> tag based on the smiles table in the database
452 * TODO: Get rid of global variables.
453 */
454 function smile($message) {
455 global $db, $url_smiles;
456
457 if ($getsmiles = mysql_query("SELECT * FROM smiles")){
458 while ($smiles = mysql_fetch_array($getsmiles)) {
459 $message = str_replace($smiles[code], "<IMG SRC=\"$url_smiles/$smiles[smile_url]\">", $message);
460 }
461 }
462 return($message);
463 }
464
465 /*
466 * Changes a Smiliy <IMG> tag into its corrasponding smile
467 * TODO: Get rid of golbal variables, and implement a method of distinguishing between :D and :grin: using the <IMG> tag
468 */
469 function desmile($message) {
470 // Ick Ick Global variables...remind me to fix these! - theFinn
471 global $db, $url_smiles;
472
473 if ($getsmiles = mysql_query("SELECT * FROM smiles")){
474 while ($smiles = mysql_fetch_array($getsmiles)) {
475 $message = str_replace("<IMG SRC=\"$url_smiles/$smiles[smile_url]\">", $smiles[code], $message);
476 }
477 }
478 return($message);
479 }
480
481 /**
482 * bbdecode/bbencode functions:
483 * Rewritten - Nathan Codding - Aug 24, 2000
484 * Using Perl-Compatible regexps now. Won't kill special chars
485 * outside of a [code]...[/code] block now, and all BBCode tags
486 * are implemented.
487 * Note: the "i" matching switch is used, so BBCode tags are
488 * case-insensitive.
489 */
490 function bbdecode($message) {
491
492 // Undo [code]
493 $message = preg_replace("#<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Code:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><PRE>(.*?)</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->#s", "[code]\\1[/code]", $message);
494
495 // Undo [quote]
496 $message = preg_replace("#<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Quote:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><BLOCKQUOTE>(.*?)</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->#s", "[quote]\\1[/quote]", $message);
497
498 // Undo [b] and [i]
499 $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message);
500 $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message);
501
502 // Undo [url] (both forms)
503 $message = preg_replace("#<!-- BBCode Start --><A HREF=\"http://(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode End -->#s", "[url=\\1]\\2[/url]", $message);
504
505 // Undo [email]
506 $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message);
507
508 // Undo [img]
509 $message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message);
510
511 // Undo lists (unordered/ordered)
512
513 // unordered list code..
514 $matchCount = preg_match_all("#<!-- BBCode ulist Start --><UL>(.*?)</UL><!-- BBCode ulist End -->#s", $message, $matches);
515
516 for ($i = 0; $i < $matchCount; $i++)
517 {
518 $currMatchTextBefore = preg_quote($matches[1][$i]);
519 $currMatchTextBefore = escape_slashes($currMatchTextBefore);
520 $currMatchTextAfter = preg_replace("#<LI>#s", "[*]", $matches[1][$i]);
521
522 $message = preg_replace("#<!-- BBCode ulist Start --><UL>$currMatchTextBefore</UL><!-- BBCode ulist End -->#s", "[list]" . $currMatchTextAfter . "[/list]", $message);
523 }
524
525 // ordered list code..
526 $matchCount = preg_match_all("#<!-- BBCode olist Start --><OL TYPE=([A1])>(.*?)</OL><!-- BBCode olist End -->#si", $message, $matches);
527
528 for ($i = 0; $i < $matchCount; $i++)
529 {
530 $currMatchTextBefore = preg_quote($matches[2][$i]);
531 $currMatchTextBefore = escape_slashes($currMatchTextBefore);
532 $currMatchTextAfter = preg_replace("#<LI>#s", "[*]", $matches[2][$i]);
533
534 $message = preg_replace("#<!-- BBCode olist Start --><OL TYPE=([A1])>$currMatchTextBefore</OL><!-- BBCode olist End -->#si", "[list=\\1]" . $currMatchTextAfter . "[/list]", $message);
535 }
536
537 return($message);
538 }
539
540 function bbencode($message) {
541
542 // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
543 $matchCount = preg_match_all("#\[code\](.*?)\[/code\]#si", $message, $matches);
544
545 for ($i = 0; $i < $matchCount; $i++)
546 {
547 $currMatchTextBefore = preg_quote($matches[1][$i]);
548 $currMatchTextBefore = escape_slashes($currMatchTextBefore);
549 $currMatchTextAfter = htmlspecialchars($matches[1][$i]);
550
551 $message = preg_replace("/\[code\]$currMatchTextBefore\[\/code\]/si", "<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Code:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><PRE>$currMatchTextAfter</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->", $message);
552 }
553
554 // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
555 $message = preg_replace("/\[quote\](.*?)\[\/quote]/si", "<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Quote:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><BLOCKQUOTE>\\1</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->", $message);
556
557 // [b] and [/b] for bolding text.
558 $message = preg_replace("/\[b\](.*?)\[\/b\]/si", "<!-- BBCode Start --><B>\\1</B><!-- BBCode End -->", $message);
559
560 // [i] and [/i] for italicizing text.
561 $message = preg_replace("/\[i\](.*?)\[\/i\]/si", "<!-- BBCode Start --><I>\\1</I><!-- BBCode End -->", $message);
562
563 // [url]www.phpbb.com[/url] code..
564 $message = preg_replace("/\[url\](http:\/\/)?(.*?)\[\/url\]/si", "<!-- BBCode Start --><A HREF=\"http://\\2\" TARGET=\"_blank\">\\2</A><!-- BBCode End -->", $message);
565
566 // [url=www.phpbb.com]phpBB[/url] code..
567 $message = preg_replace("/\[url=(http:\/\/)?(.*?)\](.*?)\[\/url\]/si", "<!-- BBCode Start --><A HREF=\"http://\\2\" TARGET=\"_blank\">\\3</A><!-- BBCode End -->", $message);
568
569 // [email]user@domain.tld[/email] code..
570 $message = preg_replace("/\[email\](.*?)\[\/email\]/si", "<!-- BBCode Start --><A HREF=\"mailto:\\1\">\\1</A><!-- BBCode End -->", $message);
571
572 // [img]image_url_here[/img] code..
573 $message = preg_replace("/\[img\](.*?)\[\/img\]/si", "<!-- BBCode Start --><IMG SRC=\"\\1\"><!-- BBCode End -->", $message);
574
575 // unordered list code..
576 $matchCount = preg_match_all("/\[list\](.*?)\[\/list\]/si", $message, $matches);
577
578 for ($i = 0; $i < $matchCount; $i++)
579 {
580 $currMatchTextBefore = preg_quote($matches[1][$i]);
581 $currMatchTextBefore = escape_slashes($currMatchTextBefore);
582 $currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[1][$i]);
583
584 $message = preg_replace("/\[list\]$currMatchTextBefore\[\/list\]/si", "<!-- BBCode ulist Start --><UL>$currMatchTextAfter</UL><!-- BBCode ulist End -->", $message);
585 }
586
587 // ordered list code..
588 $matchCount = preg_match_all("/\[list=([a1])\](.*?)\[\/list\]/si", $message, $matches);
589
590 for ($i = 0; $i < $matchCount; $i++)
591 {
592 $currMatchTextBefore = preg_quote($matches[2][$i]);
593 $currMatchTextBefore = escape_slashes($currMatchTextBefore);
594 $currMatchTextAfter = preg_replace("\\[\*\]/si", "<LI>", $matches[2][$i]);
595
596 $message = preg_replace("/\[list=([a1])\]$currMatchTextBefore\[\/list\]/si", "<!-- BBCode olist Start --><OL TYPE=\\1>$currMatchTextAfter</OL><!-- BBCode olist End -->", $message);
597 }
598
599 return($message);
600 }
601
602
603 /**
604 * Nathan Codding - Oct. 30, 2000
605 *
606 * Escapes the "/" character with "\/". This is useful when you need
607 * to stick a runtime string into a PREG regexp that is being delimited
608 * with slashes.
609 */
610 function escape_slashes($input)
611 {
612 $output = preg_replace("#/#", "\/", $input);
613 return $output;
614 }
615
616 /*
617 * Returns the name of the forum based on ID number
618 */
619 function get_forum_name($forum_id, $db) {
620 $sql = "SELECT forum_name FROM forums WHERE forum_id = '$forum_id'";
621 if(!$r = mysql_query($sql, $db))
622 return("ERROR");
623 if(!$m = mysql_fetch_array($r))
624 return("None");
625 return($m[forum_name]);
626 }
627
628
629 /**
630 * Modified by Nathan Codding - July 20, 2000.
631 * Made it only work on URLs and e-mail addresses preceeded by a space, in order to stop
632 * mangling HTML code.
633 *
634 * The Following function was taken from the Scriplets area of http://www.phpwizard.net, and was written by Tobias Ratschiller.
635 * Visit phpwizard.net today, its an excellent site!
636 */
637
638 function make_clickable($text) {
639 $ret = eregi_replace(" ([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", " <a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $text);
640 $ret = eregi_replace(" (([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", " <a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $ret);
641 return($ret);
642 }
643
644 /**
645 * Nathan Codding - August 24, 2000.
646 * Takes a string, and does the reverse of the PHP standard function
647 * htmlspecialchars().
648 */
649 function undo_htmlspecialchars($input) {
650 $input = preg_replace("/>/i", ">", $input);
651 $input = preg_replace("/</i", "<", $input);
652 $input = preg_replace("/"/i", "\"", $input);
653 $input = preg_replace("/&/i", "&", $input);
654
655 return $input;
656 }
657 /*
658 * Make sure a username isn't on the disallow list
659 */
660 function validate_username($username, $db) {
661 $sql = "SELECT disallow_username FROM disallow WHERE disallow_username = '" . addslashes($username) . "'";
662 if(!$r = mysql_query($sql, $db))
663 return(0);
664 if($m = mysql_fetch_array($r)) {
665 if($m[disallow_username] == $username)
666 return(1);
667 else
668 return(0);
669 }
670 return(0);
671 }
672 /*
673 * Check if this is the first post in a topic. Used in editpost.php
674 */
675 function is_first_post($topic_id, $post_id, $db) {
676 $sql = "SELECT post_id FROM posts WHERE topic_id = '$topic_id' ORDER BY post_id LIMIT 1";
677 if(!$r = mysql_query($sql, $db))
678 return(0);
679 if(!$m = mysql_fetch_array($r))
680 return(0);
681 if($m[post_id] == $post_id)
682 return(1);
683 else
684 return(0);
685 }
686
687 /*
688 * Replaces banned words in a string with their replacements
689 */
690 function censor_string($string, $db) {
691 $sql = "SELECT word, replacement FROM words";
692 if(!$r = mysql_query($sql, $db))
693 die("Error, could not contact the database! Please check your database settings in config.$phpEx");
694 while($w = mysql_fetch_array($r)) {
695 $word = stripslashes($w[word]);
696 $replacement = stripslashes($w[replacement]);
697 $string = eregi_replace(" $word", " $replacement", $string);
698 $string = eregi_replace("^$word", "$replacement", $string);
699 $string = eregi_replace("<BR>$word", "<BR>$replacement", $string);
700 }
701 return($string);
702 }
703
704 function is_banned($ipuser, $type, $db) {
705
706 // Remove old bans
707 $sql = "DELETE FROM banlist WHERE (ban_end < ". mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")).") AND (ban_end > 0)";
708 @mysql_query($sql, $db);
709
710 switch($type) {
711 case "ip":
712 $sql = "SELECT ban_ip FROM banlist";
713 if($r = mysql_query($sql, $db)) {
714 while($iprow = mysql_fetch_array($r)) {
715 $ip = $iprow[ban_ip];
716 if($ip[strlen($ip) - 1] == ".") {
717 $db_ip = explode(".", $ip);
718 $this_ip = explode(".", $ipuser);
719
720 for($x = 0; $x < count($db_ip) - 1; $x++)
721 $my_ip .= $this_ip[$x] . ".";
722
723 if($my_ip == $ip)
724 return(TRUE);
725 }
726 else {
727 if($ipuser == $ip)
728 return(TRUE);
729 }
730 }
731 }
732 else
733 return(FALSE);
734 break;
735 case "username":
736 $sql = "SELECT ban_userid FROM banlist WHERE ban_userid = '$ipuser'";
737 if($r = mysql_query($sql, $db)) {
738 if(mysql_num_rows($r) > 0)
739 return(TRUE);
740 }
741 break;
742 }
743
744 return(FALSE);
745 }
746
747
748 ?>
749