<?php
/**
* Shoutbox Plugin for MyBB
* Copyright © 2006 MyBB Mods
*
* By: Musicalmidget
* Website: http://mods.mybboard.com/
* Version: 2.0
*/
define('IN_MYBB', 1);
$templatelist = 'shoutbox,shoutbox_add_shout,shoutbox_error,shoutbox_error_no_shouts,shoutbox_shout,shoutbox_edit_shout,shoutbox_delete_shout,shoutbox_multipage';
require_once './global.php';
require_once MYBB_ROOT.'inc/functions_post.php';
require_once MYBB_ROOT.'inc/class_parser.php';
$parser = new postParser;
function sb_error($message)
{
global $headerinclude, $mybb, $templates, $theme;
eval("\$error = \"".$templates->get('shoutbox_error')."\";");
output_page($error);
exit;
}
switch($mybb->input['action'])
{
case 'do_add':
if($mybb->user['uid'] < 1)
{
if($mybb->settings['sb_guest_shouting'] != 'yes')
{
sb_error($lang->error_guest_shouting);
}
else
{
$mybb->user['username'] = $lang->guest;
}
}
if($mybb->user['usergroup'] != 4 && $mybb->user['usergroup'] != 3)
{
$query = $db->simple_select(TABLE_PREFIX.'shouts', 'COUNT(sid)');
$count = $db->fetch_field($query, 'count');
}
else
{
$count = 0;
}
if($count > $mybb->settings['sb_max_consec_shouts'] - 1)
{
$start = $count - $mybb->settings['sb_max_consec_shouts'];
$flood_check = 0;
$options = array(
'order_by' => 'dateline',
'limit_start' => $start,
'limit' => intval($mybb->settings['sb_max_consec_shouts'])
);
$query = $db->simple_select(TABLE_PREFIX.'shouts', 'sid, uid', '', $options);
while($shout = $db->fetch_array($query))
{
if($shout['uid'] == $mybb->user['uid'])
{
++$flood_check;
}
}
if($flood_check > $mybb->settings['sb_max_consec_shouts'] - 1)
{
sb_error($lang->error_flood);
}
}
if(empty($mybb->input['message']))
{
sb_error($lang->error_shout_empty);
}
if(strlen($mybb->input['message']) > $mybb->settings['sb_max_length'])
{
$lang->error_shout_length = sprintf($lang->error_shout_length, $mybb->settings['sb_max_length']);
sb_error($lang->error_shout_length);
}
$new_shout = array(
'uid' => $mybb->user['uid'],
'username' => $mybb->user['username'],
'message' => $db->escape_string($mybb->input['message']),
'dateline' => time(),
'ipaddress' => get_ip()
);
$db->insert_query(TABLE_PREFIX.'shouts', $new_shout);
redirect('shoutbox.php', $lang->redirect_shout_added);
break;
case 'do_delete':
if($mybb->input['deletesubmit'])
{
if(intval($mybb->input['sid']))
{
$sid = intval($mybb->input['sid']);
}
else
{
sb_error($lang->error_invalid_shout);
}
$where_sql = "WHERE sid='$sid'";
if($mybb->user['usergroup'] != 3 && $mybb->user['usergroup'] != 4)
{
$where_sql .= " AND uid='".$mybb->user['uid']."'";
}
$query = $db->query("DELETE FROM ".TABLE_PREFIX."shouts ".$where_sql);
if(!$query)
{
sb_error($lang->error_perms);
}
redirect('shoutbox.php', $lang->redirect_shout_deleted);
}
break;
case 'do_edit':
if(intval($mybb->input['sid']))
{
$sid = intval($mybb->input['sid']);
}
else
{
sb_error($lang->error_invalid_shout);
}
if(empty($mybb->input['message']))
{
sb_error($lang->error_shout_empty);
}
if(strlen($mybb->input['message']) > $mybb->settings['sb_max_length'])
{
$lang->error_shout_length = sprintf($lang->error_shout_length, $mybb->settings['sb_max_length']);
sb_error($lang->error_shout_length);
}
$updated_shout = array(
'message' => $db->escape_string($mybb->input['message'])
);
$where_sql = "sid='$sid'";
if($mybb->user['usergroup'] != 3 && $mybb->user['usergroup'] != 4)
{
$where_sql .= " AND uid='".$mybb->user['uid']."'";
}
$query = $db->update_query(TABLE_PREFIX.'shouts', $updated_shout, $where_sql);
if(!$query)
{
sb_error($lang->error_perms);
}
redirect('shoutbox.php', $lang->redirect_shout_edited);
break;
case 'edit':
if(intval($mybb->input['sid']))
{
$sid = intval($mybb->input['sid']);
}
else
{
sb_error($lang->error_invalid_shout);
}
$query = $db->simple_select(TABLE_PREFIX.'shouts', 'sid, uid, message', "sid='$sid'");
$shout = $db->fetch_array($query);
if($mybb->user['uid'] == 0 || $shout['uid'] != 0 && ($mybb->user['uid'] != $shout['uid']))
{
if($mybb->user['usergroup'] != 3 && $mybb->user['usergroup'] != 4)
{
sb_error($lang->error_invalid_shout);
}
}
$message = stripslashes($shout['message']);
$message = str_replace('"', '"', $message);
eval("\$edit_shout = \"".$templates->get('shoutbox_edit_shout')."\";");
output_page($edit_shout);
break;
case 'delete':
if(intval($mybb->input['sid']))
{
$sid = intval($mybb->input['sid']);
}
else
{
sb_error($lang->error_invalid_shout);
}
$query = $db->simple_select(TABLE_PREFIX.'shouts', 'sid, uid', "sid='$sid'");
$shout = $db->fetch_array($query);
if($mybb->user['uid'] == 0 || $shout['uid'] != 0 && ($mybb->user['uid'] != $shout['uid']))
{
if($mybb->user['usergroup'] != 3 && $mybb->user['usergroup'] != 4)
{
sb_error($lang->error_invalid_shout);
}
}
eval("\$delete_shout = \"".$templates->get('shoutbox_delete_shout')."\";");
output_page($delete_shout);
break;
default:
// First things first, pagination. Woohoo!
$query = $db->simple_select(TABLE_PREFIX.'shouts', 'COUNT(sid) AS count');
$count = $db->fetch_field($query, 'count');
if(!$count)
{
$multipage = '';
eval("\$shouts = \"".$templates->get('shoutbox_error_no_shouts')."\";");
}
else
{
$perpage = intval($mybb->settings['sb_shouts_per_page']);
$total_pages = ceil($count / $perpage);
if(intval($mybb->input['page']))
{
$page = intval($mybb->input['page']);
}
else
{
$page = 1;
}
if($page == $total_pages)
{
$start = 0;
$limit = $count - (($total_pages - 1) * $perpage);
}
else
{
$limit = $perpage;
if($page == 1)
{
$start = $count - $limit;
}
else
{
$start = $count - ($limit * $page);
}
}
$multipage_links = multipage($count, $perpage, $page, 'shoutbox.php?');
// Start getting shouts!
$query = $db->query("
SELECT s.*, s.username AS shout_username, u.username, u.usergroup, u.displaygroup
FROM ".TABLE_PREFIX."shouts s
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=s.uid)
ORDER BY s.dateline
LIMIT $start, $limit
");
if($total_pages > 1)
{
$bgcolor = alt_trow();
eval("\$multipage_top = \"".$templates->get('shoutbox_multipage')."\";");
}
while($shout = $db->fetch_array($query))
{
$parser_options = array(
'allow_html' => $mybb->settings['sb_allow_html'],
'allow_mycode' => $mybb->settings['sb_allow_mycode'],
'allow_smilies' => $mybb->settings['sb_allow_smilies'],
'allow_imgcode' => $mybb->settings['sb_allow_imgcode'],
'me_username' => $shout['username']
);
// Check for /me and /slap tags in shout and adjust username displying accordingly.
$mecheck = explode(' ', $shout['message']);
if($mecheck[0] == '/me' || $mecheck[0] == '/slap')
{
$shout['username'] = '';
}
else
{
if($shout['uid'] > 0)
{
$shout['username'] = format_name($shout['username'], $shout['usergroup'], $shout['displaygroup']);
$shout['username'] = '<<a href="member.php?action=profile&uid='.intval($shout['uid']).'">'.$shout['username'].'</a>> ';
}
else
{
$shout['username'] = '<'.$lang->guest.'> ';
}
}
$shout['message'] = $parser->parse_message($shout['message'], $parser_options);
// Prepare hover message
$shout['date'] = my_date($mybb->settings['dateformat'], $shout['dateline']);
$shout['time'] = my_date($mybb->settings['timeformat'], $shout['dateline']);
$shout['ip'] = '';
if($mybb->user['usergroup'] == 3 || $mybb->user['usergroup'] == 4)
{
$shout['ip'] = sprintf($lang->shout_hover_ip, $shout['ipaddress']);
}
$title = sprintf($lang->shout_hover, $shout['date'], $shout['time'], $shout['ip']);
// Edit and delete options
$options = '';
if($mybb->user['usergroup'] == 3 || $mybb->user['usergroup'] == 4 || ($mybb->user['uid'] == $shout['uid']) && ($mybb->user['uid'] != 0))
{
$options = ' [ <a href="shoutbox.php?action=edit&sid='.$shout['sid'].'">'.$lang->edit.'</a> ] [ <a href="shoutbox.php?action=delete&sid='.$shout['sid'].'">'.$lang->delete.'</a> ]';
}
$bgcolor = alt_trow();
eval("\$shouts .= \"".$templates->get('shoutbox_shout')."\";");
}
if($total_pages > 1)
{
$bgcolor = alt_trow();
eval("\$multipage_bottom = \"".$templates->get('shoutbox_multipage')."\";");
}
}
if(($mybb->user['uid'] > 0 && $mybb->user['usergroup'] != 5) || $mybb->settings['sb_guest_shouting'] == 'yes')
{
eval("\$add_shout = \"".$templates->get('shoutbox_add_shout')."\";");
}
$refresh = '';
if($mybb->settings['sb_refresh_time'] > 0)
{
$refresh = '<meta http-equiv="refresh" content="'.$mybb->settings['sb_refresh_time'].';URL=shoutbox.php" />';
}
eval("\$shoutbox = \"".$templates->get('shoutbox')."\";");
output_page($shoutbox);
break;
}
?>