News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Hide links based on membergroups

Started by ~DS~, March 23, 2010, 08:38:53 PM

Previous topic - Next topic

Arantor

So, assuming GMs are groups 24/25, it'd probably be slightly easier just to give them all the links in batches.


<?php
$left 
false;
global 
$user_info;

// Groups. Makes it easier to follow what's going on later
$admin 1;
$asl 16;
$charter 17;
$gm1 24;
$gm2 25;

// This is for all the possible links
$links = array(
  
'new' => '<a href="http://thetwoworldsforum.com/index.php?action=unread">New</a>',
  
'replies' => '<a href="http://thetwoworldsforum.com/index.php?action=unreadreplies">Unread</a>',
  
'asl' => '<a href="http://thetwoworldsforum.com/index.php/board,32.0.html">ASL Community</a>',
  
'charter' => '<a href="http://thetwoworldsforum.com/index.php/board,76.0.html">Charter</a>',
  
'helpdesk' => '<a href="http://thetwoworldsforum.com/index.php?action=helpdesk">Helpdesk</a>',
  
'banlist' => '<a href="http://thetwoworldsforum.com/index.php?action=admin;area=ban">Banlist</a>',
  
'bugtracker' => '<a href="http://thetwoworldsforum.com/index.php?action=projects">Bug Tracker</a>',
);

$subheading '';

$visible = array();

// Admins / GMs have lotsa links
if (array_intersect($user_info['groups'], array($admin$gm1$gm2)))
{
  if (
allowedTo(array('manage_bans''admin_forum')))
    
$visible = array('new''replies''asl''charter''helpdesk''banlist''bugtracker');
  else
    
$visible = array('new''replies''asl''charter''helpdesk''bugtracker');
}
elseif (
array_intersect($user_info['groups'], array($asl)))
{
  
$visible = array('new''replies''asl''helpdesk');
  
$subheading 'Thank you for joining the ASL community.';
}
elseif (
array_intersect($user_info['groups'], array($charter)))
{
  
$visible = array('new''replies''charter''helpdesk''bugtracker');
  
$subheading 'Thank you for donating.';
}

// OK, now we've determined what items should be visible and a possible subheading, let's go make.

$items = array();
foreach (
$visible as $item)
  
$items[] = $links[$item];

echo 
implode(' | '$items), !empty($subheading) ? '<br />' $subheading '';
?>


I wasn't sure what link you wanted for the support item, or indeed any others but this way it should be fairly easy to add whatever rules and links you want afterwards.

~DS~

Works perfect yet there a issue when a member join the support membership when they are already joined on another group. The support link is not showing unless the member leave another group first.
<?php
$left 
false;
global 
$user_info;

// Groups. Makes it easier to follow what's going on later
$admin 1;
$asl 26;
$support 23;
$charter 17;
$gm1 24;
$gm2 25;

// This is for all the possible links
$links = array(
  
'new' => '<a href="http://thetwoworldsforum.com/index.php?action=unread">New</a>',
  
'replies' => '<a href="http://thetwoworldsforum.com/index.php?action=unreadreplies">Unread</a>',
  
'support' => '<a href="http://thetwoworldsforum.com/index.php/board,90.0.html">Support</a>',
  
'asl' => '<a href="http://thetwoworldsforum.com/index.php/board,32.0.html">ASL Community</a>',
  
'charter' => '<a href="http://thetwoworldsforum.com/index.php/board,76.0.html">Charter</a>',
  
'helpdesk' => '<a href="http://thetwoworldsforum.com/index.php?action=helpdesk">Helpdesk</a>',
  
'banlist' => '<a href="http://thetwoworldsforum.com/index.php?action=admin;area=ban">Banlist</a>',
  
'bugtracker' => '<a href="http://thetwoworldsforum.com/index.php?action=projects">Bug Tracker</a>',
);

$subheading '';

$visible = array();

// Admins / GMs have lotsa links
if (array_intersect($user_info['groups'], array($admin$gm1$gm2)))
{
  if (
allowedTo(array('manage_bans''admin_forum')))
    
$visible = array('new''replies''support''asl''charter''helpdesk''banlist''bugtracker');
  else
    
$visible = array('new''replies''support''asl''charter''helpdesk''bugtracker');
}
elseif (
array_intersect($user_info['groups'], array($asl)))
{
  
$visible = array('new''replies''asl''helpdesk');
  
$subheading 'Thank you for joining the ASL community.';
}
elseif (
array_intersect($user_info['groups'], array($charter)))
{
  
$visible = array('new''replies''charter''helpdesk''bugtracker');
  
$subheading 'Thank you for donating.';
}
elseif (
array_intersect($user_info['groups'], array($support)))
{
  
$visible = array('new''replies''support''helpdesk''bugtracker');
  
$subheading 'Thank you for helping to provide community support.';
}

// OK, now we've determined what items should be visible and a possible subheading, let's go make.

$items = array();
foreach (
$visible as $item)
  
$items[] = $links[$item];

echo 
implode(' | '$items), !empty($subheading) ? '<br />' $subheading '';
?>
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor

Not really an issue, you didn't give me the details for support before.

Though that looks right to me.

~DS~

#43
Quote from: Arantor on March 24, 2010, 06:19:45 PM
Not really an issue, you didn't give me the details for support before.

