Recent Topics

1 Aug 30, 2007 14:05    

My b2evolution Version: 1.10.x

Hi all,

Sorry but I have to confess I find it very difficult to get into the code of b2. I'm not that familiar with OO code, so please bear with my incompetency here.

This is the trick : I'm patching the send_mail() function and the _comment.class.php file in order to receive nicely formatted HTML e-mails when comments are submitted.That is not quite difficult and I'm almost done.

However, I'd like smilies to be rendered in the comment text. I know it's more difficult than just calling some function like render_smilies ( $comment_text ); so I tried to dig into the smilies plugin. I'm sorry, I'm completely lost in this architecture.

Could anyone tell me (hopefully concisely) how I can render smilies in a designated comment contents (namely, $this->get('content') in the 'Comment' class)...

Thanks !

2 Aug 30, 2007 14:42

The plugin has certain points where to act. In the smilies that's RenderItemAsHtml. It does it's work when it's outputted to the screen. This particular moment is called a hook. Try to read it in plain English: when the post (text) is about to be displayed, there's the moment it's hook calls the plugin at RenderItemAsHtml.

For your email, this stage never occurs, so the plugin isn't called. You want another hook. If you find the correct hook, you can copy/paste the code from RenderItemAsHtml because that code does what you want.

Here: http://doc.b2evolution.net/v-1-10/plugins/Plugin.html is a list with all the methods of the Plugin class. Choose one that's called at the right moment (probably RenderItemAsXml or so but I have no idea when the text of the post is guided to the send_mail() function and what you have done with it before that.)

For good understanding, you want another hook into the smilies plugin, not in the code you are working on.

Good luck

3 Aug 30, 2007 15:38

Errr... nope, sorry, i'm lost here... |-|

I can totally see that RenderItemAsHtml() is the method I want to invoke. However, I can absolutely not simply copy / paste its contents. First because if there's a plugin, I'll use the plugin API and not duplicate things up. Second because it's not as simple as that and there are things in there that belong to the smilies_plugin object and that won't be useable elsewhere.

So again, more clearly I hope : does anybody have a good enough knowledge of the smilies plugin architecture (and of the b2evo object arch ingeneral) and could he (or she) tell me clearly how I can invoke the RenderItemAsHtml() method in order to render smilies in a string ?

Alt : Can I hack the Comment object so that it sports a RenderItemAsHtml() method ?

No, the real question is : how the heck does the comment content get translated when rendered on page ? I just need to do that...

Thanks and sorry to be such a n00b...

4 Aug 30, 2007 15:52

OK. It was easier than I thought.

Open _comment.class.php
Find this piece of code :

			$notify_message .=
				T_('Comment').': '.str_replace('&', '&', $this->get_permanent_url( 'pid' ))."\n" // We use pid to get a short URL and avoid it to wrap on a new line in the mail which may prevent people from clicking
				.$this->get('content')."\n\n"
				.T_('Edit/Delete').': '.$admin_url.'?ctrl=browse&tab=posts&blog='.$this->Item->blog_ID.'&p='.$this->Item->ID.'&c=1#c'.$this->ID."\n\n"
				.T_('Edit your subscriptions/notifications').': '.str_replace('&', '&', url_add_param( $Blog->get( 'blogurl' ), 'disp=subs' ) )."\n";


and replace this

.$this->get('content')."\n\n"


with this

.$this->get_content()."\n\n"


Simple explanation (n00b version, of course) : get() is a generic method to access different informations about the current Comment. get_content() is more specific and gets AND parses the contents, allowing plugins to work.

Thanks anyway ;)

5 Aug 30, 2007 15:57

If it works, then it's a good solution. :p
If you still want to go OO you should try something like this in the smilies plugin:

function RenderItemAsText( & $params )
	{
		$this->RenderItemAsHtml( $params );
	}


where you need the right hook if RenderItemAsText doesn't work properlly.

Well done anyway.


Form is loading...