PDA

View Full Version : Replace bbcode on the post?


luxinterior
08-25-2012, 05:37 AM
Hi

LATEST PROBLEM

I was able to replace the code between my custom tags using...


$text = preg_replace("/\[flow-rtmp\](.*)\[\/flow-rtmp\]/Usi", $replacement, $text);


but now the problem is if I assign the return to $text the html object I have created shows as text on the page but if I assign it to $parsedtext the object displays correctly but all the other text in the post is not parsed and all the formatting is removed.

Any suggestion?

Lux

I need to replace a custom bbcode on the page NOT in the custom bb page. The code I'm putting in will be re-generated every time the page is loaded with different return values each time.

I've started writing a simple plugin that will replace the custom bbcode but the problem I'm having is how to identify the tag by name, extract it's param and then replace it with new code.

If anybody has an example of doing something like this it would be great. I've bee looking at loads of articles and other plugins for hours but no luck. All the code I've found so far relates to changing the bbcode when users are posting and not when the post is displayed which is what i'm trying to do.

Thanks

Lux

--------------- Added 1345885381 at 1345885381 ---------------

I came up with a solution in the end but I'm sure it's not the most elegant way of doing it. If anybody does have the correct solution please let me know.

I ended up doing this to find the tag and extract the param/text


foreach($this->tag_list as $tag_item => $tag){
if($tag['flow-rtmp']){
preg_match('/\[flow-rtmp\](.*?)\[\/flow-rtmp\]/i',$text,$match);
if($match){


and then assigned a value to $parsedtext to change the value.

Like I said it's not the best solution but it's all I could come up with. Hopefully somebody has a more elegant/correct solution.

Thanks

Lux

--------------- Added 1345945424 at 1345945424 ---------------

Well while my solution seemed to have worked I noticed some problem with it.

The code replaces ALL the text in the post and not just the text in between the custom bbcode which is not really what I want.

I'll continue trying to find a solution but if anybody can shed some light on this I'd appreciate it.

Thanks

Lux

nhawk
08-26-2012, 11:07 AM
Take a look at my BB Code Hider...

https://vborg.vbsupport.ru/showthread.php?t=266744&highlight=hider

Your main concern will be with the bbcode_parse_start hook. Also pay attention to the uninstall code for the mod.

luxinterior
08-27-2012, 09:33 PM
Hi nhawk - Thanks for the tip. I looked at the code but couldn't see any way to make the object html show as html rather than text on the page.

I'd figured out how to find my custom bb tag but the latest problem I have is that assigning the new text to $parsedtext means I lose all the formatting and the normal bbtags are just written to the page. If I assign it to $text then the object html shows as text on the page rather than showing the player as it should do.

Any suggestions?

Thanks

Lux

SOLUTION

This is a bit of a hack but it works. I went ahead and used the $parsetext and then parsed it myself using pregreplace for the bbcode.


$search = array(
'@\[(?i)b\](.*?)\[/(?i)b\]@si',
'@\[(?i)i\](.*?)\[/(?i)i\]@si',
'@\[(?i)u\](.*?)\[/(?i)u\]@si',
'@\[(?i)img\](.*?)\[/(?i)img\]@si',
'@\[(?i)url=(.*?)\](.*?)\[/(?i)url\]@si',
'@\[(?i)code\](.*?)\[/(?i)code\]@si'
);
$replace = array(
'<b>\\1</b>',
'<i>\\1</i>',
'<u>\\1</u>',
'<img src="\\1">',
'<a href="\\1">\\2</a>',
'<code>\\1</code>'
);


$parsedtext = nl2br(preg_replace($search, $replace, $parsedtext));



Hope that saves somebody else some time. If anybody has a 'cleaner' solution please let me know.

Thanks

Lux