MyBB Community Forums

Full Version: Need PHP expert help?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Please help me to make this code check:

If duplicated post had been made by the same user and within last hour?

function validator(&$post)
{
    global $mybb, $db;
	
$query = $db->simple_select("posts", "message", "message LIKE '%{$db->escape_string($mybb->input['message'])}%'");
				$duplicatepost = $db->fetch_field($query, "message");

				if ($duplicatepost)
				{
					$post->set_error("some error");
				}

}

Maybe something like this:

if ($post['dateline'] =< 3600) && ($post['uid'] == $mybb->$user['uid']){
	//check
}

$query = $db->simple_select('posts', 'tid', "pid = '{$post['tid']}'");
$post['tid'] == $post['uid']
$post['dateline'] =< 3600 would need to be $post['dateline'] =< TIME_NOW - 3600 as the original would only return true if the timestamp was before or equal to 3600 seconds after 1st Jan 1970. Wink
Thanks very much so do you think this will work?

function validator(&$post)
{
    global $mybb, $db;
    
$query = $db->simple_select("posts", "message", "message LIKE '%{$db->escape_string($mybb->input['message'])}%'");
                $duplicatepost = $db->fetch_field($query, "message");

                if ($duplicatepost)
                {
                if ($post['dateline'] =< TIME_NOW - 3600 && $post['uid'] == $mybb->$user['uid']){
                    $post->set_error("some error");
                }

}
}
Marcus - this forum is for general support of the MyBB software, not how to code php. Please post in the appropriate forum http://community.mybb.com/forum-68.html

moving.
Please help me I know you can?
It is really ugly how you're doing the query. I strongly dislike changing a variable when the query itself is executing. You also can eliminate much of the PHP code by changing the WHERE clause.

What I'd do is
$escapedmessage = $db->escape_string($mybb->input['message']);
$cutoff = TIME_NOW - 3600;
$query = $db->simple_select("posts", "message", "message LIKE '%" . $escapedmessage . "%' AND uid=" . $mybb->user['uid'] . " AND dateline>" . $cutoff);
 if ($db->num_rows($query)) {
                    $post->set_error("some error");
                }
Wow you are awesome thanks very much my man +1
Could you please help me to make this code not to check anything if user is updating or editing the post?

if($mybb->input['update'])
{
//This is not working!
}
I'm not too sure on how it handles Quick Edit.
No problem I have found the way around it. Listen do you think this puts too much load on the server? Let say I have thousands of users posting this could really overstress the server or what do you think?
Pages: 1 2