You are here

function privatemsg_view in Privatemsg 7

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. 6 privatemsg.module \privatemsg_view()
  5. 7.2 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.pages.inc, line 763
User menu callbacks for Privatemsg.

Code

function privatemsg_view($thread) {
  drupal_set_title($thread['subject']);
  $content = array(
    '#thread' => $thread,
  );
  if ($thread['to'] != $thread['message_count'] || !empty($thread['start'])) {

    // Generate paging links.
    $older = '';
    if (isset($thread['older_start'])) {
      $options = array(
        'query' => array(
          'start' => $thread['older_start'],
        ),
        'attributes' => array(
          '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'],
        ),
        'attributes' => array(
          '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'] = array(
      '#markup' => trim($title),
      '#prefix' => '<div class="privatemsg-view-pager">',
      '#suffix' => '</div>',
      '#weight' => 3,
    );
  }

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

  // Render the messages.
  $content['messages']['#weight'] = 0;
  $i = 1;
  $count = count($thread['messages']);
  foreach ($thread['messages'] as $pmid => $message) {

    // Set message as read and theme it.
    // Add CSS classes.
    $message->classes = array(
      'privatemsg-message',
      'privatemsg-message-' . $i,
      $i % 2 == 1 ? 'privatemsg-message-even' : 'privatemsg-message-odd',
    );
    if (!empty($message->is_new)) {

      // Mark message as read.
      privatemsg_message_change_status($pmid, PRIVATEMSG_READ, $thread['user']);
      $message->classes[] = 'privatemsg-message-new';
    }
    if ($i == 1) {
      $message->classes[] = 'privatemsg-message-first';
    }
    if ($i == $count) {
      $message->classes[] = 'privatemsg-message-last';
    }
    $i++;
    $content['messages'][$pmid] = array(
      '#markup' => theme('privatemsg_view', array(
        'message' => $message,
      )),
    );
  }

  // Display the reply form if user is allowed to use it.
  if (privatemsg_user_access('write privatemsg') || privatemsg_user_access('reply only privatemsg')) {
    $content['reply'] = drupal_get_form('privatemsg_new', $thread['participants'], $thread['subject-original'], $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 privileges and may not be the same as shown to normal users.'), 'warning');
  }
  drupal_alter('privatemsg_view', $content);
  return $content;
}