array('add' => t('Add'), 'remove' => t('Remove')), 'types' => array('buddylist' => t('Buddylist')), 'roles' => array( 'author' => array( '#name' => t('Author'), '#description' => t('The person who performed the action.'), '#default' => '', ), // This is what corresponds to ACTIVITY_ALL 'all' => array( '#name' => t('All'), '#description' => t('The general public.'), '#default' => '', ), ), ); } function buddylistactivity_token_list($type = 'buddylistactivity') { if ($type == 'buddylistactivity') { $tokens['buddylistactivity']['user-name'] = t('Person who added a buddy'); $tokens['buddylistactivity']['user-link'] = t("Link to the adder's profile"); $tokens['buddylistactivity']['buddy-name'] = t("Person who has been added"); $tokens['buddylistactivity']['buddy-link'] = t("Link to the addee's profile"); $tokens['buddylistactivity'] += buddylist_translation(); return $tokens; } } function buddylistactivity_token_values($type, $data = NULL, $options = array()) { static $authors; if ($type == 'buddylistactivity' && !empty($data)) { if (!isset($authors[$data['user-id']])) { $author = activity_user_load($data['user-id']); $authors[$data['user-id']] = array('uid' => $author->uid, 'name' => $author->name, 'link' => theme('username', $author)); } $author = $authors[$data['user-id']]; if (!isset($authors[$data['buddy-id']])) { $buddy = activity_user_load($data['buddy-id']); $authors[$data['buddy-id']] = array('uid' => $buddy->uid, 'name' => $buddy->name, 'link' => theme('username', $buddy)); } $buddy = $authors[$data['buddy-id']]; $tokens = array( 'user-name' => $author['name'], 'user-link' => $author['link'], 'buddy-name' => $buddy['name'], 'buddy-link' => $buddy['link'], ); $tokens += buddylist_translation(); return $tokens; } } /** * Implementation of hook_buddylist_api() * $arg[0] = operation * $arg[1] = user being added/removed * $arg[2] = user doing the add/remove */ function buddylistactivity_buddylist() { $args = func_get_args(); $action = $args[0]; $type = 'buddylist'; $user = user_load(array('uid' => $args[2]->uid)); $data = array( 'user-id' => $user->uid, 'buddy-id' => $args[1]->uid, ); $target_users_roles = array( ACTIVITY_ALL => 'all', $user->uid => 'author', ); activity_insert('buddylistactivity', $type, $action, $data, $target_users_roles); } function buddylistactivity_block($op = 'list', $delta = 0, $edit = array()) { global $user; if ($op == 'list') { $block['buddies']['info'] = t("Activity - My buddies: show activities of current user's buddies."); return $block; } elseif ($op == 'configure') { $form['items'] = array( '#type' => 'select', '#title' => t('Number of items'), '#default_value' => variable_get('activity_block_'. $delta, 5), '#options' => drupal_map_assoc(range(1, 50)), ); return $form; } elseif ($op == 'save') { variable_set('activity_block_'. $delta, $edit['items']); } elseif ($op == 'view') { switch ($delta) { case 'buddies': if (user_access('view own activity')) { $uids = array_keys(buddylist_get_buddies($user->uid, 'uid')); $activity = activity_get_activity((empty($uids) ? $user->uid : $uids), NULL, 5); if ($count = count($activity)) { if ($count > variable_get('activity_block_'. $delta, 5)) { $more_link = theme('activity_more_link', 'activity'); array_pop($activity); } $activites = array(); foreach ($activity as $item) { $activities[] = theme('activity', activity_token_replace($item), $item); } return array( 'subject' => t('My @buddies\' activity', buddylist_translation()), 'content' => theme('activity_block', $activities, $more_link)); } } break; } } } function buddylistactivity_menu($may_cache) { $items = array(); global $user; if ($may_cache) { $items[] = array( 'path' => 'activity/buddies', 'title' => t('My buddies\' activity'), 'callback' => 'buddylistactivity_page', 'access' => $user->uid, 'type' => MENU_LOCAL_TASK, 'access' => user_access('view own activity'), ); } return $items; } function buddylistactivity_page($page = 'buddies') { global $user; if ($page == 'buddies') { if (user_access('view own activity')) { $uids = array_keys(buddylist_get_buddies($user->uid, 'uid')); $activities = activity_get_activity((empty($uids) ? $user->uid : $uids), NULL, 20); $table = activity_table($activities); return theme('activity_page', $activities, $table); } } }