function heartbeat_block in Heartbeat 6.3
Same name and namespace in other branches
- 6.4 heartbeat.module \heartbeat_block()
- 6.2 heartbeat.module \heartbeat_block()
Implementation of hook_blocks()
File
- ./
heartbeat.module, line 250
Code
function heartbeat_block($op = 'list', $delta = 0, $edit = array()) {
if (!user_access('view heartbeat messages') || !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'] = ucfirst($access_type['name']);
$blocks[$key]['cache'] = BLOCK_CACHE_PER_USER;
}
return $blocks;
}
else {
if ($op == 'view') {
// Message streams for each access type
if (isset($access_types[$delta])) {
if ($access_types[$delta]['module'] != 'heartbeat') {
heartbeat_include($access_types[$delta]['class'], $access_types[$delta]['module']);
}
$accesstype = $access_types[$delta]['class'];
$context = new HeartbeatMessageBuilder(new $accesstype());
if (!$context
->hasErrors()) {
$messages = $context
->execute();
$block['subject'] = t($access_types[$delta]['name']);
$block['content'] = theme('heartbeat_list', $messages);
return $block;
}
}
}
else {
if ($op == 'configure') {
$class = strtolower($access_types[$delta]['class']);
$form['items'] = array(
'#type' => 'checkbox',
'#title' => t('Show activity for the displayed user on the user profile page'),
'#description' => t('By default heartbeat will show activity in relation to the
currently logged in user. With this setting enabled and only on the user profile page,
the messages will be shown in relation to the user profile.'),
'#default_value' => variable_get('heartbeat_show_user_profile_messages_' . $class, 0),
);
return $form;
}
else {
if ($op == 'save') {
$class = strtolower($access_types[$delta]['class']);
variable_set('heartbeat_show_user_profile_messages_' . $class, $edit['heartbeat_show_user_profile_messages_' . $class]);
}
}
}
}
}