You are here

function heartbeat_activity_older in Heartbeat 7

JavaScript callback to load older messages.

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

File

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

Code

function heartbeat_activity_older() {

  // Stream name and offset time are required for fetching older messages.
  // @TODO Check if this is the best way to handle these requests.
  if (empty($_GET['stream_class']) || empty($_GET['offset_time']) || !$_GET['ajax']) {
    return drupal_access_denied();
  }

  // Messages have to loaded by ajax if the url contains an offset
  // variable AND a post variable ajax is defined.
  $page = empty($_GET['block']);
  $stream_name = $_GET['stream_name'];
  $stream_class = $_GET['stream_class'];
  $uid = $_GET['uid'];
  $offset_time = $_GET['offset_time'];
  $account = user_load($uid);
  if ($heartbeatStream = heartbeat_stream($stream_class, $page, $account)) {

    // Changes at runtime.
    $heartbeatStream
      ->setOffsetTime($offset_time);
    $heartbeatStream
      ->setIsPage($page);
    heartbeat_stream_build($heartbeatStream);
    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);
  }
  else {
    $build = t('You don\'t have access to this stream.');
  }
  return drupal_json_output(array(
    'status' => TRUE,
    'data' => drupal_render($build),
  ));
}