You are here

function heartbeat_messages_page in Heartbeat 6.4

Same name and namespace in other branches
  1. 7 heartbeat.pages.inc \heartbeat_messages_page()

Page callback function to load an activity stream page.

Parameters

array $access_type:

Return value

string Themed list of messages

1 string reference to 'heartbeat_messages_page'
heartbeat_menu in ./heartbeat.module
Implementation of hook_menu().

File

./heartbeat.pages.inc, line 14
Separate codefile for page displays

Code

function heartbeat_messages_page($access_type, $offset_time = 0, $account = NULL) {
  if (!user_access('view heartbeat messages') || !variable_get('heartbeat_enabled', 1)) {
    drupal_access_denied();
    exit;
  }
  $output = '';
  if ($offset_time == 0) {
    $offset_time = $_SERVER['REQUEST_TIME'];
  }

  // Messages have to loaded by ajax if the url contains an offset
  // variable AND a post variable ajax is defined.
  $ajax = !empty($_POST['ajax']);
  $page = empty($_POST['block']);

  // Normal page request with a offset time need a previous link
  if (!$ajax && $offset_time > 0 && $offset_time != $_SERVER['REQUEST_TIME']) {
    $output .= heartbeat_stream_prev_link($access_type);
  }

  // For block updates by ajax displayed on the user
  // profile page, we want to show the account requested.
  if (is_numeric($account) && $account > 0) {
    if (!$page) {
      if (variable_get('heartbeat_show_user_profile_messages_' . $access_type, 1)) {
        $account = heartbeat_user_load($account);
      }
    }
    else {
      $account = heartbeat_user_load($account);
    }
  }

  // Message streams for each access type
  $context = heartbeat_stream_view($access_type, $page, $offset_time, $ajax, $account);
  if (!isset($context)) {
    return $ajax ? drupal_json(array(
      'status' => TRUE,
      'data' => t('No messages found.'),
    )) : t('No messages found.');
  }

  // Get the messages
  $messages = $context
    ->execute();
  if (variable_get('heartbeat_debug', 0) && $context
    ->hasErrors()) {
    drupal_set_message(implode('<br />', $context
      ->getErrors()), 'warning');
  }
  $heartbeataccess = $context
    ->getState();
  $link = '';
  if ($context
    ->hasMoreMessages()) {
    $last_message = end($messages);
    $link = theme('heartbeat_stream_more_link', $heartbeataccess, $last_message->timestamp, $page);
  }
  $theme_function = $ajax ? 'heartbeat_messages' : 'heartbeat_list';
  $output .= theme($theme_function, $messages, $heartbeataccess, $link);
  if ($ajax) {
    return drupal_json(array(
      'status' => TRUE,
      'data' => $output,
    ));
  }
  return $output;
}