PDA

View Full Version : Replace Word in Post - only HTML!


BRotondi
09-03-2009, 07:21 PM
Hello!

I want to replace e.g. every xxx to yyy - but only in the HTML-Output. This means: If someone posts "We show you xxx." then the browser will show "We show you yyy.", but if he presses "Edit post" the Editor (WYSIWYG and Text) will still give him "We show you xxx."

I tried different things, e.g. a Plug-In for bbcode_parse_complete:
$text = str_replace('xxx', 'yyy', $text);But this will change also the text for the editor.

How can I do this correct?

=> I don't need a plugin! This is a study for a more complex problem: Replace </br>-breaks with <p>-paragraphs which needs much more programming, since every [ code]...[ /code] needs his <p>...</p> etc.

Of course, if there exists allready a br-to-p-solution I'm even happier :).

Thanks for any help!
Bruno

Lynne
09-03-2009, 09:14 PM
I use a str_replace statement on my site that only effects the html output. I use the postbit_display_complete hook location to do it.

BRotondi
09-04-2009, 01:06 AM
This sounds good! Which var do I have to change? $text has no effect... (or how can I find out this myself. Is there any documentation about that?)

Thanks!
Bruno

Lynne
09-04-2009, 01:32 AM
The best way to find out what variables are used in a plugin is to find the plugin in the code and look at how variables are used around it. In this case, you need to use $this->post['message'] to modify the message text.

Dismounted
09-04-2009, 05:08 AM
Also, make sure you use the _complete hook, and not the _start hook. The post is not parsed yet at the latter.

BRotondi
09-04-2009, 05:46 AM
Thanks for your help! This works fine :).

Does this mean, that there exists almost no documentation about hooks, variables etc. and search & ask in this forum is the best way of research?

I'm searching now for the correct hook and variable to do the same when pressing "preview".

Thanks for any help!
Bruno

Dismounted
09-04-2009, 07:03 AM
Does this mean, that there exists almost no documentation about hooks, variables etc. and search & ask in this forum is the best way of research?
There are many articles available here on vBulletin.org which cover some "common" tasks.

BRotondi
09-04-2009, 07:50 AM
Yes, I have seen them and more on vBulletin-german.org. But some Kind of Reference would habe been nice :).

Do you know which hook is executed after parsing the "Preview"?

Bruno
(I'm trying the ones in editpost.php right now...)

Dismounted
09-04-2009, 09:24 AM
Do you know which kook is executed after parsing the "Preview"?
Are you talking about the page you see after clicking "Preview Post" in newreply.php?

BRotondi
09-04-2009, 10:22 AM
Yes... There are multiple hooks there and since I'm also not sure which variable needs the search & replace, trial and error is difficult...

Bruno