Page 1 of 1

how to add new authorization fields?

Posted: Fri Dec 02, 2005 4:38 pm
by asinshesq
I know I can reverse engineer and figure this out, but if anyone either knows off the top of his head or knows of a place that describes this, that'll save me some work:

How do you add a new authorization field that will come up when you set group or user permissions for each forum? In another words, if I want to have the ability to set special permissions per forum that will specify who can use a new feature I add with a mod, how do I go about it?

Posted: Fri Dec 02, 2005 5:06 pm
by Ptirhiik
Here is a sample for a mod called "pic album", the auth being "auth_pic", initialized with auth_post value :

Code: Select all

#
#-----[ SQL ]-------------------------------------------------
#
ALTER TABLE phpbb_auth_access ADD auth_pic TINYINT(1) DEFAULT '0' NOT NULL;
ALTER TABLE phpbb_forums ADD auth_pic TINYINT(2) DEFAULT '0' NOT NULL;

UPDATE phpbb_auth_access SET auth_pic = auth_post;
UPDATE phpbb_forums SET auth_pic = auth_post;
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_forumauth.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full line is longer
//                View      Read      Post      Reply
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
// here we added for each row a new column for pic album auth similar to the Post value
// and add Pic Album in the comment header
//-- modify
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
Delete
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------- 
#
  Pic album
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
	0  => array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
	0  => array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG
#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
, AUTH_ALL
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
	1  => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
	1  => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG
#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
, AUTH_REG
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
	2  => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
	2  => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG
