[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/includes/ucp/ -> ucp_pm_viewmessage.php (source)

   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  * View private message
  24  */
  25  function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
  26  {
  27      global $user, $template, $auth, $db, $phpbb_container;
  28      global $phpbb_root_path, $request, $phpEx, $config, $phpbb_dispatcher;
  29  
  30      $user->add_lang(array('viewtopic', 'memberlist'));
  31  
  32      $msg_id        = (int) $msg_id;
  33      $folder_id    = (int) $folder_id;
  34      $author_id    = (int) $message_row['author_id'];
  35      $view        = $request->variable('view', '');
  36  
  37      // Not able to view message, it was deleted by the sender
  38      if ($message_row['pm_deleted'])
  39      {
  40          $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;folder=$folder_id");
  41          $message = $user->lang['NO_AUTH_READ_REMOVED_MESSAGE'];
  42  
  43          $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
  44          send_status_line(403, 'Forbidden');
  45          trigger_error($message);
  46      }
  47  
  48      // Do not allow hold messages to be seen
  49      if ($folder_id == PRIVMSGS_HOLD_BOX)
  50      {
  51          trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
  52      }
  53  
  54      // Load the custom profile fields
  55      if ($config['load_cpf_pm'])
  56      {
  57          /* @var $cp \phpbb\profilefields\manager */
  58          $cp = $phpbb_container->get('profilefields.manager');
  59  
  60          $profile_fields = $cp->grab_profile_fields_data($author_id);
  61      }
  62  
  63      // Assign TO/BCC Addresses to template
  64      write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
  65  
  66      $user_info = get_user_information($author_id, $message_row);
  67  
  68      // Parse the message and subject
  69      $parse_flags = ($message_row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
  70      $message = generate_text_for_display($message_row['message_text'], $message_row['bbcode_uid'], $message_row['bbcode_bitfield'], $parse_flags, true);
  71  
  72      // Replace naughty words such as farty pants
  73      $message_row['message_subject'] = censor_text($message_row['message_subject']);
  74  
  75      // Editing information
  76      if ($message_row['message_edit_count'] && $config['display_last_edited'])
  77      {
  78          if (!$message_row['message_edit_user'])
  79          {
  80              $display_username = get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour']);
  81          }
  82          else
  83          {
  84              $edit_user_info = get_user_information($message_row['message_edit_user'], false);
  85              $display_username = get_username_string('full', $message_row['message_edit_user'], $edit_user_info['username'], $edit_user_info['user_colour']);
  86          }
  87          $l_edited_by = '<br /><br />' . $user->lang('EDITED_TIMES_TOTAL', (int) $message_row['message_edit_count'], $display_username, $user->format_date($message_row['message_edit_time'], false, true));
  88      }
  89      else
  90      {
  91          $l_edited_by = '';
  92      }
  93  
  94      // Pull attachment data
  95      $display_notice = false;
  96      $attachments = array();
  97  
  98      if ($message_row['message_attachment'] && $config['allow_pm_attach'])
  99      {
 100          if ($auth->acl_get('u_pm_download'))
 101          {
 102              $sql = 'SELECT *
 103                  FROM ' . ATTACHMENTS_TABLE . "
 104                  WHERE post_msg_id = $msg_id
 105                      AND in_message = 1
 106                  ORDER BY filetime DESC, post_msg_id ASC";
 107              $result = $db->sql_query($sql);
 108  
 109              while ($row = $db->sql_fetchrow($result))
 110              {
 111                  $attachments[] = $row;
 112              }
 113              $db->sql_freeresult($result);
 114  
 115              // No attachments exist, but message table thinks they do so go ahead and reset attach flags
 116              if (!count($attachments))
 117              {
 118                  $sql = 'UPDATE ' . PRIVMSGS_TABLE . "
 119                      SET message_attachment = 0
 120                      WHERE msg_id = $msg_id";
 121                  $db->sql_query($sql);
 122              }
 123          }
 124          else
 125          {
 126              $display_notice = true;
 127          }
 128      }
 129  
 130      // Assign inline attachments
 131      if (!empty($attachments))
 132      {
 133          $update_count = array();
 134          parse_attachments(false, $message, $attachments, $update_count);
 135  
 136          // Update the attachment download counts
 137          if (count($update_count))
 138          {
 139              $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
 140                  SET download_count = download_count + 1
 141                  WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
 142              $db->sql_query($sql);
 143          }
 144      }
 145  
 146      $user_info['sig'] = '';
 147  
 148      $signature = ($message_row['enable_sig'] && $config['allow_sig'] && $auth->acl_get('u_sig') && $user->optionget('viewsigs')) ? $user_info['user_sig'] : '';
 149  
 150      // End signature parsing, only if needed
 151      if ($signature)
 152      {
 153          $parse_flags = ($user_info['user_sig_bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
 154          $signature = generate_text_for_display($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield'], $parse_flags, true);
 155      }
 156  
 157      $url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
 158  
 159      // Number of "to" recipients
 160      $num_recipients = (int) preg_match_all('/:?(u|g)_([0-9]+):?/', $message_row['to_address'], $match);
 161  
 162      $bbcode_status    = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false;
 163  
 164      // Get the profile fields template data
 165      $cp_row = array();
 166      if ($config['load_cpf_pm'] && isset($profile_fields[$author_id]))
 167      {
 168          // Filter the fields we don't want to show
 169          foreach ($profile_fields[$author_id] as $used_ident => $profile_field)
 170          {
 171              if (!$profile_field['data']['field_show_on_pm'])
 172              {
 173                  unset($profile_fields[$author_id][$used_ident]);
 174              }
 175          }
 176  
 177          if (isset($profile_fields[$author_id]))
 178          {
 179              $cp_row = $cp->generate_profile_fields_template_data($profile_fields[$author_id]);
 180          }
 181      }
 182  
 183      $u_pm = $u_jabber = '';
 184  
 185      if ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user_info['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')))
 186      {
 187          $u_pm = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;u=' . $author_id);
 188      }
 189  
 190      if ($config['jab_enable'] && $user_info['user_jabber'] && $auth->acl_get('u_sendim'))
 191      {
 192          $u_jabber = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=jabber&amp;u=' . $author_id);
 193      }
 194  
 195      $msg_data = array(
 196          'MESSAGE_AUTHOR_FULL'        => get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
 197          'MESSAGE_AUTHOR_COLOUR'        => get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
 198          'MESSAGE_AUTHOR'            => get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
 199          'U_MESSAGE_AUTHOR'            => get_username_string('profile', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
 200  
 201          'RANK_TITLE'        => $user_info['rank_title'],
 202          'RANK_IMG'            => $user_info['rank_image'],
 203          'AUTHOR_AVATAR'        => (isset($user_info['avatar'])) ? $user_info['avatar'] : '',
 204          'AUTHOR_JOINED'        => $user->format_date($user_info['user_regdate']),
 205          'AUTHOR_POSTS'        => (int) $user_info['user_posts'],
 206          'U_AUTHOR_POSTS'    => ($config['load_search'] && $auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$author_id&amp;sr=posts") : '',
 207          'CONTACT_USER'        => $user->lang('CONTACT_USER', get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username'])),
 208  
 209          'ONLINE_IMG'        => (!$config['load_onlinetrack']) ? '' : ((isset($user_info['online']) && $user_info['online']) ? $user->img('icon_user_online', $user->lang['ONLINE']) : $user->img('icon_user_offline', $user->lang['OFFLINE'])),
 210          'S_ONLINE'            => (!$config['load_onlinetrack']) ? false : ((isset($user_info['online']) && $user_info['online']) ? true : false),
 211          'DELETE_IMG'        => $user->img('icon_post_delete', $user->lang['DELETE_MESSAGE']),
 212          'INFO_IMG'            => $user->img('icon_post_info', $user->lang['VIEW_PM_INFO']),
 213          'PROFILE_IMG'        => $user->img('icon_user_profile', $user->lang['READ_PROFILE']),
 214          'EMAIL_IMG'            => $user->img('icon_contact_email', $user->lang['SEND_EMAIL']),
 215          'QUOTE_IMG'            => $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']),
 216          'REPLY_IMG'            => $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']),
 217          'REPORT_IMG'        => $user->img('icon_post_report', 'REPORT_PM'),
 218          'EDIT_IMG'            => $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']),
 219          'MINI_POST_IMG'        => $user->img('icon_post_target', $user->lang['PM']),
 220  
 221          'SENT_DATE'            => ($view == 'print') ? $user->format_date($message_row['message_time'], false, true) : $user->format_date($message_row['message_time']),
 222          'SUBJECT'            => $message_row['message_subject'],
 223          'MESSAGE'            => $message,
 224          'SIGNATURE'            => ($message_row['enable_sig']) ? $signature : '',
 225          'EDITED_MESSAGE'    => $l_edited_by,
 226          'MESSAGE_ID'        => $message_row['msg_id'],
 227  
 228          'U_PM'            =>  $u_pm,
 229          'U_JABBER'        =>  $u_jabber,
 230  
 231          'U_DELETE'            => ($auth->acl_get('u_pm_delete')) ? "$url&amp;mode=compose&amp;action=delete&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
 232          'U_EMAIL'            => $user_info['email'],
 233          'U_REPORT'            => ($config['allow_pm_report']) ? $phpbb_container->get('controller.helper')->route('phpbb_report_pm_controller', array('id' => $message_row['msg_id'])) : '',
 234          'U_QUOTE'            => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=quote&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
 235          'U_EDIT'            => (($message_row['message_time'] > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']) && $folder_id == PRIVMSGS_OUTBOX && $auth->acl_get('u_pm_edit')) ? "$url&amp;mode=compose&amp;action=edit&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
 236          'U_POST_REPLY_PM'    => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
 237          'U_POST_REPLY_ALL'    => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;reply_to_all=1&amp;p=" . $message_row['msg_id'] : '',
 238          'U_PREVIOUS_PM'        => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=previous",
 239          'U_NEXT_PM'            => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=next",
 240  
 241          'U_PM_ACTION'        => $url . '&amp;mode=compose&amp;f=' . $folder_id . '&amp;p=' . $message_row['msg_id'],
 242  
 243          'S_HAS_ATTACHMENTS'    => (count($attachments)) ? true : false,
 244          'S_DISPLAY_NOTICE'    => $display_notice && $message_row['message_attachment'],
 245          'S_AUTHOR_DELETED'    => ($author_id == ANONYMOUS) ? true : false,
 246          'S_SPECIAL_FOLDER'    => in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
 247          'S_PM_RECIPIENTS'    => $num_recipients,
 248          'S_BBCODE_ALLOWED'    => ($bbcode_status) ? 1 : 0,
 249          'S_CUSTOM_FIELDS'    => (!empty($cp_row['row'])) ? true : false,
 250  
 251          'U_PRINT_PM'        => ($config['print_pm'] && $auth->acl_get('u_pm_printpm')) ? "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=print" : '',
 252          'U_FORWARD_PM'        => ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&amp;mode=compose&amp;action=forward&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
 253      );
 254  
 255      /**
 256      * Modify pm and sender data before it is assigned to the template
 257      *
 258      * @event core.ucp_pm_view_messsage
 259      * @var    mixed    id            Active module category (can be int or string)
 260      * @var    string    mode        Active module
 261      * @var    int        folder_id    ID of the folder the message is in
 262      * @var    int        msg_id        ID of the private message
 263      * @var    array    folder        Array with data of user's message folders
 264      * @var    array    message_row    Array with message data
 265      * @var    array    cp_row        Array with senders custom profile field data
 266      * @var    array    msg_data    Template array with message data
 267      * @var     array    user_info    User data of the sender
 268      * @since 3.1.0-a1
 269      * @changed 3.1.6-RC1        Added user_info into event
 270      * @changed 3.2.2-RC1        Deprecated
 271      * @deprecated 4.0.0            Event name is misspelled and is replaced with new event with correct name
 272      */
 273      $vars = array(
 274          'id',
 275          'mode',
 276          'folder_id',
 277          'msg_id',
 278          'folder',
 279          'message_row',
 280          'cp_row',
 281          'msg_data',
 282          'user_info',
 283      );
 284      extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_messsage', compact($vars)));
 285  
 286      /**
 287       * Modify pm and sender data before it is assigned to the template
 288       *
 289       * @event core.ucp_pm_view_message
 290       * @var    mixed    id            Active module category (can be int or string)
 291       * @var    string    mode        Active module
 292       * @var    int        folder_id    ID of the folder the message is in
 293       * @var    int        msg_id        ID of the private message
 294       * @var    array    folder        Array with data of user's message folders
 295       * @var    array    message_row    Array with message data
 296       * @var    array    cp_row        Array with senders custom profile field data
 297       * @var    array    msg_data    Template array with message data
 298       * @var array    user_info    User data of the sender
 299       * @var array    attachments    Attachments data
 300       * @since 3.2.2-RC1
 301       * @changed 3.2.5-RC1 Added attachments
 302       */
 303      $vars = array(
 304          'id',
 305          'mode',
 306          'folder_id',
 307          'msg_id',
 308          'folder',
 309          'message_row',
 310          'cp_row',
 311          'msg_data',
 312          'user_info',
 313          'attachments',
 314      );
 315      extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_message', compact($vars)));
 316  
 317      $template->assign_vars($msg_data);
 318  
 319      $contact_fields = array(
 320          array(
 321              'ID'        => 'pm',
 322              'NAME'        => $user->lang['SEND_PRIVATE_MESSAGE'],
 323              'U_CONTACT' => $u_pm,
 324          ),
 325          array(
 326              'ID'        => 'email',
 327              'NAME'        => $user->lang['SEND_EMAIL'],
 328              'U_CONTACT'    => $user_info['email'],
 329          ),
 330          array(
 331              'ID'        => 'jabber',
 332              'NAME'        => $user->lang['JABBER'],
 333              'U_CONTACT'    => $u_jabber,
 334          ),
 335      );
 336  
 337      foreach ($contact_fields as $field)
 338      {
 339          if ($field['U_CONTACT'])
 340          {
 341              $template->assign_block_vars('contact', $field);
 342          }
 343      }
 344  
 345      // Display the custom profile fields
 346      if (!empty($cp_row['row']))
 347      {
 348          $template->assign_vars($cp_row['row']);
 349  
 350          foreach ($cp_row['blockrow'] as $cp_block_row)
 351          {
 352              $template->assign_block_vars('custom_fields', $cp_block_row);
 353  
 354              if ($cp_block_row['S_PROFILE_CONTACT'])
 355              {
 356                  $template->assign_block_vars('contact', array(
 357                      'ID'        => $cp_block_row['PROFILE_FIELD_IDENT'],
 358                      'NAME'        => $cp_block_row['PROFILE_FIELD_NAME'],
 359                      'U_CONTACT'    => $cp_block_row['PROFILE_FIELD_CONTACT'],
 360                  ));
 361              }
 362          }
 363      }
 364  
 365      // Display not already displayed Attachments for this post, we already parsed them. ;)
 366      if (isset($attachments) && count($attachments))
 367      {
 368          foreach ($attachments as $attachment)
 369          {
 370              $template->assign_block_vars('attachment', array(
 371                  'DISPLAY_ATTACHMENT'    => $attachment)
 372              );
 373          }
 374      }
 375  
 376      if (!isset($_REQUEST['view']) || $request->variable('view', '') != 'print')
 377      {
 378          // Message History
 379          if (message_history($msg_id, $user->data['user_id'], $message_row, $folder))
 380          {
 381              $template->assign_var('S_DISPLAY_HISTORY', true);
 382          }
 383      }
 384  }
 385  
 386  /**
 387  * Get user information (only for message display)
 388  */
 389  function get_user_information($user_id, $user_row)
 390  {
 391      global $db, $auth, $user;
 392      global $phpbb_root_path, $phpEx, $config;
 393  
 394      if (!$user_id)
 395      {
 396          return array();
 397      }
 398  
 399      if (empty($user_row))
 400      {
 401          $sql = 'SELECT *
 402              FROM ' . USERS_TABLE . '
 403              WHERE user_id = ' . (int) $user_id;
 404          $result = $db->sql_query($sql);
 405          $user_row = $db->sql_fetchrow($result);
 406          $db->sql_freeresult($result);
 407      }
 408  
 409      // Some standard values
 410      $user_row['online'] = false;
 411      $user_row['rank_title'] = $user_row['rank_image'] = $user_row['rank_image_src'] = $user_row['email'] = '';
 412  
 413      // Generate online information for user
 414      if ($config['load_onlinetrack'])
 415      {
 416          $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
 417              FROM ' . SESSIONS_TABLE . "
 418              WHERE session_user_id = $user_id
 419              GROUP BY session_user_id";
 420          $result = $db->sql_query_limit($sql, 1);
 421          $row = $db->sql_fetchrow($result);
 422          $db->sql_freeresult($result);
 423  
 424          $update_time = $config['load_online_time'] * 60;
 425          if ($row)
 426          {
 427              $user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? true : false;
 428          }
 429      }
 430  
 431      $user_row['avatar'] = ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($user_row) : '';
 432  
 433      if (!function_exists('phpbb_get_user_rank'))
 434      {
 435          include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 436      }
 437  
 438      $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']);
 439      $user_row['rank_title'] = $user_rank_data['title'];
 440      $user_row['rank_image'] = $user_rank_data['img'];
 441      $user_row['rank_image_src'] = $user_rank_data['img_src'];
 442  
 443      if ((!empty($user_row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email'))
 444      {
 445          $user_row['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$user_id") : ((($config['board_hide_emails'] && !$auth->acl_get('a_email')) || empty($user_row['user_email'])) ? '' : 'mailto:' . $user_row['user_email']);
 446      }
 447  
 448      return $user_row;
 449  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1