function privatemsg_view in Privatemsg 5
Same name and namespace in other branches
- 5.3 privatemsg.module \privatemsg_view()
- 6.2 privatemsg.pages.inc \privatemsg_view()
- 6 privatemsg.module \privatemsg_view()
- 7.2 privatemsg.pages.inc \privatemsg_view()
- 7 privatemsg.pages.inc \privatemsg_view()
Display a private message to a user.
We calculate previous and next message here. Let's assume the order is from oldest to newest. The next message is then the first row from: SELECT id FROM privatemsg WHERE timestamp > %d ORDER BY timestamp ASC The code below is the abstraction of this to every field and ASC/DESC.
1 string reference to 'privatemsg_view'
- privatemsg_menu in ./
privatemsg.module - Implementation of hook_menu().
File
- ./
privatemsg.module, line 1783
Code
function privatemsg_view($message_id) {
global $user;
if ($message = privatemsg_load($message_id)) {
$threaded_view = variable_get('privatemsg_threaded_view', 0);
if (isset($_SESSION['privatemsg_list_sql'])) {
// This is the SQL assembled in privatemsg_list
$sql = $_SESSION['privatemsg_list_sql']['sql'];
// These are the arguments, again from privatemsg_list
$args = $_SESSION['privatemsg_list_sql']['args'];
// This is the field we are ordering on.
$field = $_SESSION['privatemsg_list_sql']['field'];
// This is either ASC or DESC.
$sort = $_SESSION['privatemsg_list_sql']['sort'];
if ($threaded_view) {
$sql .= ' AND thread != %d';
$args[] = $message->thread;
}
$placeholder = $field == 'type' || $field == 'subject' ? "'%s'" : '%d';
$args[] = $message->{$field};
if ($sort == 'ASC') {
$prev_operator = '<';
$next_operator = '>';
$prev_sort = 'DESC';
$next_sort = 'ASC';
}
else {
$prev_operator = '>';
$next_operator = '<';
$prev_sort = 'ASC';
$next_sort = 'DESC';
}
if ($previous_id = db_result(db_query_range("{$sql} AND {$field} {$prev_operator} {$placeholder} ORDER BY {$field} {$prev_sort}", $args, 0, 1))) {
$previous_link = l(t('Previous'), 'privatemsg/view/' . $previous_id, array(), NULL, 'message-' . $previous_id);
}
else {
$previous_link = '';
}
if ($next_id = db_result(db_query_range("{$sql} AND {$field} {$next_operator} {$placeholder} ORDER BY {$field} {$next_sort}", $args, 0, 1))) {
$next_link = l(t('Next'), 'privatemsg/view/' . $next_id, array(), NULL, 'message-' . $next_id);
}
else {
$next_link = '';
}
}
if ($threaded_view && $message->thread) {
$result = db_query('SELECT p.id, u.uid, u.name, p.author, p.timestamp, p.subject, p.message, p.newmsg, p.recipient, p.folder, p.format FROM {privatemsg} p INNER JOIN {users} u ON p.author = u.uid WHERE p.thread = %d ORDER BY timestamp ASC', $message->thread);
$messages = '';
while ($message = db_fetch_object($result)) {
if (!isset($first)) {
$first = $message;
}
if ($message->recipient == $user->uid) {
$last = $message;
}
$messages .= _privatemsg_view($message);
}
}
else {
$first = $message;
$messages = _privatemsg_view($message);
}
$output = theme('privatemsg_links', $previous_link, $next_link);
$output .= $messages;
if ($last->recipient == $user->uid) {
$output .= drupal_get_form('privatemsg_new_form', $last->id);
}
return $output;
}
drupal_goto('privatemsg');
}