I am using mbirth's SMF Shoutbox (http://mods.simplemachines.org/index.php?mod=412) on my forum and I simply added the code
if (function_exists('sbox')) sbox();
in a php center block, to show the shoutbox on the front page - works great.
You can add the code in TPortal.template.php as well.
Since you are using this shoutbox you can try this if you want.Ã, It will work on the latest versions but I can't say that it will work on future versions
sboxDB.php in Sources Replace with
<?php
header('Pragma: no-cache');
header('Expires: 0');
header('Cache-control: none');
require("../SSI.php");
if (!defined('SMF'))
Ã, die('Hacking attempt...');
is_not_banned(true);
loadLanguage('sbox');
/***[ BEGIN CONFIGURATION ]***************************************************/
$sbox_HistoryFile = $boarddir . '/sbox.history.html';
$sbox_NickPrefix = '<';Ã, Ã, Ã, // this won't be linked to the profile page
$sbox_NickInnerPrefix = '<b>';Ã, // this will be linked to the profile page, use formatting tags (<B>) here
$sbox_NickInnerSuffix = '</b>';Ã, // so that they are applied inside the <A>, otherwise they won't work
$sbox_NickSuffix = '>';
$sbox_DatePrefix = '[';
$sbox_DateSeparator = ' ';Ã, Ã, // separates weekday from time
$sbox_DateSuffix = ']';
/***[ END CONFIGURATION ]*****************************************************/
// BEGIN: BORROWED FROM http://de2.php.net/manual/en/function.flock.php
/*
* I hope this is usefull.
* If mkdir() is atomic,
* then we do not need to worry about race conditions while trying to make the lockDir,
* unless of course we're writing to NFS, for which this function will be useless.
* so thats why i pulled out the usleep(rand()) piece from the last version
*
* Again, its important to tailor some of the parameters to ones indivdual usage
* I set the default $timeLimit to 3/10th's of a second (maximum time allowed to achieve a lock),
* but if you're writing some extrememly large files, and/or your server is very slow, you may need to increase it.
* Obviously, the $staleAge of the lock directory will be important to consider as well if the writing operations might take a while.
* My defaults are extrememly general and you're encouraged to set your own
*
* $timeLimit is in microseconds
* $staleAge is in seconds
*/
function microtime_float() {
Ã, list($usec, $sec) = explode(' ', microtime());
Ã, return ((float)$usec + (float)$sec);
}
function locked_filewrite($filename, $data, $timeLimit = 300000, $staleAge = 5) {
Ã, ignore_user_abort(1);
Ã, $lockDir = $filename . '.lock';
Ã, if (is_dir($lockDir)) {
Ã, Ã, if ((time() - filemtime($lockDir)) > $staleAge) {
Ã, Ã, Ã, rmdir($lockDir);
Ã, Ã, }
Ã, }
Ã, $locked = @mkdir($lockDir);
Ã, if ($locked === false) {
Ã, Ã, $timeStart = microtime_float();
Ã, Ã, do {
Ã, Ã, Ã, if ((microtime_float() - $timeStart) > $timeLimit) break;
Ã, Ã, Ã, $locked = @mkdir($lockDir);
Ã, Ã, } while ($locked === false);
Ã, }
Ã, $success = false;
Ã, if ($locked === true) {
Ã, Ã, $fp = @fopen($filename, 'at');
Ã, Ã, if (@fwrite($fp, $data)) $success = true;
Ã, Ã, @fclose($fp);
Ã, Ã, rmdir($lockDir);
Ã, }
Ã, ignore_user_abort(0);
Ã, return $success;
}
// END: BORROWED FROM http://de2.php.net/manual/en/function.flock.php
function missinghtmlentities($text) {
Ã, // entitify missing characters, ignore entities already there (Unicode / UTF8) (hopefully in {-notation)
Ã, $split = preg_split('/(&#[\d]+;)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
Ã, $result = '';
Ã, foreach ($split as $s) {
Ã, Ã, if (substr($s, 0, 2) != '&#' || substr($s, -1, 1) != ';') {
Ã, Ã, Ã,Â
Ã, Ã, Ã, $result .= $s;
Ã, Ã, }
Ã, }
Ã, return $result;
}
//display html header
echo '<html xmlns="http://www.w3.org/1999/xhtml"' . ($context['right_to_left']?' dir="rtl"':'') . '>
<head>
Ã, <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />';
Ã,Â
$result = db_query("SELECT value2 FROM {$db_prefix}tp_variables WHERE type = 'shoutbox' ORDER BY value2 DESC LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
$refreshBlocked = false;
$delta = time() - $row['value2'];
if ((!empty($_REQUEST['action'])) && ($_REQUEST['action'] == 'write')) $dontblock = true; else $dontblock = false;
if (($delta > $modSettings['lastActive']*60) && ($modSettings['sbox_BlockRefresh'] == '1') && (!$dontblock)) {
Ã, $refreshBlocked = true;
} else {
Ã, echo '
Ã, <meta http-equiv="refresh" content="' . $modSettings['sbox_RefreshTime'] . ';URL=sboxDB.php?ts=' . time() . '">';
}
$sbox_CurTheme = strtolower(substr($settings['theme_url'], strrpos($settings['theme_url'], '/')+1));
$sbox_DarkThemes = explode('|', strtolower($modSettings['sbox_DarkThemes']));
if (in_array($sbox_CurTheme, $sbox_DarkThemes)) {
Ã, $sbox_TextColor2 = $modSettings['sbox_TextColor2'];
} else {
Ã, $sbox_TextColor2 = $modSettings['sbox_TextColor1'];
}
echo '
Ã, <link rel="stylesheet" type="text/css" href="' . $settings['theme_url'] . '/style.css?rc2" />
Ã, <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
Ã, Ã, function kill() { return confirm("' . $txt['sbox_KillShout'] . '"); }
Ã, Ã, function clearHist() { return confirm("' . $txt['quickmod_confirm'] . '"); }
Ã, Ã, // get SMF-time including time zone corrections (system+user)
Ã, Ã, if (parent && parent.document.sbox.ts) {
Ã, Ã, Ã, parent.document.sbox.ts.value = ' . forum_time(true) . ';
Ã, Ã, }
Ã, Ã, // ]]></script>
Ã, <style type="text/css">
Ã,Â
Ã, Ã, .windowbg2 {
Ã, Ã, Ã, font-family: ' . $modSettings['sbox_FontFamily'] . ';
Ã, Ã, Ã, font-style: normal;
Ã, Ã, Ã, font-size: ' . $modSettings['sbox_TextSize'] . ';
Ã, Ã, Ã, font-weight: normal;
Ã, Ã, Ã, text-decoration: none;
Ã, Ã, }
Ã, Ã, .Even {
Ã, Ã, Ã, color: ' . $sbox_TextColor2 . ';
Ã, Ã, Ã, font-weight: normal;
Ã, Ã, Ã, text-decoration: none;
Ã, Ã, }
Ã, Ã,Â
Ã, Ã, body {
Ã, Ã, Ã, width: 100%;
Ã, Ã, Ã, padding: 0;
Ã, Ã, Ã, margin: 0;
Ã, Ã, Ã, border: 0;
Ã, Ã, }
Ã, Ã, .Kill, A.Kill {
Ã, Ã, Ã, color: #ff0000;
Ã, Ã, }
Ã, </style>';
if (!empty($_REQUEST['action'])) switch ($_REQUEST['action']) {
Ã, case 'write':
Ã, Ã, ifÃ, (((!$context['user']['is_guest']) || ($modSettings['sbox_GuestAllowed'] == '1')) && !empty($_REQUEST['sboxText'])) {
Ã, Ã, Ã, $content = $_REQUEST['sboxText'];
Ã, Ã, Ã, // get current timestamp
Ã, Ã, Ã, $date = time();
Ã, Ã,Â
Ã, Ã, Ã, $posterip = $user_info['ip'];
Ã, Ã, Ã, $pip = explode('.', $posterip);
Ã, Ã, Ã, $piph = sprintf("%02s%02s%02s%02s", dechex($pip[0]), dechex($pip[1]), dechex($pip[2]), dechex($pip[3]));
Ã, Ã,Â
Ã, Ã, Ã, // handle special characters
//Ã, Ã, Ã, $content = addslashes($piph . $content);
Ã, Ã,Â
Ã, Ã, Ã, // insert shout message into database
Ã, Ã, Ã, $sql = "INSERT INTO " . $db_prefix . "tp_variables (value5, value1, value2, type) VALUES ('" . $context['user']['id'] . "', '" . $content . "', '$date', 'shoutbox')";
Ã, Ã, Ã, db_query($sql, __FILE__, __LINE__);
Ã, Ã,Â
Ã, Ã, Ã, // delete old shout messages (get id of last shouting and delete all shoutings as defined in settings
Ã, Ã, Ã, $result = db_query("SELECT id FROM " . $db_prefix . "tp_variables WHERE value5 ='" . $context['user']['id'] . "' AND value1='" . $content . "' AND value2='$date' AND type = 'shoutbox'", __FILE__, __LINE__);
Ã, Ã, Ã, $rows = mysql_fetch_assoc($result);
Ã, Ã, Ã, $sql = 'DELETE FROM ' . $db_prefix . "tp_variables WHERE id < '" . ($rows["id"]-$modSettings['sbox_MaxLines']) . "' AND type = 'shoutbox'";
Ã, Ã, Ã, db_query($sql, __FILE__, __LINE__);
Ã, Ã, Ã,Â
Ã, Ã, Ã, // write into history if needed
Ã, Ã, Ã, if ($modSettings['sbox_DoHistory'] == '1') {
Ã, Ã, Ã, Ã, $ds = $sbox_DatePrefix . date('Y-m-d', $date) . $sbox_DateSeparator . date('H:i.s', $date) . $sbox_DateSuffix;
Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, $content = stripslashes($content); // shouting content
//Ã, Ã, Ã, Ã, $content = substr($content, 8);
Ã, Ã, Ã, Ã, $content = missinghtmlentities($content);
Ã, Ã, Ã, Ã, if ($modSettings['sbox_AllowBBC'] == '1' && ($context['user']['id'] > 0 || $modSettings['sbox_GuestBBC'] == '1')) {
Ã, Ã, Ã, Ã, Ã, $content = parse_bbc($content);
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, $output = $ds . ' ' . $sbox_NickPrefix;
Ã, Ã, Ã, Ã, if ($context['user']['id'] > 0) {
Ã, Ã, Ã, Ã, Ã, $output .= '<a href="' . $scripturl . '?action=profile;u=' . $context['user']['id'] . '" target="_blank" class="' . $divclass . '">';
Ã, Ã, Ã, Ã, Ã, $output .= $sbox_NickInnerPrefix . ((!empty($context['user']['name']))?$context['user']['name']:$context['user']['username']) . $sbox_NickInnerSuffix;
Ã, Ã, Ã, Ã, Ã, $output .= '</a>';
Ã, Ã, Ã, Ã, } else {
Ã, Ã, Ã, Ã, Ã, $output .= $sbox_NickInnerPrefix . 'Guest-' . base_convert($piph, 16, 36) . $sbox_NickInnerSuffix;
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, $output .= $sbox_NickSuffix . ' ' . $content . '</div><br />' . "\n";
Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, if (!file_exists($sbox_HistoryFile)) {
Ã, Ã, Ã, Ã, Ã, // TODO: Prepare file ... HTML-header, stylesheet, etc.
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, locked_filewrite($sbox_HistoryFile, $output);
Ã, Ã, Ã, }
Ã, Ã, }
Ã, Ã, break;
Ã,Â
Ã, case 'clearhist':
Ã, Ã, if ($context['user']['is_admin']) {
Ã, Ã, Ã, if (file_exists($sbox_HistoryFile)) {
Ã, Ã, Ã, Ã, $lockDir = $sbox_HistoryFile . '.lock';
Ã, Ã, Ã, Ã, $start = time();
Ã, Ã, Ã, Ã, while ((is_dir($lockDir)) && ((time() - $start) < 5)) {
Ã, Ã, Ã, Ã, Ã, usleep(100000);Ã, // sleep 1/10th of a second (for a PC these are ages!)
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, if (!is_dir($lockDir)) @unlink($sbox_HistoryFile);
Ã, Ã, Ã, }
Ã, Ã, }
Ã, Ã, break;
Ã, case 'kill':
Ã, Ã, ifÃ, (!empty($_REQUEST['kill']) && ($context['user']['is_admin'] || ($modSettings['sbox_ModsRule'] && count(boardsAllowedTo('moderate_board'))>0))) {
$sql = 'DELETE FROM ' . $db_prefix . 'tp_variables WHERE type = "shoutbox" AND id=' . intval($_REQUEST['kill']);
Ã, Ã, Ã, db_query($sql, __FILE__, __LINE__);
Ã, Ã, }
Ã, Ã, break;
Ã, Ã,Â
}
// close header and open body
echo '
</head>
<body class="windowbg2"><div class="windowbg2">';
echo "\n" . '<b>' . $sbox_DatePrefix . strftime($user_info['time_format'], forum_time(true)) . $sbox_DateSuffix;
if ($refreshBlocked) {
Ã, echo ' ' . $txt['sbox_RefreshBlocked'];
}
echo '</b><br />';
if ($context['user']['is_admin']) {
Ã, if ($modSettings['sbox_DoHistory'] == '1') {
Ã, Ã, echo "\n";
Ã, Ã, if (file_exists($sbox_HistoryFile)) {
Ã, Ã, Ã, echo '[<a href="' . str_replace($boarddir, $boardurl, $sbox_HistoryFile) . '" target="_blank">' . $txt['sbox_History'] . '</a>]';
Ã, Ã, Ã, echo ' [<a href="' . $_SERVER['PHP_SELF'] . '?action=clearhist" class="Kill" onClick="return clearHist();">' . $txt['sbox_HistoryClear'] . '</a>]';
Ã, Ã, } else {
Ã, Ã, Ã, echo '[' . $txt['sbox_HistoryNotFound'] . ']';
Ã, Ã, }
Ã, Ã, echo '';
Ã, }
}
/*
if (!empty($settings['display_who_viewing'])) {
Ã, echo '<small>';
Ã, if ($settings['display_who_viewing'] == 1)
Ã, Ã, echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt[19];
Ã, else
Ã, Ã, echo empty($context['view_members_list']) ? '0 ' . $txt[19] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) or $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
Ã, echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board'], '</small>';
}
*/
// get shout messages out of database
$result = db_query("
Ã, SELECT *
Ã, FROM {$db_prefix}tp_variables AS sb, {$db_prefix}members AS mem
Ã, WHERE mem.ID_MEMBER = sb.value5 AND sb.type = 'shoutbox' ORDER BY id DESC, value2 ASC LIMIT " . $modSettings['sbox_MaxLines'], __FILE__, __LINE__);
if(mysql_num_rows($result)) {
Ã, $lname = '';
Ã, $count = 0;
Ã, $div = false;
Ã, $alert = false;
Ã, while($row = mysql_fetch_assoc($result)) {
Ã, Ã, $name = $row['value5'];Ã, Ã, Ã, Ã, Ã, // user name
Ã, Ã, $date = forum_time(true, $row['value2']);Ã, Ã, Ã, Ã, Ã, // shouting date and time
Ã, Ã, $content = stripslashes($row['value1']); // shouting content
//Ã, Ã, $piph = substr($content, 0, 8);
//Ã, Ã, $content = substr($content, 8);
Ã, Ã, censorText($content);
Ã, Ã, $content = missinghtmlentities($content);
Ã, Ã, if ($modSettings['sbox_AllowBBC'] == '1' && ($name > 0 || $modSettings['sbox_GuestBBC'] == '1')) {
Ã, Ã, Ã, $content = parse_bbc($content);
Ã, Ã, }
Ã, Ã, if (!empty($_REQUEST['ts']) && !$div && $date<$_REQUEST['ts']) {
Ã, Ã, Ã, if ($count > 0 && $modSettings['sbox_NewShoutsBar'] == '1') {
Ã, Ã, Ã, Ã, echo '<hr>' . "\n";
Ã, Ã, Ã, }
Ã, Ã, Ã, $div = true;
Ã, Ã, }
Ã, Ã,Â
Ã, Ã, if ($name != $lname) {
Ã, Ã, Ã, $count++;Ã, Ã, Ã, Ã, Ã, // increase counter
Ã, Ã, }
Ã, Ã, $lname = $name;
Ã, Ã, // display shouting message and use a different color each second row
Ã, Ã, if ($count % 2 == 0) {
Ã, Ã, Ã, $divclass = 'windowbg2';
Ã, Ã, } else {
Ã, Ã, Ã, $divclass = 'Even';
Ã, Ã, }
/*Ã, Ã, $r = $g = $b = 0;
Ã, Ã, for ($i=0;$i<strlen($name);$i++) {
Ã, Ã, Ã, $x = ord(substr($name, $i, 1));
Ã, Ã, Ã, switch ($i % 3) {
Ã, Ã, Ã, Ã, case 0: $r += $x; break;
Ã, Ã, Ã, Ã, case 1: $g += $x; break;
Ã, Ã, Ã, Ã, case 2: $b += $x; break;
Ã, Ã, Ã, }
Ã, Ã, }
Ã, Ã, $r = dechex($r % 192);
Ã, Ã, $g = dechex($g % 192);
Ã, Ã, $b = dechex($b % 192);
Ã, Ã, if (strlen($r)<2) $r = '0' . $r;
Ã, Ã, if (strlen($g)<2) $g = '0' . $g;
Ã, Ã, if (strlen($b)<2) $b = '0' . $b;
Ã, Ã, $colh = $r . $g . $b;
Ã, Ã, echo "\n" . '<div class="' . $divclass . '" style="color: #' . $colh . '">'; */
Ã, Ã, echo "\n" . '<div class="' . $divclass . '">';
Ã, Ã,Â
Ã, Ã, if ($context['user']['is_admin'] || ($modSettings['sbox_ModsRule'] && count(boardsAllowedTo('moderate_board'))>0)) {
Ã, Ã, Ã, echo '[<a title="' . $txt['sbox_KillShout'] . '" class="Kill" onClick="return kill();" href="' . $_SERVER['PHP_SELF'] . '?action=kill&kill=' . $row['id'] . '">X</a>]';
Ã, Ã, }
Ã, Ã,Â
Ã, Ã, $wd = $txt['days_short'][date('w', $date)];
Ã, Ã, $ts = date('H:i', $date);
Ã, Ã, $ds = $sbox_DatePrefix . $wd . $sbox_DateSeparator . $ts . $sbox_DateSuffix;
Ã, Ã,Â
Ã, Ã, // highlight username, realname and make sound
Ã, Ã, if (!empty($context['user']['name']) && strpos($content, $context['user']['name']) !== false) {
Ã, Ã, Ã, if ($div === false) $alert = true;
Ã, Ã, Ã, $content = str_replace($context['user']['name'], '<b><u>' . $context['user']['name'] . '</u></b>', $content);
Ã, Ã, }
Ã, Ã, if (!empty($user_info['username']) && $user_info['username'] != $context['user']['name'] && strpos($content, $user_info['username']) !== false) {
Ã, Ã, Ã, if ($div === false) $alert = true;
Ã, Ã, Ã, $content = str_replace($user_info['username'], '<b><u>' . $user_info['username'] . '</u></b>', $content);
Ã, Ã, }
Ã, Ã,Â
Ã, Ã, echo $ds . ' ' . $sbox_NickPrefix;
Ã, Ã, if ($name > 0) {
Ã, Ã, Ã, if ($modSettings['sbox_UserLinksVisible'] == '1') echo '<a href="' . $scripturl . '?action=profile;u=' . $name . '" target="_top" style="text-decoration: none;"><span class="' . $divclass . '">';
Ã, Ã, Ã, echo $sbox_NickInnerPrefix . ((!empty($row['realName']))?$row['realName']:$row['memberName']) . $sbox_NickInnerSuffix;
Ã, Ã, Ã, if ($modSettings['sbox_UserLinksVisible'] == '1') echo '</span></a>';
Ã, Ã, } else {
Ã, Ã, Ã, echo $sbox_NickInnerPrefix . $txt['sbox_Guest'] . '-' . base_convert($piph, 16, 36) . $sbox_NickInnerSuffix;
Ã, Ã, }
Ã, Ã, echo $sbox_NickSuffix . ' ' . $content . '</div>';
Ã, }
Ã, if (($modSettings['sbox_EnableSounds']) && ($alert === true) && ($div === true)) {
Ã, Ã, echo '<embed src="' . $boardurl . '/chat-inbound_GSM.wav" hidden="true" autostart="true" loop="false"></embed>' . "\n";
Ã, }
}
?>
</div>
</body>
</html>
This will put shouts in tp_variables so you can view them in your profile.
Feel free to modify it, but let me have a copy as well!! :)