Skip to:
Content

BuddyPress.org

Changeset 4088


Ignore:
Timestamp:
03/08/2011 06:35:03 AM (13 years ago)
Author:
johnjamesjacoby
Message:

More auditing of _slug and _root_slug functions.

Introduce functions for updating '$bp->is_' globals to prevent loading $bp global in several functions.

Various phpDoc fixes and whitespace clean-up. (1.3 trunk)

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-screens.php

    r3982 r4088  
    11<?php
    2 
    3 /*******************************************************************************
    4  * Screen Functions
    5  *
    6  * Screen functions are the controllers of BuddyPress. They will execute when
    7  * their specific URL is caught. They will first save or manipulate data using
    8  * business functions, then pass on the user to a template file.
    9  */
    102
    113/**
     
    157 */
    168function bp_activity_screen_index() {
    17     global $bp;
    18 
    19     if ( !bp_displayed_user_id() && bp_is_current_component( 'activity' ) && !bp_current_action() ) {
    20         $bp->is_directory = true;
     9    if ( !bp_displayed_user_id() && bp_is_activity_component() && !bp_current_action() ) {
     10        bp_update_is_directory( true, 'activity' );
    2111
    2212        do_action( 'bp_activity_screen_index' );
     
    3323
    3424function bp_activity_screen_friends() {
    35     global $bp;
    36 
    3725    if ( !bp_is_active( 'friends' ) )
    3826        return false;
    3927
    40     if ( !is_super_admin() )
    41         $bp->is_item_admin = false;
    42 
     28    bp_update_is_item_admin( is_super_admin(), 'activity' );
    4329    do_action( 'bp_activity_screen_friends' );
    4430    bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
     
    4632
    4733function bp_activity_screen_groups() {
    48     global $bp;
    49 
    5034    if ( !bp_is_active( 'groups' ) )
    5135        return false;
    5236
    53     if ( !is_super_admin() )
    54         $bp->is_item_admin = false;
    55 
     37    bp_update_is_item_admin( is_super_admin(), 'activity' );
    5638    do_action( 'bp_activity_screen_groups' );
    5739    bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
     
    5941
    6042function bp_activity_screen_favorites() {
    61     global $bp;
    62 
    63     if ( !is_super_admin() )
    64         $bp->is_item_admin = false;
    65 
     43    bp_update_is_item_admin( is_super_admin(), 'activity' );
    6644    do_action( 'bp_activity_screen_favorites' );
    6745    bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
     
    6947
    7048function bp_activity_screen_mentions() {
    71     global $bp;
    72 
    73     if ( !is_super_admin() )
    74         $bp->is_item_admin = false;
    75 
     49    bp_update_is_item_admin( is_super_admin(), 'activity' );
    7650    do_action( 'bp_activity_screen_mentions' );
    7751    bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
  • trunk/bp-blogs/bp-blogs-screens.php

    r3917 r4088  
    11<?php
    2 
    3 /******************************************************************************
    4  * Screen functions are the controllers of BuddyPress. They will execute when their
    5  * specific URL is caught. They will first save or manipulate data using business
    6  * functions, then pass on the user to a template file.
    7  */
    82
    93function bp_blogs_screen_my_blogs() {
     
    3024
    3125function bp_blogs_screen_index() {
    32     global $bp;
    33 
    3426    if ( is_multisite() && bp_is_blogs_component() && !bp_current_action() ) {
    35         $bp->is_directory = true;
     27        bp_update_is_directory( true, 'blogs' );
    3628
    3729        do_action( 'bp_blogs_screen_index' );
  • trunk/bp-core/admin/bp-core-update.php

    r4041 r4088  
    332332
    333333        // Check for defined slugs
    334         if ( isset( $bp->members->slug ) )
     334        if ( !empty( $bp->members->slug ) )
    335335            $members_slug = $bp->members->slug;
    336336        else
    337             $members_slug = __( 'Members', 'buddypress' );
     337            $members_slug = __( 'members', 'buddypress' );
    338338
    339339        // Groups
    340         if ( isset( $bp->groups->slug ) )
    341             $groups_slug = constant( 'BP_GROUPS_SLUG' );
     340        if ( !empty( $bp->groups->slug ) )
     341            $groups_slug = $bp->groups->slug;
    342342        else
    343             $groups_slug = __( 'Groups', 'buddypress' );
     343            $groups_slug = __( 'groups', 'buddypress' );
    344344
    345345        // Activity
    346         if ( isset( $bp->activity->slug ) )
     346        if ( !empty( $bp->activity->slug ) )
    347347            $activity_slug = $bp->activity->slug;
    348348        else
     
    350350
    351351        // Forums
    352         if ( isset( $bp->forums->slug ) )
     352        if ( !empty( $bp->forums->slug ) )
    353353            $forums_slug = $bp->forums->slug;
    354354        else
     
    356356
    357357        // Blogs
    358         if ( isset( $bp->blogs->slug ) )
     358        if ( !empty( $bp->blogs->slug ) )
    359359            $blogs_slug = $bp->blogs->slug;
    360360        else
     
    362362
    363363        // Register
    364         if ( isset( $bp->register->slug ) )
     364        if ( !empty( $bp->register->slug ) )
    365365            $register_slug = $bp->register->slug;
    366366        else
    367367            $register_slug = __( 'register', 'buddypress' );
    368368
    369         if ( isset( $bp->activation->slug ) )
     369        if ( !empty( $bp->activation->slug ) )
    370370            $activation_slug = $bp->activation->slug;
    371371        else
  • trunk/bp-core/bp-core-functions.php

    r4053 r4088  
    762762    bp_core_update_page_meta( $page_ids );
    763763}
     764
     765/** Global Manipulators *******************************************************/
     766
     767/**
     768 * Set the $bp->is_directory global
     769 *
     770 * @global obj $bp
     771 * @param bool $is_directory
     772 * @param str $component
     773 */
     774function bp_update_is_directory( $is_directory = false, $component = '' ) {
     775    global $bp;
     776
     777    if ( empty( $component ) )
     778        $component = bp_current_component();
     779
     780    $bp->is_directory = apply_filters( 'bp_update_is_directory', $is_directory, $component );
     781}
     782
     783/**
     784 * Set the $bp->is_item_admin global
     785 *
     786 * @global obj $bp
     787 * @param bool $is_item_admin
     788 * @param str $component
     789 */
     790function bp_update_is_item_admin( $is_item_admin = false, $component = '' ) {
     791    global $bp;
     792
     793    if ( empty( $component ) )
     794        $component = bp_current_component();
     795
     796    $bp->is_item_admin = apply_filters( 'bp_update_is_item_admin', $is_item_admin, $component );
     797}
     798
     799/**
     800 * Set the $bp->is_item_mod global
     801 *
     802 * @global obj $bp
     803 * @param bool $is_item_mod
     804 * @param str $component
     805 */
     806function bp_update_is_item_mod( $is_item_mod = false, $component = '' ) {
     807    global $bp;
     808
     809    if ( empty( $component ) )
     810        $component = bp_current_component();
     811
     812    $bp->is_item_mod = apply_filters( 'bp_update_is_item_mod', $is_item_mod, $component );
     813}
     814
    764815?>
  • trunk/bp-core/bp-core-widgets.php

    r3777 r4088  
    3939        <?php if ( bp_has_members( 'user_id=0&type=' . $instance['member_default'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
    4040            <div class="item-options" id="members-list-options">
    41                 <a href="<?php echo site_url() . '/' . $bp->members->slug ?>" id="newest-members" <?php if ( $instance['member_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></a>
    42                 |  <a href="<?php echo site_url() . '/' . $bp->members->slug ?>" id="recently-active-members" <?php if ( $instance['member_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></a>
     41                <a href="<?php echo site_url( bp_get_members_root_slug() ); ?>" id="newest-members" <?php if ( $instance['member_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></a>
     42                |  <a href="<?php echo site_url( bp_get_members_root_slug() ); ?>" id="recently-active-members" <?php if ( $instance['member_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></a>
    4343
    4444                <?php if ( bp_is_active( 'friends' ) ) : ?>
    4545
    46                     | <a href="<?php echo site_url() . '/' . $bp->members->slug ?>" id="popular-members" <?php if ( $instance['member_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></a>
     46                    | <a href="<?php echo site_url( bp_get_members_root_slug() ); ?>" id="popular-members" <?php if ( $instance['member_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></a>
    4747
    4848                <?php endif; ?>
  • trunk/bp-forums/bp-forums-filters.php

    r3982 r4088  
    124124    $content = htmlspecialchars_decode( $content );
    125125
    126     $pattern = "|<a href=&#039;" . bp_get_root_domain() . "/" . $bp->members->slug . "/[A-Za-z0-9-_\.]+/&#039; rel=&#039;nofollow&#039;>(@[A-Za-z0-9-_\.]+)</a>|";
     126    $pattern = "|<a href=&#039;" . bp_get_root_domain() . "/" . bp_get_members_root_slug() . "/[A-Za-z0-9-_\.]+/&#039; rel=&#039;nofollow&#039;>(@[A-Za-z0-9-_\.]+)</a>|";
    127127
    128128    $content = preg_replace( $pattern, "$1", $content );
  • trunk/bp-forums/bp-forums-screens.php

    r4012 r4088  
    1313        }
    1414
    15         $bp->is_directory = true;
     15        bp_update_is_directory( true, 'forums' );
    1616
    1717        do_action( 'bbpress_init' );
  • trunk/bp-forums/bp-forums-template.php

    r4012 r4088  
    240240
    241241    // If $_GET['fs'] is set, let's auto populate the search_terms var
    242     if ( isset( $bp->is_directory ) && !empty( $_GET['fs'] ) )
     242    if ( bp_is_directory() && !empty( $_GET['fs'] ) )
    243243        $search_terms = $_GET['fs'];
    244244
     
    713713        global $bp;
    714714
    715         if ( !$bp->is_directory || !$bp->current_action )
     715        if ( !bp_is_directory() || !$bp->current_action )
    716716            return 'newest';
    717717
     
    726726        global $bp;
    727727
    728         if ( $bp->is_directory && $bp->forums->slug == $bp->current_component )
     728        if ( bp_is_directory() && $bp->forums->slug == $bp->current_component )
    729729            return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] );
    730730    }
  • trunk/bp-groups/bp-groups-loader.php

    r4057 r4088  
    9999            // Using "item" not "group" for generic support in other components.
    100100            if ( is_super_admin() )
    101                 $bp->is_item_admin = 1;
     101                bp_update_is_item_admin( true, 'groups' );
    102102            else
    103                 $bp->is_item_admin = groups_is_user_admin( $bp->loggedin_user->id, $this->current_group->id );
     103                bp_update_is_item_admin( groups_is_user_admin( $bp->loggedin_user->id, $this->current_group->id ), 'groups' );
    104104
    105105            // If the user is not an admin, check if they are a moderator
    106             if ( empty( $bp->is_item_admin ) )
    107                 $bp->is_item_mod = groups_is_user_mod( $bp->loggedin_user->id, $this->current_group->id );
     106            if ( !bp_is_item_admin() )
     107                bp_update_is_item_mod  ( groups_is_user_mod  ( $bp->loggedin_user->id, $this->current_group->id ), 'groups' );
    108108
    109109            // Is the logged in user a member of the group?
  • trunk/bp-groups/bp-groups-screens.php

    r4012 r4088  
    1010
    1111function groups_directory_groups_setup() {
    12     global $bp;
    13 
    1412    if ( bp_is_groups_component() && !bp_current_action() && !bp_current_item() ) {
    15         $bp->is_directory = true;
     13        bp_update_is_directory( true, 'groups' );
    1614
    1715        do_action( 'groups_directory_groups_setup' );
  • trunk/bp-members/bp-members-functions.php

    r3982 r4088  
    11<?php
    22
    3 /********************************************************************************
    4  * Business Functions
    5  *
    6  * Business functions are where all the magic happens in BuddyPress. They will
    7  * handle the actual saving or manipulation of information. Usually they will
    8  * hand off to a database class for data access, then return
    9  * true or false on success or failure.
    10  */
     3/**
     4 * BuddyPress Member Functions
     5 *
     6 * Functions specific to the members component.
     7 *
     8 * @package BuddyPress
     9 * @subpackage Members
     10 */
     11
    1112
    1213/**
     
    2324    global $bp;
    2425
    25     if ( !defined( 'BP_MEMBERS_SLUG' ) && !empty( $bp->pages->members ) )
    26         define( 'BP_MEMBERS_SLUG', $bp->pages->members->slug );
    27     else if ( !defined( 'BP_MEMBERS_SLUG' ) )
    28         define( 'BP_MEMBERS_SLUG', 'members' );
    29 
    30     if ( !defined( 'BP_REGISTER_SLUG' ) && !empty( $bp->pages->register ) )
    31         define( 'BP_REGISTER_SLUG', $bp->pages->register->slug );
    32     else if ( !defined( 'BP_REGISTER_SLUG' ) )
    33         define( 'BP_REGISTER_SLUG', 'register' );
    34 
    35     if ( !defined( 'BP_ACTIVATION_SLUG' ) && !empty( $bp->pages->activate ) )
    36         define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug );
    37     else if ( !defined( 'BP_ACTIVATION_SLUG' ) )
    38         define( 'BP_ACTIVATION_SLUG', 'activate' );
     26    // No custom members slug
     27    if ( !defined( 'BP_MEMBERS_SLUG' ) )
     28        if ( !empty( $bp->pages->members ) )
     29            define( 'BP_MEMBERS_SLUG', $bp->pages->members->slug );
     30        else
     31            define( 'BP_MEMBERS_SLUG', 'members' );
     32
     33    // No custom registration slug
     34    if ( !defined( 'BP_REGISTER_SLUG' ) )
     35        if ( !empty( $bp->pages->register ) )
     36            define( 'BP_REGISTER_SLUG', $bp->pages->register->slug );
     37        else
     38            define( 'BP_REGISTER_SLUG', 'register' );
     39
     40    // No custom activation slug
     41    if ( !defined( 'BP_ACTIVATION_SLUG' ) )
     42        if ( !empty( $bp->pages->activate ) )
     43            define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug );
     44        else
     45            define( 'BP_ACTIVATION_SLUG', 'activate' );
    3946
    4047}
  • trunk/bp-members/bp-members-loader.php

    r4084 r4088  
    77 *
    88 * @package BuddyPress
    9  * @subpackage Member Core
     9 * @subpackage Members
    1010 */
    1111
     
    7373        $bp->loggedin_user->fullname       = bp_core_get_user_displayname( $bp->loggedin_user->id );
    7474
    75         // is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop.
    76         $bp->loggedin_user->is_super_admin = is_super_admin();
    77         $bp->loggedin_user->is_site_admin  = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6
     75        // Hits the DB on single WP installs so get this separately
     76        $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin();
    7877
    7978        // The domain for the user currently logged in. eg: http://domain.com/members/andy
     
    8887         * something, is_item_admin is used. This is a generic variable so it
    8988         * can be used by other components. It can also be modified, so when
    90          * viewing a group 'is_item_admin' would be 1 if they are a group
    91          * admin, 0 if they are not.
     89         * viewing a group 'is_item_admin' would be 'true' if they are a group
     90         * admin, and 'false' if they are not.
    9291         */
    93         $bp->is_item_admin = bp_user_has_access();
     92        bp_update_is_item_admin( bp_user_has_access(), 'members' );
    9493
    95         // Used to determine if the logged in user is a moderator for
    96         // the current content.
    97         $bp->is_item_mod = false;
     94        // Is the logged in user is a mod for the current item?
     95        bp_update_is_item_mod  ( false,                'members' );
    9896
    9997        /** Displayed user ****************************************************/
  • trunk/bp-members/bp-members-notifications.php

    r3963 r4088  
    11<?php
     2
     3/**
     4 * BuddyPress Member Notifications
     5 *
     6 * Functions and filters used for member notification
     7 *
     8 * @package BuddyPress
     9 * @subpackage Members
     10 */
    211
    312function bp_members_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = 0, $date_notified = false ) {
  • trunk/bp-members/bp-members-screens.php

    r4006 r4088  
    11<?php
     2
     3/**
     4 * BuddyPress Member Screens
     5 *
     6 * Handlers for member screens that aren't handled elsewhere
     7 *
     8 * @package BuddyPress
     9 * @subpackage Members
     10 */
    211
    312/**
     
    1221}
    1322
     23/**
     24 * Handles the display of the members directory index
     25 *
     26 * @global object $bp
     27 *
     28 * @uses bp_is_user()
     29 * @uses bp_is_current_component()
     30 * @uses do_action()
     31 * @uses bp_core_load_template()
     32 * @uses apply_filters()
     33 */
    1434function bp_members_screen_index() {
    15     global $bp;
    16 
    1735    if ( !bp_is_user() && bp_is_current_component( 'members' ) ) {
    18         $bp->is_directory = true;
     36        bp_update_is_directory( true, 'members' );
    1937
    2038        do_action( 'bp_members_screen_index' );
  • trunk/bp-members/bp-members-signup.php

    r4056 r4088  
    11<?php
     2
     3/**
     4 * BuddyPress Member Sign-up
     5 *
     6 * Functions and filters specific to the member sign-up process
     7 *
     8 * @package BuddyPress
     9 * @subpackage Members
     10 */
    211
    312
     
    514    global $bp, $wpdb;
    615
    7     if ( $bp->current_component != BP_REGISTER_SLUG )
    8         return false;
    9 
    10     $bp->is_directory = false;
     16    if ( !bp_is_current_component( 'register' ) )
     17        return false;
     18
     19    // Not a directory
     20    bp_update_is_directory( false, 'register' );
    1121
    1222    if ( bp_is_component_front_page( 'register' ) && ( is_user_logged_in() || !bp_get_signup_allowed() ) )
    13         bp_core_redirect( bp_get_root_domain() . '/' . $bp->members->slug );
     23        bp_core_redirect( bp_get_root_domain() . '/' . bp_get_members_root_slug() );
    1424
    1525    // If the user is logged in, redirect away from here
     
    155165    global $bp, $wpdb;
    156166
    157     if ( BP_ACTIVATION_SLUG != $bp->current_component )
     167    if ( bp_is_current_component( 'activate' ) )
    158168        return false;
    159169
     
    167177        if ( !empty( $user->errors ) ) {
    168178            bp_core_add_message( $user->get_error_message(), 'error' );
    169             bp_core_redirect( bp_get_root_domain() . '/' . BP_ACTIVATION_SLUG );
     179            bp_core_redirect( trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug ) );
    170180        }
    171181
     
    593603// Kill the wp-signup.php if custom registration signup templates are present
    594604function bp_members_wpsignup_redirect() {
     605    global $bp;
     606
    595607    $action = '';
    596608    if ( isset( $_GET['action'] ) )
     
    601613
    602614    if ( locate_template( array( 'registration/register.php' ), false ) || locate_template( array( 'register.php' ), false ) )
    603         bp_core_redirect( bp_get_root_domain() . '/' . BP_REGISTER_SLUG . '/' );
     615        bp_core_redirect( bp_get_root_domain() . '/' . $bp->pages->register->slug . '/' );
    604616}
    605617if ( is_multisite() )
  • trunk/bp-members/bp-members-template.php

    r4084 r4088  
    11<?php
     2
     3/**
     4 * BuddyPress Member Template Tags
     5 *
     6 * Functions that are safe to use inside your template files and themes
     7 *
     8 * @package BuddyPress
     9 * @subpackage Members
     10 */
    211
    312/**
     
    4756        global $bp;
    4857        return apply_filters( 'bp_get_members_root_slug', $bp->members->root_slug );
     58    }
     59
     60/**
     61 * Output the sign-up slug
     62 *
     63 * @package BuddyPress
     64 * @subpackage Members Template
     65 * @since BuddyPress {unknown}
     66 *
     67 * @uses bp_get_members_slug()
     68 */
     69function bp_signup_slug() {
     70    echo bp_get_signup_slug();
     71}
     72    /**
     73     * Return the sign-up slug
     74     *
     75     * @package BuddyPress
     76     * @subpackage Members Template
     77     * @since BuddyPress {unknown}
     78     */
     79    function bp_get_signup_slug() {
     80        global $bp;
     81
     82        if ( !empty( $bp->pages->register->slug ) )
     83            $slug = $bp->pages->register->slug;
     84        elseif ( defined( 'BP_REGISTER_SLUG' ) )
     85            $slug = BP_REGISTER_SLUG;
     86        else
     87            $slug = 'register';
     88
     89        return apply_filters( 'bp_get_signup_slug', $bp->pages->register->slug );
     90    }
     91
     92/**
     93 * Output the activation slug
     94 *
     95 * @package BuddyPress
     96 * @subpackage Members Template
     97 * @since BuddyPress {unknown}
     98 *
     99 * @uses bp_get_members_slug()
     100 */
     101function bp_activate_slug() {
     102    echo bp_get_activate_slug();
     103}
     104    /**
     105     * Return the activation slug
     106     *
     107     * @package BuddyPress
     108     * @subpackage Members Template
     109     * @since BuddyPress {unknown}
     110     */
     111    function bp_get_activate_slug() {
     112        global $bp;
     113
     114        if ( !empty( $bp->pages->activate->slug ) )
     115            $slug = $bp->pages->activate->slug;
     116        elseif ( defined( 'BP_ACTIVATION_SLUG' ) )
     117            $slug = BP_ACTIVATION_SLUG;
     118        else
     119            $slug = 'activate';
     120
     121        return apply_filters( 'bp_get_activate_slug', $bp->pages->activate->slug );
    49122    }
    50123
     
    802875
    803876        if ( bp_has_custom_signup_page() )
    804             $page = bp_get_root_domain() . '/' . BP_REGISTER_SLUG;
     877            $page = trailingslashit( bp_get_root_domain() . '/' . $bp->pages->register->slug );
    805878        else
    806879            $page = bp_get_root_domain() . '/wp-signup.php';
     
    823896
    824897        if ( bp_has_custom_activation_page() )
    825             $page = trailingslashit( bp_get_root_domain() ) . BP_ACTIVATION_SLUG;
     898            $page = trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug );
    826899        else
    827900            $page = trailingslashit( bp_get_root_domain() ) . 'wp-activate.php';
  • trunk/bp-xprofile/bp-xprofile-filters.php

    r4083 r4088  
    131131                    $new_values[] = $value;
    132132                } else {
    133                     $new_values[] = '<a href="' . site_url( BP_MEMBERS_SLUG ) . '/?s=' . strip_tags( $value ) . '" rel="nofollow">' . $value . '</a>';
     133                    $new_values[] = '<a href="' . site_url( bp_get_members_root_slug() ) . '/?s=' . strip_tags( $value ) . '" rel="nofollow">' . $value . '</a>';
    134134                }
    135135            }
Note: See TracChangeset for help on using the changeset viewer.