Beispiel #1
0
/**
 * This helps organize things...
 * @todo this should be a simple dispatcher....
 */
function MessageMain()
{
    global $txt, $scripturl, $sourcedir, $context, $user_info, $user_settings, $smcFunc, $modSettings;
    // No guests!
    is_not_guest();
    // You're not supposed to be here at all, if you can't even read PMs.
    isAllowedTo('pm_read');
    // This file contains the basic functions for sending a PM.
    require_once $sourcedir . '/Subs-Post.php';
    loadLanguage('PersonalMessage+Drafts');
    if (WIRELESS && WIRELESS_PROTOCOL == 'wap') {
        fatal_lang_error('wireless_error_notyet', false);
    } elseif (WIRELESS) {
        $context['sub_template'] = WIRELESS_PROTOCOL . '_pm';
    } elseif (!isset($_REQUEST['xml'])) {
        loadTemplate('PersonalMessage');
    }
    // Load up the members maximum message capacity.
    if ($user_info['is_admin']) {
        $context['message_limit'] = 0;
    } elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) {
        // @todo Why do we do this?  It seems like if they have any limit we should use it.
        $request = $smcFunc['db_query']('', '
			SELECT MAX(max_messages) AS top_limit, MIN(max_messages) AS bottom_limit
			FROM {db_prefix}membergroups
			WHERE id_group IN ({array_int:users_groups})', array('users_groups' => $user_info['groups']));
        list($maxMessage, $minMessage) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        $context['message_limit'] = $minMessage == 0 ? 0 : $maxMessage;
        // Save us doing it again!
        cache_put_data('msgLimit:' . $user_info['id'], $context['message_limit'], 360);
    }
    // Prepare the context for the capacity bar.
    if (!empty($context['message_limit'])) {
        $bar = $user_info['messages'] * 100 / $context['message_limit'];
        $context['limit_bar'] = array('messages' => $user_info['messages'], 'allowed' => $context['message_limit'], 'percent' => $bar, 'bar' => min(100, (int) $bar), 'text' => sprintf($txt['pm_currently_using'], $user_info['messages'], round($bar, 1)));
    }
    // a previous message was sent successfully? show a small indication.
    if (isset($_GET['done']) && $_GET['done'] == 'sent') {
        $context['pm_sent'] = true;
    }
    // Now we have the labels, and assuming we have unsorted mail, apply our rules!
    if ($user_settings['new_pm']) {
        $context['labels'] = $user_settings['message_labels'] == '' ? array() : explode(',', $user_settings['message_labels']);
        foreach ($context['labels'] as $id_label => $label_name) {
            $context['labels'][(int) $id_label] = array('id' => $id_label, 'name' => trim($label_name), 'messages' => 0, 'unread_messages' => 0);
        }
        $context['labels'][-1] = array('id' => -1, 'name' => $txt['pm_msg_label_inbox'], 'messages' => 0, 'unread_messages' => 0);
        ApplyRules();
        updateMemberData($user_info['id'], array('new_pm' => 0));
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}pm_recipients
			SET is_new = {int:not_new}
			WHERE id_member = {int:current_member}', array('current_member' => $user_info['id'], 'not_new' => 0));
    }
    // Load the label data.
    if ($user_settings['new_pm'] || ($context['labels'] = cache_get_data('labelCounts:' . $user_info['id'], 720)) === null) {
        $context['labels'] = $user_settings['message_labels'] == '' ? array() : explode(',', $user_settings['message_labels']);
        foreach ($context['labels'] as $id_label => $label_name) {
            $context['labels'][(int) $id_label] = array('id' => $id_label, 'name' => trim($label_name), 'messages' => 0, 'unread_messages' => 0);
        }
        $context['labels'][-1] = array('id' => -1, 'name' => $txt['pm_msg_label_inbox'], 'messages' => 0, 'unread_messages' => 0);
        // Looks like we need to reseek!
        $result = $smcFunc['db_query']('', '
			SELECT labels, is_read, COUNT(*) AS num
			FROM {db_prefix}pm_recipients
			WHERE id_member = {int:current_member}
				AND deleted = {int:not_deleted}
			GROUP BY labels, is_read', array('current_member' => $user_info['id'], 'not_deleted' => 0));
        while ($row = $smcFunc['db_fetch_assoc']($result)) {
            $this_labels = explode(',', $row['labels']);
            foreach ($this_labels as $this_label) {
                $context['labels'][(int) $this_label]['messages'] += $row['num'];
                if (!($row['is_read'] & 1)) {
                    $context['labels'][(int) $this_label]['unread_messages'] += $row['num'];
                }
            }
        }
        $smcFunc['db_free_result']($result);
        // Store it please!
        cache_put_data('labelCounts:' . $user_info['id'], $context['labels'], 720);
    }
    // This determines if we have more labels than just the standard inbox.
    $context['currently_using_labels'] = count($context['labels']) > 1 ? 1 : 0;
    // Some stuff for the labels...
    $context['current_label_id'] = isset($_REQUEST['l']) && isset($context['labels'][(int) $_REQUEST['l']]) ? (int) $_REQUEST['l'] : -1;
    $context['current_label'] =& $context['labels'][(int) $context['current_label_id']]['name'];
    $context['folder'] = !isset($_REQUEST['f']) || $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent';
    // This is convenient.  Do you know how annoying it is to do this every time?!
    $context['current_label_redirect'] = 'action=pm;f=' . $context['folder'] . (isset($_GET['start']) ? ';start=' . $_GET['start'] : '') . (isset($_REQUEST['l']) ? ';l=' . $_REQUEST['l'] : '');
    $context['can_issue_warning'] = in_array('w', $context['admin_features']) && allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1;
    // Build the linktree for all the actions...
    $context['linktree'][] = array('url' => $scripturl . '?action=pm', 'name' => $txt['personal_messages']);
    // Preferences...
    $context['display_mode'] = WIRELESS ? 0 : $user_settings['pm_prefs'] & 3;
    $subActions = array('addbuddy' => 'WirelessAddBuddy', 'manlabels' => 'ManageLabels', 'manrules' => 'ManageRules', 'pmactions' => 'MessageActionsApply', 'prune' => 'MessagePrune', 'removeall' => 'MessageKillAllQuery', 'removeall2' => 'MessageKillAll', 'report' => 'ReportMessage', 'search' => 'MessageSearch', 'search2' => 'MessageSearch2', 'send' => 'MessagePost', 'send2' => 'MessagePost2', 'settings' => 'MessageSettings', 'showpmdrafts' => 'MessageDrafts');
    if (!isset($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) {
        MessageFolder();
    } else {
        if (!isset($_REQUEST['xml'])) {
            messageIndexBar($_REQUEST['sa']);
        }
        $subActions[$_REQUEST['sa']]();
    }
}
Beispiel #2
0
function MessageMain()
{
    global $txt, $scripturl, $sourcedir, $context, $user_info, $user_settings, $db_prefix, $ID_MEMBER;
    // No guests!
    is_not_guest();
    // You're not supposed to be here at all, if you can't even read PMs.
    isAllowedTo('pm_read');
    // This file contains the basic functions for sending a PM.
    require_once $sourcedir . '/Subs-Post.php';
    if (loadLanguage('PersonalMessage', '', false) === false) {
        loadLanguage('InstantMessage');
    }
    if (WIRELESS) {
        $context['sub_template'] = WIRELESS_PROTOCOL . '_pm';
    } else {
        if (loadTemplate('PersonalMessage', false) === false) {
            loadTemplate('InstantMessage');
        }
    }
    // Load up the members maximum message capacity.
    if (!$user_info['is_admin']) {
        // !!! Why do we do this?  It seems like if they have any limit we should use it.
        $request = db_query("\n\t\t\tSELECT MAX(maxMessages) AS topLimit, MIN(maxMessages) AS bottomLimit\n\t\t\tFROM {$db_prefix}membergroups\n\t\t\tWHERE ID_GROUP IN (" . implode(', ', $user_info['groups']) . ')', __FILE__, __LINE__);
        list($maxMessage, $minMessage) = mysql_fetch_row($request);
        mysql_free_result($request);
        $context['message_limit'] = $minMessage == 0 ? 0 : $maxMessage;
    } else {
        $context['message_limit'] = 0;
    }
    // Prepare the context for the capacity bar.
    if (!empty($context['message_limit'])) {
        $bar = $user_info['messages'] * 100 / $context['message_limit'];
        $context['limit_bar'] = array('messages' => $user_info['messages'], 'allowed' => $context['message_limit'], 'percent' => $bar, 'bar' => min(100, (int) $bar), 'text' => sprintf($txt['pm_currently_using'], $user_info['messages'], round($bar, 1)));
    }
    // We should probably cache this information for speed.
    $context['labels'] = $user_settings['messageLabels'] == '' ? array() : explode(',', $user_settings['messageLabels']);
    foreach ($context['labels'] as $k => $v) {
        $context['labels'][(int) $k] = array('id' => $k, 'name' => trim($v), 'messages' => 0, 'unread_messages' => 0);
    }
    $context['labels'][-1] = array('id' => -1, 'name' => $txt['pm_msg_label_inbox'], 'messages' => 0, 'unread_messages' => 0);
    // !!! The idea would be to cache this information in the members table, and invlidate it when they are sent messages.
    $result = db_query("\n\t\tSELECT labels, is_read, COUNT(*) AS num\n\t\tFROM {$db_prefix}pm_recipients\n\t\tWHERE ID_MEMBER = {$ID_MEMBER}\n\t\tGROUP BY labels, is_read", __FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($result)) {
        $this_labels = explode(',', $row['labels']);
        foreach ($this_labels as $this_label) {
            $context['labels'][(int) $this_label]['messages'] += $row['num'];
            if (!($row['is_read'] & 1)) {
                $context['labels'][(int) $this_label]['unread_messages'] += $row['num'];
            }
        }
    }
    mysql_free_result($result);
    // This determines if we have more labels than just the standard inbox.
    $context['currently_using_labels'] = count($context['labels']) > 1 ? 1 : 0;
    // Some stuff for the labels...
    $context['current_label_id'] = isset($_REQUEST['l']) && isset($context['labels'][(int) $_REQUEST['l']]) ? (int) $_REQUEST['l'] : -1;
    $context['current_label'] =& $context['labels'][(int) $context['current_label_id']]['name'];
    $context['folder'] = !isset($_REQUEST['f']) || $_REQUEST['f'] != 'outbox' ? 'inbox' : 'outbox';
    // This is convenient.  Do you know how annoying it is to do this every time?!
    $context['current_label_redirect'] = 'action=pm;f=' . $context['folder'] . (isset($_GET['start']) ? ';start=' . $_GET['start'] : '') . (isset($_REQUEST['l']) ? ';l=' . $_REQUEST['l'] : '');
    // Build the linktree for all the actions...
    $context['linktree'][] = array('url' => $scripturl . '?action=pm', 'name' => $txt[144]);
    $subActions = array('addbuddy' => 'WirelessAddBuddy', 'manlabels' => 'ManageLabels', 'outbox' => 'MessageFolder', 'pmactions' => 'MessageActionsApply', 'prune' => 'MessagePrune', 'removeall' => 'MessageKillAllQuery', 'removeall2' => 'MessageKillAll', 'report' => 'ReportMessage', 'search' => 'MessageSearch', 'search2' => 'MessageSearch2', 'send' => 'MessagePost', 'send2' => 'MessagePost2');
    if (!isset($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) {
        MessageFolder();
    } else {
        messageIndexBar($_REQUEST['sa']);
        $subActions[$_REQUEST['sa']]();
    }
}