function privatemsg_view in Privatemsg 6.2
Same name and namespace in other branches
- 5.3 privatemsg.module \privatemsg_view()
- 5 privatemsg.module \privatemsg_view()
- 6 privatemsg.module \privatemsg_view()
- 7.2 privatemsg.pages.inc \privatemsg_view()
- 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
1 string reference to 'privatemsg_view'
- privatemsg_menu in ./
privatemsg.module - Implements hook_menu().
File
- ./
privatemsg.pages.inc, line 110 - User menu callbacks for Privatemsg.
Code
function privatemsg_view($thread) {
drupal_set_title(check_plain($thread['subject']));
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'],
),
'title' => t('Display older messages'),
);
$older = l(t('<<'), privatemsg_get_dynamic_url_prefix() . '/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('>>'), privatemsg_get_dynamic_url_prefix() . '/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(
'#value' => trim($title),
'#prefix' => '<div class="privatemsg-view-pager">',
'#suffix' => '</div>',
'#weight' => 3,
);
}
// Render the participants.
$content['participants']['#value'] = theme('privatemsg_recipients', $thread);
$content['participants']['#weight'] = -5;
// Render the messages.
$output = '';
$i = 1;
$count = count($thread['messages']);
foreach ($thread['messages'] as $pmid => $message) {
// 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++;
$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') || privatemsg_user_access('reply only privatemsg')) {
$content['reply']['#value'] = drupal_get_form('privatemsg_form_reply', $thread);
$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');
}
// Allow other modules to hook into the $content array and alter it.
drupal_alter('privatemsg_view_messages', $content, $thread);
return drupal_render($content);
}