Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/09/2012 10:10:47 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Remove unneeded globals and clean up some code in Activity component. See #3989.

File:
1 edited

Legend:

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

    r5639 r5684  
    210210
    211211        function the_activity() {
    212                 global $activity;
    213212
    214213                $this->in_the_loop = true;
    215                 $this->activity = $this->next_activity();
     214                $this->activity    = $this->next_activity();
    216215
    217216                if ( is_array( $this->activity ) )
     
    441440         * @since 1.2.0
    442441         *
    443          * @global object $bp BuddyPress global settings
    444442         * @global object $activities_template {@link BP_Activity_Template}
    445443         * @uses bp_core_number_format()
     
    448446         */
    449447        function bp_get_activity_pagination_count() {
    450                 global $bp, $activities_template;
     448                global $activities_template;
    451449
    452450                $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
     
    566564 */
    567565function bp_activities_title() {
    568         global $bp_activity_title;
    569 
    570566        echo bp_get_activities_title();
    571567}
     
    595591 */
    596592function bp_activities_no_activity() {
    597         global $bp_activity_no_activity;
    598 
    599593        echo bp_get_activities_no_activity();
    600594}
     
    970964         * @param array $args optional
    971965         *
    972          * @global object $bp BuddyPress global settings
    973966         * @global object $activities_template {@link BP_Activity_Template}
    974967         * @uses wp_parse_args()
     
    982975         */
    983976        function bp_get_activity_secondary_avatar( $args = '' ) {
    984                 global $bp, $activities_template;
     977                global $activities_template;
    985978
    986979                $defaults = array(
     
    11591152         * @todo properly deprecate this function
    11601153         *
    1161          * @global object $activities_template {@link BP_Activity_Template}
    11621154         * @uses bp_get_activity_action()
    11631155         * @uses bp_get_activity_content_body()
     
    11671159         */
    11681160        function bp_get_activity_content() {
    1169                 global $activities_template;
    1170 
    11711161                /**
    11721162                 * If you want to filter activity update content, please use
     
    11881178 *
    11891179 * @global object $activities_template {@link BP_Activity_Template}
    1190  * @global object $bp BuddyPress global settings
    11911180 * @uses bp_core_time_since()
    11921181 * @uses apply_filters_ref_array() To call the 'bp_activity_time_since' hook
     
    12001189 */
    12011190function bp_insert_activity_meta( $content ) {
    1202         global $activities_template, $bp;
     1191        global $activities_template;
    12031192
    12041193        // Strip any legacy time since placeholders from BP 1.0-1.1
     
    12251214 *
    12261215 * @global object $activities_template {@link BP_Activity_Template}
    1227  * @global object $bp BuddyPress global settings
    12281216 * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook
    12291217 *
     
    12311219 */
    12321220function bp_activity_user_can_delete( $activity = false ) {
    1233         global $activities_template, $bp;
     1221        global $activities_template;
    12341222
    12351223        if ( !$activity )
     
    12471235                $can_delete = true;
    12481236
    1249         if ( $bp->is_item_admin && $bp->is_single_item )
     1237        if ( bp_is_item_admin() && bp_is_single_item() )
    12501238                $can_delete = true;
    12511239
     
    12731261         * @param array $args Optional
    12741262         *
    1275          * @global object $bp BuddyPress global settings
    12761263         * @global object $activities_template {@link BP_Activity_Template}
    12771264         * @uses wp_parse_args()
     
    12811268         */
    12821269        function bp_get_activity_parent_content( $args = '' ) {
    1283                 global $bp, $activities_template;
     1270                global $activities_template;
    12841271
    12851272                $defaults = array(
     
    13281315         * @since 1.2.0
    13291316         *
    1330          * @global object $bp BuddyPress global settings
    13311317         * @global object $activities_template {@link BP_Activity_Template}
    13321318         * @uses apply_filters() To call the 'bp_get_activity_is_favorite' hook
     
    13351321         */
    13361322        function bp_get_activity_is_favorite() {
    1337                 global $bp, $activities_template;
     1323                global $activities_template;
    13381324
    13391325                return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$activities_template->my_favs ) );
     
    13661352         *
    13671353         * @global object $activities_template {@link BP_Activity_Template}
    1368          * @global object $bp BuddyPress global settings
    13691354         * @uses bp_activity_recurse_comments()
    13701355         */
    13711356        function bp_activity_get_comments( $args = '' ) {
    1372                 global $activities_template, $bp;
     1357                global $activities_template;
    13731358
    13741359                if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
     
    13911376                 *
    13921377                 * @global object $activities_template {@link BP_Activity_Template}
    1393                  * @global object $bp BuddyPress global settings
    13941378                 * @uses locate_template()
    13951379                 */
    13961380                function bp_activity_recurse_comments( $comment ) {
    1397                         global $activities_template, $bp, $counter;
    1398 
    1399                         if ( !$comment )
     1381                        global $activities_template;
     1382
     1383                        if ( empty( $comment ) )
    14001384                                return false;
    14011385
     
    16141598         * @since 1.5.0
    16151599         *
    1616          * @global object $bp BuddyPress global settings
    16171600         * @uses wp_nonce_url()
    16181601         * @uses bp_get_root_domain()
     
    16241607         */
    16251608        function bp_get_activity_comment_delete_link() {
    1626                 global $bp;
    1627 
    16281609                $link = wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/delete/' . bp_get_activity_comment_id() . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' );
    16291610
     
    16881669         *
    16891670         * @global object $activities_template {@link BP_Activity_Template}
    1690          * @global object $bp BuddyPress global settings
    16911671         * @uses bp_activity_recurse_comment_count()
    16921672         * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
     
    16951675         */
    16961676        function bp_activity_get_comment_count( $args = '' ) {
    1697                 global $activities_template, $bp;
     1677                global $activities_template;
    16981678
    16991679                if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
     
    17181698                 * @param object $comment Activity comments object
    17191699                 *
    1720                  * @global object $activities_template {@link BP_Activity_Template}
    1721                  * @global object $bp BuddyPress global settings
    17221700                 * @uses bp_activity_recurse_comment_count()
    17231701                 * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
     
    17261704                 */
    17271705                function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
    1728                         global $activities_template, $bp;
    1729 
    1730                         if ( !$comment->children )
     1706
     1707                        if ( empty( $comment->children ) )
    17311708                                return $count;
    17321709
    1733                         foreach ( (array)$comment->children as $comment ) {
     1710                        foreach ( (array) $comment->children as $comment ) {
    17341711                                $count++;
    17351712                                $count = bp_activity_recurse_comment_count( $comment, $count );
     
    18091786         * @since 1.2.0
    18101787         *
    1811          * @global object $bp BuddyPress global settings
    18121788         * @uses home_url()
    18131789         * @uses bp_get_activity_root_slug()
     
    18171793         */
    18181794        function bp_get_activity_comment_form_action() {
    1819                 global $bp;
    1820 
    18211795                return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );
    18221796        }
     
    18651839         * @since 1.2.0
    18661840         *
    1867          * @global object $bp BuddyPress global settings
    18681841         * @uses bp_activity_get_permalink()
    18691842         * @uses apply_filters() To call the 'bp_get_activity_thread_permalink' hook
     
    18721845         */
    18731846        function bp_get_activity_thread_permalink() {
    1874                 global $bp, $activities_template;
     1847                global $activities_template;
    18751848
    18761849                $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
     
    18951868         * @since 1.2.0
    18961869         *
    1897          * @global object $bp BuddyPress global settings
    18981870         * @global object $activities_template {@link BP_Activity_Template}
    18991871         * @uses wp_nonce_url()
     
    19051877         */
    19061878        function bp_get_activity_favorite_link() {
    1907                 global $bp, $activities_template;
     1879                global $activities_template;
    19081880                return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
    19091881        }
     
    19251897         * @since 1.2.0
    19261898         *
    1927          * @global object $bp BuddyPress global settings
    19281899         * @global object $activities_template {@link BP_Activity_Template}
    19291900         * @uses wp_nonce_url()
     
    19351906         */
    19361907        function bp_get_activity_unfavorite_link() {
    1937                 global $bp, $activities_template;
     1908                global $activities_template;
    19381909                return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
    19391910        }
     
    20021973         *
    20031974         * @global object $activities_template {@link BP_Activity_Template}
    2004          * @global object $bp BuddyPress global settings
    20051975         * @uses bp_get_root_domain()
    20061976         * @uses bp_get_activity_root_slug()
     
    20151985         */
    20161986        function bp_get_activity_delete_link() {
    2017                 global $activities_template, $bp;
     1987                global $activities_template;
    20181988
    20191989                $url   = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id;
     
    20502020         * @param int $user_id Defaults to 0
    20512021         *
    2052          * @global object $bp BuddyPress global settings
    20532022         * @uses bp_is_user_inactive()
    20542023         * @uses bp_core_is_user_deleted()
     
    20632032         */
    20642033        function bp_get_activity_latest_update( $user_id = 0 ) {
    2065                 global $bp;
    2066 
    2067                 if ( !$user_id )
     2034
     2035                if ( empty( $user_id ) )
    20682036                        $user_id = bp_displayed_user_id();
    20692037
     
    21002068         * @param array $args Defaults to false
    21012069         *
    2102          * @global object $activities_template {@link BP_Activity_Template}
    2103          * @global object $bp BuddyPress global settings
    21042070         * @uses wp_parse_args()
    21052071         * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
     
    21132079         */
    21142080        function bp_get_activity_filter_links( $args = false ) {
    2115                 global $activities_template, $bp;
    21162081
    21172082                $defaults = array(
     
    21222087                extract( $r, EXTR_SKIP );
    21232088
     2089                // Define local variable
     2090                $component_links = array();
     2091
    21242092                // Fetch the names of components that have activity recorded in the DB
    21252093                $components = BP_Activity_Activity::get_recorded_components();
    21262094
    2127                 if ( !$components )
     2095                if ( empty( $components ) )
    21282096                        return false;
    21292097
    21302098                foreach ( (array) $components as $component ) {
    2131                         /* Skip the activity comment filter */
     2099
     2100                        // Skip the activity comment filter
    21322101                        if ( 'activity' == $component )
    21332102                                continue;
     
    21602129                        $link = add_query_arg( 'afilter', $component );
    21612130                        $link = remove_query_arg( 'acpage' , $link );
    2162 
    21632131                        $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
    21642132
    2165                         // Make sure all core internal component names are translatable
    2166                         $translatable_components = array( __( 'xprofile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'sites', 'buddypress' ) );
    2167 
    2168                         $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
     2133                        $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( $component ) . '</a>' . $after;
    21692134                }
    21702135
     
    21832148 *
    21842149 * @global object $activities_template {@link BP_Activity_Template}
    2185  * @global object $bp BuddyPress global settings
    21862150 * @uses bp_get_activity_action_name()
    21872151 * @uses apply_filters() To call the 'bp_activity_can_comment' hook
     
    21902154 */
    21912155function bp_activity_can_comment() {
    2192         global $activities_template, $bp;
     2156        global $activities_template;
    21932157
    21942158        $can_comment = true;
     
    22842248         * @since 1.2.0
    22852249         *
    2286          * @todo remove unnecessary $bp global
    2287          *
    22882250         * @param int $user_id Defaults to 0
    2289          *
    22902251         * @uses bp_get_user_meta()
    22912252         * @uses apply_filters() To call the 'bp_get_total_mention_count_for_user' hook
    2292          *
    22932253         * @return int The total mention count for a specified user
    22942254         */
    22952255        function bp_get_total_mention_count_for_user( $user_id = 0 ) {
    2296                 global $bp;
    2297 
    22982256                return apply_filters( 'bp_get_total_mention_count_for_user', bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) );
    22992257        }
     
    25072465         */
    25082466        function bp_get_member_activity_feed_link() {
    2509                 global $bp;
    25102467
    25112468                if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) )
     
    25152472                elseif ( bp_is_active( 'groups'  ) && bp_is_current_action( bp_get_groups_slug()  ) )
    25162473                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/';
    2517                 elseif ( 'favorites' == $bp->current_action )
     2474                elseif ( 'favorites' == bp_current_action() )
    25182475                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
    2519                 elseif ( 'mentions' == $bp->current_action )
     2476                elseif ( 'mentions' == bp_current_action() )
    25202477                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
    25212478                else
Note: See TracChangeset for help on using the changeset viewer.