Ticket #5644: 5644.patch
File 5644.patch, 30.9 KB (added by , 10 years ago) |
---|
-
src/bp-activity/bp-activity-classes.php
diff --git src/bp-activity/bp-activity-classes.php src/bp-activity/bp-activity-classes.php index f1e6054..3bef7b4 100644
class BP_Activity_Activity { 337 337 $where_conditions['search_sql'] = "a.content LIKE '%%" . esc_sql( like_escape( $search_terms ) ) . "%%'"; 338 338 } 339 339 340 // User Favorites 341 if ( ! empty( $filter['action'] ) && 'user_favorites' == $filter['action'] ) { 342 $meta_query_args = array( 343 'key' => 'user_favorites', 344 'compare' => 'EXISTS' 345 ); 346 347 if ( ! empty( $filter['user_id'] ) ) { 348 $meta_query_args['compare'] = '='; 349 $meta_query_args['value'] = absint( $filter['user_id'] ); 350 unset( $filter['user_id'] ); 351 } 352 353 $meta_query = array( $meta_query_args ); 354 355 unset( $filter['action'] ); 356 } 357 340 358 // Filtering 341 359 if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) ) 342 360 $where_conditions['filter_sql'] = $filter_sql; … … class BP_Activity_Activity { 465 483 // Generate action strings 466 484 $activities = BP_Activity_Activity::generate_action_strings( $activities ); 467 485 486 // Append favorites 487 $activities = self::append_favorites( $activities ); 488 468 489 // If $max is set, only return up to the max results 469 490 if ( !empty( $max ) ) { 470 491 if ( (int) $total_activities > (int) $max ) … … class BP_Activity_Activity { 1105 1126 } 1106 1127 1107 1128 /** 1129 * Append user who favorited activities. 1130 * 1131 * @since BuddyPress (2.1) 1132 * 1133 * @param array $activities Activities to fetch comments for. 1134 * @param bool $spam Optional. 'ham_only' (default), 'spam_only' or 'all'. 1135 * @return array The updated activities with nested comments. 1136 */ 1137 public static function append_favorites( $activities = array() ) { 1138 $user_favorites = array(); 1139 1140 // Now fetch the user who favorited matching activities. 1141 foreach ( (array) $activities as $key => $activity ) { 1142 $activities[$key]->user_favorites = bp_activity_get_meta( $activity->id, 'user_favorites', false ); 1143 } 1144 1145 return $activities; 1146 } 1147 1148 /** 1108 1149 * Get a list of components that have recorded activity associated with them. 1109 1150 * 1110 1151 * @param bool $skip_last_activity If true, components will not be … … class BP_Activity_Activity { 1283 1324 * @return int A count of the user's favorites. 1284 1325 */ 1285 1326 public static function total_favorite_count( $user_id ) { 1286 if ( !$favorite_activity_entries = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ) ) 1327 $favorite_activity_entries = self::get_activity_ids_by_meta( 'user_favorites', $user_id ); 1328 1329 if ( empty( $favorite_activity_entries ) ) 1287 1330 return 0; 1288 1331 1289 return count( maybe_unserialize( $favorite_activity_entries ));1332 return count( $favorite_activity_entries ); 1290 1333 } 1291 1334 1292 1335 /** … … class BP_Activity_Activity { 1312 1355 1313 1356 return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) ); 1314 1357 } 1358 1359 /** 1360 * Get an array of activity ids for given metadata. 1361 * 1362 * @since BuddyPress (2.1) 1363 * 1364 * @param string $meta_key. 1365 * @param mixed $meta_value. 1366 * @return array Activity ids 1367 */ 1368 public static function get_activity_ids_by_meta( $meta_key = '', $meta_value = '' ) { 1369 global $wpdb; 1370 $bp = buddypress(); 1371 1372 $activity_ids = array(); 1373 1374 if ( empty( $meta_key ) || empty( $meta_value ) ) 1375 return $activity_ids; 1376 1377 $meta_key = wp_unslash( $meta_key ); 1378 $meta_value = wp_unslash( $meta_value ); 1379 $meta_value = sanitize_meta( $meta_key, $meta_value, 'activity' ); 1380 $meta_value = maybe_serialize( $meta_value ); 1381 1382 $sql['select'] = "SELECT activity_id FROM {$bp->activity->table_name_meta}"; 1383 $sql['where']['meta_key'] = $wpdb->prepare( "meta_key = %s", $meta_key ); 1384 1385 if ( is_numeric( $meta_value ) ) { 1386 $sql['where']['meta_value'] = $wpdb->prepare( "meta_value = %d", $meta_value ); 1387 } else { 1388 $sql['where']['meta_value'] = $wpdb->prepare( "meta_value = %s", $meta_value ); 1389 } 1390 1391 $sql['where'] = 'WHERE ' . implode( ' AND ', $sql['where'] ); 1392 1393 return $wpdb->get_col( "{$sql['select']} {$sql['where']}" ); 1394 } 1315 1395 } 1316 1396 1317 1397 /** -
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 6e5d93b..8b70c4b 100644
function bp_activity_get_types() { 361 361 * 362 362 * @since BuddyPress (1.2) 363 363 * 364 * @uses bp_ get_user_meta()364 * @uses bp_activity_get_activity_ids_by_meta() 365 365 * @uses apply_filters() To call the 'bp_activity_get_user_favorites' hook. 366 366 * 367 367 * @param int $user_id ID of the user whose favorites are being queried. … … function bp_activity_get_user_favorites( $user_id = 0 ) { 374 374 $user_id = bp_displayed_user_id(); 375 375 376 376 // Get favorites for user 377 $favs = bp_ get_user_meta( $user_id, 'bp_favorite_activities', true);377 $favs = bp_activity_get_activity_ids_by_meta( 'user_favorites', $user_id ); 378 378 379 379 return apply_filters( 'bp_activity_get_user_favorites', $favs ); 380 380 } … … function bp_activity_get_user_favorites( $user_id = 0 ) { 385 385 * @since BuddyPress (1.2) 386 386 * 387 387 * @uses is_user_logged_in() 388 * @uses bp_ get_user_meta()388 * @uses bp_activity_get_user_favorites() 389 389 * @uses bp_activity_get_meta() 390 * @uses bp_update_user_meta()391 390 * @uses bp_activity_update_meta() 391 * @uses bp_activity_add_meta() 392 392 * @uses do_action() To call the 'bp_activity_add_user_favorite' hook. 393 393 * @uses do_action() To call the 'bp_activity_add_user_favorite_fail' hook. 394 394 * … … function bp_activity_get_user_favorites( $user_id = 0 ) { 399 399 function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 400 400 401 401 // Favorite activity stream items are for logged in users only 402 if ( ! is_user_logged_in() )402 if ( ! is_user_logged_in() ) 403 403 return false; 404 404 405 405 // Fallback to logged in user if no user_id is passed 406 406 if ( empty( $user_id ) ) 407 407 $user_id = bp_loggedin_user_id(); 408 408 409 $my_favs = bp_ get_user_meta( $user_id, 'bp_favorite_activities', true);409 $my_favs = bp_activity_get_user_favorites( $user_id ); 410 410 if ( empty( $my_favs ) || ! is_array( $my_favs ) ) { 411 411 $my_favs = array(); 412 412 } … … function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 416 416 return false; 417 417 } 418 418 419 // Add to user's favorites420 $my_favs[] = $activity_id;421 422 419 // Update the total number of users who have favorited this activity 423 420 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 424 421 $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1; 425 422 426 // Update user meta427 bp_ update_user_meta( $user_id, 'bp_favorite_activities', $my_favs);423 // Update activity meta counts for backcompat 424 bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ); 428 425 429 // Update activity meta counts 430 if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) { 426 if ( bp_activity_add_meta( $activity_id, 'user_favorites', $user_id ) ) { 431 427 432 428 // Execute additional code 433 429 do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id ); … … function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 450 446 * @since BuddyPress (1.2) 451 447 * 452 448 * @uses is_user_logged_in() 453 * @uses bp_ get_user_meta()449 * @uses bp_activity_delete_meta() 454 450 * @uses bp_activity_get_meta() 455 451 * @uses bp_activity_update_meta() 456 452 * @uses bp_update_user_meta() … … function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 463 459 function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) { 464 460 465 461 // Favorite activity stream items are for logged in users only 466 if ( ! is_user_logged_in() )462 if ( ! is_user_logged_in() ) 467 463 return false; 468 464 469 465 // Fallback to logged in user if no user_id is passed 470 466 if ( empty( $user_id ) ) 471 467 $user_id = bp_loggedin_user_id(); 472 468 473 $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );474 $ my_favs = array_flip( (array) $my_favs);469 // Remove the user favorite 470 $removed = bp_activity_delete_meta( $activity_id, 'user_favorites', $user_id ); 475 471 476 // Bail if the user has not previously favorited the item 477 if ( ! isset( $my_favs[ $activity_id ] ) ) { 472 if ( empty( $removed ) ) { 478 473 return false; 479 474 } 480 475 481 // Remove the fav from the user's favs482 unset( $my_favs[$activity_id] );483 $my_favs = array_unique( array_flip( $my_favs ) );484 485 476 // Update the total number of users who have favorited this activity 486 if ( $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ) ) { 487 488 // Deduct from total favorites 489 if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) { 490 491 // Update users favorites 492 if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) { 493 494 // Execute additional code 495 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); 496 497 // Success 498 return true; 477 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 499 478 500 // Error updating501 } else{502 503 479 // Error getting favorite count 480 if ( empty( $fav_count ) ) { 481 return false; 482 } 504 483 505 // Error updating favorite count 506 } else { 507 return false; 508 } 484 // Deduct from total favorites 485 $count_updated = bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ); 509 486 510 // Error getting favorite count511 } else{487 // Error updating favorite count 488 if ( empty( $count_updated ) ) { 512 489 return false; 513 490 } 491 492 // Execute additional code 493 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); 494 495 return true; 514 496 } 515 497 516 498 /** … … function bp_activity_add_meta( $activity_id, $meta_key, $meta_value, $unique = f 678 660 return $retval; 679 661 } 680 662 663 /** 664 * Get activity ids by metadata. 665 * 666 * @since BuddyPress (2.1) 667 * 668 * @param string $meta_key. 669 * @param mixed $meta_value. 670 * @return array activity ids. 671 */ 672 function bp_activity_get_activity_ids_by_meta( $meta_key = '', $meta_value = '' ) { 673 return apply_filters( 'bp_activity_get_activity_ids_by_meta', BP_Activity_Activity::get_activity_ids_by_meta( $meta_key, $meta_value ), $meta_key, $meta_value ); 674 } 675 681 676 /** Clean up *****************************************************************/ 682 677 683 678 /** … … function bp_activity_remove_all_user_data( $user_id = 0 ) { 702 697 // Clear the user's activity from the sitewide stream and clear their activity tables 703 698 bp_activity_delete( array( 'user_id' => $user_id ) ); 704 699 705 // Remove any usermeta706 bp_delete_user_meta( $user_id, 'bp_latest_update' );707 bp_delete_user_meta( $user_id, 'bp_favorite_activities' );708 709 700 // Execute additional code 710 701 do_action( 'bp_activity_remove_data', $user_id ); // Deprecated! Do not use! 711 702 … … function bp_activity_do_heartbeat() { 1943 1934 1944 1935 return $retval; 1945 1936 } 1937 1938 /** 1939 * Add filters to list favorited activities to Show dropdowns. 1940 * 1941 * @since BuddyPress (2.1.0) 1942 */ 1943 function bp_activity_activity_favorite_filter_options() { 1944 if ( bp_is_user() && bp_is_current_action( 'favorites' ) ) 1945 return; 1946 ?> 1947 1948 <option value="user_favorites"><?php _e( 'Favorited Updates', 'buddypress' ) ?></option> 1949 1950 <?php 1951 } 1952 add_action( 'bp_activity_filter_options', 'bp_activity_activity_favorite_filter_options' ); 1953 add_action( 'bp_member_activity_filter_options', 'bp_activity_activity_favorite_filter_options' ); 1954 add_action( 'bp_group_activity_filter_options', 'bp_activity_activity_favorite_filter_options' ); -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index 1acafeb..a219446 100644
class BP_Activity_Template { 184 184 // Check if blog/forum replies are disabled 185 185 $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false; 186 186 187 // Get an array of the logged in user's favorite activities188 $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) );189 190 187 // Fetch specific activity items based on ID's 191 188 if ( !empty( $include ) ) { 192 189 $this->activities = bp_activity_get_specific( array( … … function bp_has_activities( $args = '' ) { 610 607 } 611 608 break; 612 609 case 'favorites': 613 $favs = bp_activity_get_user_favorites( $user_id ); 614 if ( empty( $favs ) ) 615 return false; 616 617 $in = implode( ',', (array) $favs ); 610 $action = 'user_favorites'; 618 611 $display_comments = true; 619 $user_id = 0;620 612 break; 621 613 case 'mentions': 622 614 … … function bp_activity_is_favorite() { 1751 1743 function bp_get_activity_is_favorite() { 1752 1744 global $activities_template; 1753 1745 1754 return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) );1746 return apply_filters( 'bp_get_activity_is_favorite', in_array( bp_loggedin_user_id(), (array) $activities_template->activity->user_favorites ) ); 1755 1747 } 1756 1748 1757 1749 /** … … function bp_total_favorite_count_for_user( $user_id = 0 ) { 2737 2729 } 2738 2730 add_filter( 'bp_get_total_favorite_count_for_user', 'bp_core_number_format' ); 2739 2731 2732 2733 function bp_activity_get_favorite_count() { 2734 global $activities_template; 2735 2736 $count = 0; 2737 2738 if ( ! empty( $activities_template->activity->user_favorites ) ) { 2739 $count = count( (array) $activities_template->activity->user_favorites ); 2740 } 2741 2742 return apply_filters( 'bp_activity_get_favorite_count', $count ); 2743 } 2744 2745 2746 function bp_activity_user_favorites() { 2747 echo bp_get_activity_user_favorites(); 2748 } 2749 2750 function bp_get_activity_user_favorites() { 2751 global $activities_template; 2752 2753 if ( empty( $activities_template->activity->user_favorites ) ) { 2754 return; 2755 } 2756 2757 $output = '<ul class="user-favorites-list">'; 2758 2759 foreach( (array) $activities_template->activity->user_favorites as $user_id ) { 2760 $user_avatar = bp_core_fetch_avatar( array( 2761 'item_id' => $user_id, 2762 'object' => 'user', 2763 'type' => 'thumb', 2764 'width' => 50, 2765 'height' => 50, 2766 'html' => true, 2767 'class' => 'user-favorite-' . $user_id 2768 ) ); 2769 $output .= '<li><a href="' . bp_core_get_userlink( $user_id, false, true ) .'">' . $user_avatar . '</a></li>'; 2770 } 2771 2772 $output .= '</ul>'; 2773 2774 return apply_filters( 'bp_get_activity_user_favorites', $output, $activities_template->activity->id, $activities_template->activity->user_favorites ); 2775 } 2776 2777 2778 function bp_activity_interactions_nav() { 2779 echo bp_get_activity_interactions_nav(); 2780 } 2781 2782 function bp_get_activity_interactions_nav() { 2783 global $activities_template; 2784 2785 if ( ( is_user_logged_in() && bp_activity_can_comment() ) || ( is_user_logged_in() && bp_activity_can_favorite() ) || bp_is_single_activity() ) { 2786 2787 $class_nav = $class_favorite = ''; 2788 $comments_count = bp_activity_get_comment_count(); 2789 $favorites_count = bp_activity_get_favorite_count(); 2790 2791 if ( 0 == $comments_count + $favorites_count ) { 2792 $class_nav = ' hide'; 2793 } 2794 2795 $output = '<ul class="activity-interactions-nav'. $class_nav .'">'; 2796 $output .= '<li class="activity-interactions current"><a href="#" class="activity-comments-interaction">' . sprintf( __( 'Replies <span>%s</span>', 'buddypress' ), $comments_count ) . '</a></li>'; 2797 2798 if ( 0 == $favorites_count ) { 2799 $class_favorite = ' hide'; 2800 } 2801 2802 $output .= '<li class="activity-interactions'. $class_favorite .'"><a href="#" class="activity-favorites-interaction">' . sprintf( __( 'Favorites <span>%s</span>', 'buddypress' ), $favorites_count ) . '</a></li>'; 2803 2804 $output .= '</ul>'; 2805 2806 } else { 2807 $output = false; 2808 } 2809 2810 return apply_filters( 'bp_get_activity_interactions_nav', $output ); 2811 } 2812 2740 2813 /** 2741 2814 * Output the total mention count for a specified user. 2742 2815 * -
src/bp-members/bp-members-functions.php
diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php index eea5790..0e3efb3 100644
function bp_update_user_last_activity( $user_id = 0, $time = '' ) { 938 938 // As of BuddyPress 2.0, last_activity is no longer stored in usermeta. 939 939 // However, we mirror it there for backward compatibility. Do not use! 940 940 // Remove our warning and re-add. 941 remove_filter( 'update_user_metadata', '_bp_update_user_meta_ last_activity_warning', 10, 4 );942 remove_filter( 'get_user_metadata', '_bp_get_user_meta_ last_activity_warning', 10, 3 );941 remove_filter( 'update_user_metadata', '_bp_update_user_meta_activity_warning', 10, 4 ); 942 remove_filter( 'get_user_metadata', '_bp_get_user_meta_activity_warning', 10, 3 ); 943 943 update_user_meta( $user_id, 'last_activity', $time ); 944 add_filter( 'update_user_metadata', '_bp_update_user_meta_ last_activity_warning', 10, 4 );945 add_filter( 'get_user_metadata', '_bp_get_user_meta_ last_activity_warning', 10, 3 );944 add_filter( 'update_user_metadata', '_bp_update_user_meta_activity_warning', 10, 4 ); 945 add_filter( 'get_user_metadata', '_bp_get_user_meta_activity_warning', 10, 3 ); 946 946 947 947 return BP_Core_User::update_last_activity( $user_id, $time ); 948 948 } 949 949 950 950 /** 951 * Backward compatibility for 'last_activity' usermeta fetching.951 * Backward compatibility for 'last_activity' && bp_favorite_activities usermeta fetching. 952 952 * 953 953 * In BuddyPress 2.0, user last_activity data was moved out of usermeta. For 954 954 * backward compatibility, we continue to mirror the data there. This function 955 955 * serves two purposes: it warns plugin authors of the change, and it returns 956 956 * the data from the proper location. 957 * 958 * In BuddyPress 2.1, bp_favorite_activities was also moved out of usermeta. 957 959 * 958 960 * @since BuddyPress (2.0.0) 959 961 * … … function bp_update_user_last_activity( $user_id = 0, $time = '' ) { 963 965 * @param int $object_id ID of the user. 964 966 * @param string $meta_key Meta key being fetched. 965 967 */ 966 function _bp_get_user_meta_ last_activity_warning( $retval, $object_id, $meta_key ) {967 static $warned ;968 function _bp_get_user_meta_activity_warning( $retval, $object_id, $meta_key ) { 969 static $warned = array(); 968 970 969 971 if ( 'last_activity' === $meta_key ) { 970 972 // Don't send the warning more than once per pageload 971 if ( empty( $warned ) ) {973 if ( empty( $warned['last_activity'] ) ) { 972 974 _doing_it_wrong( 'get_user_meta( $user_id, \'last_activity\' )', __( 'User last_activity data is no longer stored in usermeta. Use bp_get_user_last_activity() instead.', 'buddypress' ), '2.0.0' ); 973 $warned = 1;975 $warned['last_activity'] = 1; 974 976 } 975 977 976 978 return bp_get_user_last_activity( $object_id ); 977 979 } 978 980 981 if ( 'bp_favorite_activities' === $meta_key ) { 982 // Don't send the warning more than once per pageload 983 if ( empty( $warned['bp_favorite_activities'] ) ) { 984 _doing_it_wrong( 'get_user_meta( $user_id, \'bp_favorite_activities\' )', __( 'User bp_favorite_activities data is no longer stored in usermeta. Use bp_activity_get_user_favorites() instead.', 'buddypress' ), '2.1.0' ); 985 $warned['bp_favorite_activities'] = 1; 986 } 987 988 return bp_activity_get_user_favorites( $object_id ); 989 } 990 979 991 return $retval; 980 992 } 981 add_filter( 'get_user_metadata', '_bp_get_user_meta_ last_activity_warning', 10, 3 );993 add_filter( 'get_user_metadata', '_bp_get_user_meta_activity_warning', 10, 3 ); 982 994 983 995 /** 984 996 * Backward compatibility for 'last_activity' usermeta setting. … … add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 997 1009 * @param string $meta_key Meta key being fetched. 998 1010 * @param string $meta_value Active time. 999 1011 */ 1000 function _bp_update_user_meta_ last_activity_warning( $meta_id, $object_id, $meta_key, $meta_value ) {1012 function _bp_update_user_meta_activity_warning( $meta_id, $object_id, $meta_key, $meta_value ) { 1001 1013 if ( 'last_activity' === $meta_key ) { 1002 1014 _doing_it_wrong( 'update_user_meta( $user_id, \'last_activity\' )', __( 'User last_activity data is no longer stored in usermeta. Use bp_update_user_last_activity() instead.', 'buddypress' ), '2.0.0' ); 1003 1015 bp_update_user_last_activity( $object_id, $meta_value ); 1004 1016 } 1017 1018 if ( 'bp_favorite_activities' === $meta_key ) { 1019 _doing_it_wrong( 'update_user_meta( $user_id, \'bp_favorite_activities\' )', __( 'User bp_favorite_activities data is no longer stored in usermeta. Use bp_activity_add_user_favorite() or bp_activity_remove_user_favorite() instead.', 'buddypress' ), '2.1.0' ); 1020 } 1005 1021 } 1006 add_filter( 'update_user_metadata', '_bp_update_user_meta_ last_activity_warning', 10, 4 );1022 add_filter( 'update_user_metadata', '_bp_update_user_meta_activity_warning', 10, 4 ); 1007 1023 1008 1024 /** 1009 1025 * Get the last activity for a given user. -
src/bp-templates/bp-legacy/buddypress-functions.php
diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php index 784b2dc..5ecb49c 100644
function bp_legacy_theme_mark_activity_favorite() { 919 919 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 920 920 return; 921 921 922 if ( bp_activity_add_user_favorite( $_POST['id'] ) ) 923 _e( 'Remove Favorite', 'buddypress' ); 924 else 925 _e( 'Favorite', 'buddypress' ); 922 $result = array(); 923 $user_id = bp_loggedin_user_id(); 924 925 if ( bp_activity_add_user_favorite( $_POST['id'] ) ) { 926 $result['button'] = __( 'Remove Favorite', 'buddypress' ); 927 $user_avatar = bp_core_fetch_avatar( array( 928 'item_id' => $user_id, 929 'object' => 'user', 930 'type' => 'thumb', 931 'width' => 50, 932 'height' => 50, 933 'html' => true, 934 'class' => 'user-favorite-' . $user_id 935 ) ); 936 $result['avatar'] = '<li><a href="' . bp_core_get_userlink( $user_id, false, true ) .'">' . $user_avatar . '</a></li>'; 937 } else { 938 $result['button'] = __( 'Favorite', 'buddypress' ); 939 $result['avatar'] = 0; 940 } 926 941 927 exit ;942 exit( json_encode( $result ) ); 928 943 } 929 944 930 945 /** … … function bp_legacy_theme_unmark_activity_favorite() { 938 953 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 939 954 return; 940 955 941 if ( bp_activity_remove_user_favorite( $_POST['id'] ) ) 942 _e( 'Favorite', 'buddypress' ); 943 else 944 _e( 'Remove Favorite', 'buddypress' ); 956 $result = array(); 945 957 946 exit; 958 if ( bp_activity_remove_user_favorite( $_POST['id'] ) ){ 959 $result['button'] = __( 'Favorite', 'buddypress' ); 960 $result['avatar'] = bp_loggedin_user_id(); 961 } else { 962 $result['button'] = __( 'Remove Favorite', 'buddypress' ); 963 $result['avatar'] = 0; 964 } 965 966 exit( json_encode( $result ) ); 947 967 } 948 968 949 969 /** -
src/bp-templates/bp-legacy/buddypress/activity/entry.php
diff --git src/bp-templates/bp-legacy/buddypress/activity/entry.php src/bp-templates/bp-legacy/buddypress/activity/entry.php index 24e296b..9825c25 100644
55 55 56 56 <?php if ( bp_activity_can_comment() ) : ?> 57 57 58 <a href="<?php bp_activity_comment_link(); ?>" class="button acomment-reply bp-primary-action" id="acomment-comment-<?php bp_activity_id(); ?>"><?php printf( __( 'Comment <span>%s</span>', 'buddypress' ), bp_activity_get_comment_count()); ?></a>58 <a href="<?php bp_activity_comment_link(); ?>" class="button acomment-reply bp-primary-action" id="acomment-comment-<?php bp_activity_id(); ?>"><?php esc_html_e( 'Comment', 'buddypress' ); ?></a> 59 59 60 60 <?php endif; ?> 61 61 … … 83 83 84 84 </div> 85 85 86 <?php bp_activity_interactions_nav(); ?> 87 86 88 <?php do_action( 'bp_before_activity_entry_comments' ); ?> 87 89 88 90 <?php if ( ( is_user_logged_in() && bp_activity_can_comment() ) || bp_is_single_activity() ) : ?> … … 117 119 118 120 <?php do_action( 'bp_after_activity_entry_comments' ); ?> 119 121 122 <?php if ( ( is_user_logged_in() && bp_activity_can_favorite() ) || bp_is_single_activity() ) : ?> 123 124 <div class="activity-favorites"> 125 126 <?php bp_activity_user_favorites(); ?> 127 128 </div> 129 130 <?php endif; ?> 131 132 <?php do_action( 'bp_after_activity_entry_favorites' ); ?> 133 120 134 </li> 121 135 122 136 <?php do_action( 'bp_after_activity_entry' ); ?> -
src/bp-templates/bp-legacy/css/buddypress.css
diff --git src/bp-templates/bp-legacy/css/buddypress.css src/bp-templates/bp-legacy/css/buddypress.css index 36a16c7..c0d7975 100644
Hello, this is the BuddyPress Legacy stylesheet. 12 12 3.1 - Activity 13 13 3.1.1 - Activity Listing 14 14 3.1.2 - Activity Comments 15 3.1.3 - Activity Favorites 15 16 3.2 - Toolbar 16 17 3.3 - Directories - Members, Groups, Blogs, Forums 17 18 3.4 - Error / Success Messages … … body.activity-permalink #buddypress div.activity-comments div.acomment-content { 484 485 color: inherit; 485 486 } 486 487 488 489 /*-------------------------------------------------------------- 490 3.1.3 - Activity Favorites 491 --------------------------------------------------------------*/ 492 #buddypress .activity-list li ul.activity-interactions-nav { 493 list-style: none; 494 margin: 20px 0 10px 70px; 495 overflow: hidden; /* IE fix */ 496 position: relative; 497 width: auto; 498 clear: both; 499 } 500 501 #buddypress .activity-list li ul.activity-interactions-nav.hide, 502 #buddypress .activity-list li ul.activity-interactions-nav li.hide { 503 display:none; 504 } 505 506 507 #buddypress .activity-list li ul.activity-interactions-nav li { 508 float: left; 509 margin:0; 510 padding: 4px 8px; 511 font-size: 90%; 512 border-bottom: none; 513 } 514 515 #buddypress .activity-list li ul.activity-interactions-nav li a { 516 text-decoration: none; 517 color:#555; 518 } 519 520 #buddypress .activity-list li ul.activity-interactions-nav li.current { 521 background-color: #eee; 522 color: #555; 523 opacity: .8; 524 font-weight: bold; 525 } 526 527 #buddypress .activity-list li ul.activity-interactions-nav li.current span { 528 background-color: #fff; 529 } 530 531 #buddypress .activity-list li ul.activity-interactions-nav li span { 532 background: #eee; 533 border-radius: 50%; 534 border: 1px solid #ccc; 535 color: #999; 536 display: inline; 537 font-size: 70%; 538 margin-left: 2px; 539 padding: 3px 6px; 540 text-align: center; 541 vertical-align: middle; 542 } 543 544 #buddypress div.activity-favorites { 545 display:none; 546 margin: 0 0 0 70px; 547 overflow: hidden; /* IE fix */ 548 position: relative; 549 width: auto; 550 clear: both; 551 } 552 553 #buddypress div.activity-favorites ul.user-favorites-list li { 554 padding:0; 555 float: left; 556 border-bottom: none; 557 } 558 559 #buddypress div.activity-favorites ul.user-favorites-list { 560 overflow: hidden; 561 list-style: none; 562 width: auto; 563 clear: both; 564 } 565 566 #buddypress div.activity-favorites ul.user-favorites-list li img { 567 border-width: 1px; 568 float: left; 569 height: 25px; 570 margin-right: 10px; 571 width: 25px; 572 } 573 574 487 575 /*-------------------------------------------------------------- 488 576 3.3 - Directories - Members, Groups, Blogs, Forums 489 577 --------------------------------------------------------------*/ -
src/bp-templates/bp-legacy/js/buddypress.js
diff --git src/bp-templates/bp-legacy/js/buddypress.js src/bp-templates/bp-legacy/js/buddypress.js index dd009ea..2a9d045 100644
jq(document).ready( function() { 284 284 target.removeClass('loading'); 285 285 286 286 target.fadeOut( 200, function() { 287 jq(this).html(response );287 jq(this).html(response['button']); 288 288 jq(this).attr('title', 'fav' === type ? BP_DTheme.remove_fav : BP_DTheme.mark_as_fav); 289 289 jq(this).fadeIn(200); 290 290 }); … … jq(document).ready( function() { 297 297 298 298 jq('.item-list-tabs ul #activity-favorites span').html( Number( jq('.item-list-tabs ul #activity-favorites span').html() ) + 1 ); 299 299 } 300 jq('#activity-' + parent_id + ' ul.activity-interactions-nav').removeClass('hide'); 301 jq('#activity-' + parent_id + ' a.activity-favorites-interaction').parent().removeClass('hide'); 302 jq('#activity-' + parent_id + ' a.activity-favorites-interaction span').html( Number( jq('#activity-' + parent_id + ' a.activity-favorites-interaction span').html() ) + 1 ); 303 304 if ( ! jq( '#activity-' + parent_id + ' .user-favorites-list' ).length ) { 305 jq( '#activity-' + parent_id + ' .activity-favorites' ).append('<ul class="user-favorites-list"></ul>'); 306 } 307 308 if ( 0 != response['avatar'] ){ 309 jq( '#activity-' + parent_id + ' .user-favorites-list' ).append( response['avatar'] ); 310 } 300 311 301 312 target.removeClass('fav'); 302 313 target.addClass('unfav'); … … jq(document).ready( function() { 306 317 target.addClass('fav'); 307 318 308 319 jq('.item-list-tabs ul #activity-favorites span').html( Number( jq('.item-list-tabs ul #activity-favorites span').html() ) - 1 ); 320 jq('#activity-' + parent_id + ' a.activity-favorites-interaction span').html( Number( jq('#activity-' + parent_id + ' a.activity-favorites-interaction span').html() ) - 1 ); 321 322 if ( jq( '#activity-' + parent_id + ' .user-favorites-list' ).length ) { 323 jq( '#activity-' + parent_id + ' .user-favorites-list li' ).each( function() { 324 avatar = jq(this).find('img').prop( 'class' ).match( /user-favorite-([0-9]+)/ ); 325 326 if ( typeof avatar != 'undefined' && avatar[1] == response['avatar'] ) { 327 jq(this).remove(); 328 } 329 }); 330 } 309 331 310 332 if ( !Number( jq('.item-list-tabs ul #activity-favorites span').html() ) ) { 311 333 if ( jq('.item-list-tabs ul #activity-favorites').hasClass('selected') ) { … … jq(document).ready( function() { 319 341 if ( 'activity-favorites' === jq( '.item-list-tabs li.selected').attr('id') ) { 320 342 target.closest( '.activity-item' ).slideUp( 100 ); 321 343 } 322 } );344 }, 'json' ); 323 345 324 346 return false; 325 347 } … … jq(document).ready( function() { 459 481 // reset the newest activities now they're displayed 460 482 newest_activities = ''; 461 483 } 484 485 if ( target.parent().hasClass( 'activity-interactions' ) ) { 486 487 event.preventDefault(); 488 489 var css_class = target.attr('class').split( ' ' ), 490 current_div = css_class[0].replace( '-interaction', '' ), 491 div_tohide = '', 492 parent_li = target.parent(), 493 parent_ul = parent_li.parent(); 494 495 parent_ul.children( 'li' ).each( function() { 496 jq( this ).removeClass( 'current' ); 497 498 if ( jq( this ).find('a').prop( 'class' ) != target.prop( 'class' ) ) { 499 div_tohide = jq.trim( jq( this ).find('a').prop( 'class' ) ).replace( '-interaction', '' ); 500 } 501 }); 502 503 jq( parent_li ).addClass( 'current' ); 504 505 if ( ! div_tohide.length ) 506 return 507 508 parent_ul.parent().find( '.' + div_tohide ).first().hide(); 509 parent_ul.parent().find( '.' + current_div ).first().show(); 510 } 462 511 }); 463 512 464 513 // Activity "Read More" links … … jq(document).ready( function() { 507 556 508 557 /* Comment / comment reply links */ 509 558 if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) { 559 560 target.parent().parent().parent().find( '.activity-comments-interaction' ).first().trigger( 'click' ); 561 510 562 if ( target.parent().hasClass('acomment-reply') ) { 511 563 target = target.parent(); 512 564 } … … jq(document).ready( function() { 612 664 jq( '#' + form.attr('id') + ' textarea').val(''); 613 665 614 666 /* Increase the "Reply (X)" button count */ 615 jq('#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 ); 667 jq('#activity-' + form_id[2] + ' ul.activity-interactions-nav').removeClass('hide'); 668 jq('#activity-' + form_id[2] + ' a.activity-comments-interaction span').html( Number( jq('#activity-' + form_id[2] + ' a.activity-comments-interaction span').html() ) + 1 ); 616 669 617 670 // Increment the 'Show all x comments' string, if present 618 671 show_all_a = activity_comments.find('.show-all').find('a');