#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
, AUTH_REG
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
	3  => array(AUTH_ALL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
	3  => array(AUTH_ALL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL
#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
, AUTH_ACL
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
	4  => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
	4  => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL
#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
, AUTH_ACL
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
	5  => array(AUTH_ALL, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
	5  => array(AUTH_ALL, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD
#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
, AUTH_MOD
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
	6  => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
	6  => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD
);
#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
, AUTH_MOD
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full-line is longer
$forum_auth_fields = array('auth_view', 'auth_read'
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
// here we added
//	, 'auth_pic'
//-- modify
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
, 'auth_delete'
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------- 
#
, 'auth_pic'
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
	'auth_delete' => $lang['Delete'],
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
//-- add
	'auth_pic' => $lang['Pic_album'],
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_forums.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
	"auth_delete" => AUTH_REG,
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
//-- add
	'auth_pic' => AUTH_ALL,
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_ug_auth.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
// Start program - define vars
//
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
// here we added
//	, 'auth_pic'
//-- modify
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full line is longer
$forum_auth_fields = array('auth_view', 'auth_read', 'auth_post'
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
, 'auth_delete'
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------- 
#
, 'auth_pic'
#
#-----[ FIND ]------------------------------------------------
#

$auth_field_match = array(
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
	'auth_delete' => AUTH_DELETE,
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
//-- add
	'auth_pic' => AUTH_PIC,
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
	'auth_delete' => $lang['Delete'],
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
//-- add
	'auth_pic' => $lang['Pic_album'],
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ OPEN ]------------------------------------------------
#
includes/auth.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full line is longer
			$a_sql = 'a.auth_view, a.auth_read, a.auth_post
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
// here we added
//	, a.auth_pic
//
// and
//	, 'auth_pic'
//-- modify
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
, a.auth_delete
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------- 
#
, a.auth_pic
#
#-----[ FIND ]------------------------------------------------
# this is a partial search : the full line is longer
			$auth_fields = array('auth_view', 'auth_read', 'auth_post'
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
, 'auth_delete'
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------- 
#
, 'auth_pic'
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
			$auth_fields = array('auth_delete');
			break;
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
//-- add
		case AUTH_PIC:
			$a_sql = 'a.auth_pic';
			$auth_fields = array('auth_pic');
			break;
//-- fin mod : pic album ---------------------------------------------------------------------------
#
#-----[ OPEN ]------------------------------------------------
#
includes/constants.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
?>
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
//-- mod : pic album -------------------------------------------------------------------------------
//-- add
define('AUTH_PIC', 21);
//-- fin mod : pic album ---------------------------------------------------------------------------

Posted: Fri Dec 02, 2005 5:16 pm
by asinshesq
Thanks, Ptirhiik - RPGnet-fr , that saves me a tremendous amount of work. I am surprised things are set up in such a scattered fashion (I had imagined that I would only need to add the field and the name of the field in one or two places), but your post should get me to where I want to be quickly anyway.

Posted: Fri Dec 02, 2005 6:35 pm
by Ptirhiik
That's why I've changed since the earlier versions of CH the way the auths were handled, in benefit of a single included file in place of the multi-place definitions ;)

Posted: Fri Dec 02, 2005 7:33 pm
by Hater
I love you Ptirhiik.

;)

Here's a how-to guide...

Posted: Fri Dec 02, 2005 9:56 pm
by asinshesq
This post explains what to do if you are writing a mod that gives users a new feature and you want that new feature to appear in the ACP permissions settings so that you can control who will be able to use it.

Before starting, let me give you a key for the different permission settings so that you know how to tweak the modfications I list below in order to fit the needs of your mod:
auth_all is for the 'all' setting (all users)
auth_reg is for the 'reg' setting (all registered users)
auth_acl is for the 'private' setting (groups or individuals granted specific access to particular forum)
auth_mod is for the 'mod' setting (moderators)
auth_admin is for the 'admin' setting (adminsitrators)

And finally before turning to the actual code, I'd like to thank Ptirhiik - RPGnet-fr for taking the time to go through the picture album mod and pulling out the code that does this...I used his work to create this guide.

And finally finally (I mean it this time), if anyoone has any corrections or suggestions to make in improving this guide, please let me know because I think it may be helpful for a lot of mod writers...

The following code shows the actual set of modifications you need to make in order to integrate your mod's new feature into phpbb's permissions settings. Note that I have called the new feature 'new_feature'...you should substitute your own text for 'new_feature', but remember that you should not skip any spaces in the name (if the text is more than one word you should separate the words by an underscore). And note that wherever a line begins with '##', that line is a note explaining how to adapt the changes to your needs

[edit: I deleted the code since I have a more complete version here: http://www.phpbb.com/phpBB/viewtopic.ph ... 83#1886483 ]

Posted: Fri Dec 02, 2005 10:04 pm
by Hater
Please forgive me, but I can't say that I understand the point.

Posted: Fri Dec 02, 2005 10:21 pm
by asinshesq
Hater wrote: Please forgive me, but I can't say that I understand the point.

If you already know the permisssions system through and through, there is no point. If you don't, it takes a while to decipher the picture albums code and figure out how to deviate from what's in there. I've added comments that explain where to change things if you want a different result and don't just want to copy what was done for picture albums. For example:

- I explain how to change the sql updates so that you have the access you want for forums that already exist at the time you install the mod

- I explain how the seven arrays in admin/admin_forumauth.php (0 through 6) correspond to the 7 levels of the simple permissions setting so that you can tinker to set whatever type of default access you want for 'registered [hidden]', etc.

- I warn about the need to change the position of some code if 'delete' is not the sixth entry in those array lines

- I explain what the actual permission levels are (some are obvious but some like ACL may not be)

- I explain how to set a default level of permission that applies when a new forum is created and advanced mod is being used

- I warn about avoiding using the same constant that some other mod uses (for example if you already have the pictures album mod installed, you will run into problems if you set the constant for the new feature to be 21)

- I added the change you need to make to the language file

You're probably right that a lot of mod writers would know this stuff without much explanation, but I can tell you that I have written a fair number of mods at this point and it took me a bit to decipher the picture album mod code that was posted earlier in this thread.

Bottom line: I needed to do this for myself so that I would have a simple template to use for my mods in the future and as long as I was at it I decided to post it.

Posted: Fri Dec 02, 2005 10:24 pm
by Hater
Okay, I understand.

Posted: Sat Dec 03, 2005 6:30 am
by Ptirhiik
Really you should remove our blank lines in your statements : http://www.phpbb.com/phpBB/viewtopic.ph ... 88#1884888

Also, if you want to set a blank after a comma, you have to search onto ", fragment", and to add (after or before) ", my_fragment" : it is the only way to let this space. If the addition has to occur at first position, you have no solution than using an IN-LINE, REPLACE WITH "my_fragment, fragment".

Posted: Sat Dec 03, 2005 9:59 am
by asinshesq
Ptirhiik - RPGnet-fr wrote: Really you should remove our blank lines in your statements : http://www.phpbb.com/phpBB/viewtopic.ph ... 88#1884888...

Thanks. I just reposted the code with the blank lines removed. I guess you're saying that I messed up on every one of my past mods by including those blank lines...the mod looks so much cleaner (and is so much easier to read for manual installation) with them, but I have long noticed that when I install with easymod I do get extra blank lines as a result. In my view, easymod should assume that the very last blank line before a new command is just intended to separate the commands rather than to be extra whitespace to be inserted into the file (so mod authors could either have the commands run together as you suggest or separate them by one blank line at each command without messing things up); if a mod author wanted to indicate insertion of extra blank space he could skip more than one line between two commands and easymod should then only ignore the last blank line. Oh well.
Ptirhiik - RPGnet-fr wrote: ...Also, if you want to set a blank after a comma, you have to search onto ", fragment", and to add (after or before) ", my_fragment" : it is the only way to let this space. If the addition has to occur at first position, you have no solution than using an IN-LINE, REPLACE WITH "my_fragment, fragment".

You'll see that I cheated in fixing the one line that had this problem: I added '...' before and after the inserted word since the word was being inserted into a commented line so it doesn't matter.

Posted: Sat Dec 03, 2005 10:28 am
by Ptirhiik
I don't agree : as I said in the other thread, blank line have not to mean ignored line : the sample I gave shows why it is important to get them correctly. BTW, inserting linefeed doesn't make the mod template more readable, at contrary it introduces a comfusion ("should I or not insert a linefeed ?"). Blank chars after the last word in a statement will be ignored as they are not visible, that's why you can't add it this way.

Posted: Sat Dec 03, 2005 1:11 pm
by asinshesq
Ptirhiik - RPGnet-fr wrote: I don't agree : as I said in the other thread, blank line have not to mean ignored line : the sample I gave shows why it is important to get them correctly....


I agree it is important for readability to pay attention to when to insert skipped lines and when not to insert skippped lines, and I am not suggesting otherwise. But I would like to see easymod changed so that it follows the folloiwng rules:...[edit: rest of post deleted because its substance is in the new topic I refer to in my post below]

Posted: Sat Dec 03, 2005 1:26 pm
by asinshesq
I've created a new topic to discuss the line skipping question here: http://www.phpbb.com/phpBB/viewtopic.ph ... 55#1885755

If people have further thoughts about that issue it probably makes sense to make them in that topic rather than here.

Posted: Sat Dec 03, 2005 11:36 pm
by asinshesq
I've now added a more formal 'mod' to add authorization fields integrated with phpbb's regular permission scheme. You can find that mod here: http://www.phpbb.com/phpBB/viewtopic.ph ... 83#1886483

If you want to discuss the authorization code further, please do so in that topic.