Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/12/2013 10:08:10 PM (9 years ago)
Author:
boonebgorges
Message:

Introduces BP_Activity_Feed class, and migrates existing feeds

RSS feeds for BP activity have historically been generated on a one-by-one
basis, with separate template files used for each theme. This resulted in a
huge amount of unnecessarily duplicated code. Moreover, it made the process
of customizing feeds, or providing new feeds, unnecessarily cumbersome.

BP_Activity_Feed abstracts the central parts of RSS feed building, allowing for
easier customization, and fewer points of failure.

This changeset also fixes our RSS implementation to match best practices with
respect to encoding content inside of the <description> element.

Fixes #5020

Props r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-actions.php

    r7193 r7207  
    422422 */
    423423function bp_activity_action_sitewide_feed() {
    424     global $bp, $wp_query;
    425 
    426     if ( !bp_is_activity_component() || !bp_is_current_action( 'feed' ) || bp_is_user() || !empty( $bp->groups->current_group ) )
    427         return false;
    428 
    429     $wp_query->is_404 = false;
    430     status_header( 200 );
    431 
    432     include_once( 'feeds/bp-activity-sitewide-feed.php' );
    433     die;
     424    global $bp;
     425
     426    if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )
     427        return false;
     428
     429    // setup the feed
     430    buddypress()->activity->feed = new BP_Activity_Feed( array(
     431        'id'            => 'sitewide',
     432
     433        /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */
     434        'title'         => sprintf( __( '%s | Site Wide Activity', 'buddypress' ), bp_get_site_name() ),
     435
     436        'link'          => bp_get_activity_directory_permalink(),
     437        'description'   => __( 'Activity feed for the entire site.', 'buddypress' ),
     438        'activity_args' => 'display_comments=threaded'
     439    ) );
    434440}
    435441add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' );
     
    448454 */
    449455function bp_activity_action_personal_feed() {
    450     global $wp_query;
    451 
    452     if ( !bp_is_user_activity() || !bp_is_current_action( 'feed' ) )
    453         return false;
    454 
    455     $wp_query->is_404 = false;
    456     status_header( 200 );
    457 
    458     include_once( 'feeds/bp-activity-personal-feed.php' );
    459     die;
     456    if ( ! bp_is_user_activity() || ! bp_is_current_action( 'feed' ) ) {
     457        return false;
     458    }
     459
     460    // setup the feed
     461    buddypress()->activity->feed = new BP_Activity_Feed( array(
     462        'id'            => 'personal',
     463
     464        /* translators: Personal activity RSS title - "[Site Name] | [User Display Name] | Activity" */
     465        'title'         => sprintf( __( '%1$s | %2$s | Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     466
     467        'link'          => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ),
     468        'description'   => sprintf( __( 'Activity feed for %s.', 'buddypress' ), bp_get_displayed_user_fullname() ),
     469        'activity_args' => 'user_id=' . bp_displayed_user_id()
     470    ) );
    460471}
    461472add_action( 'bp_actions', 'bp_activity_action_personal_feed' );
     
    477488 */
    478489function bp_activity_action_friends_feed() {
    479     global $wp_query;
    480 
    481     if ( !bp_is_active( 'friends' ) || !bp_is_user_activity() || !bp_is_current_action( bp_get_friends_slug() ) || !bp_is_action_variable( 'feed', 0 ) )
    482         return false;
    483 
    484     $wp_query->is_404 = false;
    485     status_header( 200 );
    486 
    487     include_once( 'feeds/bp-activity-friends-feed.php' );
    488     die;
     490    if ( ! bp_is_active( 'friends' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_friends_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) {
     491        return false;
     492    }
     493
     494    // setup the feed
     495    buddypress()->activity->feed = new BP_Activity_Feed( array(
     496        'id'            => 'friends',
     497
     498        /* translators: Friends activity RSS title - "[Site Name] | [User Display Name] | Friends Activity" */
     499        'title'         => sprintf( __( '%1$s | %2$s | Friends Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     500
     501        'link'          => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() ),
     502        'description'   => sprintf( __( "Activity feed for %s' friends.", 'buddypress' ), bp_get_displayed_user_fullname() ),
     503        'activity_args' => 'scope=friends'
     504    ) );
    489505}
    490506add_action( 'bp_actions', 'bp_activity_action_friends_feed' );
     
    506522 */
    507523function bp_activity_action_my_groups_feed() {
     524    if ( ! bp_is_active( 'groups' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_groups_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) {
     525        return false;
     526    }
     527
     528    // get displayed user's group IDs
     529    $groups    = groups_get_user_groups();
     530    $group_ids = implode( ',', $groups['groups'] );
     531
     532    // setup the feed
     533    buddypress()->activity->feed = new BP_Activity_Feed( array(
     534        'id'            => 'mygroups',
     535
     536        /* translators: Member groups activity RSS title - "[Site Name] | [User Display Name] | Groups Activity" */
     537        'title'         => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     538
     539        'link'          => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() ),
     540        'description'   => sprintf( __( "Public group activity feed of which %s is a member of.", 'buddypress' ), bp_get_displayed_user_fullname() ),
     541        'activity_args' => array(
     542            'object'           => buddypress()->groups->id,
     543            'primary_id'       => $group_ids,
     544            'display_comments' => 'threaded'
     545        )
     546    ) );
     547}
     548add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );
     549
     550/**
     551 * Load a user's @mentions feed.
     552 *
     553 * @since BuddyPress (1.2)
     554 *
     555 * @global object $wp_query
     556 * @uses bp_is_user_activity()
     557 * @uses bp_is_current_action()
     558 * @uses bp_is_action_variable()
     559 * @uses status_header()
     560 *
     561 * @return bool False on failure
     562 */
     563function bp_activity_action_mentions_feed() {
    508564    global $wp_query;
    509565
    510     if ( !bp_is_active( 'groups' ) || !bp_is_user_activity() || !bp_is_current_action( bp_get_groups_slug() ) || !bp_is_action_variable( 'feed', 0 ) )
     566    if ( ! bp_activity_do_mentions() ) {
     567        return false;
     568    }
     569
     570    if ( !bp_is_user_activity() || !bp_is_current_action( 'mentions' ) || !bp_is_action_variable( 'feed', 0 ) )
    511571        return false;
    512572
     
    514574    status_header( 200 );
    515575
    516     include_once( 'feeds/bp-activity-mygroups-feed.php' );
     576    include_once( 'feeds/bp-activity-mentions-feed.php' );
    517577    die;
    518578}
    519 add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );
    520 
    521 /**
    522  * Load a user's @mentions feed.
     579add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );
     580
     581/**
     582 * Load a user's favorites feed.
    523583 *
    524584 * @since BuddyPress (1.2)
     
    532592 * @return bool False on failure
    533593 */
    534 function bp_activity_action_mentions_feed() {
    535     global $wp_query;
    536 
    537     if ( ! bp_activity_do_mentions() ) {
    538         return false;
    539     }
    540 
    541     if ( !bp_is_user_activity() || !bp_is_current_action( 'mentions' ) || !bp_is_action_variable( 'feed', 0 ) )
    542         return false;
    543 
    544     $wp_query->is_404 = false;
    545     status_header( 200 );
    546 
    547     include_once( 'feeds/bp-activity-mentions-feed.php' );
    548     die;
    549 }
    550 add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );
    551 
    552 /**
    553  * Load a user's favorites feed.
    554  *
    555  * @since BuddyPress (1.2)
    556  *
    557  * @global object $wp_query
    558  * @uses bp_is_user_activity()
    559  * @uses bp_is_current_action()
    560  * @uses bp_is_action_variable()
    561  * @uses status_header()
    562  *
    563  * @return bool False on failure
    564  */
    565594function bp_activity_action_favorites_feed() {
    566     global $wp_query;
    567 
    568     if ( !bp_is_user_activity() || !bp_is_current_action( 'favorites' ) || !bp_is_action_variable( 'feed', 0 ) )
    569         return false;
    570 
    571     $wp_query->is_404 = false;
    572     status_header( 200 );
    573 
    574     include_once( 'feeds/bp-activity-favorites-feed.php' );
    575     die;
     595    if ( ! bp_is_user_activity() || ! bp_is_current_action( 'favorites' ) || ! bp_is_action_variable( 'feed', 0 ) ) {
     596        return false;
     597    }
     598
     599    // get displayed user's favorite activity IDs
     600    $favs = bp_activity_get_user_favorites( bp_displayed_user_id() );
     601    $fav_ids = implode( ',', (array) $favs );
     602
     603    // setup the feed
     604    buddypress()->activity->feed = new BP_Activity_Feed( array(
     605        'id'            => 'favorites',
     606
     607        /* translators: User activity favorites RSS title - "[Site Name] | [User Display Name] | Favorites" */
     608        'title'         => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     609
     610        'link'          => bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/',
     611        'description'   => sprintf( __( "Activity feed of %s' favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ),
     612        'activity_args' => 'include=' . $fav_ids
     613    ) );
    576614}
    577615add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
Note: See TracChangeset for help on using the changeset viewer.