MyBB Community Forums

Full Version: How to post additional information when a user makes a reply?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm working on the plugin part of GoMobile, and I can't get this hook stuff down pat. A feature requested is to show an icon beside a post when it's sent from a mobile device.

My idea of executing this was to include a hidden field with a value of 1 on the mobile theme, so that when a user makes a post I can pull either a 0 or a 1 and display an image accordingly.

Now, my problem is I have absolutely no idea what the heck I'm doing when it comes to hooking in and whatnot. I've looked through the Wiki a bit here and there but it doesn't seem to clearly outline exactly how one would go about inserting additional code. I would assume that when hooking into 'newreply_do_newreply_start', for example, the code I place into my plugin would simply get filled in there.

Here is what I would assume will work (not the final revision by any means, this was/is for testing purposes):
function gomobile_posts()
{
    global $post, $mybb;
    
    $is_mobile = 1;

    // Hopefully this will post to the processor correctly
    $post['mobile'] = $is_mobile;
}

gomobile_posts() hooks into the hook I mentioned above. I would think that I would define $post['mobile'] with a value of 1, and it would post that data to the database but that isn't so. I have the column set up, and the rest of the code is correct as far as I know.

Can someone at least point me in the right direction? Thanks. I'm new to this so go easy pl0x Blush
Never mind, this isn't the function I need to use :|
Heres how I would do it:

Hook to datahandler_post_insert_post instead of newreply hook instead, since it occurs just
before the post data is inserted in to the database

As for your function, this is waht I would do:
function gomobile_posts($post)
{
    global $mybb;
    
    $is_mobile = intval($mybb->input['is_mobile'];

    $post['mobile'] = $is_mobile;

    return $post;
}

The above is assuming your hidden input in the form is called is_mobile.

I haven't tested the above but it should work, let me know how it goes.
Returns the following error: Fatal error: Cannot use object of type PostDataHandler as array in C:\xampp\htdocs\mybb_16\inc\plugins\gomobile.php on line 192

I'm stumped :/ Thanks for your input so far though!
Sorry, try this:
function gomobile_posts($p)
{
    global $mybb;
    
    $is_mobile = intval($mybb->input['is_mobile'];

    $p['mobile'] = $is_mobile;

    return $p;
} 
Same thing still..
OK had to test this to make sure it works:

function gomobile_posts($p)
{
    global $mybb;
    
    $is_mobile = intval($mybb->input['is_mobile']);

    $p->post_insert_data['mobile'] = $is_mobile;

    return $p;
} 
Big Grin

Thanks so much!!
Make sure you use &$p in the argument. Just to make sure you're not making a copy of the variable
Do I place that in between the brackets or everywhere? As mentioned above I've got very little experience with PHP Blush