You are here

function heartbeat_messages_page in Heartbeat 7

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

Page callback function to load an activity stream page

Parameters

String $stream_name: Stream class name.

Integer $offset_time: The Offset timestamp to fetch activity.

stdClass $account: Optional user account object. If none given, global user will be used as "viewer" of the stream.

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

File

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

Code

function heartbeat_messages_page($stream_name, $offset_time = 0, $account = NULL) {

  // $_GET['stream_class'] is not used, it's available in uri.
  $stream_name = $stream_name;
  $page = empty($_GET['block']);

  // Get the active stream.
  $heartbeatStream = heartbeat_stream($stream_name, $page);

  // Determine view mode.
  $view_mode = $page ? $heartbeatStream->config->page_view_mode : $heartbeatStream->config->block_view_mode;
  if (!$heartbeatStream) {
    drupal_access_denied();
    return;
  }
  else {

    // When view a streams specific for a user (E.g. stream blocks on profile page),
    // alter the viewed person.
    if (!$page && is_numeric($account) && $account > 0 && variable_get('heartbeat_show_user_profile_messages_' . $stream_name, 0)) {
      $heartbeatStream
        ->setViewed(user_load($account));
    }
    elseif (isset($_GET['uid']) && is_numeric($_GET['uid']) && $_GET['uid'] > 0) {
      $heartbeatStream
        ->setViewed(user_load($_GET['uid']));
    }

    // If OG related messages are excluded.
    if (!empty($heartbeatStream->config->settings['exclude_og'])) {
      $heartbeatStream
        ->excludeOg(TRUE);
    }

    // Set the offset time of the pager.
    if ($offset_time > 0) {
      $heartbeatStream
        ->setOffsetTime($offset_time);
    }
    elseif (!empty($_GET['offset_time'])) {
      $heartbeatStream
        ->setOffsetTime($_GET['offset_time']);
    }

    // Build the stream output.
    heartbeat_stream_build($heartbeatStream);

    // Catch and display errors.
    if ($heartbeatStream
      ->hasErrors()) {
      if (function_exists('dsm')) {
        dsm($heartbeatStream
          ->getErrors(), $heartbeatStream->name);
      }
      else {
        drupal_set_message(implode('<br />', $heartbeatStream
          ->getErrors()));
      }
    }
    $build = heartbeat_stream_view($heartbeatStream, $view_mode);
  }

  // Pass the content on to the theme layer.
  $content = array();
  $content['#theme'] = 'heartbeat_list';
  $content['#stream'] = $heartbeatStream;
  $content['#content'] = $build;
  return $content;
}