[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 /** 15 * @ignore 16 */ 17 if (!defined('IN_PHPBB')) 18 { 19 exit; 20 } 21 22 /** 23 * Compose private message 24 * Called from ucp_pm with mode == 'compose' 25 */ 26 function compose_pm($id, $mode, $action, $user_folders = array()) 27 { 28 global $template, $db, $auth, $user, $cache; 29 global $phpbb_root_path, $phpEx, $config; 30 global $request, $phpbb_dispatcher, $phpbb_container; 31 32 // Damn php and globals - i know, this is horrible 33 // Needed for handle_message_list_actions() 34 global $refresh, $submit, $preview; 35 36 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); 37 include($phpbb_root_path . 'includes/functions_display.' . $phpEx); 38 include($phpbb_root_path . 'includes/message_parser.' . $phpEx); 39 40 if (!$action) 41 { 42 $action = 'post'; 43 } 44 add_form_key('ucp_pm_compose'); 45 46 // Grab only parameters needed here 47 $to_user_id = request_var('u', 0); 48 $to_group_id = request_var('g', 0); 49 $msg_id = request_var('p', 0); 50 $draft_id = request_var('d', 0); 51 $lastclick = request_var('lastclick', 0); 52 53 // Reply to all triggered (quote/reply) 54 $reply_to_all = request_var('reply_to_all', 0); 55 56 $address_list = $request->variable('address_list', array('' => array(0 => ''))); 57 58 $preview = (isset($_POST['preview'])) ? true : false; 59 $save = (isset($_POST['save'])) ? true : false; 60 $load = (isset($_POST['load'])) ? true : false; 61 $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; 62 $delete = (isset($_POST['delete'])) ? true : false; 63 64 $remove_u = (isset($_REQUEST['remove_u'])) ? true : false; 65 $remove_g = (isset($_REQUEST['remove_g'])) ? true : false; 66 $add_to = (isset($_REQUEST['add_to'])) ? true : false; 67 $add_bcc = (isset($_REQUEST['add_bcc'])) ? true : false; 68 69 $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || $save || $load 70 || $remove_u || $remove_g || $add_to || $add_bcc; 71 $submit = $request->is_set_post('post') && !$refresh && !$preview; 72 73 $action = ($delete && !$preview && !$refresh && $submit) ? 'delete' : $action; 74 $select_single = ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? false : true; 75 76 $error = array(); 77 $current_time = time(); 78 79 // Was cancel pressed? If so then redirect to the appropriate page 80 if ($cancel || ($current_time - $lastclick < 2 && $submit)) 81 { 82 if ($msg_id) 83 { 84 redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&action=view_message&p=' . $msg_id)); 85 } 86 redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm')); 87 } 88 89 // Since viewtopic.php language entries are used in several modes, 90 // we include the language file here 91 $user->add_lang('viewtopic'); 92 93 /** 94 * Modify the default vars before composing a PM 95 * 96 * @event core.ucp_pm_compose_modify_data 97 * @var int msg_id post_id in the page request 98 * @var int to_user_id The id of whom the message is to 99 * @var int to_group_id The id of the group the message is to 100 * @var bool submit Whether the form has been submitted 101 * @var bool preview Whether the user is previewing the PM or not 102 * @var string action One of: post, reply, quote, forward, quotepost, edit, delete, smilies 103 * @var bool delete Whether the user is deleting the PM 104 * @var int reply_to_all Value of reply_to_all request variable. 105 * @since 3.1.4-RC1 106 */ 107 $vars = array( 108 'msg_id', 109 'to_user_id', 110 'to_group_id', 111 'submit', 112 'preview', 113 'action', 114 'delete', 115 'reply_to_all', 116 ); 117 extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_modify_data', compact($vars))); 118 119 // Output PM_TO box if message composing 120 if ($action != 'edit') 121 { 122 // Add groups to PM box 123 if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) 124 { 125 $sql = 'SELECT g.group_id, g.group_name, g.group_type 126 FROM ' . GROUPS_TABLE . ' g'; 127 128 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) 129 { 130 $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug 131 ON ( 132 g.group_id = ug.group_id 133 AND ug.user_id = ' . $user->data['user_id'] . ' 134 AND ug.user_pending = 0 135 ) 136 WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')'; 137 } 138 139 $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND '; 140 141 $sql .= 'g.group_receive_pm = 1 142 ORDER BY g.group_type DESC, g.group_name ASC'; 143 $result = $db->sql_query($sql); 144 145 $group_options = ''; 146 while ($row = $db->sql_fetchrow($result)) 147 { 148 $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>'; 149 } 150 $db->sql_freeresult($result); 151 } 152 153 $template->assign_vars(array( 154 'S_SHOW_PM_BOX' => true, 155 'S_ALLOW_MASS_PM' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? true : false, 156 'S_GROUP_OPTIONS' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) ? $group_options : '', 157 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&form=postform&field=username_list&select_single=" . (int) $select_single), 158 )); 159 } 160 161 $sql = ''; 162 $folder_id = 0; 163 164 // What is all this following SQL for? Well, we need to know 165 // some basic information in all cases before we do anything. 166 switch ($action) 167 { 168 case 'post': 169 if (!$auth->acl_get('u_sendpm')) 170 { 171 trigger_error('NO_AUTH_SEND_MESSAGE'); 172 } 173 break; 174 175 case 'reply': 176 case 'quote': 177 case 'forward': 178 case 'quotepost': 179 if (!$msg_id) 180 { 181 trigger_error('NO_MESSAGE'); 182 } 183 184 if (!$auth->acl_get('u_sendpm')) 185 { 186 trigger_error('NO_AUTH_SEND_MESSAGE'); 187 } 188 189 if ($action == 'quotepost') 190 { 191 $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 192 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u 193 WHERE p.post_id = $msg_id 194 AND t.topic_id = p.topic_id 195 AND u.user_id = p.poster_id"; 196 } 197 else 198 { 199 $sql = 'SELECT t.folder_id, p.*, u.username as quote_username 200 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u 201 WHERE t.user_id = ' . $user->data['user_id'] . " 202 AND p.author_id = u.user_id 203 AND t.msg_id = p.msg_id 204 AND p.msg_id = $msg_id"; 205 } 206 break; 207 208 case 'edit': 209 if (!$msg_id) 210 { 211 trigger_error('NO_MESSAGE'); 212 } 213 214 // check for outbox (not read) status, we do not allow editing if one user already having the message 215 $sql = 'SELECT p.*, t.folder_id 216 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p 217 WHERE t.user_id = ' . $user->data['user_id'] . ' 218 AND t.folder_id = ' . PRIVMSGS_OUTBOX . " 219 AND t.msg_id = $msg_id 220 AND t.msg_id = p.msg_id"; 221 break; 222 223 case 'delete': 224 if (!$auth->acl_get('u_pm_delete')) 225 { 226 trigger_error('NO_AUTH_DELETE_MESSAGE'); 227 } 228 229 if (!$msg_id) 230 { 231 trigger_error('NO_MESSAGE'); 232 } 233 234 $sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id 235 FROM ' . PRIVMSGS_TO_TABLE . ' 236 WHERE user_id = ' . $user->data['user_id'] . " 237 AND msg_id = $msg_id"; 238 break; 239 240 case 'smilies': 241 generate_smilies('window', 0); 242 break; 243 244 default: 245 trigger_error('NO_ACTION_MODE', E_USER_ERROR); 246 break; 247 } 248 249 if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward'))) 250 { 251 trigger_error('NO_AUTH_FORWARD_MESSAGE'); 252 } 253 254 if ($action == 'edit' && !$auth->acl_get('u_pm_edit')) 255 { 256 trigger_error('NO_AUTH_EDIT_MESSAGE'); 257 } 258 259 if ($sql) 260 { 261 /** 262 * Alter sql query to get message for user to write the PM 263 * 264 * @event core.ucp_pm_compose_compose_pm_basic_info_query_before 265 * @var string sql String with the query to be executed 266 * @var array forum_list List of forums that contain the posts 267 * @var int visibility_const Integer with one of the possible ITEM_* constant values 268 * @var int msg_id topic_id in the page request 269 * @var int to_user_id The id of whom the message is to 270 * @var int to_group_id The id of the group whom the message is to 271 * @var bool submit Whether the user is sending the PM or not 272 * @var bool preview Whether the user is previewing the PM or not 273 * @var string action One of: post, reply, quote, forward, quotepost, edit, delete, smilies 274 * @var bool delete Whether the user is deleting the PM 275 * @var int reply_to_all Value of reply_to_all request variable. 276 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) 277 * @var string sort_order_sql String with the ORDER BY SQL code used in this query 278 * @since 3.1.0-RC5 279 */ 280 $vars = array( 281 'sql', 282 'forum_list', 283 'visibility_const', 284 'msg_id', 285 'to_user_id', 286 'to_group_id', 287 'submit', 288 'preview', 289 'action', 290 'delete', 291 'reply_to_all', 292 'limit_time_sql', 293 'sort_order_sql', 294 ); 295 extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_compose_pm_basic_info_query_before', compact($vars))); 296 297 $result = $db->sql_query($sql); 298 $post = $db->sql_fetchrow($result); 299 $db->sql_freeresult($result); 300 301 if (!$post) 302 { 303 // If editing it could be the recipient already read the message... 304 if ($action == 'edit') 305 { 306 $sql = 'SELECT p.*, t.folder_id 307 FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p 308 WHERE t.user_id = ' . $user->data['user_id'] . " 309 AND t.msg_id = $msg_id 310 AND t.msg_id = p.msg_id"; 311 $result = $db->sql_query($sql); 312 $post = $db->sql_fetchrow($result); 313 $db->sql_freeresult($result); 314 315 if ($post) 316 { 317 trigger_error('NO_EDIT_READ_MESSAGE'); 318 } 319 } 320 321 trigger_error('NO_MESSAGE'); 322 } 323 324 if ($action == 'quotepost') 325 { 326 if (($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id'])) || (!$post['forum_id'] && !$auth->acl_getf_global('f_read'))) 327 { 328 trigger_error('NOT_AUTHORISED'); 329 } 330 331 /** 332 * Get the result of querying for the post to be quoted in the pm message 333 * 334 * @event core.ucp_pm_compose_quotepost_query_after 335 * @var string sql The original SQL used in the query 336 * @var array post Associative array with the data of the quoted post 337 * @var array msg_id The post_id that was searched to get the message for quoting 338 * @var int visibility_const Visibility of the quoted post (one of the possible ITEM_* constant values) 339 * @var int topic_id Topic ID of the quoted post 340 * @var int to_user_id Users the message is sent to 341 * @var int to_group_id Groups the message is sent to 342 * @var bool submit Whether the user is sending the PM or not 343 * @var bool preview Whether the user is previewing the PM or not 344 * @var string action One of: post, reply, quote, forward, quotepost, edit, delete, smilies 345 * @var bool delete If deleting message 346 * @var int reply_to_all Value of reply_to_all request variable. 347 * @since 3.1.0-RC5 348 */ 349 $vars = array( 350 'sql', 351 'post', 352 'msg_id', 353 'visibility_const', 354 'topic_id', 355 'to_user_id', 356 'to_group_id', 357 'submit', 358 'preview', 359 'action', 360 'delete', 361 'reply_to_all', 362 ); 363 extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_quotepost_query_after', compact($vars))); 364 365 // Passworded forum? 366 if ($post['forum_id']) 367 { 368 $sql = 'SELECT forum_id, forum_name, forum_password 369 FROM ' . FORUMS_TABLE . ' 370 WHERE forum_id = ' . (int) $post['forum_id']; 371 $result = $db->sql_query($sql); 372 $forum_data = $db->sql_fetchrow($result); 373 $db->sql_freeresult($result); 374 375 if (!empty($forum_data['forum_password'])) 376 { 377 login_forum_box($forum_data); 378 } 379 } 380 } 381 382 $msg_id = (int) $post['msg_id']; 383 $folder_id = (isset($post['folder_id'])) ? $post['folder_id'] : 0; 384 $message_text = (isset($post['message_text'])) ? $post['message_text'] : ''; 385 386 if ((!$post['author_id'] || ($post['author_id'] == ANONYMOUS && $action != 'delete')) && $msg_id) 387 { 388 trigger_error('NO_AUTHOR'); 389 } 390 391 if ($action == 'quotepost') 392 { 393 // Decode text for message display 394 decode_message($message_text, $post['bbcode_uid']); 395 } 396 397 if ($action != 'delete') 398 { 399 $enable_urls = $post['enable_magic_url']; 400 $enable_sig = (isset($post['enable_sig'])) ? $post['enable_sig'] : 0; 401 402 $message_attachment = (isset($post['message_attachment'])) ? $post['message_attachment'] : 0; 403 $message_subject = $post['message_subject']; 404 $message_time = $post['message_time']; 405 $bbcode_uid = $post['bbcode_uid']; 406 407 $quote_username = (isset($post['quote_username'])) ? $post['quote_username'] : ''; 408 $icon_id = (isset($post['icon_id'])) ? $post['icon_id'] : 0; 409 410 if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview) 411 { 412 // Add the original author as the recipient if quoting a post or only replying and not having checked "reply to all" 413 if ($action == 'quotepost' || !$reply_to_all) 414 { 415 $address_list = array('u' => array($post['author_id'] => 'to')); 416 } 417 else 418 { 419 // We try to include every previously listed member from the TO Header - Reply to all 420 $address_list = rebuild_header(array('to' => $post['to_address'])); 421 422 // Add the author (if he is already listed then this is no shame (it will be overwritten)) 423 $address_list['u'][$post['author_id']] = 'to'; 424 425 // Now, make sure the user itself is not listed. ;) 426 if (isset($address_list['u'][$user->data['user_id']])) 427 { 428 unset($address_list['u'][$user->data['user_id']]); 429 } 430 } 431 } 432 else if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview) 433 { 434 // Rebuild TO and BCC Header 435 $address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address'])); 436 } 437 438 if ($action == 'quotepost') 439 { 440 $check_value = 0; 441 } 442 else 443 { 444 $check_value = (($post['enable_bbcode']+1) << 8) + (($post['enable_smilies']+1) << 4) + (($enable_urls+1) << 2) + (($post['enable_sig']+1) << 1); 445 } 446 } 447 } 448 else 449 { 450 $message_attachment = 0; 451 $message_text = $message_subject = ''; 452 453 /** 454 * Predefine message text and subject 455 * 456 * @event core.ucp_pm_compose_predefined_message 457 * @var string message_text Message text 458 * @var string message_subject Messate subject 459 * @since 3.1.11-RC1 460 */ 461 $vars = array('message_text', 'message_subject'); 462 extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_predefined_message', compact($vars))); 463 464 if ($to_user_id && $to_user_id != ANONYMOUS && $action == 'post') 465 { 466 $address_list['u'][$to_user_id] = 'to'; 467 } 468 else if ($to_group_id && $action == 'post') 469 { 470 $address_list['g'][$to_group_id] = 'to'; 471 } 472 $check_value = 0; 473 } 474 475 if (($to_group_id || isset($address_list['g'])) && (!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group'))) 476 { 477 trigger_error('NO_AUTH_GROUP_MESSAGE'); 478 } 479 480 if ($action == 'edit' && !$refresh && !$preview && !$submit) 481 { 482 if (!($message_time > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time'])) 483 { 484 trigger_error('CANNOT_EDIT_MESSAGE_TIME'); 485 } 486 } 487 488 if ($action == 'post') 489 { 490 $template->assign_var('S_NEW_MESSAGE', true); 491 } 492 493 if (!isset($icon_id)) 494 { 495 $icon_id = 0; 496 } 497 498 $message_parser = new parse_message(); 499 $plupload = $phpbb_container->get('plupload'); 500 $message_parser->set_plupload($plupload); 501 502 $message_parser->message = ($action == 'reply') ? '' : $message_text; 503 unset($message_text); 504 505 $s_action = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=$mode&action=$action", true, $user->session_id); 506 $s_action .= (($folder_id) ? "&f=$folder_id" : '') . (($msg_id) ? "&p=$msg_id" : ''); 507 508 // Delete triggered ? 509 if ($action == 'delete') 510 { 511 // Folder id has been determined by the SQL Statement 512 // $folder_id = request_var('f', PRIVMSGS_NO_BOX); 513 514 // Do we need to confirm ? 515 if (confirm_box(true)) 516 { 517 delete_pm($user->data['user_id'], $msg_id, $folder_id); 518 519 // jump to next message in "history"? nope, not for the moment. But able to be included later. 520 $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&folder=$folder_id"); 521 $message = $user->lang['MESSAGE_DELETED']; 522 523 meta_refresh(3, $meta_info); 524 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>'); 525 trigger_error($message); 526 } 527 else 528 { 529 $s_hidden_fields = array( 530 'p' => $msg_id, 531 'f' => $folder_id, 532 'action' => 'delete' 533 ); 534 535 // "{$phpbb_root_path}ucp.$phpEx?i=pm&mode=compose" 536 confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields)); 537 } 538 539 redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&action=view_message&p=' . $msg_id)); 540 } 541 542 // Get maximum number of allowed recipients 543 $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients 544 FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug 545 WHERE ug.user_id = ' . $user->data['user_id'] . ' 546 AND ug.user_pending = 0 547 AND ug.group_id = g.group_id'; 548 $result = $db->sql_query($sql); 549 $max_recipients = (int) $db->sql_fetchfield('max_recipients'); 550 $db->sql_freeresult($result); 551 552 $max_recipients = (!$max_recipients) ? $config['pm_max_recipients'] : $max_recipients; 553 554 // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients 555 if (($action == 'reply' || $action == 'quote') && $max_recipients && $reply_to_all) 556 { 557 // We try to include every previously listed member from the TO Header 558 $list = rebuild_header(array('to' => $post['to_address'])); 559 560 // Can be an empty array too ;) 561 $list = (!empty($list['u'])) ? $list['u'] : array(); 562 $list[$post['author_id']] = 'to'; 563 564 if (isset($list[$user->data['user_id']])) 565 { 566 unset($list[$user->data['user_id']]); 567 } 568 569 $max_recipients = ($max_recipients < sizeof($list)) ? sizeof($list) : $max_recipients; 570 571 unset($list); 572 } 573 574 // Handle User/Group adding/removing 575 handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc); 576 577 // Check mass pm to group permission 578 if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')) && !empty($address_list['g'])) 579 { 580 $address_list = array(); 581 $error[] = $user->lang['NO_AUTH_GROUP_MESSAGE']; 582 } 583 584 // Check mass pm to users permission 585 if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1) 586 { 587 $address_list = get_recipients($address_list, 1); 588 $error[] = $user->lang('TOO_MANY_RECIPIENTS', 1); 589 } 590 591 // Check for too many recipients 592 if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients) 593 { 594 $address_list = get_recipients($address_list, $max_recipients); 595 $error[] = $user->lang('TOO_MANY_RECIPIENTS', $max_recipients); 596 } 597 598 // Always check if the submitted attachment data is valid and belongs to the user. 599 // Further down (especially in submit_post()) we do not check this again. 600 $message_parser->get_submitted_attachment_data(); 601 602 if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit') 603 { 604 // Do not change to SELECT * 605 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename, filesize 606 FROM ' . ATTACHMENTS_TABLE . " 607 WHERE post_msg_id = $msg_id 608 AND in_message = 1 609 AND is_orphan = 0 610 ORDER BY filetime DESC"; 611 $result = $db->sql_query($sql); 612 $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result)); 613 $db->sql_freeresult($result); 614 } 615 616 if (!in_array($action, array('quote', 'edit', 'delete', 'forward'))) 617 { 618 $enable_sig = ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig')); 619 $enable_smilies = ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies')); 620 $enable_bbcode = ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode')); 621 $enable_urls = true; 622 } 623 624 $enable_magic_url = $drafts = false; 625 626 // User own some drafts? 627 if ($auth->acl_get('u_savedrafts') && $action != 'delete') 628 { 629 $sql = 'SELECT draft_id 630 FROM ' . DRAFTS_TABLE . ' 631 WHERE forum_id = 0 632 AND topic_id = 0 633 AND user_id = ' . $user->data['user_id'] . 634 (($draft_id) ? " AND draft_id <> $draft_id" : ''); 635 $result = $db->sql_query_limit($sql, 1); 636 $row = $db->sql_fetchrow($result); 637 $db->sql_freeresult($result); 638 639 if ($row) 640 { 641 $drafts = true; 642 } 643 } 644 645 if ($action == 'edit') 646 { 647 $message_parser->bbcode_uid = $bbcode_uid; 648 } 649 650 $bbcode_status = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false; 651 $smilies_status = ($config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies')) ? true : false; 652 $img_status = ($config['auth_img_pm'] && $auth->acl_get('u_pm_img')) ? true : false; 653 $flash_status = ($config['auth_flash_pm'] && $auth->acl_get('u_pm_flash')) ? true : false; 654 $url_status = ($config['allow_post_links']) ? true : false; 655 656 // Save Draft 657 if ($save && $auth->acl_get('u_savedrafts')) 658 { 659 $subject = utf8_normalize_nfc(request_var('subject', '', true)); 660 $subject = (!$subject && $action != 'post') ? $user->lang['NEW_MESSAGE'] : $subject; 661 $message = utf8_normalize_nfc(request_var('message', '', true)); 662 663 if ($subject && $message) 664 { 665 if (confirm_box(true)) 666 { 667 $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( 668 'user_id' => $user->data['user_id'], 669 'topic_id' => 0, 670 'forum_id' => 0, 671 'save_time' => $current_time, 672 'draft_subject' => $subject, 673 'draft_message' => $message 674 ) 675 ); 676 $db->sql_query($sql); 677 678 $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=$mode"); 679 680 meta_refresh(3, $redirect_url); 681 $message = $user->lang['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); 682 683 trigger_error($message); 684 } 685 else 686 { 687 $s_hidden_fields = build_hidden_fields(array( 688 'mode' => $mode, 689 'action' => $action, 690 'save' => true, 691 'subject' => $subject, 692 'message' => $message, 693 'u' => $to_user_id, 694 'g' => $to_group_id, 695 'p' => $msg_id) 696 ); 697 $s_hidden_fields .= build_address_field($address_list); 698 699 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields); 700 } 701 } 702 else 703 { 704 if (utf8_clean_string($subject) === '') 705 { 706 $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT']; 707 } 708 709 if (utf8_clean_string($message) === '') 710 { 711 $error[] = $user->lang['TOO_FEW_CHARS']; 712 } 713 } 714 715 unset($subject, $message); 716 } 717 718 // Load Draft 719 if ($draft_id && $auth->acl_get('u_savedrafts')) 720 { 721 $sql = 'SELECT draft_subject, draft_message 722 FROM ' . DRAFTS_TABLE . " 723 WHERE draft_id = $draft_id 724 AND topic_id = 0 725 AND forum_id = 0 726 AND user_id = " . $user->data['user_id']; 727 $result = $db->sql_query_limit($sql, 1); 728 729 if ($row = $db->sql_fetchrow($result)) 730 { 731 $message_parser->message = $row['draft_message']; 732 $message_subject = $row['draft_subject']; 733 734 $template->assign_var('S_DRAFT_LOADED', true); 735 } 736 else 737 { 738 $draft_id = 0; 739 } 740 $db->sql_freeresult($result); 741 } 742 743 // Load Drafts 744 if ($load && $drafts) 745 { 746 load_drafts(0, 0, $id, $action, $msg_id); 747 } 748 749 if ($submit || $preview || $refresh) 750 { 751 if (($submit || $preview) && !check_form_key('ucp_pm_compose')) 752 { 753 $error[] = $user->lang['FORM_INVALID']; 754 } 755 $subject = utf8_normalize_nfc(request_var('subject', '', true)); 756 $message_parser->message = utf8_normalize_nfc(request_var('message', '', true)); 757 758 $icon_id = request_var('icon', 0); 759 760 $enable_bbcode = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true; 761 $enable_smilies = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true; 762 $enable_urls = (isset($_POST['disable_magic_url'])) ? 0 : 1; 763 $enable_sig = (!$config['allow_sig'] ||!$config['allow_sig_pm']) ? false : ((isset($_POST['attach_sig'])) ? true : false); 764 765 /** 766 * Modify private message 767 * 768 * @event core.ucp_pm_compose_modify_parse_before 769 * @var bool enable_bbcode Whether or not bbcode is enabled 770 * @var bool enable_smilies Whether or not smilies are enabled 771 * @var bool enable_urls Whether or not urls are enabled 772 * @var bool enable_sig Whether or not signature is enabled 773 * @var string subject PM subject text 774 * @var object message_parser The message parser object 775 * @var bool submit Whether or not the form has been sumitted 776 * @var bool preview Whether or not the signature is being previewed 777 * @var array error Any error strings 778 * @since 3.1.10-RC1 779 */ 780 $vars = array( 781 'enable_bbcode', 782 'enable_smilies', 783 'enable_urls', 784 'enable_sig', 785 'subject', 786 'message_parser', 787 'submit', 788 'preview', 789 'error', 790 ); 791 extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_modify_parse_before', compact($vars))); 792 793 if ($submit) 794 { 795 $status_switch = (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); 796 $status_switch = ($status_switch != $check_value); 797 } 798 else 799 { 800 $status_switch = 1; 801 } 802 803 // Parse Attachments - before checksum is calculated 804 $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true); 805 806 if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc)) 807 { 808 $error[] = implode('<br />', $message_parser->warn_msg); 809 $message_parser->warn_msg = array(); 810 } 811 812 // Parse message 813 $message_parser->parse($enable_bbcode, ($config['allow_post_links']) ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']); 814 815 // On a refresh we do not care about message parsing errors 816 if (sizeof($message_parser->warn_msg) && !$refresh) 817 { 818 $error[] = implode('<br />', $message_parser->warn_msg); 819 } 820 821 if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood')) 822 { 823 // Flood check 824 $last_post_time = $user->data['user_lastpost_time']; 825 826 if ($last_post_time) 827 { 828 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval'])) 829 { 830 $error[] = $user->lang['FLOOD_ERROR']; 831 } 832 } 833 } 834 835 // Subject defined 836 if ($submit) 837 { 838 if (utf8_clean_string($subject) === '') 839 { 840 $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT']; 841 } 842 843 if (!sizeof($address_list)) 844 { 845 $error[] = $user->lang['NO_RECIPIENT']; 846 } 847 } 848 849 // Store message, sync counters 850 if (!sizeof($error) && $submit) 851 { 852 $pm_data = array( 853 'msg_id' => (int) $msg_id, 854 'from_user_id' => $user->data['user_id'], 855 'from_user_ip' => $user->ip, 856 'from_username' => $user->data['username'], 857 'reply_from_root_level' => (isset($post['root_level'])) ? (int) $post['root_level'] : 0, 858 'reply_from_msg_id' => (int) $msg_id, 859 'icon_id' => (int) $icon_id, 860 'enable_sig' => (bool) $enable_sig, 861 'enable_bbcode' => (bool) $enable_bbcode, 862 'enable_smilies' => (bool) $enable_smilies, 863 'enable_urls' => (bool) $enable_urls, 864 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 865 'bbcode_uid' => $message_parser->bbcode_uid, 866 'message' => $message_parser->message, 867 'attachment_data' => $message_parser->attachment_data, 868 'filename_data' => $message_parser->filename_data, 869 'address_list' => $address_list 870 ); 871 872 // ((!$message_subject) ? $subject : $message_subject) 873 $msg_id = submit_pm($action, $subject, $pm_data); 874 875 $return_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&p=' . $msg_id); 876 $inbox_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'); 877 $outbox_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=outbox'); 878 879 $folder_url = ''; 880 if (($folder_id > 0) && isset($user_folders[$folder_id])) 881 { 882 $folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=' . $folder_id); 883 } 884 885 $return_box_url = ($action === 'post' || $action === 'edit') ? $outbox_folder_url : $inbox_folder_url; 886 $return_box_lang = ($action === 'post' || $action === 'edit') ? 'PM_OUTBOX' : 'PM_INBOX'; 887 888 $save_message = ($action === 'edit') ? $user->lang['MESSAGE_EDITED'] : $user->lang['MESSAGE_STORED']; 889 $message = $save_message . '<br /><br />' . $user->lang('VIEW_PRIVATE_MESSAGE', '<a href="' . $return_message_url . '">', '</a>'); 890 891 $last_click_type = 'CLICK_RETURN_FOLDER'; 892 if ($folder_url) 893 { 894 $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $folder_url . '">', '</a>', $user_folders[$folder_id]['folder_name']); 895 $last_click_type = 'CLICK_GOTO_FOLDER'; 896 } 897 $message .= '<br /><br />' . sprintf($user->lang[$last_click_type], '<a href="' . $return_box_url . '">', '</a>', $user->lang[$return_box_lang]); 898 899 meta_refresh(3, $return_message_url); 900 trigger_error($message); 901 } 902 903 $message_subject = $subject; 904 } 905 906 // Preview 907 if (!sizeof($error) && $preview) 908 { 909 $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false); 910 911 $preview_signature = $user->data['user_sig']; 912 $preview_signature_uid = $user->data['user_sig_bbcode_uid']; 913 $preview_signature_bitfield = $user->data['user_sig_bbcode_bitfield']; 914 915 // Signature 916 if ($enable_sig && $config['allow_sig'] && $preview_signature) 917 { 918 $parse_sig = new parse_message($preview_signature); 919 $parse_sig->bbcode_uid = $preview_signature_uid; 920 $parse_sig->bbcode_bitfield = $preview_signature_bitfield; 921 922 $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']); 923 $preview_signature = $parse_sig->message; 924 unset($parse_sig); 925 } 926 else 927 { 928 $preview_signature = ''; 929 } 930 931 // Attachment Preview 932 if (sizeof($message_parser->attachment_data)) 933 { 934 $template->assign_var('S_HAS_ATTACHMENTS', true); 935 936 $update_count = array(); 937 $attachment_data = $message_parser->attachment_data; 938 939 parse_attachments(false, $preview_message, $attachment_data, $update_count, true); 940 941 foreach ($attachment_data as $i => $attachment) 942 { 943 $template->assign_block_vars('attachment', array( 944 'DISPLAY_ATTACHMENT' => $attachment) 945 ); 946 } 947 unset($attachment_data); 948 } 949 950 $preview_subject = censor_text($subject); 951 952 if (!sizeof($error)) 953 { 954 $template->assign_vars(array( 955 'PREVIEW_SUBJECT' => $preview_subject, 956 'PREVIEW_MESSAGE' => $preview_message, 957 'PREVIEW_SIGNATURE' => $preview_signature, 958 959 'S_DISPLAY_PREVIEW' => true) 960 ); 961 } 962 unset($message_text); 963 } 964 965 // Decode text for message display 966 $bbcode_uid = (($action == 'quote' || $action == 'forward') && !$preview && !$refresh && (!sizeof($error) || (sizeof($error) && !$submit))) ? $bbcode_uid : $message_parser->bbcode_uid; 967 968 $message_parser->decode_message($bbcode_uid); 969 970 if (($action == 'quote' || $action == 'quotepost') && !$preview && !$refresh && !$submit) 971 { 972 if ($action == 'quotepost') 973 { 974 $post_id = request_var('p', 0); 975 if ($config['allow_post_links']) 976 { 977 $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"; 978 } 979 else 980 { 981 $message_link = $user->lang['SUBJECT'] . $user->lang['COLON'] . ' ' . $message_subject . " (" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id})\n\n"; 982 } 983 } 984 else 985 { 986 $message_link = ''; 987 } 988 $message_parser->message = $message_link . '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n"; 989 } 990 991 if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh) 992 { 993 $message_subject = ((!preg_match('/^Re:/', $message_subject)) ? 'Re: ' : '') . censor_text($message_subject); 994 } 995 996 if ($action == 'forward' && !$preview && !$refresh && !$submit) 997 { 998 $fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true); 999 1000 if ($config['allow_post_links']) 1001 { 1002 $quote_username_text = '[url=' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$post['author_id']}]{$quote_username}[/url]"; 1003 } 1004 else 1005 { 1006 $quote_username_text = $quote_username . ' (' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$post['author_id']})"; 1007 } 1008 1009 $forward_text = array(); 1010 $forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE']; 1011 $forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject)); 1012 $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time, false, true)); 1013 $forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text); 1014 $forward_text[] = sprintf($user->lang['FWD_TO'], implode($user->lang['COMMA_SEPARATOR'], $fwd_to_field['to'])); 1015 1016 $message_parser->message = implode("\n", $forward_text) . "\n\n[quote="{$quote_username}"]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]"; 1017 $message_subject = ((!preg_match('/^Fwd:/', $message_subject)) ? 'Fwd: ' : '') . censor_text($message_subject); 1018 } 1019 1020 $attachment_data = $message_parser->attachment_data; 1021 $filename_data = $message_parser->filename_data; 1022 $message_text = $message_parser->message; 1023 1024 // MAIN PM PAGE BEGINS HERE 1025 1026 // Generate smiley listing 1027 generate_smilies('inline', 0); 1028 1029 // Generate PM Icons 1030 $s_pm_icons = false; 1031 if ($config['enable_pm_icons']) 1032 { 1033 $s_pm_icons = posting_gen_topic_icons($action, $icon_id); 1034 } 1035 1036 // Generate inline attachment select box 1037 posting_gen_inline_attachments($attachment_data); 1038 1039 // Build address list for display 1040 // array('u' => array($author_id => 'to')); 1041 if (sizeof($address_list)) 1042 { 1043 // Get Usernames and Group Names 1044 $result = array(); 1045 if (!empty($address_list['u'])) 1046 { 1047 $sql = 'SELECT user_id as id, username as name, user_colour as colour 1048 FROM ' . USERS_TABLE . ' 1049 WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . ' 1050 ORDER BY username_clean ASC'; 1051 $result['u'] = $db->sql_query($sql); 1052 } 1053 1054 if (!empty($address_list['g'])) 1055 { 1056 $sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type 1057 FROM ' . GROUPS_TABLE . ' g'; 1058 1059 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) 1060 { 1061 $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug 1062 ON ( 1063 g.group_id = ug.group_id 1064 AND ug.user_id = ' . $user->data['user_id'] . ' 1065 AND ug.user_pending = 0 1066 ) 1067 WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')'; 1068 } 1069 1070 $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND '; 1071 1072 $sql .= 'g.group_receive_pm = 1 1073 AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . ' 1074 ORDER BY g.group_name ASC'; 1075 1076 $result['g'] = $db->sql_query($sql); 1077 } 1078 1079 $u = $g = array(); 1080 $_types = array('u', 'g'); 1081 foreach ($_types as $type) 1082 { 1083 if (isset($result[$type]) && $result[$type]) 1084 { 1085 while ($row = $db->sql_fetchrow($result[$type])) 1086 { 1087 if ($type == 'g') 1088 { 1089 $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name']; 1090 } 1091 1092 ${$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']); 1093 } 1094 $db->sql_freeresult($result[$type]); 1095 } 1096 } 1097 1098 // Now Build the address list 1099 $plain_address_field = ''; 1100 foreach ($address_list as $type => $adr_ary) 1101 { 1102 foreach ($adr_ary as $id => $field) 1103 { 1104 if (!isset(${$type}[$id])) 1105 { 1106 unset($address_list[$type][$id]); 1107 continue; 1108 } 1109 1110 $field = ($field == 'to') ? 'to' : 'bcc'; 1111 $type = ($type == 'u') ? 'u' : 'g'; 1112 $id = (int) $id; 1113 1114 $tpl_ary = array( 1115 'IS_GROUP' => ($type == 'g') ? true : false, 1116 'IS_USER' => ($type == 'u') ? true : false, 1117 'UG_ID' => $id, 1118 'NAME' => ${$type}[$id]['name'], 1119 'COLOUR' => (${$type}[$id]['colour']) ? '#' . ${$type}[$id]['colour'] : '', 1120 'TYPE' => $type, 1121 ); 1122 1123 if ($type == 'u') 1124 { 1125 $tpl_ary = array_merge($tpl_ary, array( 1126 'U_VIEW' => get_username_string('profile', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']), 1127 'NAME_FULL' => get_username_string('full', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']), 1128 )); 1129 } 1130 else 1131 { 1132 $tpl_ary = array_merge($tpl_ary, array( 1133 'U_VIEW' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $id), 1134 )); 1135 } 1136 1137 $template->assign_block_vars($field . '_recipient', $tpl_ary); 1138 } 1139 } 1140 } 1141 1142 // Build hidden address list 1143 $s_hidden_address_field = build_address_field($address_list); 1144 1145 $bbcode_checked = (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode')) ? !$user->optionget('bbcode') : 1); 1146 $smilies_checked = (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies'] && $auth->acl_get('u_pm_smilies')) ? !$user->optionget('smilies') : 1); 1147 $urls_checked = (isset($enable_urls)) ? !$enable_urls : 0; 1148 $sig_checked = $enable_sig; 1149 1150 switch ($action) 1151 { 1152 case 'post': 1153 $page_title = $user->lang['POST_NEW_PM']; 1154 break; 1155 1156 case 'quote': 1157 $page_title = $user->lang['POST_QUOTE_PM']; 1158 break; 1159 1160 case 'quotepost': 1161 $page_title = $user->lang['POST_PM_POST']; 1162 break; 1163 1164 case 'reply': 1165 $page_title = $user->lang['POST_REPLY_PM']; 1166 break; 1167 1168 case 'edit': 1169 $page_title = $user->lang['POST_EDIT_PM']; 1170 break; 1171 1172 case 'forward': 1173 $page_title = $user->lang['POST_FORWARD_PM']; 1174 break; 1175 1176 default: 1177 trigger_error('NO_ACTION_MODE', E_USER_ERROR); 1178 break; 1179 } 1180 1181 $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />'; 1182 $s_hidden_fields .= (isset($check_value)) ? '<input type="hidden" name="status_switch" value="' . $check_value . '" />' : ''; 1183 $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) . '" />' : ''; 1184 1185 $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"'; 1186 1187 // Start assigning vars for main posting page ... 1188 $template->assign_vars(array( 1189 'L_POST_A' => $page_title, 1190 'L_ICON' => $user->lang['PM_ICON'], 1191 'L_MESSAGE_BODY_EXPLAIN' => $user->lang('MESSAGE_BODY_EXPLAIN', (int) $config['max_post_chars']), 1192 1193 'SUBJECT' => (isset($message_subject)) ? $message_subject : '', 1194 'MESSAGE' => $message_text, 1195 '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>'), 1196 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 1197 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 1198 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 1199 'URL_STATUS' => ($url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 1200 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'], 1201 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']), 1202 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', 1203 'MAX_RECIPIENTS' => ($config['allow_mass_pm'] && ($auth->acl_get('u_masspm') || $auth->acl_get('u_masspm_group'))) ? $max_recipients : 0, 1204 1205 'S_COMPOSE_PM' => true, 1206 'S_EDIT_POST' => ($action == 'edit'), 1207 'S_SHOW_PM_ICONS' => $s_pm_icons, 1208 'S_BBCODE_ALLOWED' => ($bbcode_status) ? 1 : 0, 1209 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '', 1210 'S_SMILIES_ALLOWED' => $smilies_status, 1211 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '', 1212 'S_SIG_ALLOWED' => ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig')), 1213 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '', 1214 'S_LINKS_ALLOWED' => $url_status, 1215 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', 1216 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $action != 'edit') ? true : false, 1217 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $drafts), 1218 'S_FORM_ENCTYPE' => $form_enctype, 1219 'S_ATTACH_DATA' => json_encode($message_parser->attachment_data), 1220 1221 'S_BBCODE_IMG' => $img_status, 1222 'S_BBCODE_FLASH' => $flash_status, 1223 'S_BBCODE_QUOTE' => true, 1224 'S_BBCODE_URL' => $url_status, 1225 1226 'S_POST_ACTION' => $s_action, 1227 'S_HIDDEN_ADDRESS_FIELD' => $s_hidden_address_field, 1228 'S_HIDDEN_FIELDS' => $s_hidden_fields, 1229 1230 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']), 1231 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&mode=popup'), 1232 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&mode=popup')), 1233 )); 1234 1235 // Build custom bbcodes array 1236 display_custom_bbcodes(); 1237 1238 // Show attachment box for adding attachments if true 1239 $allowed = ($auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype); 1240 1241 if ($allowed) 1242 { 1243 $max_files = ($auth->acl_gets('a_', 'm_')) ? 0 : (int) $config['max_attachments_pm']; 1244 $plupload->configure($cache, $template, $s_action, false, $max_files); 1245 } 1246 1247 // Attachment entry 1248 posting_gen_attachment_entry($attachment_data, $filename_data, $allowed); 1249 1250 // Message History 1251 if ($action == 'reply' || $action == 'quote' || $action == 'forward') 1252 { 1253 if (message_history($msg_id, $user->data['user_id'], $post, array(), true)) 1254 { 1255 $template->assign_var('S_DISPLAY_HISTORY', true); 1256 } 1257 } 1258 } 1259 1260 /** 1261 * For composing messages, handle list actions 1262 */ 1263 function handle_message_list_actions(&$address_list, &$error, $remove_u, $remove_g, $add_to, $add_bcc) 1264 { 1265 global $auth, $db, $user; 1266 global $request; 1267 1268 // Delete User [TO/BCC] 1269 if ($remove_u && $request->variable('remove_u', array(0 => ''))) 1270 { 1271 $remove_user_id = array_keys($request->variable('remove_u', array(0 => ''))); 1272 1273 if (isset($remove_user_id[0])) 1274 { 1275 unset($address_list['u'][(int) $remove_user_id[0]]); 1276 } 1277 } 1278 1279 // Delete Group [TO/BCC] 1280 if ($remove_g && $request->variable('remove_g', array(0 => ''))) 1281 { 1282 $remove_group_id = array_keys($request->variable('remove_g', array(0 => ''))); 1283 1284 if (isset($remove_group_id[0])) 1285 { 1286 unset($address_list['g'][(int) $remove_group_id[0]]); 1287 } 1288 } 1289 1290 // Add Selected Groups 1291 $group_list = request_var('group_list', array(0)); 1292 1293 // Build usernames to add 1294 $usernames = request_var('username', '', true); 1295 $usernames = (empty($usernames)) ? array() : array($usernames); 1296 1297 $username_list = request_var('username_list', '', true); 1298 if ($username_list) 1299 { 1300 $usernames = array_merge($usernames, explode("\n", $username_list)); 1301 } 1302 1303 // If add to or add bcc not pressed, users could still have usernames listed they want to add... 1304 if (!$add_to && !$add_bcc && (sizeof($group_list) || sizeof($usernames))) 1305 { 1306 $add_to = true; 1307 1308 global $refresh, $submit, $preview; 1309 1310 $refresh = true; 1311 $submit = false; 1312 1313 // Preview is only true if there was also a message entered 1314 if (request_var('message', '')) 1315 { 1316 $preview = true; 1317 } 1318 } 1319 1320 // Add User/Group [TO] 1321 if ($add_to || $add_bcc) 1322 { 1323 $type = ($add_to) ? 'to' : 'bcc'; 1324 1325 if (sizeof($group_list)) 1326 { 1327 foreach ($group_list as $group_id) 1328 { 1329 $address_list['g'][$group_id] = $type; 1330 } 1331 } 1332 1333 // User ID's to add... 1334 $user_id_ary = array(); 1335 1336 // Reveal the correct user_ids 1337 if (sizeof($usernames)) 1338 { 1339 $user_id_ary = array(); 1340 user_get_id_name($user_id_ary, $usernames, array(USER_NORMAL, USER_FOUNDER, USER_INACTIVE)); 1341 1342 // If there are users not existing, we will at least print a notice... 1343 if (!sizeof($user_id_ary)) 1344 { 1345 $error[] = $user->lang['PM_NO_USERS']; 1346 } 1347 } 1348 1349 // Add Friends if specified 1350 $friend_list = array_keys($request->variable('add_' . $type, array(0))); 1351 $user_id_ary = array_merge($user_id_ary, $friend_list); 1352 1353 foreach ($user_id_ary as $user_id) 1354 { 1355 if ($user_id == ANONYMOUS) 1356 { 1357 continue; 1358 } 1359 1360 $address_list['u'][$user_id] = $type; 1361 } 1362 } 1363 1364 // Check for disallowed recipients 1365 if (!empty($address_list['u'])) 1366 { 1367 $can_ignore_allow_pm = $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'); 1368 1369 // Administrator deactivated users check and we need to check their 1370 // PM status (do they want to receive PM's?) 1371 // Only check PM status if not a moderator or admin, since they 1372 // are allowed to override this user setting 1373 $sql = 'SELECT user_id, user_allow_pm 1374 FROM ' . USERS_TABLE . ' 1375 WHERE ' . $db->sql_in_set('user_id', array_keys($address_list['u'])) . ' 1376 AND ( 1377 (user_type = ' . USER_INACTIVE . ' 1378 AND user_inactive_reason = ' . INACTIVE_MANUAL . ') 1379 ' . ($can_ignore_allow_pm ? '' : ' OR user_allow_pm = 0') . ' 1380 )'; 1381 1382 $result = $db->sql_query($sql); 1383 1384 $removed_no_pm = $removed_no_permission = false; 1385 while ($row = $db->sql_fetchrow($result)) 1386 { 1387 if (!$can_ignore_allow_pm && !$row['user_allow_pm']) 1388 { 1389 $removed_no_pm = true; 1390 } 1391 else 1392 { 1393 $removed_no_permission = true; 1394 } 1395 1396 unset($address_list['u'][$row['user_id']]); 1397 } 1398 $db->sql_freeresult($result); 1399 1400 // print a notice about users not being added who do not want to receive pms 1401 if ($removed_no_pm) 1402 { 1403 $error[] = $user->lang['PM_USERS_REMOVED_NO_PM']; 1404 } 1405 1406 // print a notice about users not being added who do not have permission to receive PMs 1407 if ($removed_no_permission) 1408 { 1409 $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION']; 1410 } 1411 1412 if (!sizeof(array_keys($address_list['u']))) 1413 { 1414 return; 1415 } 1416 1417 // Check if users have permission to read PMs 1418 $can_read = $auth->acl_get_list(array_keys($address_list['u']), 'u_readpm'); 1419 $can_read = (empty($can_read) || !isset($can_read[0]['u_readpm'])) ? array() : $can_read[0]['u_readpm']; 1420 $cannot_read_list = array_diff(array_keys($address_list['u']), $can_read); 1421 if (!empty($cannot_read_list)) 1422 { 1423 foreach ($cannot_read_list as $cannot_read) 1424 { 1425 unset($address_list['u'][$cannot_read]); 1426 } 1427 1428 $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION']; 1429 } 1430 1431 // Check if users are banned 1432 $banned_user_list = phpbb_get_banned_user_ids(array_keys($address_list['u']), false); 1433 if (!empty($banned_user_list)) 1434 { 1435 foreach ($banned_user_list as $banned_user) 1436 { 1437 unset($address_list['u'][$banned_user]); 1438 } 1439 1440 $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION']; 1441 } 1442 } 1443 } 1444 1445 /** 1446 * Build the hidden field for the recipients. Needed, as the variable is not read via request_var. 1447 */ 1448 function build_address_field($address_list) 1449 { 1450 $s_hidden_address_field = ''; 1451 foreach ($address_list as $type => $adr_ary) 1452 { 1453 foreach ($adr_ary as $id => $field) 1454 { 1455 $s_hidden_address_field .= '<input type="hidden" name="address_list[' . (($type == 'u') ? 'u' : 'g') . '][' . (int) $id . ']" value="' . (($field == 'to') ? 'to' : 'bcc') . '" />'; 1456 } 1457 } 1458 return $s_hidden_address_field; 1459 } 1460 1461 /** 1462 * Return number of private message recipients 1463 */ 1464 function num_recipients($address_list) 1465 { 1466 $num_recipients = 0; 1467 1468 foreach ($address_list as $field => $adr_ary) 1469 { 1470 $num_recipients += sizeof($adr_ary); 1471 } 1472 1473 return $num_recipients; 1474 } 1475 1476 /** 1477 * Get number of 'num_recipients' recipients from first position 1478 */ 1479 function get_recipients($address_list, $num_recipients = 1) 1480 { 1481 $recipient = array(); 1482 1483 $count = 0; 1484 foreach ($address_list as $field => $adr_ary) 1485 { 1486 foreach ($adr_ary as $id => $type) 1487 { 1488 if ($count >= $num_recipients) 1489 { 1490 break 2; 1491 } 1492 $recipient[$field][$id] = $type; 1493 $count++; 1494 } 1495 } 1496 1497 return $recipient; 1498 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |