verify text entered in custom profile field (Facebook, Twitt

Discussion forum for MOD Writers regarding MOD Development.
techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

verify text entered in custom profile field (Facebook, Twitt

Post by techman41973 » Wed Jun 12, 2013 11:51 pm

I added a custom profile field for users to add their twitter and facebook links.
I'd like to avoid users clicking on these buttons, only to be taken to malicious, non-relevant or porn sites by forum spammers.
When a user fills out these fields, if the syntax doesn't match, I want PHPBB to prevent updates to the field, and to tell the user that the link they entered
doesn't adhere to proper syntax guidelines,
More specifically:
For twitter link: Don't accept the entry if the begninning of the entry doesn't contain http://www.twitter.com/
For Facebook link: Don't accept the entry if the begninning of the entry doesn't contain http://www.facebook.com/

Looking for some guidance on how to handle syntax checking on custom profile text fields.
Thanks

User avatar
AmigoJack
Registered User
Posts: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: verify text entered in custom profile field (Facebook, T

Post by AmigoJack » Thu Jun 13, 2013 6:49 am

That would both disallow HTTPS.
The worst thing about censorship is ███████████

techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: verify text entered in custom profile field (Facebook, T

Post by techman41973 » Thu Jun 13, 2013 6:33 pm

yes. So how about syntax check for
facebook.com/
and
twitter.com/

For each specific custom profile field, the entry must contain that string to get accepted

User avatar
AmigoJack
Registered User
Posts: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: verify text entered in custom profile field (Facebook, T

Post by AmigoJack » Fri Jun 14, 2013 6:01 am

Open /includes/functions_profile_fields.php and find:

Code: Select all

            break;
        }

        return false;
    }

    /**
    * Build profile cache, used for display
    * @access private
    */
    function build_cache()
Before, add:

Code: Select all

                /*** 2013-06-14 BEGIN AmigoJack
                    http://www.phpbb.com/community/viewtopic.php?t=2186548 ***/
                $aCustomCheck= array
                ( 'the_facebook_field_identification'=> '#^https?://(www\\.)?facebook\\.com/.+$#i'
                , 'the_twitter_field_identification'=> '#^https?://(www\\.)?twitter\\.com/.+$#i'
                );
                foreach( $aCustomCheck as $sIdent=> $sRE ) {
                    if( $field_data['field_ident']== $sIdent ) {
                        if( !preg_match( $sRE, trim( $field_value ) ) ) return 'AVATAR_URL_INVALID';
                    }
                }
                /*** 2013-06-14 END ***/
Find:

Code: Select all

                    case 'FIELD_INVALID_DATE':
                    case 'FIELD_INVALID_VALUE':
                    case 'FIELD_REQUIRED':
Before, add:

Code: Select all

                    /*** 2013-06-14 BEGIN AmigoJack
                        http://www.phpbb.com/community/viewtopic.php?t=2186548 ***/
                    case 'AVATAR_URL_INVALID':
                    /*** 2013-06-14 END ***/
Tested. Obviously, change the_facebook_field_identification and the_twitter_field_identification to appropriate values.
The worst thing about censorship is ███████████

techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: verify text entered in custom profile field (Facebook, T

Post by techman41973 » Sun Jun 16, 2013 2:10 am

Thanks! I will get back after I had a chance to try it.

techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: verify text entered in custom profile field (Facebook, T

Post by techman41973 » Thu Jun 27, 2013 5:44 am

Hi, I tried your code strategy above. It doesn't seem to work for me.
After making the code changes, I went into the profile tab in the UCP.
I purposely typed in http://www.facbook.com/myname (purposely removing the e in facebook)
in order to test the syntax checking code you proposed. When I clicked submit, my entry was accepted.

For reference, the facebook profile field appears in the following file
file: /public_html/forum/styles/prosilver/template/ucp_profile_profile_info.html

Code: Select all

	<dl>
		<dt><label for="facebook">{L_UCP_FACEBOOK}:</label><br /><span>{L_FACEBOOK_EXPLAIN}</span></dt>
		<dd><input type="text" name="facebook" id="facebook" maxlength="255" value="{FACEBOOK}" class="inputbox" /></dd>
	</dl>
Therefore I changed
'the_facebook_field_identification'
to 'facebook'

Perhaps you have some insight on what I may be doing wrong. THANKS!

User avatar
tmbackoff
Former Team Member
Posts: 6995
Joined: Thu Jun 04, 2009 1:41 am
Location: cheerleading practice
Name: Tabitha Backoff

Re: verify text entered in custom profile field (Facebook, T

Post by tmbackoff » Thu Jun 27, 2013 6:24 am

I just tested AmigoJack's code and it works perfectly. If I tried to enter http://www.facbook.com/phpbb, I get the invalid URL message. Are you sure you did it correctly?

Also, why did you add that piece of code? What are you using it for?

User avatar
AmigoJack
Registered User
Posts: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: verify text entered in custom profile field (Facebook, T

Post by AmigoJack » Thu Jun 27, 2013 6:40 am

Make sure we're talking about the same thing: Documentation: 3.5.5. Custom profile fields
The worst thing about censorship is ███████████

techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: verify text entered in custom profile field (Facebook, T

Post by techman41973 » Thu Jun 27, 2013 7:29 am

I just realized. My Facebook, Linkedin and Twitter fields were added through a MOD
https://www.phpbb.com/customise/db/mod/ ... _buttons_2
This MOD inserted these fields into the default profile fields file (not as custom profile fields)
I guess I can remove the MOD and manually create custom profile fields for twitter, facebook and linkedin,
although there were some extra features this MOD provided, for example that show icons (facebook, twitter, linkedin) in the mini profile panel in each post.
Sorry for missing this detail.

techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: verify text entered in custom profile field (Facebook, T

Post by techman41973 » Wed Jul 03, 2013 8:10 am

Following up:

Indeed AmigoJack's code works flawlessly on a custom profile field. Thank you Amigojack.
The suggested code is helpful for URL pattern checks in custom profile fields.

In context of the MOD I'm working with - Social Networking site buttons, which adds social media profile fields to the UCP and displays social media icons in user's profiles. https://www.phpbb.com/customise/db/mod/ ... buttons_2/
This MOD adds these fields to the PHPBB default collection of profile fields, NOT as custom profile fields.
This is why AmigoJack's code wasn't working for me. I apologize for not catching this detail earlier. I'm still new to PHP and PHPBB structure.

Today, I thoroughly went through the code added/changed by the Social Networking Site Buttons MOD
and found the line of code that tests the user's entry into each profile field and tests for pattern matching.
When the entry doesn't match the correct pattern, a "bad URL" message appears in the UCP and the entry is not accepted.

The specific line of code is in includes/acp/acp_users.php

Code: Select all

$data['facebook'] = request_var('facebook', $user_row['user_facebook']);
'facebook'			=> array(array('string', true, 12, 255),array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
AmigoJack or anyone else on this thread, I would appreciate some guidance on updating the above line of code
to pattern match for http://www.facebook.com/ in the beginning of the user's entry.

Thank you to everyone for your support

Below is a reference to all code additions that came with the Social Networking site buttons MOD

memberlist.php

Code: Select all

'USER_FACEBOOK_SN'	=> $data['user_facebook'],
'U_FACEBOOK_SN'		=> ($data['user_facebook']) ? urlencode($data['user_facebook']) : '',
viewtopic.php

Code: Select all

$template->assign_var('FACEBOOK_IMG', $user->img('icon_contact_fb', 'FACEBOOK'));

$user_cache[$poster_id]['facebook'] = '';

$user_cache[$poster_id]['facebook'] = $row['user_facebook'];

$postrow['U_FACEBOOK_SN'] = $user_cache[$poster_id]['facebook']
adm/style/acp_users_profile.html

Code: Select all

<dl>
<dt><label for="facebook">{L_UCP_FACEBOOK}:</label></dt>
<dd><input type="text" name="facebook" id="facebook" value="{FACEBOOK}" /></dd>
</dl>
includes/acp/acp_styles.php

Code: Select all

$this->imageset_keys['icons'][] = 'icon_contact_fb';

includes/acp/acp_users.php
$data['facebook'] = request_var('facebook', $user_row['user_facebook']);
'facebook'			=> array(array('string', true, 12, 255),array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),

$sql_ary['user_facebook'] = $data['facebook']

$template->assign_var('FACEBOOK', $data['facebook']);

includes/ucp/ucp_pm_viewmessage.php

Code: Select all

$template->assign_var('U_FACEBOOK_SN', ($user_info['user_facebook']) ? $user_info['user_facebook'] : '');

includes/ucp/ucp_profile.php

Code: Select all

$data['facebook'] = request_var('facebook', $user->data['user_facebook']);
'facebook'		=> array(array('string', true, 12, 255),array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),

$sql_ary['user_facebook'] = $data['facebook'];

$template->assign_var('FACEBOOK', $data['facebook']);


styles/prosilver/imageset/imageset.cfg

img_icon_contact_fb = icon_contact_fb.gif*20*20
styles/prosilver/template/memberlist_view.html

Code: Select all

<!-- IF USER_FACEBOOK_SN --><dt>{L_FACEBOOK}:</dt> <dd><a href="{USER_FACEBOOK_SN}" title="{L_VIEW_FACEBOOK}: {USER_FACEBOOK_SN}">{L_VIEW_FACEBOOK}</a></dd><!-- ENDIF -->

styles/prosilver/template/ucp_pm_viewmessage.html
<!-- IF U_FACEBOOK_SN --><li class="facebooksn-icon"><a href="{U_FACEBOOK_SN}" title="{L_FACEBOOK}"><span>{L_FACEBOOK}</span></a></li><!-- ENDIF -->

styles/prosilver/template/ucp_profile_profile_info.html

Code: Select all

<dl>
		<dt><label for="facebook">{L_UCP_FACEBOOK}:</label><br /><span>{L_FACEBOOK_EXPLAIN}</span></dt>
		<dd><input type="text" name="facebook" id="facebook" maxlength="255" value="{FACEBOOK}" class="inputbox" /></dd>
	</dl>

styles/prosilver/template/viewtopic_body.html
<!-- IF postrow.U_FACEBOOK_SN --><li class="facebooksn-icon"><a href="{postrow.U_FACEBOOK_SN}" title="{L_FACEBOOK}"><span>{L_FACEBOOK}</span></a></li><!-- ENDIF -->

User avatar
AmigoJack
Registered User
Posts: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: verify text entered in custom profile field (Facebook, T

Post by AmigoJack » Wed Jul 03, 2013 8:32 am

Obviously change
each array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')
into array('match', true, '#^https?://(www\\.)?facebook\\.com/.+$#i')
where it relates to Farcebook.
The worst thing about censorship is ███████████

User avatar
Jessica
Former Team Member
Posts: 4341
Joined: Sun Jul 18, 2010 2:53 pm
Location: Pennsylvania, USA
Name: Jessica
Contact:

Re: verify text entered in custom profile field (Facebook, T

Post by Jessica » Wed Jul 03, 2013 4:03 pm

There's a mod that already has the feature of rejecting an entry if it's not a proper Twitter or Facebook link: http://projectblueblood.com/viewtopic.php?f=3&t=34

Just throwing it out there; you don't need to install a whole new mod.
Please do not PM me for support unless it is absolutely necessary
Pro-choice, Atheist, Pro-LGBT rights

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. - Albert Einstein

techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: verify text entered in custom profile field (Facebook, T

Post by techman41973 » Thu Jul 04, 2013 12:46 am

Jessica, I prefer the social buttons MOD. It puts a nice icon in the user's profile and mini profile
and also has Linkedin.
All I needed was this small change from Amigo Jack. Enjoy!

User avatar
Jessica
Former Team Member
Posts: 4341
Joined: Sun Jul 18, 2010 2:53 pm
Location: Pennsylvania, USA
Name: Jessica
Contact:

Re: verify text entered in custom profile field (Facebook, T

Post by Jessica » Thu Jul 04, 2013 1:33 am

techman41973 wrote:Jessica, I prefer the social buttons MOD. It puts a nice icon in the user's profile and mini profile
and also has Linkedin.
All I needed was this small change from Amigo Jack. Enjoy!
Mod I linked to does that too (put an icon in the mini profile and profile); though you're right, it just has FB and Twitter while the social buttons one has a lot more.
Please do not PM me for support unless it is absolutely necessary
Pro-choice, Atheist, Pro-LGBT rights

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. - Albert Einstein

User avatar
Volksdevil
Registered User
Posts: 2413
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: verify text entered in custom profile field (Facebook, T

Post by Volksdevil » Sat Mar 08, 2014 8:57 pm

Great snippet AmigoJack! 8-)

I currently have the below:
/*** 2013-06-14 BEGIN AmigoJack
http://www.phpbb.com/community/viewtopic.php?t=2186548 ***/
$aCustomCheck= array
( 'my_twitter'=> '#^https?://(www\\.)?twitter\\.com/.+$#i'
, 'my_facebook'=> '#^https?://(www\\.)?facebook\\.com/.+$#i'
, 'my_plusgoogle'=> '#^https?://(plus\\.)?google\\.com/.+$#i'
, 'my_instagram'=> '#^https?://(www\\.)?instagram\\.com/.+$#i'
, 'my_linkedin'=> '#^https?://(www\\.)?linkedin\\.com/pub/.+$#i'

);
foreach( $aCustomCheck as $sIdent=> $sRE ) {
if( $field_data['field_ident']== $sIdent ) {
if( !preg_match( $sRE, trim( $field_value ) ) ) return 'AVATAR_URL_INVALID';
}
}
/*** 2013-06-14 END ***/


Just two/three (Hopefully) quick questions:
1/ If I was to add Paypal to the validation, How could I validate email addresses? I've done some searching/trying but made a mess of it :oops:

2/ How can I split the returned error to be individual for each profile field?
I presume this part can be exploded/split?

Code: Select all

                foreach( $aCustomCheck as $sIdent=> $sRE ) {
                    if( $field_data['field_ident']== $sIdent ) {
                        if( !preg_match( $sRE, trim( $field_value ) ) ) return 'AVATAR_URL_INVALID';
3/ Where can I add the lang vars for the 'AVATAR_URL_INVALID' for example?

Thanks for any help, really do love your coding, always works and easy to implement. 8-)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
My Volkswagen Corrado G60 | Opel Manta Owners Forum

Locked

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

Who is online

Users browsing this forum: No registered users and 12 guests

cron