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
Contact:

Forum Template User-defined permissions

Post by Josh » Fri Feb 20, 2009 1:47 pm

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: 50510
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Forum Template User-defined permissions

Post by stevemaury » Fri Feb 20, 2009 4:38 pm

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
Contact:

Re: Forum Template User-defined permissions

Post by Josh » Sat Feb 21, 2009 5:34 am

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
Contact:

Re: Forum Template User-defined permissions

Post by Josh » Thu Mar 26, 2009 9:35 am

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 » Tue May 12, 2009 3:05 pm

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: 50510
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Forum Template User-defined permissions

Post by stevemaury » Tue May 12, 2009 3:20 pm

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 -->).
For REALLY good and VERY inexpensive hosting CLICK HERE

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 » Tue May 12, 2009 3:37 pm

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: 50510
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Forum Template User-defined permissions

Post by stevemaury » Tue May 12, 2009 3:43 pm

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.
For REALLY good and VERY inexpensive hosting CLICK HERE

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 » Thu May 14, 2009 2:02 pm

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 » Thu Jun 18, 2009 7:21 am

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
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Forum Template User-defined permissions

Post by RMcGirr83 » Sun Aug 16, 2009 12:32 pm

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.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

richey
Registered User
Posts: 612
Joined: Mon Feb 18, 2002 4:26 pm
Location: now@Cyberspace
Contact:

Re: Forum Template User-defined permissions

Post by richey » Sun Aug 16, 2009 1:26 pm

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: 51726
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Forum Template User-defined permissions

Post by Brf » Sun Aug 16, 2009 1:45 pm

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.

richey
Registered User
Posts: 612
Joined: Mon Feb 18, 2002 4:26 pm
Location: now@Cyberspace
Contact:

Re: Forum Template User-defined permissions

Post by richey » Sun Aug 16, 2009 5:26 pm

Thanks a lot, works like a charm that way! :mrgreen:
.

User avatar
noth
Registered User
Posts: 2472
Joined: Fri Jan 07, 2005 7:10 pm
Location: North Surrey
Contact:

Re: Forum Template User-defined permissions

Post by noth » Fri Aug 21, 2009 6:23 pm

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

Locked

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