[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

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

   1  <?php
   2  /** 
   3  *
   4  * @package ucp
   5  * @version $Id: ucp_pm_viewmessage.php,v 1.44 2006/11/12 15:35:43 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * View private message
  13  */
  14  function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
  15  {
  16      global $user, $template, $auth, $db, $cache;
  17      global $phpbb_root_path, $phpEx, $config;
  18  
  19      $user->add_lang(array('viewtopic', 'memberlist'));
  20  
  21      $msg_id        = (int) $msg_id;
  22      $folder_id    = (int) $folder_id;
  23      $author_id    = (int) $message_row['author_id'];
  24  
  25      // Not able to view message, it was deleted by the sender
  26      if ($message_row['pm_deleted'])
  27      {
  28          trigger_error('NO_AUTH_READ_REMOVED_MESSAGE');
  29      }
  30  
  31      // Do not allow hold messages to be seen
  32      if ($folder_id == PRIVMSGS_HOLD_BOX)
  33      {
  34          trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
  35      }
  36  
  37      // Grab icons
  38      $icons = $cache->obtain_icons();
  39  
  40      $bbcode = false;
  41  
  42      // Instantiate BBCode if need be
  43      if ($message_row['bbcode_bitfield'])
  44      {
  45          include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  46          $bbcode = new bbcode($message_row['bbcode_bitfield']);
  47      }
  48  
  49      // Assign TO/BCC Addresses to template
  50      write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
  51  
  52      $user_info = get_user_informations($author_id, $message_row);
  53  
  54      // Parse the message and subject
  55      $message = $message_row['message_text'];
  56      $message = str_replace("\n", '<br />', censor_text($message));
  57  
  58      // Second parse bbcode here
  59      if ($message_row['bbcode_bitfield'])
  60      {
  61          $bbcode->bbcode_second_pass($message, $message_row['bbcode_uid'], $message_row['bbcode_bitfield']);
  62      }
  63  
  64      // Always process smilies after parsing bbcodes
  65      $message = smiley_text($message);
  66  
  67      // Replace naughty words such as farty pants
  68      $message_row['message_subject'] = censor_text($message_row['message_subject']);
  69  
  70      // Editing information
  71      if ($message_row['message_edit_count'] && $config['display_last_edited'])
  72      {
  73          $l_edit_time_total = ($message_row['message_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
  74          $l_edited_by = '<br /><br />' . sprintf($l_edit_time_total, (!$message_row['message_edit_user']) ? $message_row['username'] : $message_row['message_edit_user'], $user->format_date($message_row['message_edit_time']), $message_row['message_edit_count']);
  75      }
  76      else
  77      {
  78          $l_edited_by = '';
  79      }
  80  
  81      // Pull attachment data
  82      $display_notice = false;
  83      $attachments = array();
  84  
  85      if ($message_row['message_attachment'] && $config['allow_pm_attach'])
  86      {
  87          if ($auth->acl_get('u_pm_download'))
  88          {
  89              include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  90  
  91              $sql = 'SELECT *
  92                  FROM ' . ATTACHMENTS_TABLE . "
  93                  WHERE post_msg_id = $msg_id
  94                      AND in_message = 1
  95                  ORDER BY filetime " . ((!$config['display_order']) ? 'DESC' : 'ASC') . ', post_msg_id ASC';
  96              $result = $db->sql_query($sql);
  97  
  98              while ($row = $db->sql_fetchrow($result))
  99              {
 100                  $attachments[] = $row;
 101              }
 102              $db->sql_freeresult($result);
 103  
 104              // No attachments exist, but message table thinks they do so go ahead and reset attach flags
 105              if (!sizeof($attachments))
 106              {
 107                  $sql = 'UPDATE ' . PRIVMSGS_TABLE . "
 108                      SET message_attachment = 0
 109                      WHERE msg_id = $msg_id";
 110                  $db->sql_query($sql);
 111              }
 112          }
 113          else
 114          {
 115              $display_notice = true;
 116          }
 117      }
 118  
 119      // Assign inline attachments
 120      if (isset($attachments) && sizeof($attachments))
 121      {
 122          $update_count = array();
 123          $unset_attachments = parse_inline_attachments($message, $attachments, $update_count, 0);
 124  
 125          // Needed to let not display the inlined attachments at the end of the message again
 126          foreach ($unset_attachments as $index)
 127          {
 128              unset($attachments[$index]);
 129          }
 130  
 131          // Update the attachment download counts
 132          if (sizeof($update_count))
 133          {
 134              $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
 135                  SET download_count = download_count + 1
 136                  WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
 137              $db->sql_query($sql);
 138          }
 139      }
 140  
 141      $user_info['sig'] = '';
 142  
 143      $signature = ($message_row['enable_sig'] && $config['allow_sig'] && $auth->acl_get('u_sig') && $user->optionget('viewsigs')) ? $user_info['user_sig'] : '';
 144  
 145      // End signature parsing, only if needed
 146      if ($signature)
 147      {
 148          $signature = censor_text($signature);
 149          $signature = str_replace("\n", '<br />', censor_text($signature));
 150  
 151          if ($user_info['user_sig_bbcode_bitfield'])
 152          {
 153              if ($bbcode === false)
 154              {
 155                  include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 156                  $bbcode = new bbcode($user_info['user_sig_bbcode_bitfield']);
 157              }
 158  
 159              $bbcode->bbcode_second_pass($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield']);
 160          }
 161  
 162          $signature = smiley_text($signature);
 163      }
 164  
 165      $url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
 166  
 167      $template->assign_vars(array(
 168          'AUTHOR_NAME'        => ($user_info['user_colour']) ? '<span style="color:#' . $user_info['user_colour'] . '">' . $user_info['username'] . '</span>' : $user_info['username'],
 169          'AUTHOR_RANK'        => $user_info['rank_title'],
 170          'RANK_IMAGE'        => $user_info['rank_image'],
 171          'AUTHOR_AVATAR'        => (isset($user_info['avatar'])) ? $user_info['avatar'] : '',
 172          'AUTHOR_JOINED'        => $user->format_date($user_info['user_regdate']),
 173          'AUTHOR_POSTS'        => (!empty($user_info['user_posts'])) ? $user_info['user_posts'] : '',
 174          'AUTHOR_FROM'        => (!empty($user_info['user_from'])) ? $user_info['user_from'] : '',
 175  
 176          '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'])),
 177          'S_ONLINE'            => (!$config['load_onlinetrack']) ? false : ((isset($user_info['online']) && $user_info['online']) ? true : false),
 178          'DELETE_IMG'        => $user->img('icon_post_delete', $user->lang['DELETE_MESSAGE']),
 179          'INFO_IMG'            => $user->img('icon_post_info', $user->lang['VIEW_PM_INFO']),
 180          'PROFILE_IMG'        => $user->img('icon_user_profile', $user->lang['READ_PROFILE']),
 181          'EMAIL_IMG'            => $user->img('icon_contact_email', $user->lang['SEND_EMAIL']),
 182          'QUOTE_IMG'            => $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']),
 183          'REPLY_IMG'            => $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']),
 184          'EDIT_IMG'            => $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']),
 185          'MINI_POST_IMG'        => $user->img('icon_post_target', $user->lang['PM']),
 186  
 187          'SENT_DATE'            => $user->format_date($message_row['message_time']),
 188          'SUBJECT'            => $message_row['message_subject'],
 189          'MESSAGE'            => $message,
 190          'SIGNATURE'            => ($message_row['enable_sig']) ? $signature : '',
 191          'EDITED_MESSAGE'    => $l_edited_by,
 192  
 193          'U_INFO'            => ($auth->acl_get('m_info') && $message_row['pm_forwarded']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'mode=pm_details&amp;p=' . $message_row['msg_id'], true, $user->session_id) : '',
 194          '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'] : '',
 195          'U_AUTHOR_PROFILE'    => ($author_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $author_id) : '',
 196          'U_EMAIL'            => $user_info['email'],
 197          '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'] : '',
 198          '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'] : '',
 199          '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'] : '',
 200          'U_PREVIOUS_PM'        => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=previous",
 201          'U_NEXT_PM'            => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=next",
 202  
 203          'S_HAS_ATTACHMENTS'    => (sizeof($attachments)) ? true : false,
 204          'S_DISPLAY_NOTICE'    => $display_notice && $message_row['message_attachment'],
 205          'S_AUTHOR_DELETED'    => ($author_id == ANONYMOUS) ? true : false,
 206  
 207          '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" : '',
 208          'U_FORWARD_PM'        => ($config['forward_pm'] && $auth->acl_get('u_pm_forward')) ? "$url&amp;mode=compose&amp;action=forward&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '')
 209      );
 210  
 211      // Display not already displayed Attachments for this post, we already parsed them. ;)
 212      if (isset($attachments) && sizeof($attachments))
 213      {
 214          foreach ($attachments as $attachment)
 215          {
 216              $template->assign_block_vars('attachment', array(
 217                  'DISPLAY_ATTACHMENT'    => $attachment)
 218              );
 219          }
 220      }
 221  
 222      if (!isset($_REQUEST['view']) || $_REQUEST['view'] != 'print')
 223      {
 224          // Message History
 225          if (message_history($msg_id, $user->data['user_id'], $message_row, $folder))
 226          {
 227              $template->assign_var('S_DISPLAY_HISTORY', true);
 228          }
 229      }
 230  }
 231  
 232  /**
 233  * Display Message History
 234  */
 235  function message_history($msg_id, $user_id, $message_row, $folder)
 236  {
 237      global $db, $user, $config, $template, $phpbb_root_path, $phpEx, $auth, $bbcode;
 238  
 239      // Get History Messages (could be newer)
 240      $sql = 'SELECT t.*, p.*, u.*
 241          FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . ' t, ' . USERS_TABLE . ' u
 242          WHERE t.msg_id = p.msg_id
 243              AND p.author_id = u.user_id
 244              AND t.folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ")
 245              AND t.user_id = $user_id";
 246  
 247      if (!$message_row['root_level'])
 248      {
 249          $sql .= " AND (p.root_level = $msg_id OR (p.root_level = 0 AND p.msg_id = $msg_id))";
 250      }
 251      else
 252      {
 253          $sql .= " AND (p.root_level = " . $message_row['root_level'] . ' OR p.msg_id = ' . $message_row['root_level'] . ')';
 254      }
 255      $sql .= ' ORDER BY p.message_time ';
 256      $sort_dir = (!empty($user->data['user_sortby_dir'])) ? $user->data['user_sortby_dir'] : 'd';
 257      $sql .= ($sort_dir == 'd') ? 'ASC' : 'DESC';
 258  
 259      $result = $db->sql_query($sql);
 260      $row = $db->sql_fetchrow($result);
 261  
 262      if (!$row)
 263      {
 264          $db->sql_freeresult($result);
 265          return false;
 266      }
 267  
 268      $rowset = array();
 269      $bbcode_bitfield = '';
 270      $folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm') . '&amp;folder=';
 271  
 272      $title = ($sort_dir == 'd') ? $row['message_subject'] : '';
 273      do
 274      {
 275          $folder_id = (int) $row['folder_id'];
 276  
 277          $row['folder'][] = (isset($folder[$folder_id])) ? '<a href="' . $folder_url . $folder_id . '">' . $folder[$folder_id]['folder_name'] . '</a>' : $user->lang['UNKOWN_FOLDER'];
 278  
 279          if (isset($rowset[$row['msg_id']]))
 280          {
 281              $rowset[$row['msg_id']]['folder'][] = (isset($folder[$folder_id])) ? '<a href="' . $folder_url . $folder_id . '">' . $folder[$folder_id]['folder_name'] . '</a>' : $user->lang['UNKOWN_FOLDER'];
 282          }
 283          else
 284          {
 285              $rowset[$row['msg_id']] = $row;
 286              $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
 287          }
 288      }
 289      while ($row = $db->sql_fetchrow($result));
 290      $db->sql_freeresult($result);
 291  
 292      $title = ($sort_dir == 'a') ? $row['message_subject'] : $title;
 293  
 294      if (sizeof($rowset) == 1)
 295      {
 296          return false;
 297      }
 298  
 299      // Instantiate BBCode class
 300      if ((empty($bbcode) || $bbcode === false) && $bbcode_bitfield !== '')
 301      {
 302          if (!class_exists('bbcode'))
 303          {
 304              include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 305          }
 306          $bbcode = new bbcode(base64_encode($bbcode_bitfield));
 307      }
 308  
 309      $title = censor_text($title);
 310  
 311      $url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
 312      $next_history_pm = $previous_history_pm = $prev_id = 0;
 313  
 314      foreach ($rowset as $id => $row)
 315      {
 316          $author_id    = $row['author_id'];
 317          $author        = $row['username'];
 318          $folder_id    = (int) $row['folder_id'];
 319  
 320          $subject    = $row['message_subject'];
 321          $message    = $row['message_text'];
 322  
 323          $message = censor_text($message);
 324          $message = str_replace("\n", '<br />', $message);
 325  
 326          if ($row['bbcode_bitfield'])
 327          {
 328              $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
 329          }
 330  
 331          $message = smiley_text($message, !$row['enable_smilies']);
 332  
 333          $subject = censor_text($subject);
 334  
 335          if ($id == $msg_id)
 336          {
 337              $next_history_pm = next($rowset);
 338              $next_history_pm = (sizeof($next_history_pm)) ? (int) $next_history_pm['msg_id'] : 0;
 339              $previous_history_pm = $prev_id;
 340          }
 341  
 342          $template->assign_block_vars('history_row', array(
 343              'AUTHOR_NAME'    => $author,
 344              'SUBJECT'        => $subject,
 345              'SENT_DATE'        => $user->format_date($row['message_time']),
 346              'MESSAGE'        => $message,
 347              'FOLDER'        => implode(', ', $row['folder']),
 348  
 349              'S_CURRENT_MSG'        => ($row['msg_id'] == $msg_id),
 350              'S_AUTHOR_DELETED'    => ($author_id == ANONYMOUS) ? true : false,
 351  
 352              'U_MSG_ID'            => $row['msg_id'],
 353              'U_VIEW_MESSAGE'    => "$url&amp;f=$folder_id&amp;p=" . $row['msg_id'],
 354              'U_AUTHOR_PROFILE'    => ($author_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$author_id") : '',
 355              'U_QUOTE'            => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS && $author_id != $user->data['user_id']) ? "$url&amp;mode=compose&amp;action=quote&amp;f=" . $folder_id . "&amp;p=" . $row['msg_id'] : '',
 356              'U_POST_REPLY_PM'    => ($author_id != $user->data['user_id'] && $author_id != ANONYMOUS && $auth->acl_get('u_sendpm')) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;p=" . $row['msg_id'] : '')
 357          );
 358          unset($rowset[$id]);
 359          $prev_id = $id;
 360      }
 361  
 362      $template->assign_vars(array(
 363          'QUOTE_IMG'    => $user->img('icon_post_quote', $user->lang['REPLY_WITH_QUOTE']),
 364          'TITLE'        => $title,
 365  
 366          'U_VIEW_NEXT_HISTORY'        => "$url&amp;p=" . (($next_history_pm) ? $next_history_pm : $msg_id),
 367          'U_VIEW_PREVIOUS_HISTORY'    => "$url&amp;p=" . (($previous_history_pm) ? $previous_history_pm : $msg_id))
 368      );
 369  
 370      return true;
 371  }
 372  
 373  /**
 374  * Get User Informations (only for message display)
 375  */
 376  function get_user_informations($user_id, $user_row)
 377  {
 378      global $db, $auth, $user, $cache;
 379      global $phpbb_root_path, $phpEx, $config;
 380  
 381      if (!$user_id)
 382      {
 383          return array();
 384      }
 385  
 386      if (empty($user_row))
 387      {
 388          $sql = 'SELECT *
 389              FROM ' . USERS_TABLE . '
 390              WHERE user_id = ' . (int) $user_id;
 391          $result = $db->sql_query($sql);
 392          $user_row = $db->sql_fetchrow($result);
 393          $db->sql_freeresult($result);
 394      }
 395  
 396      // Grab ranks
 397      $ranks = $cache->obtain_ranks();
 398  
 399      // Generate online information for user
 400      if ($config['load_onlinetrack'])
 401      {
 402          $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
 403              FROM ' . SESSIONS_TABLE . "
 404              WHERE session_user_id = $user_id
 405              GROUP BY session_user_id";
 406          $result = $db->sql_query_limit($sql, 1);
 407          $row = $db->sql_fetchrow($result);
 408          $db->sql_freeresult($result);
 409  
 410          $update_time = $config['load_online_time'] * 60;
 411          if ($row)
 412          {
 413              $user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'] && $user_row['user_allow_viewonline'])) ? true : false;
 414          }
 415      }
 416      else
 417      {
 418          $user_row['online'] = false;
 419      }
 420  
 421      if ($user_row['user_avatar'] && $user->optionget('viewavatars'))
 422      {
 423          $avatar_img = '';
 424          switch ($user_row['user_avatar_type'])
 425          {
 426              case AVATAR_UPLOAD:
 427                  $avatar_img = $config['avatar_path'] . '/';
 428              break;
 429  
 430              case AVATAR_GALLERY:
 431                  $avatar_img = $config['avatar_gallery_path'] . '/';
 432              break;
 433          }
 434          $avatar_img .= $user_row['user_avatar'];
 435  
 436          $user_row['avatar'] = '<img src="' . $avatar_img . '" width="' . $user_row['user_avatar_width'] . '" height="' . $user_row['user_avatar_height'] . '" alt="' . $user->lang['USER_AVATAR'] . '" />';
 437      }
 438  
 439      $user_row['rank_title'] = $user_row['rank_image'] = '';
 440  
 441      if (!empty($user_row['user_rank']))
 442      {
 443          $user_row['rank_title'] = (isset($ranks['special'][$user_row['user_rank']])) ? $ranks['special'][$user_row['user_rank']]['rank_title'] : '';
 444          $user_row['rank_image'] = (!empty($ranks['special'][$user_row['user_rank']]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$user_row['user_rank']]['rank_image'] . '" alt="' . $ranks['special'][$user_row['user_rank']]['rank_title'] . '" title="' . $ranks['special'][$user_row['user_rank']]['rank_title'] . '" /><br />' : '';
 445      }
 446      else
 447      {
 448          if (isset($ranks['normal']))
 449          {
 450              foreach ($ranks['normal'] as $rank)
 451              {
 452                  if ($user_row['user_posts'] >= $rank['rank_min'])
 453                  {
 454                      $user_row['rank_title'] = $rank['rank_title'];
 455                      $user_row['rank_image'] = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" /><br />' : '';
 456                      break;
 457                  }
 458              }
 459          }
 460      }
 461  
 462      if (!empty($user_row['user_allow_viewemail']) || $auth->acl_get('a_email'))
 463      {
 464          $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')) ? '' : 'mailto:' . $user_row['user_email']);
 465      }
 466      else
 467      {
 468          $user_row['email'] = '';
 469      }
 470  
 471      return $user_row;
 472  }
 473  
 474  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6