Skip to:
Content

bbPress.org

Changeset 4124


Ignore:
Timestamp:
07/26/2012 02:09:59 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Topic and Reply Widgets:

  • Add 'show_user' option, to toggle display of user and Avatar.
  • Update reply widget to use time_since.
  • Fixes #1903.
  • Props jaredatch.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-core-widgets.php

    r4121 r4124  
    527527        $max_shown    = !empty( $instance['max_shown']    ) ? (int) $instance['max_shown'] : 5;
    528528        $show_date    = !empty( $instance['show_date']    ) ? 'on'                         : false;
     529        $show_user    = !empty( $instance['show_user']    ) ? 'on'                         : false;
    529530        $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum']    : 'any';
    530531        $order_by     = !empty( $instance['order_by']     ) ? $instance['order_by']        : false;
     
    596597
    597598                    $widget_query->the_post();
    598                     $topic_id = bbp_get_topic_id( $widget_query->post->ID ); ?>
     599                    $topic_id    = bbp_get_topic_id( $widget_query->post->ID );
     600                    $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) ); ?>
    599601
    600602                    <li>
    601603                        <a class="bbp-forum-title" href="<?php bbp_topic_permalink( $topic_id ); ?>" title="<?php bbp_topic_title( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a>
     604
     605                        <?php if ( 'on' == $show_user ) : ?>
     606
     607                            <?php printf( _x( 'by %1$s', 'widgets', 'bbpress' ), '<span class="topic-author">' . $author_link . '</span>' ); ?>
     608
     609                        <?php endif; ?>
    602610
    603611                        <?php if ( 'on' == $show_date ) : ?>
     
    631639        $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
    632640        $instance['show_date'] = strip_tags( $new_instance['show_date'] );
     641        $instance['show_user'] = strip_tags( $new_instance['show_user'] );
    633642        $instance['order_by']  = strip_tags( $new_instance['order_by']  );
    634643
     
    649658        $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
    650659        $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : '';
     660        $show_user = !empty( $instance['show_user'] ) ? esc_attr( $instance['show_user'] ) : '';
    651661        $order_by  = !empty( $instance['order_by']  ) ? esc_attr( $instance['order_by']  ) : ''; ?>
    652662
     
    654664        <p><label for="<?php echo $this->get_field_id( 'max_shown' ); ?>"><?php _e( 'Maximum topics to show:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_shown' ); ?>" name="<?php echo $this->get_field_name( 'max_shown' ); ?>" type="text" value="<?php echo $max_shown; ?>" /></label></p>
    655665        <p><label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show post date:',         'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" <?php checked( 'on', $show_date ); ?> /></label></p>
     666        <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show topic author:',      'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $show_user ); ?> /></label></p>
     667
    656668        <p>
    657669            <label for="<?php echo $this->get_field_id( 'order_by' ); ?>"><?php _e( 'Order By:',        'bbpress' ); ?></label>
     
    730742
    731743        $title      = apply_filters( 'bbp_replies_widget_title', $instance['title'] );
    732         $max_shown  = !empty( $instance['max_shown'] ) ? $instance['max_shown']    : '5';
    733         $show_date  = !empty( $instance['show_date'] ) ? 'on'                      : false;
     744        $max_shown  = !empty( $instance['max_shown'] ) ? $instance['max_shown'] : '5';
     745        $show_date  = !empty( $instance['show_date'] ) ? 'on'                   : false;
     746        $show_user  = !empty( $instance['show_user'] ) ? 'on'                   : false;
    734747        $post_types = !empty( $instance['post_type'] ) ? array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) : bbp_get_reply_post_type();
    735748
     
    754767
    755768                    <li>
     769
    756770                        <?php
    757771
     
    760774                        $reply_link  = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url( $reply_id ) ) . '" title="' . bbp_get_reply_excerpt( $reply_id, 50 ) . '">' . bbp_get_reply_topic_title( $reply_id ) . '</a>';
    761775
    762                         /* translators: bbpress replies widget: 1: reply author, 2: reply link, 3: reply date, 4: reply time */
    763                         if ( $show_date == 'on' ) {
    764                             printf( _x( '%1$s on %2$s %3$s, %4$s', 'widgets', 'bbpress' ), $author_link, $reply_link, '<div>' . get_the_date(), get_the_time() . '</div>' );
    765                         } else {
    766                             printf( _x( '%1$s on %2$s',            'widgets', 'bbpress' ), $author_link, $reply_link );
    767                         }
     776                        // Reply author, link, and timestamp
     777                        if ( ( 'on' == $show_date ) && ( 'on' == $show_user ) ) :
     778
     779                            // translators: 1: reply author, 2: reply link, 3: reply timestamp
     780                            printf( _x( '%1$s on %2$s %3$s', 'widgets', 'bbpress' ), $author_link, $reply_link, '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>' );
     781
     782                        // Reply link and timestamp
     783                        elseif ( $show_date == 'on' ) :
     784
     785                            // translators: 1: reply link, 2: reply timestamp
     786                            printf( _x( '%1$s %2$s',         'widgets', 'bbpress' ), $reply_link,  '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>'              );
     787
     788                        // Reply author and title
     789                        elseif ( $show_user == 'on' ) :
     790
     791                            // translators: 1: reply author, 2: reply link
     792                            printf( _x( '%1$s on %2$s',      'widgets', 'bbpress' ), $author_link, $reply_link                                                                 );
     793
     794                        // Only the reply title
     795                        else :
     796
     797                            // translators: 1: reply link
     798                            printf( _x( '%1$s',              'widgets', 'bbpress' ), $reply_link                                                                               );
     799
     800                        endif;
    768801
    769802                        ?>
     
    793826        $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
    794827        $instance['show_date'] = strip_tags( $new_instance['show_date'] );
     828        $instance['show_user'] = strip_tags( $new_instance['show_user'] );
    795829
    796830        return $instance;
     
    809843        $title     = !empty( $instance['title']     ) ? esc_attr( $instance['title']     ) : '';
    810844        $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
    811         $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; ?>
     845        $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : '';
     846        $show_user = !empty( $instance['show_user'] ) ? esc_attr( $instance['show_user'] ) : ''; ?>
    812847
    813848        <p><label for="<?php echo $this->get_field_id( 'title'     ); ?>"><?php _e( 'Title:',                   'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title'     ); ?>" name="<?php echo $this->get_field_name( 'title'     ); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
    814849        <p><label for="<?php echo $this->get_field_id( 'max_shown' ); ?>"><?php _e( 'Maximum replies to show:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_shown' ); ?>" name="<?php echo $this->get_field_name( 'max_shown' ); ?>" type="text" value="<?php echo $max_shown; ?>" /></label></p>
    815850        <p><label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show post date:',          'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" <?php checked( 'on', $show_date ); ?> /></label></p>
     851        <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show reply author:',       'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $show_user ); ?> /></label></p>
    816852
    817853        <?php
Note: See TracChangeset for help on using the changeset viewer.