Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/31/2023 05:26:39 PM (13 months ago)
Author:
imath
Message:

Make sure all displayed user URLs are built using the BP Rewrites API

Replace all remaining bp_displayed_user_domain() usage in favor of
bp_displayed_user_url().
Introduce the bp_members_get_path_chunks() function to quickly build BP
Rewrites argument for member's URL using an array of slugs.
Deprecate bp_activities_member_rss_link(), bp_blogs_blog_tabs() &
bp_groups_header_tabs().
Improve bp_displayed_user_link() so that it's possible to pass an array
of slugs to output an escaped BP Rewrites ready URL.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/79
See #4954

File:
1 edited

Legend:

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

    r13433 r13443  
    2525
    2626    // Setup the feed.
    27     buddypress()->activity->feed = new BP_Activity_Feed( array(
    28         'id'            => 'sitewide',
    29 
    30         /* translators: %s Site Name */
    31         'title'         => sprintf( __( '%s | Site-Wide Activity', 'buddypress' ), bp_get_site_name() ),
    32         'link'          => $link,
    33         'description'   => __( 'Activity feed for the entire site.', 'buddypress' ),
    34         'activity_args' => 'display_comments=threaded'
    35     ) );
     27    buddypress()->activity->feed = new BP_Activity_Feed(
     28        array(
     29            'id'            => 'sitewide',
     30
     31            /* translators: %s Site Name */
     32            'title'         => sprintf( __( '%s | Site-Wide Activity', 'buddypress' ), bp_get_site_name() ),
     33            'link'          => $link,
     34            'description'   => __( 'Activity feed for the entire site.', 'buddypress' ),
     35            'activity_args' => 'display_comments=threaded'
     36        )
     37    );
    3638
    3739    if ( ! buddypress()->activity->feed->enabled ) {
     
    5355    }
    5456
    55     $link = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() );
    56 
    57     // Setup the feed.
    58     buddypress()->activity->feed = new BP_Activity_Feed( array(
    59         'id'            => 'personal',
    60 
    61         /* translators: 1: Site Name. 2: User Display Name. */
    62         'title'         => sprintf( _x( '%1$s | %2$s | Activity', 'Personal activity feed title', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
    63         'link'          => $link,
    64 
    65         /* translators: %s: User Display Name */
    66         'description'   => sprintf( __( 'Activity feed for %s.', 'buddypress' ), bp_get_displayed_user_fullname() ),
    67         'activity_args' => 'user_id=' . bp_displayed_user_id()
    68     ) );
     57    $activity_slug = bp_get_activity_slug();
     58    $link          = bp_displayed_user_url(
     59        array(
     60            'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug ),
     61        )
     62    );
     63
     64    // Setup the feed.
     65    buddypress()->activity->feed = new BP_Activity_Feed(
     66        array(
     67            'id'            => 'personal',
     68
     69            /* translators: 1: Site Name. 2: User Display Name. */
     70            'title'         => sprintf( _x( '%1$s | %2$s | Activity', 'Personal activity feed title', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     71            'link'          => $link,
     72
     73            /* translators: %s: User Display Name */
     74            'description'   => sprintf( __( 'Activity feed for %s.', 'buddypress' ), bp_get_displayed_user_fullname() ),
     75            'activity_args' => 'user_id=' . bp_displayed_user_id()
     76        )
     77    );
    6978
    7079    if ( ! buddypress()->activity->feed->enabled ) {
     
    8695    }
    8796
    88     $link = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() );
    89 
    90     // Setup the feed.
    91     buddypress()->activity->feed = new BP_Activity_Feed( array(
    92         'id'            => 'friends',
    93 
    94         /* translators: 1: Site Name 2: User Display Name */
    95         'title'         => sprintf( __( '%1$s | %2$s | Friends Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
    96         'link'          => $link,
    97 
    98         /* translators: %s: User Display Name */
    99         'description'   => sprintf( __( "Activity feed for %s's friends.", 'buddypress' ), bp_get_displayed_user_fullname() ),
    100         'activity_args' => 'scope=friends'
    101     ) );
     97    $activity_slug = bp_get_activity_slug();
     98    $friends_slug  = bp_get_friends_slug();
     99    $link          = bp_displayed_user_url(
     100        array(
     101            'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug ),
     102            'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $friends_slug, $friends_slug ),
     103        )
     104    );
     105
     106    // Setup the feed.
     107    buddypress()->activity->feed = new BP_Activity_Feed(
     108        array(
     109            'id'            => 'friends',
     110
     111            /* translators: 1: Site Name 2: User Display Name */
     112            'title'         => sprintf( __( '%1$s | %2$s | Friends Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     113            'link'          => $link,
     114
     115            /* translators: %s: User Display Name */
     116            'description'   => sprintf( __( "Activity feed for %s's friends.", 'buddypress' ), bp_get_displayed_user_fullname() ),
     117            'activity_args' => 'scope=friends'
     118        )
     119    );
    102120
    103121    if ( ! buddypress()->activity->feed->enabled ) {
     
    120138
    121139    // Get displayed user's group IDs.
    122     $groups    = groups_get_user_groups();
    123     $group_ids = implode( ',', $groups['groups'] );
    124     $link      = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() );
    125 
    126     // Setup the feed.
    127     buddypress()->activity->feed = new BP_Activity_Feed( array(
    128         'id'            => 'mygroups',
    129 
    130         /* translators: 1: Site Name 2: User Display Name */
    131         'title'         => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
    132         'link'          => $link,
    133 
    134         /* translators: %s: User Display Name */
    135         'description'   => sprintf( __( "Public group activity feed of which %s is a member.", 'buddypress' ), bp_get_displayed_user_fullname() ),
    136         'activity_args' => array(
    137             'object'           => buddypress()->groups->id,
    138             'primary_id'       => $group_ids,
    139             'display_comments' => 'threaded'
    140         )
    141     ) );
     140    $groups        = groups_get_user_groups();
     141    $group_ids     = implode( ',', $groups['groups'] );
     142    $activity_slug = bp_get_activity_slug();
     143    $groups_slug   = bp_get_groups_slug();
     144    $link          = bp_displayed_user_url(
     145        array(
     146            'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug ),
     147            'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $groups_slug, $groups_slug ),
     148        )
     149    );
     150
     151    // Setup the feed.
     152    buddypress()->activity->feed = new BP_Activity_Feed(
     153        array(
     154            'id'            => 'mygroups',
     155
     156            /* translators: 1: Site Name 2: User Display Name */
     157            'title'         => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     158            'link'          => $link,
     159
     160            /* translators: %s: User Display Name */
     161            'description'   => sprintf( __( 'Public group activity feed of which %s is a member.', 'buddypress' ), bp_get_displayed_user_fullname() ),
     162            'activity_args' => array(
     163                'object'           => buddypress()->groups->id,
     164                'primary_id'       => $group_ids,
     165                'display_comments' => 'threaded'
     166            )
     167        )
     168    );
    142169
    143170    if ( ! buddypress()->activity->feed->enabled ) {
     
    163190    }
    164191
    165     $link = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions' );
    166 
    167     // Setup the feed.
    168     buddypress()->activity->feed = new BP_Activity_Feed( array(
    169         'id'            => 'mentions',
    170 
    171         /* translators: 1: Site Name 2: User Display Name */
    172         'title'         => sprintf( __( '%1$s | %2$s | Mentions', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
    173         'link'          => $link,
    174 
    175         /* translators: %s: User Display Name */
    176         'description'   => sprintf( __( "Activity feed mentioning %s.", 'buddypress' ), bp_get_displayed_user_fullname() ),
    177         'activity_args' => array(
    178             'search_terms' => '@' . bp_members_get_user_slug( bp_displayed_user_id() )
    179         )
    180     ) );
     192    $activity_slug = bp_get_activity_slug();
     193    $link          = bp_displayed_user_url(
     194        array(
     195            'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug ),
     196            'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_mentions', 'mentions' ),
     197        )
     198    );
     199
     200    // Setup the feed.
     201    buddypress()->activity->feed = new BP_Activity_Feed(
     202        array(
     203            'id'            => 'mentions',
     204
     205            /* translators: 1: Site Name 2: User Display Name */
     206            'title'         => sprintf( __( '%1$s | %2$s | Mentions', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     207            'link'          => $link,
     208
     209            /* translators: %s: User Display Name */
     210            'description'   => sprintf( __( "Activity feed mentioning %s.", 'buddypress' ), bp_get_displayed_user_fullname() ),
     211            'activity_args' => array(
     212                'search_terms' => '@' . bp_members_get_user_slug( bp_displayed_user_id() )
     213            )
     214        )
     215    );
    181216
    182217    if ( ! buddypress()->activity->feed->enabled ) {
     
    199234
    200235    // Get displayed user's favorite activity IDs.
    201     $favs    = bp_activity_get_user_favorites( bp_displayed_user_id() );
    202     $fav_ids = implode( ',', (array) $favs );
    203     $link    = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites' );
    204 
    205     // Setup the feed.
    206     buddypress()->activity->feed = new BP_Activity_Feed( array(
    207         'id'            => 'favorites',
    208 
    209         /* translators: 1: Site Name 2: User Display Name */
    210         'title'         => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
    211         'link'          => $link,
    212 
    213         /* translators: %s: User Display Name */
    214         'description'   => sprintf( __( "Activity feed of %s's favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ),
    215         'activity_args' => 'include=' . $fav_ids
    216     ) );
     236    $favs          = bp_activity_get_user_favorites( bp_displayed_user_id() );
     237    $fav_ids       = implode( ',', (array) $favs );
     238    $activity_slug = bp_get_activity_slug();
     239    $link          = bp_displayed_user_url(
     240        array(
     241            'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug ),
     242            'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_favorites', 'favorites' ),
     243        )
     244    );
     245
     246    // Setup the feed.
     247    buddypress()->activity->feed = new BP_Activity_Feed(
     248        array(
     249            'id'            => 'favorites',
     250
     251            /* translators: 1: Site Name 2: User Display Name */
     252            'title'         => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
     253            'link'          => $link,
     254
     255            /* translators: %s: User Display Name */
     256            'description'   => sprintf( __( "Activity feed of %s's favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ),
     257            'activity_args' => 'include=' . $fav_ids
     258        )
     259    );
    217260
    218261    if ( ! buddypress()->activity->feed->enabled ) {
Note: See TracChangeset for help on using the changeset viewer.