View source
<?php
function heartbeat_views_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'heartbeat_views'),
);
}
function heartbeat_views_views_bulk_operations_object_info() {
return array(
'heartbeat_activity' => array(
'type' => 'heartbeat_activity',
'base_table' => 'heartbeat_activity',
'load' => 'heartbeat_load_message_instance',
'title' => 'message',
'oid' => 'uaid',
'access' => '_heartbeat_message_has_access',
),
);
}
function heartbeat_views_action_info() {
return array(
'heartbeat_activity_delete_action' => array(
'description' => t('Delete activity'),
'type' => 'heartbeat_activity',
'configurable' => FALSE,
'hooks' => array(
'heartbeat_activity' => array(
'delete',
),
),
),
);
}
function heartbeat_activity_delete_action($heartbeatactivity, $context = array()) {
if (_heartbeat_message_delete_access($heartbeatactivity->uaid)) {
_heartbeat_activity_delete($heartbeatactivity->uaid);
}
}
function heartbeat_views_views_pre_view(&$view, &$display_id = 0, &$args = NULL) {
if ($view->base_table == 'heartbeat_activity' && !empty($view->result)) {
_heartbeat_render_view($view);
$view->rendered = TRUE;
}
}
function heartbeat_views_views_pre_render(&$view) {
if ($view->base_table == 'heartbeat_activity' && !empty($view->result) && empty($view->rendered)) {
_heartbeat_render_view($view);
$view->rendered = TRUE;
}
}
function heartbeat_views_views_plugins() {
return array(
'module' => 'views',
'row' => array(
'heartbeat_rss' => array(
'title' => t('Heartbeat'),
'help' => t('Display the heartbeat with standard view.'),
'handler' => 'views_plugin_row_heartbeat_rss',
'path' => drupal_get_path('module', 'heartbeat_views'),
'theme' => 'views_view_row_rss',
'base' => array(
'heartbeat_activity',
),
'uses options' => TRUE,
'type' => 'feed',
'help topic' => 'style-heartbeat-rss',
),
),
);
}
function _heartbeat_render_view(&$view) {
$name = $view->name . '_' . $view->current_display;
$stream = isset($view->filter['access_type']->stream) ? $view->filter['access_type']->stream : new stdClass();
if ($view->style_plugin
->uses_fields()) {
$field_handlers = array();
foreach ($view->field as $fieldname => $handler) {
$fieldalias = isset($handler->field_alias) && $handler->field_alias != 'unknown' ? $handler->field_alias : $handler->real_field;
$field_handlers[$fieldname] = $fieldalias;
}
}
$results = array();
foreach ($view->result as $row) {
if (!isset($stream->messages_denied[$row->message_id])) {
$template = new HeartbeatMessageTemplate($row->hid, $row->message_id, $row->message_orig, $row->message_concat_orig, $row->concat_args);
$template->perms = $row->perms;
$template->custom = $row->custom;
$template->description = $row->description;
$template
->set_variables($row->variables_orig);
$template
->set_attachments($row->attachments);
$template
->set_roles(isset($template->concat_args['roles']) ? $template->concat_args['roles'] : array());
$heartbeatactivity = new HeartbeatActivity($row, $template);
$results[$row->uaid]->count = 1;
if (!empty($field_handlers)) {
foreach ($field_handlers as $fieldname => $fieldalias) {
if ($fieldname == 'counter') {
continue;
}
$heartbeatactivity->{$fieldalias} = $row->{$fieldalias};
}
}
$uses_ds = $view->style_plugin
->uses_row_plugin() && $view->style_plugin->row_plugin->definition['module'] == 'ds';
if ($uses_ds) {
$heartbeatactivity->content['message'] = $heartbeatactivity->message;
$heartbeatactivity->content['widgets'] = _theme_heartbeat_widgets($heartbeatactivity);
$heartbeatactivity->content['time_info'] = theme('heartbeat_time_ago', $heartbeatactivity);
$heartbeatactivity->content['buttons'] = theme('heartbeat_buttons', $heartbeatactivity);
}
$results[$row->uaid] = $heartbeatactivity;
}
}
if (isset($view->pager['items_per_page'])) {
$stream->limit_sql = $view->pager['items_per_page'];
}
$result = _heartbeat_group_views_messages($name, $results, $stream);
$view->result = $result;
}
function _heartbeat_group_views_messages($name, $messages, $stream) {
heartbeat_include('HeartbeatParser');
$heartbeat = HeartbeatParser::instantiate($name);
if (!empty($stream->grouping_seconds)) {
$timespan = $stream->grouping_seconds;
}
else {
$timespan = variable_get('heartbeat_activity_grouping_seconds', 7200);
}
$heartbeat
->set_timespan_gap($timespan);
$heartbeat
->build_sets($messages);
$heartbeat
->merge_sets();
$messages = $heartbeat
->get_messages();
$num_total_messages = count($messages);
$messages = array_values(array_slice($messages, 0, $stream->limit_sql));
if (empty($stream->name)) {
heartbeat_include('heartbeatstream', 'heartbeat');
heartbeat_include('publicheartbeat', 'heartbeat');
$heartbeatAccess = new PublicHeartbeat(new HeartbeatStream(heartbeat_stream_load('publicheartbeat')));
}
else {
$class = $stream->name;
heartbeat_include($stream->name, $stream->module);
$heartbeatAccess = new $class($stream);
}
$hook = 'heartbeat_load';
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
$function($messages, $heartbeatAccess);
}
$hook = 'heartbeat_theme_alter';
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
$result = $function($messages, $heartbeatAccess);
}
$hook = 'heartbeat_view';
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
$function($messages, $heartbeatAccess);
}
return $messages;
}