function activity_block in Activity 6
Same name and namespace in other branches
- 5.4 activity.module \activity_block()
- 5 activity.module \activity_block()
- 5.2 activity.module \activity_block()
- 5.3 activity.module \activity_block()
Implementation of hook_block().
File
- ./
activity.module, line 766 - activity.module
Code
function activity_block($op = 'list', $delta = 0, $edit = array()) {
global $user;
switch ($op) {
case 'list':
$block['my']['info'] = t("Activity (Mine): show the current user's activity.");
$block['all']['info'] = t("Activity (All): show all recent activity");
$block['user']['info'] = t("Activity (User): show activity of the user being viewed");
return $block;
break;
case 'configure':
$form['items'] = array(
'#type' => 'select',
'#title' => t('Number of activity items to display'),
'#default_value' => variable_get('activity_block_' . $delta, 5),
'#options' => drupal_map_assoc(range(1, 50)),
);
return $form;
break;
case 'save':
variable_set('activity_block_' . $delta, $edit['items']);
break;
case 'view':
switch ($delta) {
case 'my':
if (user_access('view own activity')) {
// Grab the number of requested activities plus one. We use this one
// to determine whether or not to show the "more" link and only display
// the correct number of items.
$activity = activity_get_activity($user->uid, NULL, variable_get('activity_block_' . $delta, 5) + 1);
if ($count = count($activity)) {
drupal_add_css(drupal_get_path('module', 'activity') . '/activity.css');
if ($count > variable_get('activity_block_' . $delta, 5)) {
$more_link = theme('activity_more_link', 'activity/mine');
array_pop($activity);
}
$activities = array();
foreach ($activity as $item) {
$item['delete-link'] = activity_delete_link($item);
$activities[] = theme('activity', activity_token_replace($item), $item);
}
return array(
'subject' => t('My activity'),
'content' => theme('activity_block', $activities, $more_link),
);
}
}
break;
case 'all':
if (user_access('view public activity')) {
$activity = activity_get_activity(ACTIVITY_ALL, NULL, variable_get('activity_block_' . $delta, 5) + 1);
if ($count = count($activity)) {
drupal_add_css(drupal_get_path('module', 'activity') . '/activity.css');
if ($count > variable_get('activity_block_' . $delta, 5)) {
$more_link = theme('activity_more_link', 'activity');
array_pop($activity);
}
$activities = array();
foreach ($activity as $item) {
$item['delete-link'] = activity_delete_link($item);
$activities[] = theme('activity', activity_token_replace($item), $item);
}
return array(
'subject' => t('Recent activity'),
'content' => theme('activity_block', $activities, $more_link),
);
}
}
break;
case 'user':
if (user_access('view public activity') && arg(0) == "user" && is_numeric(arg(1))) {
$uid = arg(1);
$author = activity_user_load($uid);
$activity = activity_get_activity($uid, NULL, variable_get('activity_block_' . $delta, 5) + 1);
if ($count = count($activity)) {
drupal_add_css(drupal_get_path('module', 'activity') . '/activity.css');
if ($count > variable_get('activity_block_' . $delta, 5)) {
$more_link = theme('activity_more_link', 'activity');
array_pop($activity);
}
$activities = array();
foreach ($activity as $item) {
$item['delete-link'] = activity_delete_link($item);
$activities[] = theme('activity', activity_token_replace($item), $item);
}
return array(
'subject' => t("@username's activity", array(
'@username' => $author->name,
)),
'content' => theme('activity_block', $activities, $more_link),
);
}
}
break;
}
break;
}
}