Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2012, 05:37 AM
luxinterior's Avatar
luxinterior luxinterior is offline
 
Join Date: Mar 2005
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Replace bbcode on the post?

Hi

LATEST PROBLEM

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

Code:
$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 [DATE]1345885381[/DATE] at [TIME]1345885381[/TIME] ---------------

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

Code:
	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 [DATE]1345945424[/DATE] at [TIME]1345945424[/TIME] ---------------

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
Reply With Quote
  #2  
Old 08-26-2012, 11:07 AM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Take a look at my BB Code Hider...

https://vborg.vbsupport.ru/showthrea...ighlight=hider

Your main concern will be with the bbcode_parse_start hook. Also pay attention to the uninstall code for the mod.
Reply With Quote
  #3  
Old 08-27-2012, 09:33 PM
luxinterior's Avatar
luxinterior luxinterior is offline
 
Join Date: Mar 2005
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

Code:
$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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:06 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03299 seconds
  • Memory Usage 2,180KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete