MyBB Community Forums

Full Version: Accessing message (first post content) with postbit hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have below function in a plugin:

$plugins->add_hook("postbit", "insert_in_content");

function insert_in_content(&$post)
{
               global $mybb, $templates;
               $msg = $post['message'];
                $pieces = explode(<delimiter>, $msg);
                $res = $pieces[0]."\n"."Adding some string here"."\n".$pieces[1]; 
                $post['message'] = $res;
                return $post;
} 

I tried to access the thread content with $post['message'] in the above function, but found it is not working.

Can some body let me know, whats is the correct variable here to access message (thread content ie first post content) in above function and also whether this message is my code converted into html at this stage or not?
global $mybb, $templates, $post;
(2013-08-08, 05:47 PM)effone Wrote: [ -> ]global $mybb, $templates, $post;

hmm, I missed that!!!!

Its working with that but when I do above operation written in the function (in first post of this thread), postbit buttons and user postbit details are getting messed up and disappearing!!! What may be reason for this?
global $post should be wrong. If it's passed as parameter to the hook, that's what should be used.

Raise the warning level, and echo something in the function itself (at the start and before the return), maybe something else is going wrong.
(2013-08-08, 07:02 PM)frostschutz Wrote: [ -> ]global $post should be wrong. If it's passed as parameter to the hook, that's what should be used.

Raise the warning level, and echo something in the function itself (at the start and before the return), maybe something else is going wrong.

Yes, thats what I thought and didn't declare $post as global as I already have from the function argument. It didn't show up anything when echoed the $post['message'] if I don't declare it as global.
The hook works fine for me in the Google SEO plugin though (google_seo/meta.php, grabs the message for meta description). If it works for me, it should do for you.
(2013-08-08, 07:16 PM)frostschutz Wrote: [ -> ]The hook works fine for me in the Google SEO plugin though (google_seo/meta.php, grabs the message for meta description). If it works for me, it should do for you.

I have viewed meta.php and will check back in my function. Thanks again.

(2013-08-08, 07:16 PM)frostschutz Wrote: [ -> ]it should do for you.

Yes it is bro. I don't know how it didn't worked previously. I am still playing with that, I will post back in case if I encounter any problems. Thank you.
@frostschutz

That has worked pretty well.

But I have my code parsing problem.

Let me say I have below string in message variable:

$post['message'] = "[b][i]Hello this is a test [/b][i] delme
[color=#f0f0f0]And this is the thread description here[/color]";

Suppose if I do this:

                $msg = $post['message'];
                $pieces = explode("delme", $msg);
                $res = $pieces[0]."\n"."<b>Adding some string here</b>"."\n".$pieces[1]; 
                $post['message'] = $res;
                return $post;

This is the output I am getting at thread display:
[b][i]Hello this is a test [/b][i] Adding some string here[/php] [color=#f0f0f0]And this is the thread description here[/color]

In the above its showing the string Adding some string here only in bold text (as I have given directly the html tags) and the remaining all content is showing without any my code conversion (For all bb codes). As I have mentioned here on my earlier post. And then I have tried to implement what Cedric told at this post to convert bb code to html, but didn't had success and which is same as I have described above.


Let me know, what I have to do for converting the bbcode to html at the postbit hook.