Changeset 5319
- Timestamp:
- 11/09/2011 06:38:28 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-catchuri.php
r5316 r5319 1 1 <?php 2 3 /** 4 * BuddyPress URI catcher 5 * 6 * Functions for parsing the URI and determining which BuddyPress template file 7 * to use on-screen. 8 * 9 * Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/ 10 * Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/ 11 * 12 * @package BuddyPress 13 * @subpackage Core 14 */ 15 2 16 // Exit if accessed directly 3 17 if ( !defined( 'ABSPATH' ) ) exit; 4 18 5 /*6 Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/7 Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/8 */9 10 19 /** 11 20 * Analyzes the URI structure and breaks it down into parts for use in code. 12 * The idea is that BuddyPress can use complete custom friendly URI's without the 13 * user having to add new re-write rules. 14 * 15 * Future custom components would then be able to use their own custom URI structure. 21 * BuddyPress can use complete custom friendly URI's without the user having to 22 * add new re-write rules. Custom components are able to use their own custom 23 * URI structures with very little work. 16 24 * 17 25 * @package BuddyPress Core … … 36 44 return false; 37 45 46 // Define local variables 47 $root_profile = $match = false; 48 $key_slugs = $matches = $uri_chunks = array(); 49 38 50 // Fetch all the WP page names for each component 39 51 if ( empty( $bp->pages ) ) … … 49 61 $path = apply_filters( 'bp_uri', $path ); 50 62 51 // Take GET variables off the URL to avoid problems, 52 // they are still registered in the global $_GET variable 53 if ( $noget = substr( $path, 0, strpos( $path, '?' ) ) ) 54 $path = $noget; 55 56 // Fetch the current URI and explode each part separated by '/' into an array 63 // Take GET variables off the URL to avoid problems 64 $path = strtok( $path, '?' ); 65 66 // Fetch current URI and explode each part separated by '/' into an array 57 67 $bp_uri = explode( '/', $path ); 58 68 59 69 // Loop and remove empties 60 foreach ( (array)$bp_uri as $key => $uri_chunk ) 61 if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] ); 62 63 // Running off blog other than root 70 foreach ( (array)$bp_uri as $key => $uri_chunk ) { 71 if ( empty( $bp_uri[$key] ) ) { 72 unset( $bp_uri[$key] ); 73 } 74 } 75 76 // If running off blog other than root, any subdirectory names must be 77 // removed from $bp_uri. This includes two cases: 78 // 79 // 1. when WP is installed in a subdirectory, 80 // 2. when BP is running on secondary blog of a subdirectory 81 // multisite installation. Phew! 64 82 if ( is_multisite() && !is_subdomain_install() && ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) { 65 83 66 // Any subdirectory names must be removed from $bp_uri. 67 // This includes two cases: (1) when WP is installed in a subdirectory, 68 // and (2) when BP is running on secondary blog of a subdirectory 69 // multisite installation. Phew! 70 if ( $chunks = explode( '/', $current_blog->path ) ) { 84 // Blow chunks 85 $chunks = explode( '/', $current_blog->path ); 86 87 // If chunks exist... 88 if ( !empty( $chunks ) ) { 89 90 // ...loop through them... 71 91 foreach( $chunks as $key => $chunk ) { 72 92 $bkey = array_search( $chunk, $bp_uri ); 73 93 74 if ( $bkey !== false ) { 94 // ...and unset offending keys 95 if ( false !== $bkey ) { 75 96 unset( $bp_uri[$bkey] ); 76 97 } … … 80 101 } 81 102 } 82 83 // Set the indexes, these are incresed by one if we are not on a VHOST install84 $component_index = 0;85 $action_index = $component_index + 1;86 103 87 104 // Get site path items … … 178 195 179 196 // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above 180 if ( empty( $matches ) && defined( 'BP_ENABLE_ROOT_PROFILES' ) && BP_ENABLE_ROOT_PROFILES) {197 if ( empty( $matches ) && bp_core_enable_root_profiles() ) { 181 198 182 199 // Make sure there's a user corresponding to $bp_uri[0] … … 296 313 297 314 /** 315 * Are root profiles enabled and allowed 316 * 317 * @since BuddyPress (1.6) 318 * @return bool True if yes, false if no 319 */ 320 function bp_core_enable_root_profiles() { 321 322 $retval = false; 323 324 if ( defined( 'BP_ENABLE_ROOT_PROFILES' ) && ( true == BP_ENABLE_ROOT_PROFILES ) ) 325 $retval = true; 326 327 return apply_filters( 'bp_core_enable_root_profiles', $retval ); 328 } 329 330 /** 298 331 * bp_core_load_template() 299 332 * … … 310 343 */ 311 344 function bp_core_load_template( $templates ) { 312 global $post, $bp, $wpdb, $wp_query; 313 314 // Determine if the root object WP page exists for this request (TODO: is there an API function for this? 315 if ( !empty( $bp->unfiltered_uri_offset ) && !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) ) 345 global $post, $bp, $wp_query; 346 347 // Bail if there is no offset 348 if ( empty( $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) 349 return false; 350 351 // Determine if the root object WP page exists for this request 352 if ( !get_page_by_path( $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) 316 353 return false; 317 354 318 355 // Set the root object as the current wp_query-ied item 319 356 $object_id = 0; 320 foreach ( (array) $bp->pages as $page ) {321 if ( isset( $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) && ( $page->name == $bp->unfiltered_uri[$bp->unfiltered_uri_offset] )) {357 foreach ( (array) $bp->pages as $page ) { 358 if ( $page->name == $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) { 322 359 $object_id = $page->id; 323 360 } … … 331 368 } 332 369 370 // Define local variables 371 $located_template = false; 372 $filtered_templates = array(); 373 333 374 // Fetch each template and add the php suffix 334 foreach ( (array) $templates as $template )375 foreach ( (array) $templates as $template ) 335 376 $filtered_templates[] = $template . '.php'; 336 377 337 378 // Filter the template locations so that plugins can alter where they are located 338 if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) { 379 $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ); 380 if ( !empty( $located_template ) ) { 381 339 382 // Template was located, lets set this as a valid page and not a 404. 340 383 status_header( 200 ); … … 405 448 406 449 // Apply filters to these variables 407 $mode = apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message ); 408 $redirect = apply_filters( 'bp_no_access_redirect', $redirect, $root, $message, $mode ); 409 $root = trailingslashit( apply_filters( 'bp_no_access_root', $root, $redirect, $message, $mode ) ); 410 $message = apply_filters( 'bp_no_access_message', $message, $root, $redirect, $mode ); 450 $mode = apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message ); 451 $redirect = apply_filters( 'bp_no_access_redirect', $redirect, $root, $message, $mode ); 452 $root = apply_filters( 'bp_no_access_root', $root, $redirect, $message, $mode ); 453 $message = apply_filters( 'bp_no_access_message', $message, $root, $redirect, $mode ); 454 $root = trailingslashit( $root ); 411 455 412 456 switch ( $mode ) { -
trunk/bp-members/bp-members-functions.php
r5305 r5319 110 110 $username = rawurlencode( $username ); 111 111 112 // If we are using a members slug, include it. 113 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) 114 $domain = bp_get_root_domain() . '/' . bp_get_members_root_slug() . '/' . $username; 115 else 116 $domain = bp_get_root_domain() . '/' . $username; 117 118 // Add a slash at the end, and filter before caching 119 $domain = apply_filters( 'bp_core_get_user_domain_pre_cache', trailingslashit( $domain ), $user_id, $user_nicename, $user_login ); 112 $after_domain = bp_core_enable_root_profiles() ? $username : bp_get_members_root_slug() . '/' . $username; 113 $domain = trailingslashit( bp_get_root_domain() . '/' . $after_domain ); 114 $domain = apply_filters( 'bp_core_get_user_domain_pre_cache', $domain, $user_id, $user_nicename, $user_login ); 120 115 121 116 // Cache the link 122 if ( !empty( $domain ) ) 117 if ( !empty( $domain ) ) { 123 118 wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' ); 119 } 124 120 } 125 121
Note: See TracChangeset
for help on using the changeset viewer.