PDA

View Full Version : Another plugin question


Dean C
07-15-2005, 10:36 AM
I need to parse the contents of a postbit on the fly, i.e. when a page is rendered server-side. I've had a play with postbit_display_complete but preg_replace('/moo/', 'baa', $this->post['message']); will not replace the only reference of moo with baa in the post :(

Chris M
07-15-2005, 12:44 PM
I've tried several methods and also cannot get it to do so :ermm:

Looks like you'll have to edit class_postbit :(

Satan

Dean C
07-15-2005, 02:21 PM
Hmm strange :(

Paul M
07-15-2005, 04:27 PM
Are you sure the preg_replace is correct ?

If you simply put something like ;

$this->post['message'] .= " # END # ";

Then it works, which suggests the preg_replace is failing to do what you expect.

Dean C
07-15-2005, 06:25 PM
Interesting. Then try using this hook @ postbit_display_complete:


str_replace('moo', 'baa', $this->post['message']);


Obviously make sure your post has "moo" somewhere in it. It won't replace it... yet your example works Paul :)

Marco van Herwaarden
07-15-2005, 07:40 PM
Better try:
$this->post['message'] = str_replace('moo', 'baa', $this->post['message']);

Paul M
07-15-2005, 08:54 PM
Interesting. Then try using this hook @ postbit_display_complete:


str_replace('moo', 'baa', $this->post['message']);


Obviously make sure your post has "moo" somewhere in it. It won't replace it... yet your example works Paul :)Okay, I was trying to diplomatically suggest you may have the syntax wrong.

I would expect it to be ;

$this->post['message'] = preg_replace('/moo/', 'baa', $this->post['message']);
Surely you need to assign the replaced text back to the actual message variable ?

Since my test board has currently disappeared up it's own ar*e I can't prove this atm

Edit: Darn, I see Marco has beaten me to pretty much suggesting the same. :)

Edit 2: It does work. :)

Dean C
07-15-2005, 09:10 PM
I'm having a real bad day it would seem ;) Now i'm having trouble accessing the db object within this class. $GLOBALS['vbulletin']->db seems to be the only way I can access it at the moment, but even that is throwing up some unexpected behaviour with no results turned when I'm 100% positive there are.

Andreas
07-16-2005, 01:12 AM
Almost (?) all vBulletin Classes take a reference of the Registry ($vbulletin) object that can be accessed as $this->registry.

Marco van Herwaarden
07-16-2005, 08:54 AM
Edit: Darn, I see Marco has beaten me to pretty much suggesting the same.
Lol, only by an hour and 15 minutes. :D

Don't worry happens to me a lot of times to. I open a lot of pages at once and read tehm when i have time. Sometimes that is 1 hour later.

Paul M
07-16-2005, 03:40 PM
Lol, only by an hour and 15 minutes. :DI had the reply screen open for ages because I got dragged away on something else (I was at work) :)

Marco van Herwaarden
07-16-2005, 03:46 PM
Happens to me all the time.

Lol sometimes i open a thread in the morning, and i donn't really have time to look into it immediate, so i 'park' it at the beginning of my tab pages for later answering. By the time i leave for home at the end of the day, i still haven't answered, so i close it and forget to ever look at it again.