Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/09/2012 03:25:20 PM (13 years ago)
Author:
boonebgorges
Message:

Reconfigures canonical redirection so that URIs canonicalize up (less specific) rather than down (more specific). Fixes #1741

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-buddybar.php

    r5868 r5895  
    6565
    6666    // Look for current component
    67     if ( bp_is_current_component( $slug ) && !bp_current_action() ) {
    68         if ( !is_object( $screen_function[0] ) )
    69             add_action( 'bp_screens', $screen_function );
    70         else
    71             add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
    72 
    73         if ( !empty( $default_subnav_slug ) ) {
    74             $bp->current_action           = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
    75             $bp->redirect_stack['action'] = $bp->current_action;
     67    if ( bp_is_current_component( $slug ) ) {
     68        if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) ) {
     69            // The requested URL has explicitly included the default subnav (eg
     70            // example.com/members/membername/activity/just-me/). The canonical
     71            // version will not contain this subnav slug.
     72            unset( $bp->canonical_stack['action'] );
     73        } else if ( !bp_current_action() ) {
     74            if ( !is_object( $screen_function[0] ) )
     75                add_action( 'bp_screens', $screen_function );
     76            else
     77                add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
     78   
     79            if ( !empty( $default_subnav_slug ) ) {
     80                $bp->current_action            = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
     81            }
    7682        }
    7783
    7884    // Look for current item
    79     } elseif ( bp_is_current_item( $slug ) && !bp_current_action() ) {
    80         if ( !is_object( $screen_function[0] ) )
    81             add_action( 'bp_screens', $screen_function );
    82         else
    83             add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
    84 
    85         if ( !empty( $default_subnav_slug ) ) {
    86             $bp->current_action           = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
    87             $bp->redirect_stack['action'] = $bp->current_action;
     85    } elseif ( bp_is_current_item( $slug ) ) {
     86        if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) ) {
     87            // The requested URL has explicitly included the default subnav (eg
     88            // example.com/members/membername/activity/just-me/). The canonical
     89            // version will not contain this subnav slug.
     90            unset( $bp->canonical_stack['action'] );
     91        } else if ( !bp_current_action() ) {
     92            if ( !is_object( $screen_function[0] ) )
     93                add_action( 'bp_screens', $screen_function );
     94            else
     95                add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
     96   
     97            if ( !empty( $default_subnav_slug ) ) {
     98                $bp->current_action            = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
     99            }
    88100        }
    89101    }
     
    109121    $r = wp_parse_args( $args, $defaults );
    110122    extract( $r, EXTR_SKIP );
    111 
     123   
    112124    if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {
    113125        if ( !is_object( $function[0] ) )
     
    119131    $bp->bp_nav[$parent_slug]['screen_function'] = &$screen_function;
    120132
    121     // If the current_action has been set to the default_subnav_slug, it will be reflected
    122     // in the redirect_stack. Unset the action manually so that the new nav default can be set
    123     if ( !empty( $bp->redirect_stack['action'] ) && $bp->redirect_stack['action'] == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) {
    124         $bp->current_action = '';
    125     }
    126 
    127     if ( bp_is_current_component( $parent_slug ) && !bp_current_action() ) {
    128         if ( !is_object( $screen_function[0] ) ) {
    129             add_action( 'bp_screens', $screen_function );
     133    if ( bp_is_current_component( $parent_slug ) ) {
     134       
     135        // The only way to tell whether to set the subnav is to peek at the unfiltered_uri
     136        // Find the component
     137        $component_uri_key = array_search( $parent_slug, $bp->unfiltered_uri );
     138       
     139        if ( false !== $component_uri_key ) {
     140            if ( !empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) {
     141                $unfiltered_action = $bp->unfiltered_uri[$component_uri_key + 1];
     142            }
     143        }
     144       
     145        if ( empty( $unfiltered_action ) ) {
     146            // No subnav item has been requested in the URL, so set a new nav default
     147            if ( !bp_is_current_action( $subnav_slug ) ) {
     148                if ( !is_object( $screen_function[0] ) ) {
     149                    add_action( 'bp_screens', $screen_function );
     150                } else {
     151                    add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ) );
     152                }
     153       
     154                $bp->current_action = $subnav_slug;
     155                unset( $bp->canonical_stack['action'] );
     156            }
     157        } else if ( $unfiltered_action == $subnav_slug ) {
     158            // The URL is explicitly requesting the new subnav item, but should be
     159            // directed to the canonical URL
     160            unset( $bp->canonical_stack['action'] );
    130161        } else {
    131             add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ) );
    132         }
    133 
    134         if ( $subnav_slug ) {
    135             $bp->current_action           = $subnav_slug;
    136             $bp->redirect_stack['action'] = $bp->current_action;
    137         }
    138     }
     162            // In all other cases (including the case where the original subnav item
     163            // is explicitly called in the URL), the canonical URL will contain the
     164            // subnav slug
     165            $bp->canonical_stack['action'] = bp_current_action();
     166        }
     167    }
     168   
     169    return;
    139170}
    140171
Note: See TracChangeset for help on using the changeset viewer.