/sources/controllers/PersonalMessage.controller.php
PHP | 2770 lines | 2052 code | 346 blank | 372 comment | 492 complexity | 3a25487873b7ba521b145170ac6f87a0 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @name ElkArte Forum
- * @copyright ElkArte Forum contributors
- * @license BSD http://opensource.org/licenses/BSD-3-Clause
- *
- * This software is a derived product, based on:
- *
- * Simple Machines Forum (SMF)
- * copyright: 2011 Simple Machines (http://www.simplemachines.org)
- * license: BSD, See included LICENSE.TXT for terms and conditions.
- *
- * @version 1.0 Alpha
- *
- * This file is mainly meant for controlling the actions related to personal
- * messages. It allows viewing, sending, deleting, and marking personal
- * messages. For compatibility reasons, they are often called "instant messages".
- *
- */
- if (!defined('ELKARTE'))
- die('No access...');
- /**
- * This is the main function of personal messages, called before the action handler.
- * It should set the context, load templates and language file(s), as necessary
- * for the function that will be called.
- *
- * @todo this should be a (pre)dispatcher.
- */
- function action_pm()
- {
- global $txt, $scripturl, $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 our PM functions such as mark, send, delete
- require_once(SUBSDIR . '/PersonalMessage.subs.php');
- loadLanguage('PersonalMessage+Drafts');
- loadJavascriptFile(array('PersonalMessage.js', 'suggest.js'));
- if (!isset($_REQUEST['xml']))
- loadTemplate('PersonalMessage');
- // Load up the members maximum message capacity.
- loadMessageLimit();
- // 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,
- );
- loadPMLabels();
- }
- // 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;
- // Are PM drafts enabled?
- $context['drafts_pm_save'] = !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_pm_enabled']) && allowedTo('pm_draft');
- $context['drafts_autosave'] = !empty($context['drafts_pm_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('pm_autosave_draft');
- // Build the linktree for all the actions...
- $context['linktree'][] = array(
- 'url' => $scripturl . '?action=pm',
- 'name' => $txt['personal_messages']
- );
- // Preferences...
- $context['display_mode'] = $user_settings['pm_prefs'] & 3;
- // Finally all the things we know how to do
- $subActions = array(
- 'manlabels' => 'action_messagelabels',
- 'manrules' => 'action_messagerules',
- 'pmactions' => 'action_messageactions',
- 'prune' => 'action_messageprune',
- 'removeall' => 'action_removemessage',
- 'removeall2' => 'action_removemessage2',
- 'report' => 'action_reportmessage',
- 'search' => array('Search.controller.php','MessageSearch'),
- 'search2' => array('Search.controller.php','MessageSearch2'),
- 'send' => 'action_sendmessage',
- 'send2' => 'action_sendmessage2',
- 'settings' => 'action_messagesettings',
- 'showpmdrafts' => 'action_messagedrafts',
- );
- // Known action, go to it, otherwise the inbox for you
- if (!isset($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']]))
- action_messagefolder();
- else
- {
- if (!isset($_REQUEST['xml']))
- messageIndexBar($_REQUEST['sa']);
- // So it was set - let's go to that action.
- if (is_array($subActions[$_REQUEST['sa']]))
- {
- require_once(CONTROLLERDIR . '/' . $subActions[$_REQUEST['sa']][0]);
- $subActions[$_REQUEST['sa']][1]();
- }
- else
- $subActions[$_REQUEST['sa']]();
- }
- }
- /**
- * A menu to easily access different areas of the PM section
- *
- * @param string $area
- */
- function messageIndexBar($area)
- {
- global $txt, $context, $scripturl, $sc, $modSettings, $settings, $user_info, $options;
- $pm_areas = array(
- 'folders' => array(
- 'title' => $txt['pm_messages'],
- 'areas' => array(
- 'send' => array(
- 'label' => $txt['new_message'],
- 'custom_url' => $scripturl . '?action=pm;sa=send',
- 'permission' => allowedTo('pm_send'),
- ),
- 'inbox' => array(
- 'label' => $txt['inbox'],
- 'custom_url' => $scripturl . '?action=pm',
- ),
- 'sent' => array(
- 'label' => $txt['sent_items'],
- 'custom_url' => $scripturl . '?action=pm;f=sent',
- ),
- 'drafts' => array(
- 'label' => $txt['drafts_show'],
- 'custom_url' => $scripturl . '?action=pm;sa=showpmdrafts',
- 'permission' => allowedTo('pm_draft'),
- 'enabled' => !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_pm_enabled']),
- ),
- ),
- ),
- 'labels' => array(
- 'title' => $txt['pm_labels'],
- 'areas' => array(),
- ),
- 'actions' => array(
- 'title' => $txt['pm_actions'],
- 'areas' => array(
- 'search' => array(
- 'label' => $txt['pm_search_bar_title'],
- 'custom_url' => $scripturl . '?action=pm;sa=search',
- ),
- 'prune' => array(
- 'label' => $txt['pm_prune'],
- 'custom_url' => $scripturl . '?action=pm;sa=prune'
- ),
- ),
- ),
- 'pref' => array(
- 'title' => $txt['pm_preferences'],
- 'areas' => array(
- 'manlabels' => array(
- 'label' => $txt['pm_manage_labels'],
- 'custom_url' => $scripturl . '?action=pm;sa=manlabels',
- ),
- 'manrules' => array(
- 'label' => $txt['pm_manage_rules'],
- 'custom_url' => $scripturl . '?action=pm;sa=manrules',
- ),
- 'settings' => array(
- 'label' => $txt['pm_settings'],
- 'custom_url' => $scripturl . '?action=pm;sa=settings',
- ),
- ),
- ),
- );
- // Handle labels.
- if (empty($context['currently_using_labels']))
- unset($pm_areas['labels']);
- else
- {
- // Note we send labels by id as it will have less problems in the querystring.
- $unread_in_labels = 0;
- foreach ($context['labels'] as $label)
- {
- if ($label['id'] == -1)
- continue;
- // Count the amount of unread items in labels.
- $unread_in_labels += $label['unread_messages'];
- // Add the label to the menu.
- $pm_areas['labels']['areas']['label' . $label['id']] = array(
- 'label' => $label['name'] . (!empty($label['unread_messages']) ? ' (<strong>' . $label['unread_messages'] . '</strong>)' : ''),
- 'custom_url' => $scripturl . '?action=pm;l=' . $label['id'],
- 'unread_messages' => $label['unread_messages'],
- 'messages' => $label['messages'],
- );
- }
- if (!empty($unread_in_labels))
- $pm_areas['labels']['title'] .= ' (' . $unread_in_labels . ')';
- }
- $pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];
- $pm_areas['folders']['areas']['inbox']['messages'] = &$context['labels'][-1]['messages'];
- // If we have unread messages, make note of the number in the menus
- if (!empty($context['labels'][-1]['unread_messages']))
- {
- $pm_areas['folders']['areas']['inbox']['label'] .= ' (<strong>' . $context['labels'][-1]['unread_messages'] . '</strong>)';
- $pm_areas['folders']['title'] .= ' (' . $context['labels'][-1]['unread_messages'] . ')';
- }
- // Do we have a limit on the amount of messages we can keep?
- if (!empty($context['message_limit']))
- {
- $bar = round(($user_info['messages'] * 100) / $context['message_limit'], 1);
- $context['limit_bar'] = array(
- 'messages' => $user_info['messages'],
- 'allowed' => $context['message_limit'],
- 'percent' => $bar,
- 'bar' => $bar > 100 ? 100 : (int) $bar,
- 'text' => sprintf($txt['pm_currently_using'], $user_info['messages'], $bar)
- );
- }
- require_once(SUBSDIR . '/Menu.subs.php');
- // What page is this, again?
- $current_page = $scripturl . '?action=pm' . (!empty($_REQUEST['sa']) ? ';sa=' . $_REQUEST['sa'] : '') . (!empty($context['folder']) ? ';f=' . $context['folder'] : '') . (!empty($context['current_label_id']) ? ';l=' . $context['current_label_id'] : '');
- // Set a few options for the menu.
- $menuOptions = array(
- 'current_area' => $area,
- 'disable_url_session_check' => true,
- );
- // Actually create the menu!
- $pm_include_data = createMenu($pm_areas, $menuOptions);
- unset($pm_areas);
- // No menu means no access.
- if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
- fatal_lang_error('no_access', false);
- // Make a note of the Unique ID for this menu.
- $context['pm_menu_id'] = $context['max_menu_id'];
- $context['pm_menu_name'] = 'menu_data_' . $context['pm_menu_id'];
- // Set the selected item.
- $current_area = $pm_include_data['current_area'];
- $context['menu_item_selected'] = $current_area;
- // Set the template for this area and add the profile layer.
- if (!isset($_REQUEST['xml']))
- $context['template_layers'][] = 'pm';
- }
- /**
- * A folder, ie. inbox/sent etc.
- */
- function action_messagefolder()
- {
- global $txt, $scripturl, $modSettings, $context, $subjects_request;
- global $messages_request, $user_info, $recipients, $options, $smcFunc, $memberContext, $user_settings;
- // Changing view?
- if (isset($_GET['view']))
- {
- $context['display_mode'] = $context['display_mode'] > 1 ? 0 : $context['display_mode'] + 1;
- updateMemberData($user_info['id'], array('pm_prefs' => ($user_settings['pm_prefs'] & 252) | $context['display_mode']));
- }
- // Make sure the starting location is valid.
- $start = '';
- if (isset($_GET['start']) && $_GET['start'] != 'new')
- $start = (int) $_GET['start'];
- elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
- $start = 0;
- else
- $start = 'new';
- // Set up some basic theme stuff.
- $context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
- $context['get_pmessage'] = 'prepareMessageContext';
- $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
- $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
- $labelQuery = $context['folder'] != 'sent' ? '
- AND FIND_IN_SET(' . $context['current_label_id'] . ', pmr.labels) != 0' : '';
- // Set the index bar correct!
- messageIndexBar($context['current_label_id'] == -1 ? $context['folder'] : 'label' . $context['current_label_id']);
- // They didn't pick a sort, use the forum default.
- if (!isset($_GET['sort']))
- {
- $sort_by = 'date';
- $descending = !empty($options['view_newest_pm_first']);
- }
- // Otherwise use the defaults: ascending, by date.
- else
- {
- $sort_by = $_GET['sort'];
- $descending = isset($_GET['desc']);
- }
- // Set our sort by query
- switch ($sort_by)
- {
- case 'date':
- $sort_by_query = 'pm.id_pm';
- case 'name':
- $sort_by_query = 'IFNULL(mem.real_name, \'\')';
- case 'subject':
- $sort_by_query = 'pm.subject';
- default:
- $sort_by_query = 'pm.id_pm';
- }
- // Set the text to resemble the current folder.
- $pmbox = $context['folder'] != 'sent' ? $txt['inbox'] : $txt['sent_items'];
- $txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
- // Now, build the link tree!
- if ($context['current_label_id'] == -1)
- $context['linktree'][] = array(
- 'url' => $scripturl . '?action=pm;f=' . $context['folder'],
- 'name' => $pmbox
- );
- // Build it further for a label.
- if ($context['current_label_id'] != -1)
- $context['linktree'][] = array(
- 'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
- 'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
- );
- // Figure out how many messages there are.
- $max_messages = getPMCount(false, null, $labelQuery);
- // Only show the button if there are messages to delete.
- $context['show_delete'] = $max_messages > 0;
- // Start on the last page.
- if (!is_numeric($start) || $start >= $max_messages)
- $start = ($max_messages - 1) - (($max_messages - 1) % $modSettings['defaultMaxMessages']);
- elseif ($start < 0)
- $start = 0;
- // ... but wait - what if we want to start from a specific message?
- if (isset($_GET['pmid']))
- {
- $pmID = (int) $_GET['pmid'];
- // Make sure you have access to this PM.
- if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
- fatal_lang_error('no_access', false);
- $context['current_pm'] = $pmID;
- // With only one page of PM's we're gonna want page 1.
- if ($max_messages <= $modSettings['defaultMaxMessages'])
- $start = 0;
- // If we pass kstart we assume we're in the right place.
- elseif (!isset($_GET['kstart']))
- {
- $start = getPMCount($descending, $pmID, $labelQuery);
- // To stop the page index's being abnormal, start the page on the page the message would normally be located on...
- $start = $modSettings['defaultMaxMessages'] * (int) ($start / $modSettings['defaultMaxMessages']);
- }
- }
- // Sanitize and validate pmsg variable if set.
- if (isset($_GET['pmsg']))
- {
- $pmsg = (int) $_GET['pmsg'];
- if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
- fatal_lang_error('no_access', false);
- }
- // Determine the navigation context (especially useful for the wireless template).
- $context['links'] = array(
- 'first' => $start >= $modSettings['defaultMaxMessages'] ? $scripturl . '?action=pm;start=0' : '',
- 'prev' => $start >= $modSettings['defaultMaxMessages'] ? $scripturl . '?action=pm;start=' . ($start - $modSettings['defaultMaxMessages']) : '',
- 'next' => $start + $modSettings['defaultMaxMessages'] < $max_messages ? $scripturl . '?action=pm;start=' . ($start + $modSettings['defaultMaxMessages']) : '',
- 'last' => $start + $modSettings['defaultMaxMessages'] < $max_messages ? $scripturl . '?action=pm;start=' . (floor(($max_messages - 1) / $modSettings['defaultMaxMessages']) * $modSettings['defaultMaxMessages']) : '',
- 'up' => $scripturl,
- );
- $context['page_info'] = array(
- 'current_page' => $start / $modSettings['defaultMaxMessages'] + 1,
- 'num_pages' => floor(($max_messages - 1) / $modSettings['defaultMaxMessages']) + 1
- );
- // First work out what messages we need to see - if grouped is a little trickier...
- if ($context['display_mode'] == 2)
- {
- // On a non-default sort due to PostgreSQL we have to do a harder sort.
- if ($smcFunc['db_title'] == 'PostgreSQL' && $sort_by_query != 'pm.id_pm')
- {
- $sub_request = $smcFunc['db_query']('', '
- SELECT MAX({raw:sort}) AS sort_param, pm.id_pm_head
- FROM {db_prefix}personal_messages AS pm' . ($context['folder'] == 'sent' ? ($sort_by == 'name' ? '
- LEFT JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm)' : '') : '
- INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
- AND pmr.id_member = {int:current_member}
- AND pmr.deleted = {int:not_deleted}
- ' . $labelQuery . ')') . ($sort_by == 'name' ? ( '
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:id_member})') : '') . '
- WHERE ' . ($context['folder'] == 'sent' ? 'pm.id_member_from = {int:current_member}
- AND pm.deleted_by_sender = {int:not_deleted}' : '1=1') . (empty($pmsg) ? '' : '
- AND pm.id_pm = {int:id_pm}') . '
- GROUP BY pm.id_pm_head
- ORDER BY sort_param' . ($descending ? ' DESC' : ' ASC') . (empty($pmsg) ? '
- LIMIT ' . $start . ', ' . $modSettings['defaultMaxMessages'] : ''),
- array(
- 'current_member' => $user_info['id'],
- 'not_deleted' => 0,
- 'id_member' => $context['folder'] == 'sent' ? 'pmr.id_member' : 'pm.id_member_from',
- 'id_pm' => isset($pmsg) ? $pmsg : '0',
- 'sort' => $sort_by_query,
- )
- );
- $sub_pms = array();
- while ($row = $smcFunc['db_fetch_assoc']($sub_request))
- $sub_pms[$row['id_pm_head']] = $row['sort_param'];
- $smcFunc['db_free_result']($sub_request);
- $request = $smcFunc['db_query']('', '
- SELECT pm.id_pm AS id_pm, pm.id_pm_head
- FROM {db_prefix}personal_messages AS pm' . ($context['folder'] == 'sent' ? ($sort_by == 'name' ? '
- LEFT JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm)' : '') : '
- INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
- AND pmr.id_member = {int:current_member}
- AND pmr.deleted = {int:not_deleted}
- ' . $labelQuery . ')') . ($sort_by == 'name' ? ( '
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:id_member})') : '') . '
- WHERE ' . (empty($sub_pms) ? '0=1' : 'pm.id_pm IN ({array_int:pm_list})') . '
- ORDER BY ' . ($sort_by_query == 'pm.id_pm' && $context['folder'] != 'sent' ? 'id_pm' : '{raw:sort}') . ($descending ? ' DESC' : ' ASC') . (empty($pmsg) ? '
- LIMIT ' . $start . ', ' . $modSettings['defaultMaxMessages'] : ''),
- array(
- 'current_member' => $user_info['id'],
- 'pm_list' => array_keys($sub_pms),
- 'not_deleted' => 0,
- 'sort' => $sort_by_query,
- 'id_member' => $context['folder'] == 'sent' ? 'pmr.id_member' : 'pm.id_member_from',
- )
- );
- }
- else
- {
- $request = $smcFunc['db_query']('pm_conversation_list', '
- SELECT MAX(pm.id_pm) AS id_pm, pm.id_pm_head
- FROM {db_prefix}personal_messages AS pm' . ($context['folder'] == 'sent' ? ($sort_by == 'name' ? '
- LEFT JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm)' : '') : '
- INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
- AND pmr.id_member = {int:current_member}
- AND pmr.deleted = {int:deleted_by}
- ' . $labelQuery . ')') . ($sort_by == 'name' ? ( '
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:pm_member})') : '') . '
- WHERE ' . ($context['folder'] == 'sent' ? 'pm.id_member_from = {int:current_member}
- AND pm.deleted_by_sender = {int:deleted_by}' : '1=1') . (empty($pmsg) ? '' : '
- AND pm.id_pm = {int:pmsg}') . '
- GROUP BY pm.id_pm_head
- ORDER BY ' . ($sort_by_query == 'pm.id_pm' && $context['folder'] != 'sent' ? 'id_pm' : '{raw:sort}') . ($descending ? ' DESC' : ' ASC') . (isset($pmsg) ? '
- LIMIT ' . $start . ', ' . $modSettings['defaultMaxMessages'] : ''),
- array(
- 'current_member' => $user_info['id'],
- 'deleted_by' => 0,
- 'sort' => $sort_by_query,
- 'pm_member' => $context['folder'] == 'sent' ? 'pmr.id_member' : 'pm.id_member_from',
- 'pmsg' => isset($pmsg) ? (int) $pmsg : 0,
- )
- );
- }
- }
- // This is kinda simple!
- else
- {
- // @todo SLOW This query uses a filesort. (inbox only.)
- $request = $smcFunc['db_query']('', '
- SELECT pm.id_pm, pm.id_pm_head, pm.id_member_from
- FROM {db_prefix}personal_messages AS pm' . ($context['folder'] == 'sent' ? '' . ($sort_by == 'name' ? '
- LEFT JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm)' : '') : '
- INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
- AND pmr.id_member = {int:current_member}
- AND pmr.deleted = {int:is_deleted}
- ' . $labelQuery . ')') . ($sort_by == 'name' ? ( '
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:pm_member})') : '') . '
- WHERE ' . ($context['folder'] == 'sent' ? 'pm.id_member_from = {raw:current_member}
- AND pm.deleted_by_sender = {int:is_deleted}' : '1=1') . (empty($pmsg) ? '' : '
- AND pm.id_pm = {int:pmsg}') . '
- ORDER BY ' . ($sort_by_query == 'pm.id_pm' && $context['folder'] != 'sent' ? 'pmr.id_pm' : '{raw:sort}') . ($descending ? ' DESC' : ' ASC') . (isset($pmsg) ? '
- LIMIT ' . $start . ', ' . $modSettings['defaultMaxMessages'] : ''),
- array(
- 'current_member' => $user_info['id'],
- 'is_deleted' => 0,
- 'sort' => $sort_by_query,
- 'pm_member' => $context['folder'] == 'sent' ? 'pmr.id_member' : 'pm.id_member_from',
- 'pmsg' => isset($pmsg) ? (int) $pmsg : 0,
- )
- );
- }
- // Load the id_pms and initialize recipients.
- $pms = array();
- $lastData = array();
- $posters = $context['folder'] == 'sent' ? array($user_info['id']) : array();
- $recipients = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if (!isset($recipients[$row['id_pm']]))
- {
- if (isset($row['id_member_from']))
- $posters[$row['id_pm']] = $row['id_member_from'];
- $pms[$row['id_pm']] = $row['id_pm'];
- $recipients[$row['id_pm']] = array(
- 'to' => array(),
- 'bcc' => array()
- );
- }
- // Keep track of the last message so we know what the head is without another query!
- if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
- $lastData = array(
- 'id' => $row['id_pm'],
- 'head' => $row['id_pm_head'],
- );
- }
- $smcFunc['db_free_result']($request);
- // Make sure that we have been given a correct head pm id!
- if ($context['display_mode'] === 2 && !empty($pmID) && $pmID != $lastData['id'])
- fatal_lang_error('no_access', false);
- if (!empty($pms))
- {
- // Select the correct current message.
- if (empty($pmID))
- $context['current_pm'] = $lastData['id'];
- // This is a list of the pm's that are used for "full" display.
- if ($context['display_mode'] == 0)
- $display_pms = $pms;
- else
- $display_pms = array($context['current_pm']);
- // At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
- if ($context['display_mode'] == 2)
- {
- $request = $smcFunc['db_query']('', '
- SELECT pm.id_pm, pm.id_member_from, pm.deleted_by_sender, pmr.id_member, pmr.deleted
- FROM {db_prefix}personal_messages AS pm
- INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm)
- WHERE pm.id_pm_head = {int:id_pm_head}
- AND ((pm.id_member_from = {int:current_member} AND pm.deleted_by_sender = {int:not_deleted})
- OR (pmr.id_member = {int:current_member} AND pmr.deleted = {int:not_deleted}))
- ORDER BY pm.id_pm',
- array(
- 'current_member' => $user_info['id'],
- 'id_pm_head' => $lastData['head'],
- 'not_deleted' => 0,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- // This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
- if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
- continue;
- elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
- continue;
- if (!isset($recipients[$row['id_pm']]))
- $recipients[$row['id_pm']] = array(
- 'to' => array(),
- 'bcc' => array()
- );
- $display_pms[] = $row['id_pm'];
- $posters[$row['id_pm']] = $row['id_member_from'];
- }
- $smcFunc['db_free_result']($request);
- }
- // This is pretty much EVERY pm!
- $all_pms = array_merge($pms, $display_pms);
- $all_pms = array_unique($all_pms);
- // Get recipients (don't include bcc-recipients for your inbox, you're not supposed to know :P).
- $request = $smcFunc['db_query']('', '
- SELECT pmr.id_pm, mem_to.id_member AS id_member_to, mem_to.real_name AS to_name, pmr.bcc, pmr.labels, pmr.is_read
- FROM {db_prefix}pm_recipients AS pmr
- LEFT JOIN {db_prefix}members AS mem_to ON (mem_to.id_member = pmr.id_member)
- WHERE pmr.id_pm IN ({array_int:pm_list})',
- array(
- 'pm_list' => $all_pms,
- )
- );
- $context['message_labels'] = array();
- $context['message_replied'] = array();
- $context['message_unread'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if ($context['folder'] == 'sent' || empty($row['bcc']))
- $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
- if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
- {
- $context['message_replied'][$row['id_pm']] = $row['is_read'] & 2;
- $context['message_unread'][$row['id_pm']] = $row['is_read'] == 0;
- $row['labels'] = $row['labels'] == '' ? array() : explode(',', $row['labels']);
- foreach ($row['labels'] as $v)
- {
- if (isset($context['labels'][(int) $v]))
- $context['message_labels'][$row['id_pm']][(int) $v] = array('id' => $v, 'name' => $context['labels'][(int) $v]['name']);
- }
- }
- }
- $smcFunc['db_free_result']($request);
- // Make sure we don't load unnecessary data.
- if ($context['display_mode'] == 1)
- {
- foreach ($posters as $k => $v)
- if (!in_array($k, $display_pms))
- unset($posters[$k]);
- }
- // Load any users....
- $posters = array_unique($posters);
- if (!empty($posters))
- loadMemberData($posters);
- // If we're on grouped/restricted view get a restricted list of messages.
- if ($context['display_mode'] != 0)
- {
- // Get the order right.
- $orderBy = array();
- foreach (array_reverse($pms) as $pm)
- $orderBy[] = 'pm.id_pm = ' . $pm;
- // Seperate query for these bits!
- $subjects_request = $smcFunc['db_query']('', '
- SELECT pm.id_pm, pm.subject, pm.id_member_from, pm.msgtime, IFNULL(mem.real_name, pm.from_name) AS from_name,
- IFNULL(mem.id_member, 0) AS not_guest
- FROM {db_prefix}personal_messages AS pm
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = pm.id_member_from)
- WHERE pm.id_pm IN ({array_int:pm_list})
- ORDER BY ' . implode(', ', $orderBy) . '
- LIMIT ' . count($pms),
- array(
- 'pm_list' => $pms,
- )
- );
- }
- // Execute the query!
- $messages_request = $smcFunc['db_query']('', '
- SELECT pm.id_pm, pm.subject, pm.id_member_from, pm.body, pm.msgtime, pm.from_name
- FROM {db_prefix}personal_messages AS pm' . ($context['folder'] == 'sent' ? '
- LEFT JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm)' : '') . ($sort_by == 'name' ? '
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:id_member})' : '') . '
- WHERE pm.id_pm IN ({array_int:display_pms})' . ($context['folder'] == 'sent' ? '
- GROUP BY pm.id_pm, pm.subject, pm.id_member_from, pm.body, pm.msgtime, pm.from_name' : '') . '
- ORDER BY ' . ($context['display_mode'] == 2 ? 'pm.id_pm' : $sort_by_query) . ($descending ? ' DESC' : ' ASC') . '
- LIMIT ' . count($display_pms),
- array(
- 'display_pms' => $display_pms,
- 'id_member' => $context['folder'] == 'sent' ? 'pmr.id_member' : 'pm.id_member_from',
- )
- );
- }
- else
- $messages_request = false;
- // prepare some items for the template
- $context['can_send_pm'] = allowedTo('pm_send');
- $context['can_send_email'] = allowedTo('send_email_to_members');
- $context['sub_template'] = 'folder';
- $context['page_title'] = $txt['pm_inbox'];
- $context['sort_direction'] = $descending ? 'down' : 'up';
- $context['sort_by'] = $sort_by;
- // Set up the page index.
- $context['page_index'] = constructPageIndex($scripturl . '?action=pm;f=' . $context['folder'] . (isset($_REQUEST['l']) ? ';l=' . (int) $_REQUEST['l'] : '') . ';sort=' . $context['sort_by'] . ($descending ? ';desc' : ''), $start, $max_messages, $modSettings['defaultMaxMessages']);
- $context['start'] = $start;
- // Finally mark the relevant messages as read.
- if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
- {
- // If the display mode is "old sk00l" do them all...
- if ($context['display_mode'] == 0)
- markMessages(null, $context['current_label_id']);
- // Otherwise do just the current one!
- elseif (!empty($context['current_pm']))
- markMessages($display_pms, $context['current_label_id']);
- }
- // Build the conversation button array.
- if ($context['display_mode'] === 2 && !empty($context['current_pm']))
- {
- $context['conversation_buttons'] = array(
- 'delete' => array('text' => 'delete_conversation', 'image' => 'delete.png', 'lang' => true, 'url' => $scripturl . '?action=pm;sa=pmactions;pm_actions[' . $context['current_pm'] . ']=delete;conversation;f=' . $context['folder'] . ';start=' . $context['start'] . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '') . ';' . $context['session_var'] . '=' . $context['session_id'], 'custom' => 'onclick="return confirm(\'' . addslashes($txt['remove_message']) . '?\');"'),
- );
- // Allow mods to add additional buttons here
- call_integration_hook('integrate_conversation_buttons');
- }
- }
- /**
- * Get a personal message for the theme. (used to save memory.)
- *
- * @param $type
- * @param $reset
- */
- function prepareMessageContext($type = 'subject', $reset = false)
- {
- global $txt, $scripturl, $modSettings, $settings, $context, $messages_request, $memberContext, $recipients, $smcFunc;
- global $user_info, $subjects_request;
- // Count the current message number....
- static $counter = null;
- if ($counter === null || $reset)
- $counter = $context['start'];
- static $temp_pm_selected = null;
- if ($temp_pm_selected === null)
- {
- $temp_pm_selected = isset($_SESSION['pm_selected']) ? $_SESSION['pm_selected'] : array();
- $_SESSION['pm_selected'] = array();
- }
- // If we're in non-boring view do something exciting!
- if ($context['display_mode'] != 0 && $subjects_request && $type == 'subject')
- {
- $subject = $smcFunc['db_fetch_assoc']($subjects_request);
- if (!$subject)
- {
- $smcFunc['db_free_result']($subjects_request);
- return false;
- }
- $subject['subject'] = $subject['subject'] == '' ? $txt['no_subject'] : $subject['subject'];
- censorText($subject['subject']);
- $output = array(
- 'id' => $subject['id_pm'],
- 'member' => array(
- 'id' => $subject['id_member_from'],
- 'name' => $subject['from_name'],
- 'link' => $subject['not_guest'] ? '<a href="' . $scripturl . '?action=profile;u=' . $subject['id_member_from'] . '">' . $subject['from_name'] . '</a>' : $subject['from_name'],
- ),
- 'recipients' => &$recipients[$subject['id_pm']],
- 'subject' => $subject['subject'],
- 'time' => timeformat($subject['msgtime']),
- 'timestamp' => forum_time(true, $subject['msgtime']),
- 'number_recipients' => count($recipients[$subject['id_pm']]['to']),
- 'labels' => &$context['message_labels'][$subject['id_pm']],
- 'fully_labeled' => count($context['message_labels'][$subject['id_pm']]) == count($context['labels']),
- 'is_replied_to' => &$context['message_replied'][$subject['id_pm']],
- 'is_unread' => &$context['message_unread'][$subject['id_pm']],
- 'is_selected' => !empty($temp_pm_selected) && in_array($subject['id_pm'], $temp_pm_selected),
- );
- return $output;
- }
- // Bail if it's false, ie. no messages.
- if ($messages_request == false)
- return false;
- // Reset the data?
- if ($reset == true)
- return @$smcFunc['db_data_seek']($messages_request, 0);
- // Get the next one... bail if anything goes wrong.
- $message = $smcFunc['db_fetch_assoc']($messages_request);
- if (!$message)
- {
- if ($type != 'subject')
- $smcFunc['db_free_result']($messages_request);
- return false;
- }
- // Use '(no subject)' if none was specified.
- $message['subject'] = $message['subject'] == '' ? $txt['no_subject'] : $message['subject'];
- // Load the message's information - if it's not there, load the guest information.
- if (!loadMemberContext($message['id_member_from'], true))
- {
- $memberContext[$message['id_member_from']]['name'] = $message['from_name'];
- $memberContext[$message['id_member_from']]['id'] = 0;
- // Sometimes the forum sends messages itself (Warnings are an example) - in this case don't label it from a guest.
- $memberContext[$message['id_member_from']]['group'] = $message['from_name'] == $context['forum_name'] ? '' : $txt['guest_title'];
- $memberContext[$message['id_member_from']]['link'] = $message['from_name'];
- $memberContext[$message['id_member_from']]['email'] = '';
- $memberContext[$message['id_member_from']]['show_email'] = showEmailAddress(true, 0);
- $memberContext[$message['id_member_from']]['is_guest'] = true;
- }
- else
- {
- $memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view_any') || ($message['id_member_from'] == $user_info['id'] && allowedTo('profile_view_own'));
- $memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
- }
- $memberContext[$message['id_member_from']]['show_profile_buttons'] = $settings['show_profile_buttons'] && (!empty($memberContext[$message['id_member_from']]['can_view_profile']) || (!empty($memberContext[$message['id_member_from']]['website']['url']) && !isset($context['disabled_fields']['website'])) || (in_array($memberContext[$message['id_member_from']]['show_email'], array('yes', 'yes_permission_override', 'no_through_forum'))) || $context['can_send_pm']);
- // Censor all the important text...
- censorText($message['body']);
- censorText($message['subject']);
- // Run UBBC interpreter on the message.
- $message['body'] = parse_bbc($message['body'], true, 'pm' . $message['id_pm']);
- // Send the array.
- $output = array(
- 'alternate' => $counter % 2,
- 'id' => $message['id_pm'],
- 'member' => &$memberContext[$message['id_member_from']],
- 'subject' => $message['subject'],
- 'time' => timeformat($message['msgtime']),
- 'timestamp' => forum_time(true, $message['msgtime']),
- 'counter' => $counter,
- 'body' => $message['body'],
- 'recipients' => &$recipients[$message['id_pm']],
- 'number_recipients' => count($recipients[$message['id_pm']]['to']),
- 'labels' => &$context['message_labels'][$message['id_pm']],
- 'fully_labeled' => count($context['message_labels'][$message['id_pm']]) == count($context['labels']),
- 'is_replied_to' => &$context['message_replied'][$message['id_pm']],
- 'is_unread' => &$context['message_unread'][$message['id_pm']],
- 'is_selected' => !empty($temp_pm_selected) && in_array($message['id_pm'], $temp_pm_selected),
- 'is_message_author' => $message['id_member_from'] == $user_info['id'],
- 'can_report' => !empty($modSettings['enableReportPM']),
- 'can_see_ip' => allowedTo('moderate_forum') || ($message['id_member_from'] == $user_info['id'] && !empty($user_info['id'])),
- );
- $counter++;
- return $output;
- }
- /**
- * Send a new message?
- */
- function action_sendmessage()
- {
- global $txt, $scripturl, $modSettings;
- global $context, $options, $smcFunc, $language, $user_info;
- isAllowedTo('pm_send');
- loadLanguage('PersonalMessage');
- // Just in case it was loaded from somewhere else.
- loadTemplate('PersonalMessage');
- $context['sub_template'] = 'send';
- // Extract out the spam settings - cause it's neat.
- list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
- // Set the title...
- $context['page_title'] = $txt['send_message'];
- $context['reply'] = isset($_REQUEST['pmsg']) || isset($_REQUEST['quote']);
- // Check whether we've gone over the limit of messages we can send per hour.
- if (!empty($modSettings['pm_posts_per_hour']) && !allowedTo(array('admin_forum', 'moderate_forum', 'send_mail')) && $user_info['mod_cache']['bq'] == '0=1' && $user_info['mod_cache']['gq'] == '0=1')
- {
- // How many messages have they sent this last hour?
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(pr.id_pm) AS post_count
- FROM {db_prefix}personal_messages AS pm
- INNER JOIN {db_prefix}pm_recipients AS pr ON (pr.id_pm = pm.id_pm)
- WHERE pm.id_member_from = {int:current_member}
- AND pm.msgtime > {int:msgtime}',
- array(
- 'current_member' => $user_info['id'],
- 'msgtime' => time() - 3600,
- )
- );
- list ($postCount) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
- fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
- }
- // Quoting/Replying to a message?
- if (!empty($_REQUEST['pmsg']))
- {
- $pmsg = (int) $_REQUEST['pmsg'];
- // Make sure this is yours.
- if (!isAccessiblePM($pmsg))
- fatal_lang_error('no_access', false);
- // Work out whether this is one you've received?
- $request = $smcFunc['db_query']('', '
- SELECT
- id_pm
- FROM {db_prefix}pm_recipients
- WHERE id_pm = {int:id_pm}
- AND id_member = {int:current_member}
- LIMIT 1',
- array(
- 'current_member' => $user_info['id'],
- 'id_pm' => $pmsg,
- )
- );
- $isReceived = $smcFunc['db_num_rows']($request) != 0;
- $smcFunc['db_free_result']($request);
- // Get the quoted message (and make sure you're allowed to see this quote!).
- $request = $smcFunc['db_query']('', '
- SELECT
- pm.id_pm, CASE WHEN pm.id_pm_head = {int:id_pm_head_empty} THEN pm.id_pm ELSE pm.id_pm_head END AS pm_head,
- pm.body, pm.subject, pm.msgtime, mem.member_name, IFNULL(mem.id_member, 0) AS id_member,
- IFNULL(mem.real_name, pm.from_name) AS real_name
- FROM {db_prefix}personal_messages AS pm' . (!$isReceived ? '' : '
- INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = {int:id_pm})') . '
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = pm.id_member_from)
- WHERE pm.id_pm = {int:id_pm}' . (!$isReceived ? '
- AND pm.id_member_from = {int:current_member}' : '
- AND pmr.id_member = {int:current_member}') . '
- LIMIT 1',
- array(
- 'current_member' => $user_info['id'],
- 'id_pm_head_empty' => 0,
- 'id_pm' => $pmsg,
- )
- );
- if ($smcFunc['db_num_rows']($request) == 0)
- fatal_lang_error('pm_not_yours', false);
- $row_quoted = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- // Censor the message.
- censorText($row_quoted['subject']);
- censorText($row_quoted['body']);
- // Add 'Re: ' to it....
- if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
- {
- if ($language === $user_info['language'])
- $context['response_prefix'] = $txt['response_prefix'];
- else
- {
- loadLanguage('index', $language, false);
- $context['response_prefix'] = $txt['response_prefix'];
- loadLanguage('index');
- }
- cache_put_data('response_prefix', $context['response_prefix'], 600);
- }
- $form_subject = $row_quoted['subject'];
- if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
- $form_subject = $context['response_prefix'] . $form_subject;
- if (isset($_REQUEST['quote']))
- {
- // Remove any nested quotes and <br />...
- $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
- if (!empty($modSettings['removeNestedQuotes']))
- $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
- if (empty($row_quoted['id_member']))
- $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]';
- else
- $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
- }
- else
- $form_message = '';
- // Do the BBC thang on the message.
- $row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
- // Set up the quoted message array.
- $context['quoted_message'] = array(
- 'id' => $row_quoted['id_pm'],
- 'pm_head' => $row_quoted['pm_head'],
- 'member' => array(
- 'name' => $row_quoted['real_name'],
- 'username' => $row_quoted['member_name'],
- 'id' => $row_quoted['id_member'],
- 'href' => !empty($row_quoted['id_member']) ? $scripturl . '?action=profile;u=' . $row_quoted['id_member'] : '',
- 'link' => !empty($row_quoted['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row_quoted['id_member'] . '">' . $row_quoted['real_name'] . '</a>' : $row_quoted['real_name'],
- ),
- 'subject' => $row_quoted['subject'],
- 'time' => timeformat($row_quoted['msgtime']),
- 'timestamp' => forum_time(true, $row_quoted['msgtime']),
- 'body' => $row_quoted['body']
- );
- }
- else
- {
- $context['quoted_message'] = false;
- $form_subject = '';
- $form_message = '';
- }
- $context['recipients'] = array(
- 'to' => array(),
- 'bcc' => array(),
- );
- // Sending by ID? Replying to all? Fetch the real_name(s).
- if (isset($_REQUEST['u']))
- {
- // If the user is replying to all, get all the other members this was sent to..
- if ($_REQUEST['u'] == 'all' && isset($row_quoted))
- {
- // Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
- if ($row_quoted['id_member'] != $user_info['id'])
- $context['recipients']['to'][] = array(
- 'id' => $row_quoted['id_member'],
- 'name' => htmlspecialchars($row_quoted['real_name']),
- );
- // Now to get the others.
- $request = $smcFunc['db_query']('', '
- SELECT mem.id_member, mem.real_name
- FROM {db_prefix}pm_recipients AS pmr
- INNER JOIN {db_prefix}members AS mem ON (mem.id_member = pmr.id_member)
- WHERE pmr.id_pm = {int:id_pm}
- AND pmr.id_member != {int:current_member}
- AND pmr.bcc = {int:not_bcc}',
- array(
- 'current_member' => $user_info['id'],
- 'id_pm' => $pmsg,
- 'not_bcc' => 0,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $context['recipients']['to'][] = array(
- 'id' => $row['id_member'],
- 'name' => $row['real_name'],
- );
- $smcFunc['db_free_result']($request);
- }
- else
- {
- $_REQUEST['u'] = explode(',', $_REQUEST['u']);
- foreach ($_REQUEST['u'] as $key => $uID)
- $_REQUEST['u'][$key] = (int) $uID;
- $_REQUEST['u'] = array_unique($_REQUEST['u']);
- $request = $smcFunc['db_query']('', '
- SELECT id_member, real_name
- FROM {db_prefix}members
- WHERE id_member IN ({array_int:member_list})
- LIMIT ' . count($_REQUEST['u']),
- array(
- 'member_list' => $_REQUEST['u'],
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $context['recipients']['to'][] = array(
- 'id' => $row['id_member'],
- 'name' => $row['real_name'],
- );
- $smcFunc['db_free_result']($request);
- }
- // Get a literal name list in case the user has JavaScript disabled.
- $names = array();
- foreach ($context['recipients']['to'] as $to)
- $names[] = $to['name'];
- $context['to_value'] = empty($names) ? '' : '"' . implode('", "', $names) . '"';
- }
- else
- $context['to_value'] = '';
- // Set the defaults...
- $context['subject'] = $form_subject;
- $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message);
- $context['copy_to_outbox'] = !empty($options['copy_to_outbox']);
- // And build the link tree.
- $context['linktree'][] = array(
- 'url' => $scripturl . '?action=pm;sa=send',
- 'name' => $txt['new_message']
- );
- $modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']);
- // Generate a list of drafts that they can load in to the editor
- if (!empty($context['drafts_pm_save']))
- {
- require_once(CONTROLLERDIR . '/Drafts.controller.php');
- $pm_seed = isset($_REQUEST['pmsg']) ? $_REQUEST['pmsg'] : (isset($_REQUEST['quote']) ? $_REQUEST['quote'] : 0);
- action_showDrafts($user_info['id'], $pm_seed, 1);
- }
- // Needed for the WYSIWYG editor.
- require_once(SUBSDIR . '/Editor.subs.php');
- // Now create the editor.
- $editorOptions = array(
- 'id' => 'message',
- 'value' => $context['message'],
- 'height' => '250px',
- 'width' => '100%',
- 'labels' => array(
- 'post_button' => $txt['send_message'],
- ),
- 'preview_type' => 2,
- );
- create_control_richedit($editorOptions);
- // Store the ID for old compatibility.
- $context['post_box_name'] = $editorOptions['id'];
- $context['bcc_value'] = '';
- $context['require_verification'] = !$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && $user_info['posts'] < $modSettings['pm_posts_verification'];
- if ($context['require_verification'])
- {
- $verificationOptions = array(
- 'id' => 'pm',
- );
- $context['require_verification'] = create_control_verification($verificationOptions);
- $context['visual_verification_id'] = $verificationOptions['id'];
- }
- // Register this form and get a sequence number in $context.
- checkSubmitOnce('register');
- }
- /**
- * This function allows the user to view their PM drafts
- * Accessed by ?action=pm;sa=showpmdrafts
- */
- function action_messagedrafts()
- {
- global $user_info;
- // validate with loadMemberData()
- $memberResult = loadMemberData($user_info['id'], false);
- if (!is_array($memberResult))
- fatal_lang_error('not_a_user', false);
- list ($memID) = $memberResult;
- // drafts is where the functions reside
- require_once(CONTROLLERDIR . '/Drafts.controller.php');
- action_showPMDrafts($memID);
- }
- /**
- * An error in the message...
- *
- * @param $named_recipients
- * @param $recipient_ids
- */
- function messagePostError($named_recipients, $recipient_ids = array())
- {
- global $txt, $context, $scripturl, $modSettings;
- global $smcFunc, $user_info;
- if (!isset($_REQUEST['xml']))
- $context['menu_data_' . $context['pm_menu_id']]['current_area'] = 'send';
- if (!isset($_REQUEST['xml']))
- $context['sub_template'] = 'send';
- elseif (isset($_REQUEST['xml']))
- $context['sub_template'] = 'pm';
- $context['page_title'] = $txt['send_message'];
- $error_types = error_context::context('pm', 1);
- // Got some known members?
- $context['recipients'] = array(
- 'to' => array(),
- 'bcc' => array(),
- );
- if (!empty($recipient_ids['to']) || !empty($recipient_ids['bcc']))
- {
- $allRecipients = array_merge($recipient_ids['to'], $recipient_ids['bcc']);
- $request = $smcFunc['db_query']('', '
- SELECT id_member, real_name
- FROM {db_prefix}members
- WHERE id_member IN ({array_int:member_list})',
- array(
- 'member_list' => $allRecipients,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $recipientType = in_array($row['id_member'], $recipient_ids['bcc']) ? 'bcc' : 'to';
- $context['recipients'][$recipientType][] = array(
- 'id' => $row['id_member'],
- 'name' => $row['real_name'],
- );
- }
- $smcFunc['db_free_result']($request);
- }
- // Set everything up like before....
- $context['subject'] = isset($_REQUEST['subject']) ? $smcFunc['htmlspecialchars']($_REQUEST['subject']) : '';
- $context['message'] = isset($_REQUEST['message']) ? str_replace(array(' '), array(' '), $smcFunc['htmlspecialchars']($_REQUEST['message'])) : '';
- $context['copy_to_outbox'] = !empty($_REQUEST['outbox']);
- $context['reply'] = !empty($_REQUEST['replied_to']);
- if ($context['reply'])
- {
- $_REQUEST['replied_to'] = (int) $_REQUEST['replied_to'];
- $request = $smcFunc['db_query']('', '
- SELECT
- pm.id_pm, CASE WHEN pm.id_pm_head = {int:no_id_pm_head} THEN pm.id_pm ELSE pm.id_pm_head END AS pm_head,
- pm.body, pm.subject, pm.msgtime, mem.member_name, IFNULL(mem.id_member, 0) AS id_member,
- IFNULL(mem.real_name, pm.from_name) AS real_name
- FROM {db_prefix}personal_messages AS pm' . ($context['folder'] == 'sent' ? '' : '
- INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = {int:replied_to})') . '
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = pm.id_member_from)
- WHERE pm.id_pm = {int:replied_to}' . ($context['folder'] == 'sent' ? '
- AND pm.id_member_from = {int:current_member}' : '
- AND pmr.id_member = {int:current_member}') . '
- LIMIT 1',
- array(
- 'current_member' => $user_info['id'],
- 'no_id_pm_head' => 0,
- 'replied_to' => $_REQUEST['replied_to'],
- )
- );
- if ($smcFunc['db_num_rows']($request) == 0)
- {
- if (!isset($_REQUEST['xml']))
- fatal_lang_error('pm_not_yours', false);
- else
- $error_types->addError('pm_not_yours');
- }
- $row_quoted = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- censorText($row_quoted['subject']);
- censorText($…
Large files files are truncated, but you can click here to view the full file