Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/24/2012 09:28:14 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Statistics:

  • Add widget and shortcode for forum statistics.
  • Props MZAWeb.
  • Fixes #2052.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/common/widgets.php

    r4495 r4510  
    575575                    'order'          => 'DESC',
    576576                    'meta_query'     => array( bbp_exclude_forum_ids( 'meta_query' ) )
    577                 );         
     577                );
    578578                break;
    579579
     
    590590                    'order'          => 'DESC',
    591591                    'meta_query'     => array( bbp_exclude_forum_ids( 'meta_query' ) )
    592                 );         
     592                );
    593593                break;
    594594        }
    595        
     595
    596596        // Note: private and hidden forums will be excluded via the
    597597        // bbp_pre_get_posts_exclude_forums filter and function.
     
    599599
    600600        // Topics exist
    601         if ( $widget_query->have_posts() ) : 
    602            
     601        if ( $widget_query->have_posts() ) :
     602
    603603            echo $args['before_widget'];
    604604            echo $args['before_title'] . $title . $args['after_title']; ?>
     
    609609
    610610                    $widget_query->the_post();
    611                     $topic_id    = bbp_get_topic_id( $widget_query->post->ID ); 
     611                    $topic_id    = bbp_get_topic_id( $widget_query->post->ID );
    612612                    $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) ); ?>
    613613
     
    691691
    692692        <?php
     693    }
     694}
     695
     696/**
     697 * bbPress Stats Widget
     698 *
     699 * Adds a widget which displays the forum statistics
     700 *
     701 * @since bbPress (r4509)
     702 *
     703 * @uses WP_Widget
     704 */
     705class BBP_Stats_Widget extends WP_Widget {
     706
     707    /**
     708     * bbPress Stats Widget
     709     *
     710     * Registers the stats widget
     711     *
     712     * @since bbPress (r4509)
     713     *
     714     * @uses  apply_filters() Calls 'bbp_stats_widget_options' with the
     715     *        widget options
     716     */
     717    public function __construct() {
     718        $widget_ops = apply_filters( 'bbp_stats_widget_options', array(
     719            'classname'   => 'widget_display_stats',
     720            'description' => __( 'Some statistics from your forum.', 'bbpress' )
     721        ) );
     722
     723        parent::__construct( false, __( '(bbPress) Statistics', 'bbpress' ), $widget_ops );
     724    }
     725
     726    /**
     727     * Register the widget
     728     *
     729     * @since bbPress (r4509)
     730     *
     731     * @uses register_widget()
     732     */
     733    public static function register_widget() {
     734        register_widget( 'BBP_Stats_Widget' );
     735    }
     736
     737    /**
     738     * Displays the output, the statistics
     739     *
     740     * @since bbPress (r4509)
     741     *
     742     * @param mixed $args     Arguments
     743     * @param array $instance Instance
     744     *
     745     * @uses apply_filters() Calls 'bbp_stats_widget_title' with the title
     746     * @uses bbp_get_template_part() To get the content-forum-statistics template
     747     */
     748    public function widget( $args, $instance ) {
     749
     750        $title = apply_filters( 'widget_title',           $instance['title'], $instance, $this->id_base );
     751        $title = apply_filters( 'bbp_stats_widget_title', $instance['title'], $instance, $this->id_base );
     752
     753        echo $args['before_widget'];
     754        echo $args['before_title'] . $title . $args['after_title'];
     755
     756        bbp_get_template_part( 'content', 'statistics' );
     757
     758        echo $args['after_widget'];
     759    }
     760
     761    /**
     762     * Update the stats widget options
     763     *
     764     * @since bbPress (r4509)
     765     *
     766     * @param array $new_instance The new instance options
     767     * @param array $old_instance The old instance options
     768     *
     769     * @return array
     770     */
     771    public function update( $new_instance, $old_instance ) {
     772        $instance          = $old_instance;
     773        $instance['title'] = strip_tags( $new_instance['title'] );
     774
     775        return $instance;
     776    }
     777
     778    /**
     779     * Output the stats widget options form
     780     *
     781     * @since bbPress (r4509)
     782     *
     783     * @param $instance
     784     *
     785     * @return string|void
     786     */
     787    public function form( $instance ) {
     788        $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?>
     789
     790        <p>
     791            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
     792                <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
     793                   name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
     794            </label>
     795        </p>
     796
     797    <?php
    693798    }
    694799}
Note: See TracChangeset for help on using the changeset viewer.