Ticket #5644: 5644.activity_table.patch
File 5644.activity_table.patch, 60.6 KB (added by , 10 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
diff --git src/bp-activity/bp-activity-actions.php src/bp-activity/bp-activity-actions.php index f8c5d52..6624213 100644
add_action( 'bp_actions', 'bp_activity_action_mentions_feed' ); 600 600 * @return bool False on failure. 601 601 */ 602 602 function bp_activity_action_favorites_feed() { 603 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'favorites') || ! bp_is_action_variable( 'feed', 0 ) ) {603 if ( ! bp_is_user_activity() || ! bp_is_current_action( bp_get_activity_favorite_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) { 604 604 return false; 605 605 } 606 606 … … function bp_activity_action_favorites_feed() { 615 615 /* translators: User activity favorites RSS title - "[Site Name] | [User Display Name] | Favorites" */ 616 616 'title' => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 617 617 618 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/ favorites/',618 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_activity_favorite_slug() . '/', 619 619 'description' => sprintf( __( "Activity feed of %s's favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ), 620 620 'activity_args' => 'include=' . $fav_ids 621 621 ) ); … … function bp_activity_setup_akismet() { 647 647 // Instantiate Akismet for BuddyPress 648 648 $bp->activity->akismet = new BP_Akismet(); 649 649 } 650 651 /** 652 * Add globals for activity favorites / likes 653 * 654 * @since BuddyPress (2.1.0) 655 * 656 * @uses buddypress() to get main instance 657 */ 658 function bp_activity_favorites_globals() { 659 $bp = buddypress(); 660 661 /** 662 * First are we using favorites as likes ? 663 * true if likes is enabled 664 */ 665 $bp->activity->favorites_as_likes = bp_is_activity_favorites_as_likes_active(); 666 667 /** 668 * Second, add some globals for names/slugs/strings 669 * that can be customised using the activity_favorites_as_likes args filter. 670 */ 671 $bp->activity->favorite = new stdClass; 672 673 // Default 674 $favorite_args = array( 675 // Activity action args 676 'description' => _x( 'Favorited an update', 'favorite activity description', 'buddypress' ), 677 'label' => _x( 'Favorites', 'favorite activity dropdown label', 'buddypress' ), 678 'contexts' => array(), 679 // Strings 680 'directory_tab' => _x( 'My Favorites', 'favorite directory tab', 'buddypress' ), 681 'fav_button' => _x( 'Favorite', 'favorite button', 'buddypress' ), 682 'unfav_button' => _x( 'Remove Favorite', 'unfavorite button', 'buddypress' ), 683 // Nav name 684 'subnav' => _x( 'Favorites', 'favorite member subnav', 'buddypress' ), 685 // Slug 686 'slug' => 'favorites' 687 ); 688 689 // Like feature is chosen by admin 690 if ( ! empty( $bp->activity->favorites_as_likes ) ) { 691 $favorite_args = bp_parse_args( 692 array( 693 'description' => _x( 'Liked an update', 'alternative favorite activity description', 'buddypress' ), 694 'label' => _x( 'Likes', 'alternative favorite activity dropdown label', 'buddypress' ), 695 'contexts' => array( 'activity', 'group', 'member', 'member_groups' ), 696 'directory_tab' => _x( 'My Likes', 'alternative favorite directory tab', 'buddypress' ), 697 'fav_button' => _x( 'Like', 'alternative favorite button', 'buddypress' ), 698 'unfav_button' => _x( 'Liked', 'alternative unfavorite button', 'buddypress' ), 699 // Nav name 700 'subnav' => _x( 'Likes', 'alternative favorite member subnav', 'buddypress' ), 701 // Slug 702 'slug' => 'likes' 703 ), 704 $favorite_args, 705 'activity_favorites_as_likes' 706 ); 707 } 708 709 // Set favorite globals 710 foreach ( $favorite_args as $key => $arg ) { 711 $bp->activity->favorite->{$key} = $arg; 712 } 713 } 714 add_action( 'bp_activity_setup_globals', 'bp_activity_favorites_globals' ); -
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..b32a229 100644
class BP_Activity_Activity { 324 324 325 325 // Where conditions 326 326 $where_conditions = array(); 327 $excluded_types = array(); 327 328 328 329 // Spam 329 330 if ( 'ham_only' == $spam ) … … class BP_Activity_Activity { 337 338 $where_conditions['search_sql'] = "a.content LIKE '%%" . esc_sql( like_escape( $search_terms ) ) . "%%'"; 338 339 } 339 340 341 // In activity administration & stream mode, display likes/favorites 342 if ( 'stream' !== $display_comments || empty( $bp->activity->favorites_as_likes ) ) { 343 // Exclude 'activity_favorite' items unless the 'action' filter has 344 // been explicitly set 345 if ( empty( $filter['action'] ) ) { 346 $excluded_types[] = 'activity_favorite'; 347 348 // If explicitly set transform this as a specific meta query in case of likes 349 } else if ( 'activity_favorite' == $filter['action'] && ! empty( $bp->activity->favorites_as_likes ) ) { 350 $meta_query_args = array( 351 'key' => 'activity_favorite', 352 'compare' => 'EXISTS' 353 ); 354 355 if ( ! empty( $filter['user_id'] ) ) { 356 $meta_query_args['compare'] = '='; 357 $meta_query_args['value'] = absint( $filter['user_id'] ); 358 unset( $filter['user_id'] ); 359 } 360 361 $meta_query = array( $meta_query_args ); 362 363 unset( $filter['action'] ); 364 } 365 } 366 340 367 // Filtering 341 368 if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) ) 342 369 $where_conditions['filter_sql'] = $filter_sql; … … class BP_Activity_Activity { 376 403 // comments in the stream like normal comments or threaded below 377 404 // the activity. 378 405 if ( false === $display_comments || 'threaded' === $display_comments ) { 379 $ where_conditions[] = "a.type != 'activity_comment'";406 $excluded_types[] = 'activity_comment'; 380 407 } 381 408 382 409 // Exclude 'last_activity' items unless the 'action' filter has 383 410 // been explicitly set 384 411 if ( empty( $filter['object'] ) ) { 385 $where_conditions[] = "a.type != 'last_activity'"; 412 $excluded_types[] = 'last_activity'; 413 } 414 415 if ( ! empty( $excluded_types ) ) { 416 $where_conditions[] = "a.type NOT IN( '" . implode( "','", $excluded_types ) . "' )"; 386 417 } 387 418 388 419 // Filter the where conditions … … class BP_Activity_Activity { 465 496 // Generate action strings 466 497 $activities = BP_Activity_Activity::generate_action_strings( $activities ); 467 498 499 // Append Favorites / likes 500 $activities = self::append_favorites( $activities ); 501 468 502 // If $max is set, only return up to the max results 469 503 if ( !empty( $max ) ) { 470 504 if ( (int) $total_activities > (int) $max ) … … class BP_Activity_Activity { 644 678 645 679 // WP_Meta_Query expects the table name at 646 680 // $wpdb->activitymeta 647 $wpdb->activitymeta = buddypress()->activity->table_name_meta; 681 if( ! empty( $activity_meta_query->queries[0]['key'] ) && 'activity_favorite' == $activity_meta_query->queries[0]['key'] ) { 682 $wpdb->activitymeta = buddypress()->activity->table_name; 683 } else { 684 $wpdb->activitymeta = buddypress()->activity->table_name_meta; 685 } 648 686 649 687 $meta_sql = $activity_meta_query->get_sql( 'activity', 'a', 'id' ); 650 688 651 689 // Strip the leading AND - BP handles it in get() 652 690 $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] ); 653 691 $sql_array['join'] = $meta_sql['join']; 692 693 if ( buddypress()->activity->table_name == $wpdb->activitymeta ) { 694 $sql_array['join'] = str_replace( 'JOIN '. $wpdb->activitymeta, 'JOIN '. $wpdb->activitymeta . ' f', $sql_array['join'] ); 695 $sql_array['join'] = str_replace( $wpdb->activitymeta .'.activity_id' , 'f.item_id', $sql_array['join'] ); 696 697 if ( 'EXISTS' == strtoupper( $activity_meta_query->queries[0]['compare'] ) ) { 698 $sql_array['where'] = str_replace( $wpdb->activitymeta .'.meta_key', 'f.type', $sql_array['where'] ); 699 } else { 700 $user_id = $activity_meta_query->queries[0]['value']; 701 preg_match( '/CAST\((.*)meta_value(.*)[' .$user_id. ']\'\)/', $sql_array['where'], $matches ); 702 703 if ( ! empty( $matches[1] ) ) { 704 $table = str_replace( $wpdb->activitymeta, 'f', $matches[1] ); 705 $sql_array['where'] = $wpdb->prepare( "( f.type = %s AND {$table}user_id = %d )", $activity_meta_query->queries[0]['key'], $user_id ); 706 } 707 } 708 // Restore activitymeta table 709 $wpdb->activitymeta = buddypress()->activity->table_name_meta; 710 } 654 711 } 655 712 656 713 return $sql_array; … … class BP_Activity_Activity { 811 868 else 812 869 return false; 813 870 814 // Fetch the activity IDs so we can delete any c ommentsfor this activity item871 // Fetch the activity IDs so we can delete any children for this activity item 815 872 $activity_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ); 816 873 817 874 if ( ! $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) { 818 875 return false; 819 876 } 820 877 821 // Handle accompanying activity c ommentsand meta deletion878 // Handle accompanying activity children and meta deletion 822 879 if ( $activity_ids ) { 823 880 $activity_ids_comma = implode( ',', wp_parse_id_list( $activity_ids ) ); 824 $activity_c omments_where_sql = "WHERE type = 'activity_comment'AND item_id IN ({$activity_ids_comma})";881 $activity_children_where_sql = "WHERE type IN ( 'activity_comment', 'activity_favorite' ) AND item_id IN ({$activity_ids_comma})"; 825 882 826 // Fetch the activity c ommentIDs for our deleted activity items827 $activity_c omment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$activity_comments_where_sql}" );883 // Fetch the activity child IDs for our deleted activity items 884 $activity_child_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$activity_children_where_sql}" ); 828 885 829 886 // We have activity comments! 830 if ( ! empty( $activity_c omment_ids ) ) {887 if ( ! empty( $activity_child_ids ) ) { 831 888 // Delete activity comments 832 $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$activity_c omments_where_sql}" );889 $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$activity_children_where_sql}" ); 833 890 834 891 // Merge activity IDs with activity comment IDs 835 $activity_ids = array_merge( $activity_ids, $activity_c omment_ids );892 $activity_ids = array_merge( $activity_ids, $activity_child_ids ); 836 893 } 837 894 838 895 // Delete all activity meta entries for activity items and activity comments … … class BP_Activity_Activity { 1283 1340 * @return int A count of the user's favorites. 1284 1341 */ 1285 1342 public static function total_favorite_count( $user_id ) { 1286 if ( !$favorite_activity_entries = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ) ) 1343 $favorite_activity_entries = self::get_favorites_by_user_id( $user_id ); 1344 1345 if ( empty( $favorite_activity_entries ) ) 1287 1346 return 0; 1288 1347 1289 return count( maybe_unserialize( $favorite_activity_entries ));1348 return count( $favorite_activity_entries ); 1290 1349 } 1291 1350 1292 1351 /** … … class BP_Activity_Activity { 1312 1371 1313 1372 return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) ); 1314 1373 } 1374 1375 /** 1376 * Append user_ids who favorited/liked activities. 1377 * 1378 * @since BuddyPress (2.1.0) 1379 * 1380 * @param array $activities Activities to fetch user who favorited / liked. 1381 * @return array The updated activities with attached user ids. 1382 */ 1383 public static function append_favorites( $activities = array() ) { 1384 1385 // Now fetch the user who liked matching activities. 1386 foreach ( (array) $activities as $key => $activity ) { 1387 if ( 'activity_favorite' == $activity->type ) 1388 continue; 1389 1390 $activities[$key]->favorites = self::get_favorites_by_activity_id( $activity->id ); 1391 } 1392 1393 return $activities; 1394 } 1395 1396 /** 1397 * Get user_ids who favorited/liked activities. 1398 * 1399 * @since BuddyPress (2.1.0) 1400 * 1401 * @param int $activity_id 1402 * @return array $users The users who favorited the activities. 1403 */ 1404 public static function get_favorites_by_activity_id( $activity_id = 0 ) { 1405 global $wpdb; 1406 $bp = buddypress(); 1407 1408 $users = array(); 1409 1410 if ( empty( $activity_id ) ) 1411 return $users; 1412 1413 $users = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->activity->table_name} WHERE type = 'activity_favorite' AND item_id = %d", $activity_id ) ); 1414 return $users; 1415 } 1416 1417 /** 1418 * Get user_ids who favorited/liked activities. 1419 * 1420 * @since BuddyPress (2.1.0) 1421 * 1422 * @param int $user_id 1423 * @param int $activity_id 1424 * @return array $favorites The favorited activities. 1425 */ 1426 public static function get_favorites_by_user_id( $user_id = 0, $activity_id = 0 ) { 1427 global $wpdb; 1428 $bp = buddypress(); 1429 1430 $favorites = array(); 1431 1432 if ( empty( $user_id ) ) 1433 return $favorites; 1434 1435 $where = array( 1436 "type = 'activity_favorite'", 1437 $wpdb->prepare( "user_id = %d", $user_id ) 1438 ); 1439 1440 if ( ! empty( $activity_id ) ) { 1441 $where[] = $wpdb->prepare( "item_id = %d", $activity_id ); 1442 } 1443 1444 $where = 'WHERE ' . implode( ' AND ', $where ); 1445 1446 $favorites = $wpdb->get_col( "SELECT item_id FROM {$bp->activity->table_name} {$where}" ); 1447 return $favorites; 1448 } 1315 1449 } 1316 1450 1317 1451 /** … … class BP_Activity_Feed { 1530 1664 switch ( $this->id ) { 1531 1665 1532 1666 // also output parent activity item if we're on a specific feed 1533 case 'favorites':1667 case bp_get_activity_favorite_slug() : 1534 1668 case 'friends' : 1535 1669 case 'mentions' : 1536 1670 case 'personal' : -
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 507387e..278f121 100644
function bp_activity_get_types() { 367 367 * 368 368 * @since BuddyPress (1.2) 369 369 * 370 * @uses bp_get_user_meta()370 * @uses BP_Activity_Activity::get_favorites_by_user_id() to get user's favorites/likes 371 371 * @uses apply_filters() To call the 'bp_activity_get_user_favorites' hook. 372 372 * 373 373 * @param int $user_id ID of the user whose favorites are being queried. … … function bp_activity_get_user_favorites( $user_id = 0 ) { 380 380 $user_id = bp_displayed_user_id(); 381 381 382 382 // Get favorites for user 383 $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true);383 $favs = BP_Activity_Activity::get_favorites_by_user_id( $user_id ); 384 384 385 385 return apply_filters( 'bp_activity_get_user_favorites', $favs ); 386 386 } … … function bp_activity_get_user_favorites( $user_id = 0 ) { 391 391 * @since BuddyPress (1.2) 392 392 * 393 393 * @uses is_user_logged_in() 394 * @uses bp_get_user_meta() 394 * @uses bp_loggedin_user_id() to default to current user logged in 395 * @uses BP_Activity_Activity::get_favorites_by_user_id() to check if the activity to favorite is not already favorited 395 396 * @uses bp_activity_get_meta() 396 * @uses bp_update_user_meta()397 397 * @uses bp_activity_update_meta() 398 * @uses bp_activity_add_favorite() to create the 'activity_favorite' activity 398 399 * @uses do_action() To call the 'bp_activity_add_user_favorite' hook. 399 400 * @uses do_action() To call the 'bp_activity_add_user_favorite_fail' hook. 400 401 * … … function bp_activity_get_user_favorites( $user_id = 0 ) { 405 406 function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 406 407 407 408 // Favorite activity stream items are for logged in users only 408 if ( ! is_user_logged_in() )409 if ( ! is_user_logged_in() ) 409 410 return false; 410 411 411 412 // Fallback to logged in user if no user_id is passed 412 413 if ( empty( $user_id ) ) 413 414 $user_id = bp_loggedin_user_id(); 414 415 415 $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ); 416 if ( empty( $my_favs ) || ! is_array( $my_favs ) ) { 417 $my_favs = array(); 418 } 416 $is_fav = BP_Activity_Activity::get_favorites_by_user_id( $user_id, $activity_id ); 419 417 420 // Bail if the user has already favorited this activity item421 if ( in_array( $activity_id, $my_favs) ) {418 // Bail if Already favorited 419 if ( ! empty( $is_fav ) ) { 422 420 return false; 423 421 } 424 422 425 // Add to user's favorites426 $my_favs[] = $activity_id;427 428 423 // Update the total number of users who have favorited this activity 429 424 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 430 $fav_count = ! empty( $fav_count ) ? (int) $fav_count + 1 : 1;425 $fav_count = ! empty( $fav_count ) ? (int) $fav_count + 1 : 1; 431 426 432 // Update user meta433 bp_ update_user_meta( $user_id, 'bp_favorite_activities', $my_favs);427 // Update activity meta counts for backcompat 428 bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ); 434 429 435 // Update activity meta counts436 if ( bp_activity_ update_meta( $activity_id, 'favorite_count', $fav_count) ) {430 // Save the favorite 431 if ( bp_activity_add_favorite( $activity_id, $user_id ) ) { 437 432 438 433 // Execute additional code 439 434 do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id ); … … function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 456 451 * @since BuddyPress (1.2) 457 452 * 458 453 * @uses is_user_logged_in() 459 * @uses bp_get_user_meta() 454 * @uses bp_loggedin_user_id() to default to current user logged in 455 * @uses bp_activity_delete_by_item_id() to delete the favorite/like 460 456 * @uses bp_activity_get_meta() 461 457 * @uses bp_activity_update_meta() 462 * @uses bp_update_user_meta()463 458 * @uses do_action() To call the 'bp_activity_remove_user_favorite' hook. 464 459 * 465 460 * @param int $activity_id ID of the activity item being unfavorited. … … function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 469 464 function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) { 470 465 471 466 // Favorite activity stream items are for logged in users only 472 if ( ! is_user_logged_in() )467 if ( ! is_user_logged_in() ) 473 468 return false; 474 469 475 470 // Fallback to logged in user if no user_id is passed 476 471 if ( empty( $user_id ) ) 477 472 $user_id = bp_loggedin_user_id(); 478 473 479 $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ); 480 $my_favs = array_flip( (array) $my_favs ); 474 // the favorite / like is an activity, so let's delete it 475 $removed = bp_activity_delete_by_item_id( array( 476 'item_id' => $activity_id, 477 'type' => 'activity_favorite', 478 'user_id' => $user_id, 479 ) ); 481 480 482 481 // Bail if the user has not previously favorited the item 483 if ( ! isset( $my_favs[ $activity_id ]) ) {482 if ( empty( $removed ) ) { 484 483 return false; 485 484 } 486 485 487 // Remove the fav from the user's favs 488 unset( $my_favs[$activity_id] ); 489 $my_favs = array_unique( array_flip( $my_favs ) ); 486 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 487 488 // Error getting favorite count 489 if ( empty( $fav_count ) ) { 490 return false; 491 } 492 493 // Deduct from total favorites 494 $count_updated = bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ); 490 495 491 // Update the total number of users who have favorited this activity 492 if ( $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ) ) { 496 // Error updating favorite count 497 if ( empty( $count_updated ) ) { 498 return false; 499 } 500 501 // Execute additional code 502 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); 503 504 return true; 505 } 506 507 /** 508 * Add an activity typed 'activity_favorite' for the favorited / liked activity 509 * 510 * The action strings will be adapted at run time if the admin changes the 511 * favorite feature behavior between like or favorite 512 * @see bp_activity_format_activity_action_activity_favorites() 513 * 514 * @since BuddyPress (2.1.0) 515 * @uses BP_Activity_Activity 516 * @uses bp_activity_get_permalink() 517 * @uses bp_core_get_userlink() 518 * @uses bp_activity_add() 519 * @return int|bool the activity id created or false if it fails 520 */ 521 function bp_activity_add_favorite( $activity_id = 0, $user_id = 0 ) { 522 if ( empty( $activity_id ) || empty( $user_id ) ) 523 return false; 493 524 494 // Deduct from total favorites 495 if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) { 525 $bp = buddypress(); 496 526 497 // Update users favorites498 if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) {527 // Parent activity exists ? 528 $activity = new BP_Activity_Activity( $activity_id ); 499 529 500 // Execute additional code 501 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); 530 if ( empty( $activity->type ) || 'activity_favorite' == $activity->type ) { 531 return false; 532 } 502 533 503 // Success504 return true;534 $primary_link = bp_activity_get_permalink( $activity_id, $activity ); 535 $description = $bp->activity->actions->{$bp->activity->id}->activity_favorite['value']; 505 536 506 // Error updating 507 } else { 508 return false; 509 } 537 $action = sprintf( _x( '%1$s %2$s', 'favorite action string', 'buddypress' ), bp_core_get_userlink( $user_id ), $description ); 510 538 511 // Error updating favorite count 512 } else { 513 return false; 539 $args = array( 540 'user_id' => $user_id, 541 'component' => $bp->activity->id, 542 'type' => 'activity_favorite', 543 'action' => $action, 544 'content' => '', 545 'primary_link' => $primary_link, 546 'item_id' => $activity_id, 547 'secondary_item_id' => $activity->user_id 548 ); 549 550 return bp_activity_add( $args ); 551 } 552 553 /** 554 * Migrate user's favorite (previously in bp_favorite_activities user meta) to activity table 555 * 556 * @since BuddyPress (2.1.0) 557 * @uses bp_activity_add_favorite() to create the 'activity_favorite' activities 558 */ 559 function bp_activity_favorites_migrate() { 560 global $wpdb; 561 562 $user_favorites = $wpdb->get_results( "SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = 'bp_favorite_activities'" ); 563 564 foreach( $user_favorites as $meta ) { 565 $meta_value = maybe_unserialize( $meta->meta_value ); 566 567 if ( empty( $meta_value ) ) 568 continue; 569 570 foreach( $meta_value as $favorite ) { 571 bp_activity_add_favorite( $favorite, $meta->user_id ); 514 572 } 515 573 516 // Error getting favorite count517 } else {518 return false;519 574 } 520 575 } 521 576 … … function bp_activity_register_activity_actions() { 854 909 __( 'Activity Comments', 'buddypress' ) 855 910 ); 856 911 912 // Favorites/likes 913 bp_activity_set_action( 914 $bp->activity->id, 915 'activity_favorite', 916 $bp->activity->favorite->description, 917 'bp_activity_format_activity_action_activity_favorites', 918 $bp->activity->favorite->label, 919 $bp->activity->favorite->contexts 920 ); 921 857 922 do_action( 'bp_activity_register_activity_actions' ); 858 923 859 924 // Backpat. Don't use this. … … function bp_activity_format_activity_action_activity_comment( $action, $activity 919 984 return apply_filters( 'bp_activity_comment_action', $action, $activity ); 920 985 } 921 986 987 /** 988 * Format 'activity_favorite' activity actions. 989 * 990 * @since BuddyPress (2.1.0) 991 * 992 * @param string $action Static activity action. 993 * @param object $activity Activity data object. 994 * @return string 995 */ 996 function bp_activity_format_activity_action_activity_favorites( $action, $activity ) { 997 $action = sprintf( _x( '%1$s %2$s', 'favorite action string', 'buddypress' ), bp_core_get_userlink( $activity->user_id ), buddypress()->activity->favorite->description ); 998 return apply_filters( 'bp_activity_favorite_action', $action, $activity ); 999 } 1000 922 1001 /****************************************************************************** 923 1002 * Business functions are where all the magic happens in BuddyPress. They will 924 1003 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 1599 1678 $activity_obj = $activity_obj->current_comment; 1600 1679 } 1601 1680 1602 if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type ) {1681 if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type || 'activity_favorite' == $activity_obj->type ) { 1603 1682 $link = $activity_obj->primary_link; 1604 1683 } else { 1605 1684 if ( 'activity_comment' == $activity_obj->type ) { -
src/bp-activity/bp-activity-loader.php
diff --git src/bp-activity/bp-activity-loader.php src/bp-activity/bp-activity-loader.php index 0f68f91..4c1695b 100644
class BP_Activity_Component extends BP_Component { 185 185 186 186 // Favorite activity items 187 187 $sub_nav[] = array( 188 'name' => __( 'Favorites', 'buddypress'),189 'slug' => 'favorites',188 'name' => bp_get_activity_favorite_nav(), 189 'slug' => bp_get_activity_favorite_slug(), 190 190 'parent_url' => $activity_link, 191 191 'parent_slug' => $this->slug, 192 192 'screen_function' => 'bp_activity_screen_favorites', 193 193 'position' => 30, 194 'item_css_id' => 'activity-favs' 194 'item_css_id' => 'activity-favs', 195 'user_has_access' => ! empty( $this->favorites_as_likes ) ? $this->favorites_as_likes : bp_core_can_edit_settings() 195 196 ); 196 197 197 198 // Additional menu if friends is active … … class BP_Activity_Component extends BP_Component { 291 292 $wp_admin_nav[] = array( 292 293 'parent' => 'my-account-' . $this->id, 293 294 'id' => 'my-account-' . $this->id . '-favorites', 294 'title' => __( 'Favorites', 'buddypress'),295 'href' => trailingslashit( $activity_link . 'favorites')295 'title' => bp_get_activity_favorite_nav(), 296 'href' => trailingslashit( $activity_link . bp_get_activity_favorite_slug() ) 296 297 ); 297 298 298 299 // Friends? -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index 0a7ceeb..1af1135 100644
function bp_activity_root_slug() { 57 57 } 58 58 59 59 /** 60 * Output the activity favorite slug. 61 * 62 * @since BuddyPress (2.1.0) 63 * 64 * @uses bp_get_activity_favorite_slug() 65 */ 66 function bp_activity_favorite_slug() { 67 echo bp_get_activity_favorite_slug(); 68 } 69 /** 70 * Return the activity favorite slug. 71 * 72 * @since BuddyPress (2.1.0) 73 * 74 * @uses apply_filters() To call the 'bp_get_activity_favorite_slug' hook. 75 * @uses buddypress() to get main instance 76 * 77 * @return string The activity favorite slug. 78 */ 79 function bp_get_activity_favorite_slug() { 80 return apply_filters( 'bp_get_activity_favorite_slug', buddypress()->activity->favorite->slug ); 81 } 82 83 /** 84 * Output the activity favorite nav name. 85 * 86 * @since BuddyPress (2.1.0) 87 * 88 * @uses bp_get_activity_favorite_nav() 89 */ 90 function bp_activity_favorite_nav() { 91 echo bp_get_activity_favorite_nav(); 92 } 93 /** 94 * Return the activity favorite nav name. 95 * 96 * @since BuddyPress (2.1.0) 97 * 98 * @uses apply_filters() To call the 'bp_get_activity_favorite_nav' hook. 99 * @uses buddypress() to get main instance 100 * 101 * @return string The activity favorite nav name. 102 */ 103 function bp_get_activity_favorite_nav() { 104 return apply_filters( 'bp_get_activity_favorite_nav', buddypress()->activity->favorite->subnav ); 105 } 106 107 /** 108 * Output the activity favorite fav button caption. 109 * 110 * @since BuddyPress (2.1.0) 111 * 112 * @uses bp_get_activity_favorite_fav_button() 113 */ 114 function bp_activity_favorite_fav_button() { 115 echo bp_get_activity_favorite_fav_button(); 116 } 117 /** 118 * Return the activity favorite fav button caption. 119 * 120 * @since BuddyPress (2.1.0) 121 * 122 * @uses apply_filters() To call the 'bp_get_activity_favorite_fav_button' hook. 123 * @uses buddypress() to get main instance 124 * 125 * @return string The activity favorite fav button caption. 126 */ 127 function bp_get_activity_favorite_fav_button() { 128 return apply_filters( 'bp_get_activity_favorite_fav_button', buddypress()->activity->favorite->fav_button ); 129 } 130 131 /** 132 * Output the activity favorite unfav button caption. 133 * 134 * @since BuddyPress (2.1.0) 135 * 136 * @uses bp_get_activity_favorite_unfav_button() 137 */ 138 function bp_activity_favorite_unfav_button() { 139 echo bp_get_activity_favorite_unfav_button(); 140 } 141 /** 142 * Return the activity favorite unfav button caption. 143 * 144 * @since BuddyPress (2.1.0) 145 * 146 * @uses apply_filters() To call the 'bp_get_activity_favorite_unfav_button' hook. 147 * @uses buddypress() to get main instance 148 * 149 * @return string The activity favorite unfav button caption. 150 */ 151 function bp_get_activity_favorite_unfav_button() { 152 return apply_filters( 'bp_get_activity_favorite_unfav_button', buddypress()->activity->favorite->unfav_button ); 153 } 154 155 /** 156 * Output the activity favorite directory tab caption. 157 * 158 * @since BuddyPress (2.1.0) 159 * 160 * @uses bp_get_activity_favorite_directory_tab() 161 */ 162 function bp_activity_favorite_directory_tab() { 163 echo bp_get_activity_favorite_directory_tab(); 164 } 165 /** 166 * Return the activity favorite directory tab caption. 167 * 168 * @since BuddyPress (2.1.0) 169 * 170 * @uses apply_filters() To call the 'bp_get_activity_favorite_directory_tab' hook. 171 * @uses buddypress() to get main instance 172 * 173 * @return string The activity favorite directory tab caption. 174 */ 175 function bp_get_activity_favorite_directory_tab() { 176 return apply_filters( 'bp_get_activity_favorite_directory_tab', buddypress()->activity->favorite->directory_tab ); 177 } 178 179 /** 60 180 * Output activity directory permalink. 61 181 * 62 182 * @since BuddyPress (1.5) … … class BP_Activity_Template { 184 304 // Check if blog/forum replies are disabled 185 305 $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false; 186 306 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 307 // Fetch specific activity items based on ID's 191 308 if ( !empty( $include ) ) { 192 309 $this->activities = bp_activity_get_specific( array( … … function bp_has_activities( $args = '' ) { 519 636 else 520 637 $scope = bp_current_action(); 521 638 639 // A lot of Ajax/js is done threw markup let's come back to favorites 640 if ( bp_get_activity_favorite_slug() == $scope ) { 641 $scope = 'favorites'; 642 } 643 522 644 // Support for permalinks on single item pages: /groups/my-group/activity/124/ 523 645 if ( bp_is_current_action( bp_get_activity_slug() ) ) 524 646 $include = bp_action_variable( 0 ); … … function bp_has_activities( $args = '' ) { 610 732 } 611 733 break; 612 734 case 'favorites': 613 $favs = bp_activity_get_user_favorites( $user_id ); 614 if ( empty( $favs ) ) 615 return false; 735 if ( ! empty( $bp->activity->favorites_as_likes ) ) { 736 $action = 'activity_favorite'; 737 } else { 738 $favs = bp_activity_get_user_favorites( $user_id ); 739 if ( empty( $favs ) ) 740 return false; 616 741 617 $in = implode( ',', (array) $favs ); 742 $in = implode( ',', (array) $favs ); 743 $user_id = 0; 744 } 618 745 $display_comments = true; 619 $user_id = 0;620 746 break; 621 747 case 'mentions': 622 748 … … function bp_activity_is_favorite() { 1751 1877 function bp_get_activity_is_favorite() { 1752 1878 global $activities_template; 1753 1879 1754 return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) );1880 return apply_filters( 'bp_get_activity_is_favorite', in_array( bp_loggedin_user_id(), (array) $activities_template->activity->favorites ) ); 1755 1881 } 1756 1882 1757 1883 /** … … function bp_activity_can_comment_reply( $comment ) { 2687 2813 } 2688 2814 2689 2815 /** 2690 * Determine if anfavorites are allowed.2816 * Determine if favorites are allowed. 2691 2817 * 2692 * Defaults to true, but can be modified by plugins. 2818 * If likes is the chosen behavior this will return false 2819 * As favorites are activities, activity_favorite type is to exclude 2693 2820 * 2694 2821 * @since BuddyPress (1.5) 2695 2822 * … … function bp_activity_can_comment_reply( $comment ) { 2698 2825 * @return bool $can_favorite True if comment can receive comments. 2699 2826 */ 2700 2827 function bp_activity_can_favorite() { 2701 $can_favorite = true; 2828 global $activities_template; 2829 2830 $can_favorite = ! buddypress()->activity->favorites_as_likes; 2831 2832 if ( ! empty( $activities_template->activity->type ) && 'activity_favorite' == $activities_template->activity->type ) { 2833 $can_favorite = false; 2834 } 2702 2835 2703 2836 return apply_filters( 'bp_activity_can_favorite', $can_favorite ); 2704 2837 } 2705 2838 2706 2839 /** 2840 * Count the users who favorited the current activity. 2841 * 2842 * @since BuddyPress (2.1.0) 2843 * 2844 * @uses apply_filters() To call the 'bp_activity_get_favorite_count' hook. 2845 * 2846 * @return int the number of users who favorited the activity. 2847 */ 2848 function bp_activity_get_favorite_count() { 2849 global $activities_template; 2850 2851 $count = 0; 2852 2853 if ( ! empty( $activities_template->activity->favorites ) ) { 2854 $count = count( (array) $activities_template->activity->favorites ); 2855 } 2856 2857 return apply_filters( 'bp_activity_get_favorite_count', $count ); 2858 } 2859 2860 /** 2707 2861 * Output the total favorite count for a specified user. 2708 2862 * 2709 2863 * @since BuddyPress (1.2) … … function bp_total_favorite_count_for_user( $user_id = 0 ) { 2729 2883 * @return int The total favorite count for the specified user. 2730 2884 */ 2731 2885 function bp_get_total_favorite_count_for_user( $user_id = 0 ) { 2886 // Neutralize Favorite Activity Directory tab 2887 if ( buddypress()->activity->favorites_as_likes ) { 2888 return false; 2889 } 2890 2732 2891 if ( ! $user_id ) { 2733 2892 $user_id = bp_displayed_user_id(); 2734 2893 } … … function bp_total_favorite_count_for_user( $user_id = 0 ) { 2738 2897 add_filter( 'bp_get_total_favorite_count_for_user', 'bp_core_number_format' ); 2739 2898 2740 2899 /** 2900 * Determine if likes are allowed. 2901 * 2902 * If Favorites is the chosen behavior this will return false 2903 * As likes are activities, activity_favorite type is to exclude 2904 * 2905 * @since BuddyPress (2.1.0) 2906 * 2907 * @uses apply_filters() To call the 'bp_activity_can_like' hook. 2908 * 2909 * @return bool $can_like True if activity can be liked. 2910 */ 2911 function bp_activity_can_like() { 2912 global $activities_template; 2913 2914 $can_like = buddypress()->activity->favorites_as_likes; 2915 2916 if ( ! empty( $activities_template->activity->type ) && 'activity_favorite' == $activities_template->activity->type ) { 2917 $can_like = false; 2918 } 2919 2920 return apply_filters( 'bp_activity_can_like', $can_like ); 2921 } 2922 2923 /** 2924 * Output the total like count for a specified user. 2925 * 2926 * @since BuddyPress (2.1.0) 2927 * 2928 * @see bp_get_total_like_count_for_user() for description of parameters. 2929 * @uses bp_get_total_like_count_for_user() 2930 * 2931 * @param int $user_id See {@link bp_get_total_like_count_for_user()}. 2932 */ 2933 function bp_total_like_count_for_user( $user_id = 0 ) { 2934 echo bp_get_total_like_count_for_user( $user_id ); 2935 } 2936 2937 /** 2938 * Return the total like count for a specified user. 2939 * 2940 * @since BuddyPress (2.1.0) 2941 * 2942 * @uses bp_activity_total_favorites_for_user() 2943 * @uses apply_filters() To call the 'bp_get_total_like_count_for_user' hook 2944 * 2945 * @param int $user_id ID of user being queried. Default: displayed user ID. 2946 * @return int The total favorite count for the specified user. 2947 */ 2948 function bp_get_total_like_count_for_user( $user_id = 0 ) { 2949 // Neutralize Like Activity Directory tab 2950 if ( ! buddypress()->activity->favorites_as_likes ) { 2951 return false; 2952 } 2953 2954 if ( ! $user_id ) { 2955 $user_id = bp_displayed_user_id(); 2956 } 2957 2958 return apply_filters( 'bp_get_total_like_count_for_user', bp_activity_total_favorites_for_user( $user_id ) ); 2959 } 2960 add_filter( 'bp_get_total_like_count_for_user', 'bp_core_number_format' ); 2961 2962 2963 /** 2964 * Output the Activity Directory tab for likes. 2965 * 2966 * To maximize theme backcompat uses the hook bp_before_activity_type_tab_favorites 2967 * 2968 * @since BuddyPress (2.1.0) 2969 * 2970 * @uses bp_get_total_like_count_for_user() 2971 */ 2972 function bp_activity_likes_directory_tab() { 2973 if ( bp_get_total_like_count_for_user( bp_loggedin_user_id() ) ) : ?> 2974 2975 <li id="activity-favorites"><a href="<?php echo bp_loggedin_user_domain() . bp_get_activity_slug() . '/' . bp_get_activity_favorite_slug() . '/'; ?>" title="<?php esc_attr_e( "The activity I've liked.", 'buddypress' ); ?>"><?php printf( _x( '%1$s <span>%2$s</span>', 'alternative favorite directory tab output', 'buddypress' ), bp_get_activity_favorite_directory_tab(), bp_get_total_like_count_for_user( bp_loggedin_user_id() ) ); ?></a></li> 2976 2977 <?php endif; 2978 } 2979 add_action( 'bp_before_activity_type_tab_favorites', 'bp_activity_likes_directory_tab' ); 2980 2981 /** 2982 * Output the Like Button. 2983 * 2984 * To maximize theme backcompat uses the hook bp_activity_entry_meta 2985 * 2986 * @since BuddyPress (2.1.0) 2987 * 2988 * @uses bp_activity_get_like_button() 2989 */ 2990 function bp_activity_like_button() { 2991 if ( ! bp_activity_can_like() ) { 2992 return; 2993 } 2994 2995 echo bp_activity_get_like_button(); 2996 } 2997 add_action( 'bp_activity_entry_meta', 'bp_activity_like_button' ); 2998 2999 /** 3000 * Return the Like Button. 3001 * 3002 * @since BuddyPress (2.1.0) 3003 * 3004 * @uses bp_get_activity_favorite_link() 3005 * @uses bp_get_activity_favorite_fav_button() 3006 * @uses bp_get_activity_favorite_unfav_button() 3007 */ 3008 function bp_activity_get_like_button() { 3009 global $activities_template; 3010 3011 $user_id = bp_loggedin_user_id(); 3012 $likes = ! empty( $activities_template->activity->favorites ) ? $activities_template->activity->favorites : array(); 3013 3014 $attributes = array( 3015 bp_get_activity_favorite_link(), 3016 'button like bp-primary-action', 3017 bp_get_activity_favorite_fav_button() 3018 ); 3019 3020 if ( ! empty( $user_id ) && in_array( $user_id, $likes ) ) { 3021 $attributes = array( 3022 trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() . '/' . bp_get_activity_favorite_slug() ), 3023 'button liked bp-primary-action', 3024 bp_get_activity_favorite_unfav_button() 3025 ); 3026 } 3027 3028 $link = '<a href="' . esc_url( $attributes[0] ). '" class="' . esc_attr( $attributes[1] ). '" title="' . esc_attr( $attributes[2] ) . '">' . esc_html( $attributes[2] ) . ' <span>'. bp_activity_get_favorite_count() .'</span></a>'; 3029 3030 return apply_filters( 'bp_activity_get_like_button', $link, $attributes ); 3031 } 3032 3033 /** 3034 * Output the List of users who liked the activity 3035 * 3036 * To maximize theme backcompat uses the hook bp_after_activity_entry_comments 3037 * 3038 * @since BuddyPress (2.1.0) 3039 * 3040 * @uses bp_get_activity_likes() 3041 */ 3042 function bp_activity_likes() { 3043 echo bp_get_activity_likes(); 3044 } 3045 add_action( 'bp_after_activity_entry_comments', 'bp_activity_likes' ); 3046 3047 /** 3048 * Return the List of users who liked the activity 3049 * 3050 * @since BuddyPress (2.1.0) 3051 * 3052 * @uses bp_activity_list_likes() 3053 */ 3054 function bp_get_activity_likes() { 3055 if ( empty( buddypress()->activity->favorites_as_likes ) ) { 3056 return; 3057 } 3058 3059 if ( 0 == bp_activity_get_comment_count() ) { 3060 $output = '<div class="activity-likes">'; 3061 } else { 3062 $output = '<div class="activity-likes hide">'; 3063 } 3064 3065 $output .= bp_activity_list_likes() . '</div>'; 3066 3067 return $output; 3068 } 3069 3070 /** 3071 * Build the List of users who liked the activity 3072 * 3073 * @since BuddyPress (2.1.0) 3074 */ 3075 function bp_activity_list_likes() { 3076 global $activities_template; 3077 3078 if ( empty( $activities_template->activity->favorites ) ) { 3079 return; 3080 } 3081 3082 $output = '<ul class="likes-list">'; 3083 3084 foreach( (array) $activities_template->activity->favorites as $user_id ) { 3085 $user_avatar = bp_core_fetch_avatar( array( 3086 'item_id' => $user_id, 3087 'object' => 'user', 3088 'type' => 'thumb', 3089 'width' => 50, 3090 'height' => 50, 3091 'html' => true, 3092 'class' => 'user-liked-' . $user_id 3093 ) ); 3094 $output .= '<li><a href="' . bp_core_get_userlink( $user_id, false, true ) .'">' . $user_avatar . '</a></li>'; 3095 } 3096 3097 $output .= '</ul>'; 3098 3099 return apply_filters( 'bp_get_activity_likes', $output, $activities_template->activity->id, $activities_template->activity->favorites ); 3100 } 3101 3102 /** 3103 * Output the interaction nav to switch between comments & favorites/likes 3104 * 3105 * To maximize theme backcompat uses the hook bp_before_activity_entry_comments 3106 * 3107 * @since BuddyPress (2.1.0) 3108 * 3109 * @uses bp_get_activity_interactions_nav() 3110 */ 3111 function bp_activity_interactions_nav() { 3112 echo bp_get_activity_interactions_nav(); 3113 } 3114 add_action( 'bp_before_activity_entry_comments', 'bp_activity_interactions_nav' ); 3115 3116 /** 3117 * Return the interaction nav to switch between comments & favorites/likes 3118 * 3119 * @since BuddyPress (2.1.0) 3120 */ 3121 function bp_get_activity_interactions_nav() { 3122 global $activities_template; 3123 3124 if ( empty( buddypress()->activity->favorites_as_likes ) ) { 3125 return false; 3126 } 3127 3128 $can_comment = bp_activity_can_comment(); 3129 3130 if ( ( is_user_logged_in() && $can_comment ) || ( is_user_logged_in() && bp_activity_can_like() ) || bp_is_single_activity() ) { 3131 3132 $class_nav = $class_like = $class_comment = ''; 3133 $comments_count = bp_activity_get_comment_count(); 3134 $likes_count = bp_activity_get_favorite_count(); 3135 3136 if ( 0 == $comments_count + $likes_count ) { 3137 $class_nav = ' hide'; 3138 } 3139 3140 $output = '<ul class="activity-interactions-nav'. $class_nav .'">'; 3141 3142 if ( ! $can_comment ) { 3143 $class_comment = ' hide'; 3144 } else if ( 0 != $comments_count ) { 3145 $class_comment = ' current'; 3146 } 3147 3148 $output .= '<li class="activity-interactions'. $class_comment .'"><a href="#" class="activity-comments-interaction">' . __( 'Replies', 'buddypress' ) . '</a></li>'; 3149 3150 if ( 0 == $likes_count ) { 3151 $class_like = ' hide'; 3152 } else if ( ! $can_comment || 0 == $comments_count ) { 3153 $class_like = ' current'; 3154 } 3155 3156 $output .= '<li class="activity-interactions'. $class_like .'"><a href="#" class="activity-likes-interaction">' . bp_get_activity_favorite_nav() . '</a></li>'; 3157 3158 $output .= '</ul>'; 3159 3160 } else { 3161 $output = false; 3162 } 3163 3164 return apply_filters( 'bp_get_activity_interactions_nav', $output ); 3165 } 3166 3167 /** 2741 3168 * Output the total mention count for a specified user. 2742 3169 * 2743 3170 * @since BuddyPress (1.2) … … function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link 3170 3597 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/'; 3171 3598 elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) 3172 3599 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/'; 3173 elseif ( 'favorites'== bp_current_action() )3174 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/ favorites/feed/';3600 elseif ( bp_get_activity_favorite_slug() == bp_current_action() ) 3601 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_activity_favorite_slug() . '/feed/'; 3175 3602 elseif ( 'mentions' == bp_current_action() && bp_activity_do_mentions() ) 3176 3603 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; 3177 3604 else -
src/bp-core/admin/bp-core-settings.php
diff --git src/bp-core/admin/bp-core-settings.php src/bp-core/admin/bp-core-settings.php index e112df7..8f6b763 100644
function bp_admin_setting_callback_heartbeat() { 118 118 } 119 119 120 120 /** 121 * Allow Activity to be treated as likes. 122 * 123 * @since BuddyPress (2.1.0) 124 */ 125 function bp_admin_setting_callback_favorites() { 126 ?> 127 128 <input id="_bp_enable_favorites_as_likes" name="_bp_enable_favorites_as_likes" type="checkbox" value="1" <?php checked( bp_is_activity_favorites_as_likes_active( true ) ); ?> /> 129 <label for="_bp_enable_favorites_as_likes"><?php _e( 'Use favorites as a like feature', 'buddypress' ); ?></label> 130 131 <?php 132 } 133 134 /** 121 135 * Sanitization for _bp_force_buddyvar 122 136 * 123 137 * If upgraded to 1.6 and you chose to keep the BuddyBar, a checkbox asks if you want to switch to -
src/bp-core/bp-core-admin.php
diff --git src/bp-core/bp-core-admin.php src/bp-core/bp-core-admin.php index 8942a82..2d94892 100644
class BP_Admin { 385 385 add_settings_field( '_bp_enable_heartbeat_refresh', __( 'Activity auto-refresh', 'buddypress' ), 'bp_admin_setting_callback_heartbeat', 'buddypress', 'bp_activity' ); 386 386 register_setting( 'buddypress', '_bp_enable_heartbeat_refresh', 'intval' ); 387 387 388 // Activity Favorites preferences (Bookmark or like ?) 389 add_settings_field( '_bp_enable_favorites_as_likes', __( 'Activity Favorites', 'buddypress' ), 'bp_admin_setting_callback_favorites', 'buddypress', 'bp_activity' ); 390 register_setting( 'buddypress', '_bp_enable_favorites_as_likes', 'intval' ); 391 388 392 // Allow activity akismet 389 393 if ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) { 390 394 add_settings_field( '_bp_enable_akismet', __( 'Akismet', 'buddypress' ), 'bp_admin_setting_callback_activity_akismet', 'buddypress', 'bp_activity' ); -
src/bp-core/bp-core-options.php
diff --git src/bp-core/bp-core-options.php src/bp-core/bp-core-options.php index 580ceb1..389390d 100644
function bp_get_default_options() { 81 81 // HeartBeat is on to refresh activities 82 82 '_bp_enable_heartbeat_refresh' => true, 83 83 84 /** Activity Favorites as likes ***************************************/ 85 86 // Favorites are to use as likes 87 '_bp_enable_favorites_as_likes' => true, 88 84 89 /** BuddyBar **********************************************************/ 85 90 86 91 // Force the BuddyBar … … function bp_is_activity_heartbeat_active( $default = true ) { 605 610 } 606 611 607 612 /** 613 * Check whether Favorites should be treated as private bookmarks or public likes. 614 * 615 * @since BuddyPress (2.1.0) 616 * 617 * @uses bp_get_option() To get the Favorites as likes option. 618 * 619 * @param bool $default Optional. Fallback value if not found in the database. 620 * Default: true. 621 * @return bool True if Use favorites as likes is enabled, otherwise false. 622 */ 623 function bp_is_activity_favorites_as_likes_active( $default = true ) { 624 return (bool) apply_filters( 'bp_is_activity_favorites_as_likes_active', (bool) bp_get_option( '_bp_enable_favorites_as_likes', $default ) ); 625 } 626 627 /** 608 628 * Get the current theme package ID. 609 629 * 610 630 * @since BuddyPress (1.7.0) -
src/bp-core/bp-core-update.php
diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php index 20bdb6c..9dca4c5 100644
function bp_version_updater() { 240 240 if ( $raw_db_version < 8311 ) { 241 241 bp_update_to_2_0_1(); 242 242 } 243 244 // 2.1 245 if ( $raw_db_version < 8312 ) { 246 bp_update_to_2_1(); 247 } 243 248 } 244 249 245 250 /** All done! *************************************************************/ … … function bp_update_to_2_0_1() { 388 393 bp_core_maybe_install_signups(); 389 394 } 390 395 396 /** 397 * 2.1 database upgrade routine 398 * 399 * @since BuddyPress (2.1.0) 400 * 401 * @return void 402 */ 403 function bp_update_to_2_1() { 404 /** Migrate favorites data ******************************************/ 405 if ( bp_is_active( 'activity' ) ) { 406 bp_activity_favorites_migrate(); 407 } 408 } 409 391 410 /** 392 411 * Redirect user to BP's What's New page on first page load after activation. 393 412 * -
src/bp-loader.php
diff --git src/bp-loader.php src/bp-loader.php index bdd3012..ca5aea5 100644
class BuddyPress { 302 302 /** Versions **********************************************************/ 303 303 304 304 $this->version = '2.1-alpha'; 305 $this->db_version = 831 1;305 $this->db_version = 8312; 306 306 307 307 /** Loading ***********************************************************/ 308 308 -
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..d979e9b 100644
class BP_Legacy extends BP_Theme_Compat { 232 232 233 233 // Add words that we need to use in JS to the end of the page 234 234 // so they can be translated and still used. 235 $params = a pply_filters( 'bp_core_get_js_strings', array(235 $params = array( 236 236 'accepted' => __( 'Accepted', 'buddypress' ), 237 237 'close' => __( 'Close', 'buddypress' ), 238 238 'comments' => __( 'comments', 'buddypress' ), 239 239 'leave_group_confirm' => __( 'Are you sure you want to leave this group?', 'buddypress' ), 240 'mark_as_fav' => __( 'Favorite', 'buddypress' ),241 'my_favs' => __( 'My Favorites', 'buddypress' ),242 240 'rejected' => __( 'Rejected', 'buddypress' ), 243 'remove_fav' => __( 'Remove Favorite', 'buddypress' ),244 241 'show_all' => __( 'Show all', 'buddypress' ), 245 242 'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ), 246 243 'show_x_comments' => __( 'Show all %d comments', 'buddypress' ), 247 244 'unsaved_changes' => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ), 248 245 'view' => __( 'View', 'buddypress' ), 249 ) ); 246 ); 247 248 if ( bp_is_active( 'activity' ) ) { 249 $params = array_merge( $params, array( 250 'mark_as_fav' => bp_get_activity_favorite_fav_button(), 251 'remove_fav' => bp_get_activity_favorite_unfav_button(), 252 'my_favs' => bp_get_activity_favorite_directory_tab(), 253 ) ); 254 } 255 256 // Allow strings to be filtered 257 $params = apply_filters( 'bp_core_get_js_strings', $params ); 258 250 259 wp_localize_script( $asset['handle'], 'BP_DTheme', $params ); 251 260 252 261 // Maybe enqueue comment reply JS … … function bp_legacy_theme_activity_template_loader() { 648 657 $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/groups/feed/'; 649 658 break; 650 659 case 'favorites': 651 $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/ favorites/feed/';660 $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/' . bp_get_activity_favorite_slug() . '/feed/'; 652 661 break; 653 662 case 'mentions': 654 663 $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; … … function bp_legacy_theme_mark_activity_favorite() { 919 928 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 920 929 return; 921 930 922 if ( bp_activity_add_user_favorite( $_POST['id'] ) ) 923 _e( 'Remove Favorite', 'buddypress' ); 924 else 925 _e( 'Favorite', 'buddypress' ); 931 $result = array(); 932 933 if ( bp_activity_add_user_favorite( $_POST['id'] ) ){ 934 $result['button'] = bp_get_activity_favorite_unfav_button(); 935 936 if ( buddypress()->activity->favorites_as_likes ) { 937 $user_id = bp_loggedin_user_id(); 938 $user_avatar = bp_core_fetch_avatar( array( 939 'item_id' => $user_id, 940 'object' => 'user', 941 'type' => 'thumb', 942 'width' => 50, 943 'height' => 50, 944 'html' => true, 945 'class' => 'user-liked-' . $user_id 946 ) ); 947 $result['avatar'] = '<li><a href="' . bp_core_get_userlink( $user_id, false, true ) .'">' . $user_avatar . '</a></li>'; 948 } 949 } else { 950 $result['button'] = bp_get_activity_favorite_fav_button(); 951 $result['avatar'] = 0; 952 } 926 953 927 exit ;954 exit( json_encode( $result ) ); 928 955 } 929 956 930 957 /** … … function bp_legacy_theme_unmark_activity_favorite() { 938 965 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 939 966 return; 940 967 968 $result = array(); 969 941 970 if ( bp_activity_remove_user_favorite( $_POST['id'] ) ) 942 _e( 'Favorite', 'buddypress');971 $result['button'] = bp_get_activity_favorite_fav_button(); 943 972 else 944 _e( 'Remove Favorite', 'buddypress');973 $result['button'] = bp_get_activity_favorite_unfav_button(); 945 974 946 exit ;975 exit( json_encode( $result ) ); 947 976 } 948 977 949 978 /** -
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..df8546c 100644
63 63 64 64 <?php if ( !bp_get_activity_is_favorite() ) : ?> 65 65 66 <a href="<?php bp_activity_favorite_link(); ?>" class="button fav bp-secondary-action" title="<?php esc_attr_e( 'Mark as Favorite', 'buddypress' ); ?>"><?php _e( 'Favorite', 'buddypress'); ?></a>66 <a href="<?php bp_activity_favorite_link(); ?>" class="button fav bp-secondary-action" title="<?php esc_attr_e( 'Mark as Favorite', 'buddypress' ); ?>"><?php bp_activity_favorite_fav_button(); ?></a> 67 67 68 68 <?php else : ?> 69 69 70 <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( 'Remove Favorite', 'buddypress' ); ?>"><?php _e( 'Remove Favorite', 'buddypress'); ?></a>70 <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( 'Remove Favorite', 'buddypress' ); ?>"><?php bp_activity_favorite_unfav_button(); ?></a> 71 71 72 72 <?php endif; ?> 73 73 74 74 <?php endif; ?> 75 75 76 <?php do_action( 'bp_activity_entry_meta' ); ?> 77 76 78 <?php if ( bp_activity_user_can_delete() ) bp_activity_delete_link(); ?> 77 79 78 <?php do_action( 'bp_activity_ entry_meta' ); ?>80 <?php do_action( 'bp_activity_after_delete_button_entry_meta' ); ?> 79 81 80 82 <?php endif; ?> 81 83 -
src/bp-templates/bp-legacy/buddypress/activity/index.php
diff --git src/bp-templates/bp-legacy/buddypress/activity/index.php src/bp-templates/bp-legacy/buddypress/activity/index.php index 09edc01..0954b95 100644
48 48 49 49 <?php if ( bp_get_total_favorite_count_for_user( bp_loggedin_user_id() ) ) : ?> 50 50 51 <li id="activity-favorites"><a href="<?php echo bp_loggedin_user_domain() . bp_get_activity_slug() . '/ favorites/'; ?>" title="<?php esc_attr_e( "The activity I've marked as a favorite.", 'buddypress' ); ?>"><?php printf( __( 'My Favorites <span>%s</span>', 'buddypress'), bp_get_total_favorite_count_for_user( bp_loggedin_user_id() ) ); ?></a></li>51 <li id="activity-favorites"><a href="<?php echo bp_loggedin_user_domain() . bp_get_activity_slug() . '/' . bp_get_activity_favorite_slug() . '/'; ?>" title="<?php esc_attr_e( "The activity I've marked as a favorite.", 'buddypress' ); ?>"><?php printf( _x( '%1$s <span>%2$s</span>', 'favorite directory tab output', 'buddypress' ), bp_get_activity_favorite_directory_tab(), bp_get_total_favorite_count_for_user( bp_loggedin_user_id() ) ); ?></a></li> 52 52 53 53 <?php endif; ?> 54 54 -
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..adc1b55 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 Likes 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 { 485 486 } 486 487 487 488 /*-------------------------------------------------------------- 489 +3.1.3 - Activity Likes 490 +--------------------------------------------------------------*/ 491 #buddypress .activity-list li ul.activity-interactions-nav { 492 list-style: none; 493 margin: 20px 0 10px 70px; 494 overflow: hidden; /* IE fix */ 495 position: relative; 496 width: auto; 497 clear: both; 498 } 499 500 body.activity-permalink #buddypress li ul.activity-interactions-nav { 501 background: none; 502 margin-left: 170px; 503 width: auto; 504 } 505 506 #buddypress .activity-list li ul.activity-interactions-nav.hide, 507 #buddypress .activity-list li ul.activity-interactions-nav li.hide { 508 display:none; 509 } 510 511 512 #buddypress .activity-list li ul.activity-interactions-nav li { 513 float: left; 514 margin:0; 515 padding: 4px 8px; 516 font-size: 90%; 517 border-bottom: none; 518 } 519 520 #buddypress .activity-list li ul.activity-interactions-nav li a { 521 text-decoration: none; 522 color:#555; 523 } 524 525 #buddypress .activity-list li ul.activity-interactions-nav li.current { 526 background-color: #eee; 527 color: #555; 528 opacity: .8; 529 font-weight: bold; 530 } 531 532 #buddypress div.activity-likes { 533 margin: 0 0 0 70px; 534 overflow: hidden; /* IE fix */ 535 position: relative; 536 width: auto; 537 clear: both; 538 } 539 540 #buddypress div.activity-likes.hide, 541 body.activity-permalink #buddypress div.activity-likes.hide { 542 display:none; 543 } 544 545 body.activity-permalink #buddypress div.activity-likes { 546 margin-left: 170px; 547 } 548 549 #buddypress div.activity-likes ul.likes-list li { 550 padding:0; 551 float: left; 552 border-bottom: none; 553 } 554 555 #buddypress div.activity-likes ul.likes-list { 556 overflow: hidden; 557 list-style: none; 558 width: auto; 559 clear: both; 560 } 561 562 #buddypress div.activity-likes ul.likes-list li img { 563 border-width: 1px; 564 float: left; 565 height: 25px; 566 margin-right: 10px; 567 width: 25px; 568 } 569 570 /*-------------------------------------------------------------- 488 571 3.3 - Directories - Members, Groups, Blogs, Forums 489 572 --------------------------------------------------------------*/ 490 573 #buddypress div.dir-search { -
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 dea38a0..9b369f8 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() { 319 319 if ( 'activity-favorites' === jq( '.item-list-tabs li.selected').attr('id') ) { 320 320 target.closest( '.activity-item' ).slideUp( 100 ); 321 321 } 322 } );322 }, 'json' ); 323 323 324 324 return false; 325 325 } 326 326 327 /* Liking activity stream items */ 328 if ( target.hasClass( 'like' ) || target.hasClass( 'liked' ) || target.parent().hasClass( 'like' ) || target.parent().hasClass( 'liked' ) ) { 329 event.preventDefault(); 330 331 if ( target.parent().hasClass( 'like' ) || target.parent().hasClass( 'liked' ) ) { 332 target = target.parent(); 333 } 334 335 type = target.hasClass( 'like' ) ? 'fav' : 'liked'; 336 parent = target.closest( '.activity-item' ); 337 parent_id = parent.attr( 'id' ).substr( 9, parent.attr( 'id' ).length ); 338 count = Number( jq( target ).find( 'span' ).html() ); 339 340 jq( '#activity-' + parent_id + ' .activity-interactions-nav' ).removeClass( 'hide' ); 341 jq( '#activity-' + parent_id + ' a.activity-likes-interaction' ).parent( 'li' ).removeClass( 'hide' ); 342 jq( '#activity-' + parent_id + ' a.activity-likes-interaction' ).trigger( 'click' ); 343 344 if( 'liked' == type ) { 345 return; 346 } 347 348 target.addClass('loading'); 349 350 jq.post( ajaxurl, { 351 action: 'activity_mark_' + type, 352 'cookie': bp_get_cookies(), 353 'id': parent_id 354 }, 355 function(response) { 356 target.removeClass('loading'); 357 358 target.fadeOut( 200, function() { 359 count = Number( count ) + 1; 360 jq(this).html( response['button'] + ' <span>' + count +'</span>' ); 361 jq(this).prop( 'title', BP_DTheme.remove_fav ); 362 jq(this).prop( 'href', '#' ); 363 jq(this).fadeIn( 200 ); 364 }); 365 366 if ( ! jq('.item-list-tabs #activity-favs-personal-li').length ) { 367 if ( ! jq('.item-list-tabs #activity-favorites').length ) { 368 jq('.item-list-tabs ul #activity-mentions').before( '<li id="activity-favorites"><a href="#">' + BP_DTheme.my_favs + ' <span>0</span></a></li>' ); 369 } 370 371 jq('.item-list-tabs ul #activity-favorites span').html( Number( jq('.item-list-tabs ul #activity-favorites span').html() ) + 1 ); 372 } 373 374 if ( ! jq( '#activity-' + parent_id + ' .likes-list' ).length ) { 375 jq( '#activity-' + parent_id + ' .activity-likes' ).append( '<ul class="likes-list"></ul>' ); 376 } 377 378 if ( 0 != response['avatar'] ){ 379 jq( '#activity-' + parent_id + ' .likes-list' ).append( response['avatar'] ); 380 } 381 382 target.removeClass( 'like' ); 383 target.addClass( 'liked' ); 384 385 }, 'json' ); 386 387 return; 388 } 389 327 390 /* Delete activity stream items */ 328 391 if ( target.hasClass('delete-activity') ) { 329 392 li = target.parents('div.activity ul li'); … … jq(document).ready( function() { 459 522 // reset the newest activities now they're displayed 460 523 newest_activities = ''; 461 524 } 525 526 if ( target.parent().hasClass( 'activity-interactions' ) ) { 527 528 event.preventDefault(); 529 530 var css_class = target.attr('class').split( ' ' ), 531 current_div = css_class[0].replace( '-interaction', '' ), 532 div_tohide = '', 533 parent_li = target.parent(), 534 parent_ul = parent_li.parent(); 535 536 parent_ul.children( 'li' ).each( function() { 537 jq( this ).removeClass( 'current' ); 538 539 if ( jq( this ).find('a').prop( 'class' ) != target.prop( 'class' ) ) { 540 div_tohide = jq.trim( jq( this ).find('a').prop( 'class' ) ).replace( '-interaction', '' ); 541 } 542 }); 543 544 jq( parent_li ).addClass( 'current' ); 545 546 if ( ! div_tohide.length ) 547 return 548 549 parent_ul.parent().find( '.' + div_tohide ).first().hide(); 550 parent_ul.parent().find( '.' + current_div ).first().show(); 551 } 462 552 }); 463 553 464 554 // Activity "Read More" links … … jq(document).ready( function() { 507 597 508 598 /* Comment / comment reply links */ 509 599 if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) { 600 target.parent().parent().parent().find( '.activity-comments-interaction' ).first().trigger( 'click' ); 601 510 602 if ( target.parent().hasClass('acomment-reply') ) { 511 603 target = target.parent(); 512 604 } … … jq(document).ready( function() { 613 705 614 706 /* Increase the "Reply (X)" button count */ 615 707 jq('#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 ); 708 jq('#activity-' + form_id[2] + ' ul.activity-interactions-nav').removeClass('hide'); 616 709 617 710 // Increment the 'Show all x comments' string, if present 618 711 show_all_a = activity_comments.find('.show-all').find('a');