Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Show item on profile page if "x" field is populated
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #1
Show item on profile page if "x" field is populated
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?
04-27-2012 12:09 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #2
RE: Show item on profile page if "x" field is populated
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.


04-27-2012 02:59 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #3
RE: Show item on profile page if "x" field is populated
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
(This post was last modified: 04-28-2012 12:09 AM by brad-t.)
04-27-2012 11:55 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: Show item on profile page if "x" field is populated
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>


(This post was last modified: 04-28-2012 05:14 AM by RateU.)
04-28-2012 05:13 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #5
RE: Show item on profile page if "x" field is populated
Merci!
How can I show x item if user is viewing their own profile?
(This post was last modified: 05-01-2012 12:03 AM by brad-t.)
05-01-2012 12:02 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: Show item on profile page if "x" field is populated

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


My Blog
05-01-2012 08:04 AM
Find all posts by this user Quote this message in a reply
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #7
RE: Show item on profile page if "x" field is populated
(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!
05-22-2012 06:34 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #8
RE: Show item on profile page if "x" field is populated
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
Find all posts by this user Quote this message in a reply
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #9
RE: Show item on profile page if "x" field is populated
(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
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #10
RE: Show item on profile page if "x" field is populated
(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.


05-23-2012 05:01 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: