View Full Version : How do I stop parsing of BB code?
Right now on my current version I hacked it so function handle_bbcode_img($bbcode, $dobbimagecode) does not work unless you are a certain user group, to stop trolls.
Now with 3.5 this is gone. I can't update until I find where this code is now.
What file is the parsing of the IMG tag in now???????
akanevsky
12-17-2005, 08:22 PM
class_bbcode
You should be able to use a plugin to achieve what you want.
How would I use a plugin to do that? I'm not very technical.
I looked throughout class_bbcode and I can't see a clear cut function that does it. Can someone point me to which function in that file handles the parsing of the IMG tag or explain how to setup a plugin to do what I need.
akanevsky
12-18-2005, 12:56 AM
File class_bbcode.php, around line 1714:
/**
* Handles an [img] tag.
*
* @param string The text to search for an image in.
* @param string Whether to parse matching images into pictures or just links.
*
* @return string HTML representation of the tag.
*/
function handle_bbcode_img($bbcode, $do_imgcode, $has_img_code = false)
Wait. Thats not the best method. (modifying code when you dont have to is baaad :))
plugin bbcode_parse_start,
if(is_member_of($this->registry->userinfo, X)) {
$dobbimagecode = true;
}
else
{
$dobbimagecode = false;
}
akanevsky
12-18-2005, 01:24 AM
I didn't say that it's a best method. I just pointed at a location. As for your method, which is definitely better, the most error-proof solution would be simply:
if(!(is_member_of($this->registry->userinfo, X) OR is_member_of($this->registry->userinfo, Y)))
{
$dobbimagecode = false;
}
Whereas the "true" assignment in your code might cause unexpected behavior in some cases when imgcode should not be parsed.
The easiest to use modify code would be:
$usergroupids_no_img = 'X,Y,Z';
$usergroupids_no_img = explode(',', $usergroupids_no_img);
foreach ($usergroupids_no_img as $usergroupid)
{
if(!is_member_of($this->registry->userinfo, $usergroupid))
{
$dobbimagecode = false;
break;
}
}
The reason there is a break statement is to stop checking for usergroups once a restricted one has been found - in other words, for optimization.
;)
It is unnecessary to use multiple is_member_of calls. You can pass an array of usergroupids.
akanevsky
12-18-2005, 01:29 AM
Really? I didn't know. Thanks for pointing that out :) It's not really an "array", though. Rather an expanded list of parameters.
if(!is_member_of($this->registry->userinfo, X, Y, Z))
{
$dobbimagecode = false;
}
Really? I didn't know. Thanks for pointing that out :) It's not really an "array", though. Rather an expanded list of parameters.
if(!is_member_of($this->registry->userinfo, X, Y, Z))
{
$dobbimagecode = false;
}
Actually, it will accept an array as well.
So I am lost guys with these plugins. What should the hook location of this plugin be?
Will this not parse images unless they are usergroup X Y Z? Does this code work for sure?
if(!is_member_of($this->registry->userinfo, X, Y, Z))
{
$dobbimagecode = false;
}
The code Psionic posted assumes you've set your forums up to always allow bbcode and you only want to disable it for users that are in a specific usergroup. IIRC your requirement was the other way around.
The foreach loop is also useless since it is unnecessary to use a foreach loop (one already exists in is_member_of).
The best way, is to either use the code i posted (which will disable all img codes for everyone except special users in a specific usergroup - regardless of the settings of the forum)
if(is_member_of($this->registry->userinfo, X)) {
$dobbimagecode = true;
}
else
{
$dobbimagecode = false;
}
, or set all forums to disallow images and use (where x y and z are special usergroups, just remove them if you only want one)
if(!is_member_of($this->registry->userinfo, X, Y, Z))
{
$dobbimagecode = true;
}
All code we're talking about belongs to the plugin bbcode_parse_start.
That doesn't do what I wanted.
Let me try to clarify myself better.
The problem I have are users signing up and then posting pornography. So I set it up so you get promoted after 30 days and 50 posts.
What I need is a plugin that does not allow the parsing of a certain user group's IMG tags site and user group wide.
So if user group 1 posts an IMG tag, it won't parse for any user group, it will just show up as a link.
Make sense?
My mistake.
if(is_member_of($this->registry->userinfo, X)) {
$dobbimagecode = false;
}
Replace X with the usergroup you wish to "stop it from happening".
That doesn't work either. That just doesn't parse the IMG tag for whatever usergroup I put in there but all the other user groups the IMG tag parses for which I don't want.
I need a check that per post does this for all user groups:
Is this poster part of the user group listed as not able to use IMG tags? If so then do not allow their IMG tags to be parsed for ANY user group.
Right now if a user signs up they can post porn which they can't see but everyone else can.
Ah.
Gotta look for more hooks, will get back to you :)
Thanks for all the help Merk I really do appreciate it!
For the life of my I cant work out how to do it without hacking code. I hate hacking code :ninja:
Hrm. Damnit. Cant find a way in without hacking. Oh well, best way I can think of:
Inside class_postbit.php, replace function parse_bbcode() with
function parse_bbcode()
{
if(is_member_of($this->post, X)
{
$this->post['message'] = $this->bbcode_parser->parse($this->post['pagetext'], $this->forum['forumid'], $this->post['allowsmilie'], true);
}
else
{
$this->post['message'] = $this->bbcode_parser->parse($this->post['pagetext'], $this->forum['forumid'], $this->post['allowsmilie']);
}
}
And add to bbcode_parse_start hook
if($isimgcheck)
{
$dobbimagecode = false;
$isimgcheck = false;
}
I hijacked a parameter that wasnt being used. This may break in future versions.
My mistake.
if(is_member_of($this->registry->userinfo, X)) {
$dobbimagecode = false;
}
Replace X with the usergroup you wish to "stop it from happening".
That didn't work. Some bug in your code because it gave a PHP error screen.
Parse error: parse error in /home/httpd/vhosts/jeepforum.com/httpdocs/forum/includes/class_postbit.php on line 799
Fatal error: Cannot instantiate non-existent class: vb_bbcodeparser in /home/httpd/vhosts/jeepforum.com/httpdocs/forum/showthread.php on line 982
Can you paste the code around 799 in class_postbit.php?
Nm, parse_bbcode() has a typo.
function parse_bbcode()
{
if(is_member_of($this->post, X))
{
$this->post['message'] = $this->bbcode_parser->parse($this->post['pagetext'], $this->forum['forumid'], $this->post['allowsmilie'], true);
}
else
{
$this->post['message'] = $this->bbcode_parser->parse($this->post['pagetext'], $this->forum['forumid'], $this->post['allowsmilie']);
}
}
Nope:
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /home/httpd/vhosts/jeepforum.com/httpdocs/forum/includes/class_postbit.php on line 812
Fatal error: Cannot instantiate non-existent class: vb_bbcodeparser in /home/httpd/vhosts/jeepforum.com/httpdocs/forum/showthread.php on line 982
I am replacing the first parse_bbcode:
function parse_bbcode()
{
$this->post['message'] = $this->bbcode_parser->parse($this->post['pagetext'], $this->forum['forumid'], $this->post['allowsmilie']);
}
.... There is also ....
function parse_bbcode()
{
$this->bbcode_parser->attachments =& $this->post['attachments'];
$this->bbcode_parser->unsetattach = true;
$this->post['message'] = $this->bbcode_parser->parse(
$this->post['pagetext'],
$this->forum['forumid'],
$this->post['allowsmilie'],
false,
$this->post['pagetext_html'],
$this->post['hasimages'],
$this->cachable
);
$this->post_cache =& $this->bbcode_parser->cached;
}
Andreas
12-24-2005, 01:08 AM
Really? I didn't know. Thanks for pointing that out :) It's not really an "array", though. Rather an expanded list of parameters.
You can pass a scalar value (the usergroupid), and array (containing the usergroupids) - or each usergroupid as a single parameter.
Did you replace it with the code i pasted with the fixed typo?
Interesting, you were replacing the entire function as well?
The second function belongs to a seperate class, so dont worry about that one.
Can you paste what you've done with 3 or 4 lines either side?
Yes I copied and pasted your function over parse_bbcode() the orginal. That error comes out when viewing a thread.
Have you tested the code?
No, but the error you are getting indicates a typo/error in pasting :\
You're running PHP5?
PHP 4.3
I am guessing that code just doesn't work for some reason if you haven't tested it.
Are you sure if(is_member_of($this->post, X)) works in a PHP file? That variable works in plugins but in PHP files?
Its available everywhere. Ill look into it furthur after the xmas stuff is over :)
Anyone see why it's erroring out?
File class_bbcode.php, around line 1714:
/**
* Handles an [img] tag.
*
* @param string The text to search for an image in.
* @param string Whether to parse matching images into pictures or just links.
*
* @return string HTML representation of the tag.
*/
function handle_bbcode_img($bbcode, $do_imgcode, $has_img_code = false)
What tag can I put in this function and where to stop parsing of IMG tags if the poster is a user group id 1?
I tried just displaying the user group id but couldn't even find the tag to do that would work.
Dr00pY
11-11-2006, 09:12 AM
Did anyone ever figure out a way to do this??? I tried creating a plugin that does this, but it seems that a member has figure out a way around it. Was trying to avoid doing a code hack, but it might be the only solution....
My plugin used the following hooks:
editpost_update_start
newreply_post_start
newthread_post_start
all 3 places have the following code in them:
if (!in_array($vbulletin->userinfo['usergroupid'], array(x,y,z)))
{
//we need to remove the tags....
$vbulletin->GPC['message'] = str_ireplace("[img]","",$vbulletin->GPC['message']);
$vbulletin->GPC['message'] = str_ireplace("","",$vbulletin->GPC['message']);
}
Does anyone know what other place I might need to put this code in or see any errors in my code? I figure if we can catch the issue before the post is saved, this will prevent images from being posted.
Thanks for the help....
Dr00pY
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.