PluginProbe
bbPress / 2.0.2
bbPress v2.0.2
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.0.2, at bbp-includes/bbp-core-widgets.php

818 lines 25.4 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 * Register the widget
28 *
29 * @since bbPress (r3389)
30 *
31 * @uses register_widget()
32 */
33 function register_widget() {
34 register_widget( 'BBP_Login_Widget' );
35 }
36
37 /**
38 * bbPress Login Widget
39 *
40 * Registers the login widget
41 *
42 * @since bbPress (r2827)
43 *
44 * @uses apply_filters() Calls 'bbp_login_widget_options' with the
45 * widget options
46 */
47 function BBP_Login_Widget() {
48 $widget_ops = apply_filters( 'bbp_login_widget_options', array(
49 'classname' => 'bbp_widget_login',
50 'description' => __( 'The login widget.', 'bbpress' )
51 ) );
52
53 parent::WP_Widget( false, __( 'bbPress Login Widget', 'bbpress' ), $widget_ops );
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 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 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 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 * Register the widget
213 *
214 * @since bbPress (r3389)
215 *
216 * @uses register_widget()
217 */
218 function register_widget() {
219 register_widget( 'BBP_Views_Widget' );
220 }
221
222 /**
223 * bbPress View Widget
224 *
225 * Registers the view widget
226 *
227 * @since bbPress (r3020)
228 *
229 * @uses apply_filters() Calls 'bbp_views_widget_options' with the
230 * widget options
231 */
232 function BBP_Views_Widget() {
233 $widget_ops = apply_filters( 'bbp_views_widget_options', array(
234 'classname' => 'widget_display_views',
235 'description' => __( 'A list of views.', 'bbpress' )
236 ) );
237
238 parent::WP_Widget( false, __( 'bbPress View List', 'bbpress' ), $widget_ops );
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 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 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 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 * Register the widget
330 *
331 * @since bbPress (r3389)
332 *
333 * @uses register_widget()
334 */
335 function register_widget() {
336 register_widget( 'BBP_Forums_Widget' );
337 }
338
339 /**
340 * bbPress Forum Widget
341 *
342 * Registers the forum widget
343 *
344 * @since bbPress (r2653)
345 *
346 * @uses apply_filters() Calls 'bbp_forums_widget_options' with the
347 * widget options
348 */
349 function BBP_Forums_Widget() {
350 $widget_ops = apply_filters( 'bbp_forums_widget_options', array(
351 'classname' => 'widget_display_forums',
352 'description' => __( 'A list of forums.', 'bbpress' )
353 ) );
354
355 parent::WP_Widget( false, __( 'bbPress Forum List', 'bbpress' ), $widget_ops );
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_set_query_name() To set the query name to 'bbp_widget'
370 * @uses bbp_reset_query_name() To reset the query name
371 * @uses bbp_has_forums() The main forum loop
372 * @uses bbp_forums() To check whether there are more forums available
373 * in the loop
374 * @uses bbp_the_forum() Loads up the current forum in the loop
375 * @uses bbp_forum_permalink() To display the forum permalink
376 * @uses bbp_forum_title() To display the forum title
377 */
378 function widget( $args, $instance ) {
379 extract( $args );
380
381 $title = apply_filters( 'bbp_forum_widget_title', $instance['title'] );
382 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : '0';
383
384 $forums_query = array(
385 'post_parent' => $parent_forum,
386 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
387 'orderby' => 'menu_order',
388 'order' => 'ASC'
389 );
390
391 bbp_set_query_name( 'bbp_widget' );
392
393 if ( bbp_has_forums( $forums_query ) ) :
394
395 echo $before_widget;
396 echo $before_title . $title . $after_title; ?>
397
398 <ul>
399
400 <?php while ( bbp_forums() ) : bbp_the_forum(); ?>
401
402 <li><a class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>" title="<?php bbp_forum_title(); ?>"><?php bbp_forum_title(); ?></a></li>
403
404 <?php endwhile; ?>
405
406 </ul>
407
408 <?php echo $after_widget;
409
410 endif;
411
412 bbp_reset_query_name();
413 }
414
415 /**
416 * Update the forum widget options
417 *
418 * @since bbPress (r2653)
419 *
420 * @param array $new_instance The new instance options
421 * @param array $old_instance The old instance options
422 */
423 function update( $new_instance, $old_instance ) {
424 $instance = $old_instance;
425 $instance['title'] = strip_tags( $new_instance['title'] );
426 $instance['parent_forum'] = $new_instance['parent_forum'];
427
428 // Force to any
429 if ( !empty( $instance['parent_forum'] ) && !is_numeric( $instance['parent_forum'] ) ) {
430 $instance['parent_forum'] = 'any';
431 }
432
433 return $instance;
434 }
435
436 /**
437 * Output the forum widget options form
438 *
439 * @since bbPress (r2653)
440 *
441 * @param $instance Instance
442 * @uses BBP_Forums_Widget::get_field_id() To output the field id
443 * @uses BBP_Forums_Widget::get_field_name() To output the field name
444 */
445 function form( $instance ) {
446 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
447 $parent_forum = !empty( $instance['parent_forum'] ) ? esc_attr( $instance['parent_forum'] ) : '0'; ?>
448
449 <p>
450 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
451 <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; ?>" />
452 </label>
453 </p>
454
455 <p>
456 <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?>
457 <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; ?>" />
458 </label>
459
460 <br />
461
462 <small><?php _e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small>
463 </p>
464
465 <?php
466 }
467 }
468
469 /**
470 * bbPress Topic Widget
471 *
472 * Adds a widget which displays the topic list
473 *
474 * @since bbPress (r2653)
475 *
476 * @uses WP_Widget
477 */
478 class BBP_Topics_Widget extends WP_Widget {
479
480 /**
481 * Register the widget
482 *
483 * @since bbPress (r3389)
484 *
485 * @uses register_widget()
486 */
487 function register_widget() {
488 register_widget( 'BBP_Topics_Widget' );
489 }
490
491 /**
492 * bbPress Topic Widget
493 *
494 * Registers the topic widget
495 *
496 * @since bbPress (r2653)
497 *
498 * @uses apply_filters() Calls 'bbp_topics_widget_options' with the
499 * widget options
500 */
501 function BBP_Topics_Widget() {
502 $widget_ops = apply_filters( 'bbp_topics_widget_options', array(
503 'classname' => 'widget_display_topics',
504 'description' => __( 'A list of recent topics, sorted by popularity or freshness.', 'bbpress' )
505 ) );
506
507 parent::WP_Widget( false, __( 'bbPress Topics List', 'bbpress' ), $widget_ops );
508 }
509
510 /**
511 * Displays the output, the topic list
512 *
513 * @since bbPress (r2653)
514 *
515 * @param mixed $args
516 * @param array $instance
517 * @uses apply_filters() Calls 'bbp_topic_widget_title' with the title
518 * @uses bbp_set_query_name() To set the query name to 'bbp_widget'
519 * @uses bbp_reset_query_name() To reset the query name
520 * @uses bbp_has_topics() The main topic loop
521 * @uses bbp_topics() To check whether there are more topics available
522 * in the loop
523 * @uses bbp_the_topic() Loads up the current topic in the loop
524 * @uses bbp_topic_permalink() To display the topic permalink
525 * @uses bbp_topic_title() To display the topic title
526 * @uses bbp_get_topic_last_active_time() To get the topic last active
527 * time
528 * @uses bbp_get_topic_id() To get the topic id
529 * @uses bbp_get_topic_reply_count() To get the topic reply count
530 */
531 function widget( $args, $instance ) {
532
533 extract( $args );
534
535 $title = apply_filters( 'bbp_topic_widget_title', $instance['title'] );
536 $max_shown = !empty( $instance['max_shown'] ) ? (int) $instance['max_shown'] : 5;
537 $show_date = !empty( $instance['show_date'] ) ? 'on' : false;
538 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 'any';
539 $pop_check = ( $instance['pop_check'] < $max_shown || empty( $instance['pop_check'] ) ) ? -1 : $instance['pop_check'];
540
541 // Query defaults
542 $topics_query = array(
543 'author' => 0,
544 'post_parent' => $parent_forum,
545 'posts_per_page' => $max_shown > $pop_check ? $max_shown : $pop_check,
546 'posts_per_page' => $max_shown,
547 'show_stickies' => false,
548 'order' => 'DESC',
549 );
550
551 bbp_set_query_name( 'bbp_widget' );
552
553 // Topics exist
554 if ( bbp_has_topics( $topics_query ) ) :
555
556 // Sort by time
557 if ( $pop_check < $max_shown ) :
558
559 echo $before_widget;
560 echo $before_title . $title . $after_title; ?>
561
562 <ul>
563
564 <?php while ( bbp_topics() ) : bbp_the_topic(); ?>
565
566 <li>
567 <a class="bbp-forum-title" href="<?php bbp_topic_permalink(); ?>" title="<?php bbp_topic_title(); ?>"><?php bbp_topic_title(); ?></a><?php if ( $show_date == 'on' ) _e( ', ' . bbp_get_topic_last_active_time() . ' ago' ); ?>
568 </li>
569
570 <?php endwhile; ?>
571
572 </ul>
573
574 <?php echo $after_widget;
575
576 // Sort by popularity
577 elseif ( $pop_check >= $max_shown ) :
578
579 echo $before_widget;
580 echo $before_title . $title . $after_title;
581
582 while ( bbp_topics() ) {
583 bbp_the_topic();
584 $topics[bbp_get_topic_id()] = bbp_get_topic_reply_count();
585 }
586
587 arsort( $topics );
588 $topic_count = 1;
589
590 ?>
591
592 <ul>
593
594 <?php foreach ( $topics as $topic_id => $topic_reply_count ) : ?>
595
596 <li><a class="bbp-topic-title" href="<?php bbp_topic_permalink( $topic_id ); ?>" title="<?php bbp_topic_title( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a><?php if ( $show_date == 'on' ) _e( ', ' . bbp_get_topic_last_active_time( $topic_id ) . ' ago' ); ?></li>
597
598 <?php
599
600 $topic_count++;
601
602 if ( $topic_count > $max_shown )
603 break;
604
605 endforeach; ?>
606
607 </ul>
608
609 <?php echo $after_widget;
610
611 endif;
612 endif;
613
614 bbp_reset_query_name();
615
616 }
617
618 /**
619 * Update the forum widget options
620 *
621 * @since bbPress (r2653)
622 *
623 * @param array $new_instance The new instance options
624 * @param array $old_instance The old instance options
625 */
626 function update( $new_instance, $old_instance ) {
627 $instance = $old_instance;
628 $instance['title'] = strip_tags( $new_instance['title'] );
629 $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
630 $instance['show_date'] = strip_tags( $new_instance['show_date'] );
631 $instance['pop_check'] = strip_tags( $new_instance['pop_check'] );
632
633 return $instance;
634 }
635
636 /**
637 * Output the topic widget options form
638 *
639 * @since bbPress (r2653)
640 *
641 * @param $instance Instance
642 * @uses BBP_Topics_Widget::get_field_id() To output the field id
643 * @uses BBP_Topics_Widget::get_field_name() To output the field name
644 */
645 function form( $instance ) {
646 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
647 $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
648 $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : '';
649 $pop_check = !empty( $instance['pop_check'] ) ? esc_attr( $instance['pop_check'] ) : ''; ?>
650
651 <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>
652 <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>
653 <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>
654 <p>
655 <label for="<?php echo $this->get_field_id( 'pop_check' ); ?>"><?php _e( 'Popularity check:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'pop_check' ); ?>" name="<?php echo $this->get_field_name( 'pop_check' ); ?>" type="text" value="<?php echo $pop_check; ?>" /></label>
656 <br /><small><?php _e( 'Number of topics back to check reply count to determine popularity. A number less than the maximum number of topics to show disables the check.', 'bbpress' ); ?></small>
657 </p>
658
659 <?php
660 }
661 }
662
663 /**
664 * bbPress Replies Widget
665 *
666 * Adds a widget which displays the replies list
667 *
668 * @since bbPress (r2653)
669 *
670 * @uses WP_Widget
671 */
672 class BBP_Replies_Widget extends WP_Widget {
673
674 /**
675 * Register the widget
676 *
677 * @since bbPress (r3389)
678 *
679 * @uses register_widget()
680 */
681 function register_widget() {
682 register_widget( 'BBP_Replies_Widget' );
683 }
684
685 /**
686 * bbPress Replies Widget
687 *
688 * Registers the replies widget
689 *
690 * @since bbPress (r2653)
691 *
692 * @uses apply_filters() Calls 'bbp_replies_widget_options' with the
693 * widget options
694 */
695 function BBP_Replies_Widget() {
696 $widget_ops = apply_filters( 'bbp_replies_widget_options', array(
697 'classname' => 'widget_display_replies',
698 'description' => __( 'A list of bbPress recent replies.', 'bbpress' )
699 ) );
700
701 parent::WP_Widget( false, 'bbPress Reply List', $widget_ops );
702 }
703
704 /**
705 * Displays the output, the replies list
706 *
707 * @since bbPress (r2653)
708 *
709 * @param mixed $args
710 * @param array $instance
711 * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title
712 * @uses bbp_set_query_name() To set the query name to 'bbp_widget'
713 * @uses bbp_reset_query_name() To reset the query name
714 * @uses bbp_has_replies() The main reply loop
715 * @uses bbp_replies() To check whether there are more replies available
716 * in the loop
717 * @uses bbp_the_reply() Loads up the current reply in the loop
718 * @uses bbp_get_reply_author_link() To get the reply author link
719 * @uses bbp_get_reply_author() To get the reply author name
720 * @uses bbp_get_reply_id() To get the reply id
721 * @uses bbp_get_reply_url() To get the reply url
722 * @uses bbp_get_reply_excerpt() To get the reply excerpt
723 * @uses bbp_get_reply_topic_title() To get the reply topic title
724 * @uses get_the_date() To get the date of the reply
725 * @uses get_the_time() To get the time of the reply
726 */
727 function widget( $args, $instance ) {
728
729 extract( $args );
730
731 $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;
734
735 // Query defaults
736 $replies_query = array(
737 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
738 'posts_per_page' => $max_shown,
739 'order' => 'DESC'
740 );
741
742 // Set the query name
743 bbp_set_query_name( 'bbp_widget' );
744
745 // Get replies and display them
746 if ( bbp_has_replies( $replies_query ) ) :
747
748 echo $before_widget;
749 echo $before_title . $title . $after_title; ?>
750
751 <ul>
752
753 <?php while ( bbp_replies() ) : bbp_the_reply(); ?>
754
755 <li>
756
757 <?php
758 $author_link = bbp_get_reply_author_link( array( 'type' => 'both', 'size' => 14 ) );
759 $reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url() ) . '" title="' . bbp_get_reply_excerpt( bbp_get_reply_id(), 50 ) . '">' . bbp_get_reply_topic_title() . '</a>';
760
761 /* translators: bbpress replies widget: 1: reply author, 2: reply link, 3: reply date, 4: reply time */
762 printf( _x( $show_date == 'on' ? '%1$s on %2$s, %3$s, %4$s' : '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link, get_the_date(), get_the_time() );
763 ?>
764
765 </li>
766
767 <?php endwhile; ?>
768
769 </ul>
770
771 <?php echo $after_widget;
772
773 endif;
774
775 bbp_reset_query_name();
776 }
777
778 /**
779 * Update the forum widget options
780 *
781 * @since bbPress (r2653)
782 *
783 * @param array $new_instance The new instance options
784 * @param array $old_instance The old instance options
785 */
786 function update( $new_instance, $old_instance ) {
787 $instance = $old_instance;
788 $instance['title'] = strip_tags( $new_instance['title'] );
789 $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
790 $instance['show_date'] = strip_tags( $new_instance['show_date'] );
791
792 return $instance;
793 }
794
795 /**
796 * Output the reply widget options form
797 *
798 * @since bbPress (r2653)
799 *
800 * @param $instance Instance
801 * @uses BBP_Replies_Widget::get_field_id() To output the field id
802 * @uses BBP_Replies_Widget::get_field_name() To output the field name
803 */
804 function form( $instance ) {
805 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
806 $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
807 $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; ?>
808
809 <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>
810 <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>
811 <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>
812
813 <?php
814 }
815 }
816
817 ?>
818