MyBB Community Forums

Full Version: Intercepting a post/thread
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi again fellow folks, this time I'm currently trying to figure out, how I can intercept a post from being made.

The thing I'm currently struggling with is getting the forum id (fid) of the thread, where the post is supposed to be made.

I am maybe a tad too tired whilst currently looking at this, so hopefully a pair of fresh eyes can give me a small hint, since I'm probably just overthinking and overdoing things right now. I am pretty grateful for any and all input, thanks.

Here is a code snip to demonstrate:

<?php

// HOOKS
$plugins->add_hook( 'newreply_start', 'check_spam' );
$plugins->add_hook( 'newthread_start', 'check_spam' );
$plugins->add_hook( 'newreply_do_newreply_start', 'check_spam' );
$plugins->add_hook( 'newthread_do_newthread_start', 'check_spam' );


function check_spam() {
    global $db, $mybb, $thread, $post, $forum;

    // Get all Spam Limits
    $query = $db->query("SELECT * FROM ".TABLE_PREFIX."spamlimit_limit");

    $spamlimit_id = 0;

    while ($row = $db->fetch_array($query)) {
        $fid;

        if ($thread['fid']) {
            $fid = $thread['fid'];
        } elseif ($post['fid']) {
            $fid = $post['fid'];
        } elseif ($forum['fid']) {
            $fid = $forum['fid'];
        }

        $forumArr = explode(',', $row['fids']);

        if (in_array($fid, $forumArr)) {
            ...
        }
    }
   	...
}

I am pretty sure I'm overthinking things, but since I'm using 4 different hooks I wanted to make sure that it would work none the less, and practically as the same. (Not differentiating between threads and posts, both will be intercepted kind of)

And once again, thanks a lot for any help.

(Also not sure which hook to use to intercept quick_reply, any advice? I would think it was inside the newreply_do_newreply_start hook)
Have an eye on datahandler_post_validate_post and datahandler_post_validate_thread hooks.
I use them in ABP Restrict Url, which is an antispam tool.
(2020-04-18, 10:48 PM)Crazycat Wrote: [ -> ]Have an eye on datahandler_post_validate_post and datahandler_post_validate_thread hooks.
I use them in ABP Restrict Url, which is an antispam tool.

Thanks a lot, I should have found those myself... I will use them and the relevant parameters to fix the issue, thanks a lot. 

Heart

Sorry to be asking, cuz' I'm a little confused, by using those hooks, how do you stop the posting of a thread/url? Do you use a redirect? header? or something else?

Thanks a lot for your help. Those two hooks helped med fix up everything neatly.
Just use $datahandler->set_error('your error message') and the posting will be stopped, showing your error message. Or use the $datahandler->set_validate(false) to stop the process and use your own redirection to an error page, or do what you want.
(2020-04-19, 05:00 PM)Crazycat Wrote: [ -> ]Just use $datahandler->set_error('your error message') and the posting will be stopped, showing your error message. Or use the $datahandler->set_validate(false) to stop the process and use your own redirection to an error page, or do what you want.

You are a damn legend. Thanks a lot. Tbh I did try doing a Header( Location: path) but was unsuccessful. Will try using the inherent datahandler functions.