t('buddy'), '@Buddy' => t('Buddy'), '@buddylist' => t('buddylist'), '@Buddylist' => t('Buddylist'), '@buddies' => t('buddies'), '@Buddies' => t('Buddies'), '@buddyof' => t('buddy of'), '@Buddyof' => t('Buddy of'), ); return variable_get('buddylist_translation', $translations); } /** * Implementation of hook_help */ function buddylist_help($section) { switch ($section) { case 'admin/help#buddylist': $output = t("
@Buddy list enables users to keep a list of @buddies from their social network in their user account. Users can also track what their @buddies are posting to the site. Furthermore, they can track their @buddies' @buddies and thereby explore their social network.
If the administrator has enabled the profile module, users can add @buddies via their @buddies' user profiles. On the \"View\" tab of each user's profile, there is a \"@Buddylist\" section. Select the 'add @buddy' action to add the user to your @buddylist. If a user is already in your @buddylist, the 'delete' action will remove the @buddy. Administrators can also enable the @buddylist block. This block allows you to see a list of your @buddies. If the Friends Of A Friend (FOAF) module is enabled, it will be possible to share @buddylists with other FOAF-aware social networking applications.
You can:
For more information, read the configuration and customization handbook Buddylist page
", array('@userprofiles' => url('profile'), '@setaccesspermissions' => url('admin/user/access'), '@blockadministration' => url('admin/build/block'), '@buddylistsettings' => url('admin/settings/buddylist') ) + buddylist_translation()); return $output; } } /** * Implementation of hook_perm */ function buddylist_perm() { return array('maintain buddy list', 'view buddy lists'); } /** * Implementation of hook_menu */ function buddylist_menu($may_cache) { global $user; $items = array(); $id = is_numeric(arg(1)) ? arg(1) : $user->uid; if ($may_cache) { // buddylist settings page $items[] = array( 'path' => 'admin/settings/buddylist', 'title' => t('Buddylist'), // Note that this isn't translated on purpose since it is for the admin 'description' => t('Buddylist configuration options for blocks, email, etc.'), 'callback' => 'drupal_get_form', 'callback arguments' => 'buddylist_admin_settings', 'access' => user_access('administer site configuration'), ); // my buddylist menu item $items[] = array( 'path' => 'buddylist', 'title' => t('My @buddylist', buddylist_translation()), 'access' => (user_access('maintain buddy list') && $id), 'callback' => 'buddylist_buddylisting_page', 'callback arguments' => array($user->uid, 'buddies'), ); } else { // 'edit access' only granted to user's own buddy list or to administrative users $editAccess = ( ($id == $user->uid && user_access('maintain buddy list') && $user->uid) || user_access('administer users')); $approval_required = variable_get('buddylist_require_approval', 0); $items[] = array( 'path' => 'buddy/add', 'title' => t('Add to @buddylist', buddylist_translation()), 'access' => $editAccess, 'callback' => 'drupal_get_form', 'callback arguments' => array('buddylist_addbuddy', arg(2)), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'buddy/delete', 'title' => t('Delete from @buddylist', buddylist_translation()), 'access' => $editAccess, 'callback' => 'drupal_get_form', 'callback arguments' => array('buddylist_deletebuddy', arg(2)), 'type' => MENU_CALLBACK, ); // 'view only' tabs $viewAccess = (($id == $user->uid && user_access('maintain buddy list')) || user_access('view buddy lists')); // If buddylist approval is required, then upon approval, both parties become buddies of each other. // So, in effect, idea 'buddyof' becomes redundant. if (!$approval_required) { $items[] = array( 'path' => 'buddylist/'. $id .'/buddies', 'title' => t('@Buddies', buddylist_translation()), 'access' => $viewAccess, 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1, 'callback arguments' => array($id) ); $items[] = array( 'path' => 'buddylist/'. $id .'/buddyof', 'title' => t('@Buddyof', buddylist_translation()), 'access' => $viewAccess, 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_LOCAL_TASK, 'weight' => 1, 'callback arguments' => array($id, 'buddyof') ); } // subtabs $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/list', 'title' => t('@Buddylist', buddylist_translation()), 'access' => $viewAccess, 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1, 'callback arguments' => array($id), ); $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/recent', 'title' => t('Recent posts'), 'access' => ($viewAccess && module_exists('tracker')), 'callback' => 'buddylist_buddiesrecent_page', 'type' => MENU_LOCAL_TASK, 'weight' => 3, 'callback arguments' => array($id), ); if (variable_get('buddylist_buddygroups', FALSE)) { $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/groups/view', 'title' => t('View groups'), 'access' => $viewAccess, 'callback' => 'buddylist_buddiesgroups_page', 'type' => MENU_LOCAL_TASK, 'weight' => 5, 'callback arguments' => array($id), ); $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/groups/edit', 'title' => t('Edit groups'), 'access' => $editAccess, 'callback' => 'buddylist_buddiesgroups_edit', 'type' => MENU_LOCAL_TASK, 'weight' => 6, 'callback arguments' => array($id), ); } // sub-subtabs if ($approval_required && $editAccess) { $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/requests', 'title' => t('Pending requests'), 'access' => $editAccess, 'callback' => 'theme', 'type' => MENU_LOCAL_TASK, 'weight' => 0, 'callback arguments' => array('buddylist_pending_requests', $id) ); $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/requested/accept', 'title' => t('Accept Request'), 'access' => $editAccess, 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => array('buddylist_pending_requested_accept',$id), ); $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/requested/deny', 'title' => t('Deny Request'), 'access' => $editAccess, 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => array('buddylist_pending_requested_deny',$id), ); $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/request/cancel', 'title' => t('Cancel Request'), 'access' => $editAccess, 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => array('buddylist_cancel_request',$id), ); } // other callbacks if ($id != $user->uid) { // This callback can interfere with the 'my buddylist' menu item, // so we only load it if the user is viewing another user's list. $items[] = array( 'path' => 'buddylist/'. $id, 'title' => t('@Buddylist', buddylist_translation()), 'access' => (($viewAccess || $editAccess) && $id), 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_CALLBACK, 'callback arguments' => array($id), ); } $items[] = array( 'path' => 'buddylist/'. $id .'/buddies/recent/feed', 'title' => t('Xml feed'), 'access' => $viewAccess, 'callback' => 'buddylist_buddyfeed', 'type' => MENU_CALLBACK, 'callback arguments' => array($id), ); } return $items; } /** * Buddylist administration settings page */ function buddylist_admin_settings() { $form['general'] = array( '#type' => 'fieldset', '#title' => t('General settings'), ); $form['general']['buddylist_require_approval'] = array( '#type' => 'radios', '#title' => t('Require approval'), '#default_value' => variable_get('buddylist_require_approval', 0), '#description' => t("Select 'Yes' if a user's request to be someone's @buddy should be approved by the other user first. Upon approval, both parties will be @buddies of each other.", buddylist_translation()), '#options' => array(1 => t('Yes'), 0 => t('No')) ); $form['general']['buddylist_buddygroups'] = array( '#type' => 'checkbox', '#title' => t('Enable @buddy groups', buddylist_translation()), '#description' => t('Enables @buddylist @buddy groups. Users will be able to create @buddy groups to manage their @buddies.', buddylist_translation()), '#default_value' => variable_get('buddylist_buddygroups', FALSE), ); // User profile page settings $form['profile_settings'] = array( '#type' => 'fieldset', '#title' => t('Profile page options'), ); $form['profile_settings']['buddylist_prof_buddies'] = array( '#type' => 'select', '#title' => t('Number of @buddies and users who\'ve added me', buddylist_translation()), '#default_value' => variable_get('buddylist_prof_buddies', 5), '#options' => drupal_map_assoc(range(0, 10)), '#description' => t('The default maximum number of @buddies and users who\'ve added me as a @buddy to display on a user\'s profile page.', buddylist_translation()), ); // TODO: move these to block settings $form['block_settings'] = array( '#type' => 'fieldset', '#title' => t('@Buddylist block options', buddylist_translation()), ); $form['block_settings']['buddylist_blocklisting_size'] = array( '#type' => 'select', '#title' => t("Number of @buddies to list in the user's @buddy block", buddylist_translation()), '#default_value' => variable_get('buddylist_blocklisting_size', 5), '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), '#description' => t('This setting controls the maximum number of @buddies displayed in a user\'s "@buddylist block" given that the "@buddylist block" is enabled in the !link.', array('!link' => l(t('block settings'), 'admin/build/block')) + buddylist_translation()), ); $form['block_settings']['buddylist_posts_block'] = array( '#type' => 'select', '#title' => t("Number of posts to list in the @buddies' recent posts block", buddylist_translation()), '#default_value' => variable_get('buddylist_posts_block', 7), '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), '#description' => t('This setting controls the maximum number of posts to display in a user\'s "@buddy recent posts" block given that the "@buddies\' recent posts" block is enabled in the !link.', array('!link' => l(t('block settings'), 'admin/build/block')) + buddylist_translation()), ); $form['block_settings']['buddylist_block_title'] = array( '#type' => 'textfield', '#title' => t('"My @buddies\' recent posts" block title', buddylist_translation()), '#default_value' => variable_get('buddylist_block_title', t("My @buddies' recent posts", buddylist_translation())), '#size' => 70, '#maxlength' => 128, '#description' => t('This will be the title for the recent @buddies post block. If none is specified, "My @buddies\' recent posts" will be used.', buddylist_translation()), ); $form['block_settings']['buddylist_status_block_title'] = array( '#type' => 'textfield', '#title' => t('"My @buddylist status" block title', buddylist_translation()), '#default_value' => variable_get('buddylist_status_block_title', t("My @buddylist status", buddylist_translation())), '#size' => 70, '#maxlength' => 128, '#description' => t('This will be the title for the @buddylist status block. If none is specified, "My @buddylist status" will be used.', buddylist_translation()), ); $form['block_settings']['buddylist_list_block_title'] = array( '#type' => 'textfield', '#title' => t('"My @buddies list" block title', buddylist_translation()), '#weight' => 1, '#default_value' => variable_get('buddylist_list_block_title', t('My @buddylist', buddylist_translation())), '#size' => 70, '#maxlength' => 128, '#description' => t('This will be the title for the "My @buddylist" block. If none is specified, "My @buddylist" will be used.', buddylist_translation()), ); $form['block_settings']['buddylist_block_if_no_buddies'] = array( '#type' => 'checkbox', '#title' => t('Show "My @buddies list" block even if @buddylist is empty', buddylist_translation()), '#weight' => 2, '#default_value' => variable_get('buddylist_block_if_no_buddies', FALSE), '#description' => t('If a user has no @buddies, the @buddy block can show a message.', buddylist_translation()), ); $form['block_settings']['buddylist_empty_text'] = array( '#type' => 'textarea', '#title' => t('Show this text in "My @buddies list" if @buddylist is empty', buddylist_translation()), '#weight' => 3, '#default_value' => variable_get('buddylist_empty_text', t(buddylist_empty_text_default(), buddylist_translation())), '#description' => t('If a user has no @buddies and the above checkbox is checked, this message is shown instead of a list.', buddylist_translation()), ); $form['mail'] = array( '#type' => 'fieldset', '#title' => t('email'), ); global $user; $macros = implode(', ', array_keys(buddylist_mail_replacements($user, $user))); $approval_macros = implode(', ', array_keys(buddylist_approval_mail_replacements($user, $user))); $form['mail']['buddylist_user_mail'] = array( '#type' => 'checkbox', '#title' => t('Allow users to turn off buddylist messages'), '#default_value' => variable_get('buddylist_user_mail', FALSE), '#description' => t('If you check this, users will have a new setting on their account edit page.'), ); $form['mail']['buddylist_send_add'] = array( '#type' => 'checkbox', '#title' => t('Send add messages'), '#default_value' => variable_get('buddylist_send_add', FALSE), ); $form['mail']['buddylist_add_subject'] = array( '#type' => 'textfield', '#title' => t('Added @buddy email subject', buddylist_translation()), '#default_value' => BUDDYLIST_ADD_SUBJECT, ); $form['mail']['buddylist_add_message'] = array( '#type' => 'textarea', '#title' => t('Added @buddy email message', buddylist_translation()), '#default_value' => variable_get('buddylist_add_message', buddylist_mail_add_default()), '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); $form['mail']['buddylist_send_remove'] = array( '#type' => 'checkbox', '#title' => t('Send remove messages'), '#default_value' => variable_get('buddylist_send_remove', FALSE), ); $form['mail']['buddylist_remove_subject'] = array( '#type' => 'textfield', '#title' => t('Removed @buddy email subject', buddylist_translation()), '#default_value' => BUDDYLIST_REMOVE_SUBJECT, ); $form['mail']['buddylist_remove_message'] = array( '#type' => 'textarea', '#title' => t('Removed @buddy email message', buddylist_translation()), '#default_value' => variable_get('buddylist_remove_message', buddylist_mail_remove_default()), '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); $form['mail']['buddylist_send_request'] = array( '#type' => 'checkbox', '#title' => t('Send request messages.'), '#description' => t('Check this box if you want users to receive an email when someone requests to be their buddy. This setting only has effect if approval is required to be on someone\'s buddylist.'), '#default_value' => variable_get('buddylist_send_request', FALSE) ); $form['mail']['buddylist_request_subject'] = array( '#type' => 'textfield', '#title' => t('@buddy request email subject', buddylist_translation()), '#default_value' => BUDDYLIST_REQUEST_SUBJECT, ); $form['mail']['buddylist_request_message'] = array( '#type' => 'textarea', '#title' => t('@buddy request email message', buddylist_translation()), '#default_value' => variable_get('buddylist_request_message', buddylist_mail_request_default()), '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); $form['mail']['buddylist_send_approval'] = array( '#type' => 'checkbox', '#title' => t('Send approval messages'), '#default_value' => variable_get('buddylist_send_approval', FALSE), '#description' => t('Check this box if you want users to receive an email to the requester when someone approves an add request. This setting only has effect if approval is required to be on someone\'s @buddylist.', buddylist_translation()) ); $form['mail']['buddylist_approval_subject'] = array( '#type' => 'textfield', '#title' => t('@buddy request email subject', buddylist_translation()), '#default_value' => BUDDYLIST_APPROVAL_SUBJECT, ); $form['mail']['buddylist_approval_message'] = array( '#type' => 'textarea', '#title' => t('@buddy approval email message', buddylist_translation()), '#default_value' => variable_get('buddylist_approval_message', buddylist_mail_approval_default()), '#description' => t('Replacement strings are: %macros', array('%macros' => $approval_macros)), ); return system_settings_form($form); } /** * Implementation of hook_user */ function buddylist_user($type, &$edit, &$thisuser, $category = NULL) { global $user; $output = array(); // show any buddylist notifications upon login and upon viewing own profile if (user_access('maintain buddy list') && (($type == 'login') || ($type == 'view') && ($thisuser->uid == $user->uid))) { buddylist_setmsg_received($thisuser); } if ($type == 'view') { if ($list = buddylist_get_buddylist($thisuser)) { $output[] = array('title' => t('@Buddies', buddylist_translation()), 'value' => $list, 'class' => 'buddylist'); } if ($list = buddylist_get_buddylist($thisuser, TRUE)) { $output[] = array('title' => t('@buddy of', buddylist_translation()), 'value' => $list, 'class' => 'buddyoflist'); } if ($actions = buddylist_get_buddy_actions($user, $thisuser)) { $output[] = array('title' => t('@Buddy actions', buddylist_translation()), 'value' => theme('item_list', $actions), 'class' => 'buddylist_actions'); } if(count($output) > 0) { return array(t('@Buddy List', buddylist_translation()) => $output); } } else if ($type == 'delete') { db_query("DELETE FROM {buddylist} WHERE uid = %d OR buddy = %d", $thisuser->uid, $thisuser->uid); db_query("DELETE FROM {buddylist_buddy_group} WHERE uid = %d OR buddy = %d", $thisuser->uid, $thisuser->uid); db_query("DELETE FROM {buddylist_groups} WHERE uid = %d", $thisuser->uid); db_query("DELETE FROM {buddylist_pending_requests} WHERE requester_uid = %d OR requestee_uid = %d", $thisuser->uid, $thisuser->uid); } else if ($type == 'load') { $thisuser->buddies = buddylist_get_buddies($thisuser->uid); } else if ($type == 'form' && $category == 'account' && variable_get('buddylist_user_mail', FALSE) && user_access('maintain buddy list', $thisuser)) { // when user tries to edit his own data $form['buddylist_settings'] = array( '#type' => 'fieldset', '#title' => t('Buddylist settings'), '#weight' => 5); $form['buddylist_settings']['buddylist_mail'] = array( '#type' => 'checkbox', '#title' => t('Receive @buddylist notification mails', buddylist_translation()), '#default_value' => isset($edit['buddylist_mail']) ? $edit['buddylist_mail'] : 1, '#description' => t('If you check this, you will be notified about important actions regarding your @Buddylist.', buddylist_translation())); return $form; } } /* * Return a formatted list of buddies for the given user * @param $buddy_of If set to TRUE, a formatted list of users is returned, for whom this user is a buddy. */ function buddylist_get_buddylist($user, $buddy_of = FALSE) { if (user_access('view buddy lists') && !$buddy_of) { $i = 0; if ($buddies = buddylist_get_buddies($user->uid)) { foreach(array_keys($buddies) as $buddy) { $account = user_load(array('uid' => $buddy)); $listbuddies[] = $account; $i++; if ($i > variable_get('buddylist_prof_buddies', 5)) { break; } } return theme('buddylist', $listbuddies); } } else if (user_access('view buddy lists') && !variable_get('buddylist_require_approval', 0)) { // This portion of code is used to see if this $thisuser is a buddy of others and, if s/he is, returns a list // of people s/he is a buddy of. // Note the distinction between having a buddy and being someone else's buddy (i.e., 'buddyof') // Of course, this distinction doesn't exist if approval is required to add a buddy (in which case, buddy relationships are symmetric) $sql = 'SELECT b.uid, u.name FROM {buddylist} b INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = %d ORDER BY u.access DESC'; $result = db_query_range($sql, $user->uid, 0, variable_get('buddylist_prof_buddies', 5)); while ($row = db_fetch_object($result)) { $listbuddyof[$row->uid] = $row; } if ($listbuddyof) { return theme('buddylist', $listbuddyof); } } } /* * Returns an array of posible actions (html) for the viewing user, * e.g. a link to make the viewed user a buddy */ function buddylist_get_buddy_actions(&$viewing_user, &$viewed_user) { $actions = array(); if (!user_access('maintain buddy list') || $viewing_user->uid == $viewed_user->uid) { return $actions; } if (variable_get('buddylist_require_approval', FALSE) && in_array($viewed_user->uid, array_keys(buddylist_get_requestees($viewing_user->uid)))) { $actions[] = t('You have requested to add this user to your @buddylist. (See !your_pending_requests)', array('!your_pending_requests' => l(t('your pending requests'), 'buddylist/'. $viewing_user->uid .'/buddies/requests')) + buddylist_translation()); } else if (in_array($viewed_user->uid, array_keys(buddylist_get_buddies($viewing_user->uid)))) { $actions[] = theme('remove_from_buddylist_link', $viewed_user); } else if (in_array($viewing_user->uid, array_keys(buddylist_get_requestees($viewed_user->uid)))) { $actions[] = t('This user has requested to add you to their @buddylist. ', buddylist_translation()) . theme('buddylist_accept_request_link', $viewing_user->uid, $viewed_user->uid) . " | " . theme('buddylist_deny_request_link', $viewing_user->uid, $viewed_user->uid); } else if (!variable_get('buddylist_require_approval', 0) || (variable_get('buddylist_require_approval', 0) && user_access('maintain buddy list', $viewed_user))) { $actions[] = theme('add_to_buddylist_link', $viewed_user); } return $actions; } /** * Implementation for hook_block */ function buddylist_block($op = 'list', $delta = 0) { global $user; if ($op == 'list') { $block[0]['info'] = variable_get('buddylist_list_block_title', t('My @buddylist', buddylist_translation())); $block[1]['info'] = variable_get('buddylist_block_title', t('My @buddies\' recent posts', buddylist_translation())); if (variable_get('buddylist_require_approval', 0)) { $block[2]['info'] = variable_get('buddylist_status_block_title', t('My @buddy status', buddylist_translation())); } return $block; } else if ($op == 'view' && user_access('access content') && user_access('maintain buddy list') && $user->uid > 0) { switch ($delta) { case 0 : // Shows buddylist block if ($buddies = buddylist_get_buddies()) { // we have buddies defined and generate the list $i = 0; foreach (array_keys($buddies) as $buddy) { $users[] = user_load(array('uid' => $buddy)); $i++; if ($i == variable_get('buddylist_blocklisting_size', 5)) { break; } } $block['content'] = theme('buddylist', $users); } else { // buddylist is empty if(variable_get('buddylist_block_if_no_buddies', FALSE)) { // Show a message that we have no buddies yet $block['content'] = variable_get('buddylist_empty_text', t(buddylist_empty_text_default(), buddylist_translation())); } else { // If no buddies defined and no message available, end 'case' without returning block. break; } } // this is the same output whether buddylist or not $block['subject'] = variable_get('buddylist_list_block_title', t('My @buddylist', buddylist_translation())); // check if a "more" link should generated by seeing if there are more buddies than the specified $upperlimit if (count($buddies) > variable_get('buddylist_blocklisting_size', 5)) { $block['content'] .= ''. t("!someone currently !does_or_do not have any pending @buddy requests from other users.", array('!someone' => ($viewing_own_account ? t('You') : $account->name), '!does_or_do' => $viewing_own_account ? t('do') : t('does')) + buddylist_translation()) .'
'; } else { $output = ''. t("The following people have requested to be !someones @buddy.", array('!someones' => ($viewing_own_account ? t('your') : $account->name ."'s ")) + buddylist_translation()) .'
'; $html_rows = array(); while ($row = db_fetch_object($result)) { $html_row = array(); $html_row[] = theme('username', $row); $html_row[] = theme('buddylist_accept_request_link', $account->uid, $row->uid) . " | " . theme('buddylist_deny_request_link', $account->uid, $row->uid); $html_rows[] = $html_row; } $output .= theme('table', NULL, $html_rows); } return $output; } /** * Returns a list of user's who this given user has requested to be buddies with. */ function buddylist_pending_requested_list(&$account) { global $user; $viewing_own_account = ($user->uid == $account->uid); $result = db_query('SELECT bpr.requestee_uid as uid, u.name FROM {buddylist_pending_requests} bpr INNER JOIN {users} u ON bpr.requestee_uid = u.uid WHERE requester_uid = %d', $account->uid); if (!db_num_rows($result)) { $output = t('!Person !do_or_does not have any pending @buddy requests that !person !have_or_has made.', array( '!Person' => ($viewing_own_account ? t('You') : $account->name), '!do_or_does' => ($viewing_own_account ? t('do') : t('does')), '!have_or_has' => ($viewing_own_account ? t('have') : t('has')), '!person' => ($viewing_own_account ? t('you') : $account->name) ) + buddylist_translation()); } else { $output = t('!person !have_or_has requested to be added to the @buddylist of the following users.', array('!person' => ($viewing_own_account ? t('You') : $account->name), '!have_or_has' => ($viewing_own_account ? t('have') : t('has'))) + buddylist_translation()); $html_rows = array(); while ($row = db_fetch_object($result)) { $html_row = array(); $html_row[] = theme('username', $row); $html_row[] = theme('buddylist_sent_requests_cancel_link', $account->uid, $row->uid); $html_rows[] = $html_row; } $output .= theme('table', NULL, $html_rows); } return $output; } function buddylist_pending_requested_accept($requestee_uid, $requester_uid) { $requestee_account = user_load(array('uid' => $requestee_uid)); $requester_account = user_load(array('uid' => $requester_uid)); $output = confirm_form( buddylist_confirm_form($requester_account, $requestee_account), t('Accept Request'), 'buddylist/'.$requestee_uid.'/buddies/requests', t("Are you sure you want to accept the request from !name?", array('!name' => theme('username', $requester_account))), t('Yes'), t('No'), 'buddylist_request_accept_confirm'); return $output; } function buddylist_cancel_request($requestee_uid, $requester_uid){ $requestee_account = user_load(array('uid' => $requestee_uid)); $requester_account = user_load(array('uid' => $requester_uid)); $output = confirm_form( buddylist_request_cancel_form($requestee_uid, $requester_uid), t('Cancel Request'), 'buddylist/'.$requestee_uid.'/buddies/requests', t("Are you sure you want to cancel the request to !name?", array('!name' => theme('username', $requester_account))), t('Yes'), t('No'), 'buddylist_cancel_request_confirm'); return $output; } function buddylist_cancel_request_submit($form_id, $form_values){ db_query('DELETE FROM {buddylist_pending_requests} WHERE requestee_uid = %d AND requester_uid = %d', $form_values['requester_uid'], $form_values['requestee_uid']); $former_potential_buddy = user_load(array('uid' => $form_values['requester_uid'])); drupal_set_message(t('The request to add !user_name has been cancelled.', array('!user_name' => theme('username', $former_potential_buddy)))); return 'buddylist/'. $form_values['requester_uid'] .'/buddies/requests'; } function buddylist_pending_requested_deny($requestee_uid, $requester_uid) { $requestee_account = user_load(array('uid' => $requestee_uid)); $requester_account = user_load(array('uid' => $requester_uid)); $output = confirm_form( buddylist_confirm_form($requester_account, $requestee_account), t('Accept Request'), 'buddylist/'.$requestee_uid.'/buddies/requests', t("Are you sure you want to deny the request from !name?", array('!name' => theme('username', $requester_account))), t('Yes'), t('No'), 'buddylist_request_deny_confirm'); return $output; } function buddylist_pending_requested_accept_submit($form_id, $form_values) { $requestee_account = $form_values['requestee_account']; // most likely global user, unless admin looking $requester_account = $form_values['requester_account']; // Delete pending request from {buddylist_penging_requests} $result = db_query('SELECT * FROM {buddylist_pending_requests} WHERE requestee_uid = %d AND requester_uid = %d', $requestee_account->uid, $requester_account->uid); if (db_num_rows($result) == 0) { // The other user cancelled since viewing this page drupal_set_message(t('!linktouser has cancelled the request to join your @buddylist.', array('!linktouser' => theme('username', $requester_account)) + buddylist_translation())); return 'buddylist/'. $requestee_account->uid .'/buddies/requests'; } db_query('DELETE FROM {buddylist_pending_requests} WHERE requestee_uid = %d AND requester_uid = %d', $requestee_account->uid, $requester_account->uid); // Make sure, for some weird reason, we don't already have these guys marked as buddies of each other in the database $result = db_query('SELECT * FROM {buddylist} WHERE uid = %d AND buddy = %d', $requestee_account->uid, $requester_account->uid); $time = time(); if (!db_num_rows($result)) { db_query('INSERT INTO {buddylist} (uid, buddy, timestamp, received) VALUES (%d, %d, %d, %d)', $requestee_account->uid, $requester_account->uid, $time, 1); } $result = db_query('SELECT * FROM {buddylist} WHERE uid = %d AND buddy = %d', $requester_account->uid, $requestee_account->uid); if (!db_num_rows($result)) { db_query('INSERT INTO {buddylist} (uid, buddy, timestamp, received) VALUES (%d, %d, %d, %d)', $requester_account->uid, $requestee_account->uid, $time, 1); } if (variable_get('buddylist_send_approval', FALSE)) { buddylist_mail_user('approval', $requester_account, $requestee_account); } drupal_set_message(t('Congratulations! !linktouser is now your @buddy.', array('!linktouser' => theme('username', $requester_account)) + buddylist_translation())); return 'buddylist/'. $requestee_account->uid .'/buddies/requests'; } function buddylist_pending_requested_deny_submit($form_id, $form_values) { $requestee_account = $form_values['requestee_account']; // most likely global user, unless admin looking $requester_account = $form_values['requester_account']; // Delete pending request from {buddylist_penging_requests} db_query('DELETE FROM {buddylist_pending_requests} WHERE requestee_uid = %d AND requester_uid = %d', $requestee_account->uid, $requester_account->uid); drupal_set_message(t("!user's request to be your buddy has been denied.", array('!user' => theme('username', $requester_account)) + buddylist_translation())); return 'buddylist/'. $requestee_account->uid .'/buddies/requests'; } function buddylist_confirm_form($requester_account, $requestee_account) { $form = array(); $form['requester_account'] = array( '#type' => 'value', '#value' => $requester_account ); $form['requestee_account'] = array( '#type' => 'value', '#value' => $requestee_account ); return $form; } function buddylist_request_cancel_form($requestee_uid, $requester_uid) { $form['requestee_uid'] = array( '#type' => 'hidden', '#value' => $requestee_uid, ); $form['requester_uid'] = array( '#type' => 'hidden', '#value' => $requester_uid ); return $form; } function buddylist_request_cancel_form_submit($form_id, $form_values) { db_query('DELETE FROM {buddylist_pending_requests} WHERE requester_uid = %d AND requestee_uid = %d', $form_values['requester_uid'], $form_values['requestee_uid']); $former_potential_buddy = user_load(array('uid' => $form_values['requestee_uid'])); drupal_set_message(t('The request to add !user_name has been cancelled.', array('!user_name' => theme('username', $former_potential_buddy)))); return 'buddylist/'. $form_values['requester_uid'] .'/buddies/requests'; } function buddylist_form_buddiesrecent_page($buddies) { foreach ($buddies as $user_id => $buddy) { $form[] = array('#type' => 'fieldset', '#title' => $buddy['name'], '#collapsible' => 'true', '#value' => tracker_page($user_id), ); } return $form; } function buddylist_buddiesrecent_page($uid) { global $user; $thisuser = user_load(array('uid' => $uid)); drupal_set_title(t('%username\'s @buddylist', array('%username' => $thisuser->name) + buddylist_translation())); $buddies = buddylist_get_buddies($uid); $output .= drupal_get_form('buddylist_form_buddiesrecent_page', $buddies); $output .= theme('xml_icon', url('buddylist/'. $uid .'/buddies/recent/feed')); drupal_set_html_head(''); return $output; } function buddylist_buddiesgroups_page($uid) { global $user; $thisuser = user_load(array('uid' => $uid)); drupal_set_title(t('%username\'s @buddy groups', array('%username' => $thisuser->name) + buddylist_translation())); $headers = array(t('@buddy', buddylist_translation()), t('online'), t('# of @buddies', buddylist_translation()), t("@buddy's posts", buddylist_translation())); $result = db_query('SELECT label, label_id FROM {buddylist_groups} WHERE uid = %d ORDER BY label ASC', $thisuser->uid); $groups = array(); while ($row = db_fetch_object($result)) { $groups[$row->label_id] = $row->label; } if (count($groups) == 0) { if ($thisuser->uid == $user->uid) { drupal_set_message( t("To organize your @buddies into groups, visit the !edit_groups page", array('!edit_groups' => l(t('edit groups'), "buddylist/$uid/buddies/groups/edit")) + buddylist_translation()) ); } return t('No groups found.'); } $online_interval = time() - variable_get('user_block_seconds_online', 180); $buddies = buddylist_get_buddies($thisuser->uid); foreach ($groups as $label_id => $label) { $result = pager_query('SELECT bg.buddy, u.access FROM {buddylist_buddy_group} bg INNER JOIN {users} u ON bg.buddy = u.uid WHERE bg.uid = %d and bg.label_id = %d', 10, 0, NULL, $thisuser->uid, $label_id); $rows = array(); while ($row = db_fetch_object($result)) { $online = $row->access > $online_interval; $rows[] = array( theme('username', (object)$buddies[$row->buddy]), theme('buddylist_online', $online), buddylist_count_buddies($row->buddy), l(t('view posts'), 'user/'. $row->buddy. '/track') ); } $output .= theme('box', check_plain($label), $rows ? theme('table', $headers, $rows) : t('Group is empty.')); } return $output; } function buddylist_count_buddies($uid) { $result = db_query("SELECT count(DISTINCT buddy) AS buddies FROM {buddylist} WHERE uid = %d", $uid); return db_result($result); } function buddylist_get_buddy_groups($uid, $buddy = NULL) { if (isset($buddy)) { $result = db_query("SELECT bg.label_id, bg.label, bg.visible FROM {buddylist_groups} bg INNER JOIN {buddylist_buddy_group} bbg ON bbg.uid = bg.uid WHERE bbg.uid = %d AND bg.label_id = bbg.label_id AND bbg.buddy = %d ", $uid, $buddy); } else { $result = db_query("SELECT * FROM {buddylist_groups} WHERE uid=%d", $uid); } $buddy_groups = array(); while ($row = db_fetch_array($result)) { $buddy_groups[$row['label_id']] = $buddy ? $row : $row['label']; } return $buddy_groups; } function buddylist_form_edit_groups_add() { // Add group form $form['add_group'] = array( '#type' => 'textfield', '#title' => t('Add new group'), '#description' => t('Groups are a way to keep your @buddies organized. Groups can be named whatever you like.', buddylist_translation()), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Add'), ); return $form; } function buddylist_form_edit_groups_remove($all_groups) { // Make a form to remove groups $form['remove']['groups'] = array( '#type' => 'checkboxes', '#return_value' => 1, '#title' => '', '#default_value' => null, '#options' => array_map('check_plain', $all_groups), ); $form['remove']['submit'] = array( '#type' => 'submit', '#value' => t('Remove'), ); return $form; } function buddylist_form_edit_groups_table($buddies, $all_groups, $thisuser) { // Build the table with buddies and their groups $form['table']['groups'] = array ('#tree' => true); foreach ($buddies as $uid => $buddy) { $items = array(); foreach ($buddy['groups'] as $group) { $items[] = $group['label_id']; } if (count($all_groups) > 0) { $form['table']['groups'][$uid] = array( '#type' => 'checkboxes', '#title' => '', '#default_value' => $items, '#options' => array_map('check_plain', $all_groups), ); } } $form['table']['user'] = array( '#type' => 'value', '#value' => $thisuser->uid, ); if (count($form['table']['groups']) > 0) { $form['table']['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); } return $form; } /** * Callback for the buddygroup editing page */ function buddylist_buddiesgroups_edit($uid) { $thisuser = user_load(array('uid' => $uid)); drupal_set_title(t('%username\'s @buddy groups', array('%username' => $thisuser->name) + buddylist_translation())); if ($buddies = buddylist_get_buddies($thisuser->uid)) { $output['add'] = drupal_get_form('buddylist_form_edit_groups_add'); $groups = buddylist_get_buddy_groups($uid); if (count($groups) > 0) { $output['remove'] = drupal_get_form('buddylist_form_edit_groups_remove', $groups); $output['table'] = drupal_get_form('buddylist_form_edit_groups_table', $buddies, $groups, $thisuser); } else { drupal_set_message(t("You don't have any groups defined.")); } return theme('buddylist_edit_groups', $output); } else { drupal_set_message(t('Unable to edit @buddy groups. Add @buddies to your @buddylist before making groups.', buddylist_translation())); return t('No @buddies found.', buddylist_translation()); } } function theme_buddylist_edit_groups($forms) { $output = ''. $forms['add']. ''. ''. $forms['remove']. ''. ''. $forms['table']. ''; return $output; } function theme_buddylist_form_edit_groups_table($form) { $rows = array(); foreach ($form['table']['groups'] as $key => $value) { if(is_numeric($key)) { $rows[] = array(theme('username', user_load(array('uid' => $key))), drupal_render($form['table']['groups'][$key])); } } $headers = array(t('buddy'), t('@buddy groups', buddylist_translation())); $output .= theme('table', $headers, $rows); $output .= drupal_render($form); return $output; } function theme_buddylist_status_block($count, $received_count, $sent_count) { global $user; $stats .= "You can add a @buddy by visiting a user's profile page.
MESSAGE; }