// This functions must be the simplest and fastest posible
function Shoutbox_GetMsgs($error = false)
{
global $context, $txt, $scripturl, $shoutbox, $db_prefix, $ID_MEMBER, $modSettings;
// template
$context['sub_template'] = 'Shoutbox_GetMsgs';
if (!isset($_GET['xml']) || !isset($_GET['row']) || !allowedTo('shoutbox_view'))
die();
if (loadLanguage('Shoutbox') == false)
loadLanguage('Shoutbox', 'english');
loadTemplate('Shoutbox');
Shoutbox_Settings();
$context['shoutbox_echo'] = array();
// if user is banned, close Shoutbox
if (Shoutbox_isBanned())
{
$context['shoutbox_echo']['banned'] = true;
return;
}
// can't be empty :|
$_SESSION['shoutbox_lastid'] = empty($_SESSION['shoutbox_lastid']) ? -1 : (int) $_SESSION['shoutbox_lastid'];
// limits !! load a few msgs if refresh time is out or if we want it
if (isset($_GET['restart']) || empty($_SESSION['shoutbox_lastget']) || $_SESSION['shoutbox_lastget'] < time() - $shoutbox['refreshShouts'] + 15 || $_SESSION['shoutbox_lastget'] <= $shoutbox['lastPrune'])
{
// restart ALL
$_SESSION['shoutbox_lastid'] = -1;
$_SESSION['shoutbox_lastget'] = null;
// new msgs first?
if (empty($shoutbox['showmsg_down']))
$limit = 'ORDER BY ID_SHOUT DESC
LIMIT ' . $shoutbox['startShouts'];
else
{
$query_count = db_query("SELECT COUNT(*) FROM {$db_prefix}shoutbox", __FILE__, __LINE__);
list ($limit_start) = mysql_fetch_row($query_count);
mysql_free_result($query_count);
$limit_start = $limit_start - $shoutbox['startShouts'] < 0 ? 0 : $limit_start - $shoutbox['startShouts'];
$limit = 'ORDER BY ID_SHOUT ASC
LIMIT ' . $limit_start . ', ' . $shoutbox['startShouts'];
}
$context['shoutbox_echo']['reset'] = true;
}
else
$limit = 'WHERE ID_SHOUT > ' . $_SESSION['shoutbox_lastid'] . '
ORDER BY ID_SHOUT ' . (empty($shoutbox['showmsg_down']) ? 'DESC' : 'ASC');
$query = db_query("
SELECT ID_MEMBER, realName, colorName, style, message, timestamp
FROM {$db_prefix}shoutbox
$limit", __FILE__, __LINE__);
$_SESSION['shoutbox_lastget'] = time();
// so, no new msgs?
if (empty($error) && mysql_num_rows($query) == 0)
die;
elseif (!empty($error))
{
$context['shoutbox_echo']['error'] = $error;
return;
}
// last id
$query_last = db_query("SELECT MAX(ID_SHOUT) FROM {$db_prefix}shoutbox", __FILE__, __LINE__);
list ($_SESSION['shoutbox_lastid']) = mysql_fetch_row($query_last);
mysql_free_result($query_last);
$disabled = array();
if (isset($shoutbox['disableTags']))
foreach (explode(',', $shoutbox['disableTags']) as $tag)
$disabled[$tag] = 1;
// get msgs ' . ($s['timestamp'] > 0 ? timeformat($s['timestamp'], $shoutbox['timeFormat']) : $txt[470]) . '
$context['shoutbox_echo']['msgs'] = array();
while ($s = mysql_fetch_assoc($query))
{
if ($ID_MEMBER != $s['ID_MEMBER'])
$context['shoutbox_echo']['new_msgs'] = true;
$cmd_me = substr($s['message'], 0, 17) == '
';
$context['shoutbox_echo']['msgs'][] = array(
'poster' => ($cmd_me ? '' : ' ' . $s['realName'] . '') . ' ',
'message' => '' . ($cmd_me ? $s['realName'] . ' ' : '') . (isset($disabled['smileys']) ? censorText($s['message']) : Shoutbox_ParseSmileys(censorText($s['message']))) . '
' . ($s['timestamp'] > 0 ? timeformat($s['timestamp']) : $txt[470]) . '<>',
);
}
mysql_free_result($query);