2013-01-20, 11:08 PM
I've been working on improving the Mention plugin, and markwesley noticed that the PM was sending when the page was refreshed. I've tried all sorts of checks, my latest is:
(Key point being the var $hasbeensent).
I tried checking syntax (this apparently has a missing ")" in PHP 4, near the preg_replace_callback), having $hasbeensent in and out of the message function, calling it $pmstatus, having it evaluate to a string, to 1 or 0, even initially assigning it to the string "potato". In this one, the page doesn't even die!
Can someone help?
<?php
if(!defined("IN_MYBB")){
die("Forbidden!");
}
function Mention_info()
{
return array(
'name' => 'Mention',
'description' => 'Mention users in Twitterstyle @username',
'website' => 'http://mods.mybboard.net/',
'version' => '1.0',
'author' => 'SuperNovaAO',
'authorsite' => 'http://www.itshax.com/',
'guid' => '6fc1d048c9ad14a38e7510c598f7dbe1',
'compatibility' => '16*',
);
}
$plugins->add_hook("parse_message_end", "Mention_run");
function Mention_Link($pid, $tid=0)
{
//get_post_link was htmlspecialchars_uni'ing the result, which we DON'T want.
if($tid > 0)
{
$link = str_replace("{tid}", $tid, THREAD_URL_POST);
$link = str_replace("{pid}", $pid, $link);
return $link;
}
else
{
$link = str_replace("{pid}", $pid, POST_URL);
return $link;
}
}
function Mention_activate() {}
function Mention_deactivate() {}
//checking if pm was sent. markwesley noticed the PM was always sending, so I have to check this!
$hasbeensent = true;
function Mention_Message($to)
{
global $thread, $post, $mybb, $hasbeensent;
require_once(MYBB_ROOT . "inc/datahandlers/pm.php");
$pmhandler = new PMDataHandler();
$pmhandler->admin_override = true;
$postlink = Mention_Link($post['pid'], $thread['tid']);
$pm = array(
"subject" => "You were tagged!",
"message" => "{$post['username']} tagged you in [url={$mybb->settings['bburl']}/{$postlink}#pid{$post['pid']}]a post[/url].",
"icon" => "-1",
"toid" => array(),
"fromid" => 0,
"do" => "",
"pmid" => ""
);
$pm["options"] = array(
"signature" => "0",
"disablesmilies" => "0",
"savecopy" => "0",
"readreceipt" => "0"
);
if(!is_array($to))
{
array_push($pm["toid"], $to);
}
else
{
foreach($to as $uid)
{
array_push($pm["toid"], $uid);
}
}
$pmhandler->set_data($pm);
if($pmhandler->validate_pm())
{
$pmhandler->insert_pm();
$hasbeensent = true;
return true;
}
else
{
$hasbeensent = false;
return false;
}
}
function Mention_run($message) {
return preg_replace_callback('/@([^<]+?)@|@([^\s<)]+)/', "Mention__filter", $message);
}
$namecache = array();
function Mention__filter(array $match) {
global $db, $namecache, $hasbeensent;
$origName = $match[0];
array_shift($match);
while (strlen(trim($match[0])) == 0)
array_shift($match);
$usernameLower = my_strtolower(html_entity_decode($match[0]));
if (isset($namecache[$usernameLower])) {
return $namecache[$usernameLower];
} else {
$query = $db->simple_select("users", "uid, username, usergroup, displaygroup", "LOWER(username)='".$db->escape_string($usernameLower)."'", array('limit' => 1));
if($db->num_rows($query) === 1) {
$user = $db->fetch_array($query);
} else {
return $origName;
}
$username = htmlspecialchars_uni($user['username']);
$usergroup = $user['usergroup'];
$displaygroup = $user['displaygroup'];
$username = format_name($username, $usergroup, $displaygroup);
$link = get_profile_link($user['uid']);
if($hasbeensent == false)
{
Mention_Message($user['uid']);
}
else
{
die();
}
return $namecache[$usernameLower] = "@<a href=\"{$link}\">{$username}</a>";
}
}
?>
(Key point being the var $hasbeensent).
I tried checking syntax (this apparently has a missing ")" in PHP 4, near the preg_replace_callback), having $hasbeensent in and out of the message function, calling it $pmstatus, having it evaluate to a string, to 1 or 0, even initially assigning it to the string "potato". In this one, the page doesn't even die!
Can someone help?