i made a quick hack to allow this shoutbox to work without redrawing constantly and add a userlist.
new table:
Code:
CREATE TABLE `shoutbox_hash` (
`userid` int(11) NOT NULL default '0',
`hash` varchar(128) NOT NULL default '0',
`ts` int(10) NOT NULL default '0',
UNIQUE KEY `userid` (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
at the top of showshout.php, above the <table> tag, I have added:
at the bottom, just after the </table>, I added:
Code:
$o = ob_get_contents ();
ob_clean ();
$hash = md5 ($o);
$user_id = $vbulletin->userinfo['userid'];
$q = "select hash from shoutbox_hash where userid = ".$user_id;
$res = $db->query ($q);
$row = mysql_fetch_assoc ($res);
if ($_REQUEST['hash'] != '1' || $row['hash'] != $hash) {
$t = time () - 60;
$q = "select u.username, u.userid from user u, shoutbox_hash h where h.userid = u.userid and h.ts > $t order by u.username";
$res = $db->query ($q);
$i = 0;
$users = array ();
while ($row = mysql_fetch_assoc ($res)) {
$i++;
$users[] = "<a target='_user' href='/member.php?u=".$row['userid']."'>".$row['username']."</a>";
}
if ($i) {
echo "<b>Users in chat</b>: ".implode (", ", $users)."<br>";
}
echo $o;
}
$q = "replace into shoutbox_hash (userid, hash, ts) values (".$user_id.", '".$hash."', ".time ().")";
$db->query ($q);
Then in shoutshow.js, I replaced the setInterval with:
Code:
setInterval ("showshout('1');", 4000);
Finally, I replaced the showshout() function with:
Code:
function showshout(e)
{
htmlrequest = ajaxfunction();
if (htmlrequest == null)
{
alert ('Browser does not support HTTP requests');
return;
}
htmlrequest.open('GET', 'shoutshow.php?hash=' + e, true);
htmlrequest.setRequestHeader('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT');
htmlrequest.onreadystatechange = statechanged;
htmlrequest.send(null);
}
This change is a temp fix for me - it won't reduce server load, but it will reduce bandwidth consumption by a large margin.