Changeset 548
- Timestamp:
- 11/17/2008 10:54:11 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-friends.php
r527 r548 267 267 **************************************************************************/ 268 268 269 function friends_check_user_has_friends( $user_id = false ) { 270 if ( !$user_id ) 271 $user_id = $bp['current_userid']; 272 273 $friend_count = get_usermeta( $user_id, 'total_friend_count'); 274 275 if ( $friend_count == '' ) 276 return false; 277 278 if ( !(int)$friend_count ) 279 return false; 280 281 return true; 282 } 283 269 284 function friends_get_friendships( $user_id = false, $friendship_ids = false, $pag_num = 5, $pag_page = 1, $get_requests = false, $count = false ) { 270 285 global $bp; … … 322 337 } 323 338 339 function friends_get_friends_invite_list( $user_id = false, $group_id ) { 340 global $bp; 341 342 if ( !$user_id ) 343 $user_id = $bp['loggedin_userid']; 344 345 $friend_ids = BP_Friends_Friendship::get_friend_ids( $user_id ); 346 347 for ( $i = 0; $i < count($friend_ids); $i++ ) { 348 if ( groups_check_user_has_invite( $friend_ids[$i], $group_id ) || groups_is_user_member( $friend_ids[$i], $group_id ) ) 349 continue; 350 351 $display_name = bp_fetch_user_fullname($friend_ids[$i], false); 352 353 if ( $display_name != ' ' ) { 354 $friends[] = array( 355 'id' => $friend_ids[$i], 356 'full_name' => $display_name 357 ); 358 } 359 } 360 361 if ( $friends && is_array($friends) ) 362 usort($friends, 'friends_sort_by_name'); 363 364 if ( !$friends ) 365 return false; 366 367 return $friends; 368 369 } 370 371 function friends_count_invitable_friends( $user_id, $group_id ) { 372 return BP_Friends_Friendship::get_invitable_friend_count( $user_id, $group_id ); 373 } 324 374 325 375 function friends_get_friend_ids_for_user( $user_id ) { -
trunk/bp-friends/bp-friends-classes.php
r469 r548 238 238 global $wpdb, $bp; 239 239 240 $sql = $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM " . $bp['friends']['table_name'] . " WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1", $user_id, $user_id ); 241 $results = $wpdb->get_results($sql); 240 $results = $wpdb->get_results( $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM " . $bp['friends']['table_name'] . " WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1", $user_id, $user_id ) ); 242 241 243 242 for ( $i = 0; $i < count($results); $i++ ) { … … 267 266 } 268 267 268 function get_invitable_friend_count( $user_id, $group_id ) { 269 global $wpdb, $bp; 270 271 $friend_ids = BP_Friends_Friendship::get_friend_ids( $user_id ); 272 273 $invitable_count = 0; 274 for ( $i = 0; $i < count($friend_ids); $i++ ) { 275 276 if ( BP_Groups_Member::check_is_member( (int)$friend_ids[$i], $group_id ) ) 277 continue; 278 279 if ( BP_Groups_Member::check_has_invite( (int)$friend_ids[$i], $group_id ) ) 280 continue; 281 282 $invitable_count++; 283 } 284 285 return $invitable_count; 286 } 287 269 288 function get_user_ids_for_friendship( $friendship_id ) { 270 289 global $wpdb, $bp; -
trunk/bp-groups.php
r545 r548 3 3 4 4 define ( 'BP_GROUPS_IS_INSTALLED', 1 ); 5 define ( 'BP_GROUPS_VERSION', '0.2. 5' );5 define ( 'BP_GROUPS_VERSION', '0.2.6' ); 6 6 7 7 include_once( 'bp-groups/bp-groups-classes.php' ); … … 58 58 is_confirmed tinyint(1) NOT NULL DEFAULT '0', 59 59 is_banned tinyint(1) NOT NULL DEFAULT '0', 60 invite_sent tinyint(1) NOT NULL DEFAULT '0', 60 61 KEY group_id (group_id), 61 62 KEY is_admin (is_admin), … … 309 310 } 310 311 312 // Remove notifications 313 bp_core_delete_notifications_for_user_by_type( $bp['loggedin_userid'], 'groups', 'group_invite' ); 314 311 315 bp_catch_uri( 'groups/list-invites' ); 312 316 } … … 458 462 459 463 if ( $is_single_group ) { 460 if ( isset($bp['action_variables']) && $bp['action_variables'][ 1] == 'send' ) {464 if ( isset($bp['action_variables']) && $bp['action_variables'][0] == 'send' ) { 461 465 // Send the invites. 462 466 groups_send_invites($group_obj); … … 865 869 } else { 866 870 $user_fullname = bp_core_global_user_fullname( $requesting_user_id ); 867 $user_url = bp_core_get_userurl( $requesting_user_id );868 871 return '<a href="' . bp_group_permalink( $group, false ) . '/admin/membership-requests/" title="' . $user_fullname .' requests group membership">' . sprintf( __('%s requests membership for the group "%s"'), $user_fullname, $group->name ) . '</a>'; 869 872 } … … 876 879 877 880 if ( (int)$total_items > 1 ) { 878 return '<a href="' . site_url() . '/' . MEMBERS_SLUG . '/'. $bp['groups']['slug'] . '" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __('%d accepted group membership requests'), (int)$total_items, $group->name ) . '</a>';881 return '<a href="' . $bp['loggedin_domain'] . $bp['groups']['slug'] . '" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __('%d accepted group membership requests'), (int)$total_items, $group->name ) . '</a>'; 879 882 } else { 880 883 return '<a href="' . bp_group_permalink( $group, false ) . '/?new">' . sprintf( __('Membership for group "%s" accepted'), $group->name ) . '</a>'; … … 886 889 887 890 $group = new BP_Groups_Group( $group_id, false, false ); 888 891 889 892 if ( (int)$total_items > 1 ) { 890 893 return '<a href="' . site_url() . '/' . MEMBERS_SLUG . '/' . $bp['groups']['slug'] . '" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __('%d rejected group membership requests'), (int)$total_items, $group->name ) . '</a>'; … … 901 904 902 905 if ( (int)$total_items > 1 ) { 903 return '<a href="' . site_url() . '/' . MEMBERS_SLUG . '/'. $bp['groups']['slug'] . '" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __('You were promoted to an admin in %d groups'), (int)$total_items ) . '</a>';906 return '<a href="' . $bp['loggedin_domain'] . $bp['groups']['slug'] . '" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __('You were promoted to an admin in %d groups'), (int)$total_items ) . '</a>'; 904 907 } else { 905 908 return '<a href="' . bp_group_permalink( $group, false ) . '/?new">' . sprintf( __('You were promoted to an admin in the group %s'), $group->name ) . '</a>'; … … 913 916 914 917 if ( (int)$total_items > 1 ) { 915 return '<a href="' . site_url() . '/' . MEMBERS_SLUG . '/'. $bp['groups']['slug'] . '" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __('You were promoted to a mod in %d groups'), (int)$total_items ) . '</a>';918 return '<a href="' . $bp['loggedin_domain'] . $bp['groups']['slug'] . '" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __('You were promoted to a mod in %d groups'), (int)$total_items ) . '</a>'; 916 919 } else { 917 920 return '<a href="' . bp_group_permalink( $group, false ) . '/?new">' . sprintf( __('You were promoted to a mod in the group %s'), $group->name ) . '</a>'; 921 } 922 break; 923 924 case 'group_invite': 925 $group_id = $item_id; 926 927 $group = new BP_Groups_Group( $group_id, false, false ); 928 $user_url = bp_core_get_userurl( $user_id ); 929 930 if ( (int)$total_items > 1 ) { 931 return '<a href="' . $bp['loggedin_domain'] . $bp['groups']['slug'] . '/invites" title="' . __( 'Group Invites', 'buddypress' ) . '">' . sprintf( __('You have %d new group invitations'), (int)$total_items ) . '</a>'; 932 } else { 933 return '<a href="' . $bp['loggedin_domain'] . $bp['groups']['slug'] . '/invites" title="' . __( 'Group Invites', 'buddypress' ) . '">' . sprintf( __('You have an invitation to the group: %s'), $group->name ) . '</a>'; 918 934 } 919 935 break; … … 1242 1258 1243 1259 1244 function groups_get_invites_for_group( $group_id ) { 1245 return BP_Groups_Group::get_invites( $group_id ); 1246 } 1247 1248 1249 function groups_get_invites_for_user( $user_id = false ) { 1260 function groups_get_invites_for_group( $user_id, $group_id ) { 1261 return BP_Groups_Group::get_invites( $user_id, $group_id ); 1262 } 1263 1264 function groups_check_user_has_invite( $user_id, $group_id ) { 1265 BP_Groups_Member::check_has_invite( $user_id, $group_id ); 1266 } 1267 1268 function groups_get_invites_for_user( $user_id = false, $group_id = false ) { 1250 1269 global $bp; 1251 1270 … … 1253 1272 $user_id = $bp['loggedin_userid']; 1254 1273 1255 return BP_Groups_Member::get_invites( $user_id);1274 return BP_Groups_Member::get_invites( $user_id, $group_id ); 1256 1275 } 1257 1276 … … 1261 1280 1262 1281 // Send friend invites. 1263 $invited_users = groups_get_invites_for_group( $group_obj->id ); 1264 1265 for ( $i = 0; $i < count( $invited_users); $i++ ) { 1266 $user_id = $invited_users[$i]; 1267 1268 // Send the email 1269 1270 $invited_user = new BP_Core_User( $user_id ); 1271 $inviter_name = bp_core_get_userlink( $bp['loggedin_userid'], true, false, true ); 1272 1273 $message = "You have been invited to join the group '" . $group_obj->name . "' by " . $inviter_name . '.'; 1274 $message .= "\n\n"; 1275 $message .= "View the group: " . $invited_user->user_url . $bp['groups']['slug'] . "/" . $group_obj->slug . "\n"; 1276 $message .= "Accept the invite: " . $invited_user->user_url . $bp['groups']['slug'] . "/invites/accept/" . $group_obj->id . "\n"; 1277 $message .= "Reject the invite: " . $invited_user->user_url . $bp['groups']['slug'] . "/invites/reject/" . $group_obj->id . "\n"; 1278 1279 wp_mail( $invited_user->email, __("New Group Invitation:", 'buddypress') . $group_obj->name, $message, "From: noreply@" . $_SERVER[ 'HTTP_HOST' ] ); 1280 } 1281 1282 $invited_users = groups_get_invites_for_group( $bp['loggedin_userid'], $group_obj->id ); 1283 1284 for ( $i = 0; $i < count( $invited_users ); $i++ ) { 1285 $member = new BP_Groups_Member( $invited_users[$i], $group_obj->id ); 1286 $member->invite_sent = 1; 1287 $member->save(); 1288 } 1289 1290 groups_notification_group_invites( $group_obj->id, $invited_users, $bp['loggedin_userid'] ); 1291 1282 1292 do_action( 'groups_send_invites', $group_obj->id, $invited_users ); 1283 1293 } -
trunk/bp-groups/bp-groups-classes.php
r540 r548 283 283 } 284 284 285 function get_invites( $ group_id ) {286 global $wpdb, $bp; 287 return $wpdb->get_ col( $wpdb->prepare( "SELECT user_id FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d and is_confirmed = 0", $group_id ));285 function get_invites( $user_id, $group_id ) { 286 global $wpdb, $bp; 287 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d and is_confirmed = 0 AND inviter_id = %d", $group_id, $user_id ), ARRAY_A ); 288 288 } 289 289 … … 465 465 var $is_confirmed; 466 466 var $comments; 467 var $invite_sent; 467 468 468 469 var $user; … … 508 509 $this->is_confirmed = $member->is_confirmed; 509 510 $this->comments = $member->comments; 511 $this->invite_sent = $member->invite_sent; 510 512 511 513 $this->user = new BP_Core_User( $this->user_id ); … … 517 519 518 520 if ( $this->id ) { 519 $sql = $wpdb->prepare( "UPDATE " . $bp['groups']['table_name_members'] . " SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = FROM_UNIXTIME(%d), is_confirmed = %d, comments = %s WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->id );521 $sql = $wpdb->prepare( "UPDATE " . $bp['groups']['table_name_members'] . " SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = FROM_UNIXTIME(%d), is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id ); 520 522 } else { 521 $sql = $wpdb->prepare( "INSERT INTO " . $bp['groups']['table_name_members'] . " ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments ) VALUES ( %d, %d, %d, %d, %d, %d, %s, FROM_UNIXTIME(%d), %d, %s )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments);523 $sql = $wpdb->prepare( "INSERT INTO " . $bp['groups']['table_name_members'] . " ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments, invite_sent ) VALUES ( %d, %d, %d, %d, %d, %d, %s, FROM_UNIXTIME(%d), %d, %s, %d )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent ); 522 524 } 523 525 … … 623 625 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(group_id) FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND inviter_id = 0 AND is_banned = 0", $user_id ) ); 624 626 } else { 625 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.inviter_id = 0 m.is_banned = 0", $user_id ) );627 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0", $user_id ) ); 626 628 } 627 629 } … … 630 632 global $wpdb, $bp; 631 633 632 $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d and is_confirmed = 0 AND inviter_id != 0 ", $user_id ) );634 $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d and is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1", $user_id ) ); 633 635 634 636 for ( $i = 0; $i < count($group_ids); $i++ ) { … … 639 641 } 640 642 643 function check_has_invite( $user_id, $group_id ) { 644 global $wpdb, $bp; 645 646 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1", $user_id, $group_id ) ); 647 } 648 641 649 function check_is_admin( $user_id, $group_id ) { 642 650 global $wpdb, $bp; … … 666 674 global $wpdb, $bp; 667 675 668 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0 ", $user_id, $group_id ) );676 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0 AND inviter_id = 0", $user_id, $group_id ) ); 669 677 } 670 678 -
trunk/bp-groups/bp-groups-notifications.php
r542 r548 86 86 87 87 function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) { 88 global $bp , $current_user;88 global $bp; 89 89 90 90 bp_core_add_notification( $requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id ); … … 127 127 128 128 function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) { 129 global $bp , $current_user;129 global $bp; 130 130 131 131 // Post a screen notification first. … … 176 176 177 177 function groups_notification_promoted_member( $user_id, $group_id ) { 178 global $bp , $current_user;178 global $bp; 179 179 180 180 if ( groups_is_user_admin( $user_id, $group_id ) ) { … … 218 218 add_action( 'bp_groups_promoted_member', 'groups_notification_promoted_member', 10, 2 ); 219 219 220 function groups_notification_group_invites( $group_id, $invited_user_ids, $inviter_user_id ) { 221 global $bp; 222 223 $inviter_ud = get_userdata($inviter_user_id); 224 $inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true ); 225 $inviter_link = site_url() . '/' . MEMBERS_SLUG . '/' . $inviter_ud->user_login; 226 227 $group = new BP_Groups_Group( $group_id, false, false ); 228 $group_link = bp_group_permalink( $group, false ); 229 $invites_link = $inviter_link . '/' . $bp['groups']['slug'] . '/invites'; 230 231 for ( $i = 0; $i < count( $invited_user_ids ); $i++ ) { 232 $invited_user_id = $invited_user_ids[$i]; 233 234 // Post a screen notification first. 235 bp_core_add_notification( $group_id, $invited_user_id, 'groups', 'group_invite' ); 236 237 if ( get_usermeta( $invited_user_id, 'notification_group_invitation' ) == 'no' ) continue; 238 239 $invited_ud = get_userdata($invited_user_id); 240 $settings_link = site_url() . '/' . MEMBERS_SLUG . '/' . $ud->user_login . '/settings/notifications'; 241 242 // Set up and send the message 243 $to = $invited_ud->user_email; 244 245 $subject = sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), stripslashes($group->name) ); 246 247 $message = sprintf( __( 248 'One of your friends %s has invited you to the group: "%s". 249 250 To view your group invites visit: %s 251 To view the group visit: %s 252 To view %s\'s profile visit: %s 253 254 --------------------- 255 ', 'buddypress' ), $inviter_name, stripslashes($group->name), $invites_link, $group_link, $inviter_name, $inviter_link ); 256 257 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); 258 259 // Send it 260 wp_mail( $to, $subject, $message ); 261 } 262 } 263 220 264 ?> -
trunk/bp-groups/bp-groups-templatetags.php
r545 r548 795 795 <?php 796 796 } 797 function bp_group_list_ friends() {797 function bp_group_list_invite_friends() { 798 798 global $bp, $group_obj, $invites; 799 799 800 if ( bp_exists('friends') ) { 801 $friends = friends_get_friends_list( $bp['loggedin_userid'] ); 802 $invites = groups_get_invites_for_group($group_obj->id); 803 ?> 804 <div id="invite-list"> 805 <ul> 806 <?php for ( $i = 0; $i < count( $friends ); $i++ ) { 807 if ( in_array( $friends[$i]['id'], $invites ) ) { 808 $checked = ' checked="checked"'; 809 } else { 810 $checked = ''; 811 } ?> 800 if ( !function_exists('friends_install') ) 801 return false; 802 803 $friends = friends_get_friends_invite_list( $bp['loggedin_userid'], $group_obj->id ); 804 805 if ( $friends ) { 806 $invites = groups_get_invites_for_group( $bp['loggedin_userid'], $group_obj->id ); 807 808 ?> 809 <div id="invite-list"> 810 <ul> 811 <?php 812 for ( $i = 0; $i < count( $friends ); $i++ ) { 813 if ( $invites ) { 814 if ( in_array( $friends[$i]['id'], $invites ) ) { 815 $checked = ' checked="checked"'; 816 } else { 817 $checked = ''; 818 } 819 } 820 ?> 812 821 813 <li><input<?php echo $checked ?> type="checkbox" name="friends[]" id="f-<?php echo $friends[$i]['id'] ?>" value="<?php echo $friends[$i]['id'] ?>" /> <?php echo $friends[$i]['full_name']; ?></li> 814 <?php } ?> 815 </ul> 816 </div> 817 <?php 818 } 822 <li><input<?php echo $checked ?> type="checkbox" name="friends[]" id="f-<?php echo $friends[$i]['id'] ?>" value="<?php echo $friends[$i]['id'] ?>" /> <?php echo $friends[$i]['full_name']; ?></li> 823 <?php } ?> 824 </ul> 825 </div> 826 <?php 827 } else { 828 _e( 'No friends to invite.', 'buddypress' ); 829 } 819 830 } 820 831 … … 838 849 839 850 echo $bp['loggedin_domain'] . $bp['groups']['slug'] . '/invites/reject/' . $groups_template->group->id; 851 } 852 853 function bp_has_friends_to_invite() { 854 global $groups_template, $bp; 855 856 if ( !function_exists('friends_install') ) 857 return false; 858 859 if ( !friends_check_user_has_friends( $bp['loggedin_userid'] ) || !friends_count_invitable_friends( $bp['loggedin_userid'], $groups_template->group->id ) ) 860 return false; 861 862 return true; 840 863 } 841 864 … … 860 883 <div class="left-menu"> 861 884 <h4>Select Friends <img id="ajax-loader" src="<?php echo $bp['groups']['image_base'] ?>/ajax-loader.gif" height="7" alt="Loading" style="display: none;" /></h4> 862 <?php bp_group_list_ friends() ?>885 <?php bp_group_list_invite_friends() ?> 863 886 <?php if ( function_exists('wp_nonce_field') ) 864 887 wp_nonce_field( 'invite_user' );
Note: See TracChangeset
for help on using the changeset viewer.