Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Norty on September 13, 2011, 04:10:17 AM

Title: Looking for $context['user'] information
Post by: Norty on September 13, 2011, 04:10:17 AM
I am looking for a listing of the $context['user'][xxxxx] variables.

I have used $context['user']['is_guest'] and $context['user']['is_admin'].

I am now looking for something like $context['user']['is_globalmoderator'].
I am also keen to see what other variables would be of use.  I may be able to do some refactoring of my bloated noob code ;)
Title: Re: Looking for $context['user'] information
Post by: Ricky. on September 13, 2011, 04:21:42 AM
There is :
$context['user']['is_mod']
If its true then he is mod at that board or location !'

I hope that helps..

Here is $context['user'] output :
    [user] => Array
        (
            [id] => 0
            [is_logged] =>
            [is_guest] => 1
            [is_admin] =>
            [is_mod] =>
            [username] =>
            [language] => english
            [email] =>
            [name] =>
            [smiley_set] => default
            [started] =>
            [messages] => 0
            [unread_messages] => 0
            [avatar] => Array
                (
                )

            [total_time_logged_in] => Array
                (
                    [days] => 0
                    [hours] => 0
                    [minutes] => 0
                )

            [popup_messages] =>
        )


Above is from test board as guest.
Title: Re: Looking for $context['user'] information
Post by: Norty on September 13, 2011, 04:27:55 AM
Quote from: Ricky. on September 13, 2011, 04:21:42 AM
There is :
$context['user']['is_mod']
If its true then he is mod at that board or location !'

I hope that helps..


Thanks Ricky.  I will try this tonight.
One question:  The user will not be on any specific board, but rather in my custom page.  I am looking specifically for Global Moderators.
Could I safely assume that
Quoteat that board or location
means that a global moderator will always return true?
Title: Re: Looking for $context['user'] information
Post by: Ricky. on September 13, 2011, 04:31:49 AM
Yes it should technically, best way is to simply add following in your test board :
echo '<pre'>;print_r($context['user');echo '</pre>';

Now you can see variable behavour yourself. Best place would be adding it in index.template.php before </body>
Title: Re: Looking for $context['user'] information
Post by: emanuele on September 13, 2011, 04:34:19 AM
If you are in a source file $user_info is available too.
Title: Re: Looking for $context['user'] information
Post by: Norty on September 13, 2011, 05:05:50 AM
Thanks guys.  I will test this tonight.
Title: Re: Looking for $context['user'] information
Post by: Norty on September 13, 2011, 03:35:01 PM
I am using SMF 1.1.14

$context['user']['is_mod']  does not return true for Global Moderator.

Array
(
    [id] => 2
    [is_logged] => 1
    [is_guest] =>
    [is_admin] =>
    [is_mod] =>
.....
Title: Re: Looking for $context['user'] information
Post by: Kindred on September 13, 2011, 03:46:28 PM
global moderators are not "moderators" in the proper sense.

A moderator is a special "group" which is not assigned in the usual way. Moderators are only assigned in the BOARD settings (and on a per-board basis) are are only moderators in that board. Even admins should not flag the "is_mod" setting unless they are also marked as a moderator in that board.

You would have to check if the user's groups contain the global mod group ID.
Title: Re: Looking for $context['user'] information
Post by: Norty on September 13, 2011, 05:06:12 PM
Thanks Kindred.

I was looking for a shortcut  :-[

The security model works perfectly if an admin explicitly adds the fine-grained control to authorised groups.
One extra group (Global Mods) isn't going to be the end of the world.
Title: Re: Looking for $context['user'] information
Post by: iMav on August 01, 2012, 08:09:35 AM
I'm trying to use this context in my Display.template.php file.  Basically, I want to display "Thread Starter" verbage under the avatar of the user that has started the thread.  I am using the context as follows:


          if ($context['user']['started'])
                    echo '
                              <li class="threadstarter">
                                        <b>', $txt['thread_starter'], '</b>
                              </li>';


Unfortunately, it does not seem to identify any user...included the desired target of the thread starter.  If I negate the if, the desired text will show up for everybody...including the thread starter.

I'm at a loss...
Title: Re: Looking for $context['user'] information
Post by: iMav on August 01, 2012, 09:57:28 AM
aha!


$message['member']['is_topic_starter']


:)