function heartbeat_activity_poll in Heartbeat 7
Same name and namespace in other branches
- 6.4 heartbeat.pages.inc \heartbeat_activity_poll()
Callback to poll for newer messages. Each stream is displayed within a context.
1 string reference to 'heartbeat_activity_poll'
- heartbeat_menu in ./
heartbeat.module - Implements hook_menu().
File
- ./
heartbeat.pages.inc, line 171 - Separate codefile for page displays
Code
function heartbeat_activity_poll() {
// if no stream is defined or the user does not have access
if (empty($_GET['stream_class']) || !user_access('view heartbeat messages')) {
return drupal_json_output(array(
'status' => FALSE,
'data' => '',
'error' => t('No access'),
));
}
$page = empty($_GET['block']) || $_GET['block'] == 'false';
$heartbeatStream = heartbeat_stream($_GET['stream_class'], TRUE);
$view_mode = $page ? $heartbeatStream->config->page_view_mode : $heartbeatStream->config->block_view_mode;
// Configuration at runtime.
$heartbeatStream
->setLatestActivityId($_GET['latestUaid']);
$heartbeatStream
->setAjax(isset($_GET['ajax']) && $_GET['ajax']);
if (isset($_GET['language'])) {
// change the language with the post value.
$heartbeatStream
->setLanguage($_GET['language']);
}
heartbeat_stream_build($heartbeatStream);
$build = heartbeat_stream_view($heartbeatStream, $view_mode);
$json = array(
'status' => TRUE,
'data' => drupal_render($build),
'count' => $heartbeatStream
->numberOfMessages(),
'stream' => $_GET['stream_name'],
'time_updates' => array(),
);
// Get the times to update to the current time.
if (!empty($_REQUEST['uaids'])) {
$uaids = explode(',', $_REQUEST['uaids']);
$result = db_query("SELECT uaid, timestamp FROM {heartbeat_activity} WHERE uaid IN(:placeholders) ", array(
':placeholders' => $uaids,
));
foreach ($result as $row) {
$json['time_updates'][$row->uaid] = _theme_time_ago($row->timestamp);
}
}
drupal_json_output($json);
return;
}