diff options
Diffstat (limited to 'phpBB/includes/mcp/mcp_main.php')
-rw-r--r-- | phpBB/includes/mcp/mcp_main.php | 190 |
1 files changed, 135 insertions, 55 deletions
diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 3d56bba21c..744eaebd7d 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -28,9 +28,9 @@ class mcp_main var $p_master; var $u_action; - function mcp_main(&$p_master) + function __construct($p_master) { - $this->p_master = &$p_master; + $this->p_master = $p_master; } function main($id, $mode) @@ -41,13 +41,29 @@ class mcp_main $quickmod = ($mode == 'quickmod') ? true : false; + /** + * Event to perform additional actions before an MCP action is executed. + * + * @event core.mcp_main_before + * @var string action The action that is about to be performed + * @var string mode The mode in which the MCP is accessed, e.g. front, forum_view, topic_view, post_details, quickmod + * @var boolean quickmod Whether or not the action is performed via QuickMod + * @since 3.2.8-RC1 + */ + $vars = [ + 'action', + 'mode', + 'quickmod', + ]; + extract($phpbb_dispatcher->trigger_event('core.mcp_main_before', compact($vars))); + switch ($action) { case 'lock': case 'unlock': $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } @@ -60,7 +76,7 @@ class mcp_main $post_ids = (!$quickmod) ? $request->variable('post_id_list', array(0)) : array($request->variable('p', 0)); - if (!sizeof($post_ids)) + if (!count($post_ids)) { trigger_error('NO_POST_SELECTED'); } @@ -75,7 +91,7 @@ class mcp_main $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } @@ -88,7 +104,7 @@ class mcp_main $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } @@ -101,7 +117,7 @@ class mcp_main $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } @@ -118,7 +134,7 @@ class mcp_main $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } @@ -135,7 +151,7 @@ class mcp_main $post_ids = (!$quickmod) ? $request->variable('post_id_list', array(0)) : array($request->variable('p', 0)); $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; - if (!sizeof($post_ids)) + if (!count($post_ids)) { trigger_error('NO_POST_SELECTED'); } @@ -148,7 +164,7 @@ class mcp_main $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } @@ -174,7 +190,10 @@ class mcp_main switch ($mode) { case 'front': - include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx); + if (!function_exists('mcp_front_view')) + { + include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx); + } $user->add_lang('acp/common'); @@ -185,7 +204,10 @@ class mcp_main break; case 'forum_view': - include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx); + if (!function_exists('mcp_forum_view')) + { + include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx); + } $user->add_lang('viewforum'); @@ -193,7 +215,7 @@ class mcp_main $forum_info = phpbb_get_forum_data($forum_id, 'm_', true); - if (!sizeof($forum_info)) + if (!count($forum_info)) { $this->main('main', 'front'); return; @@ -208,7 +230,10 @@ class mcp_main break; case 'topic_view': - include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx); + if (!function_exists('mcp_topic_view')) + { + include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx); + } mcp_topic_view($id, $mode, $action); @@ -217,7 +242,10 @@ class mcp_main break; case 'post_details': - include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx); + if (!function_exists('mcp_post_details')) + { + include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx); + } mcp_post_details($id, $mode, $action); @@ -342,7 +370,7 @@ function lock_unlock($action, $ids) ); extract($phpbb_dispatcher->trigger_event('core.mcp_lock_unlock_after', compact($vars))); - $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS'; + $success_msg = $l_prefix . ((count($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS'; meta_refresh(2, $redirect); $message = $user->lang[$success_msg]; @@ -355,7 +383,7 @@ function lock_unlock($action, $ids) } else { - confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields); + confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((count($ids) == 1) ? '' : 'S'), $s_hidden_fields); } redirect($redirect); @@ -366,32 +394,32 @@ function lock_unlock($action, $ids) */ function change_topic_type($action, $topic_ids) { - global $user, $db, $request, $phpbb_log; + global $user, $db, $request, $phpbb_log, $phpbb_dispatcher; switch ($action) { case 'make_announce': $new_topic_type = POST_ANNOUNCE; $check_acl = 'f_announce'; - $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS'; + $l_new_type = (count($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS'; break; case 'make_global': $new_topic_type = POST_GLOBAL; $check_acl = 'f_announce_global'; - $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS'; + $l_new_type = (count($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS'; break; case 'make_sticky': $new_topic_type = POST_STICKY; $check_acl = 'f_sticky'; - $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES'; + $l_new_type = (count($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES'; break; default: $new_topic_type = POST_NORMAL; $check_acl = false; - $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS'; + $l_new_type = (count($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS'; break; } @@ -414,27 +442,43 @@ function change_topic_type($action, $topic_ids) if (confirm_box(true)) { + + /** + * Perform additional actions before changing topic(s) type + * + * @event core.mcp_change_topic_type_before + * @var int new_topic_type The candidated topic type. + * @var int forum_id The forum ID for the topic ID(s). + * @var array topic_ids Array containing the topic ID(s) that will be changed + * @since 3.2.6-RC1 + */ + $vars = array( + 'new_topic_type', + 'forum_id', + 'topic_ids', + ); + extract($phpbb_dispatcher->trigger_event('core.mcp_change_topic_type_before', compact($vars))); + + $db->sql_transaction('begin'); + $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_type = $new_topic_type WHERE " . $db->sql_in_set('topic_id', $topic_ids); $db->sql_query($sql); - if (($new_topic_type == POST_GLOBAL) && sizeof($topic_ids)) + if (($new_topic_type == POST_GLOBAL) && count($topic_ids)) { // Delete topic shadows for global announcements $sql = 'DELETE FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids); $db->sql_query($sql); - - $sql = 'UPDATE ' . TOPICS_TABLE . " - SET topic_type = $new_topic_type - WHERE " . $db->sql_in_set('topic_id', $topic_ids); - $db->sql_query($sql); } - $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED'; + $db->sql_transaction('commit'); + + $success_msg = (count($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED'; - if (sizeof($topic_ids)) + if (count($topic_ids)) { $data = phpbb_get_topic_data($topic_ids); @@ -448,6 +492,22 @@ function change_topic_type($action, $topic_ids) } } + /** + * Perform additional actions after changing topic types + * + * @event core.mcp_change_topic_type_after + * @var int new_topic_type The newly changed topic type. + * @var int forum_id The forum ID where the newly changed topic type belongs to. + * @var array topic_ids Array containing the topic IDs that have been changed + * @since 3.2.6-RC1 + */ + $vars = array( + 'new_topic_type', + 'forum_id', + 'topic_ids', + ); + extract($phpbb_dispatcher->trigger_event('core.mcp_change_topic_type_after', compact($vars))); + meta_refresh(2, $redirect); $message = $user->lang[$success_msg]; @@ -496,7 +556,7 @@ function mcp_move_topic($topic_ids) { $forum_data = phpbb_get_forum_data($to_forum_id, 'f_post'); - if (!sizeof($forum_data)) + if (!count($forum_data)) { $additional_msg = $user->lang['FORUM_NOT_EXIST']; } @@ -691,7 +751,7 @@ function mcp_move_topic($topic_ids) $sync_sql[$forum_id][] = 'forum_topics_softdeleted = forum_topics_softdeleted - ' . (int) $topics_moved_softdeleted; } - $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS'; + $success_msg = (count($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS'; foreach ($sync_sql as $forum_id_key => $array) { @@ -714,7 +774,7 @@ function mcp_move_topic($topic_ids) 'ADDITIONAL_MSG' => $additional_msg) ); - confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); + confirm_box(false, 'MOVE_TOPIC' . ((count($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); } $redirect = $request->variable('redirect', "index.$phpEx"); @@ -762,7 +822,7 @@ function mcp_restore_topic($topic_ids) if (confirm_box(true)) { - $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_RESTORED_SUCCESS' : 'TOPICS_RESTORED_SUCCESS'; + $success_msg = (count($topic_ids) == 1) ? 'TOPIC_RESTORED_SUCCESS' : 'TOPICS_RESTORED_SUCCESS'; $data = phpbb_get_topic_data($topic_ids); @@ -784,7 +844,7 @@ function mcp_restore_topic($topic_ids) } else { - confirm_box(false, (sizeof($topic_ids) == 1) ? 'RESTORE_TOPIC' : 'RESTORE_TOPICS', $s_hidden_fields); + confirm_box(false, (count($topic_ids) == 1) ? 'RESTORE_TOPIC' : 'RESTORE_TOPICS', $s_hidden_fields); } $topic_id = $request->variable('t', 0); @@ -842,7 +902,7 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' if (confirm_box(true)) { - $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS'; + $success_msg = (count($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS'; $data = phpbb_get_topic_data($topic_ids); @@ -927,13 +987,14 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' 'S_TOPIC_MODE' => true, 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id), 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id), - 'DELETE_TOPIC_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_TOPIC_PERMANENTLY', sizeof($topic_ids)), + 'DELETE_TOPIC_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_TOPIC_PERMANENTLY', count($topic_ids)), )); - $l_confirm = (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; + $count = count($topic_ids); + $l_confirm = $count === 1 ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; if ($only_softdeleted) { - $l_confirm .= '_PERMANENTLY'; + $l_confirm = array($l_confirm . '_PERMANENTLY', $count); $s_hidden_fields['delete_permanent'] = '1'; } else if ($only_shadow || !$auth->acl_get('m_softdelete', $forum_id)) @@ -1042,11 +1103,11 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', { $phpbb_content_visibility->set_post_visibility(ITEM_DELETED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), $soft_delete_reason, isset($topic_data['first_post']), isset($topic_data['last_post'])); } - $affected_topics = sizeof($topic_info); + $affected_topics = count($topic_info); // None of the topics is really deleted, so a redirect won't hurt much. $deleted_topics = 0; - $success_msg = (sizeof($post_info) == 1) ? $user->lang['POST_DELETED_SUCCESS'] : $user->lang['POSTS_DELETED_SUCCESS']; + $success_msg = (count($post_info) == 1) ? $user->lang['POST_DELETED_SUCCESS'] : $user->lang['POSTS_DELETED_SUCCESS']; foreach ($approve_log as $row) { @@ -1093,7 +1154,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', { $topic_id_list[] = $row['topic_id']; } - $affected_topics = sizeof($topic_id_list); + $affected_topics = count($topic_id_list); $db->sql_freeresult($result); $post_data = phpbb_get_post_data($post_ids); @@ -1132,7 +1193,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', } $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>'); - if (sizeof($post_ids) == 1) + if (count($post_ids) == 1) { if ($deleted_topics) { @@ -1181,13 +1242,14 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', 'S_SOFTDELETED' => $only_softdeleted, 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id), 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id), - 'DELETE_POST_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_POST_PERMANENTLY', sizeof($post_ids)), + 'DELETE_POST_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_POST_PERMANENTLY', count($post_ids)), )); - $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS'; + $count = count($post_ids); + $l_confirm = $count === 1 ? 'DELETE_POST' : 'DELETE_POSTS'; if ($only_softdeleted) { - $l_confirm .= '_PERMANENTLY'; + $l_confirm = array($l_confirm . '_PERMANENTLY', $count); $s_hidden_fields['delete_permanent'] = '1'; } else if (!$auth->acl_get('m_softdelete', $forum_id)) @@ -1247,11 +1309,11 @@ function mcp_fork_topic($topic_ids) { $forum_data = phpbb_get_forum_data($to_forum_id, 'f_post'); - if (!sizeof($topic_ids)) + if (!count($topic_ids)) { $additional_msg = $user->lang['NO_TOPIC_SELECTED']; } - else if (!sizeof($forum_data)) + else if (!count($forum_data)) { $additional_msg = $user->lang['FORUM_NOT_EXIST']; } @@ -1409,7 +1471,7 @@ function mcp_fork_topic($topic_ids) } $db->sql_freeresult($result); - if (!sizeof($post_rows)) + if (!count($post_rows)) { continue; } @@ -1458,6 +1520,24 @@ function mcp_fork_topic($topic_ids) $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $new_post_id = $db->sql_nextid(); + /** + * Perform actions after forked topic is created. + * + * @event core.mcp_main_fork_sql_after + * @var int new_topic_id The newly created topic ID + * @var int to_forum_id The forum ID where the forked topic has been moved to + * @var int new_post_id The newly created post ID + * @var array row Post data + * @since 3.2.4-RC1 + */ + $vars = array( + 'new_topic_id', + 'to_forum_id', + 'new_post_id', + 'row', + ); + extract($phpbb_dispatcher->trigger_event('core.mcp_main_fork_sql_after', compact($vars))); + switch ($row['post_visibility']) { case ITEM_APPROVED: @@ -1512,7 +1592,7 @@ function mcp_fork_topic($topic_ids) } $db->sql_freeresult($result); - if (sizeof($sql_ary)) + if (count($sql_ary)) { $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary); } @@ -1536,7 +1616,7 @@ function mcp_fork_topic($topic_ids) } $db->sql_freeresult($result); - if (sizeof($sql_ary)) + if (count($sql_ary)) { $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary); } @@ -1557,7 +1637,7 @@ function mcp_fork_topic($topic_ids) } $db->sql_freeresult($result); - if (sizeof($sql_ary)) + if (count($sql_ary)) { $db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary); } @@ -1589,7 +1669,7 @@ function mcp_fork_topic($topic_ids) sync('topic', 'topic_id', $new_topic_id_list); sync('forum', 'forum_id', $to_forum_id); - $config->increment('num_topics', sizeof($new_topic_id_list), false); + $config->increment('num_topics', count($new_topic_id_list), false); $config->increment('num_posts', $total_posts, false); foreach ($new_topic_id_list as $topic_id => $new_topic_id) @@ -1601,7 +1681,7 @@ function mcp_fork_topic($topic_ids) )); } - $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS'; + $success_msg = (count($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS'; } else { @@ -1611,7 +1691,7 @@ function mcp_fork_topic($topic_ids) 'ADDITIONAL_MSG' => $additional_msg) ); - confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); + confirm_box(false, 'FORK_TOPIC' . ((count($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); } $redirect = $request->variable('redirect', "index.$phpEx"); |