Warning: The author of this contribution does not provide support for it anymore.

Social Networking Site Buttons

Validation and implementation of more SN - Social Networking Site Buttons

Validation and implementation of more SN

by potiron » Thu May 09, 2013 10:16 pm

Hello,

First of all, many thanks for the mod. I'm not a phpBB expert unfortunately and I always appreciate to find some mods that answer my needs.
And it was again exactly the case here, as I wanted to implement some Social Network fields in the profiles of our members.

Therefore I used this mod (BTW it works perfectly fine on 3.0.6 ;) ).

However I made a few changes. I am sharing them here, so it can be used for any future release, or as a temporary fix/help for others. I am not going to post all the changes (they are straight forward from the install file, just replace the names) but to give an idea, here is par of the language file:
social_networking_buttons.php

Code: Select all

$lang = array_merge($lang, array(
   'TWITTER'         => 'Twitter',
   'FACEBOOK'         => 'Facebook',
   'GOOGLEPLUS'      => 'Google+',
   'PINTEREST'         => 'Pinterest',
   'INSTAGRAM'         => 'Instagram',
   'FLICKR'         => 'Flickr',
   'LINKEDIN'         => 'LinkedIn',
   'VIADEO'         => 'Viadeo',
   'YOUTUBE'         => 'YouTube',
   'DAILYMOTION'      => 'DailyMotion',

   'TWITTER_EXPLAIN'         => 'Enter your Twitter account name <u>only</u>.',
   'FACEBOOK_EXPLAIN'         => 'Enter your public Facebook profile URL.',
   'GOOGLEPLUS_EXPLAIN'      => 'Enter your ID (21 digits) <u>only</u>.',
   'PINTEREST_EXPLAIN'         => 'Enter your public Pinterest profile URL.',
   'INSTAGRAM_EXPLAIN'         => 'Enter your public Instagram profile URL.',
   'FLICKR_EXPLAIN'         => 'Enter your public Flickr profile URL.',
   'LINKEDIN_EXPLAIN'         => 'Enter your public LinkedIn profile URL.',
   'VIADEO_EXPLAIN'         => 'Enter your public Viadeo profile URL.',
   'YOUTUBE_EXPLAIN'         => 'Enter your YouTube URL here.',
   'DAILYMOTION_EXPLAIN'      => 'Enter your DailyMotion URL here.',

   'TWITTER_EXAMPLE'         => '<em>Example: username</em>',
   'FACEBOOK_EXAMPLE'         => '<em>Example: https://www.facebook.com/username</em>',
   'GOOGLEPLUS_EXAMPLE'      => '<em>Example: 123456789012345678901</em>',
   'PINTEREST_EXAMPLE'         => '<em>Example: http://pinterest.com/username/</em>',
   'INSTAGRAM_EXAMPLE'         => '<em>Example: http://instagram.com/username/</em>',
   'FLICKR_EXAMPLE'         => '<em>Example: http://www.flickr.com/photos/username/</em>',
   'LINKEDIN_EXAMPLE'         => '<em>Example: http://www.linkedin.com/in/username</em>',
   'VIADEO_EXAMPLE'         => '<em>Example: http://www.viadeo.com/profile/username</em>',
   'YOUTUBE_EXAMPLE'         => '<em>Example: http://www.youtube.com/user/username</em>',
   'DAILYMOTION_EXAMPLE'      => '<em>Example: http://www.dailymotion.com/username</em>',

   'WRONG_DATA_TWITTER'      => 'The name you entered is not a valid Twitter account name',
   'WRONG_DATA_FACEBOOK'      => 'The Facebook address has to be a valid URL, including the protocol. For example https://www.facebook.com/easyexpat',
   'WRONG_DATA_GOOGLEPLUS'      => 'The ID you entered is not a valid Google ID. You must enter only the 21 digits. For example enter <b>116250370408066279364</b> in https://plus.google.com/116250370408066279364/posts.',
   'WRONG_DATA_PINTEREST'      => 'The Pinterest address has to be a valid URL, including the protocol. For example http://pinterest.com/username/',
   'WRONG_DATA_INSTAGRAM'      => 'The Pinterest address has to be a valid URL, including the protocol. For example http://instagram.com/username/',
   'WRONG_DATA_FLICKR'         => 'The Flickr address has to be a valid URL, including the protocol. For example http://www.flickr.com/photos/username/',
   'WRONG_DATA_LINKEDIN'      => 'The LinkedIn address has to be a valid URL, including the protocol. For example http://www.linkedin.com/in/yourname',
   'WRONG_DATA_VIADEO'         => 'The Viadeo address has to be a valid URL, including the protocol. For example http://www.viadeo.com/profile/username',
   'WRONG_DATA_YOUTUBE'      => 'The YouTube address has to be a valid URL, including the protocol. For example http://www.youtube.com/user/username',
   'WRONG_DATA_DAILYMOTION'   => 'The DailyMotion address has to be a valid URL, including the protocol. For example http://www.dailymotion.com/username',

));


