diff options
-rw-r--r-- | phpBB/adm/style/acp_attachments.html | 8 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_attachments.php | 28 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_email.php | 9 | ||||
-rw-r--r-- | phpBB/includes/auth.php | 240 | ||||
-rw-r--r-- | phpBB/includes/db/mysql.php | 4 | ||||
-rw-r--r-- | phpBB/includes/db/mysql4.php | 4 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 115 | ||||
-rw-r--r-- | phpBB/includes/functions_module.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 87 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_queue.php | 4 | ||||
-rw-r--r-- | phpBB/includes/session.php | 21 | ||||
-rw-r--r-- | phpBB/posting.php | 90 |
13 files changed, 420 insertions, 194 deletions
diff --git a/phpBB/adm/style/acp_attachments.html b/phpBB/adm/style/acp_attachments.html index 9ad06a98b3..ba29e4852c 100644 --- a/phpBB/adm/style/acp_attachments.html +++ b/phpBB/adm/style/acp_attachments.html @@ -46,15 +46,15 @@ </dl> <dl> <dt><label for="attach_quota">{L_ATTACH_QUOTA}:</label><br /><span>{L_ATTACH_QUOTA_EXPLAIN}</span></dt> - <dd><input type="text" id="attach_quota" size="8" maxlength="15" name="attachment_quota" value="{ATTACHMENT_QUOTA}" /> {S_QUOTA_SELECT}</dd> + <dd><input type="text" id="attach_quota" size="8" maxlength="15" name="attachment_quota" value="{ATTACHMENT_QUOTA}" /> <select name="quota_size">{S_QUOTA_SIZE_OPTIONS}</select></dd> </dl> <dl> <dt><label for="max_filesize">{L_ATTACH_MAX_FILESIZE}:</label><br /><span>{L_ATTACH_MAX_FILESIZE_EXPLAIN}</span></dt> - <dd><input type="text" id="max_filesize" size="8" maxlength="15" name="max_filesize" value="{MAX_FILESIZE}" /> {S_MAX_FILESIZE_SELECT}</dd> + <dd><input type="text" id="max_filesize" size="8" maxlength="15" name="max_filesize" value="{MAX_FILESIZE}" /> <select name="size">{S_MAX_FILESIZE_OPTIONS}</select></dd> </dl> <dl> <dt><label for="max_pm_filesize">{L_ATTACH_MAX_PM_FILESIZE}:</label><br /><span>{L_ATTACH_MAX_PM_FILESIZE_EXPLAIN}</span></dt> - <dd><input type="text" id="max_pm_filesize" size="8" maxlength="15" name="max_filesize_pm" value="{MAX_PM_FILESIZE}" /> {S_MAX_PM_FILESIZE_SELECT}</dd> + <dd><input type="text" id="max_pm_filesize" size="8" maxlength="15" name="max_filesize_pm" value="{MAX_PM_FILESIZE}" /> <select name="pm_size">{S_MAX_PM_FILESIZE_OPTIONS}</select></dd> </dl> <dl> <dt><label for="max_attachments">{L_MAX_ATTACHMENTS}:</label></dt> @@ -245,7 +245,7 @@ </dl> <dl> <dt><label for="extgroup_filesize">{L_MAX_EXTGROUP_FILESIZE}:</label></dt> - <dd><input type="text" id="extgroup_filesize" size="3" maxlength="15" name="max_filesize" value="{EXTGROUP_FILESIZE}" /> {S_EXT_GROUP_SIZE}</dd> + <dd><input type="text" id="extgroup_filesize" size="3" maxlength="15" name="max_filesize" value="{EXTGROUP_FILESIZE}" /> <select name="size_select">{S_EXT_GROUP_SIZE_OPTIONS}</select></dd> </dl> <dl> <dt><label for="assigned_extensions">{L_ASSIGNED_EXTENSIONS}:</label></dt> diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php index e14053fe34..1dbd001cb6 100644 --- a/phpBB/includes/acp/acp_attachments.php +++ b/phpBB/includes/acp/acp_attachments.php @@ -139,9 +139,9 @@ class acp_attachments // We strip eventually manual added convert program, we only want the patch $new['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $new['img_imagick']); - $select_size_mode = size_select('size', $size); - $select_quota_size_mode = size_select('quota_size', $quota_size); - $select_pm_size_mode = size_select('pm_size', $pm_size); + $s_size_options = size_select_options($size); + $s_quota_size_options = size_select_options($quota_size); + $s_pm_size_options = size_select_options($pm_size); $sql = 'SELECT group_name, cat_id FROM ' . EXTENSION_GROUPS_TABLE . ' @@ -187,9 +187,9 @@ class acp_attachments 'U_SEARCH_IMAGICK' => $u_action . '&action=imgmagick', - 'S_QUOTA_SELECT' => $select_quota_size_mode, - 'S_MAX_FILESIZE_SELECT' => $select_size_mode, - 'S_MAX_PM_FILESIZE_SELECT' => $select_pm_size_mode, + 'S_QUOTA_SIZE_OPTIONS' => $s_quota_size_options, + 'S_MAX_FILESIZE_OPTIONS' => $s_size_options, + 'S_MAX_PM_FILESIZE_OPTIONS' => $s_pm_size_options, 'S_THUMBNAIL_SUPPORT' => (!$new['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) ? false : true, ) ); @@ -653,14 +653,14 @@ class acp_attachments 'EXTGROUP_FILESIZE' => $ext_group_row['max_filesize'], 'ASSIGNED_EXTENSIONS' => $assigned_extensions, - 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'), - 'S_DOWNLOAD_SELECT' => $this->download_select('download_mode', $group_id, 'download_mode'), - 'S_EXT_GROUP_SIZE' => size_select('size_select', $size_format), - 'S_EXTENSION_OPTIONS' => $s_extension_options, - 'S_FILENAME_LIST' => $filename_list, - 'S_EDIT_GROUP' => true, - 'S_NO_IMAGE' => $no_image_select, - 'S_FORUM_IDS' => (sizeof($forum_ids)) ? true : false, + 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'), + 'S_DOWNLOAD_SELECT' => $this->download_select('download_mode', $group_id, 'download_mode'), + 'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format), + 'S_EXTENSION_OPTIONS' => $s_extension_options, + 'S_FILENAME_LIST' => $filename_list, + 'S_EDIT_GROUP' => true, + 'S_NO_IMAGE' => $no_image_select, + 'S_FORUM_IDS' => (sizeof($forum_ids)) ? true : false, 'U_EXTENSIONS' => $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=extensions", diff --git a/phpBB/includes/acp/acp_email.php b/phpBB/includes/acp/acp_email.php index db49abb852..597d8a1115 100644 --- a/phpBB/includes/acp/acp_email.php +++ b/phpBB/includes/acp/acp_email.php @@ -197,13 +197,8 @@ class acp_email $result = $db->sql_query($sql); $select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>'; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($group_id == $row['group_id']) ? ' selected="selected"' : ''; - $select_list .= '<option value = "' . $row['group_id'] . '"' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . $selected . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>'; - } - $db->sql_freeresult($result); - + $select_list .= group_select_options($group_id); + $s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>'; diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth.php index 123180f081..658f4ae78d 100644 --- a/phpBB/includes/auth.php +++ b/phpBB/includes/auth.php @@ -65,13 +65,13 @@ class auth { $i = 0; + if (!isset($this->acl[$f])) + { + $this->acl[$f] = ''; + } + while ($subseq = substr($seq, $i, 6)) { - if (!isset($this->acl[$f])) - { - $this->acl[$f] = ''; - } - // We put the original bitstring into the acl array $this->acl[$f] .= str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT); $i += 6; @@ -157,6 +157,32 @@ class auth $opt = substr($opt, 1); } + // If we retrieve a list of forums not having permissions in, we need to get every forum_id + if ($negate) + { + static $acl_forum_ids; + + if (!isset($acl_forum_ids)) + { + global $db; + + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE; + + if (sizeof($this->acl)) + { + $sql .= ' WHERE forum_id NOT IN (' . implode(', ', array_keys($this->acl)) . ')'; + } + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $acl_forum_ids[] = $row['forum_id']; + } + $db->sql_freeresult($result); + } + } + if (isset($this->acl_options['local'][$opt])) { foreach ($this->acl as $f => $bitstring) @@ -183,6 +209,15 @@ class auth } } + // If we get forum_ids not having this permission, we need to fill the remaining parts + if ($negate && sizeof($acl_forum_ids)) + { + foreach ($acl_forum_ids as $f) + { + $acl_f[$f][$opt] = 1; + } + } + return $acl_f; } @@ -542,13 +577,13 @@ class auth_admin extends auth * @param mixed $forum_id forum_ids to search for. Defining a forum id also means getting local settings (required for the modes forum and mod_local) * @param string $auth_option if mode is 'custom' the auth_option defines the permission setting to look after * @param local|global $scope if mode is 'custom' the scope defines the permission scope. If local, a forum_id is additionally required + * @param ACL_NO|ACL_UNSET|ACL_YES $acl_fill defines the mode those permissions not set are getting filled with */ - function get_mask($mode, $user_id = false, $group_id = false, $forum_id = false, $auth_option = false, $scope = false) + function get_mask($mode, $user_id = false, $group_id = false, $forum_id = false, $auth_option = false, $scope = false, $acl_fill = ACL_NO) { global $db; $hold_ary = array(); - $auth_option = ''; switch ($mode) { @@ -566,7 +601,7 @@ class auth_admin extends auth } else { - $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, $auth_option . '%') : $this->acl_raw_data($user_id, $auth_option . '%'); + $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, $auth_option . '%', ($scope == 'global') ? 0 : false) : $this->acl_raw_data($user_id, $auth_option . '%', ($scope == 'global') ? 0 : false); } break; @@ -624,7 +659,7 @@ class auth_admin extends auth return array(); } - $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, 'm_%') : $this->acl_raw_data($user_id, 'm_%'); + $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, 'm_%', 0) : $this->acl_raw_data($user_id, 'm_%', 0); $auth_option = 'm_'; $scope = 'global'; @@ -675,11 +710,11 @@ class auth_admin extends auth // Now switch back to keys if (sizeof($compare_options)) { - $compare_options = array_combine($compare_options, array_fill(1, sizeof($compare_options), 0)); + $compare_options = array_combine($compare_options, array_fill(1, sizeof($compare_options), $acl_fill)); } // Defining the user-function here to save some memory - $return_zero = create_function('$value', 'return 0;'); + $return_acl_fill = create_function('$value', 'return ' . $acl_fill . ';'); // Actually fill the gaps if (sizeof($hold_ary)) @@ -693,7 +728,7 @@ class auth_admin extends auth // The differences get merged into $hold_ary (all permissions having ACL_NO set) $hold_ary[$ug_id][$id] = array_merge($options, - array_map($return_zero, + array_map($return_acl_fill, array_flip( array_diff( array_keys($compare_options), array_keys($options) @@ -819,6 +854,187 @@ class auth_admin extends auth return true; } + /** + * Set a user or group ACL record + */ + function acl_set($ug_type, &$forum_id, &$ug_id, &$auth) + { + global $db; + + // One or more forums + if (!is_array($forum_id)) + { + $forum_id = array($forum_id); + } + + // Set any flags as required + foreach ($auth as $auth_option => $setting) + { + $flag = substr($auth_option, 0, strpos($auth_option, '_') + 1); + + if (!isset($auth[$flag]) || !$auth[$flag]) + { + $auth[$flag] = $setting; + } + } + + $sql = 'SELECT auth_option_id, auth_option + FROM ' . ACL_OPTIONS_TABLE; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $option_ids[$row['auth_option']] = $row['auth_option_id']; + } + $db->sql_freeresult($result); + + $sql_forum = 'AND a.forum_id IN (' . implode(', ', array_map('intval', $forum_id)) . ')'; + + if ($ug_type == 'user') + { + $sql = 'SELECT o.auth_option_id, o.auth_option, a.forum_id, a.auth_setting + FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . " o + WHERE a.auth_option_id = o.auth_option_id + $sql_forum + AND a.user_id = $ug_id"; + } + else + { + $sql = 'SELECT o.auth_option_id, o.auth_option, a.forum_id, a.auth_setting + FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . " o + WHERE a.auth_option_id = o.auth_option_id + $sql_forum + AND a.group_id = $ug_id"; + } + $result = $db->sql_query($sql); + + $cur_auth = array(); + while ($row = $db->sql_fetchrow($result)) + { + $cur_auth[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting']; + } + $db->sql_freeresult($result); + + $table = ($ug_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE; + $id_field = $ug_type . '_id'; + + $sql_ary = array(); + foreach ($forum_id as $forum) + { + foreach ($auth as $auth_option => $setting) + { + $auth_option_id = $option_ids[$auth_option]; + + switch ($setting) + { + case ACL_UNSET: + if (isset($cur_auth[$forum][$auth_option_id])) + { + $sql_ary['delete'][] = "DELETE FROM $table + WHERE forum_id = $forum + AND auth_option_id = $auth_option_id + AND $id_field = $ug_id"; + } + break; + + default: + if (!isset($cur_auth[$forum][$auth_option_id])) + { + $sql_ary['insert'][] = "$ug_id, $forum, $auth_option_id, $setting"; + } + else if ($cur_auth[$forum][$auth_option_id] != $setting) + { + $sql_ary['update'][] = "UPDATE " . $table . " + SET auth_setting = $setting + WHERE $id_field = $ug_id + AND forum_id = $forum + AND auth_option_id = $auth_option_id"; + } + } + } + } + unset($cur_auth); + + $sql = ''; + foreach ($sql_ary as $sql_type => $sql_subary) + { + switch ($sql_type) + { + case 'insert': + switch (SQL_LAYER) + { + case 'mysql': + $sql = 'VALUES ' . implode(', ', preg_replace('#^(.*?)$#', '(\1)', $sql_subary)); + break; + + case 'mysql4': + case 'mysqli': + case 'mssql': + case 'mssql_odbc': + case 'sqlite': + $sql = implode(' UNION ALL ', preg_replace('#^(.*?)$#', 'SELECT \1', $sql_subary)); + break; + + default: + foreach ($sql_subary as $sql) + { + $sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) VALUES ($sql)"; + $db->sql_query($sql); + $sql = ''; + } + } + + if ($sql != '') + { + $sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) $sql"; + $db->sql_query($sql); + } + break; + + case 'update': + case 'delete': + foreach ($sql_subary as $sql) + { + $db->sql_query($sql); + } + break; + } + unset($sql_ary[$sql_type]); + } + unset($sql_ary); + + $this->acl_clear_prefetch(); + } + + /** + * Remove local permission + */ + function acl_delete($mode, &$forum_id, &$ug_id, $auth_ids = false) + { + global $db; + + // One or more forums + if (!is_array($forum_id)) + { + $forum_id = array($forum_id); + } + + $auth_sql = ($auth_ids) ? ' AND auth_option_id IN (' . implode(', ', array_map('intval', $auth_ids)) . ')' : ''; + + $table = ($mode == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE; + $id_field = $mode . '_id'; + + foreach ($forum_id as $forum) + { + $sql = "DELETE FROM $table + WHERE $id_field = $ug_id + AND forum_id = $forum + $auth_sql"; + $db->sql_query($sql); + } + + $this->acl_clear_prefetch(); + } } ?>
\ No newline at end of file diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 182ed52fdd..57aad449d4 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -286,8 +286,8 @@ class dbal_mysql extends dbal function _sql_error() { return array( - 'message' => @mysql_error(), - 'code' => @mysql_errno() + 'message' => @mysql_error($this->db_connect_id), + 'code' => @mysql_errno($this->db_connect_id) ); } diff --git a/phpBB/includes/db/mysql4.php b/phpBB/includes/db/mysql4.php index 143996a028..9db47f37ee 100644 --- a/phpBB/includes/db/mysql4.php +++ b/phpBB/includes/db/mysql4.php @@ -289,8 +289,8 @@ class dbal_mysql4 extends dbal function _sql_error() { return array( - 'message' => @mysql_error(), - 'code' => @mysql_errno() + 'message' => @mysql_error($this->db_connect_id), + 'code' => @mysql_errno($this->db_connect_id) ); } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 761c047d7f..ae197be1c7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2073,7 +2073,7 @@ function page_footer() } else if (time() - $config['search_last_gc'] > $config['search_gc']) { - // Tidy the cache + // Tidy the search $cron_type = 'tidy_search'; } /** diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 980880874d..73869dcb88 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -178,24 +178,45 @@ function make_forum_select($select_id = false, $ignore_id = false, $ignore_acl = /** * Generate size select form */ -function size_select($select_name, $size_compare) +function size_select_options($size_compare) { global $user; $size_types_text = array($user->lang['BYTES'], $user->lang['KB'], $user->lang['MB']); $size_types = array('b', 'kb', 'mb'); - $select_field = '<select name="' . $select_name . '">'; - + $s_size_options = ''; + for ($i = 0, $size = sizeof($size_types_text); $i < $size; $i++) { $selected = ($size_compare == $size_types[$i]) ? ' selected="selected"' : ''; - $select_field .= '<option value="' . $size_types[$i] . '"' . $selected . '>' . $size_types_text[$i] . '</option>'; + $s_size_options .= '<option value="' . $size_types[$i] . '"' . $selected . '>' . $size_types_text[$i] . '</option>'; } - $select_field .= '</select>'; + return $s_size_options; +} + +/** +* Generate list of groups +*/ +function group_select_options($group_id) +{ + global $db, $user; - return ($select_field); + $sql = 'SELECT group_id, group_name, group_type + FROM ' . GROUPS_TABLE . ' + ORDER BY group_type DESC, group_name ASC'; + $result = $db->sql_query($sql); + + $s_group_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($row['group_id'] == $group_id) ? ' selected="selected"' : ''; + $s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '"' . $selected . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>'; + } + $db->sql_freeresult($result); + + return $s_group_options; } /** @@ -2061,88 +2082,6 @@ function view_warned_users(&$users, &$user_count, $limit = 0, $offset = 0, $limi } /** -* Update Post Informations (First/Last Post in topic/forum) -* Should be used instead of sync() if only the last post informations are out of sync... faster -*/ -function update_post_information($type, $ids) -{ - global $db; - - if (!is_array($ids)) - { - $ids = array($ids); - } - - $update_sql = $empty_forums = array(); - - $sql = 'SELECT ' . $type . '_id, MAX(post_id) as last_post_id - FROM ' . POSTS_TABLE . " - WHERE post_approved = 1 - AND {$type}_id IN (" . implode(', ', $ids) . ") - GROUP BY {$type}_id"; - $result = $db->sql_query($sql); - - $last_post_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - if ($type == 'forum') - { - $empty_forums[] = $row['forum_id']; - } - - $last_post_ids[] = $row['last_post_id']; - } - $db->sql_freeresult($result); - - if ($type == 'forum') - { - $empty_forums = array_diff($ids, $empty_forums); - - foreach ($empty_forums as $void => $forum_id) - { - $update_sql[$forum_id][] = 'forum_last_post_id = 0'; - $update_sql[$forum_id][] = 'forum_last_post_time = 0'; - $update_sql[$forum_id][] = 'forum_last_poster_id = 0'; - $update_sql[$forum_id][] = "forum_last_poster_name = ''"; - } - } - - if (sizeof($last_post_ids)) - { - $sql = 'SELECT p.' . $type . '_id, p.post_id, p.post_time, p.poster_id, p.post_username, u.user_id, u.username - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_id IN (' . implode(', ', $last_post_ids) . ')'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $update_sql[$row["{$type}_id"]][] = $type . '_last_post_id = ' . (int) $row['post_id']; - $update_sql[$row["{$type}_id"]][] = $type . '_last_post_time = ' . (int) $row['post_time']; - $update_sql[$row["{$type}_id"]][] = $type . '_last_poster_id = ' . (int) $row['poster_id']; - $update_sql[$row["{$type}_id"]][] = "{$type}_last_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'"; - } - $db->sql_freeresult($result); - } - unset($empty_forums, $ids, $last_post_ids); - - if (!sizeof($update_sql)) - { - return; - } - - $table = ($type == 'forum') ? FORUMS_TABLE : TOPICS_TABLE; - - foreach ($update_sql as $update_id => $update_sql_ary) - { - $sql = "UPDATE $table - SET " . implode(', ', $update_sql_ary) . " - WHERE {$type}_id = $update_id"; - $db->sql_query($sql); - } -} - -/** * Get database size * Currently only mysql and mssql are supported */ diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ffe3b2c262..45155b1d24 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -146,7 +146,7 @@ class p_master } // Module there - if ($temp_row['module_name']) + if ($temp_row['module_name'] && $temp_row['module_enabled']) { $empty_category = false; break; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index f44ac0ce04..40f17a33e9 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -90,48 +90,85 @@ function generate_smilies($mode, $forum_id) } /** -* Update Last Post Informations +* Update Post Informations (First/Last Post in topic/forum) +* Should be used instead of sync() if only the last post informations are out of sync... faster */ -function update_last_post_information($type, $id) +function update_post_information($type, $ids) { global $db; - $update_sql = array(); + if (!is_array($ids)) + { + $ids = array($ids); + } - $sql = 'SELECT MAX(p.post_id) as last_post_id - FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t - WHERE p.topic_id = t.topic_id - AND p.post_approved = 1 - AND t.topic_approved = 1 - AND p.{$type}_id = $id"; + $update_sql = $empty_forums = array(); + $sql = 'SELECT ' . $type . '_id, MAX(post_id) as last_post_id + FROM ' . POSTS_TABLE . " + WHERE post_approved = 1 + AND {$type}_id IN (" . implode(', ', $ids) . ") + GROUP BY {$type}_id"; $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - if ((int) $row['last_post_id']) + $last_post_ids = array(); + while ($row = $db->sql_fetchrow($result)) { - $sql = 'SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username + if ($type == 'forum') + { + $empty_forums[] = $row['forum_id']; + } + + $last_post_ids[] = $row['last_post_id']; + } + $db->sql_freeresult($result); + + if ($type == 'forum') + { + $empty_forums = array_diff($ids, $empty_forums); + + foreach ($empty_forums as $void => $forum_id) + { + $update_sql[$forum_id][] = 'forum_last_post_id = 0'; + $update_sql[$forum_id][] = 'forum_last_post_time = 0'; + $update_sql[$forum_id][] = 'forum_last_poster_id = 0'; + $update_sql[$forum_id][] = "forum_last_poster_name = ''"; + } + } + + if (sizeof($last_post_ids)) + { + $sql = 'SELECT p.' . $type . '_id, p.post_id, p.post_time, p.poster_id, p.post_username, u.user_id, u.username FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE p.poster_id = u.user_id - AND p.post_id = ' . $row['last_post_id']; + AND p.post_id IN (' . implode(', ', $last_post_ids) . ')'; $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - $update_sql[] = $type . '_last_post_id = ' . (int) $row['post_id']; - $update_sql[] = $type . '_last_post_time = ' . (int) $row['post_time']; - $update_sql[] = $type . '_last_poster_id = ' . (int) $row['poster_id']; - $update_sql[] = "{$type}_last_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'"; + while ($row = $db->sql_fetchrow($result)) + { + $update_sql[$row["{$type}_id"]][] = $type . '_last_post_id = ' . (int) $row['post_id']; + $update_sql[$row["{$type}_id"]][] = $type . '_last_post_time = ' . (int) $row['post_time']; + $update_sql[$row["{$type}_id"]][] = $type . '_last_poster_id = ' . (int) $row['poster_id']; + $update_sql[$row["{$type}_id"]][] = "{$type}_last_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'"; + } + $db->sql_freeresult($result); } - else if ($type == 'forum') + unset($empty_forums, $ids, $last_post_ids); + + if (!sizeof($update_sql)) { - $update_sql[] = 'forum_last_post_id = 0'; - $update_sql[] = 'forum_last_post_time = 0'; - $update_sql[] = 'forum_last_poster_id = 0'; - $update_sql[] = "forum_last_poster_name = ''"; + return array(); } - return $update_sql; + $table = ($type == 'forum') ? FORUMS_TABLE : TOPICS_TABLE; + + foreach ($update_sql as $update_id => $update_sql_ary) + { + $sql = "UPDATE $table + SET " . implode(', ', $update_sql_ary) . " + WHERE {$type}_id = $update_id"; + $db->sql_query($sql); + } } /** diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index f188de4633..0825bc1da5 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -28,6 +28,8 @@ class mcp_queue global $auth, $db, $user, $template; global $config, $phpbb_root_path, $phpEx, $SID; + include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); + $forum_id = request_var('f', 0); $start = request_var('start', 0); @@ -36,7 +38,6 @@ class mcp_queue case 'approve': case 'disapprove': include_once($phpbb_root_path . 'includes/functions_messenger.'.$phpEx); - include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); $post_id_list = request_var('post_id_list', array(0)); @@ -59,7 +60,6 @@ class mcp_queue case 'approve_details': $user->add_lang('posting'); - include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); $post_id = request_var('p', 0); $topic_id = request_var('t', 0); diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 532382cc4d..21da3a82ed 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -789,6 +789,27 @@ class user extends session $this->theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); + // User has wrong style + if (!$this->theme && $style == $this->data['user_style']) + { + $style = $this->data['user_style'] = $config['default_style']; + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_style = $style + WHERE user_id = {$this->data['user_id']}"; + $db->sql_query($sql); + + $sql = 'SELECT s.style_id, t.*, c.*, i.* + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TPL_TABLE . ' t, ' . STYLES_CSS_TABLE . ' c, ' . STYLES_IMAGE_TABLE . " i + WHERE s.style_id = $style + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + $result = $db->sql_query($sql); + $this->theme = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + if (!$this->theme) { trigger_error('Could not get style data', E_USER_ERROR); diff --git a/phpBB/posting.php b/phpBB/posting.php index d92d3d428d..99baa6a1b8 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -68,7 +68,7 @@ switch ($mode) $sql = 'SELECT * FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; - break; + break; case 'bump': case 'reply': @@ -82,7 +82,7 @@ switch ($mode) WHERE t.topic_id = $topic_id AND (f.forum_id = t.forum_id OR f.forum_id = $forum_id)"; - break; + break; case 'quote': case 'edit': @@ -99,18 +99,18 @@ switch ($mode) AND u.user_id = p.poster_id AND (f.forum_id = t.forum_id OR f.forum_id = $forum_id)"; - break; + break; case 'smilies': $sql = ''; generate_smilies('window', $forum_id); - break; + break; case 'popup': $sql = 'SELECT forum_style FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $forum_id; - break; + break; default: $sql = ''; @@ -417,9 +417,7 @@ if ($mode == 'bump' && ($bump_time = bump_topic_allowed($forum_id, $topic_bumped topic_bumper = " . $user->data['user_id'] . " WHERE topic_id = $topic_id"); - $db->sql_query('UPDATE ' . FORUMS_TABLE . ' - SET ' . implode(', ', update_last_post_information('forum', $forum_id)) . " - WHERE forum_id = $forum_id"); + update_post_information('forum', $forum_id); $db->sql_query('UPDATE ' . USERS_TABLE . " SET user_lastpost_time = $current_time @@ -555,7 +553,7 @@ if ($submit || $preview || $refresh) $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ', ' . POLL_VOTES_TABLE . " WHERE topic_id = $topic_id"; $db->sql_query($sql); - break; + break; default: $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . " @@ -718,10 +716,12 @@ if ($submit || $preview || $refresh) case POST_GLOBAL: case POST_ANNOUNCE: $auth_option = 'f_announce'; - break; + break; + case POST_STICKY: $auth_option = 'f_sticky'; - break; + break; + default: $auth_option = ''; } @@ -1027,12 +1027,12 @@ switch ($mode) { case 'post': $page_title = $user->lang['POST_TOPIC']; - break; + break; case 'quote': case 'reply': $page_title = $user->lang['POST_REPLY']; - break; + break; case 'delete': case 'edit': @@ -1213,10 +1213,15 @@ function delete_post($mode, $post_id, $topic_id, $forum_id, &$data) $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_topics = forum_topics - 1' : ''; } - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id)); + $update_sql = update_post_information('forum', $forum_id, true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; + $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + } + $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - break; + break; case 'delete_first_post': $sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username @@ -1238,7 +1243,7 @@ function delete_post($mode, $post_id, $topic_id, $forum_id, &$data) $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); $next_post_id = (int) $row['post_id']; - break; + break; case 'delete_last_post': if ($data['topic_type'] != POST_GLOBAL) @@ -1246,15 +1251,20 @@ function delete_post($mode, $post_id, $topic_id, $forum_id, &$data) $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; } - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id)); + $update_sql = update_post_information('forum', $forum_id, true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; + $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + } + $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - $update = update_last_post_information('topic', $topic_id); - if (sizeof($update)) + $update_sql = update_post_information('topic', $topic_id, true); + if (sizeof($update_sql)) { - $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update); - $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update[0]); + $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); + $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update[$topic_id][0]); } else { @@ -1268,7 +1278,7 @@ function delete_post($mode, $post_id, $topic_id, $forum_id, &$data) $next_post_id = (int) $row['last_post_id']; } - break; + break; case 'delete': $sql = 'SELECT post_id @@ -1374,7 +1384,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked'] ); - break; + break; case 'edit_first_post': case 'edit': @@ -1432,7 +1442,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message']; } - break; + break; } // And the topic ladies and gentlemen @@ -1473,7 +1483,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? ', forum_topics = forum_topics + 1' : ''); } - break; + break; case 'reply': $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? ', topic_replies = topic_replies + 1' : ''); @@ -1483,7 +1493,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } - break; + break; case 'edit_topic': case 'edit_first_post': @@ -1504,7 +1514,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_attachment' => ($post_mode == 'edit_topic') ? ((isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0) : $data['topic_attachment'] ); - break; + break; } $db->sql_transaction(); @@ -1753,27 +1763,35 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { if ($topic_type != POST_GLOBAL) { - $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id'])); + $update_sql = update_post_information('forum', $data['forum_id'], true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', $update_sql[$data['forum_id']]); + } } - $update = update_last_post_information('topic', $data['topic_id']); + $update_sql = update_post_information('topic', $data['topic_id'], true); if (sizeof($update)) { - $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update); + $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update_sql[$data['topic_id']]); } } if ($make_global) { - $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id'])); + $update_sql = update_post_information('forum', $data['forum_id'], true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', $update_sql[$forum_id]); + } } if ($post_mode == 'edit_topic') { - $update = update_last_post_information('topic', $data['topic_id']); - if (sizeof($update)) + $update_sql = update_post_information('topic', $data['topic_id'], true); + if (sizeof($update_sql)) { - $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update); + $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update_sql[$data['topic_id']]); } } |