'. t("This module adds blocks that display '[relationship]s in common' and 'users you might know.' Please see http://drupal.org/project/ur_blocks for more information.") .'

'; break; } return $output; } // function ur_blocks_help /** * Implementation of hook_perm(). */ function ur_blocks_perm() { return array('view ur_blocks pages'); } /** * Implementation of hook_block(). */ function ur_blocks_block($op='list', $delta=0) { if ($op == "list") { $block[0]["info"] = t("UR in Common"); $block[1]["info"] = t("UR Users You Might Know"); return $block; } else if ($op == 'view') { switch ($delta) { case 0: $block['subject'] = 'Status'; $block['content'] = ur_blocks_uric(); break; case 1: $block['subject'] = "Recent Status Updates"; $block['content'] = ur_blocks_uymn(); break; } return $block; } } /** * FAPI implementation for the ur_blocks administrative settings page. */ function ur_blocks_admin() { $form['ur_blocks_num_uric'] = array( '#type' => 'textfield', '#title' => t('The maximum number of users to show in the UR in Common block'), '#default_value' => variable_get('ur_blocks_num_uric', 5), '#size' => 3, '#maxlength' => 3, '#description' => t("5 is the default, 1 is the minimum."), ); $form['ur_blocks_num_uymn'] = array( '#type' => 'textfield', '#title' => t('The maximum number of users to show in the Users You Might Know block'), '#default_value' => variable_get('ur_blocks_num_uymn', 5), '#size' => 3, '#maxlength' => 3, '#description' => t("5 is the default, 1 is the minimum."), ); $form['ur_blocks_uymn_page'] = array( '#type' => 'textfield', '#title' => t('The maximum number of users to show on the Users You Might Know page.'), '$default_value' => variable_get('ur_blocks_uymn_page', 15), '#size' => 3, '#maxlength => 3, '#description' => t("15 is the default, 1 is the minimum."), ); $form['ur_blocks_picture_size_block_h'] = array( '#type' => 'textfield', '#title' => t('The maximum height of avatars to use in the UR Blocks, in pixels. Enter zero to use the original size.'), '$default_value' => variable_get('ur_blocks_picture_size_block_h', 20), '#size' => 3, '#maxlength => 3, '#description' => t("20 is the default, 1 is the minimum."), ); $form['ur_blocks_picture_size_block_w'] = array( '#type' => 'textfield', '#title' => t('The maximum width of avatars to use in the UR Blocks, in pixels. Enter zero to use the original size.'), '$default_value' => variable_get('ur_blocks_picture_size_block_w', 20), '#size' => 3, '#maxlength => 3, '#description' => t("20 is the default, 1 is the minimum."), ); $fbsur_result = db_query("SELECT plural_name, rtid FROM {user_relationship_types} WHERE is_oneway = 0 AND requires_approval = 1"); while ($row = db_fetch_array($fbsur_result)) { $i = $row['rtid']; $fbsur[$i] = $row['plural_name']; } $form['ur_blocks_ur_type'] = array( '#type' => 'select', '#title' => t('User Relationship type to use for the UR Block blocks'), '#default_value' => variable_get('ur_blocks_ur_type', $i), '#options' => $fbsur, ); return system_settings_form($form); } /** * Implementation of hook_validate(). * FAPI implementation for the ur_blocks administrative settings page. */ function ur_blocks_admin_validate($form_id, $form_values) { if (!(is_numeric($form_values['ur_blocks_num_uric']) && $form_values['ur_blocks_num_uric'] >= 1)) { form_set_error('', t('Please enter a number greater than or equal to 1 for the number of users to show in the UR in Common block.')); } if (!(is_numeric($form_values['ur_blocks_num_uymn']) && $form_values['ur_blocks_num_uymn'] >= 1)) { form_set_error('', t('Please enter a number greater than or equal to 1 for the number of users to show in the Users You Might Know block.')); } if (!(is_numeric($form_values['ur_blocks_uymn_page']) && $form_values['ur_blocks_uymn_page'] >= 1)) { form_set_error('', t('Please enter a number greater than or equal to 1 for the number of users to show on the Users You Might Know page.')); } if (!(is_numeric($form_values['ur_blocks_picture_size_block_h']) && $form_values['ur_blocks_picture_size_block_h'] >= 0)) { form_set_error('', t('Please enter a number greater than or equal to 0 for the maximum height of user avatars to show in the Users You Might Know block.')); } if (!(is_numeric($form_values['ur_blocks_picture_size_block_w']) && $form_values['ur_blocks_picture_size_block_w'] >= 0)) { form_set_error('', t('Please enter a number greater than or equal to 0 for the maximum width of user avatars to show in the Users You Might Know block.')); } } /** * Implementation of hook_menu(). */ function ur_blocks_menu() { $items = array(); $items[] = array( 'path' => 'admin/settings/ur_blocks', 'title' => t('UR Block settings'), 'description' => t('Allows administrators to adjust certain display settings for UR Block.'), 'callback' => 'drupal_get_form', 'callback arguments' => 'ur_blocks_admin', 'access' => user_access('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); $items[] = array( 'path' => 'uymn', 'title' => t('Users you might know'), 'description' => t('Displays a list of users you might know.'), 'callback' => 'ur_blocks_uymn', 'callback arguments' => 'page', 'access' => user_access('view ur_blocks pages'), 'type' => MENU_CALLBACK, ); return $items; } /** * Users the current user might know. * * @param $type * If 'page', user avatars will show up full-sized, and there will be variable_get('ur_blocks_uymn_page', 15) results. * Otherwise, use 'block' style: small avatars, fewer results. * @return * A themed unordered list of users. */ function ur_blocks_uymn($type = 'block') { global $user; $cur_user = $user->uid; $x = variable_get('ur_blocks_ur_type', db_result(db_query_range("SELECT rtid FROM {user_relationship_types} WHERE is_oneway = 0 AND requires_approval = 1", 0, 1))); $user_rel = db_query(" SELECT u.name, u.uid, u.picture FROM {users} AS u LEFT JOIN {user_relationships} AS ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id) WHERE (u.uid = ur.requester_id OR u.uid = ur.requestee_id) AND (ur.requester_id = %d OR ur.requestee_id = %d) AND (ur.approved = 1) AND (ur.rtid = %d) GROUP BY (u.name) ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC ", $cur_user, $cur_user, $x); if ( db_fetch_array($user_rel) ) { $user_rel_com = array(); //Assigns the actual values into an array. while ($value = db_fetch_array($user_rel)) { $user_rel_com[] = $value; } //Writes the sub-query for $user_rel_rel. foreach ($user_rel_com as $row) { $req_req_id_list .= " OR ur.requester_id = ". $row['uid'] ." OR ur.requestee_id = ". $row['uid']; } $len = strlen($req_req_id_list); $req_req_id_list = substr($req_req_id_list, 4, $len); //trims the first " OR " //Gets all of the current user's friends' friends and orders by how many times they show up in the list. $user_rel_rel = db_query(" SELECT u.name, u.uid, u.picture FROM {users} AS u LEFT JOIN {user_relationships} AS ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id) WHERE (u.uid = ur.requester_id OR u.uid = ur.requestee_id) AND ($req_req_id_list) AND (ur.approved = 1) AND (ur.rtid = %d) GROUP BY (u.name) ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC ", $x); $user_rel_rel_com = array(); //Assigns the actual values into an array. while ($value = db_fetch_array($user_rel_rel)) { $user_rel_rel_com[] = $value; } //Array_diff() wasn't working so I wrote my own; this just removes users who the current user already has a relationship with. $remaining = array(); foreach ($user_rel_rel_com as $value) { if ( !array_search($value,$user_rel_com) ) { $remaining[] = $value; } } if ( $type != 'page' && variable_get('ur_blocks_picture_size_block_h', 20) ) { $image_size_h = "height=\"". variable_get('ur_blocks_picture_size_block_h', 20) ."px\""; } else { $image_size_h = ''; } if ( $type != 'page' && variable_get('ur_blocks_picture_size_block_w', 20) ) { $image_size_w = " width=\"". variable_get('ur_blocks_picture_size_block_w', 20) ."px\" "; } else { $image_size_w = ''; } if ( $type == 'page' ) { $y = variable_get('ur_blocks_uymn_page', 15) } else { $y = variable_get('ur_blocks_num_uymn', 5); } //Counting needs to be done by incrementing $i instead of using db_query_range so that the current user can be removed without ending up with fewer results than wanted. $i = 0; $output = ''; if ( $type == 'page' ) { $output .= "
"; } $output .= ""; if ( $type != 'page' ) { if (user_access('view ur_blocks pages')) { $output .= l('More', 'uymn'); } } else { $output .= "
"; } return $output; } } /** * Users that both the current user and the viewed user have a relationship with. * * @return * A themed, unordered list of users. */ function ur_blocks_uric() { global $user; $cur_user = $user->uid; if (arg(0) == 'user' && is_numeric(arg(1))) { $view_user = arg(1); } else if (arg(0) == 'node' && is_numeric(arg(1))) { $view_user = db_result(db_query("SELECT uid FROM {node} WHERE nid = %d", arg(1))); } else { //If we're on a page where the viewed user cannot be identified, exit the function and don't display the block. return FALSE; } $x = variable_get('ur_blocks_ur_type', db_result(db_query_range("SELECT rtid FROM {user_relationship_types} WHERE is_oneway = 0 AND requires_approval = 1", 0, 1))); if ( variable_get('ur_blocks_picture_size_block_h', 20) ) { $image_size_h = "height=\"". variable_get('ur_blocks_picture_size_block_h', 20) ."px\""; } else { $image_size_h = ''; } if ( variable_get('ur_blocks_picture_size_block_w', 20) ) { $image_size_w = " width=\"". variable_get('ur_blocks_picture_size_block_w', 20) ."px\" "; } else { $image_size_w = ''; } $view_user_rel = db_query(" SELECT u.name, u.uid, u.picture FROM (SELECT u.name, u.uid, u.picture FROM {users} AS u LEFT JOIN {user_relationships} AS ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id) WHERE (u.uid = ur.requester_id OR u.uid = ur.requestee_id) AND (ur.requester_id = %d OR ur.requestee_id = %d) AND (ur.approved = 1) AND (ur.rtid = %d) GROUP BY (u.name)) AS u LEFT JOIN {user_relationships} AS ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id) WHERE (u.uid = ur.requester_id OR u.uid = ur.requestee_id) AND (ur.requester_id = %d OR ur.requestee_id = %d) AND (ur.approved = 1) AND (ur.rtid = %d) GROUP BY (u.name) ORDER BY RAND() ", $cur_user, $cur_user, $x, $view_user, $view_user, $x); $friend_index = db_num_rows($view_user_rel); if ( $friend_index ){ $cur_friends = db_result(db_query("SELECT COUNT(requester_id) FROM {user_relationships} WHERE (requester_id = %d OR requestee_id = %d) AND approved = 1 AND rtid = %d", $cur_user, $x)); $view_friends = db_result(db_query("SELECT COUNT(requester_id) FROM {user_relationships} WHERE (requester_id = %d OR requestee_id = %d) AND approved = 1 AND rtid = %d", $view_user, $x)); $output = ''; $output .= ""; } return $output; }