Hi, i'm rebuilding my website and want to add the moderator link, if the logged in person is a moderator (or admin)
For admin I use this code
// Is the user allowed to administrate at all? ([admin])
if ($context['allow_admin'])
echo '<li><a href="', $scripturl, '?action=admin">administratie</a></li>';
What code to use for the moderator link?
Bumping this thread. Anyone familiar with this?
Quote from: Angelotus on July 09, 2008, 05:41:36 AM
Hi, i'm rebuilding my website and want to add the moderator link, if the logged in person is a moderator (or admin)
For admin I use this code
// Is the user allowed to administrate at all? ([admin])
if ($context['allow_admin'])
echo '<li><a href="', $scripturl, '?action=admin">administratie</a></li>';
What code to use for the moderator link?
are u sure your website 2.x ?? that's admin code for 1.1.x :S
$context['user']['is_admin']
$context['user']['is_mod'] OR allowedTo('moderate_forum')
I forget which one is per-board mods, and which is for global forum mods.
$context['user']['is_logged']
$context['user']['is_guest']
I have tried to create such a link with:
// Is the user allowed to moderate at all? ([mod])
if ($context['user']['is_mod'])
echo '<li><a href="', $scripturl, '?action=moderate">moderatie</a></li>';
What is wrong?
But moderators can not see the link when logged in.
Quote from: TiReDsOuL on July 09, 2008, 04:27:15 PM
Quote from: Angelotus on July 09, 2008, 05:41:36 AM
Hi, i'm rebuilding my website and want to add the moderator link, if the logged in person is a moderator (or admin)
For admin I use this code
// Is the user allowed to administrate at all? ([admin])
if ($context['allow_admin'])
echo '<li><a href="', $scripturl, '?action=admin">administratie</a></li>';
What code to use for the moderator link?
are u sure your website 2.x ?? that's admin code for 1.1.x :S
Yes it is 2.0
And I copied the code indeed from 1.1.5
What should be the code for 2.0?
If this use is for on your website have you included ssi.php?
is context declared within your function as a global variable?
Quote from: karlbenson on July 09, 2008, 04:42:48 PM
is context declared within your function as a global variable?
Yes, this is the full coding for the function:
// Show the menu up top. Something like [home] [help] [profile] [logout]...
function template_menu()
{
global $context, $settings, $options, $scripturl, $txt;
if ($context['user']['is_logged'])
{
echo '<div class="tborder3"><div class="catbg">Mijn Menu</div><ul class="glossymenu">';
// Is the user allowed to administrate at all? ([admin])
if ($context['allow_admin'])
echo '<li><a href="', $scripturl, '?action=admin">administratie</a></li>';
// Is the user allowed to moderate at all? ([admin])
if ($context['user']['is_admin'])
echo '<li><a href="', $scripturl, '?action=moderate">moderatie</a></li>';
// Is the user allowed to moderate at all? ([admin])
if ($context['user']['is_mod'])
echo '<li><a href="', $scripturl, '?action=moderate">moderatie</a></li>';
// Go to PM center... [pm]
if ($context['user']['is_logged'] && $context['allow_pm'])
echo '<li><a href="', $scripturl, '?action=pm">Mijn Inbox ', $context['user']['unread_messages'] > 0 ? '[<strong>'. $context['user']['unread_messages'] . '</strong>]' : '' , '</a></li>';
// Edit Profile... [profile]
if ($context['allow_edit_profile'])
echo '<li><a href="', $scripturl, '?action=profile">Mijn Profiel</a></li>';
// The [bookmarks] button
if ($context['user']['is_logged'])
echo '<li><a href="', $scripturl, '?action=bookmarks">Mijn Favorieten</a></li>';
// Edit profile pictures... [profile]
if ($context['allow_edit_profile'])
echo '<li><a href="', $scripturl, '?action=profile;u=',$ID_MEMBER,';sa=pictures">Mijn Fotoalbum</a></li>';
// Edit profile buddies... [profile]
if ($context['allow_edit_profile'])
echo '<li><a href="', $scripturl, '?action=buddies">Mijn Vrienden</a></li>';
// Edit stats... [profile]
if ($context['allow_edit_profile'])
echo '<li><a href="', $scripturl, '?action=profile;u=',$ID_MEMBER,';sa=statPanel">Mijn Statistieken</a></li>';
// Edit topics... [profile]
if ($context['allow_edit_profile'])
echo '<li><a href="', $scripturl, '?action=profile;u=',$ID_MEMBER,';sa=showPosts">Mijn Topics</a></li>';
// Edit topics... [profile]
if ($context['allow_edit_profile'])
echo '<li><a href="', $scripturl, '?action=profile;u=',$ID_MEMBER,';sa=notification">Mijn Notificaties</a></li>';
echo '</ul></div>';
}
else
{
echo ' ';
}
}
which type of moderators does it not work for?
global moderators or board moderators?
I tested it with a global moderator
Then try
if ($context['user']['is_mod'] || allowedTo('moderate_forum'))
If that still doesn't work, are you getting any error messages in your error logs.
Doesn't work for the global moderator. It does work for the admin though. I don't get any errors in my errorlog.
Couldn't you just use..
$mods = array(2, 3);
global $user_info;
if( in_array( $mods, $user_info['groups'] ) ) {
echo '<li><a href="', $scripturl, '?action=moderate">moderatie</a></li>'; }
If that doesn't work, then I have no clue.
Thanks for reply! Unfortunately it doesn't work either... I don't know why because it should work...
Well I doubt you'll be able to get a trigger for general moderator out of the MessageIndex or board they are moderator in. As they aren't a moderator out of that area and I'm sure the method of checking is in a way that it's not from user to board, but board to user.
Where are you calling this code from?
$show_page = array(1,2);
if (!in_array($context['member']['group_id'], $show_page))
or
$show_page = array("id1", "id2", etc);
if($context['user']['is_admin'] || $context['can_moderate_forum'] || (in_array($context['member']['group'],$show_page)))
in the template_menu in index.template.php
Okay try:
Loads.php
Find:
// Set up the contextual user array.
$context['user'] = array(
'id' => &$ID_MEMBER,
'is_logged' => !$user_info['is_guest'],
'is_guest' => &$user_info['is_guest'],
'is_admin' => &$user_info['is_admin'],
'is_mod' => false,
'username' => &$user_info['username'],
'language' => &$user_info['language'],
'email' => &$user_info['email']
);
and replace with:
// Set up the contextual user array.
$context['user'] = array(
'id' => &$ID_MEMBER,
'is_logged' => !$user_info['is_guest'],
'is_guest' => &$user_info['is_guest'],
'is_admin' => &$user_info['is_admin'],
'groups_ids' => &$user_info['groups'],
'is_mod' => false,
'username' => &$user_info['username'],
'language' => &$user_info['language'],
'email' => &$user_info['email']
);
In in your index.template.php file use $context['user']['groups_ids'] to return a users group ID array (list of all membergroup ID's, primary/secondary). Now you can use array_intersect() to check for a person membership to a membergroup.
example
$show_page = array(id1,id2,etc);
if (array_intersect($context['user']['groups_ids'], $show_page))
echo 'Yes you are in the selected membergroup ID's';
else
echo ' You are not a member of the selected groups.';
Thanks Rumbaar!
One question. In my load.php I have
'is_mod' => &$user_info['is_mod'],
instead of 'is_mod' => false,
Is that ok?
Ah, oops. I gave you the code from 1.1.x Load.php file. The additional code should be 'groups_ids' => &$user_info['groups'], and should insert there just fine, even with 2.x. Though I did test with only 1.1.x.
BTW: that code worked perfect! Very kind of you te help me out with this!!!