MyBB Community Forums

Full Version: Placing ads in the Postbit Content
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2013-08-01, 10:11 AM)Cedric Wrote: [ -> ]May be you should use:


// Set up the message parser if it doesn't already exist.
if(!$parser)
	{
		require_once MYBB_ROOT."inc/class_parser.php";
		$parser = new postParser;
	}

// Set up Parser Options

$parser_options['allow_html'] = $forum['allowhtml'];
$parser_options['allow_mycode'] = $forum['allowmycode'];
$parser_options['allow_smilies'] = $forum['allowsmilies'];			$parser_options['allow_imgcode'] = $forum['allowimgcode'];
$parser_options['allow_videocode'] = $forum['allowvideocode'];
$parser_options['filter_badwords'] = 1;

$post['message'] = $parser->parse_message($post['message'], $parser_options);

Smile

Thanks, will try and let you know.

(2013-08-01, 10:20 AM)ksr Wrote: [ -> ]
(2013-08-01, 10:11 AM)Cedric Wrote: [ -> ]May be you should use:


// Set up the message parser if it doesn't already exist.
if(!$parser)
	{
		require_once MYBB_ROOT."inc/class_parser.php";
		$parser = new postParser;
	}

// Set up Parser Options

$parser_options['allow_html'] = $forum['allowhtml'];
$parser_options['allow_mycode'] = $forum['allowmycode'];
$parser_options['allow_smilies'] = $forum['allowsmilies'];			$parser_options['allow_imgcode'] = $forum['allowimgcode'];
$parser_options['allow_videocode'] = $forum['allowvideocode'];
$parser_options['filter_badwords'] = 1;

$post['message'] = $parser->parse_message($post['message'], $parser_options);

Smile

Thanks, will try and let you know.

Didn't work bro, still the same. But the new lines characters are working, previously the new lines between the content weren't showing which suppose to show.
$myad = ""; // your ad here
$plugins->add_hook("postbit", "ads_replace");
function ads_replace($post) {	
	$_post = $post; // the hook isn't by reference, we can't modify the array directly
	$find = "Job Description";
	if($_post['replyto'] == 0)
		str_ireplace($find, $myad.$find, $_post['message']); // add the ad
	return $_post;
}

The postbit hook is placed after the parser's effects, so the $post['message'] should be already converted.

This is somewhat wacky though. str_ireplace() doesn't detect eventual HTML tags, so your ad will be placed inside the <b> of "Job Description". There are either two ways to place it outside certain HTML tags:
  • The string is constant, so you might change $find with "<b>Job Description". Doesn't matter if cases don't match, str_ireplace is case insensitive.
  • You use PHP's XPath extension and you search for nodes, but this will lead into a slight performance lack.
(2013-08-02, 08:06 AM)Shade Wrote: [ -> ]
$myad = ""; // your ad here
$plugins->add_hook("postbit", "ads_replace");
function ads_replace($post) {	
	$_post = $post; // the hook isn't by reference, we can't modify the array directly
	$find = "Job Description";
	str_ireplace($find, $myad.$find, $_post['message']); // add the ad
	return $_post;
}

The postbit hook is placed after the parser's effects, so the $post['message'] should be already converted.

This is somewhat wacky though. str_ireplace() doesn't detect eventual HTML tags, so your ad will be placed inside the <b> of "Job Description". There are either two ways to place it outside certain HTML tags:
  • The string is constant, so you might change $find with "<b>Job Description". Doesn't matter if cases don't match, str_ireplace is case insensitive.
  • You use PHP's XPath extension and you search for nodes, but this will lead into a slight performance lack.

Bro did you tested it and worked for you? In my case its not replacing the the given code and bbcode also not converting to html?
I didn't, I'm too busy. Anyway, this should not affect the parser, so the BBCode->HTML conversion should happen without any errors.

Anyway, I've updated the code to add the ad only in first post.
(2013-08-02, 12:10 PM)Shade Wrote: [ -> ]I didn't, I'm too busy. Anyway, this should not affect the parser, so the BBCode->HTML conversion should happen without any errors.
ok bro, I am stopping here. I have got some other alternative. I am converting the original post content itself to html while posting the thread (I use forms to post jobs). So I have kept html formatting inside my form handler. And this will be applied to new threads in my forum.

(2013-08-02, 12:10 PM)Shade Wrote: [ -> ]Anyway, I've updated the code to add the ad only in first post.

For this I already have the conditions from Yaldram's plugin bro, so I am not worrying about that.

I really thank all the members who spent time here to reply.
This is not the best approach IMHO. You shouldn't insert any extra code before parsing the message, because you won't be able to easily change/delete the code you've added in the future. You should add the code just after the message is parsed: this will let you change advertisements just by changing your PHP code and not editing the database.

That's why the postbit hook is necessary.
(2013-08-02, 01:33 PM)Shade Wrote: [ -> ]This is not the best approach IMHO. You shouldn't insert any extra code before parsing the message, because you won't be able to easily change/delete the code you've added in the future. You should add the code just after the message is parsed: this will let you change advertisements just by changing your PHP code and not editing the database.

That's why the postbit hook is necessary.

I know that. Yes I am not inserting any ad code into my database via thread content while creating the thread.


Here is a detailed approach I have followed:
1) While creating the thread, I am placing two unique html tags in place where I want the ads to display
Here is pic for you: http://s11.postimg.org/sjzh579c3/ads_in_post.png
2) So now, with the plugin I am retrieving the post content and replacing with the ad code at respective unique tags with the post-bit hook
Here is pic for you: http://s12.postimg.org/3t3trg571/ads_in_posts.png
3) And the above ads are for newly created threads, as I don't have the unique tags in old posts, so for that I used template conditionals to omit them.
4) So now, If I want to change or disable the ads, I can just disable the plugin or change the ad code in the plugin .

Thats it.!!! Smile Smile Smile

What do you say for this?
Pages: 1 2