diff options
author | Maat <maat-pub@mageia.biz> | 2020-05-08 18:29:30 +0200 |
---|---|---|
committer | Maat <maat-pub@mageia.biz> | 2020-05-08 21:36:04 +0200 |
commit | 36bc1870f21fac04736a1049c1d5b8e127d729f4 (patch) | |
tree | 9d102331eeaf1ef3cd23e656320d7c08e65757ed /phpBB/includes/functions_admin.php | |
parent | 8875d385d0579b451dac4d9bda465172b4f69ee0 (diff) | |
parent | 149375253685b3a38996f63015a74b7a0f53aa14 (diff) | |
download | forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.gz forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.bz2 forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.xz forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.zip |
Merge remote-tracking branch 'upstream/prep-release-3.1.11'
Diffstat (limited to 'phpBB/includes/functions_admin.php')
-rw-r--r-- | phpBB/includes/functions_admin.php | 1214 |
1 files changed, 648 insertions, 566 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 3e69a997a2..4bac718999 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1,10 +1,13 @@ <?php /** * -* @package acp -* @version $Id$ -* @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -24,8 +27,6 @@ if (!defined('IN_PHPBB')) * @param string $table constant or fullname of the table * @param int $parent_id parent_id of the current set (default = 0) * @param array $where contains strings to compare closer on the where statement (additional) -* -* @author EXreaction */ function recalc_nested_sets(&$new_id, $pkey, $table, $parent_id = 0, $where = array()) { @@ -64,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; + global $db, $user, $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 @@ -72,16 +73,33 @@ function make_forum_select($select_id = false, $ignore_id = false, $ignore_acl = ORDER BY left_id ASC'; $result = $db->sql_query($sql, 600); + $rowset = array(); + while ($row = $db->sql_fetchrow($result)) + { + $rowset[(int) $row['forum_id']] = $row; + } + $db->sql_freeresult($result); + $right = 0; $padding_store = array('0' => ''); $padding = ''; $forum_list = ($return_array) ? array() : ''; + /** + * Modify the forum list data + * + * @event core.make_forum_select_modify_forum_list + * @var array rowset Array with the forums list data + * @since 3.1.10-RC1 + */ + $vars = array('rowset'); + extract($phpbb_dispatcher->trigger_event('core.make_forum_select_modify_forum_list', compact($vars))); + // Sometimes it could happen that forums will be displayed here not be displayed within the index page // This is the result of forums not displayed at index, having list permissions and a parent of a forum with no permissions. // If this happens, the padding could be "broken" - while ($row = $db->sql_fetchrow($result)) + foreach ($rowset as $row) { if ($row['left_id'] < $right) { @@ -132,8 +150,7 @@ function make_forum_select($select_id = false, $ignore_id = false, $ignore_acl = $forum_list .= '<option value="' . $row['forum_id'] . '"' . (($disabled) ? ' disabled="disabled" class="disabled-option"' : $selected) . '>' . $padding . $row['forum_name'] . '</option>'; } } - $db->sql_freeresult($result); - unset($padding_store); + unset($padding_store, $rowset); return $forum_list; } @@ -200,7 +217,7 @@ function group_select_options($group_id, $exclude_ids = false, $manage_founder = */ function get_forum_list($acl_list = 'f_list', $id_only = true, $postable_only = false, $no_cache = false) { - global $db, $auth; + global $db, $auth, $phpbb_dispatcher; static $forum_rows; if (!isset($forum_rows)) @@ -255,6 +272,16 @@ function get_forum_list($acl_list = 'f_list', $id_only = true, $postable_only = } } + /** + * Modify the forum list data + * + * @event core.get_forum_list_modify_data + * @var array rowset Array with the forum list data + * @since 3.1.10-RC1 + */ + $vars = array('rowset'); + extract($phpbb_dispatcher->trigger_event('core.get_forum_list_modify_data', compact($vars))); + return $rowset; } @@ -312,8 +339,6 @@ function get_forum_branch($forum_id, $type = 'all', $order = 'descending', $incl * @param bool $add_log True if log entry should be added * * @return bool False on error -* -* @author bantu */ function copy_forum_permissions($src_forum_id, $dest_forum_ids, $clear_dest_perms = true, $add_log = true) { @@ -501,7 +526,7 @@ function filelist($rootdir, $dir = '', $type = 'gif|jpg|jpeg|png') */ function move_topics($topic_ids, $forum_id, $auto_sync = true) { - global $db; + global $db, $phpbb_dispatcher; if (empty($topic_ids)) { @@ -535,6 +560,27 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true) } $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); + + /** + * Perform additional actions before topics move + * + * @event core.move_topics_before_query + * @var array table_ary Array of tables from which forum_id will be updated for all rows that hold the moved topics + * @var array topic_ids Array of the moved topic ids + * @var string forum_id The forum id from where the topics are moved + * @var array forum_ids Array of the forums where the topics are moving (includes also forum_id) + * @var bool auto_sync Whether or not to perform auto sync + * @since 3.1.5-RC1 + */ + $vars = array( + 'table_ary', + 'topic_ids', + 'forum_id', + 'forum_ids', + 'auto_sync', + ); + extract($phpbb_dispatcher->trigger_event('core.move_topics_before_query', compact($vars))); + foreach ($table_ary as $table) { $sql = "UPDATE $table @@ -556,7 +602,7 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true) */ function move_posts($post_ids, $topic_id, $auto_sync = true) { - global $db; + global $db, $phpbb_dispatcher; if (!is_array($post_ids)) { @@ -590,6 +636,28 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) trigger_error('NO_TOPIC'); } + /** + * Perform additional actions before moving posts + * + * @event core.move_posts_before + * @var array post_ids Array of post ids to move + * @var int topic_id The topic id the posts are moved to + * @var bool auto_sync Whether or not to perform auto sync + * @var array forum_ids Array of the forum ids the posts are moved from + * @var array topic_ids Array of the topic ids the posts are moved from + * @var array forum_row Array with the forum id of the topic the posts are moved to + * @since 3.1.7-RC1 + */ + $vars = array( + 'post_ids', + 'topic_id', + 'auto_sync', + 'forum_ids', + 'topic_ids', + 'forum_row', + ); + extract($phpbb_dispatcher->trigger_event('core.move_posts_before', compact($vars))); + $sql = 'UPDATE ' . POSTS_TABLE . ' SET forum_id = ' . (int) $forum_row['forum_id'] . ", topic_id = $topic_id WHERE " . $db->sql_in_set('post_id', $post_ids); @@ -600,6 +668,28 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) WHERE " . $db->sql_in_set('post_msg_id', $post_ids); $db->sql_query($sql); + /** + * Perform additional actions after moving posts + * + * @event core.move_posts_after + * @var array post_ids Array of the moved post ids + * @var int topic_id The topic id the posts are moved to + * @var bool auto_sync Whether or not to perform auto sync + * @var array forum_ids Array of the forum ids the posts are moved from + * @var array topic_ids Array of the topic ids the posts are moved from + * @var array forum_row Array with the forum id of the topic the posts are moved to + * @since 3.1.7-RC1 + */ + $vars = array( + 'post_ids', + 'topic_id', + 'auto_sync', + 'forum_ids', + 'topic_ids', + 'forum_row', + ); + extract($phpbb_dispatcher->trigger_event('core.move_posts_after', compact($vars))); + if ($auto_sync) { $forum_ids[] = (int) $forum_row['forum_id']; @@ -608,6 +698,28 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) sync('topic_attachment', 'topic_id', $topic_ids); sync('topic', 'topic_id', $topic_ids, true); sync('forum', 'forum_id', $forum_ids, true, true); + + /** + * Perform additional actions after move post sync + * + * @event core.move_posts_sync_after + * @var array post_ids Array of the moved post ids + * @var int topic_id The topic id the posts are moved to + * @var bool auto_sync Whether or not to perform auto sync + * @var array forum_ids Array of the forum ids the posts are moved from + * @var array topic_ids Array of the topic ids the posts are moved from + * @var array forum_row Array with the forum id of the topic the posts are moved to + * @since 3.1.11-RC1 + */ + $vars = array( + 'post_ids', + 'topic_id', + 'auto_sync', + 'forum_ids', + 'topic_ids', + 'forum_row', + ); + extract($phpbb_dispatcher->trigger_event('core.move_posts_sync_after', compact($vars))); } // Update posted information @@ -619,7 +731,7 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) */ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_sync = true, $call_delete_posts = true) { - global $db, $config; + global $db, $config, $phpbb_container, $phpbb_dispatcher; $approved_topics = 0; $forum_ids = $topic_ids = array(); @@ -645,7 +757,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s 'posts' => ($call_delete_posts) ? delete_posts($where_type, $where_ids, false, true, $post_count_sync, false) : 0, ); - $sql = 'SELECT topic_id, forum_id, topic_approved, topic_moved_id + $sql = 'SELECT topic_id, forum_id, topic_visibility, topic_moved_id FROM ' . TOPICS_TABLE . ' WHERE ' . $where_clause; $result = $db->sql_query($sql); @@ -655,7 +767,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s $forum_ids[] = $row['forum_id']; $topic_ids[] = $row['topic_id']; - if ($row['topic_approved'] && !$row['topic_moved_id']) + if ($row['topic_visibility'] == ITEM_APPROVED && !$row['topic_moved_id']) { $approved_topics++; } @@ -673,6 +785,20 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s $table_ary = array(BOOKMARKS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE); + /** + * Perform additional actions before topic(s) deletion + * + * @event core.delete_topics_before_query + * @var array table_ary Array of tables from which all rows will be deleted that hold a topic_id occuring in topic_ids + * @var array topic_ids Array of topic ids to delete + * @since 3.1.4-RC1 + */ + $vars = array( + 'table_ary', + 'topic_ids', + ); + extract($phpbb_dispatcher->trigger_event('core.delete_topics_before_query', compact($vars))); + foreach ($table_ary as $table) { $sql = "DELETE FROM $table @@ -681,6 +807,18 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s } unset($table_ary); + /** + * Perform additional actions after topic(s) deletion + * + * @event core.delete_topics_after_query + * @var array topic_ids Array of topic ids that were deleted + * @since 3.1.4-RC1 + */ + $vars = array( + 'topic_ids', + ); + extract($phpbb_dispatcher->trigger_event('core.delete_topics_after_query', compact($vars))); + $moved_topic_ids = array(); // update the other forums @@ -716,6 +854,14 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s set_config_count('num_topics', $approved_topics * (-1), true); } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + + $phpbb_notifications->delete_notifications(array( + 'notification.type.topic', + 'notification.type.approve_topic', + 'notification.type.topic_in_queue', + ), $topic_ids); + return $return; } @@ -724,7 +870,39 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s */ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true) { - global $db, $config, $phpbb_root_path, $phpEx; + global $db, $config, $phpbb_root_path, $phpEx, $auth, $user, $phpbb_container, $phpbb_dispatcher; + + // Notifications types to delete + $delete_notifications_types = array( + 'notification.type.quote', + 'notification.type.approve_post', + 'notification.type.post_in_queue', + 'notification.type.report_post', + ); + + /** + * Perform additional actions before post(s) deletion + * + * @event core.delete_posts_before + * @var string where_type Variable containing posts deletion mode + * @var mixed where_ids Array or comma separated list of posts ids to delete + * @var bool auto_sync Flag indicating if topics/forums should be synchronized + * @var bool posted_sync Flag indicating if topics_posted table should be resynchronized + * @var bool post_count_sync Flag indicating if posts count should be resynchronized + * @var bool call_delete_topics Flag indicating if topics having no posts should be deleted + * @var array delete_notifications_types Array with notifications types to delete + * @since 3.1.0-a4 + */ + $vars = array( + 'where_type', + 'where_ids', + 'auto_sync', + 'posted_sync', + 'post_count_sync', + 'call_delete_topics', + 'delete_notifications_types', + ); + extract($phpbb_dispatcher->trigger_event('core.delete_posts_before', compact($vars))); if ($where_type === 'range') { @@ -768,7 +946,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $approved_posts = 0; $post_ids = $topic_ids = $forum_ids = $post_counts = $remove_topics = array(); - $sql = 'SELECT post_id, poster_id, post_approved, post_postcount, topic_id, forum_id + $sql = 'SELECT post_id, poster_id, post_visibility, post_postcount, topic_id, forum_id FROM ' . POSTS_TABLE . ' WHERE ' . $where_clause; $result = $db->sql_query($sql); @@ -780,12 +958,12 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $topic_ids[] = (int) $row['topic_id']; $forum_ids[] = (int) $row['forum_id']; - if ($row['post_postcount'] && $post_count_sync && $row['post_approved']) + if ($row['post_postcount'] && $post_count_sync && $row['post_visibility'] == ITEM_APPROVED) { $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1; } - if ($row['post_approved']) + if ($row['post_visibility'] == ITEM_APPROVED) { $approved_posts++; } @@ -801,6 +979,32 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $table_ary = array(POSTS_TABLE, REPORTS_TABLE); + /** + * Perform additional actions during post(s) deletion before running the queries + * + * @event core.delete_posts_in_transaction_before + * @var array post_ids Array with deleted posts' ids + * @var array poster_ids Array with deleted posts' author ids + * @var array topic_ids Array with deleted posts' topic ids + * @var array forum_ids Array with deleted posts' forum ids + * @var string where_type Variable containing posts deletion mode + * @var mixed where_ids Array or comma separated list of post ids to delete + * @var array delete_notifications_types Array with notifications types to delete + * @var array table_ary Array with table names to delete data from + * @since 3.1.7-RC1 + */ + $vars = array( + 'post_ids', + 'poster_ids', + 'topic_ids', + 'forum_ids', + 'where_type', + 'where_ids', + 'delete_notifications_types', + 'table_ary', + ); + extract($phpbb_dispatcher->trigger_event('core.delete_posts_in_transaction_before', compact($vars))); + foreach ($table_ary as $table) { $sql = "DELETE FROM $table @@ -848,17 +1052,15 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = } // Remove the message from the search index - $search_type = basename($config['search_type']); + $search_type = $config['search_type']; - if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) + if (!class_exists($search_type)) { trigger_error('NO_SUCH_SEARCH_MODULE'); } - include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx"); - $error = false; - $search = new $search_type($error); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher); if ($error) { @@ -869,8 +1071,56 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = delete_attachments('post', $post_ids, false); + /** + * Perform additional actions during post(s) deletion + * + * @event core.delete_posts_in_transaction + * @var array post_ids Array with deleted posts' ids + * @var array poster_ids Array with deleted posts' author ids + * @var array topic_ids Array with deleted posts' topic ids + * @var array forum_ids Array with deleted posts' forum ids + * @var string where_type Variable containing posts deletion mode + * @var mixed where_ids Array or comma separated list of posts ids to delete + * @var array delete_notifications_types Array with notifications types to delete + * @since 3.1.0-a4 + */ + $vars = array( + 'post_ids', + 'poster_ids', + 'topic_ids', + 'forum_ids', + 'where_type', + 'where_ids', + 'delete_notifications_types', + ); + extract($phpbb_dispatcher->trigger_event('core.delete_posts_in_transaction', compact($vars))); + $db->sql_transaction('commit'); + /** + * Perform additional actions after post(s) deletion + * + * @event core.delete_posts_after + * @var array post_ids Array with deleted posts' ids + * @var array poster_ids Array with deleted posts' author ids + * @var array topic_ids Array with deleted posts' topic ids + * @var array forum_ids Array with deleted posts' forum ids + * @var string where_type Variable containing posts deletion mode + * @var mixed where_ids Array or comma separated list of posts ids to delete + * @var array delete_notifications_types Array with notifications types to delete + * @since 3.1.0-a4 + */ + $vars = array( + 'post_ids', + 'poster_ids', + 'topic_ids', + 'forum_ids', + 'where_type', + 'where_ids', + 'delete_notifications_types', + ); + extract($phpbb_dispatcher->trigger_event('core.delete_posts_after', compact($vars))); + // Resync topics_posted table if ($posted_sync) { @@ -884,7 +1134,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = sync('forum', 'forum_id', $forum_ids, true, true); } - if ($approved_posts) + if ($approved_posts && $post_count_sync) { set_config_count('num_posts', $approved_posts * (-1), true); } @@ -895,6 +1145,10 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false); } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + + $phpbb_notifications->delete_notifications($delete_notifications_types, $post_ids); + return sizeof($post_ids); } @@ -907,7 +1161,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = */ function delete_attachments($mode, $ids, $resync = true) { - global $db, $config; + global $db, $config, $phpbb_dispatcher; // 0 is as bad as an empty array if (empty($ids)) @@ -952,6 +1206,24 @@ function delete_attachments($mode, $ids, $resync = true) $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 . ' @@ -981,6 +1253,32 @@ function delete_attachments($mode, $ids, $resync = true) } $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); @@ -990,6 +1288,34 @@ function delete_attachments($mode, $ids, $resync = true) $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; @@ -1012,6 +1338,38 @@ function delete_attachments($mode, $ids, $resync = 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); @@ -1132,8 +1490,6 @@ function delete_attachments($mode, $ids, $resync = true) * @param bool $auto_sync Will call sync() if this is true * * @return array Array with affected forums -* -* @author bantu */ function delete_topic_shadows($forum_id, $sql_more = '', $auto_sync = true) { @@ -1277,7 +1633,7 @@ function phpbb_unlink($filename, $mode = 'file', $entry_removed = false) * - forum Resync complete forum * - topic Resync topics * - topic_moved Removes topic shadows that would be in the same forum as the topic they link to -* - topic_approved Resyncs the topic_approved flag according to the status of the first post +* - topic_visibility Resyncs the topic_visibility flag according to the status of the first post * - post_reported Resyncs the post_reported flag, relying on actual reports * - topic_reported Resyncs the topic_reported flag, relying on post_reported flags * - post_attachement Same as post_reported, but with attachment flags @@ -1297,7 +1653,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $where_ids = ($where_ids) ? array((int) $where_ids) : array(); } - if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_approved' || $mode == 'topic_reported' || $mode == 'post_reported') + if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_visibility' || $mode == 'topic_reported' || $mode == 'post_reported') { if (!$where_type) { @@ -1343,7 +1699,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { case 'topic_moved': $db->sql_transaction('begin'); - switch ($db->sql_layer) + switch ($db->get_sql_layer()) { case 'mysql4': case 'mysqli': @@ -1383,43 +1739,55 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_transaction('commit'); break; - case 'topic_approved': + case 'topic_visibility': $db->sql_transaction('begin'); - switch ($db->sql_layer) + + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and p.topic_id = t.topic_id + AND p.post_visibility = " . ITEM_APPROVED; + $result = $db->sql_query($sql); + + $topics_approved = array(); + while ($row = $db->sql_fetchrow($result)) { - case 'mysql4': - case 'mysqli': - $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - SET t.topic_approved = p.post_approved - $where_sql_and t.topic_first_post_id = p.post_id"; - $db->sql_query($sql); - break; + $topics_approved[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - default: - $sql = 'SELECT t.topic_id, p.post_approved - FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - $where_sql_and p.post_id = t.topic_first_post_id - AND p.post_approved <> t.topic_approved"; - $result = $db->sql_query($sql); + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and " . $db->sql_in_set('t.topic_id', $topics_approved, true, true) . ' + AND p.topic_id = t.topic_id + AND p.post_visibility = ' . ITEM_DELETED; + $result = $db->sql_query($sql); - $topic_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_ids[] = $row['topic_id']; - } - $db->sql_freeresult($result); + $topics_softdeleted = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topics_softdeleted[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - if (!sizeof($topic_ids)) - { - return; - } + $topics_softdeleted = array_diff($topics_softdeleted, $topics_approved); + $topics_not_unapproved = array_merge($topics_softdeleted, $topics_approved); + + $update_ary = array( + ITEM_UNAPPROVED => (!empty($topics_not_unapproved)) ? $where_sql_and . ' ' . $db->sql_in_set('topic_id', $topics_not_unapproved, true) : '', + ITEM_APPROVED => (!empty($topics_approved)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_approved) : '', + ITEM_DELETED => (!empty($topics_softdeleted)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_softdeleted) : '', + ); + foreach ($update_ary as $visibility => $sql_where) + { + if ($sql_where) + { $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - topic_approved - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); + SET topic_visibility = ' . $visibility . ' + ' . $sql_where; $db->sql_query($sql); - break; + } } $db->sql_transaction('commit'); @@ -1660,9 +2028,12 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $forum_data[$forum_id] = $row; if ($sync_extra) { - $forum_data[$forum_id]['posts'] = 0; - $forum_data[$forum_id]['topics'] = 0; - $forum_data[$forum_id]['topics_real'] = 0; + $forum_data[$forum_id]['posts_approved'] = 0; + $forum_data[$forum_id]['posts_unapproved'] = 0; + $forum_data[$forum_id]['posts_softdeleted'] = 0; + $forum_data[$forum_id]['topics_approved'] = 0; + $forum_data[$forum_id]['topics_unapproved'] = 0; + $forum_data[$forum_id]['topics_softdeleted'] = 0; } $forum_data[$forum_id]['last_post_id'] = 0; $forum_data[$forum_id]['last_post_subject'] = ''; @@ -1683,20 +2054,27 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // 2: Get topic counts for each forum (optional) if ($sync_extra) { - $sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics + $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS total_topics FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' - GROUP BY forum_id, topic_approved'; + GROUP BY forum_id, topic_visibility'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $forum_id = (int) $row['forum_id']; - $forum_data[$forum_id]['topics_real'] += $row['forum_topics']; - if ($row['topic_approved']) + if ($row['topic_visibility'] == ITEM_APPROVED) { - $forum_data[$forum_id]['topics'] = $row['forum_topics']; + $forum_data[$forum_id]['topics_approved'] = $row['total_topics']; + } + else if ($row['topic_visibility'] == ITEM_UNAPPROVED || $row['topic_visibility'] == ITEM_REAPPROVE) + { + $forum_data[$forum_id]['topics_unapproved'] = $row['total_topics']; + } + else if ($row['topic_visibility'] == ITEM_DELETED) + { + $forum_data[$forum_id]['topics_softdeleted'] = $row['total_topics']; } } $db->sql_freeresult($result); @@ -1707,18 +2085,16 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { if (sizeof($forum_ids) == 1) { - $sql = 'SELECT SUM(t.topic_replies + 1) AS forum_posts + $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 WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 AND t.topic_status <> ' . ITEM_MOVED; } else { - $sql = 'SELECT t.forum_id, SUM(t.topic_replies + 1) AS forum_posts + $sql = 'SELECT t.forum_id, 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 WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 AND t.topic_status <> ' . ITEM_MOVED . ' GROUP BY t.forum_id'; } @@ -1729,7 +2105,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; - $forum_data[$forum_id]['posts'] = (int) $row['forum_posts']; + $forum_data[$forum_id]['posts_approved'] = (int) $row['forum_posts_approved']; + $forum_data[$forum_id]['posts_unapproved'] = (int) $row['forum_posts_unapproved']; + $forum_data[$forum_id]['posts_softdeleted'] = (int) $row['forum_posts_softdeleted']; } $db->sql_freeresult($result); } @@ -1740,14 +2118,14 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT MAX(t.topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1'; + AND t.topic_visibility = ' . ITEM_APPROVED; } else { $sql = 'SELECT t.forum_id, MAX(t.topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 + AND t.topic_visibility = ' . ITEM_APPROVED . ' GROUP BY t.forum_id'; } @@ -1810,7 +2188,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($sync_extra) { - array_push($fieldnames, 'posts', 'topics', 'topics_real'); + array_push($fieldnames, 'posts_approved', 'posts_unapproved', 'posts_softdeleted', 'topics_approved', 'topics_unapproved', 'topics_softdeleted'); } foreach ($forum_data as $forum_id => $row) @@ -1845,11 +2223,11 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, break; case 'topic': - $topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array(); + $topic_data = $post_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array(); $db->sql_transaction('begin'); - $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time + $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time FROM ' . TOPICS_TABLE . " t $where_sql"; $result = $db->sql_query($sql); @@ -1864,8 +2242,10 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $topic_id = (int) $row['topic_id']; $topic_data[$topic_id] = $row; - $topic_data[$topic_id]['replies_real'] = -1; - $topic_data[$topic_id]['replies'] = 0; + $topic_data[$topic_id]['visibility'] = ITEM_UNAPPROVED; + $topic_data[$topic_id]['posts_approved'] = 0; + $topic_data[$topic_id]['posts_unapproved'] = 0; + $topic_data[$topic_id]['posts_softdeleted'] = 0; $topic_data[$topic_id]['first_post_id'] = 0; $topic_data[$topic_id]['last_post_id'] = 0; unset($topic_data[$topic_id]['topic_id']); @@ -1882,11 +2262,11 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_freeresult($result); // Use "t" as table alias because of the $where_sql clause - // NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown. - $sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id + // NOTE: 't.post_visibility' in the GROUP BY is causing a major slowdown. + $sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id FROM ' . POSTS_TABLE . " t $where_sql - GROUP BY t.topic_id, t.post_approved"; + GROUP BY t.topic_id, t.post_visibility"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -1907,14 +2287,38 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // When we'll be done, only topics with no posts will remain unset($delete_topics[$topic_id]); - $topic_data[$topic_id]['replies_real'] += $row['total_posts']; - $topic_data[$topic_id]['first_post_id'] = (!$topic_data[$topic_id]['first_post_id']) ? $row['first_post_id'] : min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']); + if ($row['post_visibility'] == ITEM_APPROVED) + { + $topic_data[$topic_id]['posts_approved'] = $row['total_posts']; + } + else if ($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) + { + $topic_data[$topic_id]['posts_unapproved'] = $row['total_posts']; + } + else if ($row['post_visibility'] == ITEM_DELETED) + { + $topic_data[$topic_id]['posts_softdeleted'] = $row['total_posts']; + } - if ($row['post_approved'] || !$topic_data[$topic_id]['last_post_id']) + if ($row['post_visibility'] == ITEM_APPROVED) { - $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; + $topic_data[$topic_id]['visibility'] = ITEM_APPROVED; + $topic_data[$topic_id]['first_post_id'] = $row['first_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; } + else if ($topic_data[$topic_id]['visibility'] != ITEM_APPROVED) + { + // If there is no approved post, we take the min/max of the other visibilities + // for the last and first post info, because it is only visible to moderators anyway + $topic_data[$topic_id]['first_post_id'] = (!empty($topic_data[$topic_id]['first_post_id'])) ? min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']) : $row['first_post_id']; + $topic_data[$topic_id]['last_post_id'] = max($topic_data[$topic_id]['last_post_id'], $row['last_post_id']); + + if ($topic_data[$topic_id]['visibility'] == ITEM_UNAPPROVED || $topic_data[$topic_id]['visibility'] == ITEM_REAPPROVE) + { + // Soft delete status is stronger than unapproved. + $topic_data[$topic_id]['visibility'] = $row['post_visibility']; + } + } } } $db->sql_freeresult($result); @@ -1955,7 +2359,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, unset($delete_topics, $delete_topic_ids); } - $sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour + $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 WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' AND u.user_id = p.poster_id'; @@ -1968,10 +2372,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['post_id'] == $topic_data[$topic_id]['first_post_id']) { - if ($topic_data[$topic_id]['topic_approved'] != $row['post_approved']) - { - $approved_unapproved_ids[] = $topic_id; - } $topic_data[$topic_id]['time'] = $row['post_time']; $topic_data[$topic_id]['poster'] = $row['poster_id']; $topic_data[$topic_id]['first_poster_name'] = ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']; @@ -2032,7 +2432,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sync_shadow_topics = array(); if (sizeof($post_ids)) { - $sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour + $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 WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' AND u.user_id = p.poster_id'; @@ -2099,18 +2499,8 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, unset($sync_shadow_topics, $shadow_topic_data); } - // approved becomes unapproved, and vice-versa - if (sizeof($approved_unapproved_ids)) - { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - topic_approved - WHERE ' . $db->sql_in_set('topic_id', $approved_unapproved_ids); - $db->sql_query($sql); - } - unset($approved_unapproved_ids); - // These are fields that will be synchronised - $fieldnames = array('time', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); + $fieldnames = array('time', 'visibility', 'posts_approved', 'posts_unapproved', 'posts_softdeleted', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); if ($sync_extra) { @@ -2189,9 +2579,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, /** * Prune function */ -function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true) +function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true, $prune_limit = 0) { - global $db; + global $db, $phpbb_dispatcher; if (!is_array($forum_id)) { @@ -2208,6 +2598,7 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync if (!($prune_flags & FORUM_FLAG_PRUNE_ANNOUNCE)) { $sql_and .= ' AND topic_type <> ' . POST_ANNOUNCE; + $sql_and .= ' AND topic_type <> ' . POST_GLOBAL; } if (!($prune_flags & FORUM_FLAG_PRUNE_STICKY)) @@ -2225,12 +2616,42 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync $sql_and .= " AND topic_last_view_time < $prune_date"; } + if ($prune_mode == 'shadow') + { + $sql_and .= ' AND topic_status = ' . ITEM_MOVED . " AND topic_last_post_time < $prune_date"; + } + + /** + * Use this event to modify the SQL that selects topics to be pruned + * + * @event core.prune_sql + * @var string forum_id The forum id + * @var string prune_mode The prune mode + * @var string prune_date The prune date + * @var int prune_flags The prune flags + * @var bool auto_sync Whether or not to perform auto sync + * @var string sql_and SQL text appended to where clause + * @var int prune_limit The prune limit + * @since 3.1.3-RC1 + * @changed 3.1.10-RC1 Added prune_limit + */ + $vars = array( + 'forum_id', + 'prune_mode', + 'prune_date', + 'prune_flags', + 'auto_sync', + 'sql_and', + 'prune_limit', + ); + extract($phpbb_dispatcher->trigger_event('core.prune_sql', compact($vars))); + $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_id) . " AND poll_start = 0 $sql_and"; - $result = $db->sql_query($sql); + $result = $db->sql_query_limit($sql, $prune_limit); $topic_list = array(); while ($row = $db->sql_fetchrow($result)) @@ -2247,7 +2668,7 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync AND poll_start > 0 AND poll_last_vote < $prune_date $sql_and"; - $result = $db->sql_query($sql); + $result = $db->sql_query_limit($sql, $prune_limit); while ($row = $db->sql_fetchrow($result)) { @@ -2280,12 +2701,15 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr $prune_date = time() - ($prune_days * 86400); $next_prune = time() + ($prune_freq * 86400); - prune($forum_id, $prune_mode, $prune_date, $prune_flags, true); + $result = prune($forum_id, $prune_mode, $prune_date, $prune_flags, true, 300); - $sql = 'UPDATE ' . FORUMS_TABLE . " - SET prune_next = $next_prune - WHERE forum_id = $forum_id"; - $db->sql_query($sql); + if ($result['topics'] == 0 && $result['posts'] == 0) + { + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET prune_next = $next_prune + WHERE forum_id = $forum_id"; + $db->sql_query($sql); + } add_log('admin', 'LOG_AUTO_PRUNE', $row['forum_name']); } @@ -2294,36 +2718,25 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr } /** -* remove_comments will strip the sql comment lines out of an uploaded sql file -* specifically for mssql and postgres type files in the install.... +* Cache moderators. Called whenever permissions are changed +* via admin_permissions. Changes of usernames and group names +* must be carried through for the moderators table. * -* @deprecated Use phpbb_remove_comments() instead. +* @param \phpbb\db\driver\driver_interface $db Database connection +* @param \phpbb\cache\driver\driver_interface Cache driver +* @param \phpbb\auth\auth $auth Authentication object +* @return null */ -function remove_comments(&$output) +function phpbb_cache_moderators($db, $cache, $auth) { - // Remove /* */ comments (http://ostermiller.org/findcomment.html) - $output = preg_replace('#/\*(.|[\r\n])*?\*/#', "\n", $output); - - // Return by reference and value. - return $output; -} - -/** -* Cache moderators, called whenever permissions are changed via admin_permissions. Changes of username -* and group names must be carried through for the moderators table -*/ -function cache_moderators() -{ - global $db, $cache, $auth, $phpbb_root_path, $phpEx; - // Remove cached sql results $cache->destroy('sql', MODERATOR_CACHE_TABLE); // Clear table - switch ($db->sql_layer) + switch ($db->get_sql_layer()) { case 'sqlite': - case 'firebird': + case 'sqlite3': $db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE); break; @@ -2345,7 +2758,7 @@ function cache_moderators() $ug_id_ary = array_keys($hold_ary); // Remove users who have group memberships with DENY moderator permissions - $sql = $db->sql_build_query('SELECT', array( + $sql_ary_deny = array( 'SELECT' => 'a.forum_id, ug.user_id, g.group_id', 'FROM' => array( @@ -2358,8 +2771,8 @@ function cache_moderators() 'LEFT_JOIN' => array( array( 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), - 'ON' => 'a.auth_role_id = r.role_id' - ) + 'ON' => 'a.auth_role_id = r.role_id', + ), ), 'WHERE' => '(o.auth_option_id = a.auth_option_id OR o.auth_option_id = r.auth_option_id) @@ -2370,8 +2783,9 @@ function cache_moderators() AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1) AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . " AND ug.user_pending = 0 - AND o.auth_option " . $db->sql_like_expression('m_' . $db->any_char), - )); + AND o.auth_option " . $db->sql_like_expression('m_' . $db->get_any_char()), + ); + $sql = $db->sql_build_query('SELECT', $sql_ary_deny); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -2396,6 +2810,7 @@ function cache_moderators() { $usernames_ary[$row['user_id']] = $row['username']; } + $db->sql_freeresult($result); foreach ($hold_ary as $user_id => $forum_id_ary) { @@ -2486,302 +2901,45 @@ function cache_moderators() /** * View log -* If $log_count is set to false, we will skip counting all entries in the database. +* +* @param string $mode The mode defines which log_type is used and from which log the entry is retrieved +* @param array &$log The result array with the logs +* @param mixed &$log_count If $log_count is set to false, we will skip counting all entries in the database. +* Otherwise an integer with the number of total matching entries is returned. +* @param int $limit Limit the number of entries that are returned +* @param int $offset Offset when fetching the log entries, f.e. when paginating +* @param mixed $forum_id Restrict the log entries to the given forum_id (can also be an array of forum_ids) +* @param int $topic_id Restrict the log entries to the given topic_id +* @param int $user_id Restrict the log entries to the given user_id +* @param int $log_time Only get log entries newer than the given timestamp +* @param string $sort_by SQL order option, e.g. 'l.log_time DESC' +* @param string $keywords Will only return log entries that have the keywords in log_operation or log_data +* +* @return int Returns the offset of the last valid page, if the specified offset was invalid (too high) */ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '') { - global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path; + global $phpbb_log; - $topic_id_list = $reportee_id_list = $is_auth = $is_mod = array(); + $count_logs = ($log_count !== false); - $profile_url = (defined('IN_ADMIN')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview') : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile'); + $log = $phpbb_log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords); + $log_count = $phpbb_log->get_log_count(); - switch ($mode) - { - case 'admin': - $log_type = LOG_ADMIN; - $sql_forum = ''; - break; - - case 'mod': - $log_type = LOG_MOD; - $sql_forum = ''; - - if ($topic_id) - { - $sql_forum = 'AND l.topic_id = ' . (int) $topic_id; - } - else if (is_array($forum_id)) - { - $sql_forum = 'AND ' . $db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); - } - else if ($forum_id) - { - $sql_forum = 'AND l.forum_id = ' . (int) $forum_id; - } - break; - - case 'user': - $log_type = LOG_USERS; - $sql_forum = 'AND l.reportee_id = ' . (int) $user_id; - break; - - case 'users': - $log_type = LOG_USERS; - $sql_forum = ''; - break; - - case 'critical': - $log_type = LOG_CRITICAL; - $sql_forum = ''; - break; - - default: - return; - } - - // Use no preg_quote for $keywords because this would lead to sole backslashes being added - // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later). - $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY); - $sql_keywords = ''; - - if (!empty($keywords)) - { - $keywords_pattern = array(); - - // Build pattern and keywords... - for ($i = 0, $num_keywords = sizeof($keywords); $i < $num_keywords; $i++) - { - $keywords_pattern[] = preg_quote($keywords[$i], '#'); - $keywords[$i] = $db->sql_like_expression($db->any_char . $keywords[$i] . $db->any_char); - } - - $keywords_pattern = '#' . implode('|', $keywords_pattern) . '#ui'; - - $operations = array(); - foreach ($user->lang as $key => $value) - { - if (substr($key, 0, 4) == 'LOG_' && preg_match($keywords_pattern, $value)) - { - $operations[] = $key; - } - } - - $sql_keywords = 'AND ('; - if (!empty($operations)) - { - $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR '; - } - $sql_lower = $db->sql_lower_text('l.log_data'); - $sql_keywords .= "$sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; - } - - if ($log_count !== false) - { - $sql = 'SELECT COUNT(l.log_id) AS total_entries - FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u - WHERE l.log_type = $log_type - AND l.user_id = u.user_id - AND l.log_time >= $limit_days - $sql_keywords - $sql_forum"; - $result = $db->sql_query($sql); - $log_count = (int) $db->sql_fetchfield('total_entries'); - $db->sql_freeresult($result); - } - - // $log_count may be false here if false was passed in for it, - // because in this case we did not run the COUNT() query above. - // If we ran the COUNT() query and it returned zero rows, return; - // otherwise query for logs below. - if ($log_count === 0) - { - // Save the queries, because there are no logs to display - return 0; - } - - if ($offset >= $log_count) - { - $offset = ($offset - $limit < 0) ? 0 : $offset - $limit; - } - - $sql = "SELECT l.*, u.username, u.username_clean, u.user_colour - FROM " . LOG_TABLE . " l, " . USERS_TABLE . " u - WHERE l.log_type = $log_type - AND u.user_id = l.user_id - " . (($limit_days) ? "AND l.log_time >= $limit_days" : '') . " - $sql_keywords - $sql_forum - ORDER BY $sort_by"; - $result = $db->sql_query_limit($sql, $limit, $offset); - - $i = 0; - $log = array(); - while ($row = $db->sql_fetchrow($result)) - { - if ($row['topic_id']) - { - $topic_id_list[] = $row['topic_id']; - } - - if ($row['reportee_id']) - { - $reportee_id_list[] = $row['reportee_id']; - } - - $log[$i] = array( - 'id' => $row['log_id'], - - 'reportee_id' => $row['reportee_id'], - 'reportee_username' => '', - 'reportee_username_full'=> '', - - 'user_id' => $row['user_id'], - 'username' => $row['username'], - 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url), - - 'ip' => $row['log_ip'], - 'time' => $row['log_time'], - 'forum_id' => $row['forum_id'], - 'topic_id' => $row['topic_id'], - - 'viewforum' => ($row['forum_id'] && $auth->acl_get('f_read', $row['forum_id'])) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : false, - 'action' => (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}', - ); - - if (!empty($row['log_data'])) - { - $log_data_ary = @unserialize($row['log_data']); - $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary; - - if (isset($user->lang[$row['log_operation']])) - { - // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array - // It doesn't matter if we add more arguments than placeholders - if ((substr_count($log[$i]['action'], '%') - sizeof($log_data_ary)) > 0) - { - $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($log[$i]['action'], '%') - sizeof($log_data_ary), '')); - } - - $log[$i]['action'] = vsprintf($log[$i]['action'], $log_data_ary); - - // If within the admin panel we do not censor text out - if (defined('IN_ADMIN')) - { - $log[$i]['action'] = bbcode_nl2br($log[$i]['action']); - } - else - { - $log[$i]['action'] = bbcode_nl2br(censor_text($log[$i]['action'])); - } - } - else if (!empty($log_data_ary)) - { - $log[$i]['action'] .= '<br />' . implode('', $log_data_ary); - } - - /* Apply make_clickable... has to be seen if it is for good. :/ - // Seems to be not for the moment, reconsider later... - $log[$i]['action'] = make_clickable($log[$i]['action']); - */ - } - - $i++; - } - $db->sql_freeresult($result); - - if (sizeof($topic_id_list)) - { - $topic_id_list = array_unique($topic_id_list); - - // This query is not really needed if move_topics() updates the forum_id field, - // although it's also used to determine if the topic still exists in the database - $sql = 'SELECT topic_id, forum_id - FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', array_map('intval', $topic_id_list)); - $result = $db->sql_query($sql); - - $default_forum_id = 0; - - while ($row = $db->sql_fetchrow($result)) - { - if (!$row['forum_id']) - { - if ($auth->acl_getf_global('f_read')) - { - if (!$default_forum_id) - { - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type = ' . FORUM_POST; - $f_result = $db->sql_query_limit($sql, 1); - $default_forum_id = (int) $db->sql_fetchfield('forum_id', false, $f_result); - $db->sql_freeresult($f_result); - } - - $is_auth[$row['topic_id']] = $default_forum_id; - } - } - else - { - if ($auth->acl_get('f_read', $row['forum_id'])) - { - $is_auth[$row['topic_id']] = $row['forum_id']; - } - } - - if ($auth->acl_gets('a_', 'm_', $row['forum_id'])) - { - $is_mod[$row['topic_id']] = $row['forum_id']; - } - } - $db->sql_freeresult($result); - - foreach ($log as $key => $row) - { - $log[$key]['viewtopic'] = (isset($is_auth[$row['topic_id']])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $is_auth[$row['topic_id']] . '&t=' . $row['topic_id']) : false; - $log[$key]['viewlogs'] = (isset($is_mod[$row['topic_id']])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&mode=topic_logs&t=' . $row['topic_id'], true, $user->session_id) : false; - } - } - - if (sizeof($reportee_id_list)) - { - $reportee_id_list = array_unique($reportee_id_list); - $reportee_names_list = array(); - - $sql = 'SELECT user_id, username, user_colour - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $reportee_id_list); - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $reportee_names_list[$row['user_id']] = $row; - } - $db->sql_freeresult($result); - - foreach ($log as $key => $row) - { - if (!isset($reportee_names_list[$row['reportee_id']])) - { - continue; - } - - $log[$key]['reportee_username'] = $reportee_names_list[$row['reportee_id']]['username']; - $log[$key]['reportee_username_full'] = get_username_string('full', $row['reportee_id'], $reportee_names_list[$row['reportee_id']]['username'], $reportee_names_list[$row['reportee_id']]['user_colour'], false, $profile_url); - } - } - - return $offset; + return $phpbb_log->get_valid_offset(); } /** -* Update foes - remove moderators and administrators from foe lists... +* Removes moderators and administrators from foe lists. +* +* @param \phpbb\db\driver\driver_interface $db Database connection +* @param \phpbb\auth\auth $auth Authentication object +* @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore +* @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore +* @return null */ -function update_foes($group_id = false, $user_id = false) +function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) { - global $db, $auth; - // update foes for some user if (is_array($user_id) && sizeof($user_id)) { @@ -2796,18 +2954,18 @@ function update_foes($group_id = false, $user_id = false) if (is_array($group_id) && sizeof($group_id)) { // Grab group settings... - $sql = $db->sql_build_query('SELECT', array( + $sql_ary = array( 'SELECT' => 'a.group_id', 'FROM' => array( ACL_OPTIONS_TABLE => 'ao', - ACL_GROUPS_TABLE => 'a' + ACL_GROUPS_TABLE => 'a', ), 'LEFT_JOIN' => array( array( 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), - 'ON' => 'a.auth_role_id = r.role_id' + 'ON' => 'a.auth_role_id = r.role_id', ), ), @@ -2815,8 +2973,9 @@ function update_foes($group_id = false, $user_id = false) AND ' . $db->sql_in_set('a.group_id', $group_id) . " AND ao.auth_option IN ('a_', 'm_')", - 'GROUP_BY' => 'a.group_id' - )); + 'GROUP_BY' => 'a.group_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); $groups = array(); @@ -2831,11 +2990,11 @@ function update_foes($group_id = false, $user_id = false) return; } - switch ($db->sql_layer) + switch ($db->get_sql_layer()) { case 'mysqli': case 'mysql4': - $sql = 'DELETE ' . (($db->sql_layer === 'mysqli' || version_compare($db->sql_server_info(true), '4.1', '>=')) ? 'z.*' : ZEBRA_TABLE) . ' + $sql = 'DELETE ' . (($db->get_sql_layer() === 'mysqli' || version_compare($db->sql_server_info(true), '4.1', '>=')) ? 'z.*' : ZEBRA_TABLE) . ' FROM ' . ZEBRA_TABLE . ' z, ' . USER_GROUP_TABLE . ' ug WHERE z.zebra_id = ug.user_id AND z.foe = 1 @@ -2946,6 +3105,7 @@ function view_inactive_users(&$users, &$user_count, $limit = 0, $offset = 0, $li $users[] = $row; } + $db->sql_freeresult($result); return $offset; } @@ -2988,7 +3148,7 @@ function get_database_size() $database_size = false; // This code is heavily influenced by a similar routine in phpMyAdmin 2.2.0 - switch ($db->sql_layer) + switch ($db->get_sql_layer()) { case 'mysql': case 'mysql4': @@ -3002,9 +3162,9 @@ function get_database_size() { $version = $row['mysql_version']; - if (preg_match('#(3\.23|[45]\.)#', $version)) + if (preg_match('#(3\.23|[45]\.|10\.[0-9]\.[0-9]{1,2}-+Maria)#', $version)) { - $db_name = (preg_match('#^(?:3\.23\.(?:[6-9]|[1-9]{2}))|[45]\.#', $version)) ? "`{$db->dbname}`" : $db->dbname; + $db_name = (preg_match('#^(?:3\.23\.(?:[6-9]|[1-9]{2}))|[45]\.|10\.[0-9]\.[0-9]{1,2}-+Maria#', $version)) ? "`{$db->get_db_name()}`" : $db->get_db_name(); $sql = 'SHOW TABLE STATUS FROM ' . $db_name; @@ -3013,7 +3173,7 @@ function get_database_size() $database_size = 0; while ($row = $db->sql_fetchrow($result)) { - if ((isset($row['Type']) && $row['Type'] != 'MRG_MyISAM') || (isset($row['Engine']) && ($row['Engine'] == 'MyISAM' || $row['Engine'] == 'InnoDB'))) + if ((isset($row['Type']) && $row['Type'] != 'MRG_MyISAM') || (isset($row['Engine']) && ($row['Engine'] == 'MyISAM' || $row['Engine'] == 'InnoDB' || $row['Engine'] == 'Aria'))) { if ($table_prefix != '') { @@ -3033,18 +3193,8 @@ function get_database_size() } break; - case 'firebird': - global $dbname; - - // if it on the local machine, we can get lucky - if (file_exists($dbname)) - { - $database_size = filesize($dbname); - } - - break; - case 'sqlite': + case 'sqlite3': global $dbhost; if (file_exists($dbhost)) @@ -3061,7 +3211,7 @@ function get_database_size() $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - + $sql = 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize FROM sysfiles'; @@ -3070,7 +3220,7 @@ function get_database_size() // Azure stats are stored elsewhere if (strpos($row['mssql_version'], 'SQL Azure') !== false) { - $sql = 'SELECT ((SUM(reserved_page_count) * 8.0) * 1024.0) as dbsize + $sql = 'SELECT ((SUM(reserved_page_count) * 8.0) * 1024.0) as dbsize FROM sys.dm_db_partition_stats'; } } @@ -3090,7 +3240,7 @@ function get_database_size() if ($row['proname'] == 'pg_database_size') { - $database = $db->dbname; + $database = $db->get_db_name(); if (strpos($database, '.') !== false) { list($database, ) = explode('.', $database); @@ -3130,71 +3280,24 @@ function get_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 $user; - - if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout)) - { - @fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n"); - @fputs($fsock, "HOST: $host\r\n"); - @fputs($fsock, "Connection: close\r\n\r\n"); - - $timer_stop = time() + $timeout; - stream_set_timeout($fsock, $timeout); - - $file_info = ''; - $get_info = false; - - while (!@feof($fsock)) - { - if ($get_info) - { - $file_info .= @fread($fsock, 1024); - } - else - { - $line = @fgets($fsock, 1024); - if ($line == "\r\n") - { - $get_info = true; - } - else if (stripos($line, '404 not found') !== false) - { - $errstr = $user->lang['FILE_NOT_FOUND'] . ': ' . $filename; - return false; - } - } + global $phpbb_container; - $stream_meta_data = stream_get_meta_data($fsock); + // Get file downloader and assign $errstr and $errno + $file_downloader = $phpbb_container->get('file_downloader'); - if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop) - { - $errstr = $user->lang['FSOCK_TIMEOUT']; - return false; - } - } - @fclose($fsock); - } - else - { - if ($errstr) - { - $errstr = utf8_convert_message($errstr); - return false; - } - else - { - $errstr = $user->lang['FSOCK_DISABLED']; - return false; - } - } + $file_data = $file_downloader->get($host, $directory, $filename, $port, $timeout); + $errstr = $file_downloader->get_error_string(); + $errno = $file_downloader->get_error_number(); - return $file_info; + return $file_data; } -/** +/* * Tidy Warnings * Remove all warnings which have now expired from the database * The duration of a warning can be defined by the administrator @@ -3278,77 +3381,58 @@ function tidy_database() */ function add_permission_language() { - global $user, $phpEx; + global $config, $user, $phpEx, $phpbb_extension_manager; - // First of all, our own file. We need to include it as the first file because it presets all relevant variables. - $user->add_lang('acp/permissions_phpbb'); + // add permission language files from extensions + $finder = $phpbb_extension_manager->get_finder(); - $files_to_add = array(); + // 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(); - // Now search in acp and mods folder for permissions_ files. - foreach (array('acp/', 'mods/') as $path) + // Search for board default language if it's not the user language + if ($config['default_lang'] != $user->lang_name) { - $dh = @opendir($user->lang_path . $user->lang_name . '/' . $path); - - if ($dh) - { - while (($file = readdir($dh)) !== false) - { - if ($file !== 'permissions_phpbb.' . $phpEx && strpos($file, 'permissions_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx) - { - $files_to_add[] = $path . substr($file, 0, -(strlen($phpEx) + 1)); - } - } - closedir($dh); - } + $default_lang_files = $finder + ->prefix('permissions_') + ->suffix(".$phpEx") + ->core_path('language/' . basename($config['default_lang']) . '/') + ->extension_directory('/language/' . basename($config['default_lang'])) + ->find(); } - if (!sizeof($files_to_add)) + // Search for english, if its not the default or user language + if ($config['default_lang'] != 'en' && $user->lang_name != 'en') { - return false; + $english_lang_files = $finder + ->prefix('permissions_') + ->suffix(".$phpEx") + ->core_path('language/en/') + ->extension_directory('/language/en') + ->find(); } - $user->add_lang($files_to_add); - return true; -} + // Find files in the user's language + $user_lang_files = $finder + ->prefix('permissions_') + ->suffix(".$phpEx") + ->core_path('language/' . $user->lang_name . '/') + ->extension_directory('/language/' . $user->lang_name) + ->find(); -/** - * Obtains the latest version information - * - * @param bool $force_update Ignores cached data. Defaults to false. - * @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false. - * @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours). - * - * @return string | false Version info on success, false on failure. - */ -function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400) -{ - global $cache; + $lang_files = array_merge($english_lang_files, $default_lang_files, $user_lang_files); - $info = $cache->get('versioncheck'); - - if ($info === false || $force_update) + foreach ($lang_files as $lang_file => $ext_name) { - $errstr = ''; - $errno = 0; - - $info = get_remote_file('version.phpbb.com', '/phpbb', - ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); - - if (empty($info)) + if ($ext_name === '/') { - $cache->destroy('versioncheck'); - if ($warn_fail) - { - trigger_error($errstr, E_USER_WARNING); - } - return false; + $user->add_lang($lang_file); + } + else + { + $user->add_lang_ext($ext_name, $lang_file); } - - $cache->put('versioncheck', $info, $ttl); } - - return $info; } /** @@ -3370,5 +3454,3 @@ function enable_bitfield_column_flag($table_name, $column_name, $flag, $sql_more ' . $sql_more; $db->sql_query($sql); } - -?>
\ No newline at end of file |