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 06-05-2011, 08:09 PM
NovoCiv NovoCiv is offline
 
Join Date: Aug 2010
Posts: 80
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Trying to disable color tags for some users

My members have requested the ability to disable color tags just as they can disable images. I created a profile field for this and have been trying to determine the correct hook and code to make this work. The closest I've gotten is:

Code:
if ($vbulletin->userinfo['field5'] == "Yes") {
global $vbphrase, $db;
$post_text = $db->query_first("SELECT pagetext FROM " . TABLE_PREFIX . "post WHERE postid = $post[postid] ORDER BY dateline ASC");
$post_color['pagetext'] = preg_replace('#\[color=sienna\](.*?)\[/color\]#si', '\1', $post_text[pagetext]);
$post_color['pagetext'] = preg_replace('#\[color=black\](.*?)\[/color\]#si', '\1', $post_color[pagetext]);
$post['message'] = nl2br($post_color['pagetext']);
}
While this removes the sienna and black color tags, it leaves the rest of the BBcode unparsed.

I'm looking for a way to just remove the tags without unparsing everything else, and possibly a more efficient way of removing colors (than one at a time).
Reply With Quote
  #2  
Old 06-05-2011, 11:30 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could do this: create a new style and then in a plugin using hook bbcode_fetch_tags:

Code:
global $style;
if ($style['styleid'] == X)
    $tag_list['option']['color']['html'] = '%1$s';

where the X is the new style id. I think this works because posts are cached by style. If you used a profile field instead I don't think it would work because of post caching.

Obviously this isn't a good solution if you already have a number of styles that a user can choose. I'm not sure where you are putting the code in your example, maybe there's another way to do it (like maybe you could replace all <span color="xxx">whatever</span> in the post text).
Reply With Quote
  #3  
Old 06-06-2011, 12:21 AM
NovoCiv NovoCiv is offline
 
Join Date: Aug 2010
Posts: 80
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry forgot to mention this is in a plugin at the postbit_display_complete hook.

A new style is not a viable option.
Reply With Quote
  #4  
Old 06-06-2011, 12:46 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, how about this:

Code:
if ($vbulletin->userinfo['field5'] == "Yes")
    $post['message'] = preg_replace('#<font color=".*?">(.*?)</font>#si', '\1', $post['message']);
Reply With Quote
  #5  
Old 06-06-2011, 01:04 AM
NovoCiv NovoCiv is offline
 
Join Date: Aug 2010
Posts: 80
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey that worked great! Thanks!
Reply With Quote
  #6  
Old 06-06-2011, 01:24 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thinking about it more, it's probably not going to work in all situations since the SIZE and FONT bbcodes also end up as <font> tags, so something like:

This is red and big still red

would probably end up with "still red" being size 5 instead of normal.
Reply With Quote
  #7  
Old 06-06-2011, 03:08 AM
NovoCiv NovoCiv is offline
 
Join Date: Aug 2010
Posts: 80
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Thinking about it more, it's probably not going to work in all situations since the SIZE and FONT bbcodes also end up as <font> tags, so something like:

[COLOR=red]This is red [SIZE=5]and big[/SIZE] still red[/COLOR]

would probably end up with "still red" being size 5 instead of normal.
That's totally worth it unless someone has an easy fix.
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 08:26 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06459 seconds
  • Memory Usage 2,215KB
  • 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)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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