Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/18/2011 12:53:31 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Code normalization and whitespace clean-up. Introduce bp-core-deprecated.php. Introduce root_slug globals into components with directories, to help with WP page slugs. Fixes #2600. Optimus Props boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-templatetags.php

    r3701 r3728  
    163163
    164164    // Make sure we return no members if we looking at friendship requests and there are none.
    165     if ( empty( $include ) && $bp->friends->slug == $bp->current_component && 'requests' == $bp->current_action )
     165    if ( empty( $include ) && bp_is_current_component( $bp->friends->slug ) && 'requests' == $bp->current_action )
    166166        return false;
    167167
     
    583583function bp_get_options_nav() {
    584584    global $bp;
    585 
    586     if ( count( $bp->bp_options_nav[$bp->current_component] ) < 1 )
     585   
     586    // If we are looking at a member profile, then the we can use the current component as an
     587    // index. Otherwise we need to use the component's root_slug
     588    $component_index = !empty( $bp->displayed_user ) ? $bp->current_component : bp_get_root_slug( $bp->current_component );
     589   
     590    if ( count( $bp->bp_options_nav[$component_index] ) < 1 )
    587591        return false;
    588592
    589593    /* Loop through each navigation item */
    590     foreach ( (array)$bp->bp_options_nav[$bp->current_component] as $subnav_item ) {
     594    foreach ( (array)$bp->bp_options_nav[$component_index] as $subnav_item ) {
    591595        if ( !$subnav_item['user_has_access'] )
    592596            continue;
     
    15571561    }
    15581562
     1563/**
     1564 * Echoes the output of bp_get_root_slug()
     1565 *
     1566 * @package BuddyPress Core
     1567 * @since 1.3
     1568 */
     1569function bp_root_slug( $component = '' ) {
     1570    echo bp_get_root_slug( $component );
     1571}
     1572    /**
     1573     * Gets the root slug for a component slug
     1574     *
     1575     * In order to maintain backward compatibility, the following procedure is used:
     1576     * 1) Use the short slug to get the canonical component name from the
     1577     *    active component array
     1578     * 2) Use the component name to get the root slug out of the appropriate part of the $bp
     1579     *    global
     1580     * 3) If nothing turns up, it probably means that $component is itself a root slug
     1581     *
     1582     * Example: If your groups directory is at /community/companies, this function first uses
     1583     * the short slug 'companies' (ie the current component) to look up the canonical name
     1584     * 'groups' in $bp->active_components. Then it uses 'groups' to get the root slug, from
     1585     * $bp->groups->root_slug.
     1586     *
     1587     * @package BuddyPress Core
     1588     * @since 1.3
     1589     *
     1590     * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     1591     * @param string $component Optional. Defaults to the current component
     1592     * @return string $root_slug The root slug
     1593     */
     1594    function bp_get_root_slug( $component = '' ) {
     1595        global $bp;
     1596
     1597        $root_slug = '';
     1598
     1599        // Use current global component if none passed
     1600        if ( empty( $component ) )
     1601            $component = $bp->current_component;
     1602
     1603        // Component is active
     1604        if ( !empty( $bp->active_components[$component] ) ) {
     1605            $component_name = $bp->active_components[$component];
     1606
     1607            // Component has specific root slug
     1608            if ( !empty( $bp->{$component_name}->root_slug ) )
     1609                $root_slug = $bp->{$component_name}->root_slug;
     1610        }
     1611
     1612        // No specific root slug, so fall back to component slug
     1613        if ( empty( $root_slug ) )
     1614            $root_slug = $component;
     1615
     1616        return apply_filters( 'bp_get_root_slug', $root_slug, $component );
     1617    }
     1618
    15591619/* Template is_() functions to determine the current page */
     1620
     1621/**
     1622 * Checks to see whether the current page belongs to the specified component
     1623 *
     1624 * This function is designed to be generous, accepting several different kinds
     1625 * of value for the $component parameter. It checks $component_name against:
     1626 * - the component's root_slug, which matches the page slug in $bp->pages
     1627 * - the component's regular slug
     1628 * - the component's id, or 'canonical' name
     1629 *
     1630 * @package BuddyPress Core
     1631 * @since 1.3
     1632 * @return bool Returns true if the component matches, or else false.
     1633 */
     1634function bp_is_current_component( $component ) {
     1635    global $bp;
     1636
     1637    $is_current_component = false;
     1638
     1639    if ( !empty( $bp->current_component ) ) {
     1640
     1641        // First, check to see whether $component_name and the current
     1642        // component are a simple match
     1643        if ( $bp->current_component == $component ) {
     1644            $is_current_component = true;
     1645
     1646        // Next, check to see whether $component is a canonical,
     1647        // non-translatable component name. If so, we can return its
     1648        // corresponding slug from $bp->active_components.
     1649        } else if ( $key = array_search( $component, $bp->active_components ) ) {
     1650            if ( $key === $bp->current_component )
     1651                $is_current_component = true;
     1652
     1653        // If we haven't found a match yet, check against the root_slugs
     1654        // created by $bp->pages
     1655        } else {
     1656            foreach ( $bp->active_components as $key => $id ) {
     1657                // If the $component parameter does not match the current_component,
     1658                // then move along, these are not the droids you are looking for
     1659                if ( $bp->{$id}->root_slug != $bp->current_component )
     1660                    continue;
     1661
     1662                if ( $key == $component ) {
     1663                    $is_current_component = true;
     1664                    break;
     1665                }
     1666            }
     1667        }
     1668    }
     1669
     1670    return apply_filters( 'bp_is_current_component', $is_current_component, $component_name );
     1671}
     1672
     1673/**
     1674 * Checks to see if a component's URL should be in the root, not under a member page:
     1675 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
     1676 *
     1677 * @package BuddyPress Core
     1678 * @return true if root component, else false.
     1679 */
     1680function bp_is_root_component( $component_name ) {
     1681    global $bp;
     1682
     1683    foreach ( (array) $bp->active_components as $key => $slug ) {
     1684        if ( $key == $component_name || $slug == $component_name )
     1685            return true;
     1686    }
     1687
     1688    return false;
     1689}
    15601690
    15611691/**
     
    15911721        return true;
    15921722
    1593     if ( !$bp->displayed_user->id && !$bp->is_single_item && ( !isset( $bp->is_directory ) || !$bp->is_directory ) && !bp_core_is_root_component( $bp->current_component ) )
     1723    if ( !$bp->displayed_user->id && !$bp->is_single_item && ( !isset( $bp->is_directory ) || !$bp->is_directory ) && !bp_is_root_component( $bp->current_component ) )
    15941724        return true;
    15951725
     
    16611791
    16621792function bp_is_profile_component() {
    1663     global $bp;
    1664 
    1665     if ( BP_XPROFILE_SLUG == $bp->current_component )
     1793    if ( bp_is_current_component( BP_XPROFILE_SLUG ) )
    16661794        return true;
    16671795
     
    16701798
    16711799function bp_is_activity_component() {
    1672     global $bp;
    1673 
    1674     if ( BP_ACTIVITY_SLUG == $bp->current_component )
     1800    if ( bp_is_current_component( BP_ACTIVITY_SLUG ) )
    16751801        return true;
    16761802
     
    16791805
    16801806function bp_is_blogs_component() {
    1681     global $bp;
    1682 
    1683     if ( is_multisite() && BP_BLOGS_SLUG == $bp->current_component )
     1807    if ( is_multisite() && bp_is_current_component( BP_BLOGS_SLUG ) )
    16841808        return true;
    16851809
     
    16881812
    16891813function bp_is_messages_component() {
    1690     global $bp;
    1691 
    1692     if ( BP_MESSAGES_SLUG == $bp->current_component )
     1814    if ( bp_is_current_component( BP_MESSAGES_SLUG ) )
    16931815        return true;
    16941816
     
    16971819
    16981820function bp_is_friends_component() {
    1699     global $bp;
    1700 
    1701     if ( BP_FRIENDS_SLUG == $bp->current_component )
     1821    if ( bp_is_current_component( BP_FRIENDS_SLUG ) )
    17021822        return true;
    17031823
     
    17061826
    17071827function bp_is_groups_component() {
    1708     global $bp;
    1709 
    1710     if ( BP_GROUPS_SLUG == $bp->current_component )
     1828    if ( bp_is_current_component( BP_GROUPS_SLUG ) )
    17111829        return true;
    17121830
     
    17151833
    17161834function bp_is_settings_component() {
    1717     global $bp;
    1718 
    1719     if ( BP_SETTINGS_SLUG == $bp->current_component )
     1835    if ( bp_is_current_component( BP_SETTINGS_SLUG ) )
    17201836        return true;
    17211837
     
    17351851    global $bp;
    17361852
    1737     if ( $bp->activity->slug == $bp->current_component )
     1853    if ( bp_is_current_component( $bp->activity->slug ) )
    17381854        return true;
    17391855
     
    17441860    global $bp;
    17451861
    1746     if ( $bp->activity->slug == $bp->current_component && 'my-friends' == $bp->current_action )
     1862    if ( bp_is_current_component( $bp->activity->slug ) && 'my-friends' == $bp->current_action )
    17471863        return true;
    17481864
     
    17531869    global $bp;
    17541870
    1755     if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
     1871    if ( bp_is_current_component( BP_ACTIVITY_SLUG ) && is_numeric( $bp->current_action ) )
    17561872        return true;
    17571873
     
    17621878    global $bp;
    17631879
    1764     if ( defined( 'BP_XPROFILE_SLUG' ) && BP_XPROFILE_SLUG == $bp->current_component || isset( $bp->core->profile->slug ) && $bp->core->profile->slug == $bp->current_component )
     1880    if ( defined( 'BP_XPROFILE_SLUG' ) && bp_is_current_component( BP_XPROFILE_SLUG ) || isset( $bp->core->profile->slug ) && bp_is_current_component( $bp->core->profile->slug ) )
    17651881        return true;
    17661882
     
    17711887    global $bp;
    17721888
    1773     if ( BP_XPROFILE_SLUG == $bp->current_component && 'edit' == $bp->current_action )
     1889    if ( bp_is_current_component( BP_XPROFILE_SLUG ) && 'edit' == $bp->current_action )
    17741890        return true;
    17751891
     
    17801896    global $bp;
    17811897
    1782     if ( BP_XPROFILE_SLUG == $bp->current_component && 'change-avatar' == $bp->current_action )
     1898    if ( bp_is_current_component( BP_XPROFILE_SLUG ) && 'change-avatar' == $bp->current_action )
    17831899        return true;
    17841900
     
    17881904function bp_is_user_groups() {
    17891905    global $bp;
    1790 
    1791     if ( $bp->groups->slug == $bp->current_component )
     1906   
     1907    if ( bp_is_current_component( BP_GROUPS_SLUG ) )
    17921908        return true;
    17931909
     
    17971913function bp_is_group() {
    17981914    global $bp;
    1799 
    1800     if ( BP_GROUPS_SLUG == $bp->current_component && isset( $bp->groups->current_group ) && $bp->groups->current_group )
     1915   
     1916    if ( bp_is_current_component( BP_GROUPS_SLUG ) && isset( $bp->groups->current_group ) && $bp->groups->current_group )
    18011917        return true;
    18021918
     
    18071923    global $bp;
    18081924
    1809     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
     1925    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
    18101926        return true;
    18111927
     
    18161932    global $bp;
    18171933
    1818     if ( BP_GROUPS_SLUG == $bp->current_component && 'create' == $bp->current_action )
     1934    if ( bp_is_current_component( BP_GROUPS_SLUG ) && 'create' == $bp->current_action )
    18191935        return true;
    18201936
     
    18261942    global $bp;
    18271943
    1828     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'admin' == $bp->current_action )
     1944    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && 'admin' == $bp->current_action )
    18291945        return true;
    18301946
     
    18351951    global $bp;
    18361952
    1837     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action )
     1953    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && 'forum' == $bp->current_action )
    18381954        return true;
    18391955
     
    18441960    global $bp;
    18451961
    1846     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'activity' == $bp->current_action )
     1962    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && 'activity' == $bp->current_action )
    18471963        return true;
    18481964
     
    18531969    global $bp;
    18541970
    1855     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && isset( $bp->action_variables[0] ) && 'topic' == $bp->action_variables[0] )
     1971    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && 'forum' == $bp->current_action && isset( $bp->action_variables[0] ) && 'topic' == $bp->action_variables[0] )
    18561972        return true;
    18571973
     
    18621978    global $bp;
    18631979
    1864     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && isset( $bp->action_variables[0] ) && 'topic' == $bp->action_variables[0] && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] )
     1980    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && 'forum' == $bp->current_action && isset( $bp->action_variables[0] ) && 'topic' == $bp->action_variables[0] && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] )
    18651981        return true;
    18661982
     
    18711987    global $bp;
    18721988
    1873     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'members' == $bp->current_action )
     1989    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && 'members' == $bp->current_action )
    18741990        return true;
    18751991
     
    18801996    global $bp;
    18811997
    1882     if ( BP_GROUPS_SLUG == $bp->current_component && 'send-invites' == $bp->current_action )
     1998    if ( bp_is_current_component( BP_GROUPS_SLUG ) && 'send-invites' == $bp->current_action )
    18831999        return true;
    18842000
     
    18892005    global $bp;
    18902006
    1891     if ( BP_GROUPS_SLUG == $bp->current_component && 'request-membership' == $bp->current_action )
     2007    if ( bp_is_current_component( BP_GROUPS_SLUG ) && 'request-membership' == $bp->current_action )
    18922008        return true;
    18932009
     
    18982014    global $bp;
    18992015
    1900     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'leave-group' == $bp->current_action )
     2016    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item && 'leave-group' == $bp->current_action )
    19012017        return true;
    19022018
     
    19072023    global $bp;
    19082024
    1909     if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item )
     2025    if ( bp_is_current_component( BP_GROUPS_SLUG ) && $bp->is_single_item )
    19102026        return true;
    19112027
     
    19162032    global $bp;
    19172033
    1918     if ( is_multisite() && BP_BLOGS_SLUG == $bp->current_component )
     2034    if ( is_multisite() && bp_is_current_component( BP_BLOGS_SLUG ) )
    19192035        return true;
    19202036
     
    19252041    global $bp;
    19262042
    1927     if ( is_multisite() && BP_BLOGS_SLUG == $bp->current_component && 'recent-posts' == $bp->current_action )
     2043    if ( is_multisite() && bp_is_current_component( BP_BLOGS_SLUG ) && 'recent-posts' == $bp->current_action )
    19282044        return true;
    19292045
     
    19342050    global $bp;
    19352051
    1936     if ( is_multisite() && BP_BLOGS_SLUG == $bp->current_component && 'recent-comments' == $bp->current_action )
     2052    if ( is_multisite() && bp_is_current_component( BP_BLOGS_SLUG ) && 'recent-comments' == $bp->current_action )
    19372053        return true;
    19382054
     
    19432059    global $bp;
    19442060
    1945     if ( is_multisite() && BP_BLOGS_SLUG == $bp->current_component && 'create' == $bp->current_action )
     2061    if ( is_multisite() && bp_is_current_component( BP_BLOGS_SLUG ) && 'create' == $bp->current_action )
    19462062        return true;
    19472063
     
    19502066
    19512067function bp_is_user_friends() {
    1952     global $bp;
    1953 
    1954     if ( BP_FRIENDS_SLUG == $bp->current_component )
     2068    if ( bp_is_current_component( BP_FRIENDS_SLUG ) )
    19552069        return true;
    19562070
     
    19612075    global $bp;
    19622076
    1963     if ( BP_FRIENDS_SLUG == $bp->current_component && 'requests' == $bp->current_action )
     2077    if ( bp_is_current_component( BP_FRIENDS_SLUG ) && 'requests' == $bp->current_action )
    19642078        return true;
    19652079
     
    19682082
    19692083function bp_is_user_messages() {
    1970     global $bp;
    1971 
    1972     if ( BP_MESSAGES_SLUG == $bp->current_component )
     2084    if ( bp_is_current_component( BP_MESSAGES_SLUG ) )
    19732085        return true;
    19742086
     
    19792091    global $bp;
    19802092
    1981     if ( BP_MESSAGES_SLUG == $bp->current_component && ( !$bp->current_action || 'inbox' == $bp->current_action ) )
     2093    if ( bp_is_current_component( BP_MESSAGES_SLUG ) && ( !$bp->current_action || 'inbox' == $bp->current_action ) )
    19822094        return true;
    19832095
     
    19882100    global $bp;
    19892101
    1990     if ( BP_MESSAGES_SLUG == $bp->current_component && 'sentbox' == $bp->current_action )
     2102    if ( bp_is_current_component( BP_MESSAGES_SLUG ) && 'sentbox' == $bp->current_action )
    19912103        return true;
    19922104
     
    19982110    global $bp;
    19992111
    2000     if ( BP_MESSAGES_SLUG == $bp->current_component && 'notices' == $bp->current_action )
     2112    if ( bp_is_current_component( BP_MESSAGES_SLUG ) && 'notices' == $bp->current_action )
    20012113        return true;
    20022114
     
    20082120    global $bp;
    20092121
    2010     if ( BP_MESSAGES_SLUG == $bp->current_component && 'compose' == $bp->current_action )
     2122    if ( bp_is_current_component( BP_MESSAGES_SLUG ) && 'compose' == $bp->current_action )
    20112123        return true;
    20122124
     
    20242136
    20252137function bp_is_activation_page() {
    2026     global $bp;
    2027 
    2028     if ( BP_ACTIVATION_SLUG == $bp->current_component )
     2138    if ( bp_is_current_component( BP_ACTIVATION_SLUG ) )
    20292139        return true;
    20302140
     
    20332143
    20342144function bp_is_register_page() {
    2035     global $bp;
    2036 
    2037     if ( BP_REGISTER_SLUG == $bp->current_component )
     2145    if ( bp_is_current_component( BP_REGISTER_SLUG ) )
    20382146        return true;
    20392147
Note: See TracChangeset for help on using the changeset viewer.