MyBB Community Forums

Full Version: Match title with message?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Guys is this the correct way to check if the title is matching message?
Also why it doesn't work with quick reply???

Please help me with this code?

function nosubjectpost(&$post)
{
    global $mybb, $db;

     $msgmessage = $post->data['message'];
	 $msgsubject = $post->data['subject'];

    if($msgsubject == $msgmessage)

    {
        $post->set_error('ERROR - works');
	}
	
	$script = basename($_SERVER["SCRIPT_FILENAME"]);

        if ($script == 'editpost.php' || $script == 'xmlhttp.php') {
        $query = $db->simple_select("threads", "*", "`firstpost`=".intval($_GET['pid'])); 

        $thepost = $db->fetch_array($query);

       if (!empty($thepost)) {
            $firstpost = true;
       }
    }

    if (($script == 'editpost.php' && $firstpost)) {
		        if($msgsubject == $msgmessage)

    {
        $post->set_error('ERROR - works');
	}
	}
	
	 if (($script == 'xmlhttp.php' && $firstpost)) {
       if($msgsubject == $msgmessage) {
           $post->set_error('ERROR - works');
        }
	 }

}
Once again - please stop posting PHP/plugin questions in General Support. Every thread like this will be moved to Plugin Development anyways, so you only waste our time for moderation during which we could answer your thread.

Moved.
Sorry.... Could you help? Everything work except

if (($script == 'xmlhttp.php' && $firstpost))
Which hook(s) do you use? Did you try the post validation? datahandler_post_validate_post

Also I don't understand what do you mean with "it doesn't work with quick reply" while you're trying to check only the first post.
I have a hook to both:

datahandler_post_validate_post
datahandler_post_validate_thread

Oh my bad sorry! I mean it doesn't work when you edit the post with quick edit form? When posting a new thread, editing it either using editpost.php or quick edit forum it suppose to check if the content of the message matches title if so error. But cant get this line to work?

if (($script == 'xmlhttp.php' && $firstpost))

Could you help please?
Anyone please help!
First of all, get rid of that ugly $script thingy. You can already use a constant, THIS_SCRIPT, to check for the in-use script basename.

Quick reply does not use the xmlhttp.php file, it uses newreply.php instead. Also, the code you posted looks way too much complicated and it has a security problem ($_GET['pid'], which is usually written as $mybb->input['pid'] in MyBB, is unescaped into a database query).

// Any post
if ($post->data['message'] == $post->data['subject']) {
    $post->set_error('Any post');
}

// First post editing check
if ($post->method == 'update' and !$post->data['replyto'] and $post->data['message'] == $post->data['subject']) {
    $post->set_error('First post editing');
}
Thank you so much. Your code looks very clean. +1 However doesn't work with editing first post through quick edit!!!

Any idea how to make it work check if this is a first post and xmlhttp.php


Finally nailed it:

$subject = $mybb->input['subject'];
$message = $mybb->input['message'];