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

Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2008, 02:17 AM
h2ojunkie h2ojunkie is offline
 
Join Date: Sep 2004
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Need help with Regex

I sware regex is the bain of my exsistance. The more I read on it, the more confused I get and the more my brain hurts.

If anyone is willing to help with this, I'd much appreciate it.

I'm trying to make a modification to the check4spam product to add some functionality.

Here's the original:
Code:
   
    if (($vbulletin->userinfo['posts'] < $vbulletin->options['check4spam_urlstop']) && ($vbulletin->options['check4spam_urlstoponoff'] == 1)) { 

        $message = (strtolower($post['message'])) . ' ';         
        $message = preg_replace('/[\r\n]+/', ' ', $message); 

        $allowedurls = preg_split('/[\r\n]+/', $vbulletin->options['check4spam_allowedurls'], -1, PREG_SPLIT_NO_EMPTY); 

        foreach ($allowedurls as $allowedurl) { 
        $message = (preg_replace('/(\[url=?"?\]?)(https?\:\/\/)?(www\.)?' . $allowedurl . '\/?"?\]?(.*?)?\[\/url\]/i', '', $message)); 
        } 

        $message = str_replace($allowedurls, '', $message); 
         
        $detecturl = explode('|', $vbulletin->options['check4spam_urlidentifiers']); 
          
        foreach ($detecturl as $urlspam) 
        { 
          
            if (stripos($message, $urlspam) !== false) 
            { 
                     

                $dataman->set('visible', 0); 
                $check4spam_error = 1; 
                 
            } 
        } 
    }
$allowedurls is a list of URL's stored one URL to a line as domain.com (no www)

Code:
$allowedurls = preg_split('/[\r\n]+/', $vbulletin->options['check4spam_allowedurls'], -1, PREG_SPLIT_NO_EMPTY);
Then, the part I'm trying to modify.

Right now, if you want to allow a subdomain, you must add it to the allowed list. so if you want to allow imageshack URL's, simply adding imageshack.us won't do the trick.

Instead you would need to list each subdomain seperatly as so:
i433.imageshack.us
i422.imageshack.us
i415.imageshack.us
etc....

As you can see, with the literally hundreds of subdomains used by a site like imageshack, it's just not possible to add them all to the allowedurls list.

The plugin performs the following on allowedurls
Code:
        foreach ($allowedurls as $allowedurl) { 
        $message = (preg_replace('/(\[url=?"?\]?)(https?\:\/\/)?(www\.)?' . $allowedurl . '\/?"?\]?(.*?)?\[\/url\]/i', '', $message)); 
        }
This is where the part where my brain starts hurting. I just can't seem to understand what is going on there.

Let's say I have domain.com in my allowedurl list

If I post any of these

[url]http://www.domain.com[/url]
[url]www.domain.com[/url]
domain.com


It allows the url as it should

But if I post:
subdomain.domain.com

It does not allow the URL, and the only way to allow it would be to add subdomain.domain.com to the allowedurl list as described below.

Hopefully, someone can point me in the right direction of what I need to change in the preg_replace statement to allow subdomains by just adding the TLD to the allowedlist

Thanks
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 07:48 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.03366 seconds
  • Memory Usage 2,164KB
  • Queries Executed 13 (?)
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
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)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_postinfo_query
  • fetch_postinfo
  • 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