Log in

View Full Version : Conditionals. To Display something from a usergroup


6piston
02-10-2009, 01:18 PM
Hi All

Thanks for reading

i'm no programmer, so i really need anyone's help in this

What would be the IF conditional to display something from a usergroup?
The usergroup i have in mind is the Paid Subscribers.
I found a plugin which allows displaying of avatars of the thread starter but i need it to only display avatars of Paid subscribers
Also, do i do it in the template or the plugin? this is the plugin: https://vborg.vbsupport.ru/showthread.php?t=135891&page=5&highlight=avatar

I hope i won't be redirected to the plugin page cos i'm sure with the many experts here, will be able to provide a useable conditional for this purpose

thanks!

Lynne
02-10-2009, 02:46 PM
In a thread, if you have a post getting displayed and you only want to display something in that post if the poster is in a certain usergroup:
<if condition="is_member_of($post, x,y,z)">
stuff to show if poster is in group x, y, or z
</if>

6piston
02-10-2009, 03:08 PM
hi Lynne

thanks!
i did use that on the threadbit template but it wouldn't display

<tr>

<td class="alt2" align="center" valign="middle">
<if condition="$tt_displaythumbs">
<if condition="($thread['attachmentid']) AND ($thread['thumbsize'])">
<a href="showthread.php?$session[sessionurl]t=$thread[threadid]">
<img src="attachment.php?attachmentid=$thread[attachmentid]&stc=1&thumb=1" alt="" border="0" />
</a>
<else />
<img src="$stylevar[imgdir_misc]/nothumb.jpg" alt="" border="0" />
</if>
<else />
<if condition="$show['threadicon']">
<img src="$thread[threadiconpath]" alt="$thread[threadicontitle]" border="0" />
</if>
</if>
</td>

<if condition="$show['threadicons']">
<td class="alt2"><if condition="$show['threadicon']"><img src="$thread[threadiconpath]" alt="$thread[threadicontitle]" border="0" /><else />&nbsp;</if></td>
</if>

<td class="alt1" id="td_threadtitle_$thread[realthreadid]" title="$thread[preview]">

$thread[title_editable]
<div>
<if condition="$show['taglist'] OR $show['moderated'] OR $show['deletedthread'] OR $show['paperclip'] OR $show['subscribed'] OR $show['sticky'] OR $show['rexpires']">
<span style="float:$stylevar[right]">
<if condition="$show['taglist']"> <img class="inlineimg" src="$stylevar[imgdir_misc]/tag.png" alt="$thread[taglist]" /> </if>
<if condition="$show['rexpires']"> <img class="inlineimg" src="$stylevar[imgdir_misc]/expires.gif" alt="<phrase 1="$thread[expiredate]" 2="$thread[expiretime]">$vbphrase[expires_on_x_y]</phrase>" /> </if>
<if condition="$show['moderated']"> <img class="inlineimg" src="$stylevar[imgdir_misc]/moderated_small.gif" alt="<phrase 1="$thread[hiddencount]">$vbphrase[x_moderated_posts]</phrase>" /> </if>
<if condition="$show['deletedthread']"> <img class="inlineimg" src="$stylevar[imgdir_misc]/trashcan_small.gif" alt="<phrase 1="$thread[deletedcount]">$vbphrase[x_deleted_posts]</phrase>" /> </if>
<if condition="$show['paperclip']"> <a href="#" onclick="attachments($thread[threadid]); return false"> <img class="inlineimg" src="$stylevar[imgdir_misc]/paperclip.gif" border="0" alt="<phrase 1="$thread[attach]">$vbphrase[x_attachments]</phrase>" /></a> </if>
<if condition="$show['subscribed']"> <img class="inlineimg" src="$stylevar[imgdir_misc]/subscribed.gif" alt="$vbphrase[you_are_subscribed_to_this_thread]" /> </if>
<if condition="$show['sticky']"> <img class="inlineimg" src="$stylevar[imgdir_misc]/sticky.gif" alt="$vbphrase[sticky_thread]" /> </if>
</span>
</if>
<if condition="is_member_of($post,34)">$avatar</if> <if condition="$show['gotonewpost']"><a href="showthread.php?$session[sessionurl]goto=newpost&amp;t=$thread[threadid]" id="thread_gotonew_$thread[realthreadid]"><img class="inlineimg" src="$stylevar[imgdir_button]/firstnew.gif" alt="$vbphrase[go_to_first_new_post]" border="0" /></a></if>
$thread[movedprefix]
$thread[typeprefix]
$thread[moderatedprefix]
$thread[prefix_rich]
<a href="showthread.php?$session[sessionurl]t=$thread[threadid]$thread[highlight]" id="thread_title_$thread[realthreadid]"<if condition="$show['gotonewpost']"> style="font-weight:bold"</if>>$thread[threadtitle]</a>
<if condition="$thread['pagenav']">$stylevar[dirmark]<span class="smallfont" style="white-space:nowrap">(<img class="inlineimg" src="$stylevar[imgdir_misc]/multipage.gif" alt="$vbphrase[multipage_thread]" border="0" /> $thread[pagenav]<if condition="$show[pagenavmore]"> ... <a href="showthread.php?$session[sessionurl]t=$thread[threadid]&amp;page=$thread[totalpages]$thread[highlight]">$vbphrase[last_page]</a></if>)</span></if>
</div>

