Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/11/2014 04:56:19 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Code clean-up in bp-messages-template.php.

File:
1 edited

Legend:

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

    r8790 r8791  
    193193         */
    194194        function has_threads() {
    195                 if ( $this->thread_count )
     195                if ( $this->thread_count ) {
    196196                        return true;
     197                }
    197198
    198199                return false;
     
    541542         */
    542543        function bp_get_message_thread_delete_link() {
    543                 global $messages_template, $bp;
    544                 return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . $bp->messages->slug . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ) );
     544                global $messages_template;
     545                return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ) );
    545546        }
    546547
     
    561562                $class = false;
    562563
    563                 if ( $messages_template->current_thread % 2 == 1 )
     564                if ( $messages_template->current_thread % 2 == 1 ) {
    564565                        $class .= 'alt';
     566                }
    565567
    566568                return apply_filters( 'bp_get_message_css_class', trim( $class ) );
     
    575577        global $messages_template;
    576578
    577         if ( $messages_template->thread->unread_count )
    578                 return true;
    579 
    580         return false;
     579        $retval = ! empty( $messages_template->thread->unread_count )
     580                ? true
     581                : false;
     582
     583        return apply_filters( 'bp_message_thread_has_unread', $retval );
    581584}
    582585
     
    595598                global $messages_template;
    596599
    597                 if ( (int) $messages_template->thread->unread_count )
    598                         return apply_filters( 'bp_get_message_thread_unread_count', $messages_template->thread->unread_count );
    599 
    600                 return false;
     600                $count = ! empty( $messages_template->thread->unread_count )
     601                        ? (int) $messages_template->thread->unread_count
     602                        : false;
     603
     604                return apply_filters( 'bp_get_message_thread_unread_count', $count );
    601605        }
    602606
     
    713717
    714718        $start_num = intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1;
    715         $from_num = bp_core_number_format( $start_num );
    716         $to_num = bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ) );
    717         $total = bp_core_number_format( $messages_template->total_thread_count );
     719        $from_num  = bp_core_number_format( $start_num );
     720        $to_num    = bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ) );
     721        $total     = bp_core_number_format( $messages_template->total_thread_count );
    718722
    719723        echo sprintf( _n( 'Viewing 1 message', 'Viewing %1$s - %2$s of %3$s messages', $total, 'buddypress' ), $from_num, $to_num, number_format_i18n( $total ) );
     
    787791         */
    788792        function bp_get_messages_subject_value() {
    789                 $subject = '';
    790                 if ( !empty( $_POST['subject'] ) )
    791                         $subject = $_POST['subject'];
     793                $subject = ! empty( $_POST['subject'] )
     794                        ? $_POST['subject']
     795                        : '';
    792796
    793797                return apply_filters( 'bp_get_messages_subject_value', $subject );
     
    809813         */
    810814        function bp_get_messages_content_value() {
    811                 $content = '';
    812                 if ( !empty( $_POST['content'] ) )
    813                         $content = $_POST['content'];
     815
     816                $content = !empty( $_POST['content'] )
     817                        ? $_POST['content']
     818                        : '';
    814819
    815820                return apply_filters( 'bp_get_messages_content_value', $content );
     
    851856        global $messages_template;
    852857
    853         if ( $messages_template->thread->is_active )
    854                 return true;
    855 
    856         return false;
     858        $retval = ! empty( $messages_template->thread->is_active )
     859                ? true
     860                : false;
     861
     862        return apply_filters( 'bp_messages_is_active_notice', $retval );
    857863}
    858864
     
    881887        function bp_get_message_is_active_notice() {
    882888
    883                 $string = '';
    884                 if ( bp_messages_is_active_notice() )
    885                         $string = __( 'Currently Active', 'buddypress' );
     889                $string = bp_messages_is_active_notice()
     890                        ? __( 'Currently Active', 'buddypress' )
     891                        : '';
    886892
    887893                return apply_filters( 'bp_get_message_is_active_notice', $string );
     
    917923        function bp_get_message_notice_post_date() {
    918924                global $messages_template;
    919                 return apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime($messages_template->thread->date_sent) ) );
     925                return apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime( $messages_template->thread->date_sent ) ) );
    920926        }
    921927
     
    964970         */
    965971        function bp_get_message_notice_delete_link() {
    966                 global $messages_template, $bp;
    967 
    968                 return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( bp_loggedin_user_domain() . $bp->messages->slug . '/notices/delete/' . $messages_template->thread->id, 'messages_delete_thread' ) );
     972                global $messages_template;
     973
     974                return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/delete/' . $messages_template->thread->id, 'messages_delete_thread' ) );
    969975        }
    970976
     
    981987         */
    982988        function bp_get_message_activate_deactivate_link() {
    983                 global $messages_template, $bp;
    984 
    985                 if ( 1 == (int) $messages_template->thread->is_active ) {
    986                         $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . $bp->messages->slug . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
     989                global $messages_template;
     990
     991                if ( 1 === (int) $messages_template->thread->is_active ) {
     992                        $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
    987993                } else {
    988                         $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . $bp->messages->slug . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
     994                        $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
    989995                }
    990996                return apply_filters( 'bp_get_message_activate_deactivate_link', $link );
     
    10051011                global $messages_template;
    10061012
    1007                 if ( 1 == (int) $messages_template->thread->is_active  ) {
     1013                if ( 1 === (int) $messages_template->thread->is_active  ) {
    10081014                        $text = __('Deactivate', 'buddypress');
    10091015                } else {
     
    10311037         */
    10321038        function bp_get_messages_slug() {
    1033                 global $bp;
    1034                 return apply_filters( 'bp_get_messages_slug', $bp->messages->slug );
     1039                return apply_filters( 'bp_get_messages_slug', buddypress()->messages->slug );
    10351040        }
    10361041
     
    10411046        $notice = BP_Messages_Notice::get_active();
    10421047
    1043         if ( empty( $notice ) )
     1048        if ( empty( $notice ) ) {
    10441049                return false;
     1050        }
    10451051
    10461052        $closed_notices = bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true );
    10471053
    1048         if ( !$closed_notices )
     1054        if ( empty( $closed_notices ) ) {
    10491055                $closed_notices = array();
    1050 
    1051         if ( is_array($closed_notices) ) {
     1056        }
     1057
     1058        if ( is_array( $closed_notices ) ) {
    10521059                if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) {
    10531060                        ?>
    1054                         <div id="message" class="info notice" rel="n-<?php echo $notice->id ?>">
     1061                        <div id="message" class="info notice" rel="n-<?php echo esc_attr( $notice->id ); ?>">
    10551062                                <p>
    10561063                                        <strong><?php echo stripslashes( wp_filter_kses( $notice->subject ) ) ?></strong><br />
     
    10771084        function bp_get_send_private_message_link() {
    10781085
    1079                 if ( bp_is_my_profile() || !is_user_logged_in() )
     1086                if ( bp_is_my_profile() || ! is_user_logged_in() ) {
    10801087                        return false;
     1088                }
    10811089
    10821090                return apply_filters( 'bp_get_send_private_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( bp_displayed_user_id() ) ) );
     
    11371145         */
    11381146        function bp_get_message_loading_image_src() {
    1139                 global $bp;
    1140                 return apply_filters( 'bp_get_message_loading_image_src', $bp->messages->image_base . '/ajax-loader.gif' );
     1147                return apply_filters( 'bp_get_message_loading_image_src', buddypress()->messages->image_base . '/ajax-loader.gif' );
    11411148        }
    11421149
     
    11481155
    11491156        foreach ( $recipients as $recipient ) {
    1150                 $user_id = bp_is_username_compatibility_mode() ? bp_core_get_userid( $recipient ) : bp_core_get_userid_from_nicename( $recipient );
    1151 
    1152                 if ( $user_id ) : ?>
     1157
     1158                $user_id = bp_is_username_compatibility_mode()
     1159                        ? bp_core_get_userid( $recipient )
     1160                        : bp_core_get_userid_from_nicename( $recipient );
     1161
     1162                if ( ! empty( $user_id ) ) : ?>
    11531163
    11541164                        <li id="un-<?php echo esc_attr( $recipient ); ?>" class="friend-tab">
     
    12831293         */
    12841294        function has_messages() {
    1285                 if ( $this->message_count )
     1295                if ( $this->message_count ) {
    12861296                        return true;
     1297                }
    12871298
    12881299                return false;
     
    13491360
    13501361                // loop has just started
    1351                 if ( 0 == $this->current_message )
    1352                         do_action('thread_loop_start');
     1362                if ( 0 == $this->current_message ) {
     1363                        do_action( 'thread_loop_start' );
     1364                }
    13531365        }
    13541366}
     
    13691381        global $thread_template;
    13701382
    1371         $defaults = array(
     1383        $r = bp_parse_args( $args, array(
    13721384                'thread_id' => false,
    13731385                'order'     => 'ASC'
    1374         );
    1375 
    1376         $r = wp_parse_args( $args, $defaults );
    1377         extract( $r, EXTR_SKIP );
    1378 
    1379         if ( empty( $thread_id ) && bp_is_messages_component() && bp_is_current_action( 'view' ) )
    1380                 $thread_id = (int) bp_action_variable( 0 );
    1381 
    1382         $thread_template = new BP_Messages_Thread_Template( $thread_id, $order );
     1386        ), 'thread_has_messages' );
     1387
     1388        if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) {
     1389                $r['thread_id'] = (int) bp_action_variable( 0 );
     1390        }
     1391
     1392        $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'] );
     1393
    13831394        return $thread_template->has_messages();
    13841395}
     
    14721483                $recipient_links = array();
    14731484
    1474                 if ( count( $thread_template->thread->recipients ) >= 5 )
    1475                         return apply_filters( 'bp_get_the_thread_recipients', sprintf( __( '%d Recipients', 'buddypress' ), count($thread_template->thread->recipients) ) );
     1485                if ( count( $thread_template->thread->recipients ) >= 5 ) {
     1486                        return apply_filters( 'bp_get_the_thread_recipients', sprintf( __( '%d Recipients', 'buddypress' ), count( $thread_template->thread->recipients ) ) );
     1487                }
    14761488
    14771489                foreach( (array) $thread_template->thread->recipients as $recipient ) {
     
    15081520                global $thread_template;
    15091521
    1510                 $thread_message_id = isset( $thread_template->message->id ) ? (int) $thread_template->message->id : null;
     1522                $thread_message_id = isset( $thread_template->message->id )
     1523                        ? (int) $thread_template->message->id
     1524                        : null;
     1525
    15111526                return apply_filters( 'bp_get_the_thread_message_id', $thread_message_id );
    15121527        }
     
    16201635                global $thread_template;
    16211636
    1622                 $defaults = array(
     1637                $r = bp_parse_args( $args, array(
    16231638                        'type'   => 'thumb',
    16241639                        'width'  => false,
    16251640                        'height' => false,
    1626                 );
    1627 
    1628                 $r = wp_parse_args( $args, $defaults );
    1629                 extract( $r, EXTR_SKIP );
    1630 
    1631                 return apply_filters( 'bp_get_the_thread_message_sender_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $thread_template->message->sender_id, 'type' => $type, 'width' => $width, 'height' => $height, 'alt' => bp_core_get_user_displayname( $thread_template->message->sender_id ) ) ) );
     1641                ) );
     1642
     1643                return apply_filters( 'bp_get_the_thread_message_sender_avatar_thumb', bp_core_fetch_avatar( array(
     1644                        'item_id' => $thread_template->message->sender_id,
     1645                        'type'    => $r['type'],
     1646                        'width'   => $r['width'],
     1647                        'height'  => $r['height'],
     1648                        'alt'     => bp_core_get_user_displayname( $thread_template->message->sender_id )
     1649                ) ) );
    16321650        }
    16331651
     
    16651683                $display_name = bp_core_get_user_displayname( $thread_template->message->sender_id );
    16661684
    1667                 if ( empty( $display_name ) )
     1685                if ( empty( $display_name ) ) {
    16681686                        $display_name = __( 'Deleted User', 'buddypress' );
     1687                }
    16691688
    16701689                return apply_filters( 'bp_get_the_thread_message_sender_name', $display_name );
     
    16831702         */
    16841703        function bp_get_the_thread_delete_link() {
    1685                 global $bp;
    1686 
    1687                 return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( bp_loggedin_user_domain() . $bp->messages->slug . '/inbox/delete/' . bp_get_the_thread_id(), 'messages_delete_thread' ) );
     1704                return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox/delete/' . bp_get_the_thread_id(), 'messages_delete_thread' ) );
    16881705        }
    16891706
Note: See TracChangeset for help on using the changeset viewer.