PluginProbe
bbPress / 2.1
bbPress v2.1
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-core-widgets.php

bbp-core-widgets.php in bbPress 2.1, at bbp-includes/bbp-core-widgets.php

814 lines 26.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Widgets
5 *
6 * Contains the forum list, topic list, reply list and login form widgets.
7 *
8 * @package bbPress
9 * @subpackage Widgets
10 */
11
12 // Exit if accessed directly
13 if ( !defined( 'ABSPATH' ) ) exit;
14
15 /**
16 * bbPress Login Widget
17 *
18 * Adds a widget which displays the login form
19 *
20 * @since bbPress (r2827)
21 *
22 * @uses WP_Widget
23 */
24 class BBP_Login_Widget extends WP_Widget {
25
26 /**
27 * bbPress Login Widget
28 *
29 * Registers the login widget
30 *
31 * @since bbPress (r2827)
32 *
33 * @uses apply_filters() Calls 'bbp_login_widget_options' with the
34 * widget options
35 */
36 public function __construct() {
37 $widget_ops = apply_filters( 'bbp_login_widget_options', array(
38 'classname' => 'bbp_widget_login',
39 'description' => __( 'A simple login form with optional links to sign-up and lost password pages.', 'bbpress' )
40 ) );
41
42 parent::__construct( false, __( '(bbPress) Login Widget', 'bbpress' ), $widget_ops );
43 }
44
45 /**
46 * Register the widget
47 *
48 * @since bbPress (r3389)
49 *
50 * @uses register_widget()
51 */
52 public function register_widget() {
53 register_widget( 'BBP_Login_Widget' );
54 }
55
56 /**
57 * Displays the output, the login form
58 *
59 * @since bbPress (r2827)
60 *
61 * @param mixed $args Arguments
62 * @param array $instance Instance
63 * @uses apply_filters() Calls 'bbp_login_widget_title' with the title
64 * @uses get_template_part() To get the login/logged in form
65 */
66 public function widget( $args, $instance ) {
67 extract( $args );
68
69 $title = apply_filters( 'bbp_login_widget_title', $instance['title'] );
70 $register = apply_filters( 'bbp_login_widget_register', $instance['register'] );
71 $lostpass = apply_filters( 'bbp_login_widget_lostpass', $instance['lostpass'] );
72
73 echo $before_widget;
74
75 if ( !empty( $title ) )
76 echo $before_title . $title . $after_title;
77
78 if ( !is_user_logged_in() ) : ?>
79
80 <form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form">
81 <fieldset>
82 <legend><?php _e( 'Log In', 'bbpress' ); ?></legend>
83
84 <div class="bbp-username">
85 <label for="user_login"><?php _e( 'Username', 'bbpress' ); ?>: </label>
86 <input type="text" name="log" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" id="user_login" tabindex="<?php bbp_tab_index(); ?>" />
87 </div>
88
89 <div class="bbp-password">
90 <label for="user_pass"><?php _e( 'Password', 'bbpress' ); ?>: </label>
91 <input type="password" name="pwd" value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" tabindex="<?php bbp_tab_index(); ?>" />
92 </div>
93
94 <div class="bbp-remember-me">
95 <input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ), true, true ); ?> id="rememberme" tabindex="<?php bbp_tab_index(); ?>" />
96 <label for="rememberme"><?php _e( 'Remember Me', 'bbpress' ); ?></label>
97 </div>
98
99 <div class="bbp-submit-wrapper">
100
101 <?php do_action( 'login_form' ); ?>
102
103 <button type="submit" name="user-submit" id="user-submit" tabindex="<?php bbp_tab_index(); ?>" class="button submit user-submit"><?php _e( 'Log In', 'bbpress' ); ?></button>
104
105 <?php bbp_user_login_fields(); ?>
106
107 </div>
108
109 <?php if ( !empty( $register ) || !empty( $lostpass ) ) : ?>
110
111 <div class="bbp-login-links">
112
113 <?php if ( !empty( $register ) ) : ?>
114
115 <a href="<?php echo esc_url( $register ); ?>" title="<?php _e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php _e( 'Register', 'bbpress' ); ?></a>
116
117 <?php endif; ?>
118
119 <?php if ( !empty( $lostpass ) ) : ?>
120
121 <a href="<?php echo esc_url( $lostpass ); ?>" title="<?php _e( 'Lost Password', 'bbpress' ); ?>" class="bbp-lostpass-link"><?php _e( 'Lost Password', 'bbpress' ); ?></a>
122
123 <?php endif; ?>
124
125 </div>
126
127 <?php endif; ?>
128
129 </fieldset>
130 </form>
131
132 <?php else : ?>
133
134 <div class="bbp-logged-in">
135 <a href="<?php bbp_user_profile_url( bbp_get_current_user_id() ); ?>" class="submit user-submit"><?php echo get_avatar( bbp_get_current_user_id(), '40' ); ?></a>
136 <h4><?php bbp_user_profile_link( bbp_get_current_user_id() ); ?></h4>
137
138 <?php bbp_logout_link(); ?>
139 </div>
140
141 <?php endif;
142
143 echo $after_widget;
144 }
145
146 /**
147 * Update the login widget options
148 *
149 * @since bbPress (r2827)
150 *
151 * @param array $new_instance The new instance options
152 * @param array $old_instance The old instance options
153 */
154 public function update( $new_instance, $old_instance ) {
155 $instance = $old_instance;
156 $instance['title'] = strip_tags( $new_instance['title'] );
157 $instance['register'] = esc_url( $new_instance['register'] );
158 $instance['lostpass'] = esc_url( $new_instance['lostpass'] );
159
160 return $instance;
161 }
162
163 /**
164 * Output the login widget options form
165 *
166 * @since bbPress (r2827)
167 *
168 * @param $instance Instance
169 * @uses BBP_Login_Widget::get_field_id() To output the field id
170 * @uses BBP_Login_Widget::get_field_name() To output the field name
171 */
172 public function form( $instance ) {
173
174 // Form values
175 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
176 $register = !empty( $instance['register'] ) ? esc_attr( $instance['register'] ) : '';
177 $lostpass = !empty( $instance['lostpass'] ) ? esc_attr( $instance['lostpass'] ) : '';
178
179 ?>
180
181 <p>
182 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
183 <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>
184 </p>
185
186 <p>
187 <label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php _e( 'Register URI:', 'bbpress' ); ?>
188 <input class="widefat" id="<?php echo $this->get_field_id( 'register' ); ?>" name="<?php echo $this->get_field_name( 'register' ); ?>" type="text" value="<?php echo $register; ?>" /></label>
189 </p>
190
191 <p>
192 <label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php _e( 'Lost Password URI:', 'bbpress' ); ?>
193 <input class="widefat" id="<?php echo $this->get_field_id( 'lostpass' ); ?>" name="<?php echo $this->get_field_name( 'lostpass' ); ?>" type="text" value="<?php echo $lostpass; ?>" /></label>
194 </p>
195
196 <?php
197 }
198 }
199
200 /**
201 * bbPress Views Widget
202 *
203 * Adds a widget which displays the view list
204 *
205 * @since bbPress (r3020)
206 *
207 * @uses WP_Widget
208 */
209 class BBP_Views_Widget extends WP_Widget {
210
211 /**
212 * bbPress View Widget
213 *
214 * Registers the view widget
215 *
216 * @since bbPress (r3020)
217 *
218 * @uses apply_filters() Calls 'bbp_views_widget_options' with the
219 * widget options
220 */
221 public function __construct() {
222 $widget_ops = apply_filters( 'bbp_views_widget_options', array(
223 'classname' => 'widget_display_views',
224 'description' => __( 'A list of registered optional topic views.', 'bbpress' )
225 ) );
226
227 parent::__construct( false, __( '(bbPress) Topic Views List', 'bbpress' ), $widget_ops );
228 }
229
230 /**
231 * Register the widget
232 *
233 * @since bbPress (r3389)
234 *
235 * @uses register_widget()
236 */
237 public function register_widget() {
238 register_widget( 'BBP_Views_Widget' );
239 }
240
241 /**
242 * Displays the output, the view list
243 *
244 * @since bbPress (r3020)
245 *
246 * @param mixed $args Arguments
247 * @param array $instance Instance
248 * @uses apply_filters() Calls 'bbp_view_widget_title' with the title
249 * @uses bbp_get_views() To get the views
250 * @uses bbp_view_url() To output the view url
251 * @uses bbp_view_title() To output the view title
252 */
253 public function widget( $args, $instance ) {
254
255 // Only output widget contents if views exist
256 if ( bbp_get_views() ) :
257
258 extract( $args );
259
260 $title = apply_filters( 'bbp_view_widget_title', $instance['title'] );
261
262 echo $before_widget;
263 echo $before_title . $title . $after_title; ?>
264
265 <ul>
266
267 <?php foreach ( bbp_get_views() as $view => $args ) : ?>
268
269 <li><a class="bbp-view-title" href="<?php bbp_view_url( $view ); ?>" title="<?php bbp_view_title( $view ); ?>"><?php bbp_view_title( $view ); ?></a></li>
270
271 <?php endforeach; ?>
272
273 </ul>
274
275 <?php echo $after_widget;
276
277 endif;
278 }
279
280 /**
281 * Update the view widget options
282 *
283 * @since bbPress (r3020)
284 *
285 * @param array $new_instance The new instance options
286 * @param array $old_instance The old instance options
287 */
288 public function update( $new_instance, $old_instance ) {
289 $instance = $old_instance;
290 $instance['title'] = strip_tags( $new_instance['title'] );
291
292 return $instance;
293 }
294
295 /**
296 * Output the view widget options form
297 *
298 * @since bbPress (r3020)
299 *
300 * @param $instance Instance
301 * @uses BBP_Views_Widget::get_field_id() To output the field id
302 * @uses BBP_Views_Widget::get_field_name() To output the field name
303 */
304 public function form( $instance ) {
305 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?>
306
307 <p>
308 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
309 <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; ?>" />
310 </label>
311 </p>
312
313 <?php
314 }
315 }
316
317 /**
318 * bbPress Forum Widget
319 *
320 * Adds a widget which displays the forum list
321 *
322 * @since bbPress (r2653)
323 *
324 * @uses WP_Widget
325 */
326 class BBP_Forums_Widget extends WP_Widget {
327
328 /**
329 * bbPress Forum Widget
330 *
331 * Registers the forum widget
332 *
333 * @since bbPress (r2653)
334 *
335 * @uses apply_filters() Calls 'bbp_forums_widget_options' with the
336 * widget options
337 */
338 public function __construct() {
339 $widget_ops = apply_filters( 'bbp_forums_widget_options', array(
340 'classname' => 'widget_display_forums',
341 'description' => __( 'A list of forums with an option to set the parent.', 'bbpress' )
342 ) );
343
344 parent::__construct( false, __( '(bbPress) Forums List', 'bbpress' ), $widget_ops );
345 }
346
347 /**
348 * Register the widget
349 *
350 * @since bbPress (r3389)
351 *
352 * @uses register_widget()
353 */
354 public function register_widget() {
355 register_widget( 'BBP_Forums_Widget' );
356 }
357
358 /**
359 * Displays the output, the forum list
360 *
361 * @since bbPress (r2653)
362 *
363 * @param mixed $args Arguments
364 * @param array $instance Instance
365 * @uses apply_filters() Calls 'bbp_forum_widget_title' with the title
366 * @uses get_option() To get the forums per page option
367 * @uses current_user_can() To check if the current user can read
368 * private() To resety name
369 * @uses bbp_has_forums() The main forum loop
370 * @uses bbp_forums() To check whether there are more forums available
371 * in the loop
372 * @uses bbp_the_forum() Loads up the current forum in the loop
373 * @uses bbp_forum_permalink() To display the forum permalink
374 * @uses bbp_forum_title() To display the forum title
375 */
376 public function widget( $args, $instance ) {
377 extract( $args );
378
379 $title = apply_filters( 'bbp_forum_widget_title', $instance['title'] );
380 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : '0';
381 $widget_query = new WP_Query( array(
382 'post_parent' => $parent_forum,
383 'post_type' => bbp_get_forum_post_type(),
384 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
385 'orderby' => 'menu_order',
386 'order' => 'ASC',
387 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
388 ) );
389
390 if ( $widget_query->have_posts() ) :
391
392 echo $before_widget;
393 echo $before_title . $title . $after_title; ?>
394
395 <ul>
396
397 <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?>
398
399 <li><a class="bbp-forum-title" href="<?php bbp_forum_permalink( $widget_query->post->ID ); ?>" title="<?php bbp_forum_title( $widget_query->post->ID ); ?>"><?php bbp_forum_title( $widget_query->post->ID ); ?></a></li>
400
401 <?php endwhile; ?>
402
403 </ul>
404
405 <?php echo $after_widget;
406
407 endif;
408 }
409
410 /**
411 * Update the forum widget options
412 *
413 * @since bbPress (r2653)
414 *
415 * @param array $new_instance The new instance options
416 * @param array $old_instance The old instance options
417 */
418 public function update( $new_instance, $old_instance ) {
419 $instance = $old_instance;
420 $instance['title'] = strip_tags( $new_instance['title'] );
421 $instance['parent_forum'] = $new_instance['parent_forum'];
422
423 // Force to any
424 if ( !empty( $instance['parent_forum'] ) && !is_numeric( $instance['parent_forum'] ) ) {
425 $instance['parent_forum'] = 'any';
426 }
427
428 return $instance;
429 }
430
431 /**
432 * Output the forum widget options form
433 *
434 * @since bbPress (r2653)
435 *
436 * @param $instance Instance
437 * @uses BBP_Forums_Widget::get_field_id() To output the field id
438 * @uses BBP_Forums_Widget::get_field_name() To output the field name
439 */
440 public function form( $instance ) {
441 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
442 $parent_forum = !empty( $instance['parent_forum'] ) ? esc_attr( $instance['parent_forum'] ) : '0'; ?>
443
444 <p>
445 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
446 <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; ?>" />
447 </label>
448 </p>
449
450 <p>
451 <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?>
452 <input class="widefat" id="<?php echo $this->get_field_id( 'parent_forum' ); ?>" name="<?php echo $this->get_field_name( 'parent_forum' ); ?>" type="text" value="<?php echo $parent_forum; ?>" />
453 </label>
454
455 <br />
456
457 <small><?php _e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small>
458 </p>
459
460 <?php
461 }
462 }
463
464 /**
465 * bbPress Topic Widget
466 *
467 * Adds a widget which displays the topic list
468 *
469 * @since bbPress (r2653)
470 *
471 * @uses WP_Widget
472 */
473 class BBP_Topics_Widget extends WP_Widget {
474
475 /**
476 * bbPress Topic Widget
477 *
478 * Registers the topic widget
479 *
480 * @since bbPress (r2653)
481 *
482 * @uses apply_filters() Calls 'bbp_topics_widget_options' with the
483 * widget options
484 */
485 public function __construct() {
486 $widget_ops = apply_filters( 'bbp_topics_widget_options', array(
487 'classname' => 'widget_display_topics',
488 'description' => __( 'A list of recent topics, sorted by popularity or freshness.', 'bbpress' )
489 ) );
490
491 parent::__construct( false, __( '(bbPress) Recent Topics', 'bbpress' ), $widget_ops );
492 }
493
494 /**
495 * Register the widget
496 *
497 * @since bbPress (r3389)
498 *
499 * @uses register_widget()
500 */
501 public function register_widget() {
502 register_widget( 'BBP_Topics_Widget' );
503 }
504
505 /**
506 * Displays the output, the topic list
507 *
508 * @since bbPress (r2653)
509 *
510 * @param mixed $args
511 * @param array $instance
512 * @uses apply_filters() Calls 'bbp_topic_widget_title' with the title
513 * @uses bbp_topic_permalink() To display the topic permalink
514 * @uses bbp_topic_title() To display the topic title
515 * @uses bbp_get_topic_last_active_time() To get the topic last active
516 * time
517 * @uses bbp_get_topic_id() To get the topic id
518 * @uses bbp_get_topic_reply_count() To get the topic reply count
519 */
520 public function widget( $args, $instance ) {
521
522 extract( $args );
523
524 $title = apply_filters( 'bbp_topic_widget_title', $instance['title'] );
525 $max_shown = !empty( $instance['max_shown'] ) ? (int) $instance['max_shown'] : 5;
526 $show_date = !empty( $instance['show_date'] ) ? 'on' : false;
527 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 'any';
528 $order_by = !empty( $instance['order_by'] ) ? $instance['order_by'] : false;
529
530 // How do we want to order our results?
531 switch ( $order_by ) {
532
533 // Order by most recent replies
534 case 'freshness' :
535 $topics_query = array(
536 'author' => 0,
537 'post_type' => bbp_get_topic_post_type(),
538 'post_parent' => $parent_forum,
539 'posts_per_page' => $max_shown,
540 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
541 'show_stickes' => false,
542 'meta_key' => '_bbp_last_active_time',
543 'orderby' => 'meta_value',
544 'order' => 'DESC',
545 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
546 );
547 break;
548
549 // Order by total number of replies
550 case 'popular' :
551 $topics_query = array(
552 'author' => 0,
553 'post_type' => bbp_get_topic_post_type(),
554 'post_parent' => $parent_forum,
555 'posts_per_page' => $max_shown,
556 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
557 'show_stickes' => false,
558 'meta_key' => '_bbp_reply_count',
559 'orderby' => 'meta_value',
560 'order' => 'DESC',
561 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
562 );
563 break;
564
565 // Order by which topic was created most recently
566 case 'newness' :
567 default :
568 $topics_query = array(
569 'author' => 0,
570 'post_type' => bbp_get_topic_post_type(),
571 'post_parent' => $parent_forum,
572 'posts_per_page' => $max_shown,
573 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
574 'show_stickes' => false,
575 'order' => 'DESC',
576 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
577 );
578 break;
579 }
580
581 // Query defaults
582 $widget_query = new WP_Query( $topics_query );
583
584 // Topics exist
585 if ( $widget_query->have_posts() ) :
586
587 echo $before_widget;
588 echo $before_title . $title . $after_title; ?>
589
590 <ul>
591
592 <?php while ( $widget_query->have_posts() ) :
593
594 $widget_query->the_post();
595 $topic_id = bbp_get_topic_id( $widget_query->post->ID ); ?>
596
597 <li>
598 <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>
599
600 <?php if ( 'on' == $show_date ) : ?>
601
602 <div><?php bbp_topic_last_active_time( $topic_id ); ?></div>
603
604 <?php endif; ?>
605
606 </li>
607
608 <?php endwhile; ?>
609
610 </ul>
611
612 <?php echo $after_widget;
613
614 endif;
615 }
616
617 /**
618 * Update the forum widget options
619 *
620 * @since bbPress (r2653)
621 *
622 * @param array $new_instance The new instance options
623 * @param array $old_instance The old instance options
624 */
625 public function update( $new_instance, $old_instance ) {
626 $instance = $old_instance;
627 $instance['title'] = strip_tags( $new_instance['title'] );
628 $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
629 $instance['show_date'] = strip_tags( $new_instance['show_date'] );
630 $instance['order_by'] = strip_tags( $new_instance['order_by'] );
631
632 return $instance;
633 }
634
635 /**
636 * Output the topic widget options form
637 *
638 * @since bbPress (r2653)
639 *
640 * @param $instance Instance
641 * @uses BBP_Topics_Widget::get_field_id() To output the field id
642 * @uses BBP_Topics_Widget::get_field_name() To output the field name
643 */
644 public function form( $instance ) {
645 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
646 $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
647 $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : '';
648 $order_by = !empty( $instance['order_by'] ) ? esc_attr( $instance['order_by'] ) : ''; ?>
649
650 <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>
651 <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>
652 <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>
653 <p>
654 <label for="<?php echo $this->get_field_id( 'order_by' ); ?>"><?php _e( 'Order By:', 'bbpress' ); ?></label>
655 <select name="<?php echo $this->get_field_name( 'order_by' ); ?>" id="<?php echo $this->get_field_name( 'order_by' ); ?>">
656 <option <?php selected( $order_by, 'newness' ); ?> value="newness"><?php _e( 'Newest Topics', 'bbpress' ); ?></option>
657 <option <?php selected( $order_by, 'popular' ); ?> value="popular"><?php _e( 'Popular Topics', 'bbpress' ); ?></option>
658 <option <?php selected( $order_by, 'freshness' ); ?> value="freshness"><?php _e( 'Topics With Recent Replies', 'bbpress' ); ?></option>
659 </select>
660 </p>
661
662 <?php
663 }
664 }
665
666 /**
667 * bbPress Replies Widget
668 *
669 * Adds a widget which displays the replies list
670 *
671 * @since bbPress (r2653)
672 *
673 * @uses WP_Widget
674 */
675 class BBP_Replies_Widget extends WP_Widget {
676
677 /**
678 * bbPress Replies Widget
679 *
680 * Registers the replies widget
681 *
682 * @since bbPress (r2653)
683 *
684 * @uses apply_filters() Calls 'bbp_replies_widget_options' with the
685 * widget options
686 */
687 public function __construct() {
688 $widget_ops = apply_filters( 'bbp_replies_widget_options', array(
689 'classname' => 'widget_display_replies',
690 'description' => __( 'A list of the most recent replies.', 'bbpress' )
691 ) );
692
693 parent::__construct( false, __( '(bbPress) Recent Replies', 'bbpress' ), $widget_ops );
694 }
695
696 /**
697 * Register the widget
698 *
699 * @since bbPress (r3389)
700 *
701 * @uses register_widget()
702 */
703 public function register_widget() {
704 register_widget( 'BBP_Replies_Widget' );
705 }
706
707 /**
708 * Displays the output, the replies list
709 *
710 * @since bbPress (r2653)
711 *
712 * @param mixed $args
713 * @param array $instance
714 * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title
715 * @uses bbp_get_reply_author_link() To get the reply author link
716 * @uses bbp_get_reply_author() To get the reply author name
717 * @uses bbp_get_reply_id() To get the reply id
718 * @uses bbp_get_reply_url() To get the reply url
719 * @uses bbp_get_reply_excerpt() To get the reply excerpt
720 * @uses bbp_get_reply_topic_title() To get the reply topic title
721 * @uses get_the_date() To get the date of the reply
722 * @uses get_the_time() To get the time of the reply
723 */
724 public function widget( $args, $instance ) {
725
726 extract( $args );
727
728 $title = apply_filters( 'bbp_replies_widget_title', $instance['title'] );
729 $max_shown = !empty( $instance['max_shown'] ) ? $instance['max_shown'] : '5';
730 $show_date = !empty( $instance['show_date'] ) ? 'on' : false;
731 $post_types = !empty( $instance['post_type'] ) ? array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) : bbp_get_reply_post_type();
732 $widget_query = new WP_Query( array(
733 'post_type' => $post_types,
734 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
735 'posts_per_page' => $max_shown,
736 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
737 ) );
738
739 // Get replies and display them
740 if ( $widget_query->have_posts() ) :
741
742 echo $before_widget;
743 echo $before_title . $title . $after_title; ?>
744
745 <ul>
746
747 <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?>
748
749 <li>
750 <?php
751
752 $reply_id = bbp_get_reply_id( $widget_query->post->ID );
753 $author_link = bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) );
754 $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>';
755
756 /* translators: bbpress replies widget: 1: reply author, 2: reply link, 3: reply date, 4: reply time */
757 if ( $show_date == 'on' ) {
758 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>' );
759 } else {
760 printf( _x( '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link );
761 }
762
763 ?>
764
765 </li>
766
767 <?php endwhile; ?>
768
769 </ul>
770
771 <?php echo $after_widget;
772
773 endif;
774 }
775
776 /**
777 * Update the forum widget options
778 *
779 * @since bbPress (r2653)
780 *
781 * @param array $new_instance The new instance options
782 * @param array $old_instance The old instance options
783 */
784 public function update( $new_instance, $old_instance ) {
785 $instance = $old_instance;
786 $instance['title'] = strip_tags( $new_instance['title'] );
787 $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
788 $instance['show_date'] = strip_tags( $new_instance['show_date'] );
789
790 return $instance;
791 }
792
793 /**
794 * Output the reply widget options form
795 *
796 * @since bbPress (r2653)
797 *
798 * @param $instance Instance
799 * @uses BBP_Replies_Widget::get_field_id() To output the field id
800 * @uses BBP_Replies_Widget::get_field_name() To output the field name
801 */
802 public function form( $instance ) {
803 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
804 $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
805 $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; ?>
806
807 <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>
808 <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>
809 <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>
810
811 <?php
812 }
813 }
814