Some tinkering ... clear your prefetch (user_permissions) fields ...

git-svn-id: file:///svn/phpbb/trunk@3398 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-01-29 16:12:21 +00:00
parent 4d761a22d8
commit 777717dd16

View file

@ -499,65 +499,59 @@ class auth
{ {
var $founder = false; var $founder = false;
var $acl = array(); var $acl = array();
var $acl_options = array(); var $option = array();
function acl(&$userdata) function acl(&$userdata)
{ {
global $db, $acl_options; global $db, $acl_options;
$this->acl_options = &$acl_options; if (!($this->founder = $userdata['user_founder']))
if (!$this->founder = $userdata['user_founder'])
{ {
if (empty($userdata['user_permissions'])) if (empty($userdata['user_permissions']))
{ {
$this->acl_cache($userdata); $this->acl_cache($userdata);
} }
$global_chars = ceil(sizeof($this->acl_options['global']) / 8); $global_chars = ceil(sizeof($acl_options['global']) / 8);
$local_chars = ceil(sizeof($this->acl_options['local']) / 8) + 2; $local_chars = ceil(sizeof($acl_options['local']) / 8) + 2;
$globals = substr($userdata['user_permissions'], 0, $global_chars);
$locals = substr($userdata['user_permissions'], $global_chars);
for($i = 0; $i < $global_chars; $i++) for($i = 0; $i < $global_chars; $i++)
{ {
$this->acl['global'] .= str_pad(decbin(ord(substr($globals, $i, 1))), 8, 0, STR_LEFT_PAD); $this->acl['global'] .= str_pad(decbin(ord($userdata['user_permissions']{$i})), 8, 0, STR_LEFT_PAD);
} }
$forums = explode("\r\n", chunk_split($locals, $local_chars)); for ($i = $global_chars; $i < strlen($userdata['user_permissions']); $i += $local_chars)
array_pop($forums);
foreach ($forums as $forum)
{ {
$forum_id = bindec(decbin(ord(substr($forum, 0, 1))) . str_pad(decbin(ord(substr($forum, 1, 1))), 8, 0, STR_PAD_LEFT)); $forum_id = (ord($userdata['user_permissions']{$i}) << 8) + ord($userdata['user_permissions']{$i + 1});
for($j = $i + 2; $j < $i + $local_chars; $j++)
for($i = 2; $i < $local_chars; $i++)
{ {
$this->acl['local'][$forum_id] .= str_pad(decbin(ord(substr($forum, $i, 1))), 8, 0, STR_PAD_LEFT); $this->acl['local'][$forum_id] .= str_pad(decbin(ord($userdata['user_permissions']{$j})), 8, 0, STR_PAD_LEFT);
} }
} }
unset($forums); unset($forums);
}
}
return; return;
} }
// Look up an option // Look up an option
function acl_get($option, $forum_id = 0) function acl_get($opt, $f = 0)
{ {
static $acl_cache; global $acl_options;
static $cache;
if (!isset($acl_cache[$forum_id][$option]) && !$this->founder) if (!isset($cache[$f][$opt]) && !$this->founder)
{ {
if (isset($this->acl_options['global'][$option])) if (isset($acl_options['global'][$opt]))
{ {
$acl_cache[$forum_id][$option] = substr($this->acl['global'], $this->acl_options['global'][$option], 1); $cache[$f][$opt] = $this->acl['global']{$acl_options['global'][$opt]};
} }
if (isset($this->acl_options['local'][$option])) if (isset($acl_options['local'][$opt]))
{ {
$acl_cache[$forum_id][$option] |= substr($this->acl['local'][$forum_id], $this->acl_options['local'][$option], 1); $cache[$f][$opt] |= $this->acl['local'][$forum_id]{$acl_options['local'][$opt]};
} }
} }
return ($this->founder) ? true : $acl_cache[$forum_id][$option]; return ($this->founder) ? true : $cache[$f][$opt];
} }
function acl_gets() function acl_gets()
@ -567,19 +561,19 @@ class auth
return true; return true;
} }
$arguments = func_get_args(); $args = func_get_args();
$forum_id = array_pop($arguments); $f = array_pop($args);
if (!is_int($forum_id)) if (!is_int($f))
{ {
$arguments[] = $forum_id; $args[] = $f;
$forum_id = 0; $f = 0;
} }
$acl = 0; $acl = 0;
foreach ($arguments as $option) foreach ($args as $opt)
{ {
$acl |= $this->acl_get($option, $forum_id); $acl |= $this->acl_get($opt, $f);
} }
return $acl; return $acl;
@ -588,7 +582,7 @@ class auth
// Cache data // Cache data
function acl_cache(&$userdata) function acl_cache(&$userdata)
{ {
global $db; global $db, $acl_options;
$acl_db = array(); $acl_db = array();
@ -623,74 +617,64 @@ class auth
foreach ($acl_db as $row) foreach ($acl_db as $row)
{ {
if ($row['auth_allow_deny'] != ACL_INHERIT && $this->acl[$row['forum_id']][$row['auth_value']] !== ACL_DENY) if ($row['auth_allow_deny'] != ACL_INHERIT &&
$this->acl[$row['forum_id']][$row['auth_value']] !== ACL_DENY)
{ {
$this->acl[$row['forum_id']][$row['auth_value']] = intval($row['auth_allow_deny']); $this->acl[$row['forum_id']][$row['auth_value']] = intval($row['auth_allow_deny']);
} }
} }
unset($acl_db); unset($acl_db);
$global_bits = 8 * ceil(sizeof($this->acl_options['global']) / 8); $global_bits = 8 * ceil(sizeof($acl_options['global']) / 8);
$local_bits = 8 * ceil(sizeof($this->acl_options['local']) / 8); $local_bits = 8 * ceil(sizeof($acl_options['local']) / 8);
$local_hold = ''; $local_hold = '';
$global_hold = ''; $global_hold = '';
foreach ($this->acl as $forum_id => $auth_ary) foreach ($this->acl as $f => $auth_ary)
{ {
$holding = array(); $holding = array();
$option_set = array(); $option_set = array();
if (!$forum_id) if (!$f)
{ {
$fill = $global_bits; $len = $global_bits;
$ary_key = 'global'; $ary_key = 'global';
$hold_str = 'global_hold'; $hold_str = 'global_hold';
} }
else else
{ {
$fill = $local_bits; $len = $local_bits;
$ary_key = 'local'; $ary_key = 'local';
$hold_str = 'local_hold'; $hold_str = 'local_hold';
} }
for($i = 0; $i < $fill; $i++) foreach ($acl_options[$ary_key] as $opt => $id)
{ {
$holding[$i] = 0; if (!empty($auth_ary[$opt]))
}
foreach ($auth_ary as $option => $allow)
{
if ($allow)
{ {
$holding[$this->acl_options[$ary_key][$option]] = 1; $holding[$id] = 1;
$option_key = substr($option, 0, strpos($option, '_') + 1); $option_key = substr($opt, 0, strpos($opt, '_') + 1);
if (empty($holding[$this->acl_options[$ary_key][$option_key]])) if (empty($holding[$acl_options[$ary_key][$option_key]]))
{ {
$holding[$this->acl_options[$ary_key][$option_key]] = 1; $holding[$acl_options[$ary_key][$option_key]] = 1;
} }
} }
else
{
$holding[$id] = 0;
}
} }
$forum_id = ($forum_id) ? str_pad(decbin($forum_id), 16, 0, STR_PAD_LEFT) : ''; $$hold_str = ($f) ? pack('C2', $f >> 8, $f) : '';
$bitstring = explode("\r\n", chunk_split($forum_id . implode('', $holding), 8)); $bitstring = implode('', $holding);
array_pop($bitstring); for ($i = 0; $i < $len; $i += 8)
foreach ($bitstring as $byte)
{ {
$$hold_str .= chr(bindec($byte)); $$hold_str .= chr(bindec(substr($bitstring, $i, 8)));
} }
} }
unset($holding); unset($holding);
if ($global_hold == '')
{
for($i = 0; $i < $global_bits / 8; $i++)
{
$global_hold .= chr(0);
}
}
$userdata['user_permissions'] .= $global_hold . $local_hold; $userdata['user_permissions'] .= $global_hold . $local_hold;
unset($global_hold); unset($global_hold);
unset($local_hold); unset($local_hold);