Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ucp_pm_compose.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 46.57 KiB


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