<?php

######################################################################
# Modulo Splatt Forum per PHP-NUKE ver.5.X
#-------------------------
# Versione: 3.1
#
# Copyright (c) 2002 by:
#
# Giorgio Ciranni (~Splatt~)
# (http://www.splatt.it)
# (webmaster@splatt.it)
# 
#
# Supporto tecnico disponibile sul Forum di www.splatt.it
######################################################################
# PHP-NUKE Add-On 2.0 :
# =====================
#
#              PHPBB Integration 1.0.BETA
#        Brought to you by PHPNuke Add-On Team
#
# Copyright (c) 2000 by Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)
#                       Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)
# http://www.phpnuke.web.id
#
#
######################################################################
# PHPBB
#
# Copyright (C) 2000 by James Atkinson (james@totalgeek.org)
# http://www.phpbb.com
#
#
######################################################################
# Splatt Forum is free software. You can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
# Splatt Forum is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   
# 02111-1307  USA
######################################################################

$module_name = "$name";

include("config.php");


##############################################
// Keledan Begin
Function convertiData($data)
{
$data = strtotime($data);
$data = strftime(_LOCALDATETIME, $data);
return($data);
}
// Keledan End

##############################################
function addForumScripts()
{
    echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
    echo "function x () {\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "function DoSmilie(addSmilie) {\n";
    echo "\n";
    echo "var addSmilie;\n";
    echo "var revisedMessage;\n";
    echo "var currentMessage = document.coolsus.message.value;\n";
    echo "revisedMessage = currentMessage+addSmilie;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "function DoPrompt(action) {\n";
    echo "var revisedMessage;\n";
    echo "var currentMessage = document.coolsus.message.value;\n";
    echo "\n";
    echo "if (action == \"url\") {\n";
    echo "var thisURL = prompt(\"Enter the URL for the link you want to add.\", \"http://\");\n";
    echo "var thisTitle = prompt(\"Enter the web site title\", \"Page Title\");\n";
    echo "var urlBBCode = \"[URL=\"+thisURL+\"]\"+thisTitle+\"[/URL]\";\n";
    echo "revisedMessage = currentMessage+urlBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"email\") {\n";
    echo "var thisEmail = prompt(\"Enter the email address you want to add.\", \"\");\n";
    echo "var emailBBCode = \"[EMAIL]\"+thisEmail+\"[/EMAIL]\";\n";
    echo "revisedMessage = currentMessage+emailBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"bold\") {\n";
    echo "var thisBold = prompt(\"Enter the text that you want to make bold.\", \"\");\n";
    echo "var boldBBCode = \"[B]\"+thisBold+\"[/B]\";\n";
    echo "revisedMessage = currentMessage+boldBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"italic\") {\n";
    echo "var thisItal = prompt(\"Enter the text that you want to make italic.\", \"\");\n";
    echo "var italBBCode = \"[I]\"+thisItal+\"[/I]\";\n";
    echo "revisedMessage = currentMessage+italBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"image\") {\n";
    echo "var thisImage = prompt(\"Enter the URL for the image you want to display.\", \"http://\");\n";
    echo "var imageBBCode = \"[IMG]\"+thisImage+\"[/IMG]\";\n";
    echo "revisedMessage = currentMessage+imageBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"quote\") {\n";
    echo "var quoteBBCode = \"[QUOTE]  [/QUOTE]\";\n";
    echo "revisedMessage = currentMessage+quoteBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"code\") {\n";
    echo "var codeBBCode = \"[CODE]  [/CODE]\";\n";
    echo "revisedMessage = currentMessage+codeBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listopen\") {\n";
    echo "var liststartBBCode = \"[LIST]\";\n";
    echo "revisedMessage = currentMessage+liststartBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listclose\") {\n";
    echo "var listendBBCode = \"[/LIST]\";\n";
    echo "revisedMessage = currentMessage+listendBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listitem\") {\n";
    echo "var thisItem = prompt(\"Enter the new list item. Note that each list group must be preceeded by a List Close and must be ended with List Close.\", \"\");\n";
    echo "var itemBBCode = \"[*]\"+thisItem;\n";
    echo "revisedMessage = currentMessage+itemBBCode;\n";
    echo "document.coolsus.message.value=revisedMessage;\n";
    echo "document.coolsus.message.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "}\n";
    echo "//--></SCRIPT>\n";
    echo "\n";
}

######################################################
function putitems() {
    echo ""._CLICONSMI."<br>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-) ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_smile.gif\" border=\"0\" alt=\":-)\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-( ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_frown.gif\" border=\"0\" alt=\":-(\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-D ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_biggrin.gif\" border=\"0\" alt=\":-D\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' ;-) ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_wink.gif\" border=\"0\" alt=\";-)\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-o ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_eek.gif\" border=\"0\" alt=\":-0\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' 8-) ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_cool.gif\" border=\"0\" alt=\"8-)\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-? ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_confused.gif\" border=\"0\" alt=\":-?\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-P ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_razz.gif\" border=\"0\" alt=\":-P\" hspace=\"5\"></A>";
    echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-| ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon_mad.gif\" border=\"0\" alt=\":-|\" hspace=\"5\"></A>";
echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-Z ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon27.gif\" border=\"0\" alt=\":-|\" hspace=\"5\"></A>";
echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-W ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon24.gif\" border=\"0\" alt=\":-|\" hspace=\"5\"></A>";
echo "<A href=\"javascript: x()\" onClick=\"DoSmilie(' :-Y ');\"><IMG width=\"19\" height=\"19\" src=\"images/forum/icons/icon21.gif\" border=\"0\" alt=\":-|\" hspace=\"5\"></A>";
    echo "<br><br>";
    echo ""._CLIONBOT."";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('url');\"><IMG src=\"images/forum/b_url.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Web Address\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('email');\"><IMG src=\"images/forum/b_email.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Email Address\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('image');\"><IMG src=\"images/forum/b_image.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Load Image from Web\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('bold');\"><IMG src=\"images/forum/b_bold.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Bold Text\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('italic');\"><IMG src=\"images/forum/b_italic.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Italic Text\"></A><br>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('quote');\"><IMG src=\"images/forum/b_quote.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Quote\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('code');\"><IMG src=\"images/forum/b_code.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Code\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('listopen');\"><IMG src=\"images/forum/b_listopen.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Open List\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('listitem');\"><IMG src=\"images/forum/b_listitem.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: List Item\"></A>\n";
    echo "<A href=\"javascript: x()\" onClick=\"DoPrompt('listclose');\"><IMG src=\"images/forum/b_listclose.gif\" width=\"70\" height=\"21\" border=\"0\" alt=\"BBCode: Close List\"></A>\n";
}

#################################################
function bbsearchblock() {
global $module_name, $prefix;
$risult = mysql_query("select index_foot from ${prefix}_config");
list($index_foot) = mysql_fetch_row($risult);
    OpenTable();
	echo "<table width=\"100%\"><tr><td>";
    echo "<form action=\"modules.php?op=modload&name=".$module_name."&file=searchbb\" method=\"post\">";
    echo "<input type=\"hidden\" name=\"addterm\" value=\"any\">";
    echo "<input type=\"hidden\" name=\"sortby\" value=\"p.post_time\">";
	echo "<br>";
    echo "<b>"._SEARCH."</b>&nbsp;<input type=\"text\" name=\"term\" size=\"15\">";
    echo "<input type=\"hidden\" name=\"submit\" value=\"submit\"></form>";
	echo "</td><td align=\"right\">&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"images/topics/AllTopics.gif\"></td>";
$index_foot = stripslashes($index_foot);
	echo "<td><i>$index_foot</i></td>";
	echo "</td></tr></table>";
//    echo "<div align=\"left\"><font size=\"2\">&nbsp;&nbsp;[ <a href=\"modules.php?op=modload&name=".$module_name."&file=searchbb&addterm=any&amp;sortby=p.post_time&amp;adv=1\">"._FRICAV."</a> ]</font></div>";
    CloseTable();
}

##################################################
function get_total_topics($forum_id, $db) {
		global $prefix;
        $sql = "SELECT count(*) AS total FROM ${prefix}_forumtopics WHERE forum_id = '$forum_id'";
        if(!$result = mysql_query($sql, $db))
                return("ERROR");
        if(!$myrow = mysql_fetch_array($result))
                return("ERROR");

        return($myrow[total]);
}

##################################################
function get_total_posts($id, $db, $type) {
        global $prefix;
        switch($type) {
                case 'users':
                        $sql = "SELECT count(*) AS total FROM ".$prefix."_users WHERE uid != 1";
                break;
                case 'all':
                        $sql = "SELECT count(*) AS total FROM ${prefix}_posts";
                break;
                case 'forum':
                        $sql = "SELECT count(*) AS total FROM ${prefix}_posts WHERE forum_id = '$id'";
                break;
                case 'topic':
                        $sql = "SELECT count(*) AS total FROM ${prefix}_posts WHERE topic_id = '$id'";
                break;
                case 'user':
                        die("Should be using the users.user_posts column for this.");
        }
        if(!$result = mysql_query($sql, $db))
                return("ERROR");
        if(!$myrow = mysql_fetch_array($result))
                return("0");

        return($myrow[total]);

}

###################################################
function get_last_post($id, $db, $type) {
         global $prefix;
        switch($type) {
                case 'forum':
                {
                  // $sql = "SELECT p.post_time, p.poster_id, u.uname FROM ${prefix}_posts p, ".$prefix."_users u WHERE p.forum_id = '$id' ORDER BY post_time DESC";

/*
$sql = "SELECT p.poster_id FROM ${prefix}_posts p WHERE p.forum_id = '$id' ORDER BY post_time DESC limit 0, 1"; 
                  $result=mysql_query($sql);
                  $ergebnis=mysql_fetch_array($result);
                  if($ergebnis["poster_id"]=='1' || '-1') $sql = "SELECT p.topic_id, p.post_time, p.poster_id, u.uname FROM ${prefix}_posts p, ".$prefix."_users u WHERE p.forum_id = '$id' ORDER BY post_time DESC limit 0, 1";
                  else
*/
 $sql = "SELECT p.topic_id, p.post_time, p.poster_id, u.uname FROM ${prefix}_posts p, ".$prefix."_users u WHERE p.forum_id = '$id' AND p.poster_id = u.uid ORDER BY post_time DESC limit 0, 1";


                        
                }
                break;
                case 'topic':
                {
                	  ### Changed by Jens Ferner
                          ### $sql was minimized and limited

/*	
                          $sql = "SELECT p.poster_id FROM ${prefix}_posts p WHERE p.topic_id = '$id' ORDER BY post_time DESC limit 0, 1";
                          $result=mysql_query($sql);
                          $ergebnis=mysql_fetch_array($result);
                          if($ergebnis["poster_id"]=='1') $sql = "SELECT p.post_time, p.poster_id, u.uname FROM ${prefix}_posts p, ".$prefix."_users u WHERE p.topic_id = '$id' ORDER BY post_time DESC limit 0, 1";
                          else*/
 $sql = "SELECT p.post_time, p.poster_id, u.uname FROM ${prefix}_posts p, ".$prefix."_users u WHERE p.topic_id = '$id' AND p.poster_id = u.uid ORDER BY post_time DESC limit 0, 1";
                        
                }
                break;
        }
        if(!$result = mysql_query($sql, $db))
        {
                $val[post_time]="ERROR";
                return ($val);
        }
        if(!$myrow = mysql_fetch_array($result))
        {
                $val[post_time]= "";
                return ($val);
        }
        if($myrow[poster_id]=='1') $myrow[uname]=""._FANONIMO."";
        $val[post_time]=$myrow[post_time];
        $val[user]=$myrow[uname];
		$val[topic_id]=$myrow[topic_id];

//        $val = sprintf("%s <br> by %s", $myrow[post_time], $myrow[uname]);
        return($val);
}

/*
 * Returns an array of all the moderators of a forum
 */
function get_moderators($forum_id, $db) {
         global $prefix;
    $sql = "SELECT u.uid, u.uname FROM ".$prefix."_users u, ${prefix}_forum_mods f WHERE f.forum_id = '$forum_id' and f.user_id = u.uid";
    if(!$result = mysql_query($sql, $db))
     return("-1");
   if(!$myrow = mysql_fetch_array($result))
     return("-1");
   do {
      $array[] = array("$myrow[uid]" => "$myrow[uname]");
   } while($myrow = mysql_fetch_array($result));
   return($array);
}

/*
 * Checks if a user (user_id) is a moderator of a perticular forum (forumid)
 * Retruns 1 if TRUE, 0 if FALSE or Error
 */
function is_moderator($forum_id, $user_id, $db) {
		global $prefix;
   $sql = "SELECT userid FROM ${prefix}_forum_mods WHERE forum_id = '$forum_id' AND user_id = '$user_id'";
   if(!$result = mysql_query($sql, $db))
     return("0");
   if(!$myrow = mysql_fetch_array($result))
     return("0");
   if($myrow[userid] != '')
     return("1");
   else
     return("0");
}


function get_moderator($user_id, $db) {
         global $prefix;

/*
        if ($user_id == 0) {
                return("None");
        }
*/
        if ($user_id == -1) {
                return("None");
        }

		if ($user_id == 1) {
				return("None");
		
 }


        $sql = "SELECT uname FROM ".$prefix."_users WHERE uid = '$user_id' ";
        if(!$result = mysql_query($sql, $db))
                return("ERROR");
        if(!$myrow = mysql_fetch_array($result))
                return("ERROR");
        return("$myrow[uname]");
}

function get_forum_mod($forum_id, $db) {
		global $prefix;
        $sql = "SELECT forum_moderator FROM ${prefix}_forums WHERE forum_id = '$forum_id'";
        if(!$result = mysql_query($sql, $db))
                return("-1");
        if(!$myrow = mysql_fetch_array($result))
                return("-1");
        return("$myrow[forum_moderator]");
}

/**
 * Nathan Codding - July 19, 2000
 * Checks the given password against the DB for the given username. Returns true if good, false if not.
 */
function check_user_pw($username, $password, $db, $system) {
         global $prefix;
        // if (!$system) $password = crypt($password);

        // KingRichard Fix (Add-On 2.0.4)
        if (!$system) $password = crypt($password,substr($password,0,2));
        else $password = $password;

        $sql = "SELECT uid FROM ".$prefix."_users WHERE (uname = '$username') AND (pass = '$password')";
        $resultID = mysql_query($sql, $db);
        if (!$resultID) {
                echo mysql_error() . "<br>";
                die("Error doing DB query in check_user_pw()");
        }
        return mysql_num_rows($resultID);
} // check_user_pw()


/**
 * Nathan Codding - July 19, 2000
 * Returns a count of the given userid's private messages.
 */
function get_pmsg_count($user_id, $db) {
		global $prefix;
        $sql = "SELECT msg_id FROM ${prefix}_splattforum_priv_msgs WHERE (to_userid = $user_id)";
        $resultID = mysql_query($sql);
        if (!$resultID) {
                echo mysql_error() . "<br>";
                die("Error doing DB query in get_pmsg_count");
        }
        return mysql_num_rows($resultID);
} // get_pmsg_count()


/**
 * Nathan Codding - July 19, 2000
 * Checks if a given username exists in the DB. Returns true if so, false if not.
 */
function check_username($username, $db) {
         global $prefix;
        $sql = "SELECT uid FROM ".$prefix."_users WHERE (uname = '$username')";
        $resultID = mysql_query($sql);
        if (!$resultID) {
                echo mysql_error() . "<br>";
                die("Error doing DB query in check_username()");
        }
        return mysql_num_rows($resultID);
} // check_username()



################################
function get_userdata_from_id($userid, $db) {
         global $prefix;

     /*
   $sql = "SELECT * FROM ${prefix}_um_users_status  WHERE uid = $userid";
// die("<center><b>Errore!!! User NON Valido!</b></center>");
        $result = mysql_query($sql, $db);
        if(mysql_num_rows($result)<1)
           {
            $sql="INSERT into ${prefix}_splattforum_users_status (uid, posts, attachsig, rank, level) VALUES ('".$userid."',0,1,0,1)";
            mysql_query($sql);
           }
*/
/*
$sql = "SELECT u.*, s.* FROM ".$prefix."_users u, ${prefix}_splattforum_users_status s WHERE s.uid = $userid AND u.uid = $userid";
*/

        $sql = "SELECT * FROM ".$prefix."_users WHERE uid = $userid";


        if(!$result = mysql_query($sql, $db)) {
                $userdata = array("error" => "1");
                return ($userdata);
        }
        if(!$myrow = mysql_fetch_array($result)) {
                $userdata = array("error" => "1");
                return ($userdata);
        }

        return($myrow);
}

################################
function get_userdata($username, $db) {
         global $prefix;
        $sql = "SELECT * FROM ".$prefix."_users WHERE uname = '$username'";
        if(!$result = mysql_query($sql, $db))
                $userdata = array("error" => "1");
        if(!$myrow = mysql_fetch_array($result))
                $userdata = array("error" => "1");

        return($myrow);
}


function does_exists($id, $db, $type) {
		global $prefix;
        switch($type) {
                case 'forum':
                        $sql = "SELECT forum_id FROM ${prefix}_forums WHERE forum_id = '$id'";
                break;
                case 'topic':
                        $sql = "SELECT topic_id FROM ${prefix}_forumtopics WHERE topic_id = '$id'";
                break;
        }
        if(!$result = mysql_query($sql, $db))
                return(0);
        if(!$myrow = mysql_fetch_array($result))
                return(0);
        return(1);
}

function is_locked($topic, $db) {
		global $prefix;
        $sql = "SELECT topic_status FROM ${prefix}_forumtopics WHERE topic_id = '$topic'";
        if(!$r = mysql_query($sql, $db))
                return(FALSE);
        if(!$m = mysql_fetch_array($r))
                return(FALSE);
        if($m[topic_status] == 1)
                return(TRUE);
        else
                return(FALSE);
}



function smile($message) {
        $message = str_replace(":)", "<IMG SRC=\"images/forum/icons/icon_smile.gif\">", $message);
        $message = str_replace(":-)", "<IMG SRC=\"images/forum/icons/icon_smile.gif\">", $message);
        $message = str_replace(":(", "<IMG SRC=\"images/forum/icons/icon_frown.gif\">", $message);
        $message = str_replace(":-(", "<IMG SRC=\"images/forum/icons/icon_frown.gif\">", $message);
        $message = str_replace(":-D", "<IMG SRC=\"images/forum/icons/icon_biggrin.gif\">", $message);
        $message = str_replace(":D", "<IMG SRC=\"images/forum/icons/icon_biggrin.gif\">", $message);
        $message = str_replace(";)", "<IMG SRC=\"images/forum/icons/icon_wink.gif\">", $message);
        $message = str_replace(";-)", "<IMG SRC=\"images/forum/icons/icon_wink.gif\">", $message);
        $message = str_replace(":o", "<IMG SRC=\"images/forum/icons/icon_eek.gif\">", $message);
        $message = str_replace(":O", "<IMG SRC=\"images/forum/icons/icon_eek.gif\">", $message);
        $message = str_replace(":-o", "<IMG SRC=\"images/forum/icons/icon_eek.gif\">", $message);
        $message = str_replace(":-O", "<IMG SRC=\"images/forum/icons/icon_eek.gif\">", $message);
        $message = str_replace("8)", "<IMG SRC=\"images/forum/icons/icon_cool.gif\">", $message);
        $message = str_replace("8-)", "<IMG SRC=\"images/forum/icons/icon_cool.gif\">", $message);
        $message = str_replace(":?", "<IMG SRC=\"images/forum/icons/icon_confused.gif\">", $message);
        $message = str_replace(":-?", "<IMG SRC=\"images/forum/icons/icon_confused.gif\">", $message);
        $message = str_replace(":p", "<IMG SRC=\"images/forum/icons/icon_razz.gif\">", $message);
        $message = str_replace(":P", "<IMG SRC=\"images/forum/icons/icon_razz.gif\">", $message);
        $message = str_replace(":-p", "<IMG SRC=\"images/forum/icons/icon_razz.gif\">", $message);
        $message = str_replace(":-P", "<IMG SRC=\"images/forum/icons/icon_razz.gif\">", $message);
        $message = str_replace(":-|", "<IMG SRC=\"images/forum/icons/icon_mad.gif\">", $message);
        $message = str_replace(":|", "<IMG SRC=\"images/forum/icons/icon_mad.gif\">", $message);
		$message = str_replace(":-Z", "<IMG SRC=\"images/forum/icons/icon27.gif\">", $message);
		$message = str_replace(":-W", "<IMG SRC=\"images/forum/icons/icon24.gif\">", $message);
		$message = str_replace(":-Y", "<IMG SRC=\"images/forum/icons/icon21.gif\">", $message);
        return($message);
}
function desmile($message) {
        $message = str_replace("<IMG SRC=\"images/forum/icons/icon_smile.gif\">", ":-)",  $message);
        $message = str_replace("<IMG SRC=\"images/forum/icons/icon_frown.gif\">", ":-(", $message);
        $message = str_replace("<IMG SRC=\"images/forum/icons/icon_biggrin.gif\">",":-D",  $message);
        $message = str_replace("<IMG SRC=\"images/forum/icons/icon_wink.gif\">", ";-)", $message);
         $message = str_replace("<IMG SRC=\"images/forum/icons/icon_eek.gif\">", ":-o", $message);
        $message = str_replace("<IMG SRC=\"images/forum/icons/icon_eek.gif\">", ":-O", $message);
         $message = str_replace("<IMG SRC=\"images/forum/icons/icon_cool.gif\">", "8-)", $message);
         $message = str_replace("<IMG SRC=\"images/forum/icons/icon_confused.gif\">", ":-?", $message);
         $message = str_replace("<IMG SRC=\"images/forum/icons/icon_razz.gif\">", ":-p", $message);
        $message = str_replace("<IMG SRC=\"images/forum/icons/icon_razz.gif\">", ":-P", $message);
        $message = str_replace("<IMG SRC=\"images/forum/icons/icon_mad.gif\">", ":-|", $message);
		$message = str_replace("<IMG SRC=\"images/forum/icons/icon27.gif\">", ":-Z", $message);
		$message = str_replace("<IMG SRC=\"images/forum/icons/icon24.gif\">", ":-W", $message);
		$message = str_replace("<IMG SRC=\"images/forum/icons/icon21.gif\">", ":-Y", $message);

        return($message);
}




/*
 * Changes :) to an <IMG> tag based on the smiles table in the database
 * TODO: Get rid of global variables.
 */
/* function smile($message) {
   global $db, $url_smiles;

   $url_smiles = "images/forum/smiles";

   if ($getsmiles = mysql_query("SELECT * FROM forum_smiles")){
      while ($smiles = mysql_fetch_array($getsmiles)) {
         $message = str_replace($smiles[code], "<IMG SRC=\"$url_smiles/$smiles[smile_url]\">", $message);
      }
   }
   return($message);
}
*/
/*
 * Changes a Smiliy <IMG> tag into its corrasponding smile
 * TODO: Get rid of golbal variables, and implement a method of distinguishing between :D and :grin: using the <IMG> tag
 */
/* function desmile($message) {
   // Ick Ick Global variables...remind me to fix these! - theFinn
   global $db, $url_smiles;

   $url_smiles = "images/forum/smiles";

   if ($getsmiles = mysql_query("SELECT * FROM forum_smiles")){
      while ($smiles = mysql_fetch_array($getsmiles)) {
         $message = str_replace("<IMG SRC=\"$url_smiles/$smiles[smile_url]\">", $smiles[code], $message);
      }
   }
   return($message);
}

*/
/**
 * bbdecode/bbencode functions:
 * Rewritten - Nathan Codding - Aug 24, 2000
 * Using Perl-Compatible regexps now. Won't kill special chars
 * outside of a [code]...[/code] block now, and all BBCode tags
 * are implemented.
 * Note: the "i" matching switch is used, so BBCode tags are
 * case-insensitive.
 */
function bbdecode($message) {

                // Undo [code]
                $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);

                // Undo [quote]
                $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);

                // Undo [b] and [i]
                $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message);
                $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message);

                // Undo [url] (both forms)
                $message = preg_replace("#<!-- BBCode Start --><A HREF=\"http://(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode End -->#s", "[url=\\1]\\2[/url]", $message);

                // Undo [email]
                $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message);

                // Undo [img]
                $message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message);

                // Undo lists (unordered/ordered)

                // unordered list code..
                $matchCount = preg_match_all("#<!-- BBCode ulist Start --><UL>(.*?)</UL><!-- BBCode ulist End -->#s", $message, $matches);

                for ($i = 0; $i < $matchCount; $i++)
                {
                        $currMatchTextBefore = preg_quote($matches[1][$i]);
                        $currMatchTextAfter = preg_replace("#<LI>#s", "[*]", $matches[1][$i]);

                        $message = preg_replace("#<!-- BBCode ulist Start --><UL>$currMatchTextBefore</UL><!-- BBCode ulist End -->#s", "[list]" . $currMatchTextAfter . "[/list]", $message);
                }

                // ordered list code..
                $matchCount = preg_match_all("#<!-- BBCode olist Start --><OL TYPE=([A1])>(.*?)</OL><!-- BBCode olist End -->#si", $message, $matches);

                for ($i = 0; $i < $matchCount; $i++)
                {
                        $currMatchTextBefore = preg_quote($matches[2][$i]);
                        $currMatchTextAfter = preg_replace("#<LI>#s", "[*]", $matches[2][$i]);

                        $message = preg_replace("#<!-- BBCode olist Start --><OL TYPE=([A1])>$currMatchTextBefore</OL><!-- BBCode olist End -->#si", "[list=\\1]" . $currMatchTextAfter . "[/list]", $message);
                }

                return($message);
}

