You are here

function privatemsg_view in Privatemsg 6

Same name and namespace in other branches
  1. 5.3 privatemsg.module \privatemsg_view()
  2. 5 privatemsg.module \privatemsg_view()
  3. 6.2 privatemsg.pages.inc \privatemsg_view()
  4. 7.2 privatemsg.pages.inc \privatemsg_view()
  5. 7 privatemsg.pages.inc \privatemsg_view()

Menu callback for viewing a thread.

Parameters

$thread: A array containing all information about a specific thread, generated by privatemsg_thread_load().

Return value

The page content.

See also

privatemsg_thread_load()

1 string reference to 'privatemsg_view'
privatemsg_menu in ./privatemsg.module
Implements hook_menu().

File

./privatemsg.module, line 749
Allows users to send private messages to other users.

Code

function privatemsg_view($thread) {
  drupal_set_title(check_plain($thread['subject']));

  // Generate paging links.
  $older = '';
  if (isset($thread['older_start'])) {
    $options = array(
      'query' => array(
        'start' => $thread['older_start'],
      ),
      'title' => t('Display older messages'),
    );
    $older = l(t('<<'), 'messages/view/' . $thread['thread_id'], $options);
  }
  $newer = '';
  if (isset($thread['newer_start'])) {
    $options = array(
      'query' => array(
        'start' => $thread['newer_start'],
      ),
      'title' => t('Display newer messages'),
    );
    $newer = l(t('>>'), 'messages/view/' . $thread['thread_id'], $options);
  }
  $substitutions = array(
    '@from' => $thread['from'],
    '@to' => $thread['to'],
    '@total' => $thread['message_count'],
    '!previous_link' => $older,
    '!newer_link' => $newer,
  );
  $title = t('!previous_link Displaying messages @from - @to of @total !newer_link', $substitutions);
  $content['pager_top'] = array(
    '#value' => trim($title),
    '#prefix' => '<div class="privatemsg-view-pager">',
    '#suffix' => '</div>',
    '#weight' => -10,
  );

  // Display a copy at the end.
  $content['pager_bottom'] = $content['pager_top'];
  $content['pager_bottom']['#weight'] = 3;

  // Render the participants.
  $content['participants']['#value'] = theme('privatemsg_recipients', $thread);
  $content['participants']['#weight'] = -5;

  // Render the messages.
  $output = '';
  foreach ($thread['messages'] as $pmid => $message) {

    // Set message as read and theme it.
    if (!empty($message['is_new'])) {
      privatemsg_message_change_status($pmid, PRIVATEMSG_READ, $thread['user']);
    }
    $output .= theme('privatemsg_view', $message);
  }
  $content['messages']['#value'] = $output;
  $content['messages']['#weight'] = 0;

  // Display the reply form if user is allowed to use it.
  if (privatemsg_user_access('write privatemsg')) {
    $content['reply']['#value'] = drupal_get_form('privatemsg_new', $thread['participants'], $thread['subject'], $thread['thread_id'], $thread['read_all']);
    $content['reply']['#weight'] = 5;
  }

  // Check after calling the privatemsg_new form so that this message is only
  // displayed when we are not sending a message.
  if ($thread['read_all']) {

    // User has permission to read all messages AND is not a participant of the current thread.
    drupal_set_message(t('This conversation is being viewed with escalated priviledges and may not be the same as shown to normal users.'), 'warning');
  }

  // Allow other modules to hook into the $content array and alter it.
  drupal_alter('privatemsg_view_messages', $content, $thread);
  return drupal_render($content);
}