<if condition="$show['rmanage']"><div class="smallfont"><span style="float:$stylevar[right]"><a href="postings.php?$session[sessionurl]do=editthread&amp;t=$thread[redirectthreadid]">$vbphrase[manage]</a></span></div></if>

<div class="smallfont">
<if condition="$show['threadratings'] AND $show['threadrating']"><span style="float:$stylevar[right]"><img class="inlineimg" src="$stylevar[imgdir_rating]/rating_$thread[rating].gif" border="0" alt="<phrase 1="$thread[votenum]" 2="$thread[voteavg]">$vbphrase[thread_rating_x_votes_y_average]</phrase>" /></span></if>
<if condition="$show['guestuser']">
$thread[postusername]
<else />
<span style="cursor:pointer" onclick="window.open('member.php?$session[sessionurl]u=$thread[postuserid]', '_self')">$thread[postusername]</span>
</if>
</div>

<if condition="$show['unsubscribe']">
<div class="smallfont">
<a href="newreply.php?$session[sessionurl]do=newreply&amp;t=$thread[threadid]" rel="nofollow">$vbphrase[reply]</a> |
<a href="subscription.php?$session[sessionurl]do=removesubscription&amp;return=ucp&amp;t=$thread[threadid]" rel="nofollow">$vbphrase[unsubscribe]</a>
</div>
</if>

</td>

<if condition="$show['threadmoved']">
<td class="alt2" align="center">-</td>
<else />
<td class="alt2" title="<phrase 1="$thread[replycount]" 2="$thread[views]">$vbphrase[replies_x_views_y]</phrase>">
<div class="smallfont" style="text-align:$stylevar[right]; white-space:nowrap">
$thread[lastpostdate] <if condition="!$show['detailedtime']"><span class="time">$thread[lastposttime]</span></if><br />
<phrase 1="member.php?$session[sessionurl]find=lastposter&amp;t=$thread[threadid]" 2="$thread[lastposter]">$vbphrase[by_x]</phrase> <a href="showthread.php?$session[sessionurl]p=$thread[lastpostid]$thread[highlight]#post$thread[lastpostid]"><img class="inlineimg" src="$stylevar[imgdir_button]/lastpost.gif" alt="$vbphrase[go_to_last_post]" border="0" /></a>
</div>
</td>
</if>

<if condition="$show['notificationtype']">
<td class="alt1"><div class="smallfont">
<label for="sub$subscribethread[$threadid]">$thread[notification]</label>
</div></td>
<td class="alt2"><input type="checkbox" name="deletebox[$subscribethread[$threadid]]" id="sub$subscribethread[$threadid]" value="yes" /></td>
<else />
<td class="alt1" align="center"><if condition="$show['threadmoved']">-<else /><a href="misc.php?do=whoposted&amp;t=$thread[threadid]" onclick="who($thread[threadid]); return false;">$thread[replycount]</a></if></td>
<td class="alt2" align="center">$thread[views]</td>

<if condition="$show['forumlink']">
<td class="alt1"><a href="forumdisplay.php?$session[sessionurl]f=$thread[forumid]">$thread[forumtitle]</a></td>
</if>
</if>

<if condition="$show['inlinemod']">
<td class="<if condition="$show['forumlink']">alt2<else />alt1</if>">
<input type="checkbox" name="tlist[$thread[realthreadid]]" id="tlist_$thread[realthreadid]" value="$thread[checkbox_value]" <if condition="$show['disabled']">disabled="disabled"</if> />
</td>
</if>
</tr>

without the <if condition="is_member_of($post,34)"> statement the plugin works and displays thread posters' Avatars but when i include the <if condition="is_member_of($post,34)"> on it before $avatar, the all the Avatars don't display.

in case if you're wondering what $avatar is, its the plugin that displays posters' avatars in the threadbit

thanks!

--------------- Added 1234286343 at 1234286343 ---------------

this is the plugin code

require_once('./includes/functions_user.php');
$userid = $thread['postuserid'];
$username = $thread['postusername'];
$avatarurl = fetch_avatar_url($userid);
if ($avatarurl == '') {
$avatar = "<div class='avatar_forumdisplay' style='float:$stylevar[left]'><a href='member.php?u=$userid'><img src='$stylevar[imgdir_misc]/aucun_avatar.gif' border='0' width='60' height='60' alt='Profil de $username'></a></div>";
}
else {
$avatar = "<div class='avatar_forumdisplay' style='float:$stylevar[left]'><a href='member.php?u=$userid'><img src='image.php?u=$userid' border='0' width='60' height='60' alt='$username's Avatar'></a></div>";
}

