home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / private_messages / functions.php < prev    next >
Encoding:
PHP Script  |  2002-09-16  |  75.9 KB  |  1,836 lines

  1. <?php
  2.  
  3. ######################################################################
  4. # PHP-NUKE: Web Portal System
  5. # ===========================
  6. #
  7. # Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)
  8. # http://phpnuke.org
  9. #
  10. # Based on phpBB Forum
  11. # ====================
  12. # Copyright (c) 2001 by The phpBB Group
  13. # http://www.phpbb.com
  14. #
  15. # Integration based on PHPBB Forum Addon 1.4.0
  16. # ============================================
  17. # Copyright (c) 2001 by Richard Tirtadji
  18. # http://nukeaddon.com
  19. #
  20. # This program is free software. You can redistribute it and/or modify
  21. # it under the terms of the GNU General Public License as published by
  22. # the Free Software Foundation; either version 2 of the License.
  23. ######################################################################
  24.  
  25. $functions = 1;
  26.  
  27. require_once("mainfile.php");
  28. $module_name = basename(dirname(__FILE__));
  29. get_lang($module_name);
  30.  
  31. include ("config.php");
  32. $imagesdir="images/forum/icons";
  33. $subjecticonsdir="images/forum/subject";
  34. $rankimagesdir="images/forum/special";
  35. $search_results ="20";
  36. $module_member = "Memberslist";
  37. $url_smiles = "images/forum/smilies";
  38.  
  39. function new_session($userid, $remote_ip, $lifespan, $db) {
  40.  
  41.         mt_srand((double)microtime()*1000000);
  42.         $sessid = mt_rand();
  43.  
  44.         $currtime = (string) (time());
  45.         $expirytime = (string) (time() - $lifespan);
  46.  
  47.         $deleteSQL = "DELETE FROM sessions WHERE (start_time < $expirytime)";
  48.         $delresult = mysql_query($deleteSQL, $db);
  49.  
  50.         if (!$delresult) {
  51.                 die("Delete failed in new_session()");
  52.         }
  53.  
  54.         $sql = "INSERT INTO sessions (sess_id, user_id, start_time, remote_ip) VALUES ($sessid, $userid, $currtime, '$remote_ip')";
  55.  
  56.         $result = mysql_query($sql, $db);
  57.  
  58.         if ($result) {
  59.                 return $sessid;
  60.         } else {
  61.                 echo mysql_errno().": ".mysql_error()."<BR>";
  62.                 die("Insert failed in new_session()");
  63.         } // if/else
  64.  
  65. } // new_session()
  66.  
  67. /**
  68.  * Sets the sessID cookie for the given session ID. the $cookietime parameter
  69.  * is no longer used, but just hasn't been removed yet. It'll break all the modules
  70.  * (just login) that call this code when it gets removed.
  71.  * Sets a cookie with no specified expiry time. This makes the cookie last until the
  72.  * user's browser is closed. (at last that's the case in IE5 and NS4.7.. Haven't tried
  73.  * it with anything else.)
  74.  */
  75. function set_session_cookie($sessid, $cookietime, $cookiename, $cookiepath, $cookiedomain, $cookiesecure) {
  76.  
  77.         // This sets a cookie that will persist until the user closes their browser window.
  78.         // since session expiry is handled on the server-side, cookie expiry time isn't a big deal.
  79.         setcookie($cookiename,$sessid,'',$cookiepath,$cookiedomain,$cookiesecure);
  80.  
  81. } // set_session_cookie()
  82.  
  83.  
  84. /**
  85.  * Returns the userID associated with the given session, based on
  86.  * the given session lifespan $cookietime and the given remote IP
  87.  * address. If no match found, returns 0.
  88.  */
  89. function get_userid_from_session($sessid, $cookietime, $remote_ip, $db) {
  90.  
  91.         $mintime = time() - $cookietime;
  92.         $sql = "SELECT user_id FROM sessions WHERE (sess_id = $sessid) AND (start_time > $mintime) AND (remote_ip = '$remote_ip')";
  93.         $result = mysql_query($sql, $db);
  94.         if (!$result) {
  95.                 echo mysql_error() . "<br>\n";
  96.                 die("Error doing DB query in get_userid_from_session()");
  97.         }
  98.         $row = mysql_fetch_array($result);
  99.  
  100.         if (!$row) {
  101.                 return 0;
  102.         } else {
  103.                 return $row[user_id];
  104.         }
  105.  
  106. } // get_userid_from_session()
  107.  
  108. /**
  109.  * Refresh the start_time of the given session in the database.
  110.  * This is called whenever a page is hit by a user with a valid session.
  111.  */
  112. function update_session_time($sessid, $db) {
  113.  
  114.         $newtime = (string) time();
  115.         $sql = "UPDATE sessions SET start_time=$newtime WHERE (sess_id = $sessid)";
  116.         $result = mysql_query($sql, $db);
  117.         if (!$result) {
  118.                 echo mysql_error() . "<br>\n";
  119.                 die("Error doing DB update in update_session_time()");
  120.         }
  121.         return 1;
  122.  
  123. } // update_session_time()
  124.  
  125. /**
  126.  * Delete the given session from the database. Used by the logout page.
  127.  */
  128. function end_user_session($userid, $db) {
  129.  
  130.         $sql = "DELETE FROM sessions WHERE (user_id = $userid)";
  131.         $result = mysql_query($sql, $db);
  132.         if (!$result) {
  133.                 echo mysql_error() . "<br>\n";
  134.                 die("Delete failed in end_user_session()");
  135.         }
  136.         return 1;
  137.  
  138. } // end_session()
  139.  
  140. /**
  141.  * Prints either "logged in as [username]. Log out." or
  142.  * "Not logged in. Log in.", depending on the value of
  143.  * $user_logged_in.
  144.  */
  145. function print_login_status($user_logged_in, $username, $url_phpbb) {
  146.         global $l_loggedinas, $l_notloggedin, $l_logout, $l_login;
  147.  
  148.         if($user_logged_in) {
  149.                 echo "<b>$l_loggedinas $username. <a href=\"$url_phpbb/logout.php\">$l_logout.</a></b><br>\n";
  150.         } else {
  151.                 echo "<b>$l_notloggedin. <a href=\"$url_phpbb/login.php\">$l_login.</a></b><br>\n";
  152.         }
  153. } // print_login_status()
  154.  
  155. /**
  156.  * Prints a link to either login.php or logout.php, depending
  157.  * on whether the user's logged in or not.
  158.  */
  159. function make_login_logout_link($user_logged_in, $url_phpbb) {
  160.         global $l_logout, $l_login;
  161.         if ($user_logged_in) {
  162.                 $link = "<a href=\"$url_phpbb/logout.php\">$l_logout</a>";
  163.         } else {
  164.                 $link = "<a href=\"$url_phpbb/login.php\">$l_login</a>";
  165.         }
  166.         return $link;
  167. } // make_login_logout_link()
  168.  
  169. /**
  170.  * End session-management functions
  171.  */
  172.  
  173. /*
  174.  * Gets the total number of topics in a form
  175.  */
  176.  #OK
  177. function get_total_topics($forum_id, $db) {
  178.         global $prefix;
  179.         $sql = "SELECT count(*) AS total FROM ".$prefix."_bbtopics WHERE forum_id = '$forum_id'";
  180.         if(!$result = mysql_query($sql))
  181.                 return(""._BBERROR."");
  182.         if(!$myrow = mysql_fetch_array($result))
  183.                 return(""._BBERROR."");
  184.  
  185.         return($myrow[total]);
  186. }
  187. /*
  188.  * Shows the 'header' data from the header/meta/footer table
  189.  */
  190.  #OK
  191. function showheader($db) {
  192.         $sql = "SELECT header FROM headermetafooter";
  193.         if($result = mysql_query($sql)) {
  194.                 if($header = mysql_fetch_array($result)) {
  195.                         echo stripslashes($header[header]);
  196.                 }
  197.         }
  198. }
  199. /*
  200.  * Shows the meta information from the header/meta/footer table
  201.  */
  202. function showmeta($db) {
  203.         $sql = "SELECT meta FROM headermetafooter";
  204.         if($result = mysql_query($sql, $db)) {
  205.                 if($meta = mysql_fetch_array($result)) {
  206.                         echo stripslashes($meta[meta]);
  207.                 }
  208.         }
  209. }
  210. /*
  211.  * Show the footer from the header/meta/footer table
  212.  */
  213. function showfooter($db) {
  214.         $sql = "SELECT footer FROM headermetafooter";
  215.         if($result = mysql_query($sql, $db)) {
  216.                 if($footer = mysql_fetch_array($result)) {
  217.                         echo stripslashes($footer[footer]);
  218.                 }
  219.         }
  220. }
  221.  
  222. /*
  223.  * Used to keep track of all the people viewing the forum at this time
  224.  * Anyone who's been on the board within the last 300 seconds will be
  225.  * returned. Any data older then 300 seconds will be removed
  226.  */
  227. function get_whosonline($IP, $username, $forum, $db) {
  228.         global $sys_lang;
  229.         if($username == '')
  230.                 $username = get_syslang_string($sys_lang, "l_guest");
  231.  
  232.         $time= explode(  " ", microtime());
  233.         $userusec= (double)$time[0];
  234.         $usersec= (double)$time[1];
  235.         $username= addslashes($username);
  236.         $deleteuser= mysql_query( "delete from whosonline where date < $usersec - 300", $db);
  237.         $userlog= mysql_fetch_row(MYSQL_QUERY( "SELECT * FROM whosonline where IP = '$IP'", $db));
  238.         if($userlog == false) {
  239.                 $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!");
  240.         }
  241.         $resultlogtab   = mysql_query("SELECT Count(*) as total FROM whosonline", $db);
  242.         $numberlogtab   = mysql_fetch_array($resultlogtab);
  243.         return($numberlogtab[total]);
  244. }
  245.  
  246. /*
  247.  * Returns the total number of posts in the whole system, a forum, or a topic
  248.  * Also can return the number of users on the system.
  249.  */
  250. #OK
  251. function get_total_posts($id, $db, $type) {
  252. global $prefix, $dbi, $user_prefix;
  253.    switch($type) {
  254.     case 'users':
  255.       $sql = "SELECT count(*) AS total FROM ".$user_prefix."_users u, ".$prefix."_user_status us WHERE (u.uid != -1) AND (us.user_level != -1)";
  256.       break;
  257.     case 'all':
  258.       $sql = "SELECT count(*) AS total FROM ".$prefix."_posts";
  259.       break;
  260.     case 'forum':
  261.       $sql = "SELECT count(*) AS total FROM ".$prefix."_posts WHERE forum_id = '$id'";
  262.       break;
  263.     case 'topic':
  264.       $sql = "SELECT count(*) AS total FROM ".$prefix."_posts WHERE topic_id = '$id'";
  265.       break;
  266.    // Old, we should never get this.
  267.     case 'user':
  268.       die("Should be using the users.user_posts column for this.");
  269.    }
  270.    if(!$result = mysql_query($sql))
  271.      return("ERROR");
  272.    if(!$myrow = mysql_fetch_array($result))
  273.      return("0");
  274.  
  275.    return($myrow[total]);
  276.  
  277. }
  278.  
  279. /*
  280.  * Returns the most recent post in a forum, or a topic
  281.  */
  282. function get_last_post($id, $db, $type) {
  283.    global $l_error, $l_noposts, $l_by;
  284.    switch($type) {
  285.     case 'time_fix':
  286.       $sql = "SELECT p.post_time FROM posts p WHERE p.topic_id = '$id' ORDER BY post_time DESC LIMIT 1";
  287.       break;
  288.     case 'forum':
  289.       $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 LIMIT 1";
  290.       break;
  291.     case 'topic':
  292.       $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 LIMIT 1";
  293.       break;
  294.     case 'user':
  295.       $sql = "SELECT p.post_time FROM posts p WHERE p.poster_id = '$id' LIMIT 1";
  296.       break;
  297.    }
  298.    if(!$result = mysql_query($sql, $db))
  299.      return($l_error);
  300.  
  301.    if(!$myrow = mysql_fetch_array($result))
  302.      return($l_noposts);
  303.    if(($type != 'user') && ($type != 'time_fix'))
  304.      $val = sprintf("%s <br> %s %s", $myrow[post_time], $l_by, $myrow[username]);
  305.    else
  306.      $val = $myrow[post_time];
  307.  
  308.    return($val);
  309. }
  310.  
  311.  
  312. #Func OK
  313. /*
  314.  * Returns an array of all the moderators of a forum
  315.  */
  316. function get_moderators($forum_id, $db) {
  317. global $prefix, $user_prefix;
  318.    $sql = "SELECT u.uid, u.uname FROM ".$user_prefix."_users u, ".$prefix."_forum_mods f WHERE f.forum_id = '$forum_id' and f.user_id = u.uid";
  319.     if(!$result = mysql_query($sql))
  320.      return(array());
  321.    if(!$myrow = mysql_fetch_array($result))
  322.      return(array());
  323.    do {
  324.       $array[] = array("$myrow[uid]" => "$myrow[uname]");
  325.    } while($myrow = mysql_fetch_array($result));
  326.    return($array);
  327. }
  328.  
  329. /*
  330.  * Checks if a user (user_id) is a moderator of a perticular forum (forum_id)
  331.  * Retruns 1 if TRUE, 0 if FALSE or Error
  332.  */
  333. # OK
  334. function is_moderator($forum_id, $user_id, $db) {
  335.         global $prefix;
  336.    $sql = "SELECT user_id FROM ".$prefix."_forum_mods WHERE forum_id = '$forum_id' AND user_id = '$user_id'";
  337.    if(!$result = mysql_query($sql))
  338.      return("0");
  339.    if(!$myrow = mysql_fetch_array($result))
  340.      return("0");
  341.    if($myrow[user_id] != '')
  342.      return("1");
  343.    else
  344.      return("0");
  345. }
  346.  
  347. /**
  348.  * Nathan Codding - July 19, 2000
  349.  * Checks the given password against the DB for the given username. Returns true if good, false if not.
  350.  */
  351.  #OK
  352. function check_user_pw($username, $password, $db) {
  353. global $prefix, $user_prefix;
  354.         $password = md5($password);
  355.         $username = addslashes($username);
  356.         $sql = "SELECT uid FROM ".$user_prefix."_users WHERE (uname = '$username') AND (pass = '$password')";
  357.         $resultID = mysql_query($sql);
  358.         if (!$resultID) {
  359.                 echo mysql_error() . "<br>";
  360.                 die("Error doing DB query in check_user_pw()");
  361.         }
  362.         return mysql_num_rows($resultID);
  363. } // check_user_pw()
  364.  
  365.  
  366. /**
  367.  * Nathan Codding - July 19, 2000
  368.  * Returns a count of the given userid's private messages.
  369.  */
  370. function get_pmsg_count($user_id, $db) {
  371.         $sql = "SELECT msg_id FROM priv_msgs WHERE (to_userid = $user_id)";
  372.         $resultID = mysql_query($sql);
  373.         if (!$resultID) {
  374.                 echo mysql_error() . "<br>";
  375.                 die("Error doing DB query in get_pmsg_count");
  376.         }
  377.         return mysql_num_rows($resultID);
  378. } // get_pmsg_count()
  379.  
  380.  
  381. /**
  382.  * Nathan Codding - July 19, 2000
  383.  * Checks if a given username exists in the DB. Returns true if so, false if not.
  384.  */
  385.  #OK
  386. function check_username($username, $db) {
  387. global $prefix, $user_prefix;
  388.         $username = addslashes($username);
  389.         $sql = "SELECT uid FROM ".$user_prefix."_users WHERE (uname = '$username') AND (user_level != '-1')";
  390.         $resultID = mysql_query($sql);
  391.         if (!$resultID) {
  392.                 echo mysql_error() . "<br>";
  393.                 die("Error doing DB query in check_username()");
  394.         }
  395.         return mysql_num_rows($resultID);
  396. } // check_username()
  397.  
  398.  
  399. /**
  400.  * Nathan Codding, July 19/2000
  401.  * Get a user's data, given their user ID.
  402.  */
  403. #OK
  404. function get_userdata_from_id($userid) {
  405.     global $prefix, $user_prefix;
  406.     $sql = "SELECT * FROM ".$user_prefix."_users WHERE uid = $userid";
  407.     if(!$result = mysql_query($sql)) {
  408.         $userdata = array("error" => "1");
  409.         return ($userdata);
  410.     }
  411.     if(!$myrow = mysql_fetch_array($result)) {
  412.         $userdata = array("error" => "1");
  413.         return ($userdata);
  414.     }
  415.     return($myrow);
  416. }
  417.  
  418. /*
  419.  * Gets user's data based on their username
  420.  */
  421.  #OK
  422. function get_userdata($username) {
  423.     global $prefix, $user_prefix;
  424.     $username = addslashes($username);
  425.     $sql = "SELECT * FROM ".$user_prefix."_users WHERE uname = '$username' AND user_level != -1";
  426.     if(!$result = mysql_query($sql))
  427.         $userdata = array("error" => "1");
  428.     if(!$myrow = mysql_fetch_array($result))
  429.         $userdata = array("error" => "1");
  430.     return($myrow);
  431. }
  432.  
  433. /*
  434.  * Returns all the rows in the themes table
  435.  */
  436. function setuptheme($theme, $db) {
  437.         $sql = "SELECT * FROM themes WHERE theme_id = '$theme'";
  438.         if(!$result = mysql_query($sql, $db))
  439.                 return(0);
  440.         if(!$myrow = mysql_fetch_array($result))
  441.                 return(0);
  442.         return($myrow);
  443. }
  444.  
  445. /*
  446.  * Checks if a forum or a topic exists in the database. Used to prevent
  447.  * users from simply editing the URL to post to a non-existant forum or topic
  448.  */
  449.  #OK
  450. function does_exists($id, $db, $type) {
  451. global $prefix;
  452.         switch($type) {
  453.                 case 'forum':
  454.                         $sql = "SELECT forum_id FROM ".$prefix."_forums WHERE forum_id = '$id'";
  455.                 break;
  456.                 case 'topic':
  457.                         $sql = "SELECT topic_id FROM ".$prefix."_bbtopics WHERE topic_id = '$id'";
  458.                 break;
  459.         }
  460.         if(!$result = mysql_query($sql))
  461.                 return(0);
  462.         if(!$myrow = mysql_fetch_array($result))
  463.                 return(0);
  464.         return(1);
  465. }
  466.  
  467. /*
  468.  * Checks if a topic is locked
  469.  */
  470.  #OK
  471. function is_locked($topic, $db) {
  472. global $prefix;
  473.         $sql = "SELECT topic_status FROM ".$prefix."_bbtopics WHERE topic_id = '$topic'";
  474.         if(!$r = mysql_query($sql))
  475.                 return(FALSE);
  476.         if(!$m = mysql_fetch_array($r))
  477.                 return(FALSE);
  478.         if($m[topic_status] == 1)
  479.                 return(TRUE);
  480.         else
  481.                 return(FALSE);
  482. }
  483.  
  484. /*
  485.  * Changes :) to an <IMG> tag based on the smiles table in the database.
  486.  *
  487.  * Smilies must be either:
  488.  *         - at the start of the message.
  489.  *         - at the start of a line.
  490.  *         - preceded by a space or a period.
  491.  * This keeps them from breaking HTML code and BBCode.
  492.  * TODO: Get rid of global variables.
  493.  */
  494. function smile($message) {
  495.    global $db, $url_smiles;
  496.  
  497.    // Pad it with a space so the regexp can match.
  498.    $message = ' ' . $message;
  499.  
  500.    if ($getsmiles = mysql_query("SELECT *, length(code) as length FROM nuke_smiles ORDER BY length DESC"))
  501.    {
  502.       while ($smiles = mysql_fetch_array($getsmiles))
  503.       {
  504.                         $smile_code = preg_quote($smiles[code]);
  505.                         $smile_code = str_replace('/', '//', $smile_code);
  506.                         $message = preg_replace("/([\n\\ \\.])$smile_code/si", '\1<IMG SRC="' . $url_smiles . '/' . $smiles[smile_url] . '">', $message);
  507.       }
  508.    }
  509.  
  510.    // Remove padding, return the new string.
  511.    $message = substr($message, 1);
  512.    return($message);
  513. }
  514.  
  515. /*
  516.  * Changes a Smiliy <IMG> tag into its corresponding smile
  517.  * TODO: Get rid of golbal variables, and implement a method of distinguishing between :D and :grin: using the <IMG> tag
  518.  */
  519. function desmile($message) {
  520.    // Ick Ick Global variables...remind me to fix these! - theFinn
  521.    global $db, $url_smiles;
  522.  
  523.    if ($getsmiles = mysql_query("SELECT * FROM smiles")){
  524.       while ($smiles = mysql_fetch_array($getsmiles)) {
  525.          $message = str_replace("<IMG SRC=\"$url_smiles/$smiles[smile_url]\">", $smiles[code], $message);
  526.       }
  527.    }
  528.    return($message);
  529. }
  530.  
  531. /**
  532.  * bbdecode/bbencode functions:
  533.  * Rewritten - Nathan Codding - Aug 24, 2000
  534.  * quote, code, and list rewritten again in Jan. 2001.
  535.  * All BBCode tags now implemented. Nesting and multiple occurances should be
  536.  * handled fine for all of them. Using str_replace() instead of regexps often
  537.  * for efficiency. quote, list, and code are not regular, so they are
  538.  * implemented as PDAs - probably not all that efficient, but that's the way it is.
  539.  *
  540.  * Note: all BBCode tags are case-insensitive.
  541.  */
  542.  
  543. function bbencode($message, $is_html_disabled) {
  544.  
  545.         // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
  546.         // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
  547.         $message = " " . $message;
  548.  
  549.         // First: If there isn't a "[" and a "]" in the message, don't bother.
  550.         if (! (strpos($message, "[") && strpos($message, "]")) )
  551.         {
  552.                 // Remove padding, return.
  553.                 $message = substr($message, 1);
  554.                 return $message;
  555.         }
  556.  
  557.         // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
  558.         $message = bbencode_code($message, $is_html_disabled);
  559.  
  560.         // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
  561.         $message = bbencode_quote($message);
  562.  
  563.         // [list] and [list=x] for (un)ordered lists.
  564.         $message = bbencode_list($message);
  565.  
  566.         // [b] and [/b] for bolding text.
  567.         $message = preg_replace("/\[b\](.*?)\[\/b\]/si", "<!-- BBCode Start --><B>\\1</B><!-- BBCode End -->", $message);
  568.  
  569.         // [i] and [/i] for italicizing text.
  570.         $message = preg_replace("/\[i\](.*?)\[\/i\]/si", "<!-- BBCode Start --><I>\\1</I><!-- BBCode End -->", $message);
  571.  
  572.         // [img]image_url_here[/img] code..
  573.         $message = preg_replace("/\[img\](.*?)\[\/img\]/si", "<!-- BBCode Start --><IMG SRC=\"\\1\" BORDER=\"0\"><!-- BBCode End -->", $message);
  574.  
  575.         // Patterns and replacements for URL and email tags..
  576.         $patterns = array();
  577.         $replacements = array();
  578.  
  579.         // [url]xxxx://www.phpbb.com[/url] code..
  580.         $patterns[0] = "#\[url\]([a-z]+?://){1}(.*?)\[/url\]#si";
  581.         $replacements[0] = '<!-- BBCode u1 Start --><A HREF="\1\2" TARGET="_blank">\1\2</A><!-- BBCode u1 End -->';
  582.  
  583.         // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
  584.         $patterns[1] = "#\[url\](.*?)\[/url\]#si";
  585.         $replacements[1] = '<!-- BBCode u1 Start --><A HREF="http://\1" TARGET="_blank">\1</A><!-- BBCode u1 End -->';
  586.  
  587.         // [url=xxxx://www.phpbb.com]phpBB[/url] code..
  588.         $patterns[2] = "#\[url=([a-z]+?://){1}(.*?)\](.*?)\[/url\]#si";
  589.         $replacements[2] = '<!-- BBCode u2 Start --><A HREF="\1\2" TARGET="_blank">\3</A><!-- BBCode u2 End -->';
  590.  
  591.         // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
  592.         $patterns[3] = "#\[url=(.*?)\](.*?)\[/url\]#si";
  593.         $replacements[3] = '<!-- BBCode u2 Start --><A HREF="http://\1" TARGET="_blank">\2</A><!-- BBCode u2 End -->';
  594.  
  595.         // [email]user@domain.tld[/email] code..
  596.         $patterns[4] = "#\[email\](.*?)\[/email\]#si";
  597.         $replacements[4] = '<!-- BBCode Start --><A HREF="mailto:\1">\1</A><!-- BBCode End -->';
  598.  
  599.         $message = preg_replace($patterns, $replacements, $message);
  600.  
  601.         // Remove our padding from the string..
  602.         $message = substr($message, 1);
  603.         return $message;
  604.  
  605. } // bbencode()
  606.  
  607. function bbencode_priv($message) {
  608.         global $prefix;
  609.         // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
  610.         $matchCount = preg_match_all("#\[code\](.*?)\[/code\]#si", $message, $matches);
  611.  
  612.         for ($i = 0; $i < $matchCount; $i++)
  613.         {
  614.                 $currMatchTextBefore = preg_quote($matches[1][$i]);
  615.                 $currMatchTextAfter = htmlspecialchars($matches[1][$i]);
  616.                 $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);
  617.         }
  618.  
  619.         // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
  620.         $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);
  621.  
  622.         // [b] and [/b] for bolding text.
  623.         $message = preg_replace("#\[b\](.*?)\[/b\]#si", "<!-- BBCode Start --><B>\\1</B><!-- BBCode End -->", $message);
  624.  
  625.         // [i] and [/i] for italicizing text.
  626.         $message = preg_replace("#\[i\](.*?)\[/i\]#si", "<!-- BBCode Start --><I>\\1</I><!-- BBCode End -->", $message);
  627.  
  628.         // [url]www.phpbb.com[/url] code..
  629.         $message = preg_replace("#\[url\](http://)?(.*?)\[/url\]#si", "<!-- BBCode Start --><A HREF=\"http://\\2\" TARGET=\"_blank\">\\2</A><!-- BBCode End -->", $message);
  630.  
  631.         // [url=www.phpbb.com]phpBB[/url] code..
  632.         $message = preg_replace("#\[url=(http://)?(.*?)\](.*?)\[/url\]#si", "<!-- BBCode Start --><A HREF=\"http://\\2\" TARGET=\"_blank\">\\3</A><!-- BBCode End -->", $message);
  633.  
  634.         // [email]user@domain.tld[/email] code..
  635.         $message = preg_replace("#\[email\](.*?)\[/email\]#si", "<!-- BBCode Start --><A HREF=\"mailto:\\1\">\\1</A><!-- BBCode End -->", $message);
  636.  
  637.         // [img]image_url_here[/img] code..
  638.         $message = preg_replace("#\[img\](.*?)\[/img\]#si", "<!-- BBCode Start --><IMG SRC=\"\\1\"><!-- BBCode End -->", $message);
  639.  
  640.         // unordered list code..
  641.         $matchCount = preg_match_all("#\[list\](.*?)\[/list\]#si", $message, $matches);
  642.  
  643.         for ($i = 0; $i < $matchCount; $i++)
  644.         {
  645.                 $currMatchTextBefore = preg_quote($matches[1][$i]);
  646.                 $currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[1][$i]);
  647.  
  648.                 $message = preg_replace("#\[list\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode ulist Start --><UL>$currMatchTextAfter</UL><!-- BBCode ulist End -->", $message);
  649.         }
  650.  
  651.         // ordered list code..
  652.         $matchCount = preg_match_all("#\[list=([a1])\](.*?)\[/list\]#si", $message, $matches);
  653.  
  654.         for ($i = 0; $i < $matchCount; $i++)
  655.         {
  656.                 $currMatchTextBefore = preg_quote($matches[2][$i]);
  657.                 $currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[2][$i]);
  658.  
  659.                 $message = preg_replace("#\[list=([a1])\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode olist Start --><OL TYPE=\\1>$currMatchTextAfter</OL><!-- BBCode olist End -->", $message);
  660.         }
  661.  
  662.         return($message);
  663. }
  664.  
  665. function bbdecode($message) {
  666.  
  667.                 // Undo [code]
  668.                 $code_start_html = "<!-- 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>";
  669.                 $code_end_html = "</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->";
  670.                 $message = str_replace($code_start_html, "[code]", $message);
  671.                 $message = str_replace($code_end_html, "[/code]", $message);
  672.  
  673.                 // Undo [quote]
  674.                 $quote_start_html = "<!-- 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>";
  675.                 $quote_end_html = "</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->";
  676.                 $message = str_replace($quote_start_html, "[quote]", $message);
  677.                 $message = str_replace($quote_end_html, "[/quote]", $message);
  678.  
  679.                 // Undo [b] and [i]
  680.                 $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message);
  681.                 $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message);
  682.  
  683.                 // Undo [url] (long form)
  684.                 $message = preg_replace("#<!-- BBCode u2 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u2 End -->#s", "[url=\\1\\2]\\3[/url]", $message);
  685.  
  686.                 // Undo [url] (short form)
  687.                 $message = preg_replace("#<!-- BBCode u1 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u1 End -->#s", "[url]\\3[/url]", $message);
  688.  
  689.                 // Undo [email]
  690.                 $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message);
  691.  
  692.                 // Undo [img]
  693.                 $message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\" BORDER=\"0\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message);
  694.  
  695.                 // Undo lists (unordered/ordered)
  696.  
  697.                 // <li> tags:
  698.                 $message = str_replace("<!-- BBCode --><LI>", "[*]", $message);
  699.  
  700.                 // [list] tags:
  701.                 $message = str_replace("<!-- BBCode ulist Start --><UL>", "[list]", $message);
  702.  
  703.                 // [list=x] tags:
  704.                 $message = preg_replace("#<!-- BBCode olist Start --><OL TYPE=([A1])>#si", "[list=\\1]", $message);
  705.  
  706.                 // [/list] tags:
  707.                 $message = str_replace("</UL><!-- BBCode ulist End -->", "[/list]", $message);
  708.                 $message = str_replace("</OL><!-- BBCode olist End -->", "[/list]", $message);
  709.  
  710.                 return($message);
  711. }
  712. /**
  713.  * James Atkinson - Feb 5, 2001
  714.  * This function does exactly what the PHP4 function array_push() does
  715.  * however, to keep phpBB compatable with PHP 3 we had to come up with out own
  716.  * method of doing it.
  717.  */
  718. function bbcode_array_push(&$stack, $value) {
  719.    $stack[] = $value;
  720.    return(sizeof($stack));
  721. }
  722.  
  723. /**
  724.  * James Atkinson - Feb 5, 2001
  725.  * This function does exactly what the PHP4 function array_pop() does
  726.  * however, to keep phpBB compatable with PHP 3 we had to come up with out own
  727.  * method of doing it.
  728.  */
  729. function bbcode_array_pop(&$stack) {
  730.    $arrSize = count($stack);
  731.    $x = 1;
  732.    while(list($key, $val) = each($stack)) {
  733.       if($x < count($stack)) {
  734.          $tmpArr[] = $val;
  735.       }
  736.       else {
  737.          $return_val = $val;
  738.       }
  739.       $x++;
  740.    }
  741.    $stack = $tmpArr;
  742.    return($return_val);
  743. }
  744.  
  745. /**
  746.  * Nathan Codding - Jan. 12, 2001.
  747.  * Performs [quote][/quote] bbencoding on the given string, and returns the results.
  748.  * Any unmatched "[quote]" or "[/quote]" token will just be left alone.
  749.  * This works fine with both having more than one quote in a message, and with nested quotes.
  750.  * Since that is not a regular language, this is actually a PDA and uses a stack. Great fun.
  751.  *
  752.  * Note: This function assumes the first character of $message is a space, which is added by
  753.  * bbencode().
  754.  */
  755. function bbencode_quote($message)
  756. {
  757.         // First things first: If there aren't any "[quote]" strings in the message, we don't
  758.         // need to process it at all.
  759.  
  760.         if (!strpos(strtolower($message), "[quote]"))
  761.         {
  762.                 return $message;
  763.         }
  764.  
  765.         $stack = Array();
  766.         $curr_pos = 1;
  767.         while ($curr_pos && ($curr_pos < strlen($message)))
  768.         {
  769.                 $curr_pos = strpos($message, "[", $curr_pos);
  770.  
  771.                 // If not found, $curr_pos will be 0, and the loop will end.
  772.                 if ($curr_pos)
  773.                 {
  774.                         // We found a [. It starts at $curr_pos.
  775.                         // check if it's a starting or ending quote tag.
  776.                         $possible_start = substr($message, $curr_pos, 7);
  777.                         $possible_end = substr($message, $curr_pos, 8);
  778.                         if (strcasecmp("[quote]", $possible_start) == 0)
  779.                         {
  780.                                 // We have a starting quote tag.
  781.                                 // Push its position on to the stack, and then keep going to the right.
  782.                                 bbcode_array_push($stack, $curr_pos);
  783.                                 ++$curr_pos;
  784.                         }
  785.                         else if (strcasecmp("[/quote]", $possible_end) == 0)
  786.                         {
  787.                                 // We have an ending quote tag.
  788.                                 // Check if we've already found a matching starting tag.
  789.                                 if (sizeof($stack) > 0)
  790.                                 {
  791.                                         // There exists a starting tag.
  792.                                         // We need to do 2 replacements now.
  793.                                         $start_index = bbcode_array_pop($stack);
  794.  
  795.                                         // everything before the [quote] tag.
  796.                                         $before_start_tag = substr($message, 0, $start_index);
  797.  
  798.                                         // everything after the [quote] tag, but before the [/quote] tag.
  799.                                         $between_tags = substr($message, $start_index + 7, $curr_pos - $start_index - 7);
  800.  
  801.                                         // everything after the [/quote] tag.
  802.                                         $after_end_tag = substr($message, $curr_pos + 8);
  803.  
  804.                                         $message = $before_start_tag . "<!-- 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>";
  805.                                         $message .= $between_tags . "</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->";
  806.                                         $message .= $after_end_tag;
  807.  
  808.                                         // Now.. we've screwed up the indices by changing the length of the string.
  809.                                         // So, if there's anything in the stack, we want to resume searching just after it.
  810.                                         // otherwise, we go back to the start.
  811.                                         if (sizeof($stack) > 0)
  812.                                         {
  813.                                                 $curr_pos = bbcode_array_pop($stack);
  814.                                                 bbcode_array_push($stack, $curr_pos);
  815.                                                 ++$curr_pos;
  816.                                         }
  817.                                         else
  818.                                         {
  819.                                                 $curr_pos = 1;
  820.                                         }
  821.                                 }
  822.                                 else
  823.                                 {
  824.                                         // No matching start tag found. Increment pos, keep going.
  825.                                         ++$curr_pos;
  826.                                 }
  827.                         }
  828.                         else
  829.                         {
  830.                                 // No starting tag or ending tag.. Increment pos, keep looping.,
  831.                                 ++$curr_pos;
  832.                         }
  833.                 }
  834.         } // while
  835.  
  836.         return $message;
  837.  
  838. } // bbencode_quote()
  839.  
  840.  
  841. /**
  842.  * Nathan Codding - Jan. 12, 2001.
  843.  * Performs [code][/code] bbencoding on the given string, and returns the results.
  844.  * Any unmatched "[code]" or "[/code]" token will just be left alone.
  845.  * This works fine with both having more than one code block in a message, and with nested code blocks.
  846.  * Since that is not a regular language, this is actually a PDA and uses a stack. Great fun.
  847.  *
  848.  * Note: This function assumes the first character of $message is a space, which is added by
  849.  * bbencode().
  850.  */
  851. function bbencode_code($message, $is_html_disabled)
  852. {
  853.         // First things first: If there aren't any "[code]" strings in the message, we don't
  854.         // need to process it at all.
  855.         if (!strpos(strtolower($message), "[code]"))
  856.         {
  857.                 return $message;
  858.         }
  859.  
  860.         // Second things second: we have to watch out for stuff like [1code] or [/code1] in the
  861.         // input.. So escape them to [#1code] or [/code#1] for now:
  862.         $message = preg_replace("/\[([0-9]+?)code\]/si", "[#\\1code]", $message);
  863.         $message = preg_replace("/\[\/code([0-9]+?)\]/si", "[/code#\\1]", $message);
  864.  
  865.         $stack = Array();
  866.         $curr_pos = 1;
  867.         $max_nesting_depth = 0;
  868.         while ($curr_pos && ($curr_pos < strlen($message)))
  869.         {
  870.                 $curr_pos = strpos($message, "[", $curr_pos);
  871.  
  872.                 // If not found, $curr_pos will be 0, and the loop will end.
  873.                 if ($curr_pos)
  874.                 {
  875.                         // We found a [. It starts at $curr_pos.
  876.                         // check if it's a starting or ending code tag.
  877.                         $possible_start = substr($message, $curr_pos, 6);
  878.                         $possible_end = substr($message, $curr_pos, 7);
  879.                         if (strcasecmp("[code]", $possible_start) == 0)
  880.                         {
  881.                                 // We have a starting code tag.
  882.                                 // Push its position on to the stack, and then keep going to the right.
  883.                                 bbcode_array_push($stack, $curr_pos);
  884.                                 ++$curr_pos;
  885.                         }
  886.                         else if (strcasecmp("[/code]", $possible_end) == 0)
  887.                         {
  888.                                 // We have an ending code tag.
  889.                                 // Check if we've already found a matching starting tag.
  890.                                 if (sizeof($stack) > 0)
  891.                                 {
  892.                                         // There exists a starting tag.
  893.                                         $curr_nesting_depth = sizeof($stack);
  894.                                         $max_nesting_depth = ($curr_nesting_depth > $max_nesting_depth) ? $curr_nesting_depth : $max_nesting_depth;
  895.  
  896.                                         // We need to do 2 replacements now.
  897.                                         $start_index = bbcode_array_pop($stack);
  898.  
  899.                                         // everything before the [code] tag.
  900.                                         $before_start_tag = substr($message, 0, $start_index);
  901.  
  902.                                         // everything after the [code] tag, but before the [/code] tag.
  903.                                         $between_tags = substr($message, $start_index + 6, $curr_pos - $start_index - 6);
  904.  
  905.                                         // everything after the [/code] tag.
  906.                                         $after_end_tag = substr($message, $curr_pos + 7);
  907.  
  908.                                         $message = $before_start_tag . "[" . $curr_nesting_depth . "code]";
  909.                                         $message .= $between_tags . "[/code" . $curr_nesting_depth . "]";
  910.                                         $message .= $after_end_tag;
  911.  
  912.                                         // Now.. we've screwed up the indices by changing the length of the string.
  913.                                         // So, if there's anything in the stack, we want to resume searching just after it.
  914.                                         // otherwise, we go back to the start.
  915.                                         if (sizeof($stack) > 0)
  916.                                         {
  917.                                                 $curr_pos = bbcode_array_pop($stack);
  918.                                                 bbcode_array_push($stack, $curr_pos);
  919.                                                 ++$curr_pos;
  920.                                         }
  921.                                         else
  922.                                         {
  923.                                                 $curr_pos = 1;
  924.                                         }
  925.                                 }
  926.                                 else
  927.                                 {
  928.                                         // No matching start tag found. Increment pos, keep going.
  929.                                         ++$curr_pos;
  930.                                 }
  931.                         }
  932.                         else
  933.                         {
  934.                                 // No starting tag or ending tag.. Increment pos, keep looping.,
  935.                                 ++$curr_pos;
  936.                         }
  937.                 }
  938.         } // while
  939.  
  940.         if ($max_nesting_depth > 0)
  941.         {
  942.                 for ($i = 1; $i <= $max_nesting_depth; ++$i)
  943.                 {
  944.                         $start_tag = escape_slashes(preg_quote("[" . $i . "code]"));
  945.                         $end_tag = escape_slashes(preg_quote("[/code" . $i . "]"));
  946.  
  947.                         $match_count = preg_match_all("/$start_tag(.*?)$end_tag/si", $message, $matches);
  948.  
  949.                         for ($j = 0; $j < $match_count; $j++)
  950.                         {
  951.                                 $before_replace = escape_slashes(preg_quote($matches[1][$j]));
  952.                                 $after_replace = $matches[1][$j];
  953.  
  954.                                 if (($i < 2) && !$is_html_disabled)
  955.                                 {
  956.                                         // don't escape special chars when we're nested, 'cause it was already done
  957.                                         // at the lower level..
  958.                                         // also, don't escape them if HTML is disabled in this post. it'll already be done
  959.                                         // by the posting routines.
  960.                                         $after_replace = htmlspecialchars($after_replace);
  961.                                 }
  962.  
  963.                                 $str_to_match = $start_tag . $before_replace . $end_tag;
  964.  
  965.                                 $message = preg_replace("/$str_to_match/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>$after_replace</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->", $message);
  966.                         }
  967.                 }
  968.         }
  969.  
  970.         // Undo our escaping from "second things second" above..
  971.         $message = preg_replace("/\[#([0-9]+?)code\]/si", "[\\1code]", $message);
  972.         $message = preg_replace("/\[\/code#([0-9]+?)\]/si", "[/code\\1]", $message);
  973.  
  974.         return $message;
  975.  
  976. } // bbencode_code()
  977.  
  978.  
  979. /**
  980.  * Nathan Codding - Jan. 12, 2001.
  981.  * Performs [list][/list] and [list=?][/list] bbencoding on the given string, and returns the results.
  982.  * Any unmatched "[list]" or "[/list]" token will just be left alone.
  983.  * This works fine with both having more than one list in a message, and with nested lists.
  984.  * Since that is not a regular language, this is actually a PDA and uses a stack. Great fun.
  985.  *
  986.  * Note: This function assumes the first character of $message is a space, which is added by
  987.  * bbencode().
  988.  */
  989. function bbencode_list($message)
  990. {
  991.         $start_length = Array();
  992.         $start_length[ordered] = 8;
  993.         $start_length[unordered] = 6;
  994.  
  995.         // First things first: If there aren't any "[list" strings in the message, we don't
  996.         // need to process it at all.
  997.  
  998.         if (!strpos(strtolower($message), "[list"))
  999.         {
  1000.                 return $message;
  1001.         }
  1002.  
  1003.         $stack = Array();
  1004.         $curr_pos = 1;
  1005.         while ($curr_pos && ($curr_pos < strlen($message)))
  1006.         {
  1007.                 $curr_pos = strpos($message, "[", $curr_pos);
  1008.  
  1009.                 // If not found, $curr_pos will be 0, and the loop will end.
  1010.                 if ($curr_pos)
  1011.                 {
  1012.                         // We found a [. It starts at $curr_pos.
  1013.                         // check if it's a starting or ending list tag.
  1014.                         $possible_ordered_start = substr($message, $curr_pos, $start_length[ordered]);
  1015.                         $possible_unordered_start = substr($message, $curr_pos, $start_length[unordered]);
  1016.                         $possible_end = substr($message, $curr_pos, 7);
  1017.                         if (strcasecmp("[list]", $possible_unordered_start) == 0)
  1018.                         {
  1019.                                 // We have a starting unordered list tag.
  1020.                                 // Push its position on to the stack, and then keep going to the right.
  1021.                                 bbcode_array_push($stack, array($curr_pos, ""));
  1022.                                 ++$curr_pos;
  1023.                         }
  1024.                         else if (preg_match("/\[list=([a1])\]/si", $possible_ordered_start, $matches))
  1025.                         {
  1026.                                 // We have a starting ordered list tag.
  1027.                                 // Push its position on to the stack, and the starting char onto the start
  1028.                                 // char stack, the keep going to the right.
  1029.                                 bbcode_array_push($stack, array($curr_pos, $matches[1]));
  1030.                                 ++$curr_pos;
  1031.                         }
  1032.                         else if (strcasecmp("[/list]", $possible_end) == 0)
  1033.                         {
  1034.                                 // We have an ending list tag.
  1035.                                 // Check if we've already found a matching starting tag.
  1036.                                 if (sizeof($stack) > 0)
  1037.                                 {
  1038.                                         // There exists a starting tag.
  1039.                                         // We need to do 2 replacements now.
  1040.                                         $start = bbcode_array_pop($stack);
  1041.                                         $start_index = $start[0];
  1042.                                         $start_char = $start[1];
  1043.                                         $is_ordered = ($start_char != "");
  1044.                                         $start_tag_length = ($is_ordered) ? $start_length[ordered] : $start_length[unordered];
  1045.  
  1046.                                         // everything before the [list] tag.
  1047.                                         $before_start_tag = substr($message, 0, $start_index);
  1048.  
  1049.                                         // everything after the [list] tag, but before the [/list] tag.
  1050.                                         $between_tags = substr($message, $start_index + $start_tag_length, $curr_pos - $start_index - $start_tag_length);
  1051.                                         // Need to replace [*] with <LI> inside the list.
  1052.                                         $between_tags = str_replace("[*]", "<!-- BBCode --><LI>", $between_tags);
  1053.  
  1054.                                         // everything after the [/list] tag.
  1055.                                         $after_end_tag = substr($message, $curr_pos + 7);
  1056.  
  1057.                                         if ($is_ordered)
  1058.                                         {
  1059.                                                 $message = $before_start_tag . "<!-- BBCode olist Start --><OL TYPE=" . $start_char . ">";
  1060.                                                 $message .= $between_tags . "</OL><!-- BBCode olist End -->";
  1061.                                         }
  1062.                                         else
  1063.                                         {
  1064.                                                 $message = $before_start_tag . "<!-- BBCode ulist Start --><UL>";
  1065.                                                 $message .= $between_tags . "</UL><!-- BBCode ulist End -->";
  1066.                                         }
  1067.  
  1068.                                         $message .= $after_end_tag;
  1069.  
  1070.                                         // Now.. we've screwed up the indices by changing the length of the string.
  1071.                                         // So, if there's anything in the stack, we want to resume searching just after it.
  1072.                                         // otherwise, we go back to the start.
  1073.                                         if (sizeof($stack) > 0)
  1074.                                         {
  1075.                                                 $a = bbcode_array_pop($stack);
  1076.                                                 $curr_pos = $a[0];
  1077.                                                 bbcode_array_push($stack, $a);
  1078.                                                 ++$curr_pos;
  1079.                                         }
  1080.                                         else
  1081.                                         {
  1082.                                                 $curr_pos = 1;
  1083.                                         }
  1084.                                 }
  1085.                                 else
  1086.                                 {
  1087.                                         // No matching start tag found. Increment pos, keep going.
  1088.                                         ++$curr_pos;
  1089.                                 }
  1090.                         }
  1091.                         else
  1092.                         {
  1093.                                 // No starting tag or ending tag.. Increment pos, keep looping.,
  1094.                                 ++$curr_pos;
  1095.                         }
  1096.                 }
  1097.         } // while
  1098.  
  1099.         return $message;
  1100.  
  1101. } // bbencode_list()
  1102.  
  1103.  
  1104.  
  1105. /**
  1106.  * Nathan Codding - Oct. 30, 2000
  1107.  *
  1108.  * Escapes the "/" character with "\/". This is useful when you need
  1109.  * to stick a runtime string into a PREG regexp that is being delimited
  1110.  * with slashes.
  1111.  */
  1112. function escape_slashes($input)
  1113. {
  1114.         $output = str_replace('/', '\/', $input);
  1115.         return $output;
  1116. }
  1117.  
  1118. /*
  1119.  * Returns the name of the forum based on ID number
  1120.  */
  1121. function get_forum_name($forum_id, $db) {
  1122.         $sql = "SELECT forum_name FROM forums WHERE forum_id = '$forum_id'";
  1123.         if(!$r = mysql_query($sql, $db))
  1124.                 return("ERROR");
  1125.         if(!$m = mysql_fetch_array($r))
  1126.                 return("None");
  1127.         return($m[forum_name]);
  1128. }
  1129.  
  1130.  
  1131. /**
  1132.  * Rewritten by Nathan Codding - Feb 6, 2001.
  1133.  * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
  1134.  *         to that URL
  1135.  * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
  1136.  *         to http://www.xxxx.yyyy[/zzzz]
  1137.  * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
  1138.  *                to that email address
  1139.  * - Only matches these 2 patterns either after a space, or at the beginning of a line
  1140.  *
  1141.  * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
  1142.  * have it require something like xxxx@yyyy.zzzz or such. We'll see.
  1143.  */
  1144.  
  1145. function make_clickable($text) {
  1146.  
  1147.         // pad it with a space so we can match things at the start of the 1st line.
  1148.         $ret = " " . $text;
  1149.  
  1150.         // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
  1151.         // xxxx can only be alpha characters.
  1152.         // yyyy is anything up to the first space, newline, or comma.
  1153.         $ret = preg_replace("#([\n ])([a-z]+?)://([^, \n\r]+)#i", "\\1<!-- BBCode auto-link start --><a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a><!-- BBCode auto-link end -->", $ret);
  1154.  
  1155.         // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
  1156.         // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
  1157.         // yyyy contains either alphanum, "-", or "."
  1158.         // zzzz is optional.. will contain everything up to the first space, newline, or comma.
  1159.         // This is slightly restrictive - it's not going to match stuff like "forums.foo.com"
  1160.         // This is to keep it from getting annoying and matching stuff that's not meant to be a link.
  1161.         $ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \n\r]*)?)#i", "\\1<!-- BBCode auto-link start --><a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a><!-- BBCode auto-link end -->", $ret);
  1162.  
  1163.         // matches an email@domain type address at the start of a line, or after a space.
  1164.         // Note: before the @ sign, the only valid characters are the alphanums and "-", "_", or ".".
  1165.         // After the @ sign, we accept anything up to the first space, linebreak, or comma.
  1166.         $ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([^, \n\r]+)#i", "\\1<!-- BBcode auto-mailto start --><a href=\"mailto:\\2@\\3\">\\2@\\3</a><!-- BBCode auto-mailto end -->", $ret);
  1167.  
  1168.         // Remove our padding..
  1169.         $ret = substr($ret, 1);
  1170.  
  1171.         return($ret);
  1172. }
  1173.  
  1174.  
  1175. /**
  1176.  * Nathan Codding - Feb 6, 2001
  1177.  * Reverses the effects of make_clickable(), for use in editpost.
  1178.  * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs.
  1179.  *
  1180.  */
  1181.  
  1182. function undo_make_clickable($text) {
  1183.  
  1184.         $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text);
  1185.         $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text);
  1186.  
  1187.         return $text;
  1188.  
  1189. }
  1190.  
  1191.  
  1192.  
  1193. /**
  1194.  * Nathan Codding - August 24, 2000.
  1195.  * Takes a string, and does the reverse of the PHP standard function
  1196.  * htmlspecialchars().
  1197.  */
  1198. function undo_htmlspecialchars($input) {
  1199.         $input = preg_replace("/>/i", ">", $input);
  1200.         $input = preg_replace("/</i", "<", $input);
  1201.         $input = preg_replace("/"/i", "\"", $input);
  1202.         $input = preg_replace("/&/i", "&", $input);
  1203.  
  1204.         return $input;
  1205. }
  1206. /*
  1207.  * Make sure a username isn't on the disallow list
  1208.  */
  1209. function validate_username($username, $db) {
  1210.         $sql = "SELECT disallow_username FROM disallow WHERE disallow_username = '" . addslashes($username) . "'";
  1211.         if(!$r = mysql_query($sql, $db))
  1212.                 return(0);
  1213.         if($m = mysql_fetch_array($r)) {
  1214.                 if($m[disallow_username] == $username)
  1215.                         return(1);
  1216.                 else
  1217.                         return(0);
  1218.         }
  1219.         return(0);
  1220. }
  1221. /*
  1222.  * Check if this is the first post in a topic. Used in editpost.php
  1223.  */
  1224.  #OK
  1225. function is_first_post($topic_id, $post_id, $db) {
  1226.    $sql = "SELECT post_id FROM posts WHERE topic_id = '$topic_id' ORDER BY post_id LIMIT 1";
  1227.    if(!$r = mysql_query($sql))
  1228.      return(0);
  1229.    if(!$m = mysql_fetch_array($r))
  1230.      return(0);
  1231.    if($m[post_id] == $post_id)
  1232.      return(1);
  1233.    else
  1234.      return(0);
  1235. }
  1236.  
  1237. /*
  1238.  * Replaces banned words in a string with their replacements
  1239.  */
  1240.  #OK
  1241. function censor_string($string, $db) {
  1242. global $prefix;
  1243.    $sql = "SELECT word, replacement FROM ".$prefix."_words";
  1244.    if(!$r = mysql_query($sql))
  1245.       die("Error, could not contact the database! Please check your database settings in config.php");
  1246.    while($w = mysql_fetch_array($r)) {
  1247.       $word = quotemeta(stripslashes($w[word]));
  1248.       $replacement = stripslashes($w[replacement]);
  1249.       $string = eregi_replace(" $word", " $replacement", $string);
  1250.       $string = eregi_replace("^$word", "$replacement", $string);
  1251.       $string = eregi_replace("<BR>$word", "<BR>$replacement", $string);
  1252.    }
  1253.    return($string);
  1254. }
  1255.  
  1256. #OK
  1257. function is_banned($ipuser, $type, $db) {
  1258. global $prefix;
  1259.    // Remove old bans
  1260.    $sql = "DELETE FROM ".$prefix."_banlist WHERE (ban_end < ". mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")).") AND (ban_end > 0)";
  1261.    @mysql_query($sql);
  1262.  
  1263.    switch($type) {
  1264.     case "ip":
  1265.       $sql = "SELECT ban_ip FROM ".$prefix."_banlist";
  1266.       if($r = mysql_query($sql)) {
  1267.          while($iprow = mysql_fetch_array($r)) {
  1268.             $ip = $iprow[ban_ip];
  1269.             if($ip[strlen($ip) - 1] == ".") {
  1270.                $db_ip = explode(".", $ip);
  1271.                $this_ip = explode(".", $ipuser);
  1272.  
  1273.                for($x = 0; $x < count($db_ip) - 1; $x++)
  1274.                  $my_ip .= $this_ip[$x] . ".";
  1275.  
  1276.                if($my_ip == $ip)
  1277.                  return(TRUE);
  1278.             }
  1279.             else {
  1280.                if($ipuser == $ip)
  1281.                  return(TRUE);
  1282.             }
  1283.          }
  1284.       }
  1285.       else
  1286.         return(FALSE);
  1287.       break;
  1288.     case "username":
  1289.       $sql = "SELECT ban_userid FROM ".$prefix."_banlist WHERE ban_userid = '$ipuser'";
  1290.       if($r = mysql_query($sql)) {
  1291.          if(mysql_num_rows($r) > 0)
  1292.            return(TRUE);
  1293.       }
  1294.       break;
  1295.    }
  1296.  
  1297.    return(FALSE);
  1298. }
  1299.  
  1300. /**
  1301.  * Checks if the given userid is allowed to log into the given (private) forumid.
  1302.  * If the "is_posting" flag is true, checks if the user is allowed to post to that forum.
  1303.  */
  1304.  #OK
  1305. function check_priv_forum_auth($userid, $forumid, $is_posting, $db) {
  1306. global $prefix;
  1307.         $sql = "SELECT count(*) AS user_count FROM ".$prefix."_forum_access WHERE (user_id = $userid) AND (forum_id = $forumid) ";
  1308.  
  1309.         if ($is_posting)
  1310.         {
  1311.                 $sql .= "AND (can_post = 1)";
  1312.         }
  1313.  
  1314.         if (!$result = mysql_query($sql))
  1315.         {
  1316.                 // no good..
  1317.                 return FALSE;
  1318.         }
  1319.  
  1320.         if(!$row = mysql_fetch_array($result))
  1321.         {
  1322.                 return FALSE;
  1323.         }
  1324.  
  1325.           if ($row[user_count] <= 0)
  1326.           {
  1327.                   return FALSE;
  1328.           }
  1329.  
  1330.           return TRUE;
  1331.  
  1332. }
  1333.  
  1334. # used OK
  1335. /**
  1336.  * Displays an error message and exits the script. Used in the posting files.
  1337.  */
  1338. function error_die($msg){
  1339.         global $tablewidth, $table_bgcolor, $color1;
  1340.         global $db, $userdata, $user_logged_in;
  1341.         global $FontFace, $FontSize3, $textcolor, $phpbbversion;
  1342.         global $starttime;
  1343.         print("<br>
  1344.                 <TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\" ALIGN=\"CENTER\" VALIGN=\"TOP\" WIDTH=\"$tablewidth\">
  1345.                 <TR><TD BGCOLOR=\"$table_bgcolor\">
  1346.                         <TABLE BORDER=\"0\" CALLPADDING=\"1\" CELLSPACEING=\"1\" WIDTH=\"100%\">
  1347.                         <TR BGCOLOR=\"$color1\" ALIGN=\"LEFT\">
  1348.                                 <TD>
  1349.                                         <p><font face=\"Verdana\" size=\"2\"><ul>$msg</ul></font></P>
  1350.                                 </TD>
  1351.                         </TR>
  1352.                         </TABLE>
  1353.                 </TD></TR>
  1354.                  </TABLE>
  1355.          <br>");
  1356. #         include('page_tail.php');
  1357.          exit;
  1358. }
  1359. # OK
  1360. function make_jumpbox(){
  1361. global $db;
  1362. global $FontFace, $FontSize2, $textcolor, $prefix;
  1363.  
  1364.  
  1365.         ?>
  1366.         <FORM ACTION="modules.php?name=Forum&file=viewforum" METHOD="POST">
  1367.         <SELECT NAME="forum"><OPTION VALUE="-1"><?php echo ""._BBSELECTFORUM."";?></OPTION>
  1368.         <?php
  1369.           $sql = "SELECT cat_id, cat_title FROM ".$prefix."_catagories ORDER BY cat_order";
  1370.         if($result = mysql_query($sql)) {
  1371.            $myrow = mysql_fetch_array($result);
  1372.            do {
  1373.               echo "<OPTION VALUE=\"-1\"> </OPTION>\n";
  1374.               echo "<OPTION VALUE=\"-1\">$myrow[cat_title]</OPTION>\n";
  1375.               echo "<OPTION VALUE=\"-1\">----------------</OPTION>\n";
  1376.               $sub_sql = "SELECT forum_id, forum_name FROM ".$prefix."_forums WHERE cat_id =
  1377.         '$myrow[cat_id]' ORDER BY forum_id";
  1378.               if($res = mysql_query($sub_sql)) {
  1379.             if($row = mysql_fetch_array($res)) {
  1380.                do {
  1381.                   $name = stripslashes($row[forum_name]);
  1382.                   echo "<OPTION VALUE=\"$row[forum_id]\">$name</OPTION>\n";
  1383.                } while($row = mysql_fetch_array($res));
  1384.             }
  1385.             else {
  1386.                echo "<OPTION VALUE=\"0\">"._BBNOFORUM."</OPTION>\n";
  1387.             }
  1388.               }
  1389.               else {
  1390.             echo "<OPTION VALUE=\"0\">Error Connecting to DB</OPTION>\n";
  1391.               }
  1392.            } while($myrow = mysql_fetch_array($result));
  1393.         }
  1394.         else {
  1395.            echo "<OPTION VALUE=\"-1\">ERROR</OPTION>\n";
  1396.         }
  1397.         echo "</SELECT>\n<INPUT TYPE=\"SUBMIT\" VALUE=\""._BBGO."\">\n</FORM>";
  1398. }
  1399.  
  1400. function language_select($default, $name="language", $dirname="language/"){
  1401.         $dir = opendir($dirname);
  1402.         $lang_select = "<SELECT NAME=\"$name\">\n";
  1403.         while ($file = readdir($dir)) {
  1404.                 if (ereg("^lang_", $file)) {
  1405.                         $file = str_replace("lang_", "", $file);
  1406.                         $file = str_replace(".php", "", $file);
  1407.                         $file == $default ? $selected = " SELECTED" : $selected = "";
  1408.                         $lang_select .= "  <OPTION$selected>$file\n";
  1409.                 }
  1410.         }
  1411.         $lang_select .= "</SELECT>\n";
  1412.         closedir($dir);
  1413.         return $lang_select;
  1414.  
  1415. }
  1416.  
  1417. function get_translated_file($file){
  1418.         global $default_lang;
  1419.  
  1420.         // Try adding -default_lang to the filename. i.e.:
  1421.         // reply.jpg  becomes something like  reply-nederlands.jpg
  1422.         $trans_file = preg_replace("/(.*)(\..*?)/", "\\1-$default_lang\\2", $file);
  1423.         if(is_file($trans_file)){
  1424.                 return $trans_file;
  1425.         } else {
  1426.                 return $file;
  1427.         }
  1428. }
  1429.  
  1430. #function get_syslang_string($sys_lang, $string) {
  1431. #        global $language;
  1432. #        include("modules/Forum/language/lang-$language.php");
  1433. #        $ret_string = $$string;
  1434. #        return($ret_string);
  1435. #}
  1436.  
  1437.  
  1438. /**   /modules/Forum/language
  1439.  * Translates any sequence of whitespace (\t, \r, \n, or space) in the given
  1440.  * string into a single space character.
  1441.  * Returns the result.
  1442.  */
  1443. function normalize_whitespace($str)
  1444. {
  1445.         $output = "";
  1446.  
  1447.         $tok = preg_split("/[ \t\r\n]+/", $str);
  1448.         $tok_count = sizeof($tok);
  1449.         for ($i = 0; $i < ($tok_count - 1); $i++)
  1450.         {
  1451.                 $output .= $tok[$i] . " ";
  1452.         }
  1453.  
  1454.         $output .= $tok[$tok_count - 1];
  1455.  
  1456.         return $output;
  1457. }
  1458.  
  1459. function sync($db, $id, $type) {
  1460. global $prefix;
  1461.    switch($type) {
  1462.            case 'forum':
  1463.                    $sql = "SELECT max(post_id) AS last_post FROM ".$prefix."_posts WHERE forum_id = $id";
  1464.                    if(!$result = mysql_query($sql))
  1465.                    {
  1466.                            die("Could not get post ID");
  1467.                    }
  1468.                    if($row = mysql_fetch_array($result))
  1469.                    {
  1470.                            $last_post = $row["last_post"];
  1471.                    }
  1472.  
  1473.                    $sql = "SELECT count(post_id) AS total FROM ".$prefix."_posts WHERE forum_id = $id";
  1474.                    if(!$result = mysql_query($sql))
  1475.                    {
  1476.                            die("Could not get post count");
  1477.                    }
  1478.                    if($row = mysql_fetch_array($result))
  1479.                    {
  1480.                            $total_posts = $row["total"];
  1481.                    }
  1482.  
  1483.                    $sql = "SELECT count(topic_id) AS total FROM ".$prefix."_bbtopics WHERE forum_id = $id";
  1484.                    if(!$result = mysql_query($sql))
  1485.                    {
  1486.                            die("Could not get topic count");
  1487.                    }
  1488.                    if($row = mysql_fetch_array($result))
  1489.                    {
  1490.                            $total_topics = $row["total"];
  1491.                    }
  1492.  
  1493.                    $sql = "UPDATE ".$prefix."_forums SET forum_last_post_id = '$last_post', forum_posts = $total_posts, forum_topics = $total_topics WHERE forum_id = $id";
  1494.                    if(!$result = mysql_query($sql))
  1495.                    {
  1496.                            die("Could not update forum $id");
  1497.                    }
  1498.            break;
  1499.  
  1500.            case 'topic':
  1501.                    $sql = "SELECT max(post_id) AS last_post FROM ".$prefix."_posts WHERE topic_id = $id";
  1502.                    if(!$result = mysql_query($sql))
  1503.                    {
  1504.                            die("Could not get post ID");
  1505.                    }
  1506.                    if($row = mysql_fetch_array($result))
  1507.                    {
  1508.                            $last_post = $row["last_post"];
  1509.                    }
  1510.  
  1511.                    $sql = "SELECT count(post_id) AS total FROM ".$prefix."_posts WHERE topic_id = $id";
  1512.                    if(!$result = mysql_query($sql))
  1513.                    {
  1514.                            die("Could not get post count");
  1515.                    }
  1516.                    if($row = mysql_fetch_array($result))
  1517.                    {
  1518.                            $total_posts = $row["total"];
  1519.                    }
  1520.                    $total_posts -= 1;
  1521.                    $sql = "UPDATE ".$prefix."_bbtopics SET topic_replies = $total_posts, topic_last_post_id = $last_post WHERE topic_id = $id";
  1522.                    if(!$result = mysql_query($sql))
  1523.                    {
  1524.                            die("Could not update topic $id");
  1525.                    }
  1526.            break;
  1527.  
  1528.            case 'all forums':
  1529.                    $sql = "SELECT forum_id FROM ".$prefix."_forums";
  1530.                    if(!$result = mysql_query($sql))
  1531.                    {
  1532.                            die("Could not get forum IDs");
  1533.                    }
  1534.                    while($row = mysql_fetch_array($result))
  1535.                    {
  1536.                            $id = $row["forum_id"];
  1537.                            sync($db, $id, "forum");
  1538.                    }
  1539.            break;
  1540.            case 'all topics':
  1541.                    $sql = "SELECT topic_id FROM ".$prefix."_bbtopics";
  1542.                    if(!$result = mysql_query($sql))
  1543.                    {
  1544.                            die("Could not get topic ID's");
  1545.                    }
  1546.                    while($row = mysql_fetch_array($result))
  1547.                    {
  1548.                            $id = $row["topic_id"];
  1549.                            sync($db, $id, "topic");
  1550.                    }
  1551.            break;
  1552.    }
  1553.    return(TRUE);
  1554. }
  1555.  
  1556. function login_form(){
  1557.         global $TableWidth, $table_bgcolor, $color1, $color2, $textcolor;
  1558.         global $FontFace, $FontSize2;
  1559.         global $userdata, $PHP_SELF;
  1560.         global $l_userpass, $l_username, $l_password, $l_passwdlost, $l_submit;
  1561.         global $mode, $msgid;
  1562.  
  1563. ?>
  1564. <FORM ACTION="<?php echo $PHP_SELF?>" METHOD="POST">
  1565. <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="CENTER" VALIGN="TOP">
  1566. <TR><TD BGCOLOR="<?php echo $table_bgcolor?>">
  1567. <TABLE BORDER="0" CELLPADDING="10" CELLSPACING="1" WIDTH="100%">
  1568.         <TR BGCOLOR="<?php echo $color1?>" ALIGN="CENTER">
  1569.                   <TD COLSPAN="2">
  1570.                         <FONT FACE="<?php echo $FontFace?>" SIZE="<?php echo $FontSize2?>" COLOR="<?php echo $textcolor?>">
  1571.                           <b><?php echo $l_userpass?></b>
  1572.                         </FONT>
  1573.                         <br>
  1574.                 </TD>
  1575.         </TR><TR BGCOLOR="<?php echo $color2?>">
  1576.                 <TD>
  1577.                         <FONT FACE="<?php echo $FontFace?>" SIZE="<?php echo $FontSize2?>" COLOR="<?php echo $textcolor?>">
  1578.                         <b><?php echo $l_username?>:  </b></font>
  1579.                         </FONT>
  1580.                 </TD>
  1581.                 <TD>
  1582.                         <INPUT TYPE="TEXT" NAME="user" SIZE="25" MAXLENGTH="40" VALUE="<?php echo $userdata[username]?>">
  1583.                 </TD>
  1584.         </TR><TR BGCOLOR="<?php echo $color2?>">
  1585.                 <TD>
  1586.                         <FONT FACE="<?php echo $FontFace?>" SIZE="<?php echo $FontSize2?>" COLOR="<?php echo $textcolor?>">
  1587.                         <b><?php echo $l_password?>: </b>
  1588.                         </FONT>
  1589.                 </TD><TD>
  1590.                         <INPUT TYPE="PASSWORD" NAME="passwd" SIZE="25" MAXLENGTH="25">
  1591.                 </TD>
  1592.         </TR><TR BGCOLOR="<?php echo $color2?>">
  1593.                 <TD COLSPAN="2" ALIGN="CENTER">
  1594.                         <FONT FACE="<?php echo $FontFace?>" SIZE="<?php echo $FontSize2?>" COLOR="<?php echo $textcolor?>">
  1595.                         <a href="sendpassword.php"><?php echo $l_passwdlost?></a><br><br>
  1596.                         </FONT>
  1597.                         <?PHP
  1598.                         if (isset($mode))
  1599.                         {
  1600.                         ?>
  1601.                                 <INPUT TYPE="HIDDEN" NAME="mode" VALUE="<?php echo $mode?>">
  1602.                         <?PHP
  1603.                         }
  1604.                         ?>
  1605.                         <?PHP
  1606.                         // Need to pass through the msgid for deleting private messages.
  1607.                         if (isset($msgid))
  1608.                         {
  1609.                         ?>
  1610.                                 <INPUT TYPE="HIDDEN" NAME="msgid" VALUE="<?php echo $msgid?>">
  1611.                         <?PHP
  1612.                         }
  1613.                         ?>
  1614.                         <INPUT TYPE="SUBMIT" NAME="submit" VALUE="<?php echo $l_submit?>">
  1615.                 </TD>
  1616.         </TR>
  1617. </TABLE>
  1618. </TD></TR>
  1619. </TABLE>
  1620. </FORM>
  1621.  
  1622.  
  1623. <?php
  1624. }
  1625.  
  1626. /**
  1627.  * Less agressive version of stripslashes. Only replaces \\ \' and \"
  1628.  * The PHP stripslashes() also removed single backslashes from the string.
  1629.  * Expects a string or array as an argument.
  1630.  * Returns the result.
  1631.  */
  1632. function own_stripslashes($string)
  1633. {
  1634.    $find = array(
  1635.             '/\\\\\'/',  // \\\'
  1636.             '/\\\\/',    // \\
  1637.                                 '/\\\'/',    // \'
  1638.             '/\\\"/');   // \"
  1639.    $replace = array(
  1640.             '\'',   // \
  1641.             '\\',   // \
  1642.             '\'',   // '
  1643.             '"');   // "
  1644.    return preg_replace($find, $replace, $string);
  1645. }
  1646.  
  1647. function PmsgAddOn() {
  1648.     global $imagesdir, $module_name;
  1649.     echo "<TR ALIGN=\"LEFT\" BGCOLOR=\"$BgColor1\">";
  1650.     echo "<TD COLSPAN=\"7\" NOWRAP><b><FONT FACE=\"$FontFace\" SIZE=\"$FontSize2\" COLOR=\"$FontColor1\">"._BBPMSG."</font></b></TD></TR>";
  1651.     echo "<TR ALIGN=\"LEFT\" BGCOLOR=\"$BgColor3\">";
  1652.     echo "<TD COLSPAN=\"7\" NOWRAP> <img src=\"$imagesdir/inbox.gif\" alt=\""._BBINBOX."\" title=\""._BBINBOX."\"> <FONT FACE=\"$FontFace\" SIZE=\"$FontSize2\" COLOR=\"$FontColor1\"><a href=\"modules.php?name=$module_name\">"._BBINBOX."</font></a><br>";
  1653.     if (!$user) {
  1654.     echo " <FONT FACE=\"$FontFace\" SIZE=\"$FontSize2\" COLOR=\"$FontColor1\">"._BBLOGIN."</font></TD></TR>";
  1655.     } else {
  1656.     $user = base64_decode($user);
  1657.     $userdata = explode(":", $user);
  1658.     $total_messages = mysql_num_rows(mysql_query("SELECT msg_id FROM $prefix"._priv_msgs." WHERE to_userid = '$userdata[0]'"));
  1659.     $new_messages = mysql_num_rows(mysql_query("SELECT msg_id FROM $prefix"._priv_msgs." WHERE to_userid = '$userdata[0]' AND read_msg='0'"));
  1660.     echo " <FONT FACE=\"$FontFace\" SIZE=\"$FontSize2\" COLOR=\"$FontColor1\">";
  1661.     if ($total_messages > 0) {
  1662.             if ($new_messages > 0) {
  1663.         echo "$new_messages "._BBNEWPMSG." | ";
  1664.             } else {
  1665.         echo ""._BBNONEWPMSG." | ";
  1666.         }
  1667.         echo "$total_messages "._BBTOTALPMSG."</font>";
  1668.     } else {
  1669.         echo ""._BBEMPTYPMSG.".</font>";
  1670.     }
  1671.     echo "</TD></TR></TD></TR>";
  1672.     }
  1673. }
  1674.  
  1675. function putitems() {
  1676.     global $prefix, $dbi;
  1677.     echo "<br>"._CLICKSMILEBUTTONS."<br><br>";
  1678.     if ($activesmiles = sql_query("SELECT code,smile_url,active FROM ".$prefix."_smiles", $dbi)) {
  1679.     while ($actsmiles = sql_fetch_array($activesmiles, $dbi)) {
  1680.             if ($actsmiles[active]==1) {
  1681.         echo " <A href=\"javascript: x()\" onClick=\"DoSmilie(' $actsmiles[code] ');\"><IMG src=\"images/forum/smilies/$actsmiles[smile_url]\" border=\"0\" alt=\"$actsmiles[code]\" title=\"$actsmiles[code]\"></A> ";
  1682.             }
  1683.         }
  1684.     }
  1685.     echo "<br><br>";
  1686.     echo ""._CLICKCODEBUTTONS."<br><br>";
  1687.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('url');\"><IMG src=\"images/forum/b_url.gif\" border=\"0\" alt=\"BBCode: Web Address\" title=\"BBCode: Web Address\" hspace=\"3\"></a>";
  1688.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('email');\"><IMG src=\"images/forum/b_email.gif\" border=\"0\" alt=\"BBCode: Email Address\" title=\"BBCode: Email Address\" hspace=\"3\"></a>";
  1689.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('image');\"><IMG src=\"images/forum/b_image.gif\" border=\"0\" alt=\"BBCode: Load Image from Web\" title=\"BBCode: Load Image from Web\" hspace=\"3\"></a>";
  1690.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('bold');\"><IMG src=\"images/forum/b_bold.gif\" border=\"0\" alt=\"BBCode: Bold Text\" title=\"BBCode: Bold Text\" hspace=\"3\"></a>";
  1691.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('italic');\"><IMG src=\"images/forum/b_italic.gif\" border=\"0\" alt=\"BBCode: Italic Text\" title=\"BBCode: Italic Text\" hspace=\"3\"></a>";
  1692.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('quote');\"><IMG src=\"images/forum/b_quote.gif\" border=\"0\" alt=\"BBCode: Quote\" title=\"BBCode: Quote\" hspace=\"3\"></a>";
  1693.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('code');\"><IMG src=\"images/forum/b_code.gif\" border=\"0\" alt=\"BBCode: Code\" title=\"BBCode: Code\" hspace=\"3\"></a>";
  1694.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('listopen');\"><IMG src=\"images/forum/b_listopen.gif\" border=\"0\" alt=\"BBCode: Open List\" title=\"BBCode: Open List\" hspace=\"3\"></a>";
  1695.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('listitem');\"><IMG src=\"images/forum/b_listitem.gif\" border=\"0\" alt=\"BBCode: List Item\" title=\"BBCode: List Item\" hspace=\"3\"></a>";
  1696.     echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('listclose');\"><IMG src=\"images/forum/b_listclose.gif\" border=\"0\" alt=\"BBCode: Close List\" title=\"BBCode: Close List\" hspace=\"3\"></a>";
  1697.     echo "<br><br>";
  1698. }
  1699.  
  1700. function forumsearch() {
  1701.     global $textcolor1, $module_name;
  1702.     OpenTable();
  1703.     echo "<form action=\"modules.php?name=$module_name&file=search&sortby=p.post_time desc&page=1&searchboth=both&search_username=&addterms=any&forum=all\" method=\"post\">";
  1704.     echo "  <b>"._SEARCH."</b> <input type=\"text\" name=\"term\" size=\"15\">";
  1705.     echo "<input type=\"hidden\" name=\"submit\" value=\"submit\">";
  1706.     echo "<div align=\"left\"><font size=\"2\">  [ <a href=\"modules.php?name=$module_name&file=search\">Advanced Search</a> ]</font></div></form>";
  1707.     CloseTable();
  1708. }
  1709.  
  1710. function forumerror($e_code) {
  1711.     global $sitename;
  1712.     if ($e_code == "0001") {
  1713.         $error_msg = "Could not connect to the forums database.";
  1714.     }
  1715.     if ($e_code == "0002") {
  1716.         $error_msg = "The forum you selected does not exist. Please go back and try again.";
  1717.     }
  1718.     if ($e_code == "0003") {
  1719.         $error_msg = "Password Incorrect.";
  1720.     }
  1721.     if ($e_code == "0004") {
  1722.         $error_msg = "Could not query the topics database.";
  1723.     }
  1724.     if ($e_code == "0005") {
  1725.         $error_msg = "Error getting messages from the database.";
  1726.     }
  1727.     if ($e_code == "0006") {
  1728.         $error_msg = "Please enter the Nickname and the Password.";
  1729.     }
  1730.     if ($e_code == "0007") {
  1731.         $error_msg = "You are not the Moderator of this forum therefore you can't perform this function.";
  1732.     }
  1733.     if ($e_code == "0008") {
  1734.         $error_msg = "You did not enter the correct password, please go back and try again.";
  1735.     }
  1736.     if ($e_code == "0009") {
  1737.         $error_msg = "Could not remove posts from the database.";
  1738.     }
  1739.     if ($e_code == "0010") {
  1740.         $error_msg = "Could not move selected topic to selected forum. Please go back and try again.";
  1741.     }
  1742.     if ($e_code == "0011") {
  1743.         $error_msg = "Could not lock the selected topic. Please go back and try again.";
  1744.     }
  1745.     if ($e_code == "0012") {
  1746.         $error_msg = "Could not unlock the selected topic. Please go back and try again.";
  1747.     }
  1748.     if ($e_code == "0013") {
  1749.         $error_msg = "Could not query the database. <BR>Error: mysql_error()";
  1750.     }
  1751.     if ($e_code == "0014") {
  1752.         $error_msg = "No such user or post in the database.";
  1753.     }
  1754.     if ($e_code == "0015") {
  1755.         $error_msg = "Search Engine was unable to query the forums database.";
  1756.     }
  1757.     if ($e_code == "0016") {
  1758.         $error_msg = "That user does not exist. Please go back and search again.";
  1759.     }
  1760.     if ($e_code == "0017") {
  1761.         $error_msg = "You must type a subject to post. You can't post an empty subject. Go back and enter the subject";
  1762.     }
  1763.     if ($e_code == "0018") {
  1764.         $error_msg = "You must choose message icon to post. Go back and choose message icon.";
  1765.     }
  1766.     if ($e_code == "0019") {
  1767.         $error_msg = "You must type a message to post. You can't post an empty message. Go back and enter a message.";
  1768.     }
  1769.     if ($e_code == "0020") {
  1770.         $error_msg = "Could not enter data into the database. Please go back and try again.";
  1771.     }
  1772.     if ($e_code == "0021") {
  1773.         $error_msg = "Can't delete the selected message.";
  1774.     }
  1775.     if ($e_code == "0022") {
  1776.         $error_msg = "An error ocurred while querying the database.";
  1777.     }
  1778.     if ($e_code == "0023") {
  1779.         $error_msg = "Selected message was not found in the forum database.";
  1780.     }
  1781.     if ($e_code == "0024") {
  1782.         $error_msg = "You can't reply to that message. It wasn't sent to you.";
  1783.     }
  1784.     if ($e_code == "0025") {
  1785.         $error_msg = "You can't post a reply to this topic, it has been locked. Contact the administrator if you have any question.";
  1786.     }
  1787.     if ($e_code == "0026") {
  1788.         $error_msg = "The forum or topic you are attempting to post to does not exist. Please try again.";
  1789.     }
  1790.     if ($e_code == "0027") {
  1791.         $error_msg = "You must enter your username and password. Go back and do so.";
  1792.     }
  1793.     if ($e_code == "0028") {
  1794.         $error_msg = "You have entered an incorrect password. Go back and try again.";
  1795.     }
  1796.     if ($e_code == "0029") {
  1797.         $error_msg = "Couldn't update post count.";
  1798.     }
  1799.     if ($e_code == "0030") {
  1800.         $error_msg = "The forum you are attempting to post to does not exist. Please try again.";
  1801.     }
  1802.     if ($e_code == "0031") {
  1803.         return(0);
  1804.     }
  1805.     if ($e_code == "0032") {
  1806.         $error_msg = "Error doing DB query in check_user_pw()";
  1807.     }
  1808.     if ($e_code == "0033") {
  1809.         $error_msg = "Error doing DB query in get_pmsg_count";
  1810.     }
  1811.     if ($e_code == "0034") {
  1812.         $error_msg = "Error doing DB query in check_username()";
  1813.     }
  1814.     if ($e_code == "0035") {
  1815.         $error_msg = "You can't edit a post that's not yours.";
  1816.     }
  1817.     if ($e_code == "0036") {
  1818.         $error_msg = "You do not have permission to edit this post.";
  1819.     }
  1820.     if ($e_code == "0037") {
  1821.         $error_msg = "You did not supply the correct password or do not have permission to edit this post. Please go back and try again.";
  1822.     }
  1823.     if (!isset($header)) {
  1824.         include("header.php");
  1825.     }
  1826.     OpenTable2();
  1827.     echo "<center><font size=\"2\"><b>$sitename Error</b></font><br><br>";
  1828.     echo "Error Code: $e_code<br><br><br>";
  1829.     echo "<b>ERROR:</b> $error_msg<br><br><br>";
  1830.     echo "[ <a href=\"javascript:history.go(-1)\">Go Back</a> ]<br><br>";
  1831.     CloseTable2();
  1832.     die("");
  1833. }
  1834.  
  1835. ?>
  1836.