vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Trying to disable color tags for some users (https://vborg.vbsupport.ru/showthread.php?t=264763)

NovoCiv 06-05-2011 08:09 PM

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).

kh99 06-05-2011 11:30 PM

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).

NovoCiv 06-06-2011 12:21 AM

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

A new style is not a viable option.

kh99 06-06-2011 12:46 AM

OK, how about this:

Code:

if ($vbulletin->userinfo['field5'] == "Yes")
    $post['message'] = preg_replace('#<font color=".*?">(.*?)</font>#si', '\1', $post['message']);


NovoCiv 06-06-2011 01:04 AM

Hey that worked great! Thanks!

kh99 06-06-2011 01:24 AM

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.

NovoCiv 06-06-2011 03:08 AM

Quote:

Originally Posted by kh99 (Post 2204102)
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.


All times are GMT. The time now is 05:36 PM.

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.01493 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete