Show a div only to buddies.

Started by Xarcell, August 03, 2011, 01:58:32 PM

Previous topic - Next topic

Xarcell

In the profile template, I am trying to show some content only to that profiles buddies.

I tried:

global $modSettings, $context, $txt, $scripturl, $user_info;
if ($memberContext[$user_info['id']]['is_buddy']){
<div>example content</div>
}


But it didn't seem to work(nothing shows). Any help with this?

Tony Reid

Should you not be echoing that div?
Tony Reid

[unplugged]

I haven't forgotten about you on that. ;)

I have found that you can retrieve a list of the buddy IDs using $user_settings['buddy_list']. It would then just be a matter of checking that $context['member']['id'] (the viewer's ID) is among that list. Make sure to include $user_settings in your global.
« Next Edit: Tomorrow at 08:34:45 PM by SunKing »   <---- « someone stole my sig... :o »



Xarcell

Quote from: SunKing on August 03, 2011, 02:10:50 PM
I haven't forgotten about you on that. ;)

I have found that you can retrieve a list of the buddy IDs using $user_settings['buddy_list']. It would then just be a matter of checking that $context['member']['id'] (the viewer's ID) is among that list. Make sure to include $user_settings in your global.

I'm not a php coder so I don't know what that means...

Maybe this is what you mean?

global $modSettings, $user_settings, $context, $txt, $scripturl, $user_info;


if ($context['member']['id'] && $user_settings['buddy_list']){
   echo '
          <div>example content</div>';
}

Suki

try this:

global $user_settings, $context;

if( in_array($user_settings['buddy_list'], $context['member']['id']))
   echo '<div>example content</div>';
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Xarcell

Quote from: Miss All Sunday on August 03, 2011, 08:11:49 PM
try this:

global $user_settings, $context;

if( in_array($user_settings['buddy_list'], $context['member']['id']))
   echo '<div>example content</div>';

Nope, nothing appears at all.

Hj Ahmad Rasyid Hj Ismail

#6
Quote from: Xarcell on August 03, 2011, 01:58:32 PM
In the profile template, I am trying to show some content only to that profiles buddies.

I tried:

global $modSettings, $context, $txt, $scripturl, $user_info;
if ($memberContext[$user_info['id']]['is_buddy']){
   <div>example content</div>
}


But it didn't seem to work(nothing shows). Any help with this?
Try this:

if ($context['member']['is_buddy'] || $context['user']['is_owner'] || $context['user']['is_admin'])
{
   echo '<div>example content</div>';
}

I have tested this and got this working on profile page. With this, only admin, profile owner and his buddy(ies) can view the content that you allowed.

Xarcell

Quote from: ahrasis on August 04, 2011, 12:22:56 AM
Quote from: Xarcell on August 03, 2011, 01:58:32 PM
In the profile template, I am trying to show some content only to that profiles buddies.

I tried:

global $modSettings, $context, $txt, $scripturl, $user_info;
if ($memberContext[$user_info['id']]['is_buddy']){
   <div>example content</div>
}


But it didn't seem to work(nothing shows). Any help with this?
Try this:

if ($context['member']['is_buddy'] || $context['user']['is_owner'] || $context['user']['is_admin'])
{
   echo '<div>example content</div>';
}

I have tested this and got this working on profile page. With this, only admin, profile owner and his buddy(ies) can view the content that you allowed.

I've tested this and it seems to work without error. Thank you much!

Hj Ahmad Rasyid Hj Ismail

Noted. Thanks for the info. You might want to add something else if the profile viewer is not buddy (or owner or admin). Just add else { echo '<div>something else</div>' } as the second argument. All the best.

Xarcell

Quote from: ahrasis on August 04, 2011, 06:58:01 PM
Noted. Thanks for the info. You might want to add something else if the profile viewer is not buddy (or owner or admin). Just add else { echo '<div>something else</div>' } as the second argument. All the best.

I did already ;)

Advertisement: