Changeset 10356 for trunk/src/bp-core/bp-core-catchuri.php
- Timestamp:
- 11/15/2015 07:57:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-catchuri.php
r10212 r10356 35 35 global $current_blog, $wp_rewrite; 36 36 37 // Don't catch URIs on non-root blogs unless multiblog mode is on 37 // Don't catch URIs on non-root blogs unless multiblog mode is on. 38 38 if ( !bp_is_root_blog() && !bp_is_multiblog_mode() ) 39 39 return false; … … 41 41 $bp = buddypress(); 42 42 43 // Define local variables 43 // Define local variables. 44 44 $root_profile = $match = false; 45 45 $key_slugs = $matches = $uri_chunks = array(); 46 46 47 // Fetch all the WP page names for each component 47 // Fetch all the WP page names for each component. 48 48 if ( empty( $bp->pages ) ) 49 49 $bp->pages = bp_core_get_directory_pages(); … … 64 64 $path = apply_filters( 'bp_uri', $path ); 65 65 66 // Take GET variables off the URL to avoid problems 66 // Take GET variables off the URL to avoid problems. 67 67 $path = strtok( $path, '?' ); 68 68 69 // Fetch current URI and explode each part separated by '/' into an array 69 // Fetch current URI and explode each part separated by '/' into an array. 70 70 $bp_uri = explode( '/', $path ); 71 71 72 // Loop and remove empties 72 // Loop and remove empties. 73 73 foreach ( (array) $bp_uri as $key => $uri_chunk ) { 74 74 if ( empty( $bp_uri[$key] ) ) { … … 80 80 // removed from $bp_uri. This includes two cases: 81 81 // 82 // 83 // 84 // 82 // 1. when WP is installed in a subdirectory, 83 // 2. when BP is running on secondary blog of a subdirectory 84 // multisite installation. Phew! 85 85 if ( is_multisite() && !is_subdomain_install() && ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) { 86 86 87 // Blow chunks 87 // Blow chunks. 88 88 $chunks = explode( '/', $current_blog->path ); 89 89 … … 105 105 } 106 106 107 // Get site path items 107 // Get site path items. 108 108 $paths = explode( '/', bp_core_get_site_path() ); 109 109 110 // Take empties off the end of path 110 // Take empties off the end of path. 111 111 if ( empty( $paths[count( $paths ) - 1] ) ) 112 112 array_pop( $paths ); 113 113 114 // Take empties off the start of path 114 // Take empties off the start of path. 115 115 if ( empty( $paths[0] ) ) 116 116 array_shift( $paths ); 117 117 118 // Reset indexes 118 // Reset indexes. 119 119 $bp_uri = array_values( $bp_uri ); 120 120 $paths = array_values( $paths ); 121 121 122 // Unset URI indices if they intersect with the paths 122 // Unset URI indices if they intersect with the paths. 123 123 foreach ( (array) $bp_uri as $key => $uri_chunk ) { 124 124 if ( isset( $paths[$key] ) && $uri_chunk == $paths[$key] ) { … … 127 127 } 128 128 129 // Reset the keys by merging with an empty array 129 // Reset the keys by merging with an empty array. 130 130 $bp_uri = array_merge( array(), $bp_uri ); 131 131 132 132 // If a component is set to the front page, force its name into $bp_uri 133 133 // so that $current_component is populated (unless a specific WP post is being requested 134 // via a URL parameter, usually signifying Preview mode) 134 // via a URL parameter, usually signifying Preview mode). 135 135 if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && empty( $bp_uri ) && empty( $_GET['p'] ) && empty( $_GET['page_id'] ) ) { 136 136 $post = get_post( get_option( 'page_on_front' ) ); … … 140 140 } 141 141 142 // Keep the unfiltered URI safe 142 // Keep the unfiltered URI safe. 143 143 $bp->unfiltered_uri = $bp_uri; 144 144 … … 146 146 $GLOBALS['bp_unfiltered_uri'] = &$bp->unfiltered_uri; 147 147 148 // Get slugs of pages into array 148 // Get slugs of pages into array. 149 149 foreach ( (array) $bp->pages as $page_key => $bp_page ) 150 150 $key_slugs[$page_key] = trailingslashit( '/' . $bp_page->slug ); 151 151 152 // Bail if keyslugs are empty, as BP is not setup correct 152 // Bail if keyslugs are empty, as BP is not setup correct. 153 153 if ( empty( $key_slugs ) ) 154 154 return; 155 155 156 // Loop through page slugs and look for exact match to path 156 // Loop through page slugs and look for exact match to path. 157 157 foreach ( $key_slugs as $key => $slug ) { 158 158 if ( $slug == $path ) { … … 164 164 } 165 165 166 // No exact match, so look for partials 166 // No exact match, so look for partials. 167 167 if ( empty( $match ) ) { 168 168 169 // Loop through each page in the $bp->pages global 169 // Loop through each page in the $bp->pages global. 170 170 foreach ( (array) $bp->pages as $page_key => $bp_page ) { 171 171 172 // Look for a match (check members first) 172 // Look for a match (check members first). 173 173 if ( in_array( $bp_page->name, (array) $bp_uri ) ) { 174 174 … … 176 176 $uri_chunks = explode( '/', $bp_page->slug ); 177 177 178 // Loop through uri_chunks 178 // Loop through uri_chunks. 179 179 foreach ( (array) $uri_chunks as $key => $uri_chunk ) { 180 180 181 // Make sure chunk is in the correct position 181 // Make sure chunk is in the correct position. 182 182 if ( !empty( $bp_uri[$key] ) && ( $bp_uri[$key] == $uri_chunk ) ) { 183 183 $matches[] = 1; 184 184 185 // No match 185 // No match. 186 186 } else { 187 187 $matches[] = 0; … … 189 189 } 190 190 191 // Have a match 191 // Have a match. 192 192 if ( !in_array( 0, (array) $matches ) ) { 193 193 $match = $bp_page; … … 196 196 }; 197 197 198 // Unset matches 198 // Unset matches. 199 199 unset( $matches ); 200 200 } 201 201 202 // Unset uri chunks 202 // Unset uri chunks. 203 203 unset( $uri_chunks ); 204 204 } 205 205 } 206 206 207 // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above 207 // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above. 208 208 if ( empty( $matches ) && bp_core_enable_root_profiles() ) { 209 209 210 // Switch field based on compat 210 // Switch field based on compat. 211 211 $field = bp_is_username_compatibility_mode() ? 'login' : 'slug'; 212 212 213 // Make sure there's a user corresponding to $bp_uri[0] 213 // Make sure there's a user corresponding to $bp_uri[0]. 214 214 if ( !empty( $bp->pages->members ) && !empty( $bp_uri[0] ) && $root_profile = get_user_by( $field, $bp_uri[0] ) ) { 215 215 216 // Force BP to recognize that this is a members page 216 // Force BP to recognize that this is a members page. 217 217 $matches[] = 1; 218 218 $match = $bp->pages->members; … … 221 221 } 222 222 223 // Search doesn't have an associated page, so we check for it separately 223 // Search doesn't have an associated page, so we check for it separately. 224 224 if ( !empty( $bp_uri[0] ) && ( bp_get_search_slug() == $bp_uri[0] ) ) { 225 225 $matches[] = 1; … … 235 235 $wp_rewrite->use_verbose_page_rules = false; 236 236 237 // Find the offset. With $root_profile set, we fudge the offset down so later parsing works 237 // Find the offset. With $root_profile set, we fudge the offset down so later parsing works. 238 238 $slug = !empty ( $match ) ? explode( '/', $match->slug ) : ''; 239 239 $uri_offset = empty( $root_profile ) ? 0 : -1; 240 240 241 // Rejig the offset 241 // Rejig the offset. 242 242 if ( !empty( $slug ) && ( 1 < count( $slug ) ) ) { 243 243 // Only offset if not on a root profile. Fixes issue when Members page is nested. … … 249 249 250 250 // Global the unfiltered offset to use in bp_core_load_template(). 251 // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0 251 // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0. 252 252 $bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0; 253 253 254 // We have an exact match 254 // We have an exact match. 255 255 if ( isset( $match->key ) ) { 256 256 257 // Set current component to matched key 257 // Set current component to matched key. 258 258 $bp->current_component = $match->key; 259 259 260 // If members component, do more work to find the actual component 260 // If members component, do more work to find the actual component. 261 261 if ( 'members' == $match->key ) { 262 262 … … 268 268 // Are we viewing a specific user? 269 269 if ( $after_member_slug ) { 270 // If root profile, we've already queried for the user 270 // If root profile, we've already queried for the user. 271 271 if ( $root_profile instanceof WP_User ) { 272 272 $bp->displayed_user->id = $root_profile->ID; 273 273 274 // Switch the displayed_user based on compatibility mode 274 // Switch the displayed_user based on compatibility mode. 275 275 } elseif ( bp_is_username_compatibility_mode() ) { 276 276 $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $after_member_slug ) ); … … 302 302 } 303 303 304 // If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin) 304 // If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin). 305 305 if ( bp_displayed_user_id() && bp_is_user_spammer( bp_displayed_user_id() ) ) { 306 306 if ( bp_current_user_can( 'bp_moderate' ) ) { … … 318 318 $bp->current_component = $bp_uri[0]; 319 319 320 // No component, so default will be picked later 320 // No component, so default will be picked later. 321 321 } else { 322 322 $bp_uri = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) ); … … 324 324 } 325 325 326 // Reset the offset 326 // Reset the offset. 327 327 $uri_offset = 0; 328 328 } … … 347 347 $bp->current_action = $current_action; 348 348 349 // Slice the rest of the $bp_uri array and reset offset 349 // Slice the rest of the $bp_uri array and reset offset. 350 350 $bp_uri = array_slice( $bp_uri, $uri_offset + 2 ); 351 351 $uri_offset = 0; 352 352 353 // Set the entire URI as the action variables, we will unset the current_component and action in a second 353 // Set the entire URI as the action variables, we will unset the current_component and action in a second. 354 354 $bp->action_variables = $bp_uri; 355 355 356 // Reset the keys by merging with an empty array 356 // Reset the keys by merging with an empty array. 357 357 $bp->action_variables = array_merge( array(), $bp->action_variables ); 358 358 } … … 391 391 * 392 392 * @param array $templates Array of templates to attempt to load. 393 *394 * @return bool|null Returns false on failure.395 393 */ 396 394 function bp_core_load_template( $templates ) { 397 395 global $wp_query; 398 396 399 // Reset the post 397 // Reset the post. 400 398 bp_theme_compat_reset_post( array( 401 399 'ID' => 0, … … 405 403 406 404 // Set theme compat to false since the reset post function automatically sets 407 // theme compat to true 405 // theme compat to true. 408 406 bp_set_theme_compat_active( false ); 409 407 410 // Fetch each template and add the php suffix 408 // Fetch each template and add the php suffix. 411 409 $filtered_templates = array(); 412 410 foreach ( (array) $templates as $template ) { … … 414 412 } 415 413 416 // Only perform template lookup for bp-default themes 414 // Only perform template lookup for bp-default themes. 417 415 if ( ! bp_use_theme_compat_with_current_theme() ) { 418 416 $template = locate_template( (array) $filtered_templates, false ); 419 417 420 // Theme compat doesn't require a template lookup 418 // Theme compat doesn't require a template lookup. 421 419 } else { 422 420 $template = ''; … … 471 469 exit(); 472 470 473 // No template found, so setup theme compatibility 474 // @todo Some other 404 handling if theme compat doesn't kick in 471 // No template found, so setup theme compatibility. 472 // @todo Some other 404 handling if theme compat doesn't kick in. 475 473 } else { 476 474 … … 554 552 function bp_core_no_access( $args = '' ) { 555 553 556 // Build the redirect URL 554 // Build the redirect URL. 557 555 $redirect_url = is_ssl() ? 'https://' : 'http://'; 558 556 $redirect_url .= $_SERVER['HTTP_HOST']; … … 578 576 extract( $r, EXTR_SKIP ); 579 577 580 /* *578 /* 581 579 * @ignore Ignore these filters and use 'bp_core_no_access' above 582 580 */ … … 590 588 591 589 // Option to redirect to wp-login.php 592 // Error message is displayed with bp_core_no_access_wp_login_error() 590 // Error message is displayed with bp_core_no_access_wp_login_error(). 593 591 case 2 : 594 592 if ( !empty( $redirect ) ) { … … 601 599 602 600 // Redirect to root with "redirect_to" parameter 603 // Error message is displayed with bp_core_add_message() 601 // Error message is displayed with bp_core_add_message(). 604 602 case 1 : 605 603 default : … … 642 640 $error = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] ); 643 641 644 // shake shake shake!642 // Shake shake shake!. 645 643 add_action( 'login_head', 'wp_shake_js', 12 ); 646 644 } … … 682 680 } 683 681 684 // build the URL in the address bar682 // Build the URL in the address bar. 685 683 $requested_url = bp_get_requested_url(); 686 684 687 // Stash query args 685 // Stash query args. 688 686 $url_stack = explode( '?', $requested_url ); 689 687 $req_url_clean = $url_stack[0]; … … 692 690 $canonical_url = bp_get_canonical_url(); 693 691 694 // Only redirect if we've assembled a URL different from the request 692 // Only redirect if we've assembled a URL different from the request. 695 693 if ( $canonical_url !== $req_url_clean ) { 696 694 … … 698 696 699 697 // Template messages have been deleted from the cookie by this point, so 700 // they must be readded before redirecting 698 // they must be readded before redirecting. 701 699 if ( isset( $bp->template_message ) ) { 702 700 $message = stripslashes( $bp->template_message ); … … 723 721 $canonical_url = bp_get_canonical_url(); 724 722 725 // Output rel=canonical tag 723 // Output rel=canonical tag. 726 724 echo "<link rel='canonical' href='" . esc_attr( $canonical_url ) . "' />\n"; 727 725 } … … 739 737 * in the canonical URL returned from the function. 740 738 * } 741 *742 739 * @return string Canonical URL for the current page. 743 740 */ 744 741 function bp_get_canonical_url( $args = array() ) { 745 742 746 // For non-BP content, return the requested url, and let WP do the work 743 // For non-BP content, return the requested url, and let WP do the work. 747 744 if ( bp_is_blog_page() ) { 748 745 return bp_get_requested_url(); … … 752 749 753 750 $defaults = array( 754 'include_query_args' => false // Include URL arguments, eg ?foo=bar&foo2=bar2 751 'include_query_args' => false // Include URL arguments, eg ?foo=bar&foo2=bar2. 755 752 ); 756 753 $r = wp_parse_args( $args, $defaults ); … … 766 763 // URL is the front page. We detect whether we're detecting a 767 764 // component *directory* by checking that bp_current_action() 768 // is empty - ie, this not a single item or a feed 765 // is empty - ie, this not a single item or a feed. 769 766 if ( false !== $front_page_component && bp_is_current_component( $front_page_component ) && ! bp_current_action() ) { 770 767 $bp->canonical_stack['canonical_url'] = trailingslashit( bp_get_root_domain() ); … … 772 769 // Except when the front page is set to the registration page 773 770 // and the current user is logged in. In this case we send to 774 // the members directory to avoid redirect loops 771 // the members directory to avoid redirect loops. 775 772 } elseif ( bp_is_register_page() && 'register' == $front_page_component && is_user_logged_in() ) { 776 773 … … 787 784 788 785 if ( empty( $bp->canonical_stack['canonical_url'] ) ) { 789 // Build the URL in the address bar 786 // Build the URL in the address bar. 790 787 $requested_url = bp_get_requested_url(); 791 788 792 // Stash query args 789 // Stash query args. 793 790 $url_stack = explode( '?', $requested_url ); 794 791 795 // Build the canonical URL out of the redirect stack 792 // Build the canonical URL out of the redirect stack. 796 793 if ( isset( $bp->canonical_stack['base_url'] ) ) 797 794 $url_stack[0] = $bp->canonical_stack['base_url']; … … 809 806 } 810 807 811 // Add trailing slash 808 // Add trailing slash. 812 809 $url_stack[0] = trailingslashit( $url_stack[0] ); 813 810 814 // Stash in the $bp global 811 // Stash in the $bp global. 815 812 $bp->canonical_stack['canonical_url'] = implode( '?', $url_stack ); 816 813 }
Note: See TracChangeset
for help on using the changeset viewer.