As you can see I ask only for the username for Twitter, and the 21 digits for Google+
For all the others I ask for the full URL.

The big issue is the validation. We have plenty of spammers, and to leave a field available to any type of URL is like Xmas for them: who knows what they can enter instead of a pinterest or facebook URL...?

Therefore I had 2 possibilities:
1- ask them for the URL but check that it is for a specific domain name
2- ask only for their ID/username for each SN

The problem for 2- was that they might not always understand and put other things. And i have to explain for each of them what we want exactly... well possibilities of errors.
So except for Twitter (where it is mainly used like that) and Google+ (with the easy to spot 21 digits) I chose to accept the URL.

Now I need to check, so I have only what I expect (I got inspired by Blue Blood).
In the file include/functions_user.php I added:

Code: Select all

/**
 * Validate Domains for Social Network
 */
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;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

It checks for the domain name. can be (for example for Viadeo) http://www.viadeo.com, viadeo.com, fr.viadeo.com, http://www.viadeo.fr, etc... (I tried to cover most of the possibilities used by my list of social networks).

and in includes/acp/acp_users.php and includes/ucp/ucp_profile.php

Code: Select all

                  'twitter'      => array('string', true, 4, 255),
                  'facebook'        => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('facebook')),
                  'googleplus'   => array('num', true, 100000000000000000000, 999999999999999999999),
                  'pinterest'      => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('pinterest')),
                  'instagram'      => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('instagram')),
                  'flickr'      => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('flickr')),
                  'linkedin'      => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('linkedin')),
                  'viadeo'      => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('viadeo')),
                  'youtube'      => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('youtube')),
                  'dailymotion'   => array(
                     array('string', true, 12, 255),
                     array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'),
                     array('dailymotion')),


I hope it will be useful.

If by any chance someone is popping here and can help on another MOD I asked, many thanks in advance ;) :ugeek: It is here :arrow: Topic Category - Implementing categories for forum topics
potiron
Registered User
Posts: 61
Joined: Wed Dec 01, 2004 9:55 am
Contact:

Re: Validation and implementation of more SN

by _Vinny_ » Thu May 09, 2013 11:04 pm

Thanks for the tip, I will check if it can be added in future versions.
User avatar
_Vinny_
Style Customisations
Style Customisations
Posts: 8799
Joined: Tue Aug 11, 2009 12:45 am
Location: Brazil
Name: Marcus Vinicius
Contact:

Re: Validation and implementation of more SN

by Volksdevil » Wed Jul 17, 2013 2:40 am

Potiron, do you by any chance have the instagram icon available? I'd make one myself but photoshop was on my old computer which doesn't work anymore. :-(
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60
User avatar
Volksdevil
Registered User
Posts: 2415
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Validation and implementation of more SN

by potiron » Wed Jul 17, 2013 8:11 am

Volksdevil wrote:Potiron, do you by any chance have the instagram icon available? I'd make one myself but photoshop was on my old computer which doesn't work anymore. :-(

Yes here:
icon_contact_inst.gif
instagram icon
icon_contact_inst.gif (550 Bytes) Viewed 226 times
potiron
Registered User
Posts: 61
Joined: Wed Dec 01, 2004 9:55 am
Contact: