'activity', 'title' => t('activity'), 'callback' => 'activity_page', 'callback arguments' => array(arg(1)), 'access' => user_access('view activity'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'activity/feed', 'callback' => 'activity_feed', 'callback arguments' => array(arg(2)), 'access' => user_access('view activity'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/settings/activity', 'title' => t('Activity Settings'), 'description' => t('Customize what will display on your users activity page.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('activity_admin_settings'), 'access' => user_access('administer site configuration'), ); $items[] = array( 'path' => 'admin/settings/activity/implements', 'title' => t('Choose modules'), 'callback' => 'activity_admin_settings', 'access' => user_access('administer site configuration'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/settings/activity/tokens', 'title' => t('Choose tokens'), 'callback' => 'drupal_get_form', 'callback arguments' => array('activity_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); } return $items; } /** * Admin section */ function activity_admin_settings() { foreach (module_implements('activity_info') as $module) { $modules[] = module_invoke($module, 'activity_info'); } if (!empty($modules[0])) { foreach ($modules as $module) { if (!empty($module)) { switch (arg(3)) { case 'tokens': if (variable_get('activity_'. $module['name'] .'_module', 0) == 1) { $tokens = array(); foreach ($module['tokens'] as $token => $desc) { $tokens[] = '['. $token .']: '. $desc; } $form['activity_'. $module['name'] .'_token'] = array( '#type' => 'fieldset', '#title' => $module['name'], '#collapsible' => true, '#collapsed' => true, '#description' => t('Available tokens') . theme('item_list', $tokens), ); foreach ($module['ops'] as $op) { foreach ($module['types'] as $type => $name) { if (variable_get('activity_'. $module['name'] .'_'. $type, 0) == 1) { $form['activity_'. $module['name'] .'_token']['activity_'. $module['name'] .'_'. $op .'_'. $type .'_token'] = array( '#type' => 'textfield', '#title' => t($op .' '. $name), '#default_value' => variable_get('activity_'. $module['name'] .'_'. $op .'_'. $type .'_token', ''), ); } } if (empty($module['types'])) { $form['activity_'. $module['name'] .'_token']['activity_'. $module['name'] .'_'. $op .'_token'] = array( '#type' => 'textfield', '#title' => t($op), '#default_value' => variable_get('activity_'. $module['name'] .'_'. $op .'_token', ''), ); } } } break; default: $form['activity_message_limit'] = array( '#type' => 'textfield', '#title' => 'Message Limit', '#description' => t('Set a limit for how many messages display on the activity display.'), '#default_value' => variable_get('activity_message_limit', 20), ); $form['activity_'. $module['name']] = array( '#type' => 'fieldset', '#title' => $module['name'], '#collapsible' => true, '#collapsed' => false, ); $form['activity_'. $module['name']]['activity_'. $module['name'] .'_module'] = array( '#type' => 'checkbox', '#title' => $module['name'], '#default_value' => variable_get('activity_'. $module['name'] .'_module', 0), '#description' => t('Check to enable activity tracking for this module.'), ); if (!empty($module['types'])) { $form['activity_'. $module['name']]['activity_'. $module['name'] .'_type'] = array( '#type' => 'fieldset', '#title' => t('activity types'), '#collapsible' => true, '#collapsed' => true, '#description' => t('Check to enable activity tracking for this type of activity.'), ); foreach ($module['types'] as $type => $name) { $form['activity_'. $module['name']]['activity_'. $module['name'] .'_type']['activity_'. $module['name'] .'_'. $type] = array( '#type' => 'checkbox', '#title' => $name, '#default_value' => variable_get('activity_'. $module['name'] .'_'. $type, 0), ); } } break; } } } } else { $form = array(); drupal_set_message('No supported modules enabled. Check the '. l('Activity section', 'admin/build/modules') .' for supported modules.'); } return system_settings_form($form); } /** * function to get all buddy activity * @returns array of activity */ function activity_buddy_activity($account_id) { global $user; $buddies = array(); $buddy_activity = array(); // took activity_account from here $account = activity_account($account_id); switch ($_GET['who']) { case 'me': $me['uid'] = $user->uid; $me['name'] = $user->name; $me['mail'] = $user->mail; $me['online'] = 1; array_push($buddies, $me); break; case 'friends': // find who current user's buddies are = obj // $account must be int $buddies = buddylist_get_buddies($account); break; default: // find who current or viewed user's buddies are = obj $buddies = buddylist_get_buddies($account); // if looking at own friend activities, include own activities $q = explode('/', $_GET['q']); if (!is_numeric($q[1]) || $q[1]==$user->uid) { // add current user to list of buddies $me['uid'] = $user->uid; $me['name'] = $user->name; $me['mail'] = $user->mail; $me['online'] = 1; $buddies[$user->uid] = $me; } break; } // see what activity each buddy has done if (!empty($buddies)) { foreach ($buddies as $buddy) { $query = db_query(db_rewrite_sql("SELECT * FROM {activity} a WHERE a.uid = %d ORDER BY a.timestamp DESC", 'a', 'aid', array('uid' => $buddy['uid'])), $buddy['uid']); while ($row = db_fetch_object($query)) { // appending count to make the time stamp unique for sorting purposes $buddy_activity[$row->timestamp . $count] = $row; $count++; } } } return $buddy_activity; } /** * -- activity account -- * find what user we're getting buddy activity for * @param uid * @return a user object */ function activity_account($account_to_load) { // if we're on a user profile page, make sure we load that user $q = explode('/', $_GET['q']); if (is_numeric($q[1])) { $account = user_load(array('uid' => $q[1])); } $account = $account->uid ? $account->uid : $account_to_load; if (!$account) { // there was no # passed from 'q' or $account_to_load global $user; $account = $user; } return $account; } /** * create a block for display * @param op * @param delta * @returns block HTML */ function activity_block($op = 'list', $delta = 0) { global $user; if ($op == 'list') { $block[0]['info'] = t('Friend Activity'); return $block; } elseif ($op == 'view') { $block['content'] = activity_page($user->uid); return $block; } } /** * Menu callback to display the records in a page */ function activity_page($uid) { $buddy_activity = activity_buddy_activity($uid); arsort($buddy_activity); $count = 0; if (!empty($buddy_activity)) { foreach ($buddy_activity as $ba) { if ($count < variable_get('activity_message_limit', 20)) { $offset = (strftime("%j") + strftime("%Y") * 365) - (strftime("%j", $ba->timestamp) + strftime("%Y", $ba->timestamp) * 365); $timeset = ($offset > 0 && $offset != $prev_offset) ? '