[ Index ] |
|
Code source de Phorum 5.1.25 |
1 Permissions in Phorum 5 2 ======================= 3 4 This document describes the way the permission system of Phorum works. 5 It is targeted at developers that need inside information on the 6 API calls that are related to permission handling. 7 8 Table of contents: 9 10 1. Checking user permissions 11 2. Modifying user permissions 12 3. Some final notes 13 14 15 1. Checking user permissions 16 ------------------------------------------------------------------------------- 17 18 First and foremost, your code should use the function called 19 phorum_user_access_allowed() to check for a given user permission 20 in the current forum. However, if you find yourself needing to check 21 the permisssion directly, here is some information. 22 23 Permissions are stored using a bitmask. To check for a certain permission, 24 simply use the bitwise AND (&) operator to match the permission against the 25 user's permissions. 26 27 For example, if we want to check if a user has permission to read 28 a particular forum, we would use the following if statement: 29 30 if($PHORUM["user"]["permissions"] & PHORUM_USER_ALLOW_READ){ 31 // the user can read this forum 32 } else { 33 // the user can NOT read this forum 34 } 35 36 37 2. Modifying user permissions 38 ------------------------------------------------------------------------------- 39 40 If you need to modify the permissions, use the bitwise OR (|) to add 41 a permission or the bitwise XOR (^) to remove a permission. After you 42 make the change, save the user. Here is some example code: 43 44 // add new topic permissions 45 $permissions = $PHORUM["user"]["permissions"] | PHORUM_USER_ALLOW_NEW_TOPIC; 46 $userdata = array( 47 "user_id" => $PHORUM["user"]["user_id"], 48 "permissions" => $permissions 49 ); 50 phorum_user_save($userdata); 51 52 // remove new topic permissions 53 $permissions = $PHORUM["user"]["permissions"] ^ PHORUM_USER_ALLOW_NEW_TOPIC; 54 $userdata = array( 55 "user_id" => $PHORUM["user"]["user_id"], 56 "permissions" => $permissions 57 ); 58 phorum_user_save($userdata); 59 60 61 3. Some final notes 62 ------------------------------------------------------------------------------- 63 64 That should be all you need to know about the Phorum permission system. 65 Here is some stuff that helped explain this to the other developers: 66 67 > select (256 | 16); 68 > That OR's the two numbers together. 69 > you get 272 70 > then: 71 > select 16 & 272; 72 > That returns 16. 73 > So, in our data, the 272 represents what is in the database. 74 > The 16 would be one of the permission constancts 75 > Our constants would look like this: 76 > define("PHORUM_USER_ALLOW_READ", 1); 77 > define("PHORUM_USER_ALLOW_REPLY", 2); 78 > define("PHORUM_USER_ALLOW_EDIT", 4); 79 > define("PHORUM_USER_ALLOW_NEW_TOPIC", 8); 80 > define("PHORUM_USER_ALLOW_UPLOAD", 16); 81 > define("PHORUM_USER_ALLOW_ATTACH", 32); 82 > define("PHORUM_USER_ALLOW_MODERATE_MESSAGES", 64); 83 > define("PHORUM_USER_ALLOW_MODERATE_USERS", 128); 84 > define("PHORUM_USER_ALLOW_FORUM_PROPERTIES", 256); 85 > To give someone read and reply, we would set their perm to 1 | 2 86 > Then, to check it, we would $user_perm_value & $perm == $perm 87 > or in sql 88 > where permission & $perm = $perm 89 90 Another example to show that the = $perm can be left out: 91 92 > select 1 | 2 93 > read, reply 94 > = 3 95 > select 3 & 16 96 > =0 97
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:22:27 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |