Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ucp_pm_compose.php
0001 <?php
0002 /**
0003 *
0004 * This file is part of the phpBB Forum Software package.
0005 *
0006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
0007 * @license GNU General Public License, version 2 (GPL-2.0)
0008 *
0009 * For full copyright and license information, please see
0010 * the docs/CREDITS.txt file.
0011 *
0012 */
0013
0014 /**
0015 * @ignore
0016 */
0017 if (!defined('IN_PHPBB'))
0018 {
0019 exit;
0020 }
0021
0022 /**
0023 * Compose private message
0024 * Called from ucp_pm with mode == 'compose'
0025 */
0026 function compose_pm($id, $mode, $action, $user_folders = array())
0027 {
0028 global $template, $db, $auth, $user, $cache;
0029 global $phpbb_root_path, $phpEx, $config;
0030 global $request, $phpbb_dispatcher, $phpbb_container;
0031
0032 // Damn php and globals - i know, this is horrible
0033 // Needed for handle_message_list_actions()
0034 global $refresh, $submit, $preview;
0035
0036 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
0037 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
0038 include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
0039
0040 if (!$action)
0041 {
0042 $action = 'post';
0043 }
0044 add_form_key('ucp_pm_compose');
0045
0046 // Grab only parameters needed here
0047 $to_user_id = request_var('u', 0);
0048 $to_group_id = request_var('g', 0);
0049 $msg_id = request_var('p', 0);
0050 $draft_id = request_var('d', 0);
0051 $lastclick = request_var('lastclick', 0);
0052
0053 // Reply to all triggered (quote/reply)
0054 $reply_to_all = request_var('reply_to_all', 0);
0055
0056 $address_list = $request->variable('address_list', array('' => array(0 => '')));
0057
0058 $submit = (isset($_POST['post'])) ? true : false;
0059 $preview = (isset($_POST['preview'])) ? true : false;
0060 $save = (isset($_POST['save'])) ? true : false;
0061 $load = (isset($_POST['load'])) ? true : false;
0062 $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
0063 $delete = (isset($_POST['delete'])) ? true : false;
0064
0065 $remove_u = (isset($_REQUEST['remove_u'])) ? true : false;
0066 $remove_g = (isset($_REQUEST['remove_g'])) ? true : false;
0067 $add_to = (isset($_REQUEST['add_to'])) ? true : false;
0068 $add_bcc = (isset($_REQUEST['add_bcc'])) ? true : false;
0069
0070 $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || $save || $load
0071 || $remove_u || $remove_g || $add_to || $add_bcc;
0072
0073 $action = ($delete && !$preview && !$refresh && $submit) ? 'delete' : $action;
0074 $select_single = ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? false : true;
0075
0076 $error = array();
0077 $current_time = time();
0078
0079 // Was cancel pressed? If so then redirect to the appropriate page
0080 if ($cancel || ($current_time - $lastclick < 2 && $submit))
0081 {
0082 if ($msg_id)
0083 {
0084 redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&action=view_message&p=' . $msg_id));
0085 }
0086 redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm'));
0087 }
0088
0089 // Since viewtopic.php language entries are used in several modes,
0090 // we include the language file here
0091 $user->add_lang('viewtopic');
0092
0093 // Output PM_TO box if message composing
0094 if ($action != 'edit')
0095 {
0096 // Add groups to PM box
0097 if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group'))
0098 {
0099 $sql = 'SELECT g.group_id, g.group_name, g.group_type
0100 FROM ' . GROUPS_TABLE . ' g';
0101
0102 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
0103 {
0104 $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
0105 ON (
0106 g.group_id = ug.group_id
0107 AND ug.user_id = ' . $user->data['user_id'] . '
0108 AND ug.user_pending = 0
0109 )
0110 WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
0111 }
0112
0113 $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';
0114
0115 $sql .= 'g.group_receive_pm = 1
0116 ORDER BY g.group_type DESC, g.group_name ASC';
0117 $result = $db->sql_query($sql);
0118
0119 $group_options = '';
0120 while ($row = $db->sql_fetchrow($result))
0121 {
0122 $group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
0123 }
0124 $db->sql_freeresult($result);
0125 }
0126
0127 $template->assign_vars(array(
0128 'S_SHOW_PM_BOX' => true,
0129 'S_ALLOW_MASS_PM' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? true : false,
0130 'S_GROUP_OPTIONS' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) ? $group_options : '',
0131 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&form=postform&field=username_list&select_single=$select_single"),
0132 ));
0133 }
0134
0135 $sql = '';
0136 $folder_id = 0;
0137
0138 // What is all this following SQL for? Well, we need to know
0139 // some basic information in all cases before we do anything.
0140 switch ($action)
0141 {
0142 case 'post':
0143 if (!$auth->acl_get('u_sendpm'))
0144 {
0145 trigger_error('NO_AUTH_SEND_MESSAGE');
0146 }
0147 break;
0148
0149 case 'reply':
0150 case 'quote':
0151 case 'forward':
0152 case 'quotepost':
0153 if (!$msg_id)
0154 {
0155 trigger_error('NO_MESSAGE');
0156 }
0157
0158 if (!$auth->acl_get('u_sendpm'))
0159 {
0160 trigger_error('NO_AUTH_SEND_MESSAGE');
0161 }
0162
0163 if ($action == 'quotepost')
0164 {
0165 $sql = 'SELECT p.post_id as msg_id, p.forum_id, p.post_text as message_text, p.poster_id as author_id, p.post_time as message_time, p.bbcode_bitfield, p.bbcode_uid, p.enable_sig, p.enable_smilies, p.enable_magic_url, t.topic_title as message_subject, u.username as quote_username
0166 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u
0167 WHERE p.post_id = $msg_id
0168 AND t.topic_id = p.topic_id
0169 AND u.user_id = p.poster_id";
0170 }
0171 else
0172 {
0173 $sql = 'SELECT t.folder_id, p.*, u.username as quote_username
0174 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
0175 WHERE t.user_id = ' . $user->data['user_id'] . "
0176 AND p.author_id = u.user_id
0177 AND t.msg_id = p.msg_id
0178 AND p.msg_id = $msg_id";
0179 }
0180 break;
0181
0182 case 'edit':
0183 if (!$msg_id)
0184 {
0185 trigger_error('NO_MESSAGE');
0186 }
0187
0188 // check for outbox (not read) status, we do not allow editing if one user already having the message
0189 $sql = 'SELECT p.*, t.folder_id
0190 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
0191 WHERE t.user_id = ' . $user->data['user_id'] . '
0192 AND t.folder_id = ' . PRIVMSGS_OUTBOX . "
0193 AND t.msg_id = $msg_id
0194 AND t.msg_id = p.msg_id";
0195 break;
0196
0197 case 'delete':
0198 if (!$auth->acl_get('u_pm_delete'))
0199 {
0200 trigger_error('NO_AUTH_DELETE_MESSAGE');
0201 }
0202
0203 if (!$msg_id)
0204 {
0205 trigger_error('NO_MESSAGE');
0206 }
0207
0208 $sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id
0209 FROM ' . PRIVMSGS_TO_TABLE . '
0210 WHERE user_id = ' . $user->data['user_id'] . "
0211 AND msg_id = $msg_id";
0212 break;
0213
0214 case 'smilies':
0215 generate_smilies('window', 0);
0216 break;
0217
0218 default:
0219 trigger_error('NO_ACTION_MODE', E_USER_ERROR);
0220 break;
0221 }
0222
0223 if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward')))
0224 {
0225 trigger_error('NO_AUTH_FORWARD_MESSAGE');
0226 }
0227
0228 if ($action == 'edit' && !$auth->acl_get('u_pm_edit'))
0229 {
0230 trigger_error('NO_AUTH_EDIT_MESSAGE');
0231 }
0232
0233 if ($sql)
0234 {
0235 /**
0236 * Alter sql query to get message for user to write the PM
0237 *
0238 * @event core.ucp_pm_compose_compose_pm_basic_info_query_before
0239 * @var string sql String with the query to be executed
0240 * @var array forum_list List of forums that contain the posts
0241 * @var int visibility_const Integer with one of the possible ITEM_* constant values
0242 * @var int msg_id topic_id in the page request
0243 * @var int to_user_id The id of whom the message is to
0244 * @var int to_group_id The id of the group whom the message is to
0245 * @var bool submit Whether the user is sending the PM or not
0246 * @var bool preview Whether the user is previewing the PM or not
0247 * @var string action One of: post, reply, quote, forward, quotepost, edit, delete, smilies
0248 * @var bool delete Whether the user is deleting the PM
0249 * @var int reply_to_all Value of reply_to_all request variable.
0250 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string)
0251 * @var string sort_order_sql String with the ORDER BY SQL code used in this query
0252 * @since 3.1.0-RC5
0253 */
0254 $vars = array(
0255 'sql',
0256 'forum_list',
0257 'visibility_const',
0258 'msg_id',
0259 'to_user_id',
0260 'to_group_id',
0261 'submit',
0262 'preview',
0263 'action',
0264 'delete',
0265 'reply_to_all',
0266 'limit_time_sql',
0267 'sort_order_sql',
0268 );
0269 extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_compose_pm_basic_info_query_before', compact($vars)));
0270
0271 $result = $db->sql_query($sql);
0272 $post = $db->sql_fetchrow($result);
0273 $db->sql_freeresult($result);
0274
0275 if (!$post)
0276 {
0277 // If editing it could be the recipient already read the message...
0278 if ($action == 'edit')
0279 {
0280 $sql = 'SELECT p.*, t.folder_id
0281 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
0282 WHERE t.user_id = ' . $user->data['user_id'] . "
0283 AND t.msg_id = $msg_id
0284 AND t.msg_id = p.msg_id";
0285 $result = $db->sql_query($sql);
0286 $post = $db->sql_fetchrow($result);
0287 $db->sql_freeresult($result);
0288
0289 if ($post)
0290 {
0291 trigger_error('NO_EDIT_READ_MESSAGE');
0292 }
0293 }
0294
0295 trigger_error('NO_MESSAGE');
0296 }
0297
0298 if ($action == 'quotepost')
0299 {
0300 if (($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id'])) || (!$post['forum_id'] && !$auth->acl_getf_global('f_read')))
0301 {
0302 trigger_error('NOT_AUTHORISED');
0303 }
0304
0305 /**
0306 * Get the result of querying for the post to be quoted in the pm message
0307 *
0308 * @event core.ucp_pm_compose_quotepost_query_after
0309 * @var string sql The original SQL used in the query
0310 * @var array post Associative array with the data of the quoted post
0311 * @var array msg_id The post_id that was searched to get the message for quoting
0312 * @var int visibility_const Visibility of the quoted post (one of the possible ITEM_* constant values)
0313 * @var int topic_id Topic ID of the quoted post
0314 * @var int to_user_id Users the message is sent to
0315 * @var int to_group_id Groups the message is sent to
0316 * @var bool submit Whether the user is sending the PM or not
0317 * @var bool preview Whether the user is previewing the PM or not
0318 * @var string action One of: post, reply, quote, forward, quotepost, edit, delete, smilies
0319 * @var bool delete If deleting message
0320 * @var int reply_to_all Value of reply_to_all request variable.
0321 * @since 3.1.0-RC5
0322 */
0323 $vars = array(
0324 'sql',
0325 'post',
0326 'msg_id',
0327 'visibility_const',
0328 'topic_id',
0329 'to_user_id',
0330 'to_group_id',
0331 'submit',
0332 'preview',
0333 'action',
0334 'delete',
0335 'reply_to_all',
0336 );
0337 extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_quotepost_query_after', compact($vars)));
0338
0339 // Passworded forum?
0340 if ($post['forum_id'])
0341 {
0342 $sql = 'SELECT forum_id, forum_name, forum_password
0343 FROM ' . FORUMS_TABLE . '
0344 WHERE forum_id = ' . (int) $post['forum_id'];
0345 $result = $db->sql_query($sql);
0346 $forum_data = $db->sql_fetchrow($result);
0347 $db->sql_freeresult($result);
0348
0349 if (!empty($forum_data['forum_password']))
0350 {
0351 login_forum_box($forum_data);
0352 }
0353 }
0354 }
0355
0356 $msg_id = (int) $post['msg_id'];
0357 $folder_id = (isset($post['folder_id'])) ? $post['folder_id'] : 0;
0358 $message_text = (isset($post['message_text'])) ? $post['message_text'] : '';
0359
0360 if ((!$post['author_id'] || ($post['author_id'] == ANONYMOUS && $action != 'delete')) && $msg_id)
0361 {
0362 trigger_error('NO_AUTHOR');
0363 }
0364
0365 if ($action == 'quotepost')
0366 {
0367 // Decode text for message display
0368 decode_message($message_text, $post['bbcode_uid']);
0369 }
0370
0371 if ($action != 'delete')
0372 {
0373 $enable_urls = $post['enable_magic_url'];
0374 $enable_sig = (isset($post['enable_sig'])) ? $post['enable_sig'] : 0;
0375
0376 $message_attachment = (isset($post['message_attachment'])) ? $post['message_attachment'] : 0;
0377 $message_subject = $post['message_subject'];
0378 $message_time = $post['message_time'];
0379 $bbcode_uid = $post['bbcode_uid'];
0380
0381 $quote_username = (isset($post['quote_username'])) ? $post['quote_username'] : '';
0382 $icon_id = (isset($post['icon_id'])) ? $post['icon_id'] : 0;
0383
0384 if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview)
0385 {
0386 // Add the original author as the recipient if quoting a post or only replying and not having checked "reply to all"
0387 if ($action == 'quotepost' || !$reply_to_all)
0388 {
0389 $address_list = array('u' => array($post['author_id'] => 'to'));
0390 }
0391 else
0392 {
0393 // We try to include every previously listed member from the TO Header - Reply to all
0394 $address_list = rebuild_header(array('to' => $post['to_address']));
0395
0396 // Add the author (if he is already listed then this is no shame (it will be overwritten))
0397 $address_list['u'][$post['author_id']] = 'to';
0398
0399 // Now, make sure the user itself is not listed. ;)
0400 if (isset($address_list['u'][$user->data['user_id']]))
0401 {
0402 unset($address_list['u'][$user->data['user_id']]);
0403 }
0404 }
0405 }
0406 else if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview)
0407 {
0408 // Rebuild TO and BCC Header
0409 $address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address']));
0410 }
0411
0412 if ($action == 'quotepost')
0413 {
0414 $check_value = 0;
0415 }
0416 else
0417 {
0418 $check_value = (($post['enable_bbcode']+1) << 8) + (($post['enable_smilies']+1) << 4) + (($enable_urls+1) << 2) + (($post['enable_sig']+1) << 1);
0419 }
0420 }
0421 }
0422 else
0423 {
0424 $message_attachment = 0;
0425 $message_text = $message_subject = '';
0426
0427 if ($to_user_id && $to_user_id != ANONYMOUS && $action == 'post')
0428 {
0429 $address_list['u'][$to_user_id] = 'to';
0430 }
0431 else if ($to_group_id && $action == 'post')
0432 {
0433 $address_list['g'][$to_group_id] = 'to';
0434 }
0435 $check_value = 0;
0436 }
0437
0438 if (($to_group_id || isset($address_list['g'])) && (!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')))
0439 {
0440 trigger_error('NO_AUTH_GROUP_MESSAGE');
0441 }
0442
0443 if ($action == 'edit' && !$refresh && !$preview && !$submit)
0444 {
0445 if (!($message_time > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']))
0446 {
0447 trigger_error('CANNOT_EDIT_MESSAGE_TIME');
0448 }
0449 }
0450
0451 if ($action == 'post')
0452 {
0453 $template->assign_var('S_NEW_MESSAGE', true);
0454 }
0455
0456 if (!isset($icon_id))
0457 {
0458 $icon_id = 0;
0459 }
0460
0461 $message_parser = new parse_message();
0462 $plupload = $phpbb_container->get('plupload');
0463 $message_parser->set_plupload($plupload);
0464
0465 $message_parser->message = ($action == 'reply') ? '' : $message_text;
0466 unset($message_text);
0467
0468 $s_action = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=$mode&action=$action", true, $user->session_id);
0469 $s_action .= (($folder_id) ? "&f=$folder_id" : '') . (($msg_id) ? "&p=$msg_id" : '');
0470
0471 // Delete triggered ?
0472 if ($action == 'delete')
0473 {
0474 // Folder id has been determined by the SQL Statement
0475 // $folder_id = request_var('f', PRIVMSGS_NO_BOX);
0476
0477 // Do we need to confirm ?
0478 if (confirm_box(true))
0479 {
0480 delete_pm($user->data['user_id'], $msg_id, $folder_id);
0481
0482 // jump to next message in "history"? nope, not for the moment. But able to be included later.
0483 $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&folder=$folder_id");
0484 $message = $user->lang['MESSAGE_DELETED'];
0485
0486 meta_refresh(3, $meta_info);
0487 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
0488 trigger_error($message);
0489 }
0490 else
0491 {
0492 $s_hidden_fields = array(
0493 'p' => $msg_id,
0494 'f' => $folder_id,
0495 'action' => 'delete'
0496 );
0497
0498 // "{$phpbb_root_path}ucp.$phpEx?i=pm&mode=compose"
0499 confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields));
0500 }
0501
0502 redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&action=view_message&p=' . $msg_id));
0503 }
0504
0505 // Get maximum number of allowed recipients
0506 $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients
0507 FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
0508 WHERE ug.user_id = ' . $user->data['user_id'] . '
0509 AND ug.user_pending = 0
0510 AND ug.group_id = g.group_id';
0511 $result = $db->sql_query($sql);
0512 $max_recipients = (int) $db->sql_fetchfield('max_recipients');
0513 $db->sql_freeresult($result);
0514
0515 $max_recipients = (!$max_recipients) ? $config['pm_max_recipients'] : $max_recipients;
0516
0517 // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
0518 if (($action == 'reply' || $action == 'quote') && $max_recipients && $reply_to_all)
0519 {
0520 // We try to include every previously listed member from the TO Header
0521 $list = rebuild_header(array('to' => $post['to_address']));
0522
0523 // Can be an empty array too ;)
0524 $list = (!empty($list['u'])) ? $list['u'] : array();
0525 $list[$post['author_id']] = 'to';
0526
0527 if (isset($list[$user->data['user_id']]))
0528 {
0529 unset($list[$user->data['user_id']]);
0530 }
0531
0532 $max_recipients = ($max_recipients < sizeof($list)) ? sizeof($list) : $max_recipients;
0533
0534 unset($list);
0535 }
0536
0537 // Handle User/Group adding/removing
0538 handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);
0539
0540 // Check mass pm to group permission
0541 if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')) && !empty($address_list['g']))
0542 {
0543 $address_list = array();
0544 $error[] = $user->lang['NO_AUTH_GROUP_MESSAGE'];
0545 }
0546
0547 // Check mass pm to users permission
0548 if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1)
0549 {
0550 $address_list = get_recipients($address_list, 1);
0551 $error[] = $user->lang('TOO_MANY_RECIPIENTS', 1);
0552 }
0553
0554 // Check for too many recipients
0555 if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients)
0556 {
0557 $address_list = get_recipients($address_list, $max_recipients);
0558 $error[] = $user->lang('TOO_MANY_RECIPIENTS', $max_recipients);
0559 }
0560
0561 // Always check if the submitted attachment data is valid and belongs to the user.
0562 // Further down (especially in submit_post()) we do not check this again.
0563 $message_parser->get_submitted_attachment_data();
0564
0565 if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit')
0566 {
0567 // Do not change to SELECT *
0568 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename, filesize
0569 FROM ' . ATTACHMENTS_TABLE . "
0570 WHERE post_msg_id = $msg_id
0571 AND in_message = 1
0572 AND is_orphan = 0
0573 ORDER BY filetime DESC";
0574 $result = $db->sql_query($sql);
0575 $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
0576 $db->sql_freeresult($result);
0577 }
0578
0579 if (!in_array($action, array('quote', 'edit', 'delete', 'forward')))
0580 {
0581 $enable_sig = ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig'));
0582 $enable_smilies = ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies'));
0583 $enable_bbcode = ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode'));
0584 $enable_urls = true;
0585 }
0586
0587 $enable_magic_url = $drafts = false;
0588
0589 // User own some drafts?
0590 if ($auth->acl_get('u_savedrafts') && $action != 'delete')
0591 {
0592 $sql = 'SELECT draft_id
0593 FROM ' . DRAFTS_TABLE . '
0594 WHERE forum_id = 0
0595 AND topic_id = 0
0596 AND user_id = ' . $user->data['user_id'] .
0597 (($draft_id) ? " AND draft_id <> $draft_id" : '');
0598 $result = $db->sql_query_limit($sql, 1);
0599 $row = $db->sql_fetchrow($result);
0600 $db->sql_freeresult($result);
0601
0602 if ($row)
0603 {
0604 $drafts = true;
0605 }
0606 }
0607
0608 if ($action == 'edit')
0609 {
0610 $message_parser->bbcode_uid = $bbcode_uid;
0611 }
0612
0613 $bbcode_status = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false;
0614 $smilies_status = ($config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies')) ? true : false;
0615 $img_status = ($config['auth_img_pm'] && $auth->acl_get('u_pm_img')) ? true : false;
0616 $flash_status = ($config['auth_flash_pm'] && $auth->acl_get('u_pm_flash')) ? true : false;
0617 $url_status = ($config['allow_post_links']) ? true : false;
0618
0619 // Save Draft
0620 if ($save && $auth->acl_get('u_savedrafts'))
0621 {
0622 $subject = utf8_normalize_nfc(request_var('subject', '', true));
0623 $subject = (!$subject && $action != 'post') ? $user->lang['NEW_MESSAGE'] : $subject;
0624 $message = utf8_normalize_nfc(request_var('message', '', true));
0625
0626 if ($subject && $message)
0627 {
0628 if (confirm_box(true))
0629 {
0630 $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
0631 'user_id' => $user->data['user_id'],
0632 'topic_id' => 0,
0633 'forum_id' => 0,
0634 'save_time' => $current_time,
0635 'draft_subject' => $subject,
0636 'draft_message' => $message
0637 )
0638 );
0639 $db->sql_query($sql);
0640
0641 $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=$mode");
0642
0643 meta_refresh(3, $redirect_url);
0644 $message = $user->lang['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>');
0645
0646 trigger_error($message);
0647 }
0648 else
0649 {
0650 $s_hidden_fields = build_hidden_fields(array(
0651 'mode' => $mode,
0652 'action' => $action,
0653 'save' => true,
0654 'subject' => $subject,
0655 'message' => $message,
0656 'u' => $to_user_id,
0657 'g' => $to_group_id,
0658 'p' => $msg_id)
0659 );
0660 $s_hidden_fields .= build_address_field($address_list);
0661
0662 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
0663 }
0664 }
0665 else
0666 {
0667 if (utf8_clean_string($subject) === '')
0668 {
0669 $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
0670 }
0671
0672 if (utf8_clean_string($message) === '')
0673 {
0674 $error[] = $user->lang['TOO_FEW_CHARS'];
0675 }
0676 }
0677
0678 unset($subject, $message);
0679 }
0680
0681 // Load Draft
0682 if ($draft_id && $auth->acl_get('u_savedrafts'))
0683 {
0684 $sql = 'SELECT draft_subject, draft_message
0685 FROM ' . DRAFTS_TABLE . "
0686 WHERE draft_id = $draft_id
0687 AND topic_id = 0
0688 AND forum_id = 0
0689 AND user_id = " . $user->data['user_id'];
0690 $result = $db->sql_query_limit($sql, 1);
0691
0692 if ($row = $db->sql_fetchrow($result))
0693 {
0694 $message_parser->message = $row['draft_message'];
0695 $message_subject = $row['draft_subject'];
0696
0697 $template->assign_var('S_DRAFT_LOADED', true);
0698 }
0699 else
0700 {
0701 $draft_id = 0;
0702 }
0703 $db->sql_freeresult($result);
0704 }
0705
0706 // Load Drafts
0707 if ($load && $drafts)
0708 {
0709 load_drafts(0, 0, $id, $action, $msg_id);
0710 }
0711
0712 if ($submit || $preview || $refresh)
0713 {
0714 if (($submit || $preview) && !check_form_key('ucp_pm_compose'))
0715 {
0716 $error[] = $user->lang['FORM_INVALID'];
0717 }
0718 $subject = utf8_normalize_nfc(request_var('subject', '', true));
0719 $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
0720
0721 $icon_id = request_var('icon', 0);
0722
0723 $enable_bbcode = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
0724 $enable_smilies = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
0725 $enable_urls = (isset($_POST['disable_magic_url'])) ? 0 : 1;
0726 $enable_sig = (!$config['allow_sig'] ||!$config['allow_sig_pm']) ? false : ((isset($_POST['attach_sig'])) ? true : false);
0727
0728 if ($submit)
0729 {
0730 $status_switch = (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1);
0731 $status_switch = ($status_switch != $check_value);
0732 }
0733 else
0734 {
0735 $status_switch = 1;
0736 }
0737
0738 // Parse Attachments - before checksum is calculated
0739 $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
0740
0741 if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc))
0742 {
0743 $error[] = implode('<br />', $message_parser->warn_msg);
0744 $message_parser->warn_msg = array();
0745 }
0746
0747 // Parse message
0748 $message_parser->parse($enable_bbcode, ($config['allow_post_links']) ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);
0749
0750 // On a refresh we do not care about message parsing errors
0751 if (sizeof($message_parser->warn_msg) && !$refresh)
0752 {
0753 $error[] = implode('<br />', $message_parser->warn_msg);
0754 }
0755
0756 if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood'))
0757 {
0758 // Flood check
0759 $last_post_time = $user->data['user_lastpost_time'];
0760
0761 if ($last_post_time)
0762 {
0763 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
0764 {
0765 $error[] = $user->lang['FLOOD_ERROR'];
0766 }
0767 }
0768 }
0769
0770 // Subject defined
0771 if ($submit)
0772 {
0773 if (utf8_clean_string($subject) === '')
0774 {
0775 $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
0776 }
0777
0778 if (!sizeof($address_list))
0779 {
0780 $error[] = $user->lang['NO_RECIPIENT'];
0781 }
0782 }
0783
0784 // Store message, sync counters
0785 if (!sizeof($error) && $submit)
0786 {
0787 $pm_data = array(
0788 'msg_id' => (int) $msg_id,
0789 'from_user_id' => $user->data['user_id'],
0790 'from_user_ip' => $user->ip,
0791 'from_username' => $user->data['username'],
0792 'reply_from_root_level' => (isset($post['root_level'])) ? (int) $post['root_level'] : 0,
0793 'reply_from_msg_id' => (int) $msg_id,
0794 'icon_id' => (int) $icon_id,
0795 'enable_sig' => (bool) $enable_sig,
0796 'enable_bbcode' => (bool) $enable_bbcode,
0797 'enable_smilies' => (bool) $enable_smilies,
0798 'enable_urls' => (bool) $enable_urls,
0799 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
0800 'bbcode_uid' => $message_parser->bbcode_uid,
0801 'message' => $message_parser->message,
0802 'attachment_data' => $message_parser->attachment_data,
0803 'filename_data' => $message_parser->filename_data,
0804 'address_list' => $address_list
0805 );
0806
0807 // ((!$message_subject) ? $subject : $message_subject)
0808 $msg_id = submit_pm($action, $subject, $pm_data);
0809
0810 $return_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&p=' . $msg_id);
0811 $inbox_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox');
0812 $outbox_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=outbox');
0813
0814 $folder_url = '';
0815 if (($folder_id > 0) && isset($user_folders[$folder_id]))
0816 {
0817 $folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=' . $folder_id);
0818 }
0819
0820 $return_box_url = ($action === 'post' || $action === 'edit') ? $outbox_folder_url : $inbox_folder_url;
0821 $return_box_lang = ($action === 'post' || $action === 'edit') ? 'PM_OUTBOX' : 'PM_INBOX';
0822
0823 $save_message = ($action === 'edit') ? $user->lang['MESSAGE_EDITED'] : $user->lang['MESSAGE_STORED'];
0824 $message = $save_message . '<br /><br />' . $user->lang('VIEW_PRIVATE_MESSAGE', '<a href="' . $return_message_url . '">', '</a>');
0825
0826 $last_click_type = 'CLICK_RETURN_FOLDER';
0827 if ($folder_url)
0828 {
0829 $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $folder_url . '">', '</a>', $user_folders[$folder_id]['folder_name']);
0830 $last_click_type = 'CLICK_GOTO_FOLDER';
0831 }
0832 $message .= '<br /><br />' . sprintf($user->lang[$last_click_type], '<a href="' . $return_box_url . '">', '</a>', $user->lang[$return_box_lang]);
0833
0834 meta_refresh(3, $return_message_url);
0835 trigger_error($message);
0836 }
0837
0838 $message_subject = $subject;
0839 }
0840
0841 // Preview
0842 if (!sizeof($error) && $preview)
0843 {
0844 $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
0845
0846 $preview_signature = $user->data['user_sig'];
0847 $preview_signature_uid = $user->data['user_sig_bbcode_uid'];
0848 $preview_signature_bitfield = $user->data['user_sig_bbcode_bitfield'];
0849
0850 // Signature
0851 if ($enable_sig && $config['allow_sig'] && $preview_signature)
0852 {
0853 $parse_sig = new parse_message($preview_signature);
0854 $parse_sig->bbcode_uid = $preview_signature_uid;
0855 $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
0856
0857 $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
0858 $preview_signature = $parse_sig->message;
0859 unset($parse_sig);
0860 }
0861 else
0862 {
0863 $preview_signature = '';
0864 }
0865
0866 // Attachment Preview
0867 if (sizeof($message_parser->attachment_data))
0868 {
0869 $template->assign_var('S_HAS_ATTACHMENTS', true);
0870
0871 $update_count = array();
0872 $attachment_data = $message_parser->attachment_data;
0873
0874 parse_attachments(false, $preview_message, $attachment_data, $update_count, true);
0875
0876 foreach ($attachment_data as $i => $attachment)
0877 {
0878 $template->assign_block_vars('attachment', array(
0879 'DISPLAY_ATTACHMENT' => $attachment)
0880 );
0881 }
0882 unset($attachment_data);
0883 }
0884
0885 $preview_subject = censor_text($subject);
0886
0887 if (!sizeof($error))
0888 {
0889 $template->assign_vars(array(
0890 'PREVIEW_SUBJECT' => $preview_subject,
0891 'PREVIEW_MESSAGE' => $preview_message,
0892 'PREVIEW_SIGNATURE' => $preview_signature,
0893
0894 'S_DISPLAY_PREVIEW' => true)
0895 );
0896 }
0897 unset($message_text);
0898 }
0899
0900 // Decode text for message display
0901 $bbcode_uid = (($action == 'quote' || $action == 'forward') && !$preview && !$refresh && (!sizeof($error) || (sizeof($error) && !$submit))) ? $bbcode_uid : $message_parser->bbcode_uid;
0902
0903 $message_parser->decode_message($bbcode_uid);
0904
0905 if (($action == 'quote' || $action == 'quotepost') && !$preview && !$refresh && !$submit)
0906 {
0907 if ($action == 'quotepost')
0908 {
0909 $post_id = request_var('p', 0);
0910 if ($config['allow_post_links'])
0911 {
0912 $message_link = "[url=" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id}]{$user->lang['SUBJECT']}{$user->lang['COLON']} {$message_subject}[/url]\n\n";
0913 }
0914 else
0915 {
0916 $message_link = $user->lang['SUBJECT'] . $user->lang['COLON'] . ' ' . $message_subject . " (" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id})\n\n";
0917 }
0918 }
0919 else
0920 {
0921 $message_link = '';
0922 }
0923 $message_parser->message = $message_link . '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
0924 }
0925
0926 if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh)
0927 {
0928 $message_subject = ((!preg_match('/^Re:/', $message_subject)) ? 'Re: ' : '') . censor_text($message_subject);
0929 }
0930
0931 if ($action == 'forward' && !$preview && !$refresh && !$submit)
0932 {
0933 $fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true);
0934
0935 if ($config['allow_post_links'])
0936 {
0937 $quote_username_text = '[url=' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$post['author_id']}]{$quote_username}[/url]";
0938 }
0939 else
0940 {
0941 $quote_username_text = $quote_username . ' (' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$post['author_id']})";
0942 }
0943
0944 $forward_text = array();
0945 $forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE'];
0946 $forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject));
0947 $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time, false, true));
0948 $forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
0949 $forward_text[] = sprintf($user->lang['FWD_TO'], implode($user->lang['COMMA_SEPARATOR'], $fwd_to_field['to']));
0950
0951 $message_parser->message = implode("\n", $forward_text) . "\n\n[quote="{$quote_username}"]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]";
0952 $message_subject = ((!preg_match('/^Fwd:/', $message_subject)) ? 'Fwd: ' : '') . censor_text($message_subject);
0953 }
0954
0955 $attachment_data = $message_parser->attachment_data;
0956 $filename_data = $message_parser->filename_data;
0957 $message_text = $message_parser->message;
0958
0959 // MAIN PM PAGE BEGINS HERE
0960
0961 // Generate smiley listing
0962 generate_smilies('inline', 0);
0963
0964 // Generate PM Icons
0965 $s_pm_icons = false;
0966 if ($config['enable_pm_icons'])
0967 {
0968 $s_pm_icons = posting_gen_topic_icons($action, $icon_id);
0969 }
0970
0971 // Generate inline attachment select box
0972 posting_gen_inline_attachments($attachment_data);
0973
0974 // Build address list for display
0975 // array('u' => array($author_id => 'to'));
0976 if (sizeof($address_list))
0977 {
0978 // Get Usernames and Group Names
0979 $result = array();
0980 if (!empty($address_list['u']))
0981 {
0982 $sql = 'SELECT user_id as id, username as name, user_colour as colour
0983 FROM ' . USERS_TABLE . '
0984 WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . '
0985 ORDER BY username_clean ASC';
0986 $result['u'] = $db->sql_query($sql);
0987 }
0988
0989 if (!empty($address_list['g']))
0990 {
0991 $sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type
0992 FROM ' . GROUPS_TABLE . ' g';
0993
0994 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
0995 {
0996 $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
0997 ON (
0998 g.group_id = ug.group_id
0999 AND ug.user_id = ' . $user->data['user_id'] . '
1000 AND ug.user_pending = 0
1001 )
1002 WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
1003 }
1004
1005 $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';
1006
1007 $sql .= 'g.group_receive_pm = 1
1008 AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . '
1009 ORDER BY g.group_name ASC';
1010
1011 $result['g'] = $db->sql_query($sql);
1012 }
1013
1014 $u = $g = array();
1015 $_types = array('u', 'g');
1016 foreach ($_types as $type)
1017 {
1018 if (isset($result[$type]) && $result[$type])
1019 {
1020 while ($row = $db->sql_fetchrow($result[$type]))
1021 {
1022 if ($type == 'g')
1023 {
1024 $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
1025 }
1026
1027 ${$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
1028 }
1029 $db->sql_freeresult($result[$type]);
1030 }
1031 }
1032
1033 // Now Build the address list
1034 $plain_address_field = '';
1035 foreach ($address_list as $type => $adr_ary)
1036 {
1037 foreach ($adr_ary as $id => $field)
1038 {
1039 if (!isset(${$type}[$id]))
1040 {
1041 unset($address_list[$type][$id]);
1042 continue;
1043 }
1044
1045 $field = ($field == 'to') ? 'to' : 'bcc';
1046 $type = ($type == 'u') ? 'u' : 'g';
1047 $id = (int) $id;
1048
1049 $tpl_ary = array(
1050 'IS_GROUP' => ($type == 'g') ? true : false,
1051 'IS_USER' => ($type == 'u') ? true : false,
1052 'UG_ID' => $id,
1053 'NAME' => ${$type}[$id]['name'],
1054 'COLOUR' => (${$type}[$id]['colour']) ? '#' . ${$type}[$id]['colour'] : '',
1055 'TYPE' => $type,
1056 );
1057
1058 if ($type == 'u')
1059 {
1060 $tpl_ary = array_merge($tpl_ary, array(
1061 'U_VIEW' => get_username_string('profile', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
1062 'NAME_FULL' => get_username_string('full', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
1063 ));
1064 }
1065 else
1066 {
1067 $tpl_ary = array_merge($tpl_ary, array(
1068 'U_VIEW' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $id),
1069 ));
1070 }
1071
1072 $template->assign_block_vars($field . '_recipient', $tpl_ary);
1073 }
1074 }
1075 }
1076
1077 // Build hidden address list
1078 $s_hidden_address_field = build_address_field($address_list);
1079
1080 $bbcode_checked = (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode')) ? !$user->optionget('bbcode') : 1);
1081 $smilies_checked = (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies'] && $auth->acl_get('u_pm_smilies')) ? !$user->optionget('smilies') : 1);
1082 $urls_checked = (isset($enable_urls)) ? !$enable_urls : 0;
1083 $sig_checked = $enable_sig;
1084
1085 switch ($action)
1086 {
1087 case 'post':
1088 $page_title = $user->lang['POST_NEW_PM'];
1089 break;
1090
1091 case 'quote':
1092 $page_title = $user->lang['POST_QUOTE_PM'];
1093 break;
1094
1095 case 'quotepost':
1096 $page_title = $user->lang['POST_PM_POST'];
1097 break;
1098
1099 case 'reply':
1100 $page_title = $user->lang['POST_REPLY_PM'];
1101 break;
1102
1103 case 'edit':
1104 $page_title = $user->lang['POST_EDIT_PM'];
1105 break;
1106
1107 case 'forward':
1108 $page_title = $user->lang['POST_FORWARD_PM'];
1109 break;
1110
1111 default:
1112 trigger_error('NO_ACTION_MODE', E_USER_ERROR);
1113 break;
1114 }
1115
1116 $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1117 $s_hidden_fields .= (isset($check_value)) ? '<input type="hidden" name="status_switch" value="' . $check_value . '" />' : '';
1118 $s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . ((isset($_REQUEST['draft_loaded'])) ? $request->variable('draft_loaded', 0) : $draft_id) . '" />' : '';
1119
1120 $form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$config['allow_pm_attach'] || !$auth->acl_get('u_pm_attach')) ? '' : ' enctype="multipart/form-data"';
1121
1122 // Start assigning vars for main posting page ...
1123 $template->assign_vars(array(
1124 'L_POST_A' => $page_title,
1125 'L_ICON' => $user->lang['PM_ICON'],
1126 'L_MESSAGE_BODY_EXPLAIN' => $user->lang('MESSAGE_BODY_EXPLAIN', (int) $config['max_post_chars']),
1127
1128 'SUBJECT' => (isset($message_subject)) ? $message_subject : '',
1129 'MESSAGE' => $message_text,
1130 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
1131 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1132 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1133 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1134 'URL_STATUS' => ($url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1135 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'],
1136 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']),
1137 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1138 'MAX_RECIPIENTS' => ($config['allow_mass_pm'] && ($auth->acl_get('u_masspm') || $auth->acl_get('u_masspm_group'))) ? $max_recipients : 0,
1139
1140 'S_COMPOSE_PM' => true,
1141 'S_EDIT_POST' => ($action == 'edit'),
1142 'S_SHOW_PM_ICONS' => $s_pm_icons,
1143 'S_BBCODE_ALLOWED' => ($bbcode_status) ? 1 : 0,
1144 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1145 'S_SMILIES_ALLOWED' => $smilies_status,
1146 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1147 'S_SIG_ALLOWED' => ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig')),
1148 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1149 'S_LINKS_ALLOWED' => $url_status,
1150 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1151 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $action != 'edit') ? true : false,
1152 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $drafts),
1153 'S_FORM_ENCTYPE' => $form_enctype,
1154 'S_ATTACH_DATA' => json_encode($message_parser->attachment_data),
1155
1156 'S_BBCODE_IMG' => $img_status,
1157 'S_BBCODE_FLASH' => $flash_status,
1158 'S_BBCODE_QUOTE' => true,
1159 'S_BBCODE_URL' => $url_status,
1160
1161 'S_POST_ACTION' => $s_action,
1162 'S_HIDDEN_ADDRESS_FIELD' => $s_hidden_address_field,
1163 'S_HIDDEN_FIELDS' => $s_hidden_fields,
1164
1165 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']),
1166 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&mode=popup'),
1167 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&mode=popup')),
1168 ));
1169
1170 // Build custom bbcodes array
1171 display_custom_bbcodes();
1172
1173 // Show attachment box for adding attachments if true
1174 $allowed = ($auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype);
1175
1176 if ($allowed)
1177 {
1178 $max_files = ($auth->acl_gets('a_', 'm_')) ? 0 : (int) $config['max_attachments_pm'];
1179 $plupload->configure($cache, $template, $s_action, false, $max_files);
1180 }
1181
1182 // Attachment entry
1183 posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
1184
1185 // Message History
1186 if ($action == 'reply' || $action == 'quote' || $action == 'forward')
1187 {
1188 if (message_history($msg_id, $user->data['user_id'], $post, array(), true))
1189 {
1190 $template->assign_var('S_DISPLAY_HISTORY', true);
1191 }
1192 }
1193 }
1194
1195 /**
1196 * For composing messages, handle list actions
1197 */
1198 function handle_message_list_actions(&$address_list, &$error, $remove_u, $remove_g, $add_to, $add_bcc)
1199 {
1200 global $auth, $db, $user;
1201 global $request;
1202
1203 // Delete User [TO/BCC]
1204 if ($remove_u && $request->variable('remove_u', array(0 => '')))
1205 {
1206 $remove_user_id = array_keys($request->variable('remove_u', array(0 => '')));
1207
1208 if (isset($remove_user_id[0]))
1209 {
1210 unset($address_list['u'][(int) $remove_user_id[0]]);
1211 }
1212 }
1213
1214 // Delete Group [TO/BCC]
1215 if ($remove_g && $request->variable('remove_g', array(0 => '')))
1216 {
1217 $remove_group_id = array_keys($request->variable('remove_g', array(0 => '')));
1218
1219 if (isset($remove_group_id[0]))
1220 {
1221 unset($address_list['g'][(int) $remove_group_id[0]]);
1222 }
1223 }
1224
1225 // Add Selected Groups
1226 $group_list = request_var('group_list', array(0));
1227
1228 // Build usernames to add
1229 $usernames = request_var('username', '', true);
1230 $usernames = (empty($usernames)) ? array() : array($usernames);
1231
1232 $username_list = request_var('username_list', '', true);
1233 if ($username_list)
1234 {
1235 $usernames = array_merge($usernames, explode("\n", $username_list));
1236 }
1237
1238 // If add to or add bcc not pressed, users could still have usernames listed they want to add...
1239 if (!$add_to && !$add_bcc && (sizeof($group_list) || sizeof($usernames)))
1240 {
1241 $add_to = true;
1242
1243 global $refresh, $submit, $preview;
1244
1245 $refresh = true;
1246 $submit = false;
1247
1248 // Preview is only true if there was also a message entered
1249 if (request_var('message', ''))
1250 {
1251 $preview = true;
1252 }
1253 }
1254
1255 // Add User/Group [TO]
1256 if ($add_to || $add_bcc)
1257 {
1258 $type = ($add_to) ? 'to' : 'bcc';
1259
1260 if (sizeof($group_list))
1261 {
1262 foreach ($group_list as $group_id)
1263 {
1264 $address_list['g'][$group_id] = $type;
1265 }
1266 }
1267
1268 // User ID's to add...
1269 $user_id_ary = array();
1270
1271 // Reveal the correct user_ids
1272 if (sizeof($usernames))
1273 {
1274 $user_id_ary = array();
1275 user_get_id_name($user_id_ary, $usernames, array(USER_NORMAL, USER_FOUNDER, USER_INACTIVE));
1276
1277 // If there are users not existing, we will at least print a notice...
1278 if (!sizeof($user_id_ary))
1279 {
1280 $error[] = $user->lang['PM_NO_USERS'];
1281 }
1282 }
1283
1284 // Add Friends if specified
1285 $friend_list = array_keys($request->variable('add_' . $type, array(0)));
1286 $user_id_ary = array_merge($user_id_ary, $friend_list);
1287
1288 foreach ($user_id_ary as $user_id)
1289 {
1290 if ($user_id == ANONYMOUS)
1291 {
1292 continue;
1293 }
1294
1295 $address_list['u'][$user_id] = $type;
1296 }
1297 }
1298
1299 // Check for disallowed recipients
1300 if (!empty($address_list['u']))
1301 {
1302 $can_ignore_allow_pm = $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_');
1303
1304 // Administrator deactivated users check and we need to check their
1305 // PM status (do they want to receive PM's?)
1306 // Only check PM status if not a moderator or admin, since they
1307 // are allowed to override this user setting
1308 $sql = 'SELECT user_id, user_allow_pm
1309 FROM ' . USERS_TABLE . '
1310 WHERE ' . $db->sql_in_set('user_id', array_keys($address_list['u'])) . '
1311 AND (
1312 (user_type = ' . USER_INACTIVE . '
1313 AND user_inactive_reason = ' . INACTIVE_MANUAL . ')
1314 ' . ($can_ignore_allow_pm ? '' : ' OR user_allow_pm = 0') . '
1315 )';
1316
1317 $result = $db->sql_query($sql);
1318
1319 $removed_no_pm = $removed_no_permission = false;
1320 while ($row = $db->sql_fetchrow($result))
1321 {
1322 if (!$can_ignore_allow_pm && !$row['user_allow_pm'])
1323 {
1324 $removed_no_pm = true;
1325 }
1326 else
1327 {
1328 $removed_no_permission = true;
1329 }
1330
1331 unset($address_list['u'][$row['user_id']]);
1332 }
1333 $db->sql_freeresult($result);
1334
1335 // print a notice about users not being added who do not want to receive pms
1336 if ($removed_no_pm)
1337 {
1338 $error[] = $user->lang['PM_USERS_REMOVED_NO_PM'];
1339 }
1340
1341 // print a notice about users not being added who do not have permission to receive PMs
1342 if ($removed_no_permission)
1343 {
1344 $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION'];
1345 }
1346
1347 if (!sizeof(array_keys($address_list['u'])))
1348 {
1349 return;
1350 }
1351
1352 // Check if users have permission to read PMs
1353 $can_read = $auth->acl_get_list(array_keys($address_list['u']), 'u_readpm');
1354 $can_read = (empty($can_read) || !isset($can_read[0]['u_readpm'])) ? array() : $can_read[0]['u_readpm'];
1355 $cannot_read_list = array_diff(array_keys($address_list['u']), $can_read);
1356 if (!empty($cannot_read_list))
1357 {
1358 foreach ($cannot_read_list as $cannot_read)
1359 {
1360 unset($address_list['u'][$cannot_read]);
1361 }
1362
1363 $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION'];
1364 }
1365
1366 // Check if users are banned
1367 $banned_user_list = phpbb_get_banned_user_ids(array_keys($address_list['u']), false);
1368 if (!empty($banned_user_list))
1369 {
1370 foreach ($banned_user_list as $banned_user)
1371 {
1372 unset($address_list['u'][$banned_user]);
1373 }
1374
1375 $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION'];
1376 }
1377 }
1378 }
1379
1380 /**
1381 * Build the hidden field for the recipients. Needed, as the variable is not read via request_var.
1382 */
1383 function build_address_field($address_list)
1384 {
1385 $s_hidden_address_field = '';
1386 foreach ($address_list as $type => $adr_ary)
1387 {
1388 foreach ($adr_ary as $id => $field)
1389 {
1390 $s_hidden_address_field .= '<input type="hidden" name="address_list[' . (($type == 'u') ? 'u' : 'g') . '][' . (int) $id . ']" value="' . (($field == 'to') ? 'to' : 'bcc') . '" />';
1391 }
1392 }
1393 return $s_hidden_address_field;
1394 }
1395
1396 /**
1397 * Return number of private message recipients
1398 */
1399 function num_recipients($address_list)
1400 {
1401 $num_recipients = 0;
1402
1403 foreach ($address_list as $field => $adr_ary)
1404 {
1405 $num_recipients += sizeof($adr_ary);
1406 }
1407
1408 return $num_recipients;
1409 }
1410
1411 /**
1412 * Get number of 'num_recipients' recipients from first position
1413 */
1414 function get_recipients($address_list, $num_recipients = 1)
1415 {
1416 $recipient = array();
1417
1418 $count = 0;
1419 foreach ($address_list as $field => $adr_ary)
1420 {
1421 foreach ($adr_ary as $id => $type)
1422 {
1423 if ($count >= $num_recipients)
1424 {
1425 break 2;
1426 }
1427 $recipient[$field][$id] = $type;
1428 $count++;
1429 }
1430 }
1431
1432 return $recipient;
1433 }
1434