Lynne
02-10-2009, 03:30 PM
Where are you trying to show this? The condition I wrote was for posts in the showthread.php page. What page are you trying to modify? (Probably trying $userinfo instead of $post will work.)

6piston
02-10-2009, 03:34 PM
hi lynne

it is for the threadbit

i wish to display the avatars beside the threads in forumdisplay

Mr. INTENSE
02-10-2009, 03:36 PM
I want to show a small GIF image in the upper right hand corner of each post (right above the Join Date), for any user who is a member of a certain user group.

Should I use a modified version of what you recommended above Lynne?

If so, should I add this conditional statement in the Postbit template?

And how could I then make this image clickable, and send the clicker to a specific link?

Thanks in advance as always. :)

Lynne
02-10-2009, 04:25 PM
hi lynne

it is for the threadbit

i wish to display the avatars beside the threads in forumdisplay
In your plugin, you should also grab the users usergroup ($thread['usergroupid']?). Then, you can actually put a condition around the part where you define the avatar:
if (is_member_of($thread['usergroupid'], x,y,z))
{
avatar code
}
And then the avatar would only get defined if they were in the correct usergroup. I think....

I want to show a small GIF image in the upper right hand corner of each post (right above the Join Date), for any user who is a member of a certain user group.

Should I use a modified version of what you recommended above Lynne?

If so, should I add this conditional statement in the Postbit template?

And how could I then make this image clickable, and send the clicker to a specific link?

Thanks in advance as always. :)
You should start your own thread with your questions. It's too hard to follow two different conversations in one thread.

Mr. INTENSE
02-10-2009, 07:30 PM
You should start your own thread with your questions. It's too hard to follow two different conversations in one thread.
Done.

https://vborg.vbsupport.ru/showthread.php?t=204907

6piston
02-11-2009, 06:43 AM
hi Lynne

thanks again

but it still doesn't work. no avatars are displayed at all when i used these:

$usergroupid = $thread['usergroupid'];
$usergroupid = $usergroup['usergroupid'];
$usergroupid = $forum['usergroupid'];

here's my plugin code. is there anything wrong with it?
require_once('./includes/functions_user.php');
$userid = $thread['postuserid'];
$username = $thread['postusername'];
$avatarurl = fetch_avatar_url($userid);
$usergroupid = $thread['usergroupid'];

if (is_member_of($thread['usergroupid'], 34)) {

if ($avatarurl == '') {
$avatar = "<div class='avatar_forumdisplay' style='float:$stylevar[left]'><a href='member.php?u=$userid'><img src='$stylevar[imgdir_misc]/aucun_avatar.gif' border='0' width='60' height='60' alt='Profil de $username'></a></div>";
}
else {
$avatar = "<div class='avatar_forumdisplay' style='float:$stylevar[left]'><a href='member.php?u=$userid'><img src='image.php?u=$userid' border='0' width='60' height='60' alt='$username's Avatar'></a></div>";
}
}

Dismounted
02-11-2009, 08:22 AM
You're grabbing the avatar URL, but not using it? :confused:

6piston
02-11-2009, 09:41 AM
Hi Dismounted

thanks for the rpely
i'm not really sure what you're saying but,

the plugin works just fine. it's just that i want to display only avatars from paid subscribers(through their usergroup)

but the contionals just doesn't work, i've also added into the plugin, but to no avail.
maybe i'm doing it wrongly?

Lynne
02-11-2009, 02:13 PM
I could be that the usergroupid is not available at the place you are trying to use it. Or, it has a different name. I didn't go look through the code to find out. Go look and see where $thread is defined and see if the usergroupid was grabbed at the same time in the query. If not, you may have to write a query to grab it based on $thread['userid']

6piston
02-11-2009, 02:36 PM
Got it.

Would you know of any other plugin or mods residing in the forumdisplay or threadbit which requires the need to grab usergroups? It would help me learn the codes from there

As for writing queries, can you point me in the right direction to do so? i'd really love to get the plugin working for my purpose

any help is much appreciated!

Thanks!
Tom

Lynne
02-11-2009, 04:56 PM
This is on the forumdisplay.php page, right? You are wanting to put the thread starters avatar next to the thread on the page? But, you only want to display the avatar if the thread starter is a paid subscriber - it has nothing to do with the user *viewing* the page, right?

The query that grabs the thread info is around line 878 of forumdisplay. There is a hook right above it for you to grab the user.usergroupid. You will have to add a join as well as the field. The hook location is 'forumdisplay_query'.

6piston
02-12-2009, 04:01 PM
hi lynne

thanks for the advice!

deluxmall
11-20-2009, 10:16 PM
I like to know the same thing, any solution?