vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How do I stop parsing of BB code? (https://vborg.vbsupport.ru/showthread.php?t=103152)

kau 12-17-2005 06:23 PM

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

merk 12-17-2005 09:46 PM

You should be able to use a plugin to achieve what you want.

kau 12-18-2005 12:22 AM

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:

PHP Code:

    /**
    * 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


kau 12-18-2005 01:16 AM

Great! Thanks very much.

merk 12-18-2005 01:21 AM

Wait. Thats not the best method. (modifying code when you dont have to is baaad :))

plugin bbcode_parse_start,

PHP Code:

if(is_member_of($this->registry->userinfoX)) { 
$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:

PHP Code:

if(!(is_member_of($this->registry->userinfoX) OR is_member_of($this->registry->userinfoY)))
{
    
$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:

PHP Code:

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

;)

merk 12-18-2005 01:27 AM

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.

Code:

if(!is_member_of($this->registry->userinfo, X, Y, Z))
{
    $dobbimagecode = false;
}


merk 12-18-2005 04:32 AM

Quote:

Originally Posted by Psionic Vision
Really? I didn't know. Thanks for pointing that out :) It's not really an "array", though. Rather an expanded list of parameters.

Code:

if(!is_member_of($this->registry->userinfo, X, Y, Z))
{
$dobbimagecode = false;
}


Actually, it will accept an array as well.

kau 12-20-2005 04:31 PM

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;
}

merk 12-20-2005 08:48 PM

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)

PHP Code:

if(is_member_of($this->registry->userinfoX)) { 
$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)

PHP Code:

if(!is_member_of($this->registry->userinfoXYZ)) 

$dobbimagecode true


All code we're talking about belongs to the plugin bbcode_parse_start.

kau 12-22-2005 03:35 AM

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?

merk 12-22-2005 08:12 AM

My mistake.

PHP Code:

if(is_member_of($this->registry->userinfoX)) { 
$dobbimagecode false


Replace X with the usergroup you wish to "stop it from happening".

kau 12-22-2005 06:36 PM

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.

merk 12-22-2005 08:15 PM

Ah.

Gotta look for more hooks, will get back to you :)

kau 12-22-2005 08:49 PM

Thanks for all the help Merk I really do appreciate it!

merk 12-22-2005 09:39 PM

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

PHP Code:

function parse_bbcode()
{
if(
is_member_of($this->postX)
{
$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

PHP Code:

if($isimgcheck)
{
$dobbimagecode false;
$isimgcheck false;


I hijacked a parameter that wasnt being used. This may break in future versions.

kau 12-22-2005 11:15 PM

Quote:

Originally Posted by merk
My mistake.

PHP Code:

if(is_member_of($this->registry->userinfoX)) { 
$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

merk 12-23-2005 02:20 AM

Can you paste the code around 799 in class_postbit.php?

Nm, parse_bbcode() has a typo.

PHP Code:

function parse_bbcode()
{
if(
is_member_of($this->postX))
{
$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']);
}



kau 12-24-2005 01:01 AM

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

Quote:

Originally Posted by Psionic Vision
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.

merk 12-24-2005 02:25 AM

Did you replace it with the code i pasted with the fixed typo?

kau 12-24-2005 02:26 AM

Yes I did ...

merk 12-24-2005 03:59 AM

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?

kau 12-24-2005 06:15 AM

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?

merk 12-24-2005 07:28 AM

No, but the error you are getting indicates a typo/error in pasting :\

You're running PHP5?

kau 12-24-2005 05:37 PM

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?

merk 12-24-2005 09:01 PM

Its available everywhere. Ill look into it furthur after the xmas stuff is over :)

kau 12-28-2005 08:37 PM

Anyone see why it's erroring out?

Quote:

Originally Posted by Psionic Vision
File class_bbcode.php, around line 1714:

PHP Code:

    /**
    * 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:

Code:

if (!in_array($vbulletin->userinfo['usergroupid'], array(x,y,z)))
{
        //we need to remove the [img] tags....
        $vbulletin->GPC['message'] = str_ireplace("[img]","",$vbulletin->GPC['message']);
        $vbulletin->GPC['message'] = str_ireplace("[/img]","",$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


All times are GMT. The time now is 06:13 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.01299 seconds
  • Memory Usage 1,844KB
  • 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
  • (12)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (32)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