function heartbeat_block in Heartbeat 6.4
Same name and namespace in other branches
- 6.2 heartbeat.module \heartbeat_block()
- 6.3 heartbeat.module \heartbeat_block()
Implementation of hook_blocks().
File
- ./
heartbeat.module, line 514
Code
function heartbeat_block($op = 'list', $delta = 0, $edit = array()) {
if (!variable_get('heartbeat_enabled', 1)) {
return FALSE;
}
$access_types = variable_get('heartbeat_access_types', array());
if ($op == 'list') {
// A block foreach access type
foreach ($access_types as $key => $access_type) {
$blocks[$key]['info'] = drupal_ucfirst($access_type['name']);
$blocks[$key]['cache'] = BLOCK_CACHE_PER_USER | BLOCK_CACHE_PER_PAGE;
}
return $blocks;
}
elseif ($op == 'view') {
if (!user_access('view heartbeat messages')) {
return FALSE;
}
// Message streams for each access type
if (variable_get('heartbeat_show_user_profile_messages_' . drupal_strtolower($delta), 1) && arg(0) == 'user' && is_numeric(arg(1))) {
$context = heartbeat_stream_view($delta, FALSE, 0, FALSE, heartbeat_user_load(arg(1)));
}
else {
// Check if the block is set for profile pages and if we are on a profile page.
if (variable_get('heartbeat_show_node_author_messages_' . drupal_strtolower($delta), 1)) {
if (arg(0) == 'node' && is_numeric(arg(1)) && function_exists('is_content_profile')) {
$node = node_load(arg(1));
if (is_content_profile($node->type)) {
$context = heartbeat_stream_view($delta, FALSE, 0, FALSE, heartbeat_user_load($node->uid));
}
}
}
$context = heartbeat_stream_view($delta);
}
if (isset($context)) {
$messages = $context
->execute();
if (variable_get('heartbeat_debug', 0) && $context
->hasErrors()) {
drupal_set_message(implode('<br />', $context
->getErrors()), 'warning');
}
$heartbeatAccess = $context
->getState();
$block['subject'] = t($heartbeatAccess->stream->title);
$link = '';
if ($context
->hasMoreMessages(FALSE)) {
$last_message = end($messages);
$link = theme('heartbeat_stream_more_link', $heartbeatAccess, $last_message->timestamp, FALSE);
}
$block['content'] = theme('heartbeat_block', $messages, $heartbeatAccess, $link);
return $block;
}
}
elseif ($op == 'configure') {
$realname = isset($access_types[$delta]['realname']) ? $access_types[$delta]['realname'] : $access_types[$delta]['class'];
$form['items'] = array(
'#type' => 'fieldset',
'#title' => t('Automatically Determine Target User'),
'#description' => t('By default heartbeat will show activity in relation to the currently logged in user. Use these options to use a user determined by the context of the content being viewed.'),
);
$form['items']['user_profile'] = array(
'#type' => 'checkbox',
'#title' => t('Show activity for the displayed user on the user profile page'),
'#description' => t('<strong>When viewing core user profile pages</strong>, the messages will be shown in relation to the user profile.'),
'#default_value' => variable_get('heartbeat_show_user_profile_messages_' . drupal_strtolower($realname), 1),
);
$form['items']['node_author'] = array(
'#type' => 'checkbox',
'#title' => t('Show activity for author of the displayed profile node'),
'#description' => t('<strong>When viewing nodes</strong>, the messages will be shown in relation to the node author of the profile node page.'),
'#default_value' => variable_get('heartbeat_show_node_author_messages_' . drupal_strtolower($realname), 0),
);
return $form;
}
elseif ($op == 'save') {
$realname = isset($access_types[$delta]['realname']) ? $access_types[$delta]['realname'] : $access_types[$delta]['class'];
variable_set('heartbeat_show_user_profile_messages_' . drupal_strtolower($realname), $edit['user_profile']);
variable_set('heartbeat_show_node_author_messages_' . drupal_strtolower($realname), $edit['node_author']);
}
}