PluginProbe
bbPress / 2.0-rc-3
bbPress v2.0-rc-3
2.6.17 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 All 72 releases
bbpress / bbp-includes / bbp-core-widgets.php

bbp-core-widgets.php in bbPress 2.0-rc-3, at bbp-includes/bbp-core-widgets.php

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