[ Index ]

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1