function bbencode($message) {

        // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
        $matchCount = preg_match_all("#\[code\](.*?)\[/code\]#si", $message, $matches);

        for ($i = 0; $i < $matchCount; $i++)
        {
                $currMatchTextBefore = preg_quote($matches[1][$i]);
                $currMatchTextAfter = htmlspecialchars($matches[1][$i]);
                $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);
        }

        // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
        $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);

        // [b] and [/b] for bolding text.
        $message = preg_replace("#\[b\](.*?)\[/b\]#si", "<!-- BBCode Start --><B>\\1</B><!-- BBCode End -->", $message);

        // [i] and [/i] for italicizing text.
        $message = preg_replace("#\[i\](.*?)\[/i\]#si", "<!-- BBCode Start --><I>\\1</I><!-- BBCode End -->", $message);

        // [url]www.phpbb.com[/url] code..
        $message = preg_replace("#\[url\](http://)?(.*?)\[/url\]#si", "<!-- BBCode Start --><A HREF=\"http://\\2\" TARGET=\"_blank\">\\2</A><!-- BBCode End -->", $message);

        // [url=www.phpbb.com]phpBB[/url] code..
        $message = preg_replace("#\[url=(http://)?(.*?)\](.*?)\[/url\]#si", "<!-- BBCode Start --><A HREF=\"http://\\2\" TARGET=\"_blank\">\\3</A><!-- BBCode End -->", $message);

        // [email]user@domain.tld[/email] code..
        $message = preg_replace("#\[email\](.*?)\[/email\]#si", "<!-- BBCode Start --><A HREF=\"mailto:\\1\">\\1</A><!-- BBCode End -->", $message);

        // [img]image_url_here[/img] code..
        $message = preg_replace("#\[img\](.*?)\[/img\]#si", "<!-- BBCode Start --><IMG SRC=\"\\1\"><!-- BBCode End -->", $message);

        // unordered list code..
        $matchCount = preg_match_all("#\[list\](.*?)\[/list\]#si", $message, $matches);

        for ($i = 0; $i < $matchCount; $i++)
        {
                $currMatchTextBefore = preg_quote($matches[1][$i]);
                $currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[1][$i]);

                $message = preg_replace("#\[list\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode ulist Start --><UL>$currMatchTextAfter</UL><!-- BBCode ulist End -->", $message);
        }

        // ordered list code..
        $matchCount = preg_match_all("#\[list=([a1])\](.*?)\[/list\]#si", $message, $matches);

        for ($i = 0; $i < $matchCount; $i++)
        {
                $currMatchTextBefore = preg_quote($matches[2][$i]);
                $currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[2][$i]);

                $message = preg_replace("#\[list=([a1])\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode olist Start --><OL TYPE=\\1>$currMatchTextAfter</OL><!-- BBCode olist End -->", $message);
        }

        return($message);
}

