Forum Template User-defined permissions

Discussion forum for MOD Writers regarding MOD Development.
User avatar
Josh
Former Team Member
Posts: 1882
Joined: Sun Jan 25, 2009 3:08 pm
Location: Melbourne, AUS
Name: Josh Simpson

Forum Template User-defined permissions

Post by Josh »

Code: Select all

<!-- IF U_MCP --><!-- ENDIF -->
This is the code to set Moderators visual permissions on sections of the forum, I was curiouse to know whether i can make a "User-Defined" group permission code.

for example

Code: Select all

<!-- IF U_USERGROUP=CLAN -->lalala<!-- ENDIF -->

So only members of the "clan" usergroup can see "lalala"

Is any of this possible?
Josh Simpson- Formerly known as "HardStyle"
Styles: Submission Policy | Database | Knowledge Base | Demo
Please do not PM me for personal support.
Image
User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 52794
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve

Re: Forum Template User-defined permissions

Post by stevemaury »

Open includes/functions.php

FIND

Code: Select all

   // The following assigns all _common_ variables that may be used at any point in a template.
BEFORE, ADD

Code: Select all

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

Code: Select all

<!-- IF S_GROUP_2 -->some stuff here<!-- ENDIF -->
Credit = RMcGirr83
Last edited by stevemaury on Mon Jun 07, 2010 7:58 pm, edited 2 times in total.
Reason: Edited to update for version 3.0.4
User avatar
Josh
Former Team Member
Posts: 1882
Joined: Sun Jan 25, 2009 3:08 pm
Location: Melbourne, AUS
Name: Josh Simpson

Re: Forum Template User-defined permissions

Post by Josh »

Thanks stevemaury and RMcGirr83 :D
Josh Simpson- Formerly known as "HardStyle"
Styles: Submission Policy | Database | Knowledge Base | Demo
Please do not PM me for personal support.
Image
User avatar
Josh
Former Team Member
Posts: 1882
Joined: Sun Jan 25, 2009 3:08 pm
Location: Melbourne, AUS
Name: Josh Simpson

Re: Forum Template User-defined permissions

Post by Josh »

sorry to revive..

any chance on getting this to work for single user id numbers? or is there already that feature :?


EDIT: nevermind, i fiddled with a code and seems to work great :lol: luck :oops:
Josh Simpson- Formerly known as "HardStyle"
Styles: Submission Policy | Database | Knowledge Base | Demo
Please do not PM me for personal support.
Image
MsIrey
Registered User
Posts: 144
Joined: Tue Sep 02, 2008 1:50 am
Location: Florida

Re: Forum Template User-defined permissions

Post by MsIrey »

Regarding the new code to add:

Code: Select all

        if ( !function_exists('group_memberships') )
        {
            include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
        }
        $groups = group_memberships(false,$user->data['user_id']);
        foreach ($groups as $grouprec)
        {
            $template->assign_vars(array(
            'S_GROUP_' . $grouprec['group_id'] => true
            ));
        }
Do I just copy the above as shown and leave it alone?
Do I insert the group id # anywhere there?
I don't have to add anything to the 'user_id', right?

Then for the switch code:

Code: Select all

<!-- IF S_GROUP_2 -->some stuff here<!-- ENDIF -->
I gather I change the group number to the one I want and the "some stuff here" is where I put my message. I'm sorry, but I am not quite sure where to insert the switch code. Does it go on a new line after the new code?
User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 52794
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve

Re: Forum Template User-defined permissions

Post by stevemaury »

Insert the code exactly as given.

You would change the 2 in the template switch example to the id of the group in question. The switch does not need to be on a new line.

"Some stuff here" is whatever you want that group to see (or not see - note you can also use <!-- IF not S_GROUP_N -->).
I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)
MsIrey
Registered User
Posts: 144
Joined: Tue Sep 02, 2008 1:50 am
Location: Florida

Re: Forum Template User-defined permissions

