Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/24/2010 09:22:29 PM (16 years ago)
Author:
djpaul
Message:

Fixed #2676

File:
1 edited

Legend:

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

    r3234 r3300  
    4343        }
    4444
     45        // Ajax or not?
    4546        if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
    4647                $path = bp_core_referrer();
    4748        else
    48                 $path = clean_url( $_SERVER['REQUEST_URI'] );
     49                $path = esc_url( $_SERVER['REQUEST_URI'] );
    4950
    5051        $path = apply_filters( 'bp_uri', $path );
    5152
    52         // Firstly, take GET variables off the URL to avoid problems,
    53         // they are still registered in the global $_GET variable */
     53        // Take GET variables off the URL to avoid problems,
     54        // they are still registered in the global $_GET variable
    5455        $noget = substr( $path, 0, strpos( $path, '?' ) );
    55         if ( $noget != '' ) $path = $noget;
    56 
    57         /* Fetch the current URI and explode each part separated by '/' into an array */
     56        if ( $noget != '' )
     57                $path = $noget;
     58
     59        // Fetch the current URI and explode each part separated by '/' into an array
    5860        $bp_uri = explode( "/", $path );
    5961
    60         /* Loop and remove empties */
     62        // Loop and remove empties
    6163        foreach ( (array)$bp_uri as $key => $uri_chunk )
    6264                if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
    6365
    64         if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
    65                 /* If we are running BuddyPress on any blog, not just a root blog, we need to first
    66                    shift off the blog name if we are running a subdirectory install of WPMU. */
    67                 if ( $current_blog->path != '/' )
    68                         array_shift( $bp_uri );
    69         }
    70 
    71         /* Set the indexes, these are incresed by one if we are not on a VHOST install */
    72         $component_index = 0;
    73         $action_index = $component_index + 1;
    74 
    75         /* Get site path items */
     66        // Running off blog other than root
     67        if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
     68 
     69                // Any subdirectory names must be removed from $bp_uri.
     70                // This includes two cases: (1) when WP is installed in a subdirectory,
     71                // and (2) when BP is running on secondary blog of a subdirectory
     72                // multisite installation. Phew!
     73                if ( $chunks = explode( '/', $current_blog->path ) ) {
     74                        foreach( $chunks as $key => $chunk ) {
     75                                $bkey = array_search( $chunk, $bp_uri );
     76 
     77                                if ( $bkey !== false )
     78                                        unset( $bp_uri[$bkey] );
     79 
     80                                $bp_uri = array_values( $bp_uri );
     81                        }
     82                }
     83        }
     84
     85        // Set the indexes, these are incresed by one if we are not on a VHOST install
     86        $component_index        = 0;
     87        $action_index           = $component_index + 1;
     88
     89        // Get site path items
    7690        $paths = explode( '/', bp_core_get_site_path() );
    7791
    78         /* Take empties off the end of path */
     92        // Take empties off the end of path
    7993        if ( empty( $paths[count($paths) - 1] ) )
    8094                array_pop( $paths );
    8195
    82         /* Take empties off the start of path */
     96        // Take empties off the start of path
    8397        if ( empty( $paths[0] ) )
    8498                array_shift( $paths );
     
    90104        }
    91105
    92         /* Reset the keys by merging with an empty array */
    93         $bp_uri = array_merge( array(), $bp_uri );
    94         $bp_unfiltered_uri = $bp_uri;
    95 
    96         /* Find a match within registered BuddyPress controlled WP pages (check members first) */
     106        // Reset the keys by merging with an empty array
     107        $bp_uri                         = array_merge( array(), $bp_uri );
     108        $bp_unfiltered_uri      = $bp_uri;
     109
     110        // Find a match within registered BuddyPress controlled WP pages (check members first)
    97111        foreach ( (array)$bp_pages as $page_key => $bp_page ) {
    98112                if ( in_array( $bp_page->name, (array)$bp_uri ) ) {
    99                         /* Match found, now match the slug to make sure. */
     113                        // Match found, now match the slug to make sure.
    100114                        $uri_chunks = explode( '/', $bp_page->slug );
    101115
     
    120134        }
    121135
    122         /* This is not a BuddyPress page, so just return. */
     136        // This is not a BuddyPress page, so just return.
    123137        if ( in_array( 0, (array) $matches ) )
    124138                return false;
    125139
    126         /* Find the offset */
     140        // Find the offset
    127141        $uri_offset = 0;
    128142        $slug = explode( '/', $match->slug );
     
    133147        }
    134148
    135         /* Global the unfiltered offset to use in bp_core_load_template() */
     149        // Global the unfiltered offset to use in bp_core_load_template()
    136150        $bp_unfiltered_uri_offset = $uri_offset;
    137151
    138         /* This is a members page so lets check if we have a displayed member */
     152        // This is a members page so lets check if we have a displayed member
    139153        if ( 'members' == $match->key ) {
    140154                if ( !empty( $bp_uri[$uri_offset + 1] ) ) {
     
    146160                        $uri_offset = $uri_offset + 2;
    147161
    148                         /* Remove everything from the URI up to the offset and take it from there. */
     162                        // Remove everything from the URI up to the offset and take it from there.
    149163                        for ( $i = 0; $i < $uri_offset; $i++ )
    150164                                unset( $bp_uri[$i] );
     
    154168        }
    155169
    156         /* Reset the keys by merging with an empty array */
     170        // Reset the keys by merging with an empty array
    157171        $bp_uri = array_merge( array(), $bp_uri );
    158172
    159         /* Set the current component */
     173        // Set the current component
    160174        if ( empty( $current_component ) ) {
    161175                for ( $i = 0; $i <= $uri_offset; $i++ ) {
     
    170184                $i = 1;
    171185
    172         /* Set the current action */
     186        // Set the current action
    173187        $current_action = $bp_uri[$i];
    174188
    175         /* Unset the current_component and action from action_variables */
     189        // Unset the current_component and action from action_variables
    176190        for ( $j = 0; $j <= $i; $j++ )
    177191                unset( $bp_uri[$j] );
    178192
    179         /* Set the entire URI as the action variables, we will unset the current_component and action in a second */
     193        // Set the entire URI as the action variables, we will unset the current_component and action in a second
    180194        $action_variables = $bp_uri;
    181195
    182         /* Remove the username from action variables if this is not a VHOST install */
     196        // Remove the username from action variables if this is not a VHOST install
    183197        if ( 'no' == VHOST && !$is_root_component )
    184198                array_shift($bp_uri);
    185199
    186         /* Reset the keys by merging with an empty array */
     200        // Reset the keys by merging with an empty array
    187201        $action_variables = array_merge( array(), $action_variables );
    188 
    189         //var_dump($current_component, $current_action, $bp_uri);
    190202}
    191 add_action( 'plugins_loaded', 'bp_core_set_uri_globals', 3 );
     203add_action( 'bp_loaded', 'bp_core_set_uri_globals', 4 );
    192204
    193205/**
Note: See TracChangeset for help on using the changeset viewer.