function get_forum_name($forum_id, $db) {
		global $prefix;
        $sql = "SELECT forum_name FROM ${prefix}_forums WHERE forum_id = '$forum_id'";
        if(!$r = mysql_query($sql, $db))
                return("ERROR");
        if(!$m = mysql_fetch_array($r))
                return("None");
        return($m[forum_name]);
}




function convertidatasolo($data) 

{ 

$data = strtotime($data); 
$data = strftime(_LOCALDATE, $data); 

return($data); 

} 







/**
 * Modified by Nathan Codding - July 20, 2000.
 * Made it only work on URLs and e-mail addresses preceeded by a space, in order to stop
 * mangling HTML code.
 *
 * The Following function was taken from the Scriplets area of http://www.phpwizard.net, and was written by Tobias Ratschiller.
 *   Visit phpwizard.net today, its an excellent site!
 */

function make_clickable($text) {
        $ret = eregi_replace(" ([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", " <a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $text);
        $ret = eregi_replace(" (([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", " <a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $ret);
        return($ret);
}

/**
 * Nathan Codding - August 24, 2000.
 * Takes a string, and does the reverse of the PHP standard function
 * htmlspecialchars().
 */
function undo_htmlspecialchars($input) {
        $input = preg_replace("/&gt;/i", ">", $input);
        $input = preg_replace("/&lt;/i", "<", $input);
        $input = preg_replace("/&quot;/i", "\"", $input);
        $input = preg_replace("/&amp;/i", "&", $input);

        return $input;
}

function validate_username($username, $db) {
		global $prefix;
        $sql = "SELECT disallow_username FROM ${prefix}_splattforum_disallow WHERE disallow_username = '" . addslashes($username) . "'";
        if(!$r = mysql_query($sql, $db))
                return(0);
        if($m = mysql_fetch_array($r)) {
                if($m[disallow_username] == $username)
                        return(1);
                else
                        return(0);
        }
        return(0);
}

/*
 * Replaces banned words in a string with their replacements
 */
/*function censor_string($string, $db) {
   $sql = "SELECT word, replacement FROM words";
   if(!$r = mysql_query($sql, $db))
      die("Error, could not contact the database! Please check your database settings in config.$phpEx");
   while($w = mysql_fetch_array($r)) {
      $word = quotemeta(stripslashes($w[word]));
      $replacement = stripslashes($w[replacement]);
      $string = eregi_replace(" $word", " $replacement", $string);
      $string = eregi_replace("^$word", "$replacement", $string);
      $string = eregi_replace("<BR>$word", "<BR>$replacement", $string);
   }
   return($string);
}

function is_banned($ipuser, $type, $db) {
   
   // Remove old bans
   $sql = "DELETE FROM banlist WHERE (ban_end < ". mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")).") AND (ban_end > 0)";
   @mysql_query($sql, $db);
   
   switch($type) {
    case "ip":
      $sql = "SELECT ban_ip FROM banlist";
      if($r = mysql_query($sql, $db)) {
	 while($iprow = mysql_fetch_array($r)) {
	    $ip = $iprow[ban_ip];
	    if($ip[strlen($ip) - 1] == ".") {
	       $db_ip = explode(".", $ip);
	       $this_ip = explode(".", $ipuser);
	       
	       for($x = 0; $x < count($db_ip) - 1; $x++) 
		 $my_ip .= $this_ip[$x] . ".";

	       if($my_ip == $ip)
		 return(TRUE);
	    }
	    else {
	       if($ipuser == $ip)
		 return(TRUE);
	    }
	 }
      }
      else 
	return(FALSE);
      break;
    case "username":
      $sql = "SELECT ban_userid FROM banlist WHERE ban_userid = '$ipuser'";
      if($r = mysql_query($sql, $db)) {
	 if(mysql_num_rows($r) > 0)
	   return(TRUE);
      }
      break;
   }
   
   return(FALSE);
}






*/

?>