Skip to:
Content

bbPress.org

Changeset 4510


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

Statistics:

  • Add widget and shortcode for forum statistics.
  • Props MZAWeb.
  • Fixes #2052.
Location:
trunk
Files:
1 added
4 edited

Legend:

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

    r4333 r4510  
    8585                        'bbp-register'         => array( $this, 'display_register'      ), // Register
    8686                        'bbp-lost-pass'        => array( $this, 'display_lost_pass'     ), // Lost Password
     87
     88                        /** Others *******************************************************/
     89
     90                        'bbp-stats'            => array( $this, 'display_stats'         ), // Stats
    8791                ) );
    8892        }
     
    679683
    680684        /**
     685         * Display forum statistics
     686         *
     687         * @since bbPress (r4509)
     688         *
     689         * @return shring
     690         */
     691        public function display_stats() {
     692
     693                // Unset globals
     694                $this->unset_globals();
     695
     696                // Start output buffer
     697                $this->start();
     698
     699                // Output statistics
     700                bbp_get_template_part( 'content', 'statistics' );
     701
     702                // Return contents of output buffer
     703                return $this->end();
     704        }
     705
     706        /**
    681707         * Display a breadcrumb
    682708         *
  • 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}
  • trunk/includes/core/actions.php

    r4404 r4510  
    142142add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget',  'register_widget' ), 10 );
    143143add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
     144add_action( 'bbp_widgets_init', array( 'BBP_Stats_Widget',   'register_widget' ), 10 );
    144145
    145146// Template - Head, foot, errors and messages
  • trunk/templates/default/extras/page-forum-statistics.php

    r4497 r4510  
    77 * @subpackage Theme
    88 */
    9 
    10 // Get the statistics and extract them for later use in this template
    11 $stats = bbp_get_statistics();
    129
    1310get_header(); ?>
     
    2724                                <div id="bbpress-forums">
    2825
    29                                         <dl role="main">
    30 
    31                                                 <?php do_action( 'bbp_before_statistics' ); ?>
    32 
    33                                                 <dt><?php _e( 'Registered Users', 'bbpress' ); ?></dt>
    34                                                 <dd>
    35                                                         <strong><?php echo $stats['user_count']; ?></strong>
    36                                                 </dd>
    37 
    38                                                 <dt><?php _e( 'Forums', 'bbpress' ); ?></dt>
    39                                                 <dd>
    40                                                         <strong><?php echo $stats['forum_count']; ?></strong>
    41                                                 </dd>
    42 
    43                                                 <dt><?php _e( 'Topics', 'bbpress' ); ?></dt>
    44                                                 <dd>
    45                                                         <strong><?php echo $stats['topic_count']; ?></strong>
    46                                                 </dd>
    47 
    48                                                 <dt><?php _e( 'Replies', 'bbpress' ); ?></dt>
    49                                                 <dd>
    50                                                         <strong><?php echo $stats['reply_count']; ?></strong>
    51                                                 </dd>
    52 
    53                                                 <dt><?php _e( 'Topic Tags', 'bbpress' ); ?></dt>
    54                                                 <dd>
    55                                                         <strong><?php echo $stats['topic_tag_count']; ?></strong>
    56                                                 </dd>
    57 
    58                                                 <?php if ( !empty( $stats['empty_topic_tag_count'] ) ) : ?>
    59 
    60                                                         <dt><?php _e( 'Empty Topic Tags', 'bbpress' ); ?></dt>
    61                                                         <dd>
    62                                                                 <strong><?php echo $stats['empty_topic_tag_count']; ?></strong>
    63                                                         </dd>
    64 
    65                                                 <?php endif; ?>
    66 
    67                                                 <?php if ( !empty( $stats['topic_count_hidden'] ) ) : ?>
    68 
    69                                                         <dt><?php _e( 'Hidden Topics', 'bbpress' ); ?></dt>
    70                                                         <dd>
    71                                                                 <strong>
    72                                                                         <abbr title="<?php echo esc_attr( $stats['hidden_topic_title'] ); ?>"><?php echo $stats['topic_count_hidden']; ?></abbr>
    73                                                                 </strong>
    74                                                         </dd>
    75 
    76                                                 <?php endif; ?>
    77 
    78                                                 <?php if ( !empty( $stats['reply_count_hidden'] ) ) : ?>
    79 
    80                                                         <dt><?php _e( 'Hidden Replies', 'bbpress' ); ?></dt>
    81                                                         <dd>
    82                                                                 <strong>
    83                                                                         <abbr title="<?php echo esc_attr( $stats['hidden_reply_title'] ); ?>"><?php echo $stats['reply_count_hidden']; ?></abbr>
    84                                                                 </strong>
    85                                                         </dd>
    86 
    87                                                 <?php endif; ?>
    88 
    89                                                 <?php do_action( 'bbp_after_statistics' ); ?>
    90 
    91                                         </dl>
     26                                        <?php bbp_get_template_part( 'content', 'statistics' ); ?>
    9227
    9328                                        <?php do_action( 'bbp_before_popular_topics' ); ?>
     
    11954        <?php do_action( 'bbp_after_main_content' ); ?>
    12055
    121 <?php unset( $stats ); ?>
    122 
    12356<?php get_sidebar(); ?>
    12457
Note: See TracChangeset for help on using the changeset viewer.