[geeklog-cvs] geeklog: Suggested new helper functions: SEC_filterPermissions, ...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Oct 4 13:57:06 EDT 2009
changeset 7362:aaa5a1f1850e
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/aaa5a1f1850e
user: Dirk Haun <dirk at haun-online.de>
date: Sun Oct 04 19:56:54 2009 +0200
description:
Suggested new helper functions: SEC_filterPermissions, SEC_hasAccess2
diffstat:
system/lib-security.php | 70 +++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diffs (78 lines):
diff -r cb9ad1e4b759 -r aaa5a1f1850e system/lib-security.php
--- a/system/lib-security.php Sun Oct 04 18:07:39 2009 +0200
+++ b/system/lib-security.php Sun Oct 04 19:56:54 2009 +0200
@@ -1222,4 +1222,74 @@
return $retval;
}
+/**
+* Prepare an array of the standard permission values
+*
+* This helper functions does the following:
+* 1) filter permission values, e.g. after a POST request
+* 2) translates the permission checkbox arrays into numerical values
+* 3) ensures that all the standard permission entries are set, so you don't
+* have to check with isset() all the time
+*
+* <code>
+* $PERM = SEC_filterPermissions($_POST);
+* if ($PERM['perm_anon'] != 0) { ...
+* </code>
+*
+* @param array $A array to filter on, e.g. $_POST
+* @return array array of only the 6 standard permission values
+* @see SEC_getPermissionValues
+*
+*/
+function SEC_filterPermissions($A)
+{
+ $retval = array();
+
+ if (isset($A['owner_id'])) {
+ $retval['owner_id'] = COM_applyFilter($A['owner_id'], true);
+ } else {
+ $retval['owner_id'] = 0;
+ }
+
+ if (isset($A['group_id'])) {
+ $retval['group_id'] = COM_applyFilter($A['group_id'], true);
+ } else {
+ $retval['group_id'] = 0;
+ }
+
+ $perms = array('perm_owner', 'perm_group', 'perm_members', 'perm_anon');
+
+ $B = array();
+ foreach ($perms as $p) {
+ if (isset($A[$p])) {
+ $B[$p] = $A[$p];
+ } else {
+ $B[$p] = array();
+ }
+ }
+
+ $B = SEC_getPermissionValues($B['perm_owner'], $B['perm_group'],
+ $B['perm_members'], $B['perm_anon']);
+ for ($i = 0; $i < 4; $i++) {
+ $retval[$perms[$i]] = $B[$i];
+ }
+
+ return $retval;
+}
+
+/**
+* Helper function for when you want to call SEC_hasAccess and have all the
+* values to check in an array.
+*
+* @param array $A array with the standard permission values
+* @return int returns 3 for read/edit 2 for read only 0 for no access
+* @see SEC_hasAccess
+*
+*/
+function SEC_hasAccess2($A)
+{
+ return SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'],
+ $A['perm_group'], $A['perm_members'], $A['perm_anon']);
+}
+
?>
More information about the geeklog-cvs
mailing list