Changeset 3728 for trunk/bp-core/bp-core-templatetags.php
- Timestamp:
- 01/18/2011 12:53:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-templatetags.php
r3701 r3728 163 163 164 164 // 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 ) 166 166 return false; 167 167 … … 583 583 function bp_get_options_nav() { 584 584 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 ) 587 591 return false; 588 592 589 593 /* 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 ) { 591 595 if ( !$subnav_item['user_has_access'] ) 592 596 continue; … … 1557 1561 } 1558 1562 1563 /** 1564 * Echoes the output of bp_get_root_slug() 1565 * 1566 * @package BuddyPress Core 1567 * @since 1.3 1568 */ 1569 function 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 1559 1619 /* 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 */ 1634 function 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 */ 1680 function 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 } 1560 1690 1561 1691 /** … … 1591 1721 return true; 1592 1722 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 ) ) 1594 1724 return true; 1595 1725 … … 1661 1791 1662 1792 function 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 ) ) 1666 1794 return true; 1667 1795 … … 1670 1798 1671 1799 function 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 ) ) 1675 1801 return true; 1676 1802 … … 1679 1805 1680 1806 function 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 ) ) 1684 1808 return true; 1685 1809 … … 1688 1812 1689 1813 function 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 ) ) 1693 1815 return true; 1694 1816 … … 1697 1819 1698 1820 function 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 ) ) 1702 1822 return true; 1703 1823 … … 1706 1826 1707 1827 function 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 ) ) 1711 1829 return true; 1712 1830 … … 1715 1833 1716 1834 function 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 ) ) 1720 1836 return true; 1721 1837 … … 1735 1851 global $bp; 1736 1852 1737 if ( $bp->activity->slug == $bp->current_component)1853 if ( bp_is_current_component( $bp->activity->slug ) ) 1738 1854 return true; 1739 1855 … … 1744 1860 global $bp; 1745 1861 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 ) 1747 1863 return true; 1748 1864 … … 1753 1869 global $bp; 1754 1870 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 ) ) 1756 1872 return true; 1757 1873 … … 1762 1878 global $bp; 1763 1879 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 ) ) 1765 1881 return true; 1766 1882 … … 1771 1887 global $bp; 1772 1888 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 ) 1774 1890 return true; 1775 1891 … … 1780 1896 global $bp; 1781 1897 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 ) 1783 1899 return true; 1784 1900 … … 1788 1904 function bp_is_user_groups() { 1789 1905 global $bp; 1790 1791 if ( $bp->groups->slug == $bp->current_component)1906 1907 if ( bp_is_current_component( BP_GROUPS_SLUG ) ) 1792 1908 return true; 1793 1909 … … 1797 1913 function bp_is_group() { 1798 1914 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 ) 1801 1917 return true; 1802 1918 … … 1807 1923 global $bp; 1808 1924 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 ) ) 1810 1926 return true; 1811 1927 … … 1816 1932 global $bp; 1817 1933 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 ) 1819 1935 return true; 1820 1936 … … 1826 1942 global $bp; 1827 1943 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 ) 1829 1945 return true; 1830 1946 … … 1835 1951 global $bp; 1836 1952 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 ) 1838 1954 return true; 1839 1955 … … 1844 1960 global $bp; 1845 1961 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 ) 1847 1963 return true; 1848 1964 … … 1853 1969 global $bp; 1854 1970 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] ) 1856 1972 return true; 1857 1973 … … 1862 1978 global $bp; 1863 1979 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] ) 1865 1981 return true; 1866 1982 … … 1871 1987 global $bp; 1872 1988 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 ) 1874 1990 return true; 1875 1991 … … 1880 1996 global $bp; 1881 1997 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 ) 1883 1999 return true; 1884 2000 … … 1889 2005 global $bp; 1890 2006 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 ) 1892 2008 return true; 1893 2009 … … 1898 2014 global $bp; 1899 2015 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 ) 1901 2017 return true; 1902 2018 … … 1907 2023 global $bp; 1908 2024 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 ) 1910 2026 return true; 1911 2027 … … 1916 2032 global $bp; 1917 2033 1918 if ( is_multisite() && BP_BLOGS_SLUG == $bp->current_component)2034 if ( is_multisite() && bp_is_current_component( BP_BLOGS_SLUG ) ) 1919 2035 return true; 1920 2036 … … 1925 2041 global $bp; 1926 2042 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 ) 1928 2044 return true; 1929 2045 … … 1934 2050 global $bp; 1935 2051 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 ) 1937 2053 return true; 1938 2054 … … 1943 2059 global $bp; 1944 2060 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 ) 1946 2062 return true; 1947 2063 … … 1950 2066 1951 2067 function 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 ) ) 1955 2069 return true; 1956 2070 … … 1961 2075 global $bp; 1962 2076 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 ) 1964 2078 return true; 1965 2079 … … 1968 2082 1969 2083 function 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 ) ) 1973 2085 return true; 1974 2086 … … 1979 2091 global $bp; 1980 2092 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 ) ) 1982 2094 return true; 1983 2095 … … 1988 2100 global $bp; 1989 2101 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 ) 1991 2103 return true; 1992 2104 … … 1998 2110 global $bp; 1999 2111 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 ) 2001 2113 return true; 2002 2114 … … 2008 2120 global $bp; 2009 2121 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 ) 2011 2123 return true; 2012 2124 … … 2024 2136 2025 2137 function 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 ) ) 2029 2139 return true; 2030 2140 … … 2033 2143 2034 2144 function 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 ) ) 2038 2146 return true; 2039 2147
Note: See TracChangeset
for help on using the changeset viewer.