diff options
author | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
---|---|---|
committer | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
commit | 8ea437e30605e0f66b5220bf904a61d7c1d11ddd (patch) | |
tree | e0db2bb4a012d5b06a633160b19f62f4868ecd28 /phpBB/includes/functions_admin.php | |
parent | 36bc1870f21fac04736a1049c1d5b8e127d729f4 (diff) | |
parent | 2fdd46b36431ae0f58bb2e78e42553168db9a0ff (diff) | |
download | forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.gz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.bz2 forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.xz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.zip |
Merge remote-tracking branch 'upstream/prep-release-3.2.9'
Diffstat (limited to 'phpBB/includes/functions_admin.php')
-rw-r--r-- | phpBB/includes/functions_admin.php | 581 |
1 files changed, 132 insertions, 449 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 4bac718999..cc82fdbda3 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -65,7 +65,7 @@ function recalc_nested_sets(&$new_id, $pkey, $table, $parent_id = 0, $where = ar */ function make_forum_select($select_id = false, $ignore_id = false, $ignore_acl = false, $ignore_nonpost = false, $ignore_emptycat = true, $only_acl_post = false, $return_array = false) { - global $db, $user, $auth, $phpbb_dispatcher; + global $db, $auth, $phpbb_dispatcher; // This query is identical to the jumpbox one $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, forum_flags, forum_options, left_id, right_id @@ -167,7 +167,7 @@ function size_select_options($size_compare) $s_size_options = ''; - for ($i = 0, $size = sizeof($size_types_text); $i < $size; $i++) + for ($i = 0, $size = count($size_types_text); $i < $size; $i++) { $selected = ($size_compare == $size_types[$i]) ? ' selected="selected"' : ''; $s_size_options .= '<option value="' . $size_types[$i] . '"' . $selected . '>' . $size_types_text[$i] . '</option>'; @@ -187,9 +187,12 @@ function size_select_options($size_compare) */ function group_select_options($group_id, $exclude_ids = false, $manage_founder = false) { - global $db, $user, $config; + global $db, $config, $phpbb_container; + + /** @var \phpbb\group\helper $group_helper */ + $group_helper = $phpbb_container->get('group_helper'); - $exclude_sql = ($exclude_ids !== false && sizeof($exclude_ids)) ? 'WHERE ' . $db->sql_in_set('group_id', array_map('intval', $exclude_ids), true) : ''; + $exclude_sql = ($exclude_ids !== false && count($exclude_ids)) ? 'WHERE ' . $db->sql_in_set('group_id', array_map('intval', $exclude_ids), true) : ''; $sql_and = (!$config['coppa_enable']) ? (($exclude_sql) ? ' AND ' : ' WHERE ') . "group_name <> 'REGISTERED_COPPA'" : ''; $sql_founder = ($manage_founder !== false) ? (($exclude_sql || $sql_and) ? ' AND ' : ' WHERE ') . 'group_founder_manage = ' . (int) $manage_founder : ''; @@ -205,7 +208,7 @@ function group_select_options($group_id, $exclude_ids = false, $manage_founder = 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>'; + $s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '"' . $selected . '>' . $group_helper->get_name($row['group_name']) . '</option>'; } $db->sql_freeresult($result); @@ -342,7 +345,7 @@ function get_forum_branch($forum_id, $type = 'all', $order = 'descending', $incl */ function copy_forum_permissions($src_forum_id, $dest_forum_ids, $clear_dest_perms = true, $add_log = true) { - global $db; + global $db, $user, $phpbb_log; // Only one forum id specified if (!is_array($dest_forum_ids)) @@ -465,7 +468,7 @@ function copy_forum_permissions($src_forum_id, $dest_forum_ids, $clear_dest_perm if ($add_log) { - add_log('admin', 'LOG_FORUM_COPIED_PERMISSIONS', $src_forum_name, implode(', ', $dest_forum_names)); + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_COPIED_PERMISSIONS', false, array($src_forum_name, implode(', ', $dest_forum_names))); } $db->sql_transaction('commit'); @@ -540,6 +543,20 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true) $topic_ids = array($topic_ids); } + /** + * Perform additional actions before topics move + * + * @event core.move_topics_before + * @var array topic_ids Array of the moved topic ids + * @var string forum_id The forum id from where the topics are moved + * @since 3.2.9-RC1 + */ + $vars = array( + 'topic_ids', + 'forum_id', + ); + extract($phpbb_dispatcher->trigger_event('core.move_topics_before', compact($vars))); + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids) . ' AND forum_id = ' . $forum_id; @@ -590,6 +607,22 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true) } unset($table_ary); + /** + * Perform additional actions after topics move + * + * @event core.move_topics_after + * @var array topic_ids Array of the moved topic ids + * @var string forum_id The forum id from where the topics were moved + * @var array forum_ids Array of the forums where the topics were moved (includes also forum_id) + * @since 3.2.9-RC1 + */ + $vars = array( + 'topic_ids', + 'forum_id', + 'forum_ids', + ); + extract($phpbb_dispatcher->trigger_event('core.move_topics_after', compact($vars))); + if ($auto_sync) { sync('forum', 'forum_id', $forum_ids, true, true); @@ -744,7 +777,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s { $where_ids = (is_array($where_ids)) ? array_unique($where_ids) : array($where_ids); - if (!sizeof($where_ids)) + if (!count($where_ids)) { return array('topics' => 0, 'posts' => 0); } @@ -774,9 +807,9 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s } $db->sql_freeresult($result); - $return['topics'] = sizeof($topic_ids); + $return['topics'] = count($topic_ids); - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { return $return; } @@ -834,7 +867,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s } $db->sql_freeresult($result); - if (sizeof($moved_topic_ids)) + if (count($moved_topic_ids)) { $sql = 'DELETE FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $moved_topic_ids); @@ -851,9 +884,10 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s if ($approved_topics) { - set_config_count('num_topics', $approved_topics * (-1), true); + $config->increment('num_topics', $approved_topics * (-1), false); } + /* @var $phpbb_notifications \phpbb\notification\manager */ $phpbb_notifications = $phpbb_container->get('notification_manager'); $phpbb_notifications->delete_notifications(array( @@ -919,7 +953,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $where_ids = array($where_ids); } - if (!sizeof($where_ids)) + if (!count($where_ids)) { return false; } @@ -927,7 +961,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $where_ids = array_map('intval', $where_ids); /* Possible code for splitting post deletion - if (sizeof($where_ids) >= 1001) + if (count($where_ids) >= 1001) { // Split into chunks of 1000 $chunks = array_chunk($where_ids, 1000); @@ -970,7 +1004,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = } $db->sql_freeresult($result); - if (!sizeof($post_ids)) + if (!count($post_ids)) { return false; } @@ -1014,7 +1048,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = unset($table_ary); // Adjust users post counts - if (sizeof($post_counts) && $post_count_sync) + if (count($post_counts) && $post_count_sync) { foreach ($post_counts as $poster_id => $substract) { @@ -1033,7 +1067,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = } // Remove topics now having no posts? - if (sizeof($topic_ids)) + if (count($topic_ids)) { $sql = 'SELECT topic_id FROM ' . POSTS_TABLE . ' @@ -1069,7 +1103,10 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $search->index_remove($post_ids, $poster_ids, $forum_ids); - delete_attachments('post', $post_ids, false); + /** @var \phpbb\attachment\manager $attachment_manager */ + $attachment_manager = $phpbb_container->get('attachment.manager'); + $attachment_manager->delete('post', $post_ids, false); + unset($attachment_manager); /** * Perform additional actions during post(s) deletion @@ -1136,348 +1173,41 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = if ($approved_posts && $post_count_sync) { - set_config_count('num_posts', $approved_posts * (-1), true); + $config->increment('num_posts', $approved_posts * (-1), false); } // We actually remove topics now to not be inconsistent (the delete_topics function calls this function too) - if (sizeof($remove_topics) && $call_delete_topics) + if (count($remove_topics) && $call_delete_topics) { delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false); } + /* @var $phpbb_notifications \phpbb\notification\manager */ $phpbb_notifications = $phpbb_container->get('notification_manager'); $phpbb_notifications->delete_notifications($delete_notifications_types, $post_ids); - return sizeof($post_ids); + return count($post_ids); } /** * Delete Attachments * +* @deprecated 3.2.0-a1 (To be removed: 3.4.0) +* * @param string $mode can be: post|message|topic|attach|user * @param mixed $ids can be: post_ids, message_ids, topic_ids, attach_ids, user_ids * @param bool $resync set this to false if you are deleting posts or topics */ function delete_attachments($mode, $ids, $resync = true) { - global $db, $config, $phpbb_dispatcher; - - // 0 is as bad as an empty array - if (empty($ids)) - { - return false; - } - - if (is_array($ids)) - { - $ids = array_unique($ids); - $ids = array_map('intval', $ids); - } - else - { - $ids = array((int) $ids); - } - - $sql_where = ''; - - switch ($mode) - { - case 'post': - case 'message': - $sql_id = 'post_msg_id'; - $sql_where = ' AND in_message = ' . ($mode == 'message' ? 1 : 0); - break; - - case 'topic': - $sql_id = 'topic_id'; - break; - - case 'user': - $sql_id = 'poster_id'; - break; - - case 'attach': - default: - $sql_id = 'attach_id'; - $mode = 'attach'; - break; - } - - $post_ids = $message_ids = $topic_ids = $physical = array(); - - /** - * Perform additional actions before collecting data for attachment(s) deletion - * - * @event core.delete_attachments_collect_data_before - * @var string mode Variable containing attachments deletion mode, can be: post|message|topic|attach|user - * @var mixed ids Array or comma separated list of ids corresponding to the mode - * @var bool resync Flag indicating if posts/messages/topics should be synchronized - * @var string sql_id The field name to collect/delete data for depending on the mode - * @since 3.1.7-RC1 - */ - $vars = array( - 'mode', - 'ids', - 'resync', - 'sql_id', - ); - extract($phpbb_dispatcher->trigger_event('core.delete_attachments_collect_data_before', compact($vars))); - - // Collect post and topic ids for later use if we need to touch remaining entries (if resync is enabled) - $sql = 'SELECT post_msg_id, topic_id, in_message, physical_filename, thumbnail, filesize, is_orphan - FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set($sql_id, $ids); - - $sql .= $sql_where; - - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - // We only need to store post/message/topic ids if resync is enabled and the file is not orphaned - if ($resync && !$row['is_orphan']) - { - if (!$row['in_message']) - { - $post_ids[] = $row['post_msg_id']; - $topic_ids[] = $row['topic_id']; - } - else - { - $message_ids[] = $row['post_msg_id']; - } - } - - $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize'], 'is_orphan' => $row['is_orphan']); - } - $db->sql_freeresult($result); - - /** - * Perform additional actions before attachment(s) deletion - * - * @event core.delete_attachments_before - * @var string mode Variable containing attachments deletion mode, can be: post|message|topic|attach|user - * @var mixed ids Array or comma separated list of ids corresponding to the mode - * @var bool resync Flag indicating if posts/messages/topics should be synchronized - * @var string sql_id The field name to collect/delete data for depending on the mode - * @var array post_ids Array with post ids for deleted attachment(s) - * @var array topic_ids Array with topic ids for deleted attachment(s) - * @var array message_ids Array with private message ids for deleted attachment(s) - * @var array physical Array with deleted attachment(s) physical file(s) data - * @since 3.1.7-RC1 - */ - $vars = array( - 'mode', - 'ids', - 'resync', - 'sql_id', - 'post_ids', - 'topic_ids', - 'message_ids', - 'physical', - ); - extract($phpbb_dispatcher->trigger_event('core.delete_attachments_before', compact($vars))); - - // Delete attachments - $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set($sql_id, $ids); - - $sql .= $sql_where; - - $db->sql_query($sql); - $num_deleted = $db->sql_affectedrows(); - - /** - * Perform additional actions after attachment(s) deletion from the database - * - * @event core.delete_attachments_from_database_after - * @var string mode Variable containing attachments deletion mode, can be: post|message|topic|attach|user - * @var mixed ids Array or comma separated list of ids corresponding to the mode - * @var bool resync Flag indicating if posts/messages/topics should be synchronized - * @var string sql_id The field name to collect/delete data for depending on the mode - * @var array post_ids Array with post ids for deleted attachment(s) - * @var array topic_ids Array with topic ids for deleted attachment(s) - * @var array message_ids Array with private message ids for deleted attachment(s) - * @var array physical Array with deleted attachment(s) physical file(s) data - * @var int num_deleted The number of deleted attachment(s) from the database - * @since 3.1.7-RC1 - */ - $vars = array( - 'mode', - 'ids', - 'resync', - 'sql_id', - 'post_ids', - 'topic_ids', - 'message_ids', - 'physical', - 'num_deleted', - ); - extract($phpbb_dispatcher->trigger_event('core.delete_attachments_from_database_after', compact($vars))); - - if (!$num_deleted) - { - return 0; - } - - // Delete attachments from filesystem - $space_removed = $files_removed = 0; - foreach ($physical as $file_ary) - { - if (phpbb_unlink($file_ary['filename'], 'file', true) && !$file_ary['is_orphan']) - { - // Only non-orphaned files count to the file size - $space_removed += $file_ary['filesize']; - $files_removed++; - } - - if ($file_ary['thumbnail']) - { - phpbb_unlink($file_ary['filename'], 'thumbnail', true); - } - } - - /** - * Perform additional actions after attachment(s) deletion from the filesystem - * - * @event core.delete_attachments_from_filesystem_after - * @var string mode Variable containing attachments deletion mode, can be: post|message|topic|attach|user - * @var mixed ids Array or comma separated list of ids corresponding to the mode - * @var bool resync Flag indicating if posts/messages/topics should be synchronized - * @var string sql_id The field name to collect/delete data for depending on the mode - * @var array post_ids Array with post ids for deleted attachment(s) - * @var array topic_ids Array with topic ids for deleted attachment(s) - * @var array message_ids Array with private message ids for deleted attachment(s) - * @var array physical Array with deleted attachment(s) physical file(s) data - * @var int num_deleted The number of deleted attachment(s) from the database - * @var int space_removed The size of deleted files(s) from the filesystem - * @var int files_removed The number of deleted file(s) from the filesystem - * @since 3.1.7-RC1 - */ - $vars = array( - 'mode', - 'ids', - 'resync', - 'sql_id', - 'post_ids', - 'topic_ids', - 'message_ids', - 'physical', - 'num_deleted', - 'space_removed', - 'files_removed', - ); - extract($phpbb_dispatcher->trigger_event('core.delete_attachments_from_filesystem_after', compact($vars))); - - if ($space_removed || $files_removed) - { - set_config_count('upload_dir_size', $space_removed * (-1), true); - set_config_count('num_files', $files_removed * (-1), true); - } - - // If we do not resync, we do not need to adjust any message, post, topic or user entries - if (!$resync) - { - return $num_deleted; - } - - // No more use for the original ids - unset($ids); - - // Now, we need to resync posts, messages, topics. We go through every one of them - $post_ids = array_unique($post_ids); - $message_ids = array_unique($message_ids); - $topic_ids = array_unique($topic_ids); - - // Update post indicators for posts now no longer having attachments - if (sizeof($post_ids)) - { - // Just check which posts are still having an assigned attachment not orphaned by querying the attachments table - $sql = 'SELECT post_msg_id - FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . ' - AND in_message = 0 - AND is_orphan = 0'; - $result = $db->sql_query($sql); - - $remaining_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $remaining_ids[] = $row['post_msg_id']; - } - $db->sql_freeresult($result); - - // Now only unset those ids remaining - $post_ids = array_diff($post_ids, $remaining_ids); - - if (sizeof($post_ids)) - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_attachment = 0 - WHERE ' . $db->sql_in_set('post_id', $post_ids); - $db->sql_query($sql); - } - } - - // Update message table if messages are affected - if (sizeof($message_ids)) - { - // Just check which messages are still having an assigned attachment not orphaned by querying the attachments table - $sql = 'SELECT post_msg_id - FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set('post_msg_id', $message_ids) . ' - AND in_message = 1 - AND is_orphan = 0'; - $result = $db->sql_query($sql); - - $remaining_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $remaining_ids[] = $row['post_msg_id']; - } - $db->sql_freeresult($result); - - // Now only unset those ids remaining - $message_ids = array_diff($message_ids, $remaining_ids); - - if (sizeof($message_ids)) - { - $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' - SET message_attachment = 0 - WHERE ' . $db->sql_in_set('msg_id', $message_ids); - $db->sql_query($sql); - } - } - - // Now update the topics. This is a bit trickier, because there could be posts still having attachments within the topic - if (sizeof($topic_ids)) - { - // Just check which topics are still having an assigned attachment not orphaned by querying the attachments table (much less entries expected) - $sql = 'SELECT topic_id - FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . ' - AND is_orphan = 0'; - $result = $db->sql_query($sql); - - $remaining_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $remaining_ids[] = $row['topic_id']; - } - $db->sql_freeresult($result); + global $phpbb_container; - // Now only unset those ids remaining - $topic_ids = array_diff($topic_ids, $remaining_ids); + /** @var \phpbb\attachment\manager $attachment_manager */ + $attachment_manager = $phpbb_container->get('attachment.manager'); + $num_deleted = $attachment_manager->delete($mode, $ids, $resync); - if (sizeof($topic_ids)) - { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_attachment = 0 - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); - $db->sql_query($sql); - } - } + unset($attachment_manager); return $num_deleted; } @@ -1532,7 +1262,7 @@ function delete_topic_shadows($forum_id, $sql_more = '', $auto_sync = true) $db->sql_query($sql); } } - while (sizeof($topic_ids) == $batch_size); + while (count($topic_ids) == $batch_size); if ($auto_sync) { @@ -1595,27 +1325,19 @@ function update_posted_info(&$topic_ids) /** * Delete attached file +* +* @deprecated 3.2.0-a1 (To be removed: 3.4.0) */ function phpbb_unlink($filename, $mode = 'file', $entry_removed = false) { - global $db, $phpbb_root_path, $config; + global $phpbb_container; - // Because of copying topics or modifications a physical filename could be assigned more than once. If so, do not remove the file itself. - $sql = 'SELECT COUNT(attach_id) AS num_entries - FROM ' . ATTACHMENTS_TABLE . " - WHERE physical_filename = '" . $db->sql_escape(utf8_basename($filename)) . "'"; - $result = $db->sql_query($sql); - $num_entries = (int) $db->sql_fetchfield('num_entries'); - $db->sql_freeresult($result); + /** @var \phpbb\attachment\manager $attachment_manager */ + $attachment_manager = $phpbb_container->get('attachment.manager'); + $unlink = $attachment_manager->unlink($filename, $mode, $entry_removed); + unset($attachment_manager); - // Do not remove file if at least one additional entry with the same name exist. - if (($entry_removed && $num_entries > 0) || (!$entry_removed && $num_entries > 1)) - { - return false; - } - - $filename = ($mode == 'thumbnail') ? 'thumb_' . utf8_basename($filename) : utf8_basename($filename); - return @unlink($phpbb_root_path . $config['upload_path'] . '/' . $filename); + return $unlink; } /** @@ -1671,7 +1393,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // Do not sync the "global forum" $where_ids = array_diff($where_ids, array(0)); - if (!sizeof($where_ids)) + if (!count($where_ids)) { // Empty array with IDs. This means that we don't have any work to do. Just return. return; @@ -1685,7 +1407,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } else { - if (!sizeof($where_ids)) + if (!count($where_ids)) { return; } @@ -1724,7 +1446,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } $db->sql_freeresult($result); - if (!sizeof($topic_id_ary)) + if (!count($topic_id_ary)) { return; } @@ -1841,7 +1563,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $post_ids[] = $post_id; } - if (sizeof($post_ids)) + if (count($post_ids)) { $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_reported = 1 - post_reported @@ -1887,7 +1609,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } $db->sql_freeresult($result); - if (sizeof($topic_ids)) + if (count($topic_ids)) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_reported = 1 - topic_reported @@ -1946,7 +1668,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $post_ids[] = $post_id; } - if (sizeof($post_ids)) + if (count($post_ids)) { $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_attachment = 1 - post_attachment @@ -1992,7 +1714,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } $db->sql_freeresult($result); - if (sizeof($topic_ids)) + if (count($topic_ids)) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_attachment = 1 - topic_attachment @@ -2044,7 +1766,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } $db->sql_freeresult($result); - if (!sizeof($forum_ids)) + if (!count($forum_ids)) { break; } @@ -2083,7 +1805,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // 3: Get post count for each forum (optional) if ($sync_extra) { - if (sizeof($forum_ids) == 1) + if (count($forum_ids) == 1) { $sql = 'SELECT SUM(t.topic_posts_approved) AS forum_posts_approved, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t @@ -2103,7 +1825,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, while ($row = $db->sql_fetchrow($result)) { - $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; + $forum_id = (count($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; $forum_data[$forum_id]['posts_approved'] = (int) $row['forum_posts_approved']; $forum_data[$forum_id]['posts_unapproved'] = (int) $row['forum_posts_unapproved']; @@ -2113,7 +1835,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } // 4: Get last_post_id for each forum - if (sizeof($forum_ids) == 1) + if (count($forum_ids) == 1) { $sql = 'SELECT MAX(t.topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' t @@ -2133,7 +1855,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, while ($row = $db->sql_fetchrow($result)) { - $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; + $forum_id = (count($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; $forum_data[$forum_id]['last_post_id'] = (int) $row['last_post_id']; @@ -2142,7 +1864,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_freeresult($result); // 5: Retrieve last_post infos - if (sizeof($post_ids)) + if (count($post_ids)) { $sql = 'SELECT p.post_id, p.poster_id, p.post_subject, p.post_time, p.post_username, u.username, u.user_colour FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u @@ -2210,7 +1932,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } } - if (sizeof($sql_ary)) + if (count($sql_ary)) { $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' @@ -2333,20 +2055,20 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } // Now we delete empty topics and orphan posts - if (sizeof($delete_posts)) + if (count($delete_posts)) { delete_posts('topic_id', array_keys($delete_posts), false); unset($delete_posts); } - if (!sizeof($topic_data)) + if (!count($topic_data)) { // If we get there, topic ids were invalid or topics did not contain any posts delete_topics($where_type, $where_ids, true); return; } - if (sizeof($delete_topics)) + if (count($delete_topics)) { $delete_topic_ids = array(); foreach ($delete_topics as $topic_id => $void) @@ -2365,7 +2087,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, AND u.user_id = p.poster_id'; $result = $db->sql_query($sql); - $post_ids = array(); while ($row = $db->sql_fetchrow($result)) { $topic_id = intval($row['topic_id']); @@ -2390,7 +2111,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_freeresult($result); // Make sure shadow topics do link to existing topics - if (sizeof($moved_topics)) + if (count($moved_topics)) { $delete_topics = array(); @@ -2407,7 +2128,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } $db->sql_freeresult($result); - if (sizeof($delete_topics)) + if (count($delete_topics)) { delete_topics('topic_id', $delete_topics, false); } @@ -2430,7 +2151,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_freeresult($result); $sync_shadow_topics = array(); - if (sizeof($post_ids)) + if (count($post_ids)) { $sql = 'SELECT p.post_id, p.topic_id, p.post_visibility, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u @@ -2438,7 +2159,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, AND u.user_id = p.poster_id'; $result = $db->sql_query($sql); - $post_ids = array(); while ($row = $db->sql_fetchrow($result)) { $topic_id = (int) $row['topic_id']; @@ -2484,7 +2204,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $shadow_topic_data = array(); // Update the information we collected - if (sizeof($sync_shadow_topics)) + if (count($sync_shadow_topics)) { foreach ($sync_shadow_topics as $sync_topic_id => $sql_ary) { @@ -2549,7 +2269,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } } - if (sizeof($sql_ary)) + if (count($sql_ary)) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' @@ -2566,7 +2286,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // if some topics have been resync'ed then resync parent forums // except when we're only syncing a range, we don't want to sync forums during // batch processing. - if ($resync_parents && sizeof($resync_forums) && $where_type != 'range') + if ($resync_parents && count($resync_forums) && $where_type != 'range') { sync('forum', 'forum_id', array_values($resync_forums), true, true); } @@ -2588,7 +2308,7 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync $forum_id = array($forum_id); } - if (!sizeof($forum_id)) + if (!count($forum_id)) { return; } @@ -2679,6 +2399,16 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync $topic_list = array_unique($topic_list); } + /** + * Perform additional actions before topic deletion via pruning + * + * @event core.prune_delete_before + * @var int[] topic_list The IDs of the topics to be deleted + * @since 3.2.2-RC1 + */ + $vars = array('topic_list'); + extract($phpbb_dispatcher->trigger_event('core.prune_delete_before', compact($vars))); + return delete_topics('topic_id', $topic_list, $auto_sync, false); } @@ -2687,7 +2417,7 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync */ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_freq) { - global $db; + global $db, $user, $phpbb_log; $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . " @@ -2711,7 +2441,7 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr $db->sql_query($sql); } - add_log('admin', 'LOG_AUTO_PRUNE', $row['forum_name']); + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_AUTO_PRUNE', false, array($row['forum_name'])); } return; @@ -2735,7 +2465,6 @@ function phpbb_cache_moderators($db, $cache, $auth) // Clear table switch ($db->get_sql_layer()) { - case 'sqlite': case 'sqlite3': $db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE); break; @@ -2746,13 +2475,13 @@ function phpbb_cache_moderators($db, $cache, $auth) } // We add moderators who have forum moderator permissions without an explicit ACL_NEVER setting - $hold_ary = $ug_id_ary = $sql_ary = array(); + $sql_ary = array(); // Grab all users having moderative options... $hold_ary = $auth->acl_user_raw_data(false, 'm_%', false); // Add users? - if (sizeof($hold_ary)) + if (!empty($hold_ary)) { // At least one moderative option warrants a display $ug_id_ary = array_keys($hold_ary); @@ -2797,7 +2526,7 @@ function phpbb_cache_moderators($db, $cache, $auth) } $db->sql_freeresult($result); - if (sizeof($hold_ary)) + if (count($hold_ary)) { // Get usernames... $sql = 'SELECT user_id, username @@ -2837,7 +2566,7 @@ function phpbb_cache_moderators($db, $cache, $auth) // Now to the groups... $hold_ary = $auth->acl_group_raw_data(false, 'm_%', false); - if (sizeof($hold_ary)) + if (!empty($hold_ary)) { $ug_id_ary = array_keys($hold_ary); @@ -2941,7 +2670,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) { // update foes for some user - if (is_array($user_id) && sizeof($user_id)) + if (is_array($user_id) && count($user_id)) { $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE ' . $db->sql_in_set('zebra_id', $user_id) . ' @@ -2951,7 +2680,7 @@ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) } // update foes for some group - if (is_array($group_id) && sizeof($group_id)) + if (is_array($group_id) && count($group_id)) { // Grab group settings... $sql_ary = array( @@ -2985,7 +2714,7 @@ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) } $db->sql_freeresult($result); - if (!sizeof($groups)) + if (!count($groups)) { return; } @@ -3015,7 +2744,7 @@ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) } $db->sql_freeresult($result); - if (sizeof($users)) + if (count($users)) { $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE ' . $db->sql_in_set('zebra_id', $users) . ' @@ -3038,7 +2767,7 @@ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) } } - if (sizeof($perms)) + if (count($perms)) { $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE ' . $db->sql_in_set('zebra_id', array_unique($perms)) . ' @@ -3193,7 +2922,6 @@ function get_database_size() } break; - case 'sqlite': case 'sqlite3': global $dbhost; @@ -3204,7 +2932,6 @@ function get_database_size() break; - case 'mssql': case 'mssql_odbc': case 'mssqlnative': $sql = 'SELECT @@VERSION AS mssql_version'; @@ -3278,25 +3005,6 @@ function get_database_size() return $database_size; } -/** -* Retrieve contents from remotely stored file -* -* @deprecated 3.1.2 Use file_downloader instead -*/ -function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 6) -{ - global $phpbb_container; - - // Get file downloader and assign $errstr and $errno - $file_downloader = $phpbb_container->get('file_downloader'); - - $file_data = $file_downloader->get($host, $directory, $filename, $port, $timeout); - $errstr = $file_downloader->get_error_string(); - $errno = $file_downloader->get_error_number(); - - return $file_data; -} - /* * Tidy Warnings * Remove all warnings which have now expired from the database @@ -3322,7 +3030,7 @@ function tidy_warnings() } $db->sql_freeresult($result); - if (sizeof($warning_list)) + if (count($warning_list)) { $db->sql_transaction('begin'); @@ -3340,7 +3048,7 @@ function tidy_warnings() $db->sql_transaction('commit'); } - set_config('warnings_last_gc', time(), true); + $config->set('warnings_last_gc', time(), false); } /** @@ -3348,7 +3056,7 @@ function tidy_warnings() */ function tidy_database() { - global $db; + global $config, $db; // Here we check permission consistency @@ -3364,6 +3072,8 @@ function tidy_database() } $db->sql_freeresult($result); + $db->sql_transaction('begin'); + // 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); @@ -3373,7 +3083,9 @@ function tidy_database() WHERE ' . $db->sql_in_set('forum_id', $forum_ids, true); $db->sql_query($sql); - set_config('database_last_gc', time(), true); + $db->sql_transaction('commit'); + + $config->set('database_last_gc', time(), false); } /** @@ -3381,47 +3093,18 @@ function tidy_database() */ function add_permission_language() { - global $config, $user, $phpEx, $phpbb_extension_manager; + global $user, $phpEx, $phpbb_extension_manager; // add permission language files from extensions $finder = $phpbb_extension_manager->get_finder(); - // We grab the language files from the default, English and user's language. - // So we can fall back to the other files like we do when using add_lang() - $default_lang_files = $english_lang_files = $user_lang_files = array(); - - // Search for board default language if it's not the user language - if ($config['default_lang'] != $user->lang_name) - { - $default_lang_files = $finder - ->prefix('permissions_') - ->suffix(".$phpEx") - ->core_path('language/' . basename($config['default_lang']) . '/') - ->extension_directory('/language/' . basename($config['default_lang'])) - ->find(); - } - - // Search for english, if its not the default or user language - if ($config['default_lang'] != 'en' && $user->lang_name != 'en') - { - $english_lang_files = $finder - ->prefix('permissions_') - ->suffix(".$phpEx") - ->core_path('language/en/') - ->extension_directory('/language/en') - ->find(); - } - - // Find files in the user's language - $user_lang_files = $finder + $lang_files = $finder ->prefix('permissions_') ->suffix(".$phpEx") - ->core_path('language/' . $user->lang_name . '/') - ->extension_directory('/language/' . $user->lang_name) + ->core_path('language/') + ->extension_directory('/language') ->find(); - $lang_files = array_merge($english_lang_files, $default_lang_files, $user_lang_files); - foreach ($lang_files as $lang_file => $ext_name) { if ($ext_name === '/') |