public function manage_shout($message, $shoutid = 0, $type = 1, $dofetch = true, $userid = 0, $id = 0)
{
global $vbphrase;
// Get rid of junk characters
$message = str_replace("\n", ' ', trim(convert_urlencoded_unicode($message)));
// Do character count checking
if ($this->registry->options['dbtech_vbshout_maxchars'] != 0 AND ($postlength = vbstrlen($message)) > $this->registry->options['dbtech_vbshout_maxchars'])
{
$this->fetched['error'] = construct_phrase($vbphrase['dbtech_vbshout_charlimit'], $postlength, $this->registry->options['dbtech_vbshout_maxchars']);
return false;
}
// Ensure we got BBCode Parser
require_once(DIR . '/includes/functions_misc.php');
require_once(DIR . '/includes/class_bbcode_alt.php');
// Do image count checking
$bbcode_parser = new vB_BbCodeParser_ImgCheck($this->registry, fetch_tag_list());
$bbcode_parser->set_parse_userinfo($this->registry->userinfo);
if ($this->registry->options['dbtech_vbshout_maximages'])
{
$imagecount = fetch_character_count($bbcode_parser->parse($message, 'nonforum', $this->registry->options['dbtech_vbshout_allowsmilies'], true), '<img');
if ($imagecount > $this->registry->options['dbtech_vbshout_maximages'])
{
$this->fetched['error'] = construct_phrase($vbphrase['dbtech_vbshout_imagelimit'], $imagecount, $this->registry->options['dbtech_vbshout_maximages']);
return false;
}
}
if ($this->registry->options['dbtech_vbshout_maxsize'])
{
// Replace the SIZE BBCode if needed
$message = preg_replace("#\[size=(\d+)\]#ie", "\$this->process_bbcode_size('\\1')", $message);
}
// Initiate the shout arguments
$fetch_shout_args = array();
if ($shoutid)
{
if (!$exists = $this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "dbtech_vbshout_shout WHERE shoutid = " . $this->registry->db->sql_prepare($shoutid)))
{
// The shout doesn't exist
//$this->fetched['error'] = $vbphrase['dbtech_vbshout_invalid_shout'];
//return false;
}
else
{
// Type will always be what it used to be
$type = $exists['type'];
$id = $exists['id'];
$userid = $exists['userid'];
if ($exists['userid'] == $this->registry->userinfo['userid'] AND !$this->permissions['caneditown'])
{
// We can't edit our own shouts
$this->fetched['error'] = $vbphrase['dbtech_vbshout_may_not_edit_own'];
return false;
}
if ($exists['userid'] != $this->registry->userinfo['userid'] AND !$this->permissions['caneditothers'])
{
// We don't have permission to edit others' shouts
$this->fetched['error'] = $vbphrase['dbtech_vbshout_may_not_edit_others'];
return false;
}
if ($type != $this->shouttypes['me'] AND $type != $this->shouttypes['notif'])
{
// Checks if we got an action code of some description
list($type, $id, $userid) = $this->parse_action_codes($message, $type, $exists['id'], $exists['userid']);
}
if ($message)
{
// Update the shout
$this->registry->db->query_write("
UPDATE " . TABLE_PREFIX . "dbtech_vbshout_shout
SET
message = " . $this->registry->db->sql_prepare($message) . ",
type = " . $type . ",
userid = " . $userid . ",
id = " . $id . "
WHERE shoutid = " . $this->registry->db->sql_prepare($shoutid)
);
}
($hook = vBulletinHook::fetch_hook('dbtech_vbshout_shout_edit')) ? eval($hook) : false;
// Log this command
$this->log_command('shoutedit', serialize(array('old' => $exists['message'], 'new' => $message)));
// And a winrar is us
$this->fetched['success'] = $vbphrase['dbtech_vbshout_edited_shout_successfully'];
}
}
else
{
if (!$this->permissions['canshout'])
{
// We aren't allowed to post shouts
$this->fetched['error'] = $vbphrase['dbtech_vbshout_may_not_shout'];
return false;
}
if ($type == $this->shouttypes['shout'])
//if ($type != $this->shouttypes['me'] AND $type != $this->shouttypes['notif'])
{
// Checks if we got an action code of some description
list($type, $id, $userid) = $this->parse_action_codes($message, $type, $id, $userid);
}
if ($type == $this->shouttypes['pm'] AND !$id)
{
// We're sending a PM from the advanced pm interface
$id = $this->registry->input->clean_gpc($this->fetchtype, 'userid', TYPE_UINT);
// Check if user exists
if (!$exists = $this->registry->db->query_first_slave("
SELECT userid
FROM " . TABLE_PREFIX . "user
WHERE userid = " . $this->registry->db->sql_prepare($id)
))
{
// We has an error
$this->fetched['error'] = $vbphrase['dbtech_vbshout_invalid_user'];
return false;
}
// We need this local info since we came from a PM tab
//$fetch_shout_args['userids'] = array($this->registry->userinfo['userid'], $id);
$fetch_shout_args['types'] = $this->shouttypes['pm'];
$fetch_shout_args['onlyuser'] = $id;
}
// Just to ensure this hasn't cocked up
$userid = ($userid ? $userid : $this->registry->userinfo['userid']);
$id = ($id ? $id : 0);
if ($this->fetched['error'])
{
// Aaand we're done
return false;
}
if ($message)
{
// Insert shout
$this->registry->db->query_write("
INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
(userid, dateline, message, type, id)
VALUES (
" . $userid . ",
" . TIMENOW . ",
" . $this->registry->db->sql_prepare($message) . ",
" . $this->registry->db->sql_prepare($type) . ",
" . $this->registry->db->sql_prepare($id) . "
)
");
// Get the shout ID
$shoutid = $this->registry->db->insert_id();
($hook = vBulletinHook::fetch_hook('dbtech_vbshout_shout_insert')) ? eval($hook) : false;
if ($userid > 0)
{
// increment shouts count
$this->registry->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET dbtech_vbshout_shouts = dbtech_vbshout_shouts + 1
WHERE userid = $userid
");
}
}
}
if ($type == $this->shouttypes['notif'])
{
// We're done, notifications need no fetching
return;
}
if ($message)
{
// Maybe we need to update AOP
$this->set_aop();
}
if ($dofetch)
{
// We do want to fetch all shouts, though
$this->fetch_shouts($fetch_shout_args);
// Flag for clearance
$this->fetched['clear'] = 'editor';
}
}