[ Index ]

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


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1