MyBB Hacks

Full Version: Show item on profile page if "x" field is populated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Here is an example.

I want to show Twitter button on user's profile page, but only if the user has written something in the Twitter field (ID 8) in user profile. I imagine this is pretty simple?
Something like this:

Code:
<if $userfields['fid8'] then>Button Code</if>


If you include the {$userfields['fid8']} in the button code, maybe it is better if you sanitize it.

The other method is, only display the button if the value of the $userfields['fid8'] is matched with a specific format.

Don't really know how to sanitize it ... .__. I looked up some guides to sanitization but I can't understand how to apply it here.
Another question: how to show "Send PM" button only if user has PM enabled?

Thank you
If you only want htmlspecialchars_uni, you can do that like this:

Code:
<if $userfields['fid8'] then>
	<a href="http://twitter.com/<func htmlspecialchars_uni>{$userfields['fid8']}</func>" target="_blank"><img src="images_url" alt="Go to <func htmlspecialchars_uni>{$memprofile['username']}</func> Twitter page" title="Go to <func htmlspecialchars_uni>{$memprofile['username']}</func> Twitter page" /></a>
</if>


For the PM button in profile, maybe something like this:

Code:
<if $mybb->usergroup['cansendpms'] == 1 && $mybb->settings['enablepms'] == 1 && $memprofile['receivepms'] != 0 then>PM Button</if>

Merci!
How can I show x item if user is viewing their own profile?

Code:
<if $mybb->user['uid'] == $memprofile['uid'] then>
...
</if>

(04-27-2012 02:59 AM)RateU Wrote: [ -> ]The other method is, only display the button if the value of the $userfields['fid8'] is matched with a specific format.

Actually that is very interesting. How would I go about only displaying something if the custom profile field is a steam ID displayed in the correct format? IE: STEAM_#:#:########
Where the # is only numbers from 0-9

Cheers!
You can use preg_match for that (if you're using PHP In Template plugin - I can't find preg_match in the phptpl_allowed_funcs.txt file for Template Conditional).
Something like this (in template conditional style, without capturing any part of the matched pattern):

Code:
<if preg_match($pattern,$text) then>
The out put here
</if>

(05-23-2012 04:16 AM)RateU Wrote: [ -> ]You can use preg_match for that (if you're using PHP In Template plugin - I can't find preg_match in the phptpl_allowed_funcs.txt file for Template Conditional).
Something like this (in template conditional style, without capturing any part of the matched pattern):

Code:
<if preg_match($pattern,$text) then>
The out put here
</if>


Thanks RateU! Unfortunately i'm just starting learning PHP and am confused about how to set that up. Would I set $pattern = STEAM_X:X:XXXXXXXX or something before? Also how would I set that up for only custom profile field fid4?
Thanks!
(05-23-2012 04:44 AM)mdb Wrote: [ -> ]Would I set $pattern = STEAM_X:X:XXXXXXXX or something before?
You can use it directly in the conditional.

I don't know much about the STEAM ID.
Based on your post:
(05-22-2012 06:34 PM)mdb Wrote: [ -> ]IE: STEAM_#:#:########
Where the # is only numbers from 0-9
maybe you can write it like this:

Code:
<if preg_match('~^STEAM_\d:\d:\d{8}$~',$userfields['fid4']) then>
	<func htmlspecialchars_uni>{$userfields['fid4']}</func>
</if>

Or, if you're really sure about the output value, you can remove the htmlspsecialchars_uni for that.
Modify the pattern as your needs.

Pages: 1 2
Reference URL's