aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acm/acm_file.php10
-rw-r--r--phpBB/includes/acp/acp_attachments.php14
-rw-r--r--phpBB/includes/acp/acp_bbcodes.php4
-rw-r--r--phpBB/includes/acp/acp_main.php9
-rw-r--r--phpBB/includes/acp/acp_permissions.php103
-rw-r--r--phpBB/includes/acp/acp_styles.php2
-rw-r--r--phpBB/includes/acp/acp_users.php2
-rw-r--r--phpBB/includes/acp/auth.php46
-rw-r--r--phpBB/includes/auth.php434
-rw-r--r--phpBB/includes/functions.php24
-rw-r--r--phpBB/includes/functions_admin.php34
-rw-r--r--phpBB/includes/functions_content.php2
-rw-r--r--phpBB/includes/functions_profile_fields.php10
-rw-r--r--phpBB/includes/functions_upload.php6
-rw-r--r--phpBB/includes/ucp/ucp_attachments.php2
-rw-r--r--phpBB/includes/ucp/ucp_groups.php8
-rw-r--r--phpBB/includes/ucp/ucp_profile.php4
17 files changed, 405 insertions, 309 deletions
diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php
index f123f1383d..f952b372c6 100644
--- a/phpBB/includes/acm/acm_file.php
+++ b/phpBB/includes/acm/acm_file.php
@@ -306,7 +306,7 @@ class acm
if ($var_name[0] === '_')
{
- $this->remove_file($this->cache_dir . 'data' . $var_name . ".$phpEx");
+ $this->remove_file($this->cache_dir . 'data' . $var_name . ".$phpEx", true);
}
else if (isset($this->vars[$var_name]))
{
@@ -369,7 +369,7 @@ class acm
}
else if ($expired)
{
- $this->remove_file($this->cache_dir . 'sql_' . md5($query) . ".$phpEx");
+ $this->remove_file($this->cache_dir . 'sql_' . md5($query) . ".$phpEx", true);
return false;
}
@@ -452,13 +452,15 @@ class acm
/**
* Removes/unlinks file
*/
- private function remove_file($filename)
+ private function remove_file($filename, $check = false)
{
- if (!@unlink($filename))
+ if ($check && !@is_writeable($this->cache_dir))
{
// E_USER_ERROR - not using language entry - intended.
trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR);
}
+
+ return @unlink($filename);
}
}
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index 03e9f52e0e..120c6a789f 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -152,7 +152,7 @@ class acp_attachments
if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
{
$size_var = request_var($config_name, '');
- $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
+ $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? ($config_value << 10) : (($size_var == 'mb') ? ($config_value << 20) : $config_value);
}
if ($submit)
@@ -507,7 +507,7 @@ class acp_attachments
$allowed_forums = request_var('allowed_forums', array(0));
$allow_in_pm = (isset($_POST['allow_in_pm'])) ? true : false;
$max_filesize = request_var('max_filesize', 0);
- $max_filesize = ($size_select == 'kb') ? round($max_filesize * 1024) : (($size_select == 'mb') ? round($max_filesize * 1048576) : $max_filesize);
+ $max_filesize = ($size_select == 'kb') ? ($max_filesize << 10) : (($size_select == 'mb') ? ($max_filesize << 20) : $max_filesize);
$allow_group = (isset($_POST['allow_group'])) ? true : false;
if ($max_filesize == $config['max_filesize'])
@@ -680,8 +680,7 @@ class acp_attachments
}
$size_format = ($ext_group_row['max_filesize'] >= 1048576) ? 'mb' : (($ext_group_row['max_filesize'] >= 1024) ? 'kb' : 'b');
-
- $ext_group_row['max_filesize'] = ($ext_group_row['max_filesize'] >= 1048576) ? round($ext_group_row['max_filesize'] / 1048576 * 100) / 100 : (($ext_group_row['max_filesize'] >= 1024) ? round($ext_group_row['max_filesize'] / 1024 * 100) / 100 : $ext_group_row['max_filesize']);
+ $ext_group_row['max_filesize'] = get_formatted_filesize($ext_group_row['max_filesize'], false);
$img_path = $config['upload_icons_path'];
@@ -1007,11 +1006,8 @@ class acp_attachments
while ($row = $db->sql_fetchrow($result))
{
- $size_lang = ($row['filesize'] >= 1048576) ? $user->lang['MB'] : (($row['filesize'] >= 1024) ? $user->lang['KB'] : $user->lang['BYTES']);
- $row['filesize'] = ($row['filesize'] >= 1048576) ? round((round($row['filesize'] / 1048576 * 100) / 100), 2) : (($row['filesize'] >= 1024) ? round((round($row['filesize'] / 1024 * 100) / 100), 2) : $row['filesize']);
-
$template->assign_block_vars('orphan', array(
- 'FILESIZE' => $row['filesize'] . ' ' . $size_lang,
+ 'FILESIZE' => get_formatted_filesize($row['filesize']),
'FILETIME' => $user->format_date($row['filetime']),
'REAL_FILENAME' => basename($row['real_filename']),
'PHYSICAL_FILENAME' => basename($row['physical_filename']),
@@ -1417,7 +1413,7 @@ class acp_attachments
{
// Determine size var and adjust the value accordingly
$size_var = ($value >= 1048576) ? 'mb' : (($value >= 1024) ? 'kb' : 'b');
- $value = ($value >= 1048576) ? round($value / 1048576 * 100) / 100 : (($value >= 1024) ? round($value / 1024 * 100) / 100 : $value);
+ $value = get_formatted_filesize($value, false);
return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
}
diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php
index 21370036ee..33e8fe7ec1 100644
--- a/phpBB/includes/acp/acp_bbcodes.php
+++ b/phpBB/includes/acp/acp_bbcodes.php
@@ -312,7 +312,7 @@ class acp_bbcodes
'!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')"
),
'EMAIL' => array(
- '!([a-z0-9]+[a-z0-9\-\._]*@(?:(?:[0-9]{1,3}\.){3,5}[0-9]{1,3}|[a-z0-9]+[a-z0-9\-\._]*\.[a-z]+))!i' => "\$this->bbcode_specialchars('$1')"
+ '!(' . get_preg_expression('email') . ')!ie' => "\$this->bbcode_specialchars('$1')"
),
'TEXT' => array(
'!(.*?)!es' => "str_replace(array(\"\\r\\n\", '\\\"', '\\'', '(', ')'), array(\"\\n\", '\"', '&#39;', '&#40;', '&#41;'), trim('\$1'))"
@@ -334,7 +334,7 @@ class acp_bbcodes
$sp_tokens = array(
'URL' => '(?i)((?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))(?-i)',
'LOCAL_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)',
- 'EMAIL' => '([a-zA-Z0-9]+[a-zA-Z0-9\-\._]*@(?:(?:[0-9]{1,3}\.){3,5}[0-9]{1,3}|[a-zA-Z0-9]+[a-zA-Z0-9\-\._]*\.[a-zA-Z]+))',
+ 'EMAIL' => '(' . get_preg_expression('email') . ')',
'TEXT' => '(.*?)',
'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)',
'IDENTIFIER' => '([a-zA-Z0-9-_]+)',
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index 57bb52f27b..bf6e8a39b5 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -307,8 +307,8 @@ class acp_main
$users_per_day = sprintf('%.2f', $total_users / $boarddays);
$files_per_day = sprintf('%.2f', $total_files / $boarddays);
- $upload_dir_size = ($config['upload_dir_size'] >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($config['upload_dir_size'] / 1048576)) : (($config['upload_dir_size'] >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($config['upload_dir_size'] / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $config['upload_dir_size']));
-
+ $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
+
$avatar_dir_size = 0;
if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
@@ -322,10 +322,7 @@ class acp_main
}
closedir($avatar_dir);
- // This bit of code translates the avatar directory size into human readable format
- // Borrowed the code from the PHP.net annoted manual, origanally written by:
- // Jesse (jesse@jess.on.ca)
- $avatar_dir_size = ($avatar_dir_size >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($avatar_dir_size / 1048576)) : (($avatar_dir_size >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($avatar_dir_size / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $avatar_dir_size));
+ $avatar_dir_size = get_formatted_filesize($avatar_dir_size);
}
else
{
diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php
index 1b2b19d4ab..a9e64b74ae 100644
--- a/phpBB/includes/acp/acp_permissions.php
+++ b/phpBB/includes/acp/acp_permissions.php
@@ -48,7 +48,7 @@ class acp_permissions
$this->tpl_name = 'permission_trace';
- if ($user_id && isset($auth_admin->option_ids[$permission]) && $auth->acl_get('a_viewauth'))
+ if ($user_id && isset($auth_admin->acl_options['id'][$permission]) && $auth->acl_get('a_viewauth'))
{
$this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $user->lang['acl_' . $permission]['lang']);
$this->permission_trace($user_id, $forum_id, $permission);
@@ -124,7 +124,7 @@ class acp_permissions
$forum_id = array();
while ($row = $db->sql_fetchrow($result))
{
- $forum_id[] = $row['forum_id'];
+ $forum_id[] = (int) $row['forum_id'];
}
$db->sql_freeresult($result);
}
@@ -133,7 +133,7 @@ class acp_permissions
$forum_id = array();
foreach (get_forum_branch($subforum_id, 'children') as $row)
{
- $forum_id[] = $row['forum_id'];
+ $forum_id[] = (int) $row['forum_id'];
}
}
@@ -598,7 +598,7 @@ class acp_permissions
$ids = array();
while ($row = $db->sql_fetchrow($result))
{
- $ids[] = $row[$sql_id];
+ $ids[] = (int) $row[$sql_id];
}
$db->sql_freeresult($result);
}
@@ -1117,65 +1117,68 @@ class acp_permissions
global $db, $user;
$sql_forum_id = ($permission_scope == 'global') ? 'AND a.forum_id = 0' : ((sizeof($forum_id)) ? 'AND ' . $db->sql_in_set('a.forum_id', $forum_id) : 'AND a.forum_id <> 0');
- $sql_permission_option = ' AND o.auth_option ' . $db->sql_like_expression($permission_type . $db->any_char);
-
- $sql = $db->sql_build_query('SELECT_DISTINCT', array(
- 'SELECT' => 'u.username, u.username_clean, u.user_regdate, u.user_id',
-
- 'FROM' => array(
- USERS_TABLE => 'u',
- ACL_OPTIONS_TABLE => 'o',
- ACL_USERS_TABLE => 'a'
- ),
-
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
- 'ON' => 'a.auth_role_id = r.role_id'
- )
- ),
-
- 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
- $sql_permission_option
- $sql_forum_id
- AND u.user_id = a.user_id",
- 'ORDER_BY' => 'u.username_clean, u.user_regdate ASC'
- ));
+ // Permission options are only able to be a permission set... therefore we will pre-fetch the possible options and also the possible roles
+ $option_ids = $role_ids = array();
+
+ $sql = 'SELECT auth_option_id
+ FROM ' . ACL_OPTIONS_TABLE . '
+ WHERE auth_option ' . $db->sql_like_expression($permission_type . $db->any_char);
$result = $db->sql_query($sql);
- $s_defined_user_options = '';
- $defined_user_ids = array();
while ($row = $db->sql_fetchrow($result))
{
- $s_defined_user_options .= '<option value="' . $row['user_id'] . '">' . $row['username'] . '</option>';
- $defined_user_ids[] = $row['user_id'];
+ $option_ids[] = (int) $row['auth_option_id'];
}
$db->sql_freeresult($result);
- $sql = $db->sql_build_query('SELECT_DISTINCT', array(
- 'SELECT' => 'g.group_type, g.group_name, g.group_id',
+ if (sizeof($option_ids))
+ {
+ $sql = 'SELECT DISTINCT role_id
+ FROM ' . ACL_ROLES_DATA_TABLE . '
+ WHERE ' . $db->sql_in_set('auth_option_id', $option_ids);
+ $result = $db->sql_query($sql);
- 'FROM' => array(
- GROUPS_TABLE => 'g',
- ACL_OPTIONS_TABLE => 'o',
- ACL_GROUPS_TABLE => 'a'
- ),
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $role_ids[] = (int) $row['role_id'];
+ }
+ $db->sql_freeresult($result);
+ }
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
- 'ON' => 'a.auth_role_id = r.role_id'
- )
- ),
+ if (sizeof($option_ids) && sizeof($role_ids))
+ {
+ $sql_where = 'AND (' . $db->sql_in_set('a.auth_option_id', $option_ids) . ' OR ' . $db->sql_in_set('a.auth_role_id', $role_ids) . ')';
+ }
+ else
+ {
+ $sql_where = 'AND ' . $db->sql_in_set('a.auth_option_id', $option_ids);
+ }
- 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
- $sql_permission_option
+ // Not ideal, due to the filesort, non-use of indexes, etc.
+ $sql = 'SELECT DISTINCT u.user_id, u.username
+ FROM ' . USERS_TABLE . ' u, ' . ACL_USERS_TABLE . " a
+ WHERE u.user_id = a.user_id
$sql_forum_id
- AND g.group_id = a.group_id",
+ $sql_where
+ ORDER BY u.username_clean, u.user_regdate ASC";
+ $result = $db->sql_query($sql);
- 'ORDER_BY' => 'g.group_type DESC, g.group_name ASC'
- ));
+ $s_defined_user_options = '';
+ $defined_user_ids = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $s_defined_user_options .= '<option value="' . $row['user_id'] . '">' . $row['username'] . '</option>';
+ $defined_user_ids[] = $row['user_id'];
+ }
+ $db->sql_freeresult($result);
+
+ $sql = 'SELECT DISTINCT g.group_type, g.group_name, g.group_id
+ FROM ' . GROUPS_TABLE . ' g, ' . ACL_GROUPS_TABLE . " a
+ WHERE g.group_id = a.group_id
+ $sql_forum_id
+ $sql_where
+ ORDER BY g.group_type DESC, g.group_name ASC";
$result = $db->sql_query($sql);
$s_defined_group_options = '';
diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php
index 74812efd84..2f2649575b 100644
--- a/phpBB/includes/acp/acp_styles.php
+++ b/phpBB/includes/acp/acp_styles.php
@@ -1003,7 +1003,7 @@ parse_css_file = {PARSE_CSS_FILE}
'CACHED' => $user->format_date(filemtime("{$phpbb_root_path}cache/$filename")),
'FILENAME' => $file,
- 'FILESIZE' => sprintf('%.1f KB', filesize("{$phpbb_root_path}cache/$filename") / 1024),
+ 'FILESIZE' => sprintf('%.1f ' . $user->lang['KIB'], filesize("{$phpbb_root_path}cache/$filename") / 1024),
'MODIFIED' => $user->format_date((!$template_row['template_storedb']) ? filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/$tpl_file.html") : $filemtime[$file . '.html']))
);
}
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php
index 61fd5ea752..3ad8c88fb9 100644
--- a/phpBB/includes/acp/acp_users.php
+++ b/phpBB/includes/acp/acp_users.php
@@ -1745,7 +1745,7 @@ class acp_users
'REAL_FILENAME' => $row['real_filename'],
'COMMENT' => nl2br($row['attach_comment']),
'EXTENSION' => $row['extension'],
- 'SIZE' => ($row['filesize'] >= 1048576) ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : (($row['filesize'] >= 1024) ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']),
+ 'SIZE' => get_formatted_filesize($row['filesize']),
'DOWNLOAD_COUNT' => $row['download_count'],
'POST_TIME' => $user->format_date($row['filetime']),
'TOPIC_TITLE' => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
diff --git a/phpBB/includes/acp/auth.php b/phpBB/includes/acp/auth.php
index c64f27cee5..5c81092a65 100644
--- a/phpBB/includes/acp/auth.php
+++ b/phpBB/includes/acp/auth.php
@@ -22,8 +22,6 @@ if (!defined('IN_PHPBB'))
*/
class auth_admin extends auth
{
- var $option_ids = array();
-
/**
* Init auth settings
*/
@@ -33,7 +31,7 @@ class auth_admin extends auth
if (($this->acl_options = $cache->get('_acl_options')) === false)
{
- $sql = 'SELECT auth_option, is_global, is_local
+ $sql = 'SELECT auth_option_id, auth_option, is_global, is_local
FROM ' . ACL_OPTIONS_TABLE . '
ORDER BY auth_option_id';
$result = $db->sql_query($sql);
@@ -51,25 +49,14 @@ class auth_admin extends auth
{
$this->acl_options['local'][$row['auth_option']] = $local++;
}
+
+ $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id'];
+ $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option'];
}
$db->sql_freeresult($result);
$cache->put('_acl_options', $this->acl_options);
}
-
- if (!sizeof($this->option_ids))
- {
- $sql = 'SELECT auth_option_id, auth_option
- FROM ' . ACL_OPTIONS_TABLE;
- $result = $db->sql_query($sql);
-
- $this->option_ids = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $this->option_ids[$row['auth_option']] = $row['auth_option_id'];
- }
- $db->sql_freeresult($result);
- }
}
/**
@@ -126,7 +113,7 @@ class auth_admin extends auth
while ($row = $db->sql_fetchrow($result))
{
- $forum_ids[] = $row['forum_id'];
+ $forum_ids[] = (int) $row['forum_id'];
}
$db->sql_freeresult($result);
}
@@ -774,7 +761,7 @@ class auth_admin extends auth
$this->acl_clear_prefetch();
// Because we just changed the options and also purged the options cache, we instantly update/regenerate it for later calls to succeed.
- $this->option_ids = $this->acl_options = array();
+ $this->acl_options = array();
$this->__construct();
return true;
@@ -812,7 +799,7 @@ class auth_admin extends auth
$flag = substr($flag, 0, strpos($flag, '_') + 1);
// This ID (the any-flag) is set if one or more permissions are true...
- $any_option_id = (int) $this->option_ids[$flag];
+ $any_option_id = (int) $this->acl_options['id'][$flag];
// Remove any-flag from auth ary
if (isset($auth[$flag]))
@@ -824,7 +811,7 @@ class auth_admin extends auth
$auth_option_ids = array((int)$any_option_id);
foreach ($auth as $auth_option => $auth_setting)
{
- $auth_option_ids[] = (int) $this->option_ids[$auth_option];
+ $auth_option_ids[] = (int) $this->acl_options['id'][$auth_option];
}
$sql = "DELETE FROM $table
@@ -887,7 +874,7 @@ class auth_admin extends auth
{
foreach ($auth as $auth_option => $setting)
{
- $auth_option_id = (int) $this->option_ids[$auth_option];
+ $auth_option_id = (int) $this->acl_options['id'][$auth_option];
if ($setting != ACL_NO)
{
@@ -943,7 +930,7 @@ class auth_admin extends auth
$sql_ary = array();
foreach ($auth as $auth_option => $setting)
{
- $auth_option_id = (int) $this->option_ids[$auth_option];
+ $auth_option_id = (int) $this->acl_options['id'][$auth_option];
if ($setting != ACL_NO)
{
@@ -960,7 +947,7 @@ class auth_admin extends auth
{
$sql_ary[] = array(
'role_id' => (int) $role_id,
- 'auth_option_id' => (int) $this->option_ids[$flag],
+ 'auth_option_id' => (int) $this->acl_options['id'][$flag],
'auth_setting' => ACL_NEVER
);
}
@@ -1237,13 +1224,8 @@ class auth_admin extends auth
return false;
}
- $hold_ary = $this->acl_raw_data($from_user_id, false, false);
+ $hold_ary = $this->acl_raw_data_single_user($from_user_id);
- if (isset($hold_ary[$from_user_id]))
- {
- $hold_ary = $hold_ary[$from_user_id];
- }
-
// Key 0 in $hold_ary are global options, all others are forum_ids
// We disallow copying admin permissions
@@ -1251,12 +1233,12 @@ class auth_admin extends auth
{
if (strpos($opt, 'a_') === 0)
{
- $hold_ary[0][$opt] = ACL_NEVER;
+ $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_NEVER;
}
}
// Force a_switchperm to be allowed
- $hold_ary[0]['a_switchperm'] = ACL_YES;
+ $hold_ary[0][$this->acl_options['id']['a_switchperm']] = ACL_YES;
$user_permissions = $this->build_bitstring($hold_ary);
diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth.php
index ccace05f3a..16accea94e 100644
--- a/phpBB/includes/auth.php
+++ b/phpBB/includes/auth.php
@@ -39,7 +39,7 @@ class auth
if (($this->acl_options = $cache->get('_acl_options')) === false)
{
- $sql = 'SELECT auth_option, is_global, is_local
+ $sql = 'SELECT auth_option_id, auth_option, is_global, is_local
FROM ' . ACL_OPTIONS_TABLE . '
ORDER BY auth_option_id';
$result = $db->sql_query($sql);
@@ -57,6 +57,9 @@ class auth
{
$this->acl_options['local'][$row['auth_option']] = $local++;
}
+
+ $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id'];
+ $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option'];
}
$db->sql_freeresult($result);
@@ -300,7 +303,14 @@ class auth
*/
public function acl_get_list($user_id = false, $opts = false, $forum_id = false)
{
- $hold_ary = $this->acl_raw_data($user_id, $opts, $forum_id);
+ if ($user_id !== false && !is_array($user_id) && $opts === false && $forum_id === false)
+ {
+ $hold_ary = array($user_id => $this->acl_raw_data_single_user($user_id));
+ }
+ else
+ {
+ $hold_ary = $this->acl_raw_data($user_id, $opts, $forum_id);
+ }
$auth_ary = array();
foreach ($hold_ary as $user_id => $forum_ary)
@@ -330,12 +340,7 @@ class auth
// Empty user_permissions
$userdata['user_permissions'] = '';
- $hold_ary = $this->acl_raw_data($userdata['user_id'], false, false);
-
- if (isset($hold_ary[$userdata['user_id']]))
- {
- $hold_ary = $hold_ary[$userdata['user_id']];
- }
+ $hold_ary = $this->acl_raw_data_single_user($userdata['user_id']);
// Key 0 in $hold_ary are global options, all others are forum_ids
@@ -346,42 +351,11 @@ class auth
{
if (strpos($opt, 'a_') === 0)
{
- $hold_ary[0][$opt] = ACL_YES;
+ $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_YES;
}
}
}
- // Sometimes, it can happen $hold_ary holding forums which do not exist.
- // Since this function is not called that often (we are caching the data) we check for this inconsistency.
- $sql = 'SELECT forum_id
- FROM ' . FORUMS_TABLE . '
- WHERE ' . $db->sql_in_set('forum_id', array_keys($hold_ary), false, true);
- $result = $db->sql_query($sql);
-
- $forum_ids = (isset($hold_ary[0])) ? array(0) : array();
- while ($row = $db->sql_fetchrow($result))
- {
- $forum_ids[] = $row['forum_id'];
- }
- $db->sql_freeresult($result);
-
- // Now determine forums which do not exist and remove the unneeded information (for modding purposes it is clearly the wrong place. ;))
- $missing_forums = array_diff(array_keys($hold_ary), $forum_ids);
-
- if (sizeof($missing_forums))
- {
- foreach ($missing_forums as $forum_id)
- {
- unset($hold_ary[$forum_id]);
- }
-
- $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $missing_forums);
- $db->sql_query($sql);
-
- $sql = 'DELETE FROM ' . ACL_USERS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $missing_forums);
- $db->sql_query($sql);
- }
-
$hold_str = $this->build_bitstring($hold_ary);
if ($hold_str)
@@ -418,15 +392,15 @@ class auth
$bitstring = array();
foreach ($this->acl_options[$ary_key] as $opt => $id)
{
- if (isset($auth_ary[$opt]))
+ if (isset($auth_ary[$this->acl_options['id'][$opt]]))
{
- $bitstring[$id] = $auth_ary[$opt];
+ $bitstring[$id] = $auth_ary[$this->acl_options['id'][$opt]];
$option_key = substr($opt, 0, strpos($opt, '_') + 1);
// If one option is allowed, the global permission for this option has to be allowed too
// example: if the user has the a_ permission this means he has one or more a_* permissions
- if ($auth_ary[$opt] == ACL_YES && (!isset($bitstring[$this->acl_options[$ary_key][$option_key]]) || $bitstring[$this->acl_options[$ary_key][$option_key]] == ACL_NEVER))
+ if ($auth_ary[$this->acl_options['id'][$opt]] == ACL_YES && (!isset($bitstring[$this->acl_options[$ary_key][$option_key]]) || $bitstring[$this->acl_options[$ary_key][$option_key]] == ACL_NEVER))
{
$bitstring[$this->acl_options[$ary_key][$option_key]] = ACL_YES;
}
@@ -464,8 +438,31 @@ class auth
*/
public function acl_clear_prefetch($user_id = false)
{
- global $db;
+ global $db, $cache;
+
+ // Rebuild options cache
+ $cache->destroy('_role_cache');
+
+ $sql = 'SELECT *
+ FROM ' . ACL_ROLES_DATA_TABLE . '
+ ORDER BY role_id ASC';
+ $result = $db->sql_query($sql);
+
+ $this->role_cache = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+
+ foreach ($this->role_cache as $role_id => $role_options)
+ {
+ $this->role_cache[$role_id] = serialize($role_options);
+ }
+
+ $cache->put('_role_cache', $this->role_cache);
+ // Now empty user permissions
$where_sql = '';
if ($user_id !== false)
@@ -528,103 +525,71 @@ class auth
$sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : '';
$sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
- $sql_opts = '';
+ $sql_opts = $sql_opts_select = $sql_opts_from = '';
+ $hold_ary = array();
if ($opts !== false)
{
+ $sql_opts_select = ', ao.auth_option';
+ $sql_opts_from = ', ' . ACL_OPTIONS_TABLE . ' ao';
$this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
}
- $hold_ary = array();
+ $sql_ary = array();
- // First grab user settings ... each user has only one setting for each
- // option ... so we shouldn't need any ACL_NEVER checks ... he says ...
- // Grab assigned roles...
- $sql = $db->sql_build_query('SELECT', array(
- 'SELECT' => 'ao.auth_option, a.auth_role_id, r.auth_setting as role_auth_setting, a.user_id, a.forum_id, a.auth_setting',
-
- 'FROM' => array(
- ACL_OPTIONS_TABLE => 'ao',
- ACL_USERS_TABLE => 'a'
- ),
-
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
- 'ON' => 'a.auth_role_id = r.role_id'
- )
- ),
-
- 'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
- ' . (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ // Grab non-role settings - user-specific
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_USERS_TABLE . ' a' . $sql_opts_from . '
+ WHERE a.auth_role_id = 0 ' .
+ (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
$sql_forum
- $sql_opts",
- ));
- $result = $db->sql_query($sql);
+ $sql_opts";
+
+ // Now the role settings - user-specific
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
+ WHERE a.auth_role_id = r.role_id ' .
+ (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts";
- while ($row = $db->sql_fetchrow($result))
+ foreach ($sql_ary as $sql)
{
- $setting = ($row['auth_role_id']) ? $row['role_auth_setting'] : $row['auth_setting'];
- $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $setting;
- }
- $db->sql_freeresult($result);
-
- // Now grab group settings ... ACL_NEVER overrides ACL_YES so act appropriatley
- $sql_ary[] = $db->sql_build_query('SELECT', array(
- 'SELECT' => 'ug.user_id, ao.auth_option, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting',
+ $result = $db->sql_query($sql);
- 'FROM' => array(
- USER_GROUP_TABLE => 'ug',
- ACL_OPTIONS_TABLE => 'ao',
- ACL_GROUPS_TABLE => 'a'
- ),
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']];
+ $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+ }
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
- 'ON' => 'a.auth_role_id = r.role_id'
- )
- ),
+ $sql_ary = array();
- 'WHERE' => 'ao.auth_option_id = a.auth_option_id
+ // Now grab group settings - non-role specific...
+ $sql_ary[] = 'SELECT ug.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug' . $sql_opts_from . '
+ WHERE a.auth_role_id = 0 ' .
+ (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') . '
AND a.group_id = ug.group_id
AND ug.user_pending = 0
' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
$sql_forum
- $sql_opts"
- ));
-
- $sql_ary[] = $db->sql_build_query('SELECT', array(
- 'SELECT' => 'ug.user_id, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting, ao.auth_option' ,
-
- 'FROM' => array(
- ACL_OPTIONS_TABLE => 'ao'
-
- ),
+ $sql_opts";
- 'LEFT_JOIN' => array(
-
- array(
- 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
- 'ON' => 'r.auth_option_id = ao.auth_option_id'
- ),
- array(
- 'FROM' => array(ACL_GROUPS_TABLE => 'a'),
- 'ON' => 'a.auth_role_id = r.role_id'
- ),
- array(
- 'FROM' => array(USER_GROUP_TABLE => 'ug'),
- 'ON' => 'ug.group_id = a.group_id'
- )
-
- ),
-
- 'WHERE' => 'ug.user_pending = 0
+ // Now grab group settings - role specific...
+ $sql_ary[] = 'SELECT ug.user_id, a.forum_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
+ WHERE a.auth_role_id = r.role_id ' .
+ (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') . '
+ AND a.group_id = ug.group_id
+ AND ug.user_pending = 0
' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
$sql_forum
- $sql_opts"
- ));
-
+ $sql_opts";
foreach ($sql_ary as $sql)
{
@@ -632,25 +597,27 @@ class auth
while ($row = $db->sql_fetchrow($result))
{
+ $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']];
+
// @todo: use the ref technique to reduce opcode generation
- if (!isset($hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']]) || (isset($hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']]) && $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] != ACL_NEVER))
+ if (!isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) || (isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) && $hold_ary[$row['user_id']][$row['forum_id']][$option] != ACL_NEVER))
{
- $setting = ($row['auth_role_id']) ? $row['role_auth_setting'] : $row['auth_setting'];
- $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $setting;
-
- // Check for existence of ACL_YES if an option got set to ACL_NEVER
- if ($setting == ACL_NEVER)
+ $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting'];
+
+ // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again)
+ if ($row['auth_setting'] == ACL_NEVER)
{
- $flag = substr($row['auth_option'], 0, strpos($row['auth_option'], '_') + 1);
+ $flag = substr($option, 0, strpos($option, '_') + 1);
if (isset($hold_ary[$row['user_id']][$row['forum_id']][$flag]) && $hold_ary[$row['user_id']][$row['forum_id']][$flag] == ACL_YES)
{
unset($hold_ary[$row['user_id']][$row['forum_id']][$flag]);
-
- if (in_array(ACL_YES, $hold_ary[$row['user_id']][$row['forum_id']]))
+
+/* if (in_array(ACL_YES, $hold_ary[$row['user_id']][$row['forum_id']]))
{
$hold_ary[$row['user_id']][$row['forum_id']][$flag] = ACL_YES;
}
+*/
}
}
}
@@ -672,45 +639,43 @@ class auth
$sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
$sql_opts = '';
+ $hold_ary = $sql_ary = array();
if ($opts !== false)
{
$this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
}
- $hold_ary = array();
-
- // Grab user settings...
- $sql = $db->sql_build_query('SELECT', array(
- 'SELECT' => 'ao.auth_option, a.auth_role_id, r.auth_setting as role_auth_setting, a.user_id, a.forum_id, a.auth_setting',
-
- 'FROM' => array(
- ACL_OPTIONS_TABLE => 'ao',
- ACL_USERS_TABLE => 'a'
- ),
-
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
- 'ON' => 'a.auth_role_id = r.role_id'
- ),
- ),
-
- 'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
- ' . (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ // Grab user settings - non-role specific...
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option
+ FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = 0
+ AND a.auth_option_id = ao.auth_option_id ' .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
$sql_forum
- $sql_opts",
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
- 'ORDER_BY' => 'a.forum_id, ao.auth_option'
- ));
- $result = $db->sql_query($sql);
+ // Now the role settings - user-specific
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id, ao.auth_option
+ FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = r.role_id
+ AND r.auth_option_id = ao.auth_option_id ' .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
- while ($row = $db->sql_fetchrow($result))
+ foreach ($sql_ary as $sql)
{
- $setting = ($row['auth_role_id']) ? $row['role_auth_setting'] : $row['auth_setting'];
- $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $setting;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
}
- $db->sql_freeresult($result);
return $hold_ary;
}
@@ -726,43 +691,123 @@ class auth
$sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
$sql_opts = '';
+ $hold_ary = $sql_ary = array();
if ($opts !== false)
{
$this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
}
- $hold_ary = array();
+ // Grab group settings - non-role specific...
+ $sql_ary[] = 'SELECT a.group_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = 0
+ AND a.auth_option_id = ao.auth_option_id ' .
+ (($sql_group) ? 'AND a.' . $sql_group : '') . "
+ $sql_forum
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
+
+ // Now grab group settings - role specific...
+ $sql_ary[] = 'SELECT a.group_id, a.forum_id, r.auth_setting, r.auth_option_id, ao.auth_option
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = r.role_id
+ AND r.auth_option_id = ao.auth_option_id ' .
+ (($sql_group) ? 'AND a.' . $sql_group : '') . "
+ $sql_forum
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
+
+ foreach ($sql_ary as $sql)
+ {
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $hold_ary[$row['group_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+ }
+
+ return $hold_ary;
+ }
+
+ /**
+ * Get raw acl data based on user for caching user_permissions
+ * This function returns the same data as acl_raw_data(), but without the user id as the first key within the array.
+ */
+ public function acl_raw_data_single_user($user_id)
+ {
+ global $db, $cache;
- // Grab group settings...
- $sql = $db->sql_build_query('SELECT', array(
- 'SELECT' => 'a.group_id, ao.auth_option, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting',
+ // Check if the role-cache is there
+ if (($this->role_cache = $cache->get('_role_cache')) === false)
+ {
+ $this->role_cache = array();
- 'FROM' => array(
- ACL_OPTIONS_TABLE => 'ao',
- ACL_GROUPS_TABLE => 'a'
- ),
+ // We pre-fetch roles
+ $sql = 'SELECT *
+ FROM ' . ACL_ROLES_DATA_TABLE . '
+ ORDER BY role_id ASC';
+ $result = $db->sql_query($sql);
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
- 'ON' => 'a.auth_role_id = r.role_id'
- ),
- ),
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
- 'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
- ' . (($sql_group) ? 'AND a.' . $sql_group : '') . "
- $sql_forum
- $sql_opts",
+ foreach ($this->role_cache as $role_id => $role_options)
+ {
+ $this->role_cache[$role_id] = serialize($role_options);
+ }
- 'ORDER_BY' => 'a.forum_id, ao.auth_option'
- ));
+ $cache->put('_role_cache', $this->role_cache);
+ }
+
+ $hold_ary = array();
+
+ // Grab user-specific permission settings
+ $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
+ FROM ' . ACL_USERS_TABLE . '
+ WHERE user_id = ' . $user_id;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
- $setting = ($row['auth_role_id']) ? $row['role_auth_setting'] : $row['auth_setting'];
- $hold_ary[$row['group_id']][$row['forum_id']][$row['auth_option']] = $setting;
+ // If a role is assigned, assign all options included within this role. Else, only set this one option.
+ if ($row['auth_role_id'])
+ {
+ $hold_ary[$row['forum_id']] = (empty($hold_ary[$row['forum_id']])) ? unserialize($this->role_cache[$row['auth_role_id']]) : $hold_ary[$row['forum_id']] + unserialize($this->role_cache[$row['auth_role_id']]);
+ }
+ else
+ {
+ $hold_ary[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting'];
+ }
+ }
+ $db->sql_freeresult($result);
+
+ // Now grab group-specific permission settings
+ $sql = 'SELECT a.forum_id, a.auth_option_id, a.auth_role_id, a.auth_setting
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug
+ WHERE a.group_id = ug.group_id
+ AND ug.user_pending = 0
+ AND ug.user_id = ' . $user_id;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if (!$row['auth_role_id'])
+ {
+ $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $row['auth_option_id'], $row['auth_setting']);
+ }
+ else
+ {
+ foreach (unserialize($this->role_cache[$row['auth_role_id']]) as $option_id => $setting)
+ {
+ $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $option_id, $setting);
+ }
+ }
}
$db->sql_freeresult($result);
@@ -770,6 +815,35 @@ class auth
}
/**
+ * Private function snippet for setting a specific piece of the hold_ary
+ */
+ private function _set_group_hold_ary(&$hold_ary, $option_id, $setting)
+ {
+ if (!isset($hold_ary[$option_id]) || (isset($hold_ary[$option_id]) && $hold_ary[$option_id] != ACL_NEVER))
+ {
+ $hold_ary[$option_id] = $setting;
+
+ // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again)
+ if ($setting == ACL_NEVER)
+ {
+ $flag = substr($this->acl_options['option'][$option_id], 0, strpos($this->acl_options['option'][$option_id], '_') + 1);
+ $flag = (int) $this->acl_options['id'][$flag];
+
+ if (isset($hold_ary[$flag]) && $hold_ary[$flag] == ACL_YES)
+ {
+ unset($hold_ary[$flag]);
+
+/* This is uncommented, because i suspect this being slightly wrong due to mixed permission classes being possible
+ if (in_array(ACL_YES, $hold_ary))
+ {
+ $hold_ary[$flag] = ACL_YES;
+ }*/
+ }
+ }
+ }
+ }
+
+ /**
* Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
*/
public function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0)
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index ee25c9fac7..b580edb693 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -199,6 +199,26 @@ function unique_id($extra = 'c')
}
/**
+* Return formatted string for filesizes
+*/
+function get_formatted_filesize($bytes, $add_size_lang = true)
+{
+ global $user;
+
+ if ($bytes >= pow(2, 20))
+ {
+ return ($add_size_lang) ? round($bytes / 1024 / 1024, 2) . ' ' . $user->lang['MIB'] : round($bytes / 1024 / 1024, 2);
+ }
+
+ if ($bytes >= pow(2, 10))
+ {
+ return ($add_size_lang) ? round($bytes / 1024, 2) . ' ' . $user->lang['KIB'] : round($bytes / 1024, 2);
+ }
+
+ return ($add_size_lang) ? ($bytes) . ' ' . $user->lang['BYTES'] : ($bytes);
+}
+
+/**
* Determine whether we are approaching the maximum execution time. Should be called once
* at the beginning of the script in which it's used.
* @return bool Either true if the maximum execution time is nearly reached, or false
@@ -2643,7 +2663,7 @@ function get_preg_expression($mode)
switch ($mode)
{
case 'email':
- return '[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*[a-z]+';
+ return '[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.(?:[a-z0-9\-]+\.)*[a-z]+';
break;
case 'bbcode_htm':
@@ -3343,7 +3363,7 @@ function page_footer($run_cron = true)
{
global $base_memory_usage;
$memory_usage -= $base_memory_usage;
- $memory_usage = ($memory_usage >= 1048576) ? round((round($memory_usage / 1048576 * 100) / 100), 2) . ' ' . $user->lang['MB'] : (($memory_usage >= 1024) ? round((round($memory_usage / 1024 * 100) / 100), 2) . ' ' . $user->lang['KB'] : $memory_usage . ' ' . $user->lang['BYTES']);
+ $memory_usage = get_formatted_filesize($memory_usage);
$debug_output .= ' | Memory Usage: ' . $memory_usage;
}
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 7562d062e0..1e85adff9b 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -196,7 +196,7 @@ function size_select_options($size_compare)
{
global $user;
- $size_types_text = array($user->lang['BYTES'], $user->lang['KB'], $user->lang['MB']);
+ $size_types_text = array($user->lang['BYTES'], $user->lang['KIB'], $user->lang['MIB']);
$size_types = array('b', 'kb', 'mb');
$s_size_options = '';
@@ -2859,14 +2859,7 @@ function get_database_size()
break;
}
- if ($database_size !== false)
- {
- $database_size = ($database_size >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($database_size / 1048576)) : (($database_size >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($database_size / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $database_size));
- }
- else
- {
- $database_size = $user->lang['NOT_AVAILABLE'];
- }
+ $database_size = ($database_size !== false) ? get_formatted_filesize($database_size) : $user->lang['NOT_AVAILABLE'];
return $database_size;
}
@@ -2979,6 +2972,29 @@ function tidy_database()
{
global $db;
+ // Here we check permission consistency
+
+ // Sometimes, it can happen permission tables having forums listed which do not exist
+ $sql = 'SELECT forum_id
+ FROM ' . FORUMS_TABLE;
+ $result = $db->sql_query($sql);
+
+ $forum_ids = array(0);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $forum_ids[] = $row['forum_id'];
+ }
+ $db->sql_freeresult($result);
+
+ // Delete those rows from the acl tables not having listed the forums above
+ $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
+ WHERE ' . $db->sql_in_set('forum_id', $forum_ids, true);
+ $db->sql_query($sql);
+
+ $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
+ WHERE ' . $db->sql_in_set('forum_id', $forum_ids, true);
+ $db->sql_query($sql);
+
set_config('database_last_gc', time(), true);
}
diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php
index 5f148da2f8..8d4a75e2f7 100644
--- a/phpBB/includes/functions_content.php
+++ b/phpBB/includes/functions_content.php
@@ -824,7 +824,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
$filesize = $attachment['filesize'];
$size_lang = ($filesize >= 1048576) ? $user->lang['MB'] : ( ($filesize >= 1024) ? $user->lang['KB'] : $user->lang['BYTES'] );
- $filesize = ($filesize >= 1048576) ? round((round($filesize / 1048576 * 100) / 100), 2) : (($filesize >= 1024) ? round((round($filesize / 1024 * 100) / 100), 2) : $filesize);
+ $filesize = get_formatted_filesize($filesize, false);
$comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php
index b3f7752785..bd344a801d 100644
--- a/phpBB/includes/functions_profile_fields.php
+++ b/phpBB/includes/functions_profile_fields.php
@@ -873,13 +873,13 @@ class custom_profile
}
else
{
- $var = request_var($var_name, $profile_row['field_default_value']);
+ $var = request_var($var_name, (int) $profile_row['field_default_value']);
}
break;
case FIELD_STRING:
case FIELD_TEXT:
- $var = utf8_normalize_nfc(request_var($var_name, $profile_row['field_default_value'], true));
+ $var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true));
break;
case FIELD_INT:
@@ -889,10 +889,14 @@ class custom_profile
}
else
{
- $var = request_var($var_name, $profile_row['field_default_value']);
+ $var = request_var($var_name, (int) $profile_row['field_default_value']);
}
break;
+ case FIELD_DROPDOWN:
+ $var = request_var($var_name, (int) $profile_row['field_default_value']);
+ break;
+
default:
$var = request_var($var_name, $profile_row['field_default_value']);
break;
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php
index f28e299f10..6301896ff9 100644
--- a/phpBB/includes/functions_upload.php
+++ b/phpBB/includes/functions_upload.php
@@ -387,7 +387,7 @@ class filespec
if ($this->upload->max_filesize && ($this->get('filesize') > $this->upload->max_filesize || $this->filesize == 0))
{
$size_lang = ($this->upload->max_filesize >= 1048576) ? $user->lang['MB'] : (($this->upload->max_filesize >= 1024) ? $user->lang['KB'] : $user->lang['BYTES'] );
- $max_filesize = ($this->upload->max_filesize >= 1048576) ? round($this->upload->max_filesize / 1048576 * 100) / 100 : (($this->upload->max_filesize >= 1024) ? round($this->upload->max_filesize / 1024 * 100) / 100 : $this->upload->max_filesize);
+ $max_filesize = get_formatted_filesize($this->upload->max_filesize, false);
$this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
@@ -778,7 +778,7 @@ class fileupload
case 2:
$size_lang = ($this->max_filesize >= 1048576) ? $user->lang['MB'] : (($this->max_filesize >= 1024) ? $user->lang['KB'] : $user->lang['BYTES'] );
- $max_filesize = ($this->max_filesize >= 1048576) ? round($this->max_filesize / 1048576 * 100) / 100 : (($this->max_filesize >= 1024) ? round($this->max_filesize / 1024 * 100) / 100 : $this->max_filesize);
+ $max_filesize = get_formatted_filesize($this->max_filesize, false);
$error = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
break;
@@ -814,7 +814,7 @@ class fileupload
if ($this->max_filesize && ($file->get('filesize') > $this->max_filesize || $file->get('filesize') == 0))
{
$size_lang = ($this->max_filesize >= 1048576) ? $user->lang['MB'] : (($this->max_filesize >= 1024) ? $user->lang['KB'] : $user->lang['BYTES'] );
- $max_filesize = ($this->max_filesize >= 1048576) ? round($this->max_filesize / 1048576 * 100) / 100 : (($this->max_filesize >= 1024) ? round($this->max_filesize / 1024 * 100) / 100 : $this->max_filesize);
+ $max_filesize = get_formatted_filesize($this->max_filesize, false);
$file->error[] = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
}
diff --git a/phpBB/includes/ucp/ucp_attachments.php b/phpBB/includes/ucp/ucp_attachments.php
index 2732879913..5685702de2 100644
--- a/phpBB/includes/ucp/ucp_attachments.php
+++ b/phpBB/includes/ucp/ucp_attachments.php
@@ -150,7 +150,7 @@ class ucp_attachments
'FILENAME' => $row['real_filename'],
'COMMENT' => bbcode_nl2br($row['attach_comment']),
'EXTENSION' => $row['extension'],
- 'SIZE' => ($row['filesize'] >= 1048576) ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : (($row['filesize'] >= 1024) ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']),
+ 'SIZE' => get_formatted_filesize($row['filesize']),
'DOWNLOAD_COUNT' => $row['download_count'],
'POST_TIME' => $user->format_date($row['filetime']),
'TOPIC_TITLE' => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php
index d6e7a30176..d884e0d571 100644
--- a/phpBB/includes/ucp/ucp_groups.php
+++ b/phpBB/includes/ucp/ucp_groups.php
@@ -709,8 +709,8 @@ class ucp_groups
'U_SWATCH' => append_sid("{$phpbb_root_path}adm/swatch.$phpEx", 'form=ucp&amp;name=group_colour'),
'S_UCP_ACTION' => $this->u_action . "&amp;action=$action&amp;g=$group_id",
- 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))
- );
+ 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024),
+ ));
break;
@@ -1014,6 +1014,8 @@ class ucp_groups
{
trigger_error($user->lang[$error] . $return_page);
}
+
+ trigger_error($user->lang['GROUP_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
}
else
{
@@ -1028,7 +1030,7 @@ class ucp_groups
confirm_box(false, sprintf($user->lang['GROUP_CONFIRM_ADD_USER' . ((sizeof($name_ary) == 1) ? '' : 'S')], implode(', ', $name_ary)), build_hidden_fields($s_hidden_fields));
}
- trigger_error($user->lang['GROUP_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
+ trigger_error($user->lang['NO_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
break;
diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php
index a223d5232e..65fef2d267 100644
--- a/phpBB/includes/ucp/ucp_profile.php
+++ b/phpBB/includes/ucp/ucp_profile.php
@@ -594,8 +594,8 @@ class ucp_profile
'S_FORM_ENCTYPE' => ($can_upload) ? ' enctype="multipart/form-data"' : '',
- 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),)
- );
+ 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024),
+ ));
if ($display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'])
{