Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/15/2015 07:57:03 PM (9 years ago)
Author:
tw2113
Message:

[Samus Aran]
I first battled the documentation inconsistencies on planet Zebes. It was there that I foiled the plans of the
Space Pirate leader Mother Brain to use the issues to attack galactic civilization...

I next fought the inconsistencies on their homeworld SR388. I completely eradicated them except for an @since tag,
which after hatching followed me like a confused child...

I personally delivered it to the Galactic Research Station at Ceres so scientists could study its energy production qualities...

The scientists' findings were astounding! They discovered that the powers of the docs inconsistencies
might be harnessed for the good of galactic civilization!

Satisfied that all was well, I left the station to seek a new bounty to hunt. But, I had hardly gone beyond the asteroid
belt when I picked up a distress signal!

Ceres station was under attack!

More documentation cleanup for part of BP-Core component.

See #6398.

File:
1 edited

Legend:

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

    r10212 r10356  
    3535    global $current_blog, $wp_rewrite;
    3636
    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.
    3838    if ( !bp_is_root_blog() && !bp_is_multiblog_mode() )
    3939        return false;
     
    4141    $bp = buddypress();
    4242
    43     // Define local variables
     43    // Define local variables.
    4444    $root_profile = $match   = false;
    4545    $key_slugs    = $matches = $uri_chunks = array();
    4646
    47     // Fetch all the WP page names for each component
     47    // Fetch all the WP page names for each component.
    4848    if ( empty( $bp->pages ) )
    4949        $bp->pages = bp_core_get_directory_pages();
     
    6464    $path = apply_filters( 'bp_uri', $path );
    6565
    66     // Take GET variables off the URL to avoid problems
     66    // Take GET variables off the URL to avoid problems.
    6767    $path = strtok( $path, '?' );
    6868
    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.
    7070    $bp_uri = explode( '/', $path );
    7171
    72     // Loop and remove empties
     72    // Loop and remove empties.
    7373    foreach ( (array) $bp_uri as $key => $uri_chunk ) {
    7474        if ( empty( $bp_uri[$key] ) ) {
     
    8080    // removed from $bp_uri. This includes two cases:
    8181    //
    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!
     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!
    8585    if ( is_multisite() && !is_subdomain_install() && ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) {
    8686
    87         // Blow chunks
     87        // Blow chunks.
    8888        $chunks = explode( '/', $current_blog->path );
    8989
     
    105105    }
    106106
    107     // Get site path items
     107    // Get site path items.
    108108    $paths = explode( '/', bp_core_get_site_path() );
    109109
    110     // Take empties off the end of path
     110    // Take empties off the end of path.
    111111    if ( empty( $paths[count( $paths ) - 1] ) )
    112112        array_pop( $paths );
    113113
    114     // Take empties off the start of path
     114    // Take empties off the start of path.
    115115    if ( empty( $paths[0] ) )
    116116        array_shift( $paths );
    117117
    118     // Reset indexes
     118    // Reset indexes.
    119119    $bp_uri = array_values( $bp_uri );
    120120    $paths  = array_values( $paths );
    121121
    122     // Unset URI indices if they intersect with the paths
     122    // Unset URI indices if they intersect with the paths.
    123123    foreach ( (array) $bp_uri as $key => $uri_chunk ) {
    124124        if ( isset( $paths[$key] ) && $uri_chunk == $paths[$key] ) {
     
    127127    }
    128128
    129     // Reset the keys by merging with an empty array
     129    // Reset the keys by merging with an empty array.
    130130    $bp_uri = array_merge( array(), $bp_uri );
    131131
    132132    // If a component is set to the front page, force its name into $bp_uri
    133133    // 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).
    135135    if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && empty( $bp_uri ) && empty( $_GET['p'] ) && empty( $_GET['page_id'] ) ) {
    136136        $post = get_post( get_option( 'page_on_front' ) );
     
    140140    }
    141141
    142     // Keep the unfiltered URI safe
     142    // Keep the unfiltered URI safe.
    143143    $bp->unfiltered_uri = $bp_uri;
    144144
     
    146146    $GLOBALS['bp_unfiltered_uri'] = &$bp->unfiltered_uri;
    147147
    148     // Get slugs of pages into array
     148    // Get slugs of pages into array.
    149149    foreach ( (array) $bp->pages as $page_key => $bp_page )
    150150        $key_slugs[$page_key] = trailingslashit( '/' . $bp_page->slug );
    151151
    152     // Bail if keyslugs are empty, as BP is not setup correct
     152    // Bail if keyslugs are empty, as BP is not setup correct.
    153153    if ( empty( $key_slugs ) )
    154154        return;
    155155
    156     // Loop through page slugs and look for exact match to path
     156    // Loop through page slugs and look for exact match to path.
    157157    foreach ( $key_slugs as $key => $slug ) {
    158158        if ( $slug == $path ) {
     
    164164    }
    165165
    166     // No exact match, so look for partials
     166    // No exact match, so look for partials.
    167167    if ( empty( $match ) ) {
    168168
    169         // Loop through each page in the $bp->pages global
     169        // Loop through each page in the $bp->pages global.
    170170        foreach ( (array) $bp->pages as $page_key => $bp_page ) {
    171171
    172             // Look for a match (check members first)
     172            // Look for a match (check members first).
    173173            if ( in_array( $bp_page->name, (array) $bp_uri ) ) {
    174174
     
    176176                $uri_chunks = explode( '/', $bp_page->slug );
    177177
    178                 // Loop through uri_chunks
     178                // Loop through uri_chunks.
    179179                foreach ( (array) $uri_chunks as $key => $uri_chunk ) {
    180180
    181                     // Make sure chunk is in the correct position
     181                    // Make sure chunk is in the correct position.
    182182                    if ( !empty( $bp_uri[$key] ) && ( $bp_uri[$key] == $uri_chunk ) ) {
    183183                        $matches[] = 1;
    184184
    185                     // No match
     185                    // No match.
    186186                    } else {
    187187                        $matches[] = 0;
     
    189189                }
    190190
    191                 // Have a match
     191                // Have a match.
    192192                if ( !in_array( 0, (array) $matches ) ) {
    193193                    $match      = $bp_page;
     
    196196                };
    197197
    198                 // Unset matches
     198                // Unset matches.
    199199                unset( $matches );
    200200            }
    201201
    202             // Unset uri chunks
     202            // Unset uri chunks.
    203203            unset( $uri_chunks );
    204204        }
    205205    }
    206206
    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.
    208208    if ( empty( $matches ) && bp_core_enable_root_profiles() ) {
    209209
    210         // Switch field based on compat
     210        // Switch field based on compat.
    211211        $field = bp_is_username_compatibility_mode() ? 'login' : 'slug';
    212212
    213         // Make sure there's a user corresponding to $bp_uri[0]
     213        // Make sure there's a user corresponding to $bp_uri[0].
    214214        if ( !empty( $bp->pages->members ) && !empty( $bp_uri[0] ) && $root_profile = get_user_by( $field, $bp_uri[0] ) ) {
    215215
    216             // Force BP to recognize that this is a members page
     216            // Force BP to recognize that this is a members page.
    217217            $matches[]  = 1;
    218218            $match      = $bp->pages->members;
     
    221221    }
    222222
    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.
    224224    if ( !empty( $bp_uri[0] ) && ( bp_get_search_slug() == $bp_uri[0] ) ) {
    225225        $matches[]   = 1;
     
    235235    $wp_rewrite->use_verbose_page_rules = false;
    236236
    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.
    238238    $slug       = !empty ( $match ) ? explode( '/', $match->slug ) : '';
    239239    $uri_offset = empty( $root_profile ) ? 0 : -1;
    240240
    241     // Rejig the offset
     241    // Rejig the offset.
    242242    if ( !empty( $slug ) && ( 1 < count( $slug ) ) ) {
    243243        // Only offset if not on a root profile. Fixes issue when Members page is nested.
     
    249249
    250250    // 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.
    252252    $bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
    253253
    254     // We have an exact match
     254    // We have an exact match.
    255255    if ( isset( $match->key ) ) {
    256256
    257         // Set current component to matched key
     257        // Set current component to matched key.
    258258        $bp->current_component = $match->key;
    259259
    260         // If members component, do more work to find the actual component
     260        // If members component, do more work to find the actual component.
    261261        if ( 'members' == $match->key ) {
    262262
     
    268268            // Are we viewing a specific user?
    269269            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.
    271271                if ( $root_profile instanceof WP_User ) {
    272272                    $bp->displayed_user->id = $root_profile->ID;
    273273
    274                 // Switch the displayed_user based on compatibility mode
     274                // Switch the displayed_user based on compatibility mode.
    275275                } elseif ( bp_is_username_compatibility_mode() ) {
    276276                    $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $after_member_slug ) );
     
    302302            }
    303303
    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).
    305305            if ( bp_displayed_user_id() && bp_is_user_spammer( bp_displayed_user_id() ) ) {
    306306                if ( bp_current_user_can( 'bp_moderate' ) ) {
     
    318318                    $bp->current_component = $bp_uri[0];
    319319
    320                 // No component, so default will be picked later
     320                // No component, so default will be picked later.
    321321                } else {
    322322                    $bp_uri                = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) );
     
    324324                }
    325325
    326                 // Reset the offset
     326                // Reset the offset.
    327327                $uri_offset = 0;
    328328            }
     
    347347    $bp->current_action = $current_action;
    348348
    349     // Slice the rest of the $bp_uri array and reset offset
     349    // Slice the rest of the $bp_uri array and reset offset.
    350350    $bp_uri      = array_slice( $bp_uri, $uri_offset + 2 );
    351351    $uri_offset  = 0;
    352352
    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.
    354354    $bp->action_variables = $bp_uri;
    355355
    356     // Reset the keys by merging with an empty array
     356    // Reset the keys by merging with an empty array.
    357357    $bp->action_variables = array_merge( array(), $bp->action_variables );
    358358}
     
    391391 *
    392392 * @param array $templates Array of templates to attempt to load.
    393  *
    394  * @return bool|null Returns false on failure.
    395393 */
    396394function bp_core_load_template( $templates ) {
    397395    global $wp_query;
    398396
    399     // Reset the post
     397    // Reset the post.
    400398    bp_theme_compat_reset_post( array(
    401399        'ID'          => 0,
     
    405403
    406404    // Set theme compat to false since the reset post function automatically sets
    407     // theme compat to true
     405    // theme compat to true.
    408406    bp_set_theme_compat_active( false );
    409407
    410     // Fetch each template and add the php suffix
     408    // Fetch each template and add the php suffix.
    411409    $filtered_templates = array();
    412410    foreach ( (array) $templates as $template ) {
     
    414412    }
    415413
    416     // Only perform template lookup for bp-default themes
     414    // Only perform template lookup for bp-default themes.
    417415    if ( ! bp_use_theme_compat_with_current_theme() ) {
    418416        $template = locate_template( (array) $filtered_templates, false );
    419417
    420     // Theme compat doesn't require a template lookup
     418    // Theme compat doesn't require a template lookup.
    421419    } else {
    422420        $template = '';
     
    471469        exit();
    472470
    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.
    475473    } else {
    476474
     
    554552function bp_core_no_access( $args = '' ) {
    555553
    556     // Build the redirect URL
     554    // Build the redirect URL.
    557555    $redirect_url  = is_ssl() ? 'https://' : 'http://';
    558556    $redirect_url .= $_SERVER['HTTP_HOST'];
     
    578576    extract( $r, EXTR_SKIP );
    579577
    580     /**
     578    /*
    581579     * @ignore Ignore these filters and use 'bp_core_no_access' above
    582580     */
     
    590588
    591589        // 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().
    593591        case 2 :
    594592            if ( !empty( $redirect ) ) {
     
    601599
    602600        // 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().
    604602        case 1 :
    605603        default :
     
    642640    $error = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] );
    643641
    644     // shake shake shake!
     642    // Shake shake shake!.
    645643    add_action( 'login_head', 'wp_shake_js', 12 );
    646644}
     
    682680        }
    683681
    684         // build the URL in the address bar
     682        // Build the URL in the address bar.
    685683        $requested_url  = bp_get_requested_url();
    686684
    687         // Stash query args
     685        // Stash query args.
    688686        $url_stack      = explode( '?', $requested_url );
    689687        $req_url_clean  = $url_stack[0];
     
    692690        $canonical_url  = bp_get_canonical_url();
    693691
    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.
    695693        if ( $canonical_url !== $req_url_clean ) {
    696694
     
    698696
    699697            // 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.
    701699            if ( isset( $bp->template_message ) ) {
    702700                $message      = stripslashes( $bp->template_message );
     
    723721    $canonical_url = bp_get_canonical_url();
    724722
    725     // Output rel=canonical tag
     723    // Output rel=canonical tag.
    726724    echo "<link rel='canonical' href='" . esc_attr( $canonical_url ) . "' />\n";
    727725}
     
    739737 *                                    in the canonical URL returned from the function.
    740738 * }
    741  *
    742739 * @return string Canonical URL for the current page.
    743740 */
    744741function bp_get_canonical_url( $args = array() ) {
    745742
    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.
    747744    if ( bp_is_blog_page() ) {
    748745        return bp_get_requested_url();
     
    752749
    753750    $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.
    755752    );
    756753    $r = wp_parse_args( $args, $defaults );
     
    766763        // URL is the front page. We detect whether we're detecting a
    767764        // 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.
    769766        if ( false !== $front_page_component && bp_is_current_component( $front_page_component ) && ! bp_current_action() ) {
    770767            $bp->canonical_stack['canonical_url'] = trailingslashit( bp_get_root_domain() );
     
    772769        // Except when the front page is set to the registration page
    773770        // 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.
    775772        } elseif ( bp_is_register_page() && 'register' == $front_page_component && is_user_logged_in() ) {
    776773
     
    787784
    788785    if ( empty( $bp->canonical_stack['canonical_url'] ) ) {
    789         // Build the URL in the address bar
     786        // Build the URL in the address bar.
    790787        $requested_url  = bp_get_requested_url();
    791788
    792         // Stash query args
     789        // Stash query args.
    793790        $url_stack      = explode( '?', $requested_url );
    794791
    795         // Build the canonical URL out of the redirect stack
     792        // Build the canonical URL out of the redirect stack.
    796793        if ( isset( $bp->canonical_stack['base_url'] ) )
    797794            $url_stack[0] = $bp->canonical_stack['base_url'];
     
    809806        }
    810807
    811         // Add trailing slash
     808        // Add trailing slash.
    812809        $url_stack[0] = trailingslashit( $url_stack[0] );
    813810
    814         // Stash in the $bp global
     811        // Stash in the $bp global.
    815812        $bp->canonical_stack['canonical_url'] = implode( '?', $url_stack );
    816813    }
Note: See TracChangeset for help on using the changeset viewer.