Exemplo n.º 1
0
 function groupRequests(&$schedule, $requests)
 {
     /** @var \frontend\models\vks\Request[] $requests */
     foreach ($requests as $key => $request) {
         $currentGroup = end($schedule);
         if (end($currentGroup)->endTime <= $request->beginTime) {
             $schedule[count($schedule) - 1][] = $request;
             unset($requests[$key]);
         }
     }
     if (count($requests)) {
         $schedule[][] = array_shift($requests);
         groupRequests($schedule, $requests);
     }
 }
 /**
  * Show a list of all the group requests they can see.
  * Checks permissions for group moderation.
  */
 public function block_groupRequests()
 {
     global $context, $user_info;
     // Make sure they can even moderate someone!
     if ($user_info['mod_cache']['gq'] == '0=1') {
         return 'group_requests_block';
     }
     $context['group_requests'] = groupRequests();
     return 'group_requests_block';
 }
Exemplo n.º 3
0
/**
 * Loads the number of items awaiting moderation attention
 *  - Only loads the value a given permission level can see
 *  - If supplied a board number will load the values only for that board
 *  - Unapproved posts
 *  - Unapproved topics
 *  - Unapproved attachments
 *  - Failed emails
 *  - Reported posts
 *  - Members awaiting approval (activation, deletion, group requests)
 *
 * @param int|null $brd
 */
function loadModeratorMenuCounts($brd = null)
{
    global $modSettings, $user_info;
    static $menu_errors = array();
    // Work out what boards they can work in!
    $approve_boards = !empty($user_info['mod_cache']['ap']) ? $user_info['mod_cache']['ap'] : boardsAllowedTo('approve_posts');
    // Supplied a specific board to check?
    if (!empty($brd)) {
        $filter_board = array((int) $brd);
        $approve_boards = $approve_boards == array(0) ? $filter_board : array_intersect($approve_boards, $filter_board);
    }
    // Work out the query
    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';
    }
    // Set up the cache key for this permissions level
    $cache_key = md5($user_info['query_see_board'] . $approve_query . $user_info['mod_cache']['bq'] . $user_info['mod_cache']['gq'] . $user_info['mod_cache']['mq'] . (int) allowedTo('approve_emails') . '_' . (int) allowedTo('moderate_forum'));
    if (isset($menu_errors[$cache_key])) {
        return $menu_errors[$cache_key];
    }
    // If its been cached, guess what, thats right use it!
    $temp = cache_get_data('num_menu_errors', 900);
    if ($temp === null || !isset($temp[$cache_key])) {
        // Starting out with nothing is a good start
        $menu_errors[$cache_key] = array('memberreq' => 0, 'groupreq' => 0, 'attachments' => 0, 'reports' => 0, 'emailmod' => 0, 'postmod' => 0, 'topics' => 0, 'posts' => 0);
        if ($modSettings['postmod_active'] && !empty($approve_boards)) {
            $totals = recountUnapprovedPosts($approve_query);
            $menu_errors[$cache_key]['posts'] = $totals['posts'];
            $menu_errors[$cache_key]['topics'] = $totals['topics'];
            // Totals for the menu item unapproved posts and topics
            $menu_errors[$cache_key]['postmod'] = $menu_errors[$cache_key]['topics'] + $menu_errors[$cache_key]['posts'];
        }
        // Attachments
        if ($modSettings['postmod_active'] && !empty($approve_boards)) {
            require_once SUBSDIR . '/ManageAttachments.subs.php';
            $menu_errors[$cache_key]['attachments'] = list_getNumUnapprovedAttachments($approve_query);
        }
        // Reported posts
        if (!empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1') {
            $menu_errors[$cache_key]['reports'] = recountOpenReports(false);
        }
        // Email failures that require attention
        if (!empty($modSettings['maillist_enabled']) && allowedTo('approve_emails')) {
            $menu_errors[$cache_key]['emailmod'] = recountFailedEmails($approve_query);
        }
        // Group requests
        if (!empty($user_info['mod_cache']) && $user_info['mod_cache']['gq'] != '0=1') {
            $menu_errors[$cache_key]['groupreq'] = count(groupRequests());
        }
        // Member requests
        if (allowedTo('moderate_forum') && (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2 || !empty($modSettings['approveAccountDeletion']))) {
            require_once SUBSDIR . '/Members.subs.php';
            $awaiting_activation = 0;
            $activation_numbers = countInactiveMembers();
            // 5 = COPPA, 4 = Awaiting Deletion, 3 = Awaiting Approval
            foreach ($activation_numbers as $activation_type => $total_members) {
                if (in_array($activation_type, array(3, 4, 5))) {
                    $awaiting_activation += $total_members;
                }
            }
            $menu_errors[$cache_key]['memberreq'] = $awaiting_activation;
        }
        // Grand Totals for the top most menus
        $menu_errors[$cache_key]['pt_total'] = $menu_errors[$cache_key]['emailmod'] + $menu_errors[$cache_key]['postmod'] + $menu_errors[$cache_key]['reports'] + $menu_errors[$cache_key]['attachments'];
        $menu_errors[$cache_key]['mg_total'] = $menu_errors[$cache_key]['memberreq'] + $menu_errors[$cache_key]['groupreq'];
        $menu_errors[$cache_key]['grand_total'] = $menu_errors[$cache_key]['pt_total'] + $menu_errors[$cache_key]['mg_total'];
        // Add this key in to the array, technically this resets the cache time for all keys
        // done this way as the entire thing needs to go null once *any* moderation action is taken
        $menu_errors = is_array($temp) ? array_merge($temp, $menu_errors) : $menu_errors;
        // Store it away for a while, not like this should change that often
        cache_put_data('num_menu_errors', $menu_errors, 900);
    } else {
        $menu_errors = $temp === null ? array() : $temp;
    }
    return $menu_errors[$cache_key];
}