Skip to:
Content

BuddyPress.org

Changeset 9537


Ignore:
Timestamp:
02/23/2015 06:41:51 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Activity: Clean up bp-activity-template.php:

  • Brackets
  • Whitespace
  • Remove unused variables
File:
1 edited

Legend:

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

    r9536 r9537  
    240240     * }
    241241     */
    242     function __construct( $args ) {
     242    public function __construct( $args ) {
    243243        $bp = buddypress();
    244244
     
    367367        // Fetch parent content for activity comments so we do not have to query in the loop
    368368        foreach ( (array) $this->activities as $activity ) {
    369             if ( 'activity_comment' != $activity->type )
     369            if ( 'activity_comment' != $activity->type ) {
    370370                continue;
     371            }
    371372
    372373            $parent_ids[] = $activity->item_id;
    373374        }
    374375
    375         if ( !empty( $parent_ids ) )
     376        if ( !empty( $parent_ids ) ) {
    376377            $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
     378        }
    377379
    378380        if ( !empty( $activity_parents['activities'] ) ) {
    379             foreach( $activity_parents['activities'] as $parent )
     381            foreach( $activity_parents['activities'] as $parent ) {
    380382                $this->activity_parents[$parent->id] = $parent;
     383            }
    381384
    382385            unset( $activity_parents );
     
    405408     */
    406409    function has_activities() {
    407         if ( $this->activity_count )
     410        if ( $this->activity_count ) {
    408411            return true;
     412        }
    409413
    410414        return false;
     
    416420     * @return object The next activity item to iterate over.
    417421     */
    418     function next_activity() {
     422    public function next_activity() {
    419423        $this->current_activity++;
    420         $this->activity = $this->activities[$this->current_activity];
     424        $this->activity = $this->activities[ $this->current_activity ];
    421425
    422426        return $this->activity;
     
    426430     * Rewind the posts and reset post index.
    427431     */
    428     function rewind_activities() {
     432    public function rewind_activities() {
    429433        $this->current_activity = -1;
    430434        if ( $this->activity_count > 0 ) {
     
    445449     *              otherwise false.
    446450     */
    447     function user_activities() {
    448         if ( $this->current_activity + 1 < $this->activity_count ) {
     451    public function user_activities() {
     452        if ( ( $this->current_activity + 1 ) < $this->activity_count ) {
    449453            return true;
    450         } elseif ( $this->current_activity + 1 == $this->activity_count ) {
     454        } elseif ( ( $this->current_activity + 1 ) == $this->activity_count ) {
    451455
    452456            /**
     
    456460             */
    457461            do_action( 'activity_loop_end' );
     462
    458463            // Do some cleaning up after the loop
    459464            $this->rewind_activities();
     
    461466
    462467        $this->in_the_loop = false;
     468
    463469        return false;
    464470    }
     
    473479     * @see bp_the_activity()
    474480     */
    475     function the_activity() {
     481    public function the_activity() {
    476482
    477483        $this->in_the_loop = true;
    478484        $this->activity    = $this->next_activity();
    479485
    480         if ( is_array( $this->activity ) )
     486        if ( is_array( $this->activity ) ) {
    481487            $this->activity = (object) $this->activity;
    482 
    483         if ( $this->current_activity == 0 ) { // loop has just started
     488        }
     489
     490        // loop has just started
     491        if ( $this->current_activity == 0 ) {
    484492
    485493            /**
     
    15051513
    15061514        // If this is a user object pass the users' email address for Gravatar so we don't have to prefetch it.
    1507         if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) )
     1515        if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) ) {
    15081516            $email = $current_activity_item->user_email;
     1517        }
    15091518
    15101519        /**
     
    17451754        global $activities_template;
    17461755
    1747         $defaults = array(
     1756        $args = wp_parse_args( $args, array(
    17481757            'no_timestamp' => false,
    1749         );
    1750 
    1751         $args = wp_parse_args( $args, $defaults );
    1752         extract( $args, EXTR_SKIP );
     1758        ) );
    17531759
    17541760        $action = $activities_template->activity->action;
     
    17631769        $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array( $action, &$activities_template->activity, $args ) );
    17641770
    1765         if ( ! empty( $action ) && ! $no_timestamp )
     1771        if ( ! empty( $action ) && empty( $r['no_timestamp'] ) ) {
    17661772            $action = bp_insert_activity_meta( $action );
     1773        }
    17671774
    17681775        /**
     
    18021809
    18031810        // Backwards compatibility if action is not being used
    1804         if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
     1811        if ( empty( $activities_template->activity->action ) && ! empty( $activities_template->activity->content ) ) {
    18051812            $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
     1813        }
    18061814
    18071815        /**
     
    18271835    global $activities_template;
    18281836
    1829     if ( !empty( $activities_template->activity->content ) )
     1837    if ( ! empty( $activities_template->activity->content ) ) {
    18301838        return true;
     1839    }
    18311840
    18321841    return false;
     
    20122021     *
    20132022     * @global object $activities_template {@link BP_Activity_Template}
    2014      * @uses wp_parse_args()
    20152023     * @uses apply_filters() To call the 'bp_get_activity_parent_content' hook.
    20162024     *
    2017      * @param array $args {
    2018      *     Array of optional arguments.
    2019      *     @deprecated bool $hide_user No longer used.
    2020      * }
     2025     * @param string $args Unused. Left over from an earlier implementation.
     2026     *
    20212027     * @return mixed False on failure, otherwise the activity parent content
    20222028     */
     
    20242030        global $activities_template;
    20252031
    2026         $defaults = array(
    2027             'hide_user' => false
    2028         );
    2029 
    2030         $r = wp_parse_args( $args, $defaults );
    2031         extract( $r, EXTR_SKIP );
     2032        // Bail if no activity on no item ID
     2033        if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) {
     2034            return false;
     2035        }
    20322036
    20332037        // Get the ID of the parent activity content
    2034         if ( !$parent_id = $activities_template->activity->item_id )
     2038        $parent_id = (int) $activities_template->activity->item_id;
     2039
     2040        // Bail if no parent content
     2041        if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
    20352042            return false;
    2036 
    2037         // Bail if no parent content
    2038         if ( empty( $activities_template->activity_parents[$parent_id] ) )
     2043        }
     2044
     2045        // Bail if no action
     2046        if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) {
    20392047            return false;
    2040 
    2041         // Bail if no action
    2042         if ( empty( $activities_template->activity_parents[$parent_id]->action ) )
    2043             return false;
     2048        }
    20442049
    20452050        // Content always includes action
    2046         $content = $activities_template->activity_parents[$parent_id]->action;
     2051        $content = $activities_template->activity_parents[ $parent_id ]->action;
    20472052
    20482053        // Maybe append activity content, if it exists
    2049         if ( ! empty( $activities_template->activity_parents[$parent_id]->content ) )
    2050             $content .= ' ' . $activities_template->activity_parents[$parent_id]->content;
     2054        if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) {
     2055            $content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content;
     2056        }
    20512057
    20522058        // Remove the time since content for backwards compatibility
     
    20892095
    20902096        // Bail if no activity on no item ID
    2091         if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) )
     2097        if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) {
    20922098            return false;
     2099        }
    20932100
    20942101        // Get the ID of the parent activity content
    2095         if ( !$parent_id = $activities_template->activity->item_id )
     2102        $parent_id = (int) $activities_template->activity->item_id;
     2103
     2104        // Bail if no parent item
     2105        if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
    20962106            return false;
    2097 
    2098         // Bail if no parent item
    2099         if ( empty( $activities_template->activity_parents[$parent_id] ) )
     2107        }
     2108
     2109        // Bail if no parent user ID
     2110        if ( empty( $activities_template->activity_parents[ $parent_id ]->user_id ) ) {
    21002111            return false;
    2101 
    2102         // Bail if no parent user ID
    2103         if ( empty( $activities_template->activity_parents[$parent_id]->user_id ) )
    2104             return false;
    2105 
    2106         $retval = $activities_template->activity_parents[$parent_id]->user_id;
     2112        }
     2113
     2114        $retval = $activities_template->activity_parents[ $parent_id ]->user_id;
    21072115
    21082116        /**
     
    21572165 * @todo deprecate $args param
    21582166 *
    2159  * @param string $args Unused. Appears to be left over from an earlier implementation.
     2167 * @param array $args See {@link bp_activity_get_comments} for description.
    21602168 */
    21612169function bp_activity_comments( $args = '' ) {
     
    21732181     *    this function can probably be streamlined or removed.
    21742182     *
    2175      * @param string $args Unused. Appears to be left over from an earlier implementation.
     2183     * @param string $args Unused. Left over from an earlier implementation.
    21762184     *
    21772185     * @global object $activities_template {@link BP_Activity_Template}
     
    21812189        global $activities_template;
    21822190
    2183         if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
     2191        if ( empty( $activities_template->activity->children ) ) {
    21842192            return false;
     2193        }
    21852194
    21862195        bp_activity_recurse_comments( $activities_template->activity );
     
    22032212            global $activities_template;
    22042213
    2205             if ( empty( $comment ) )
     2214            if ( empty( $comment ) ) {
    22062215                return false;
    2207 
    2208             if ( empty( $comment->children ) )
     2216            }
     2217
     2218            if ( empty( $comment->children ) ) {
    22092219                return false;
     2220            }
    22102221
    22112222            /**
     
    22162227             * @param string $value Opening tag for the HTML markup to use.
    22172228             */
    2218             echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>');
     2229            echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' );
    22192230            foreach ( (array) $comment->children as $comment_child ) {
     2231
    22202232                // Put the comment into the global so it's available to filters
    22212233                $activities_template->activity->current_comment = $comment_child;
     
    22432255             * @param string $value Closing tag for the HTML markup to use.
    22442256             */
    2245             echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>');
     2257            echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' );
    22462258        }
    22472259
     
    24552467        global $activities_template;
    24562468
    2457         if ( empty( $activities_template->activity->current_comment->date_recorded ) )
     2469        if ( empty( $activities_template->activity->current_comment->date_recorded ) ) {
    24582470            return false;
     2471        }
    24592472
    24602473        $date_recorded = bp_core_time_since( $activities_template->activity->current_comment->date_recorded );
     
    27242737    function bp_get_activity_comment_form_nojs_display() {
    27252738        global $activities_template;
    2726         if ( isset( $_GET['ac'] ) && $_GET['ac'] == $activities_template->activity->id . '/' )
     2739
     2740        if ( isset( $_GET['ac'] ) && ( $_GET['ac'] === ( $activities_template->activity->id . '/' ) ) ) {
    27272741            return 'style="display: block"';
     2742        }
    27282743
    27292744        return false;
     
    29983013        $class = ' activity-item';
    29993014
    3000         if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) )
     3015        if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) ) {
    30013016            $class .= ' mini';
    3002 
    3003         if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
     3017        }
     3018
     3019        if ( bp_activity_get_comment_count() && bp_activity_can_comment() ) {
    30043020            $class .= ' has-comments';
     3021        }
    30053022
    30063023        /**
     
    31493166    function bp_get_activity_latest_update( $user_id = 0 ) {
    31503167
    3151         if ( empty( $user_id ) )
     3168        if ( empty( $user_id ) ) {
    31523169            $user_id = bp_displayed_user_id();
    3153 
    3154         if ( bp_is_user_inactive( $user_id ) )
     3170        }
     3171
     3172        if ( bp_is_user_inactive( $user_id ) ) {
    31553173            return false;
    3156 
    3157         if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) )
     3174        }
     3175
     3176        if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) ) {
    31583177            return false;
     3178        }
    31593179
    31603180        /**
     
    32203240    function bp_get_activity_filter_links( $args = false ) {
    32213241
    3222         $defaults = array(
     3242        $r = wp_parse_args( $args, array(
    32233243            'style' => 'list'
    3224         );
    3225 
    3226         $r = wp_parse_args( $args, $defaults );
    3227         extract( $r, EXTR_SKIP );
     3244        ) );
    32283245
    32293246        // Define local variable
     
    32333250        $components = BP_Activity_Activity::get_recorded_components();
    32343251
    3235         if ( empty( $components ) )
     3252        if ( empty( $components ) ) {
    32363253            return false;
     3254        }
    32373255
    32383256        foreach ( (array) $components as $component ) {
    32393257
    32403258            // Skip the activity comment filter
    3241             if ( 'activity' == $component )
     3259            if ( 'activity' == $component ) {
    32423260                continue;
    3243 
    3244             if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
     3261            }
     3262
     3263            if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] ) {
    32453264                $selected = ' class="selected"';
    3246             else
    3247                 unset($selected);
     3265            } else {
     3266                $selected = '';
     3267            }
    32483268
    32493269            $component = esc_attr( $component );
    32503270
    3251             switch ( $style ) {
     3271            switch ( $r['style'] ) {
    32523272                case 'list':
    32533273                    $tag = 'li';
     
    32853305        $link = remove_query_arg( 'afilter' , $link );
    32863306
    3287         if ( isset( $_GET['afilter'] ) )
     3307        if ( isset( $_GET['afilter'] ) ) {
    32883308            $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
     3309        }
    32893310
    32903311        /**
Note: See TracChangeset for help on using the changeset viewer.