Post by MsIrey »

stevemaury wrote:...You would change the 2 in the template switch example to the id of the group in question. The switch does not need to be on a new line....
So the switch gets added after the last } of the new added code?

Sorry to be so thick headed about this. Your patience is really appreciated.
User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 52794
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve

Re: Forum Template User-defined permissions

Post by stevemaury »

The added code goes in includes/functions.php.

The switches go in whatever template files you want to use them in. The code in functions.php enables the use of the switch in any html template file.
I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)
MsIrey
Registered User
Posts: 144
Joined: Tue Sep 02, 2008 1:50 am
Location: Florida

Re: Forum Template User-defined permissions

Post by MsIrey »

Is it possible to change the text in the first field from "Warning" to something else (Tip, Reminder, Comment, Location, etc.) or leave it blank, leaving just the message in the second field? Either way would work for me.

Edit: Disregard the above. I had been testing a couple mods and posted in the wrong one. :oops:
Last edited by MsIrey on Fri Jul 31, 2009 3:52 am, edited 2 times in total.
User avatar
.Joel
Registered User
Posts: 127
Joined: Sat Jan 28, 2006 11:41 pm

Re: Forum Template User-defined permissions

Post by .Joel »

Alright I followed that link and added:

Code: Select all

    if ( !function_exists('group_memberships') )
    {
        include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
    }
    $groups = group_memberships(false,$user->data['user_id']);
    foreach ($groups as $grouprec)
    {
        $template->assign_vars(array(
        'S_GROUP_' . $grouprec['group_id'] => true
        ));
    }
However it gives me an error:
Parse error: syntax error, unexpected T_STRING in /forums/includes/functions.php on line 3767

Code: Select all

		'A_COOKIE_SETTINGS'		=> addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
	));



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



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

	header('Cache-Control: private, no-cache="set-cookie"');
	header('Expires: 0');
	header('Pragma: no-cache');

	return;
}
I have put 3767# in to the code above so you see where the error starts. I have played with it, usually the error is a simple ; missing or misconfiguration of brackets around a statement. However I can't seem to spot the error.

Any help appreciated.
User avatar
RMcGirr83
Former Team Member
Posts: 22074
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Forum Template User-defined permissions

Post by RMcGirr83 »

Instead, add it before this (few lines up from that find)

Code: Select all

	// The following assigns all _common_ variables that may be used at any point in a template.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺
User avatar
richey
Registered User
Posts: 636
Joined: Mon Feb 18, 2002 4:26 pm
Location: now@Cyberspace

Re: Forum Template User-defined permissions

Post by richey »

Just a small additional question: 'while already being there' 8-), could I use the above lines to check whether a user is a member in a specific group right in the code?

Like

if (!array_search('Good_Souls',$groups,true) === false) {
$good_souls_member = true;
}
.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53569
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Forum Template User-defined permissions

Post by Brf »

No.
Use:

Code: Select all

$good_souls_member  = group_memberships(69,$user->data['user_id']);
Where 69 is the group_id of the group you are checking.
User avatar
richey
Registered User
Posts: 636
Joined: Mon Feb 18, 2002 4:26 pm
Location: now@Cyberspace

Re: Forum Template User-defined permissions

Post by richey »

Thanks a lot, works like a charm that way! :mrgreen:
.
User avatar
noth
Registered User
Posts: 2528
Joined: Fri Jan 07, 2005 7:10 pm
Location: North Surrey

Re: Forum Template User-defined permissions

Post by noth »

I have used it now and it's great

ideal for placing "members only" panels on the index page

I tried "transferring user permissions" via ACP but this does not succeed in testing out the visibility of this code

you have to physically remove yourself or add yourself to the usergroup specified to see or "not see" the panel

anyway FIRST CLASS stuff, it gives us yet another opportunity to fine tune our sites

THANK YOU Steve Maury :D

Return to “[3.0.x] MOD Writers Discussion”