/** * View all unapproved posts or topics */ public function action_unapproved() { global $txt, $scripturl, $context, $user_info; $context['current_view'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? 'topics' : 'replies'; $context['page_title'] = $txt['mc_unapproved_posts']; $context['header_title'] = $txt['mc_' . ($context['current_view'] == 'topics' ? 'topics' : 'posts')]; // Work out what boards we can work in! $approve_boards = !empty($user_info['mod_cache']['ap']) ? $user_info['mod_cache']['ap'] : boardsAllowedTo('approve_posts'); // If we filtered by board remove ones outside of this board. // @todo Put a message saying we're filtered? if (isset($_REQUEST['brd'])) { $filter_board = array((int) $_REQUEST['brd']); $approve_boards = $approve_boards == array(0) ? $filter_board : array_intersect($approve_boards, $filter_board); } if ($approve_boards == array(0)) { $approve_query = ''; } elseif (!empty($approve_boards)) { $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; } else { $approve_query = ' AND 1=0'; } // We also need to know where we can delete topics and/or replies to. if ($context['current_view'] == 'topics') { $delete_own_boards = boardsAllowedTo('remove_own'); $delete_any_boards = boardsAllowedTo('remove_any'); $delete_own_replies = array(); } else { $delete_own_boards = boardsAllowedTo('delete_own'); $delete_any_boards = boardsAllowedTo('delete_any'); $delete_own_replies = boardsAllowedTo('delete_own_replies'); } $toAction = array(); // Check if we have something to do? if (isset($_GET['approve'])) { $toAction[] = (int) $_GET['approve']; } elseif (isset($_GET['delete'])) { $toAction[] = (int) $_GET['delete']; } elseif (isset($_POST['item'])) { foreach ($_POST['item'] as $item) { $toAction[] = (int) $item; } } // What are we actually doing. if (isset($_GET['approve']) || isset($_POST['do']) && $_POST['do'] == 'approve') { $curAction = 'approve'; } elseif (isset($_GET['delete']) || isset($_POST['do']) && $_POST['do'] == 'delete') { $curAction = 'delete'; } // Right, so we have something to do? if (!empty($toAction) && isset($curAction)) { checkSession('request'); require_once SUBSDIR . '/Topic.subs.php'; require_once SUBSDIR . '/Messages.subs.php'; // Handy shortcut. $any_array = $curAction == 'approve' ? $approve_boards : $delete_any_boards; // Now for each message work out whether it's actually a topic, and what board it's on. $request = loadMessageDetails(array('m.id_board', 't.id_topic', 't.id_first_msg', 't.id_member_started'), array('INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)', 'LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)'), array('message_list' => $toAction, 'not_approved' => 0), array('additional_conditions' => ' AND m.approved = {int:not_approved} AND {query_see_board}')); $toAction = array(); $details = array(); foreach ($request as $row) { // If it's not within what our view is ignore it... if ($row['id_msg'] == $row['id_first_msg'] && $context['current_view'] != 'topics' || $row['id_msg'] != $row['id_first_msg'] && $context['current_view'] != 'replies') { continue; } $can_add = false; // If we're approving this is simple. if ($curAction == 'approve' && ($any_array == array(0) || in_array($row['id_board'], $any_array))) { $can_add = true; } elseif ($curAction == 'delete') { // Own post is easy! if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) { $can_add = true; } elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) { $can_add = true; } elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) { $can_add = true; } } if ($can_add) { $anItem = $context['current_view'] == 'topics' ? $row['id_topic'] : $row['id_msg']; $toAction[] = $anItem; // All clear. What have we got now, what, what? $details[$anItem] = array(); $details[$anItem]['subject'] = $row['subject']; $details[$anItem]['topic'] = $row['id_topic']; $details[$anItem]['member'] = $context['current_view'] == 'topics' ? $row['id_member_started'] : $row['id_member']; $details[$anItem]['board'] = $row['id_board']; } } // If we have anything left we can actually do the approving (etc). if (!empty($toAction)) { if ($curAction == 'approve') { approveMessages($toAction, $details, $context['current_view']); } else { removeMessages($toAction, $details, $context['current_view']); } cache_put_data('num_menu_errors', null, 900); } } // Get the moderation values for the board level $brd = isset($_REQUEST['brd']) ? (int) $_REQUEST['brd'] : null; require_once SUBSDIR . '/Moderation.subs.php'; $mod_count = loadModeratorMenuCounts($brd); $context['total_unapproved_topics'] = $mod_count['topics']; $context['total_unapproved_posts'] = $mod_count['posts']; $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=postmod;sa=' . $context['current_view'] . (isset($_REQUEST['brd']) ? ';brd=' . (int) $_REQUEST['brd'] : ''), $_GET['start'], $context['current_view'] == 'topics' ? $context['total_unapproved_topics'] : $context['total_unapproved_posts'], 10); $context['start'] = $_GET['start']; // We have enough to make some pretty tabs! $context[$context['moderation_menu_name']]['tab_data'] = array('title' => $txt['mc_unapproved_posts'], 'help' => 'postmod', 'description' => $txt['mc_unapproved_posts_desc']); // Update the tabs with the correct number of actions to account for brd filtering $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['posts']['label'] = $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['posts']['label'] . ' [' . $context['total_unapproved_posts'] . ']'; $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['topics']['label'] = $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['topics']['label'] . ' [' . $context['total_unapproved_topics'] . ']'; // If we are filtering some boards out then make sure to send that along with the links. if (isset($_REQUEST['brd'])) { $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['posts']['add_params'] = ';brd=' . (int) $_REQUEST['brd']; $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['topics']['add_params'] = ';brd=' . (int) $_REQUEST['brd']; } // Get all unapproved posts. $context['unapproved_items'] = getUnapprovedPosts($approve_query, $context['current_view'], array('delete_own_boards' => $delete_own_boards, 'delete_any_boards' => $delete_any_boards, 'delete_own_replies' => $delete_own_replies), $context['start'], 10); foreach ($context['unapproved_items'] as $key => $item) { $context['unapproved_items'][$key]['buttons'] = array('quickmod_check' => array('checkbox' => true, 'name' => 'item', 'value' => $item['id']), 'approve' => array('href' => $scripturl . '?action=moderate;area=postmod;sa=' . $context['current_view'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';approve=' . $item['id'], 'text' => $txt['approve']), 'unapprove' => array('href' => $scripturl . '?action=moderate;area=postmod;sa=' . $context['current_view'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';delete=' . $item['id'], 'text' => $txt['remove'], 'test' => 'can_delete')); $context['unapproved_items'][$key]['tests'] = array('can_delete' => $item['can_delete']); } $context['sub_template'] = 'unapproved_posts'; }
/** * Shows a list of items requiring moderation action * Includes post, topic, attachment, group, member and PBE values with links to each */ public function block_actionRequired() { global $context; // Get the action totals $mod_totals = loadModeratorMenuCounts(); // This blocks total is only these fields $context['mc_required'] = $mod_totals['attachments'] + $mod_totals['emailmod'] + $mod_totals['topics'] + $mod_totals['posts'] + $mod_totals['memberreq'] + $mod_totals['groupreq'] + +$mod_totals['reports']; unset($mod_totals['postmod'], $mod_totals['pt_total'], $mod_totals['mg_total'], $mod_totals['grand_total']); $context['required'] = $mod_totals; // Links to the areas $context['links'] = array('attachments' => '?action=moderate;area=attachmod;sa=attachments', 'emailmod' => '?action=admin;area=maillist;sa=emaillist', 'topics' => '?action=moderate;area=postmod;sa=topics', 'posts' => '?action=moderate;area=postmod;sa=posts', 'memberreq' => '?action=admin;area=viewmembers;sa=browse;type=approve', 'groupreq' => '?action=moderate;area=groups;sa=requests', 'reports' => '?action=moderate;area=reports;sa=open'); return 'action_required'; }
/** * Sets up all of the top menu buttons * * What it does: * - defines every master item in the menu, as well as any sub-items * - ensures the chosen action is set so the menu is highlighted * - Saves them in the cache if it is available and on * - Places the results in $context */ function setupMenuContext() { global $context, $modSettings, $user_info, $txt, $scripturl, $settings; // Set up the menu privileges. $context['allow_search'] = !empty($modSettings['allow_guestAccess']) ? allowedTo('search_posts') : !$user_info['is_guest'] && allowedTo('search_posts'); $context['allow_admin'] = allowedTo(array('admin_forum', 'manage_boards', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_attachments', 'manage_smileys')); $context['allow_edit_profile'] = !$user_info['is_guest'] && allowedTo(array('profile_view_own', 'profile_view_any', 'profile_identity_own', 'profile_identity_any', 'profile_extra_own', 'profile_extra_any', 'profile_remove_own', 'profile_remove_any', 'moderate_forum', 'manage_membergroups', 'profile_title_own', 'profile_title_any')); $context['allow_memberlist'] = allowedTo('view_mlist'); $context['allow_calendar'] = allowedTo('calendar_view') && !empty($modSettings['cal_enabled']); $context['allow_moderation_center'] = $context['user']['can_mod']; $context['allow_pm'] = allowedTo('pm_read'); if ($context['allow_search']) { $context['theme_header_callbacks'] = elk_array_insert($context['theme_header_callbacks'], 'login_bar', array('search_bar'), 'after'); } $cacheTime = $modSettings['lastActive'] * 60; // Update the Moderation menu items with action item totals if ($context['allow_moderation_center']) { // Get the numbers for the menu ... require_once SUBSDIR . '/Moderation.subs.php'; $menu_count = loadModeratorMenuCounts(); } $menu_count['unread_messages'] = $context['user']['unread_messages']; $menu_count['mentions'] = $context['user']['mentions']; // All the buttons we can possible want and then some, try pulling the final list of buttons from cache first. if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated']) { // Start things up: this is what we know by default require_once SUBSDIR . '/Menu.subs.php'; $buttons = array('home' => array('title' => $txt['community'], 'href' => $scripturl, 'data-icon' => '', 'show' => true, 'sub_buttons' => array('help' => array('title' => $txt['help'], 'href' => $scripturl . '?action=help', 'show' => true), 'search' => array('title' => $txt['search'], 'href' => $scripturl . '?action=search', 'show' => $context['allow_search']), 'calendar' => array('title' => $txt['calendar'], 'href' => $scripturl . '?action=calendar', 'show' => $context['allow_calendar']), 'memberlist' => array('title' => $txt['members_title'], 'href' => $scripturl . '?action=memberlist', 'show' => $context['allow_memberlist']), 'recent' => array('title' => $txt['recent_posts'], 'href' => $scripturl . '?action=recent', 'show' => true)))); // Will change title correctly if user is either a mod or an admin. // Button highlighting works properly too (see current action stuffz). if ($context['allow_admin']) { $buttons['admin'] = array('title' => $context['current_action'] !== 'moderate' ? $txt['admin'] : $txt['moderate'], 'counter' => 'grand_total', 'href' => $scripturl . '?action=admin', 'data-icon' => '', 'show' => true, 'sub_buttons' => array('admin_center' => array('title' => $txt['admin_center'], 'href' => $scripturl . '?action=admin', 'show' => $context['allow_admin']), 'featuresettings' => array('title' => $txt['modSettings_title'], 'href' => $scripturl . '?action=admin;area=featuresettings', 'show' => allowedTo('admin_forum')), 'packages' => array('title' => $txt['package'], 'href' => $scripturl . '?action=admin;area=packages', 'show' => allowedTo('admin_forum')), 'permissions' => array('title' => $txt['edit_permissions'], 'href' => $scripturl . '?action=admin;area=permissions', 'show' => allowedTo('manage_permissions')), 'errorlog' => array('title' => $txt['errlog'], 'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc', 'show' => allowedTo('admin_forum') && !empty($modSettings['enableErrorLogging'])), 'moderate_sub' => array('title' => $txt['moderate'], 'counter' => 'grand_total', 'href' => $scripturl . '?action=moderate', 'show' => $context['allow_moderation_center'], 'sub_buttons' => array('reports' => array('title' => $txt['mc_reported_posts'], 'counter' => 'reports', 'href' => $scripturl . '?action=moderate;area=reports', 'show' => !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1'), 'modlog' => array('title' => $txt['modlog_view'], 'href' => $scripturl . '?action=moderate;area=modlog', 'show' => !empty($modSettings['modlog_enabled']) && !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1'), 'attachments' => array('title' => $txt['mc_unapproved_attachments'], 'counter' => 'attachments', 'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments', 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'poststopics' => array('title' => $txt['mc_unapproved_poststopics'], 'counter' => 'postmod', 'href' => $scripturl . '?action=moderate;area=postmod;sa=posts', 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'postbyemail' => array('title' => $txt['mc_emailerror'], 'counter' => 'emailmod', 'href' => $scripturl . '?action=admin;area=maillist;sa=emaillist', 'show' => !empty($modSettings['maillist_enabled']) && allowedTo('approve_emails')))))); } else { $buttons['admin'] = array('title' => $txt['moderate'], 'counter' => 'grand_total', 'href' => $scripturl . '?action=moderate', 'data-icon' => '', 'show' => $context['allow_moderation_center'], 'sub_buttons' => array('reports' => array('title' => $txt['mc_reported_posts'], 'counter' => 'reports', 'href' => $scripturl . '?action=moderate;area=reports', 'show' => !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1'), 'modlog' => array('title' => $txt['modlog_view'], 'href' => $scripturl . '?action=moderate;area=modlog', 'show' => !empty($modSettings['modlog_enabled']) && !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1'), 'attachments' => array('title' => $txt['mc_unapproved_attachments'], 'counter' => 'attachments', 'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments', 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'poststopics' => array('title' => $txt['mc_unapproved_poststopics'], 'counter' => 'postmod', 'href' => $scripturl . '?action=moderate;area=postmod;sa=posts', 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'postbyemail' => array('title' => $txt['mc_emailerror'], 'counter' => 'emailmod', 'href' => $scripturl . '?action=admin;area=maillist;sa=emaillist', 'show' => !empty($modSettings['maillist_enabled']) && allowedTo('approve_emails')))); } $buttons += array('profile' => array('title' => (!empty($user_info['avatar']['href']) ? '<img class="avatar" src="' . $user_info['avatar']['href'] . '" alt="" /> ' : '') . (!empty($modSettings['displayMemberNames']) ? $user_info['name'] : $txt['account_short']), 'href' => $scripturl . '?action=profile', 'data-icon' => '', 'show' => $context['allow_edit_profile'], 'sub_buttons' => array('account' => array('title' => $txt['account'], 'href' => $scripturl . '?action=profile;area=account', 'show' => allowedTo(array('profile_identity_any', 'profile_identity_own', 'manage_membergroups'))), 'forumprofile' => array('title' => $txt['forumprofile'], 'href' => $scripturl . '?action=profile;area=forumprofile', 'show' => allowedTo(array('profile_extra_any', 'profile_extra_own'))), 'theme' => array('title' => $txt['theme'], 'href' => $scripturl . '?action=profile;area=theme', 'show' => allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_extra_any'))), 'logout' => array('title' => $txt['logout'], 'href' => $scripturl . '?action=logout', 'show' => !$user_info['is_guest']))), 'pm' => array('title' => $txt['pm_short'], 'counter' => 'unread_messages', 'href' => $scripturl . '?action=pm', 'data-icon' => '', 'show' => $context['allow_pm'], 'sub_buttons' => array('pm_read' => array('title' => $txt['pm_menu_read'], 'href' => $scripturl . '?action=pm', 'show' => allowedTo('pm_read')), 'pm_send' => array('title' => $txt['pm_menu_send'], 'href' => $scripturl . '?action=pm;sa=send', 'show' => allowedTo('pm_send')))), 'mentions' => array('title' => $txt['mention'], 'counter' => 'mentions', 'href' => $scripturl . '?action=mentions', 'data-icon' => '', 'show' => !$user_info['is_guest'] && !empty($modSettings['mentions_enabled'])), 'unread' => array('title' => $txt['view_unread_category'], 'href' => $scripturl . '?action=unread', 'data-icon' => '', 'show' => !$user_info['is_guest']), 'unreadreplies' => array('title' => $txt['view_replies_category'], 'href' => $scripturl . '?action=unreadreplies', 'data-icon' => '', 'show' => !$user_info['is_guest']), 'login' => array('title' => $txt['login'], 'href' => $scripturl . '?action=login', 'data-icon' => '', 'show' => $user_info['is_guest']), 'register' => array('title' => $txt['register'], 'href' => $scripturl . '?action=register', 'data-icon' => '', 'show' => $user_info['is_guest'] && $context['can_register']), 'contact' => array('title' => $txt['contact'], 'href' => $scripturl . '?action=contact', 'data-icon' => '', 'show' => $user_info['is_guest'] && !empty($modSettings['enable_contactform']) && $modSettings['enable_contactform'] == 'menu')); // Allow editing menu buttons easily. call_integration_hook('integrate_menu_buttons', array(&$buttons, &$menu_count)); // Now we put the buttons in the context so the theme can use them. $menu_buttons = array(); foreach ($buttons as $act => $button) { if (!empty($button['show'])) { $button['active_button'] = false; // This button needs some action. if (isset($button['action_hook'])) { $needs_action_hook = true; } if (isset($button['counter']) && !empty($menu_count[$button['counter']])) { $button['alttitle'] = $button['title'] . ' [' . $menu_count[$button['counter']] . ']'; if (!empty($settings['menu_numeric_notice'][0])) { $button['title'] .= sprintf($settings['menu_numeric_notice'][0], $menu_count[$button['counter']]); $button['indicator'] = true; } } // Go through the sub buttons if there are any. if (isset($button['sub_buttons'])) { foreach ($button['sub_buttons'] as $key => $subbutton) { if (empty($subbutton['show'])) { unset($button['sub_buttons'][$key]); } elseif (isset($subbutton['counter']) && !empty($menu_count[$subbutton['counter']])) { $button['sub_buttons'][$key]['alttitle'] = $subbutton['title'] . ' [' . $menu_count[$subbutton['counter']] . ']'; if (!empty($settings['menu_numeric_notice'][1])) { $button['sub_buttons'][$key]['title'] .= sprintf($settings['menu_numeric_notice'][1], $menu_count[$subbutton['counter']]); } // 2nd level sub buttons next... if (isset($subbutton['sub_buttons'])) { foreach ($subbutton['sub_buttons'] as $key2 => $subbutton2) { $button['sub_buttons'][$key]['sub_buttons'][$key2] = $subbutton2; if (empty($subbutton2['show'])) { unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); } elseif (isset($subbutton2['counter']) && !empty($menu_count[$subbutton2['counter']])) { $button['sub_buttons'][$key]['sub_buttons'][$key2]['alttitle'] = $subbutton2['title'] . ' [' . $menu_count[$subbutton2['counter']] . ']'; if (!empty($settings['menu_numeric_notice'][2])) { $button['sub_buttons'][$key]['sub_buttons'][$key2]['title'] .= sprintf($settings['menu_numeric_notice'][2], $menu_count[$subbutton2['counter']]); } unset($menu_count[$subbutton2['counter']]); } } } } } } $menu_buttons[$act] = $button; } } if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); } } if (!empty($menu_buttons['profile']['sub_buttons']['logout'])) { $menu_buttons['profile']['sub_buttons']['logout']['href'] .= ';' . $context['session_var'] . '=' . $context['session_id']; } $context['menu_buttons'] = $menu_buttons; // Figure out which action we are doing so we can set the active tab. // Default to home. $current_action = 'home'; if (isset($context['menu_buttons'][$context['current_action']])) { $current_action = $context['current_action']; } elseif ($context['current_action'] == 'profile') { $current_action = 'pm'; } elseif ($context['current_action'] == 'theme') { $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; } elseif ($context['current_action'] == 'register2') { $current_action = 'register'; } elseif ($context['current_action'] == 'login2' || $user_info['is_guest'] && $context['current_action'] == 'reminder') { $current_action = 'login'; } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { $current_action = 'moderate'; } elseif ($context['current_action'] == 'moderate' && $context['allow_admin']) { $current_action = 'admin'; } // Not all actions are simple. if (!empty($needs_action_hook)) { call_integration_hook('integrate_current_action', array(&$current_action)); } if (isset($context['menu_buttons'][$current_action])) { $context['menu_buttons'][$current_action]['active_button'] = true; } }