Changeset 4096 for trunk/bp-core/bp-core-catchuri.php
- Timestamp:
- 03/10/2011 10:48:38 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-catchuri.php
r4091 r4096 34 34 $bp->action_variables = $bp->displayed_user->id = ''; 35 35 36 // Only catch URI's on the root blog if we are not running 37 // on multiple blogs 36 38 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() ) { 37 // Only catch URI's on the root blog if we are not running38 // on multiple blogs39 39 if ( BP_ROOT_BLOG != (int) $current_blog->blog_id ) 40 40 return false; … … 51 51 $path = esc_url( $_SERVER['REQUEST_URI'] ); 52 52 53 // Filter the path 53 54 $path = apply_filters( 'bp_uri', $path ); 54 55 … … 92 93 93 94 // Take empties off the end of path 94 if ( empty( $paths[count( $paths) - 1] ) )95 if ( empty( $paths[count( $paths ) - 1] ) ) 95 96 array_pop( $paths ); 96 97 … … 99 100 array_shift( $paths ); 100 101 101 foreach ( (array)$bp_uri as $key => $uri_chunk ) { 102 if ( in_array( $uri_chunk, $paths )) { 102 // Unset URI indices if they intersect with the paths 103 foreach ( (array) $bp_uri as $key => $uri_chunk ) { 104 if ( in_array( $uri_chunk, $paths ) ) { 103 105 unset( $bp_uri[$key] ); 104 106 } … … 108 110 $bp_uri = array_merge( array(), $bp_uri ); 109 111 110 // If a component is set to the front page, force its name into $bp_uri so that $current_component is populated 112 // If a component is set to the front page, force its name into $bp_uri 113 // so that $current_component is populated 111 114 if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && empty( $bp_uri ) ) { 112 115 $post = get_post( get_option( 'page_on_front' ) ); … … 115 118 } 116 119 120 // Keep the unfiltered URI safe 117 121 $bp_unfiltered_uri = $bp_uri; 118 122 119 // Loop through each page in the global123 // Get slugs of pages into array 120 124 foreach ( (array) $bp->pages as $page_key => $bp_page ) { 121 122 // Look for a match (check members first) 123 if ( in_array( $bp_page->name, (array) $bp_uri ) ) { 124 125 // Match found, now match the slug to make sure. 126 $uri_chunks = explode( '/', $bp_page->slug ); 127 128 // Loop through uri_chunks 129 foreach ( (array) $uri_chunks as $key => $uri_chunk ) { 130 131 // Make sure chunk is in the correct position 132 if ( !empty( $bp_uri[$key] ) && ( $bp_uri[$key] == $uri_chunk ) ) { 133 $matches[] = 1; 134 135 // No match 136 } else { 137 $matches[] = 0; 125 $key_slugs[$page_key] = trailingslashit( '/' . $bp_page->slug ); 126 } 127 128 // Loop through page slugs and look for exact match to path 129 foreach ( $key_slugs as $key => $slug ) { 130 if ( $slug == $path ) { 131 $match = $bp->pages->{$key}; 132 $match->key = $key; 133 $matches[] = 1; 134 break; 135 } 136 } 137 138 // No exact match, so look for partials 139 if ( empty( $match ) ) { 140 141 // Loop through each page in the $bp->pages global 142 foreach ( (array) $bp->pages as $page_key => $bp_page ) { 143 144 // Look for a match (check members first) 145 if ( in_array( $bp_page->name, (array) $bp_uri ) ) { 146 147 // Match found, now match the slug to make sure. 148 $uri_chunks = explode( '/', $bp_page->slug ); 149 150 // Loop through uri_chunks 151 foreach ( (array) $uri_chunks as $key => $uri_chunk ) { 152 153 // Make sure chunk is in the correct position 154 if ( !empty( $bp_uri[$key] ) && ( $bp_uri[$key] == $uri_chunk ) ) { 155 $matches[] = 1; 156 157 // No match 158 } else { 159 $matches[] = 0; 160 } 138 161 } 162 163 // Have a match 164 if ( !in_array( 0, (array) $matches ) ) { 165 $match = $bp_page; 166 $match->key = $page_key; 167 break; 168 }; 169 170 // Unset matches 171 unset( $matches ); 139 172 } 140 173 141 // Have a match 142 if ( !in_array( 0, (array) $matches ) ) { 143 $match = $bp_page; 144 $match->key = $page_key; 145 break; 146 }; 147 148 // Unset matches 149 unset( $matches ); 150 } 151 152 // Unset uri chunks 153 unset( $uri_chunks ); 174 // Unset uri chunks 175 unset( $uri_chunks ); 176 } 154 177 } 155 178 156 179 // Search doesn't have an associated page, so we check for it separately 157 if ( !empty( $bp_uri[0] ) && BP_SEARCH_SLUG == $bp_uri[0])180 if ( !empty( $bp_uri[0] ) && ( BP_SEARCH_SLUG == $bp_uri[0] ) ) 158 181 $matches[] = 1; 159 182 … … 163 186 164 187 // Find the offset 188 $slug = !empty ( $match ) ? explode( '/', $match->slug ) : ''; 165 189 $uri_offset = 0; 166 $slug = explode( '/', $match->slug ); 167 168 if ( !empty( $slug ) && 1 != count( $slug) ) {190 191 // Rejig the offset 192 if ( !empty( $slug ) && ( 1 < count( $slug ) ) ) { 169 193 array_pop( $slug ); 170 194 $uri_offset = count( $slug ); … … 174 198 $bp_unfiltered_uri_offset = $uri_offset; 175 199 176 // This is a members page so lets check if we have a displayed member 177 if ( isset( $match->key ) && 'members' == $match->key ) { 178 if ( !empty( $bp_uri[$uri_offset + 1] ) ) { 179 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 180 $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) ); 181 else 182 $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) ); 183 184 $uri_offset = $uri_offset + 2; 185 186 // Remove everything from the URI up to the offset and take it from there. 187 for ( $i = 0; $i < $uri_offset; $i++ ) 188 unset( $bp_uri[$i] ); 189 190 $bp->current_component = isset( $bp_uri[$uri_offset] ) ? $bp_uri[$uri_offset] : ''; 191 } 192 } 193 194 // Reset the keys by merging with an empty array 195 $bp_uri = array_merge( array(), $bp_uri ); 196 197 // Set the current component 198 if ( empty( $bp->current_component ) ) { 199 for ( $i = 0; $i <= $uri_offset; $i++ ) { 200 if ( !empty( $bp_uri[$i] ) ) { 201 $bp->current_component .= $bp_uri[$i]; 202 203 if ( $i != $uri_offset ) 204 $bp->current_component .= '/'; 200 // We have an exact match 201 if ( isset( $match->key ) ) { 202 203 // Set current component to matched key 204 $bp->current_component = $match->key; 205 206 // If members component, do more work to find the actual component 207 if ( 'members' == $match->key ) { 208 209 // Viewing a specific user 210 if ( !empty( $bp_uri[$uri_offset + 1] ) ) { 211 212 // Switch the displayed_user based on cmpatbility mode 213 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 214 $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) ); 215 else 216 $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) ); 217 218 // Bump the offset 219 if ( isset( $bp_uri[$uri_offset + 2] ) ) { 220 $bp_uri = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) ); 221 $bp->current_component = $bp_uri[0]; 222 223 // No component, so default will be picked later 224 } else { 225 $bp_uri = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) ); 226 $bp->current_component = ''; 227 } 228 229 // Reset the offset 230 $uri_offset = 0; 205 231 } 206 232 } 207 } else {208 $i = 1;209 233 } 210 234 211 235 // Set the current action 212 $bp->current_action = isset( $bp_uri[$ i] ) ? $bp_uri[$i] : '';213 214 // Unset the current_component and action from action_variables215 for ( $j = 0; $j <= $i; $j++ )216 unset( $bp_uri[$j] );236 $bp->current_action = isset( $bp_uri[$uri_offset + 1] ) ? $bp_uri[$uri_offset + 1] : ''; 237 238 // Slice the rest of the $bp_uri array and reset offset 239 $bp_uri = array_slice( $bp_uri, $uri_offset + 2 ); 240 $uri_offset = 0; 217 241 218 242 // Set the entire URI as the action variables, we will unset the current_component and action in a second
Note: See TracChangeset
for help on using the changeset viewer.