I am currently doing a rewrite which includes an administration feature that lets you manage shouts. Also I am compiling the code into one php file and one template file.
Here is the code I have so far. It works great.
----- Create MYSQL table -----
CREATE TABLE shoutbox (
id int(11) NOT NULL auto_increment,
name text NOT NULL,
message text NOT NULL,
timestamp int(11) NOT NULL default '0',
ip varchar(15) NOT NULL default '0',
browser varchar(255) NOT NULL default '',
block int(50) NOT NULL default '0',
KEY msg_id (id)
) TYPE=MyISAM;
----- shout.php ----- place in the 4images root
<?
define('ROOT_PATH', './');
include(ROOT_PATH.'global.php');
require(ROOT_PATH.'includes/sessions.php');
$user_access = get_permission();
include(ROOT_PATH.'includes/page_header.php');$action = $_GET["action"];
if ($action == "shout") {
if ($message == !"" && $user_info['user_level'] >= USER){
$ip = $REMOTE_ADDR;
$info = $HTTP_USER_AGENT;
$goto = $HTTP_REFERER;
$add_date=time (void);
$message = stripslashes($message);
$message = htmlspecialchars($message);
$user_name = $user_info['user_name'];
$result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,timestamp,ip,browser,block)".
"VALUES ('NULL', '$user_name', '$message', '$add_date', '$ip', '$info', '$block')");
echo "<META http-equiv='refresh' content='0;URL=http://www.yourdomain/shout.php'>";
}
else {
echo "<META http-equiv='refresh' content='0;URL=http://www.yourdomain/shout.php'>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Shout Box</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/templates/default/style.css" type=text/css>
</head>
<body>
<table width="159" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="5"></td>
<td width="135">
<?php
include("shoutbox.php");
?>
</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
----- shoutbox.php ----- place this file anywhere you like and call it up in shout.php using the 'include' function.
<?PHP
$result = mysql_query("SELECT * FROM `shoutbox` WHERE block <> 1 ORDER BY 'id' DESC LIMIT 20") or died("Query Error");
while($row = mysql_fetch_array($result))
{
$id = $row["id"];
$timestamp = strftime("%d %b - %H:%M", $row["timestamp"]);
$name = $row["name"];
$message = $row["message"];
$ip = $row["ip"];
$browser = $row["browser"];
$badwords[] = array('shit', '****');
$badwords[] = array('tra-la-la', '****');
foreach ($badwords as $badword) {
$message = eregi_replace($badword[0],$badword[1],$message);
}
$message = str_replace(":)","<img src=\"/images/smile.gif\" align=\"texttop\">",$message);
$message = str_replace(":D","<img src=\"/images/teeth.gif\" align=\"texttop\">",$message);
$message = str_replace(":o)","<img src=\"/images/clown.gif\" align=\"texttop\">",$message);
$message = str_replace(":0)","<img src=\"/images/clown.gif\" align=\"texttop\">",$message);
$message = str_replace(":O)","<img src=\"/images/clown.gif\" align=\"texttop\">",$message);
$message = str_replace(":-/","<img src=\"/images/hmm.gif\" align=\"texttop\">",$message);
$message = str_replace(":(","<img src=\"/images/frown.gif\" align=\"texttop\">",$message);
$message = str_replace(":p","<img src=\"/images/tounge.gif\" align=\"texttop\">",$message);
$message = str_replace(":P","<img src=\"/images/tounge.gif\" align=\"texttop\">",$message);
$name = strtolower($name);
echo("<span style=\"cursor:default\"><table align=\"center\" width=\"135\" bgcolor=\"EEEEEE\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\">
<tr><td>
<table width=\"135\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\" title=\"Posted: $timestamp, IP Logged\">
<tr>
<td width=\"135\" bgcolor=\"#EEEEEE\"><font class=\"name\"> $name</font></td>
</tr>
<tr>
<td><font class=\"message\">$message</font></td>
</tr>
</table></td></tr></table></span><img src=\"/images/spacer.gif\" width=\"1\" height=\"4\" border=\"0\">");
}
?>
The WHERE block <> 1 in the above MYSQL query is there to give you a bit more control over what messages are viewed. for example if you want to hide a bad or offensive message from public view but dont want it deleted, then place a '1' in the 'block' cell of the MYSQL table for that post. I added this feature because I don't like deleting the messages from MYSQL. I like to keep all the bad messages so I can track trouble makers. You can disable this feature by removing the WHERE block <> 1. Finally the code you need for your templates
----- place this code where you want the shoutbox displayed -----
<iframe src="shout.php" name="shoutbox" scrolling="no" width="159" height="235" frameborder="0" onload="document.shout.reset()"></iframe>
{if user_loggedin}
<SCRIPT language=JavaScript type=text/javascript>
<!--
function emoticon(text) {
text = ''+text+' ';
if (document.shout.message.createTextRange && document.shout.message.caretPos) {
var caretPos = document.shout.message.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
document.shout.message.focus();
} else {
document.shout.message.value += text;
document.shout.message.focus();
}
}
//-->
</SCRIPT> <form method="post" name="shout" action="shout.php?action=shout" target="shoutbox">
<table align="center" cellspacing="0" cellpadding="0" width="147" border="0">
<tr>
<td colspan="2" align="center"><input type="text" name="message" maxlength="200">
<input type='hidden' name='block' value=''></td>
</tr>
<tr>
<td width="84" align="center" valign="top">
<img src="/images/smile.gif" onmouseover="this.style.cursor='hand';" onclick="emoticon(':)');" alt="// laughing click to add" width="12" height="12" hspace="1" border="0"><img src="/images/teeth.gif" onmouseover="this.style.cursor='hand';" onclick="emoticon(':D');" alt="// cheezy grin click to add" width="12" height="12" hspace="1" border="0"><img src="/images/clown.gif" onmouseover="this.style.cursor='hand';" onclick="emoticon(':o)');" alt="// clowning around click to add" width="12" height="12" hspace="1" border="0"><img src="/images/hmm.gif" onmouseover="this.style.cursor='hand';" onclick="emoticon(':-/');" alt="// upset and crying click to add" width="12" height="12" hspace="1" border="0"><img src="/images/frown.gif" onmouseover="this.style.cursor='hand';" onclick="emoticon(':(');" alt="// frowning click to add" width="12" height="12" hspace="1" border="0"><img src="/images/tounge.gif" onmouseover="this.style.cursor='hand';" onclick="emoticon(':P');" alt="// sticking your tongue out click to add" width="12" height="12" hspace="1" border="0">
</td>
<td width="63"><input type="submit" value="Shout"></td>
</tr>
</table>
</form>
{endif user_loggedin} {if user_loggedout}
<table align="center" cellspacing="0" cellpadding="0" width="147" border="0">
<tr>
<td align="center">Please login or register to post in the shoutbox.</td>
</tr>
</table>
{endif user_loggedout}
And thats it, it needs bit of modification to work on another site as it was built for myself. But the basics of the code is there. If you need any pointers please do ask.
Good luck. I will post my new version when I build it.
Carl