Skip to:
Content

BuddyPress.org

Changeset 3219


Ignore:
Timestamp:
08/26/2010 11:14:46 PM (16 years ago)
Author:
johnjamesjacoby
Message:

Carefully clean up bp_core_set_uri_globals. Fixes #2604. Props boonebgorges.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-core/bp-core-catchuri.php

    r3192 r3219  
    3333        global $bp, $current_blog;
    3434
    35         if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && bp_core_is_multisite() ) {
    36                 /* Only catch URI's on the root blog if we are not running BP on multiple blogs */
     35        // Only catch URI's on the root blog if we are not running BP on multiple blogs
     36        if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && bp_core_is_multisite() )
    3737                if ( BP_ROOT_BLOG != (int) $current_blog->blog_id )
    3838                        return false;
    39         }
    40 
     39
     40        // Ajax or not?
    4141        if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
    4242                $path = bp_core_referrer();
    … …  
    4646        $path = apply_filters( 'bp_uri', $path );
    4747
    48         // Firstly, take GET variables off the URL to avoid problems,
    49         // they are still registered in the global $_GET variable */
     48        // Take GET variables off the URL to avoid problems,
     49        // they are still registered in the global $_GET variable
    5050        $noget = substr( $path, 0, strpos( $path, '?' ) );
    51         if ( $noget != '' ) $path = $noget;
    52 
    53         /* Fetch the current URI and explode each part separated by '/' into an array */
    54         $bp_uri = explode( "/", $path );
    55 
    56         /* Loop and remove empties */
     51        if ( $noget != '' )
     52                $path = $noget;
     53
     54        // Fetch the current URI and explode each part separated by '/' into an array
     55        $bp_uri = explode( '/', $path );
     56
     57        // Loop and remove empties
    5758        foreach ( (array)$bp_uri as $key => $uri_chunk )
    5859                if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
    5960
     61        // Running off blog other than root
    6062        if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
    61                 /* If we are running BuddyPress on any blog, not just a root blog, we need to first
    62                    shift off the blog name if we are running a subdirectory install of WPMU. */
    63                 if ( $current_blog->path != '/' )
    64                         array_shift( $bp_uri );
    65         }
    66 
    67         /* Set the indexes, these are incresed by one if we are not on a VHOST install */
     63
     64                // Any subdirectory names must be removed from $bp_uri.
     65                // This includes two cases: (1) when WP is installed in a subdirectory,
     66                // and (2) when BP is running on secondary blog of a subdirectory
     67                // multisite installation. Phew!
     68                if ( $chunks = explode( '/', $current_blog->path ) ) {
     69                        foreach( $chunks as $key => $chunk ) {
     70                                $bkey = array_search( $chunk, $bp_uri );
     71
     72                                if ( $bkey !== false )
     73                                        unset( $bp_uri[$bkey] );
     74
     75                                $bp_uri = array_values( $bp_uri );
     76                        }
     77                }
     78        }
     79
     80        // Set the indexes, these are incresed by one if we are not on a VHOST install
    6881        $component_index = 0;
    69         $action_index = $component_index + 1;
     82        $action_index    = $component_index + 1;
    7083
    7184        // If this is a WordPress page, return from the function.
    … …  
    7386                return false;
    7487
    75         /* Get site path items */
     88        // Get site path items
    7689        $paths = explode( '/', bp_core_get_site_path() );
    7790
    78         /* Take empties off the end of path */
     91        // Take empties off the end of path
    7992        if ( empty( $paths[count($paths) - 1] ) )
    8093                array_pop( $paths );
    8194
    82         /* Take empties off the start of path */
     95        // Take empties off the start of path
    8396        if ( empty( $paths[0] ) )
    8497                array_shift( $paths );
    8598
    86         foreach ( (array)$bp_uri as $key => $uri_chunk ) {
    87                 if ( in_array( $uri_chunk, $paths )) {
     99        foreach ( (array)$bp_uri as $key => $uri_chunk )
     100                if ( in_array( $uri_chunk, $paths ))
    88101                        unset( $bp_uri[$key] );
    89                 }
    90         }
    91 
    92         /* Reset the keys by merging with an empty array */
    93         $bp_uri = array_merge( array(), $bp_uri );
     102
     103        // Reset the keys by merging with an empty array
     104        $bp_uri            = array_merge( array(), $bp_uri );
    94105        $bp_unfiltered_uri = $bp_uri;
    95106
    96         /* If we are under anything with a members slug, set the correct globals */
     107        // If we are under anything with a members slug, set the correct globals
    97108        if ( $bp_uri[0] == BP_MEMBERS_SLUG ) {
    98                 $is_member_page = true;
     109                $is_member_page    = true;
    99110                $is_root_component = true;
    100111        }
    101112
    102         /* Catch a member page and set the current member ID */
     113        // Catch a member page and set the current member ID
    103114        if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {
    104115                if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
    … …  
    112123                        unset($bp_uri[1]);
    113124
    114                         /* Reset the keys by merging with an empty array */
     125                        // Reset the keys by merging with an empty array
    115126                        $bp_uri = array_merge( array(), $bp_uri );
    116127                }
    117128        } else {
    118129                if ( get_userdatabylogin( $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
    119                         $is_member_page = true;
     130                        $is_member_page    = true;
    120131                        $is_root_component = true;
    121132
    … …  
    128139                        unset($bp_uri[0]);
    129140
    130                         /* Reset the keys by merging with an empty array */
     141                        // Reset the keys by merging with an empty array
    131142                        $bp_uri = array_merge( array(), $bp_uri );
    132143                }
    133144        }
    134145
    135         if ( !isset($is_root_component) )
     146        if ( !isset( $is_root_component ) )
    136147                $is_root_component = in_array( $bp_uri[0], $bp->root_components );
    137148
    … …  
    141152        }
    142153
    143         /* Set the current component */
     154        // Set the current component
    144155        $current_component = $bp_uri[$component_index];
    145156
    146         /* Set the current action */
    147         $current_action = $bp_uri[$action_index];
    148 
    149         /* Set the entire URI as the action variables, we will unset the current_component and action in a second */
    150         $action_variables = $bp_uri;
    151 
    152         /* Unset the current_component and action from action_variables */
    153         unset($action_variables[$component_index]);
    154         unset($action_variables[$action_index]);
    155 
    156         /* Remove the username from action variables if this is not a VHOST install */
     157        // Set the current action
     158        $current_action    = $bp_uri[$action_index];
     159
     160        // Set the entire URI as the action variables, we will unset the current_component and action in a second
     161        $action_variables  = $bp_uri;
     162
     163        // Unset the current_component and action from action_variables
     164        unset( $action_variables[$component_index] );
     165        unset( $action_variables[$action_index] );
     166
     167        // Remove the username from action variables if this is not a VHOST install
    157168        if ( !is_subdomain_install() && !$is_root_component )
    158                 array_shift($action_variables);
    159 
    160         /* Reset the keys by merging with an empty array */
     169                array_shift( $action_variables );
     170
     171        // Reset the keys by merging with an empty array
    161172        $action_variables = array_merge( array(), $action_variables );
    162173}
Note: See TracChangeset for help on using the changeset viewer.