- fix a very nasty error: If there is a tree of more than one category but with no module in there there is no module to activate (module not found error). We have to go through the tree to make sure we are not displaying categories with no modules - took a bit to find this bug. :/

git-svn-id: file:///svn/phpbb/trunk@5408 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2005-12-30 17:56:28 +00:00
parent 3bf7635b3c
commit 1324d64c9d

View file

@ -75,6 +75,12 @@ class p_master
$this->module_cache['modules'] = array(); $this->module_cache['modules'] = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
// Only add if we are allowed to view this module...
if (!$this->module_auth($row['module_auth']))
{
continue;
}
$this->module_cache['modules'][] = $row; $this->module_cache['modules'][] = $row;
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -102,21 +108,12 @@ class p_master
$right = $depth = $i = 0; $right = $depth = $i = 0;
$depth_ary = $disable = array(); $depth_ary = $disable = array();
foreach ($this->module_cache['modules'] as $row) foreach ($this->module_cache['modules'] as $key => $row)
{ {
/** // Not allowed to view module?
* Authorisation is required ... not authed, skip if (!$this->module_auth($row['module_auth']))
* @todo implement $this->is_module_id
* @todo put in seperate method for authentication
*/
if ($row['module_auth'])
{ {
$is_auth = false; continue;
eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z_]+)(,\$id)?#e', '#\$id#', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1"\\2)', '$this->acl_forup_id', '(int) $config["\\1"]'), trim($row['module_auth'])) . ');');
if (!$is_auth)
{
continue;
}
} }
// Category with no members, ignore // Category with no members, ignore
@ -125,6 +122,45 @@ class p_master
continue; continue;
} }
// Category with no members on their way down (we have to check every level)
if (!$row['module_name'])
{
$empty_category = true;
// If we do find members we can add this module to the array
$right_id = $row['right_id'];
// Get branch (from this module to module with left_id >= right_id)
$temp_module_cache = array_slice($this->module_cache['modules'], $key + 1);
if (!sizeof($temp_module_cache))
{
continue;
}
foreach ($temp_module_cache as $temp_row)
{
if ($temp_row['left_id'] >= $right_id)
{
break;
}
// Module there
if ($temp_row['module_name'])
{
$empty_category = false;
break;
}
}
unset($temp_module_cache);
if ($empty_category)
{
continue;
}
}
// Not enabled? // Not enabled?
if (!$row['module_enabled']) if (!$row['module_enabled'])
{ {
@ -198,6 +234,28 @@ class p_master
unset($this->module_cache['modules']); unset($this->module_cache['modules']);
} }
/**
* Check module authorisation
* @todo implement $this->is_module_id
*/
function module_auth($module_auth)
{
global $auth, $config;
$module_auth = trim($module_auth);
// Generally allowed to access module if module_auth is empty
if (!$module_auth)
{
return true;
}
$is_auth = false;
eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z_]+)(,\$id)?#e', '#\$id#', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1"\\2)', '$this->acl_forup_id', '(int) $config["\\1"]'), trim($module_auth)) . ');');
return $is_auth;
}
function set_active($id = false, $mode = false) function set_active($id = false, $mode = false)
{ {
$category = false; $category = false;