Template variable for checking group membership

Support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
Forum rules
Please only request support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Template variable for checking group membership

Post by RMcGirr83 »

This will allow an admin of a board to make it so that "if user is a member of group X, then display message X".

Open: includes/functions.php

Find This may be a partial find and not the whole line

Code: Select all

    // application/xhtml+xml not used because of IE
    header('Content-type: text/html; charset=UTF-8');


Add before Add these lines on a new blank line before the preceding line(s) to find

Code: Select all

if (!function_exists('group_memberships'))
{
    include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
}
$groups = group_memberships(false,$user->data['user_id']);
if (sizeof($groups))
{
    foreach ($groups as $grouprec)
    {
        $template->assign_vars(array(
            'S_GROUP_' . $grouprec['group_id'] => true)
        );
    }
}



then use the switch like so in an html file, where the number is the group_id.

Code: Select all

<!-- IF S_GROUP_2 -->ad code here<!-- ENDIF -->


Alternatively, you can also use

Code: Select all

<!-- IF not S_GROUP_2 -->ad code here<!-- ENDIF -->


and to check for multiple groups

Code: Select all

<!-- IF (S_GROUP_2 and S_GROUP_3) -->


Code: Select all

<!-- IF (S_GROUP_2 or S_GROUP_3) -->


if you would like those not in the group to see the code. Helpful for displaying advertisements to those in a specific group, for example.
Last edited by RMcGirr83 on 13 Jan 2015, 00:00, edited 9 times in total.
Reason: fixed code if not in group
muggins
New member
New member
Posts: 7
Joined: 02 Nov 2008, 22:12

Re: Template variable for checking group membership

Post by muggins »

Sweet! Thank you, sir. :thumbup:
Muggins
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: Template variable for checking group membership

Post by RMcGirr83 »

:)
statm
New member
New member
Posts: 3
Joined: 29 Aug 2009, 10:02
Location: NC, US
Contact:

Re: Template variable for checking group membership

Post by statm »

Wow, I asked about this exact thing on the phpbb board a few years ago and never really got a good answer. And here you are with a mod to do the very thing..

Thank you very much!
Lyndka
New member
New member
Posts: 8
Joined: 06 Feb 2009, 20:54
Contact:

Re: Template variable for checking group membership

Post by Lyndka »

I've been Googling for just this sort of MOD - BUT (sorry - there's always a but...) could this be incorporated into a BBcode that would do either of the following?

Either display some text if the condition is true or grayed if false

or

Show text if true or hide text if false

(the BBcode can do one or the other - it doesnt have to offer both within the same tag)

I want to be able to post a topic 'common' to several groups but mask or differentiate text to members of certain groups,
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: Template variable for checking group membership

Post by RMcGirr83 »

No you can't pass IF statements within custom bbcode tags.
LDD
New member
New member
Posts: 4
Joined: 17 May 2010, 11:24

Re: Template variable for checking group membership

Post by LDD »

YOU ARE THE BEST !

Very thank you !

:cheers:
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: Template variable for checking group membership

Post by RMcGirr83 »

You're very welcome. :)
falcon
New member
New member
Posts: 2
Joined: 09 May 2011, 06:25

Re: Template variable for checking group membership

Post by falcon »

thanks
Futeki
New member
New member
Posts: 1
Joined: 30 Jun 2011, 10:14

Re: Template variable for checking group membership

Post by Futeki »

Hello, I am trying to define the "Guests" group so that unregistered guest will be able to view the members list and forums but would not be able to click the member names which would lead to profile view.

I've tried to put this

$_profile_cache['tpl_profile'] = '<!-- IF not S_GROUP_1 --><a href="{PROFILE_URL}" target="_blank">{USERNAME}</a><!-- ELSE -->{USERNAME}<!-- ENDIF -->';

in functions_content.php and it is not working. Can anyone here help me please? Thank you very much!
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: Template variable for checking group membership

Post by RMcGirr83 »

OPEN

includes/functions_content.php

Find This may be a partial find and not the whole line

Code: Select all

            $profile_url = ($custom_profile_url != false) ? $custom_profile_url . '&amp;u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']);


Add after Add these lines on a new blank line after the preceding line(s) to find

Code: Select all

            if ($user->data['user_id'] == ANONYMOUS)
            {
               $profile_url = '';
            }
Ashley.S.
New member
New member
Posts: 35
Joined: 01 Aug 2009, 23:02
Location: Falmouth, Cornwall, UK

Re: Template variable for checking group membership

Post by Ashley.S. »

this is a great snippet, thanks Rich :cool:
Kind Regards,
-Ashley.S. [ ProphpBB Free Forum Hosting Moderator ]
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: Template variable for checking group membership

Post by RMcGirr83 »

If you became a donor you could get the hook file which does the same thing but you don't have to edit any php file. ;)
Ashley.S.
New member
New member
Posts: 35
Joined: 01 Aug 2009, 23:02
Location: Falmouth, Cornwall, UK

Re: Template variable for checking group membership

Post by Ashley.S. »

RMcGirr83 wrote:If you became a donor you could get the hook file which does the same thing but you don't have to edit any php file. ;)


I'll think about it :)
Kind Regards,
-Ashley.S. [ ProphpBB Free Forum Hosting Moderator ]
neuropass
Member
Member
Posts: 66
Joined: 12 Apr 2010, 17:07

Re: Template variable for checking group membership

Post by neuropass »

Futeki wrote:Hello, I am trying to define the "Guests" group so that unregistered guest will be able to view the members list and forums but would not be able to click the member names which would lead to profile view.


Can you not use phpbb permission for that?
Post Reply