UCP Profile valid URL & specific domain

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
Blue Blood
Registered User
Posts: 767
Joined: Sat Apr 11, 2009 7:09 am
Location: U§A
Name: Blue Blood
Contact:

UCP Profile valid URL & specific domain

Post by Blue Blood »

So I want to specify the domain Facebook & Twitter.
I know how to check for a valid URL but not specific domain.

How would I do this.
Thanks!!

Code: Select all

						'facebook'		=> array(
							array('string', true, 12, 255),
							array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),						
						'twitter'		=> array(
							array('string', true, 12, 255),
							array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
Last edited by Blue Blood on Tue Jan 17, 2012 6:00 am, edited 2 times in total.
User avatar
Blue Blood
Registered User
Posts: 767
Joined: Sat Apr 11, 2009 7:09 am
Location: U§A
Name: Blue Blood
Contact:

Re: UCP Profile help

Post by Blue Blood »

So I have added this to functions_user.php

Code: Select all

    function validate_facebook($facebook, $allowed_facebook= false)
    {
       global $config, $db, $user;

       $facebook= strtolower($facebook);
       $validdomains = array('facebook.com');
       foreach ($validdomains as $validdomain) $validdomains = ( preg_match("/[@\.]$validdomain$/is", $facebook));
       if ( !$validdomains )
       {
          return 'WRONG_DATA_FACEBOOK';
       }

       return false;
    }
& added this to ucp_profile.php

Code: Select all

						'facebook'		=> array(
							array('string', true, 12, 255),
							array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
							array('facebook')),	
This problem now is it will only allow
http://www.facebook.com
& NOT
http://www.facebook.com/profile.php?id=########

I only need it to check the domain not the whole address..
User avatar
Blue Blood
Registered User
Posts: 767
Joined: Sat Apr 11, 2009 7:09 am
Location: U§A
Name: Blue Blood
Contact:

Re: UCP Profile help

Post by Blue Blood »

I figured it out!! made a few changes and here it is!!!

BUT

Now if the field is blank the error shows.

So my question now is how do I allow a blank field..
Thanks!!

IN functions_user.php

Code: Select all

    function validate_facebook($facebook, $allowed_facebook= false)
    {
       global $config, $db, $user;

       $validdomains = array('facebook.com/');
       $facebook == $validdomains;
       foreach ($validdomains as $validdomain) $validdomains = ( preg_match("/[@\.]$validdomain", $facebook));
       if ( !$validdomains )
       {
          return 'WRONG_DATA_FACEBOOK';
       }

       return false;
    }

/**
* Validate Twitter Domain
*
* @author ProjectBlueBlood.com
*/
    function validate_twitter($twitter, $allowed_twitter= false)
    {
       global $config, $db, $user;

       $validdomains = array('twitter.com/');
       $twitter== $validdomains;
       foreach ($validdomains as $validdomain) $validdomains = ( preg_match("/[@\.]$validdomain", $twitter));
       if ( !$validdomains )
       {
          return 'WRONG_DATA_TWITTER';
       }

       return false;
    }
IN ucp_profile.php

Code: Select all

						'facebook'		=> array('facebook'),
						'twitter'		=> array('twitter'),
User avatar
Blue Blood
Registered User
Posts: 767
Joined: Sat Apr 11, 2009 7:09 am
Location: U§A
Name: Blue Blood
Contact:

Re: UCP Profile valid URL & specific domain

Post by Blue Blood »

OK here is my solution. Not sure if this is the most efficient way but it works.

Code: Select all

/**
* Validate Facebook Domain
*
* @author ProjectBlueBlood.com
*/
    function validate_facebook($facebook, $allowed_facebook = false)
    {
       global $config, $db, $user;

       if ( $facebook )
       {
			$validdomains = array('facebook.com/');
			$facebook == $validdomains;
			foreach ($validdomains as $validdomain) $validdomains = ( preg_match("/[@\.]$validdomain", $facebook));
			if ( !$validdomains )
			{
				return 'WRONG_DATA_FACEBOOK';
			}
       }
	   


       return false;
    }

/**
* Validate Twitter Domain
*
* @author ProjectBlueBlood.com
*/
	function validate_twitter($twitter, $allowed_twitter= false)
    {
		global $config, $db, $user;
       
		if ( $twitter )
		{
			$validdomains = array('twitter.com/');
			$twitter == $validdomains;
			foreach ($validdomains as $validdomain) $validdomains = ( preg_match("/[@\.]$validdomain", $twitter));
			if ( !$validdomains )
			{
				return 'WRONG_DATA_TWITTER';
			}
		}
		return false;
    }
potiron
Registered User
Posts: 61
Joined: Wed Dec 01, 2004 9:55 am

Re: UCP Profile valid URL & specific domain

Post by potiron »

Hi,

Just to let you know: I got inspired by your code to also implement a validation on social networking.

The problem I found with your code is that the door was still open to a lot of possibilities and I wanted to restrain as much as possible to avoid spammers :twisted: .

Everything is explained in my post, but basically I change the validate function to:

Code: Select all

function validate_facebook($url)
{
	global $config, $db, $user;

	if ( $url )
	{
		$host = parse_url($url, PHP_URL_HOST);
		$validdomain = preg_match('/(?:[^\.]+\.)?(facebook)+\.[a-z]{2,3}$/i', $host);
		if ( !$validdomain )
		{
			return 'WRONG_DATA_FACEBOOK';
		}
	}
	return false;
}
Locked

Return to “[3.0.x] MOD Writers Discussion”