array( 'add' => t('Add'), 'remove' => t('Remove'), 'add_request' => t('Request'), 'request_deny' => t('Deny'), 'cancel_request' => t('Cancel'), ), 'types' => array('buddylist' => t('Buddylist')), 'roles' => array( 'author' => array( '#name' => t('Author'), '#description' => t('The person who performed the action.'), '#default' => array( 'add' => t('[author] added [buddy] to [possessive] [buddylist-link]'), 'remove' => t('[author] removed [buddy] from [possessive] [buddylist-link]'), 'add_request' => t('[author] asked [buddy] to be added to [possessive] [buddylist-link]'), 'request_deny' => t('[author] denied [buddy]\'s request to be added to [possessive] [buddylist-link]'), 'cancel_request' => t('[author] cancelled [possessive] request to add [buddy] to [possessive] [buddylist-link]'), ), ), // This is what corresponds to ACTIVITY_ALL 'all' => array( '#name' => t('All'), '#description' => t('The general public.'), '#default' => array( 'add' => t('[author-all] added [buddy-all] to their [buddylist-link]'), 'remove' => t('[author-all] removed [buddy-all] from their [buddylist-link]'), 'add_request' => t('[author-all] asked [buddy-all] to be added to their [buddylist-link]'), 'request_deny' => t('[author-all] denied [buddy-all]\'s request to be added to their [buddylist-link]'), 'cancel_request' => t('[author-all] cancelled their request to add [buddy-all] to their [buddylist-link]'), ), ), ), ); } /** * Token module integration. Defines available default tokens. */ function buddylist2activity_token_list($type = 'all') { if ($type == 'buddylist2activity') { $tokens['buddylist2activity'] = array( 'possessive' => t('Possessive pronoun indicating whose buddylist ("yours" or "theirs")'), 'buddylist-link' => t("Link to the user's buddylist"), 'buddy-uid' => t('User Id of the person who has been added or removed'), 'buddy' => t('Person who has been added or removed (used for "author" role)'), 'buddy-all' => t('Person who has been added or removed (used for "all" role)'), 'buddy-name' => t("The name of the person who has been added or removed"), ); $tokens['buddylist2activity'] += buddy_api_translation(); return $tokens; } } /** * Token module integration. Defines available default token values. */ function buddylist2activity_token_values($type, $data = NULL, $options = array()) { global $user; static $authors; if ($type == 'buddylist2activity' && !empty($data)) { if (!isset($authors[$data['buddy-uid']])) { $authors[$data['buddy-uid']] = activity_user_load($data['buddy-uid']); } $buddy = $authors[$data['buddy-uid']]; $data['possessive'] = ($user->uid == $data['uid']) ? t('your') : t('their'); $data['buddy'] = theme('activity_username', $buddy, TRUE); $data['buddy-all'] = theme('activity_username', $buddy); $data['buddy-name'] = $buddy->name; $data['buddylist-link'] = l(t('@buddylist', buddy_api_translation()), 'buddylist/'. $data['uid']); $data += buddy_api_translation(); return $data; } } /** * Implementation of hook_buddy_api(). * @param $op: string, operation: add/delete/... * @param $userA: User Object A, for example logged in user * @param $userB: User Object B, [proper] buddy of User A * @param $buddyinfo: array, additional informations */ function buddylist2activity_buddy_api($op, $user, $buddy, $buddyinfo) { $type = 'buddylist'; if ($op == 'request_accept') { $op = 'add'; } // Check if both type and operation are // enabled for activity. If not then stop here if (!in_array($type, variable_get('buddylist2activity_token_types', array($type)), TRUE) || !in_array($op, variable_get('buddylist2activity_op_types', array($op)), TRUE)) { return FALSE; } // Privacy setting check if (activity_user_privacy_optout($user)) { return FALSE; } $data = array( 'buddy-uid' => $buddy->uid, ); $target_users_roles = array( ACTIVITY_ALL => 'all', $user->uid => 'author', ); activity_insert($user->uid, 'buddylist2activity', $type, $op, $data, $target_users_roles); } /** * Implementation of hook_block(). */ function buddylist2activity_block($op = 'list', $delta = 0, $edit = array()) { global $user; switch ($op) { case 'list': $block['buddies']['info'] = t("Activity - My buddies: show activities of current user's buddies."); return $block; case '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; case 'save': variable_set('activity_block_'. $delta, $edit['items']); break; case 'view': switch ($delta) { case 'buddies': if (user_access('view own activity')) { $uids = array_keys(buddy_api_get_buddies($user->uid, 'uid')); if (!$uids) { return FALSE; } $activity = array(); $activity = activity_get_activity($uids, NULL, variable_get('activity_block_'. $delta, 5) + 1); drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css'); if (count($activity) > variable_get('activity_block_'. $delta, 5)) { $more_link = theme('activity_more_link', 'activity/buddies'); array_pop($activity); } $activities = array(); foreach ($activity as $item) { $activities[] = theme('activity', activity_token_replace($item), $item) . activity_delete_link($item); } return array( 'subject' => t('My @buddies\' activity', buddy_api_translation()), 'content' => theme('activity_block', $activities, $more_link) ); } break; } } } /** * Implementation of hook_menu(). */ function buddylist2activity_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'activity/buddies', 'title' => t('My buddies\' activity'), 'callback' => 'buddylist2activity_page', 'type' => MENU_LOCAL_TASK, 'access' => user_access('view own activity'), ); } return $items; } /** * buddylist2 activity page callback */ function buddylist2activity_page($page = 'buddies') { global $user; drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css'); if ($page == 'buddies') { if (user_access('view own activity')) { $uids = array_keys(buddy_api_get_buddies($user->uid, 'uid')); $activities = array(); if ($uids) { $activities = activity_get_activity($uids, NULL, variable_get('activity_page_pager', 20)); } $table = theme('activity_table', $activities); return theme('activity_page', $activities, $table); } } }