Though that looks right to me.
Yes, I have add more details in the code now.  :)
However regular user join ASL community, and join Support helper but the "support" link is not showing for register user if joins both memberships. It would for gm1 and gm2 regardless of what groups the GM joining.
Something is overriding from keeping "support" link. Maybe I am missing something in the code...
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor

No, the code is functioning exactly as I had it down. See, you didn't tell me about the support group being joinable!

* Arantor needs people to be precise and thorough.

<?php
$left 
false;
global 
$user_info;

// Groups. Makes it easier to follow what's going on later
$admin 1;
$asl 26;
$support 23;
$charter 17;
$gm1 24;
$gm2 25;

// This is for all the possible links
$links = array(
  
'new' => '<a href="http://thetwoworldsforum.com/index.php?action=unread">New</a>',
  
'replies' => '<a href="http://thetwoworldsforum.com/index.php?action=unreadreplies">Unread</a>',
  
'support' => '<a href="http://thetwoworldsforum.com/index.php/board,90.0.html">Support</a>',
  
'asl' => '<a href="http://thetwoworldsforum.com/index.php/board,32.0.html">ASL Community</a>',
  
'charter' => '<a href="http://thetwoworldsforum.com/index.php/board,76.0.html">Charter</a>',
  
'helpdesk' => '<a href="http://thetwoworldsforum.com/index.php?action=helpdesk">Helpdesk</a>',
  
'banlist' => '<a href="http://thetwoworldsforum.com/index.php?action=admin;area=ban">Banlist</a>',
  
'bugtracker' => '<a href="http://thetwoworldsforum.com/index.php?action=projects">Bug Tracker</a>',
);

$subheading '';

$visible = array();

// Admins / GMs have lotsa links
if (array_intersect($user_info['groups'], array($admin$gm1$gm2)))
{
  if (
allowedTo(array('manage_bans''admin_forum')))
    
$visible = array('new''replies''support''asl''charter''helpdesk''banlist''bugtracker');
  else
    
$visible = array('new''replies''support''asl''charter''helpdesk''bugtracker');
}
elseif (
array_intersect($user_info['groups'], array($asl)))
{
  if (
in_array($support$user_info['groups']))
    
$visible = array('new''replies''support''asl''helpdesk');
  else
    
$visible = array('new''replies''asl''helpdesk');
  
$subheading 'Thank you for joining the ASL community.';
}
elseif (
array_intersect($user_info['groups'], array($charter)))
{
  if (
in_array($support$user_info['groups']))
    
$visible = array('new''replies''support''charter''helpdesk''bugtracker');
  else
    
$visible = array('new''replies''charter''helpdesk''bugtracker');
  
$subheading 'Thank you for donating.';
}
elseif (
array_intersect($user_info['groups'], array($support)))
{
  
$visible = array('new''replies''support''helpdesk''bugtracker');
  
$subheading 'Thank you for helping to provide community support.';
}

// OK, now we've determined what items should be visible and a possible subheading, let's go make.

$items = array();
foreach (
$visible as $item)
  
$items[] = $links[$item];

echo 
implode(' | '$items), !empty($subheading) ? '<br />' $subheading '';
?>

~DS~

Sorry for not being precise enough.  ;D
What did you add?
I think I am done. This works like a charm but unfortunately maybe text need to go because if a member join multiple groups it override subheadings.

You should build in into a mod or post of How to. Cheers.
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

~DS~

Quote from: Dismal Shadow on March 24, 2010, 06:50:23 PM
What did you add?
Never mind figure it out.
if (in_array($support, $user_info['groups']))
    $visible = array('new', 'replies', 'support', 'asl', 'helpdesk');

"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor

There's also an 'else' rule in there to give them the groups otherwise.

~DS~

Arantor, can you make a guideline or tutorial for this? This had me confusing as I am trying to add another link and make it joinable.  :P

Like this so we should know where to put it:
//Now to make membergroup joinable

Or something like that.
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor

Not really because it's still based on membergroup ids...

~DS~

So I decide to add a little comment at the end of the script.
<br />
<span class="middletext">Thank you for for your support.</span>
<br />

But it looks a little funny. Maybe I am wrong?
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor


~DS~

First Chrome, 2 FF
A little too much gap as well at the bottom.
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor

Try taking the <br /> off the end.

There's a natural gap at the end of the block where the rounded corners are, I have a feeling the extra <br /> is causing more of a gap.

~DS~

If I did that...the sentences get cut of a bit and also shows sightly visible scrollbar at the right.
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor

Hmm.

How about:
<div class="middletext">Thank you for for your support.</div>

Would replace both the both the <br />s and span.

~DS~

Quote from: Arantor on May 07, 2010, 05:39:53 AM
Hmm.

How about:
<div class="middletext">Thank you for for your support.</div>

Would replace both the both the <br />s and span.
Removed the  <br />s and replace span with div, still same. What about the <p> tags?
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor


~DS~

Oh well, it was worth a try nothings works  :-[
So I add the <li> tags...it looks better and fixed the scrollbar. :P
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

~DS~

Ok I did some digging.
<br />
<div class="clear-block">
Thank you for for your support.
</div>

That fixes it but trying to figure where middletext should be...
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Advertisement: