Changeset 4806
- Timestamp:
- 03/15/2013 08:59:15 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/common/widgets.php
r4579 r4806 64 64 * @uses get_template_part() To get the login/logged in form 65 65 */ 66 public function widget( $args, $instance ) { 66 public function widget( $args = array(), $instance = array() ) { 67 68 // Get widget settings 69 $settings = $this->parse_settings( $instance ); 67 70 68 71 // Typical WordPress filter 69 $ title = apply_filters( 'widget_title', $instance['title'],$instance, $this->id_base );72 $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 70 73 71 74 // bbPress filters 72 $ title = apply_filters( 'bbp_login_widget_title', $instance['title'], $instance, $this->id_base );73 $ register = apply_filters( 'bbp_login_widget_register', $instance['register'], $instance, $this->id_base );74 $ lostpass = apply_filters( 'bbp_login_widget_lostpass', $instance['lostpass'], $instance, $this->id_base );75 $settings['title'] = apply_filters( 'bbp_login_widget_title', $settings['title'], $instance, $this->id_base ); 76 $settings['register'] = apply_filters( 'bbp_login_widget_register', $settings['register'], $instance, $this->id_base ); 77 $settings['lostpass'] = apply_filters( 'bbp_login_widget_lostpass', $settings['lostpass'], $instance, $this->id_base ); 75 78 76 79 echo $args['before_widget']; 77 80 78 if ( !empty( $title ) ) 79 echo $args['before_title'] . $title . $args['after_title']; 81 if ( !empty( $settings['title'] ) ) { 82 echo $args['before_title'] . $settings['title'] . $args['after_title']; 83 } 80 84 81 85 if ( !is_user_logged_in() ) : ?> … … 110 114 </div> 111 115 112 <?php if ( !empty( $ register ) || !empty( $lostpass) ) : ?>116 <?php if ( !empty( $settings['register'] ) || !empty( $settings['lostpass'] ) ) : ?> 113 117 114 118 <div class="bbp-login-links"> 115 119 116 <?php if ( !empty( $ register) ) : ?>117 118 <a href="<?php echo esc_url( $ register); ?>" title="<?php esc_attr_e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php _e( 'Register', 'bbpress' ); ?></a>120 <?php if ( !empty( $settings['register'] ) ) : ?> 121 122 <a href="<?php echo esc_url( $settings['register'] ); ?>" title="<?php esc_attr_e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php _e( 'Register', 'bbpress' ); ?></a> 119 123 120 124 <?php endif; ?> 121 125 122 <?php if ( !empty( $ lostpass) ) : ?>123 124 <a href="<?php echo esc_url( $ lostpass); ?>" title="<?php esc_attr_e( 'Lost Password', 'bbpress' ); ?>" class="bbp-lostpass-link"><?php _e( 'Lost Password', 'bbpress' ); ?></a>126 <?php if ( !empty( $settings['lostpass'] ) ) : ?> 127 128 <a href="<?php echo esc_url( $settings['lostpass'] ); ?>" title="<?php esc_attr_e( 'Lost Password', 'bbpress' ); ?>" class="bbp-lostpass-link"><?php _e( 'Lost Password', 'bbpress' ); ?></a> 125 129 126 130 <?php endif; ?> … … 173 177 * @uses BBP_Login_Widget::get_field_name() To output the field name 174 178 */ 175 public function form( $instance ) { 176 177 // Form values 178 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; 179 $register = !empty( $instance['register'] ) ? esc_attr( $instance['register'] ) : ''; 180 $lostpass = !empty( $instance['lostpass'] ) ? esc_attr( $instance['lostpass'] ) : ''; 181 182 ?> 179 public function form( $instance = array() ) { 180 181 // Get widget settings 182 $settings = $this->parse_settings( $instance ); ?> 183 183 184 184 <p> 185 185 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 186 <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>186 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /></label> 187 187 </p> 188 188 189 189 <p> 190 190 <label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php _e( 'Register URI:', 'bbpress' ); ?> 191 <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>191 <input class="widefat" id="<?php echo $this->get_field_id( 'register' ); ?>" name="<?php echo $this->get_field_name( 'register' ); ?>" type="text" value="<?php echo esc_url( $settings['register'] ); ?>" /></label> 192 192 </p> 193 193 194 194 <p> 195 195 <label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php _e( 'Lost Password URI:', 'bbpress' ); ?> 196 <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>196 <input class="widefat" id="<?php echo $this->get_field_id( 'lostpass' ); ?>" name="<?php echo $this->get_field_name( 'lostpass' ); ?>" type="text" value="<?php echo esc_url( $settings['lostpass'] ); ?>" /></label> 197 197 </p> 198 198 199 199 <?php 200 } 201 202 /** 203 * Merge the widget settings into defaults array. 204 * 205 * @since bbPress (r4802) 206 * 207 * @param $instance Instance 208 * @uses bbp_parse_args() To merge widget settings into defaults 209 */ 210 public function parse_settings( $instance = array() ) { 211 return bbp_parse_args( $instance, array( 212 'title' => '', 213 'register' => '', 214 'lostpass' => '' 215 ), 'login_widget_settings' ); 200 216 } 201 217 } … … 254 270 * @uses bbp_view_title() To output the view title 255 271 */ 256 public function widget( $args , $instance) {272 public function widget( $args = array(), $instance = array() ) { 257 273 258 274 // Only output widget contents if views exist 259 if ( bbp_get_views() ) : 260 261 // Typical WordPress filter 262 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); 263 264 // bbPress filter 265 $title = apply_filters( 'bbp_view_widget_title', $instance['title'], $instance, $this->id_base ); 266 267 echo $args['before_widget']; 268 echo $args['before_title'] . $title . $args['after_title']; ?> 269 270 <ul> 271 272 <?php foreach ( array_keys( bbp_get_views() ) as $view ) : ?> 273 274 <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> 275 276 <?php endforeach; ?> 277 278 </ul> 279 280 <?php echo $args['after_widget']; 281 282 endif; 275 if ( ! bbp_get_views() ) { 276 return; 277 } 278 279 // Get widget settings 280 $settings = $this->parse_settings( $instance ); 281 282 // Typical WordPress filter 283 $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 284 285 // bbPress filter 286 $settings['title'] = apply_filters( 'bbp_view_widget_title', $settings['title'], $instance, $this->id_base ); 287 288 echo $args['before_widget']; 289 290 if ( !empty( $settings['title'] ) ) { 291 echo $args['before_title'] . $settings['title'] . $args['after_title']; 292 } ?> 293 294 <ul> 295 296 <?php foreach ( array_keys( bbp_get_views() ) as $view ) : ?> 297 298 <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> 299 300 <?php endforeach; ?> 301 302 </ul> 303 304 <?php echo $args['after_widget']; 283 305 } 284 306 … … 291 313 * @param array $old_instance The old instance options 292 314 */ 293 public function update( $new_instance , $old_instance) {315 public function update( $new_instance = array(), $old_instance = array() ) { 294 316 $instance = $old_instance; 295 317 $instance['title'] = strip_tags( $new_instance['title'] ); … … 307 329 * @uses BBP_Views_Widget::get_field_name() To output the field name 308 330 */ 309 public function form( $instance ) { 310 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?> 331 public function form( $instance = array() ) { 332 333 // Get widget settings 334 $settings = $this->parse_settings( $instance ); ?> 311 335 312 336 <p> 313 337 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 314 <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; ?>" />338 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /> 315 339 </label> 316 340 </p> 317 341 318 342 <?php 343 } 344 345 /** 346 * Merge the widget settings into defaults array. 347 * 348 * @since bbPress (r4802) 349 * 350 * @param $instance Instance 351 * @uses bbp_parse_args() To merge widget settings into defaults 352 */ 353 public function parse_settings( $instance = array() ) { 354 return bbp_parse_args( $instance, array( 355 'title' => '' 356 ), 'view_widget_settings' ); 319 357 } 320 358 } … … 371 409 public function widget( $args, $instance ) { 372 410 411 // Get widget settings 412 $settings = $this->parse_settings( $instance ); 413 373 414 // Typical WordPress filter 374 $ title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );415 $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 375 416 376 417 // bbPress filter 377 $ title = apply_filters( 'bbp_search_widget_title', $instance['title'], $instance, $this->id_base );418 $settings['title'] = apply_filters( 'bbp_search_widget_title', $settings['title'], $instance, $this->id_base ); 378 419 379 420 echo $args['before_widget']; 380 echo $args['before_title'] . $title . $args['after_title']; 421 422 if ( !empty( $settings['title'] ) ) { 423 echo $args['before_title'] . $settings['title'] . $args['after_title']; 424 } 381 425 382 426 bbp_get_template_part( 'form', 'search' ); … … 410 454 */ 411 455 public function form( $instance ) { 412 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?> 456 457 // Get widget settings 458 $settings = $this->parse_settings( $instance ); ?> 413 459 414 460 <p> 415 461 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 416 <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; ?>" />462 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /> 417 463 </label> 418 464 </p> 419 465 420 466 <?php 467 } 468 469 /** 470 * Merge the widget settings into defaults array. 471 * 472 * @since bbPress (r4802) 473 * 474 * @param $instance Instance 475 * @uses bbp_parse_args() To merge widget settings into defaults 476 */ 477 public function parse_settings( $instance = array() ) { 478 return bbp_parse_args( $instance, array( 479 'title' => '' 480 ), 'search_widget_settings' ); 421 481 } 422 482 } … … 483 543 public function widget( $args, $instance ) { 484 544 545 // Get widget settings 546 $settings = $this->parse_settings( $instance ); 547 485 548 // Typical WordPress filter 486 $ title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );549 $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 487 550 488 551 // bbPress filter 489 $title = apply_filters( 'bbp_forum_widget_title', $instance['title'], $instance, $this->id_base ); 490 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : '0'; 552 $settings['title'] = apply_filters( 'bbp_forum_widget_title', $settings['title'], $instance, $this->id_base ); 491 553 492 554 // Note: private and hidden forums will be excluded via the 493 555 // bbp_pre_get_posts_exclude_forums filter and function. 494 556 $widget_query = new WP_Query( array( 495 'post_parent' => $ parent_forum,557 'post_parent' => $settings['parent_forum'], 496 558 'post_type' => bbp_get_forum_post_type(), 497 559 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ), … … 500 562 ) ); 501 563 502 if ( $widget_query->have_posts() ) : 503 504 echo $args['before_widget']; 505 echo $args['before_title'] . $title . $args['after_title']; ?> 506 507 <ul> 508 509 <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?> 510 511 <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> 512 513 <?php endwhile; ?> 514 515 </ul> 516 517 <?php echo $args['after_widget']; 518 519 // Reset the $post global 520 wp_reset_postdata(); 521 522 endif; 564 // Bail if no posts 565 if ( ! $widget_query->have_posts() ) { 566 return; 567 } 568 569 echo $args['before_widget']; 570 571 if ( !empty( $settings['title'] ) ) { 572 echo $args['before_title'] . $settings['title'] . $args['after_title']; 573 } ?> 574 575 <ul> 576 577 <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?> 578 579 <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> 580 581 <?php endwhile; ?> 582 583 </ul> 584 585 <?php echo $args['after_widget']; 586 587 // Reset the $post global 588 wp_reset_postdata(); 523 589 } 524 590 … … 554 620 */ 555 621 public function form( $instance ) { 556 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; 557 $parent_forum = !empty( $instance['parent_forum'] ) ? esc_attr( $instance['parent_forum'] ) : '0'; ?> 622 623 // Get widget settings 624 $settings = $this->parse_settings( $instance ); ?> 558 625 559 626 <p> 560 627 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 561 <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; ?>" />628 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /> 562 629 </label> 563 630 </p> … … 565 632 <p> 566 633 <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?> 567 <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; ?>" />634 <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 esc_attr( $settings['parent_forum'] ); ?>" /> 568 635 </label> 569 636 … … 574 641 575 642 <?php 643 } 644 645 /** 646 * Merge the widget settings into defaults array. 647 * 648 * @since bbPress (r4802) 649 * 650 * @param $instance Instance 651 * @uses bbp_parse_args() To merge widget settings into defaults 652 */ 653 public function parse_settings( $instance = array() ) { 654 return bbp_parse_args( $instance, array( 655 'title' => '', 656 'parent_forum' => 0 657 ), 'forum_widget_settings' ); 576 658 } 577 659 } … … 632 714 * @uses bbp_get_topic_id() To get the topic id 633 715 */ 634 public function widget( $args, $instance ) { 716 public function widget( $args = array(), $instance = array() ) { 717 718 // Get widget settings 719 $settings = $this->parse_settings( $instance ); 635 720 636 721 // Typical WordPress filter 637 $ title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );722 $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 638 723 639 724 // bbPress filter 640 $title = apply_filters( 'bbp_topic_widget_title', $instance['title'], $instance, $this->id_base ); 641 $max_shown = !empty( $instance['max_shown'] ) ? (int) $instance['max_shown'] : 5; 642 $show_date = !empty( $instance['show_date'] ) ? 'on' : false; 643 $show_user = !empty( $instance['show_user'] ) ? 'on' : false; 644 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 'any'; 645 $order_by = !empty( $instance['order_by'] ) ? $instance['order_by'] : false; 725 $settings['title'] = apply_filters( 'bbp_topic_widget_title', $settings['title'], $instance, $this->id_base ); 646 726 647 727 // How do we want to order our results? 648 switch ( $ order_by) {728 switch ( $settings['order_by'] ) { 649 729 650 730 // Order by most recent replies 651 731 case 'freshness' : 652 732 $topics_query = array( 653 'author' => 0,654 733 'post_type' => bbp_get_topic_post_type(), 655 'post_parent' => $ parent_forum,656 'posts_per_page' => $max_shown,657 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id()) ),658 'show_stick es'=> false,734 'post_parent' => $settings['parent_forum'], 735 'posts_per_page' => (int) $settings['max_shown'], 736 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 737 'show_stickies' => false, 659 738 'meta_key' => '_bbp_last_active_time', 660 739 'orderby' => 'meta_value', 661 740 'order' => 'DESC', 662 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )663 741 ); 664 742 break; … … 667 745 case 'popular' : 668 746 $topics_query = array( 669 'author' => 0,670 747 'post_type' => bbp_get_topic_post_type(), 671 'post_parent' => $ parent_forum,672 'posts_per_page' => $max_shown,673 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id()) ),674 'show_stick es'=> false,748 'post_parent' => $settings['parent_forum'], 749 'posts_per_page' => (int) $settings['max_shown'], 750 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 751 'show_stickies' => false, 675 752 'meta_key' => '_bbp_reply_count', 676 753 'orderby' => 'meta_value', 677 'order' => 'DESC', 678 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) ) 754 'order' => 'DESC' 679 755 ); 680 756 break; … … 684 760 default : 685 761 $topics_query = array( 686 'author' => 0,687 762 'post_type' => bbp_get_topic_post_type(), 688 'post_parent' => $parent_forum, 689 'posts_per_page' => $max_shown, 690 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), 691 'show_stickes' => false, 692 'order' => 'DESC', 693 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) ) 763 'post_parent' => $settings['parent_forum'], 764 'posts_per_page' => (int) $settings['max_shown'], 765 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 766 'show_stickies' => false, 767 'order' => 'DESC' 694 768 ); 695 769 break; … … 700 774 $widget_query = new WP_Query( $topics_query ); 701 775 702 // Topics exist 703 if ( $widget_query->have_posts() ) : 704 705 echo $args['before_widget']; 706 echo $args['before_title'] . $title . $args['after_title']; ?> 707 708 <ul> 709 710 <?php while ( $widget_query->have_posts() ) : 711 712 $widget_query->the_post(); 713 $topic_id = bbp_get_topic_id( $widget_query->post->ID ); 714 $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) ); ?> 715 716 <li> 717 <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> 718 719 <?php if ( 'on' == $show_user ) : ?> 720 721 <?php printf( _x( 'by %1$s', 'widgets', 'bbpress' ), '<span class="topic-author">' . $author_link . '</span>' ); ?> 722 723 <?php endif; ?> 724 725 <?php if ( 'on' == $show_date ) : ?> 726 727 <div><?php bbp_topic_last_active_time( $topic_id ); ?></div> 728 729 <?php endif; ?> 730 731 </li> 732 733 <?php endwhile; ?> 734 735 </ul> 736 737 <?php echo $args['after_widget']; 738 739 // Reset the $post global 740 wp_reset_postdata(); 741 742 endif; 776 // Bail if no topics are found 777 if ( ! $widget_query->have_posts() ) { 778 return; 779 } 780 781 echo $args['before_widget']; 782 783 if ( !empty( $settings['title'] ) ) { 784 echo $args['before_title'] . $settings['title'] . $args['after_title']; 785 } ?> 786 787 <ul> 788 789 <?php while ( $widget_query->have_posts() ) : 790 791 $widget_query->the_post(); 792 $topic_id = bbp_get_topic_id( $widget_query->post->ID ); 793 $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) ); ?> 794 795 <li> 796 <a class="bbp-forum-title" href="<?php echo esc_url( bbp_get_topic_permalink( $topic_id ) ); ?>" title="<?php echo esc_attr( bbp_get_topic_title( $topic_id ) ); ?>"><?php bbp_topic_title( $topic_id ); ?></a> 797 798 <?php if ( 'on' == $settings['show_user'] ) : ?> 799 800 <?php printf( _x( 'by %1$s', 'widgets', 'bbpress' ), '<span class="topic-author">' . $author_link . '</span>' ); ?> 801 802 <?php endif; ?> 803 804 <?php if ( 'on' == $settings['show_date'] ) : ?> 805 806 <div><?php bbp_topic_last_active_time( $topic_id ); ?></div> 807 808 <?php endif; ?> 809 810 </li> 811 812 <?php endwhile; ?> 813 814 </ul> 815 816 <?php echo $args['after_widget']; 817 818 // Reset the $post global 819 wp_reset_postdata(); 743 820 } 744 821 … … 751 828 * @param array $old_instance The old instance options 752 829 */ 753 public function update( $new_instance , $old_instance) {830 public function update( $new_instance = array(), $old_instance = array() ) { 754 831 $instance = $old_instance; 755 $instance['title'] = strip_tags( $new_instance['title'] ); 756 $instance['max_shown'] = strip_tags( $new_instance['max_shown'] ); 757 $instance['show_date'] = strip_tags( $new_instance['show_date'] ); 758 $instance['show_user'] = strip_tags( $new_instance['show_user'] ); 759 $instance['order_by'] = strip_tags( $new_instance['order_by'] ); 832 $instance['title'] = strip_tags( $new_instance['title'] ); 833 $instance['order_by'] = strip_tags( $new_instance['order_by'] ); 834 $instance['show_date'] = (bool) $new_instance['show_date']; 835 $instance['show_user'] = (bool) $new_instance['show_user']; 836 $instance['max_shown'] = (int) $new_instance['max_shown']; 837 838 // Force to any 839 if ( !empty( $instance['parent_forum'] ) && !is_numeric( $instance['parent_forum'] ) ) { 840 $instance['parent_forum'] = 'any'; 841 } else { 842 $instance['parent_forum'] = (int) $new_instance['parent_forum']; 843 } 760 844 761 845 return $instance; … … 771 855 * @uses BBP_Topics_Widget::get_field_name() To output the field name 772 856 */ 773 public function form( $instance ) { 774 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; 775 $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : ''; 776 $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; 777 $show_user = !empty( $instance['show_user'] ) ? esc_attr( $instance['show_user'] ) : ''; 778 $order_by = !empty( $instance['order_by'] ) ? esc_attr( $instance['order_by'] ) : ''; ?> 779 780 <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> 781 <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> 782 <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> 783 <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show topic author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $show_user ); ?> /></label></p> 857 public function form( $instance = array() ) { 858 859 // Get widget settings 860 $settings = $this->parse_settings( $instance ); ?> 861 862 <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 esc_attr( $settings['title'] ); ?>" /></label></p> 863 <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 esc_attr( $settings['max_shown'] ); ?>" /></label></p> 864 865 <p> 866 <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?> 867 <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 esc_attr( $settings['parent_forum'] ); ?>" /> 868 </label> 869 870 <br /> 871 872 <small><?php _e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small> 873 </p> 874 875 <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', $settings['show_date'] ); ?> /></label></p> 876 <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show topic author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $settings['show_user'] ); ?> /></label></p> 784 877 785 878 <p> 786 879 <label for="<?php echo $this->get_field_id( 'order_by' ); ?>"><?php _e( 'Order By:', 'bbpress' ); ?></label> 787 880 <select name="<?php echo $this->get_field_name( 'order_by' ); ?>" id="<?php echo $this->get_field_name( 'order_by' ); ?>"> 788 <option <?php selected( $ order_by, 'newness' ); ?> value="newness"><?php _e( 'Newest Topics', 'bbpress' ); ?></option>789 <option <?php selected( $ order_by, 'popular' ); ?> value="popular"><?php _e( 'Popular Topics', 'bbpress' ); ?></option>790 <option <?php selected( $ order_by, 'freshness' ); ?> value="freshness"><?php _e( 'Topics With Recent Replies', 'bbpress' ); ?></option>881 <option <?php selected( $settings['order_by'], 'newness' ); ?> value="newness"><?php _e( 'Newest Topics', 'bbpress' ); ?></option> 882 <option <?php selected( $settings['order_by'], 'popular' ); ?> value="popular"><?php _e( 'Popular Topics', 'bbpress' ); ?></option> 883 <option <?php selected( $settings['order_by'], 'freshness' ); ?> value="freshness"><?php _e( 'Topics With Recent Replies', 'bbpress' ); ?></option> 791 884 </select> 792 885 </p> 793 886 794 887 <?php 888 } 889 890 /** 891 * Merge the widget settings into defaults array. 892 * 893 * @since bbPress (r4802) 894 * 895 * @param $instance Instance 896 * @uses bbp_parse_args() To merge widget options into defaults 897 */ 898 public function parse_settings( $instance = array() ) { 899 return bbp_parse_args( $instance, array( 900 'title' => '', 901 'max_shown' => 5, 902 'show_date' => false, 903 'show_user' => false, 904 'parent_forum' => 'any', 905 'order_by' => false 906 ), 'topic_widget_settings' ); 795 907 } 796 908 } … … 848 960 * @uses bbp_get_template_part() To get the content-forum-statistics template 849 961 */ 850 public function widget( $args, $instance ) { 851 852 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); 853 $title = apply_filters( 'bbp_stats_widget_title', $instance['title'], $instance, $this->id_base ); 962 public function widget( $args = array(), $instance = array() ) { 963 964 // Get widget settings 965 $settings = $this->parse_settings( $instance ); 966 967 // Typical WordPress filter 968 $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 969 970 // bbPress widget title filter 971 $settings['title'] = apply_filters( 'bbp_stats_widget_title', $settings['title'], $instance, $this->id_base ); 854 972 855 973 echo $args['before_widget']; 856 echo $args['before_title'] . $title . $args['after_title']; 974 975 if ( !empty( $settings['title'] ) ) { 976 echo $args['before_title'] . $settings['title'] . $args['after_title']; 977 } 857 978 858 979 bbp_get_template_part( 'content', 'statistics' ); … … 888 1009 */ 889 1010 public function form( $instance ) { 890 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?> 1011 1012 // Get widget settings 1013 $settings = $this->parse_settings( $instance ); ?> 891 1014 892 1015 <p> 893 1016 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 894 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" 895 name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/> 1017 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>"/> 896 1018 </label> 897 1019 </p> 898 1020 899 1021 <?php 1022 } 1023 1024 /** 1025 * Merge the widget settings into defaults array. 1026 * 1027 * @since bbPress (r4802) 1028 * 1029 * @param $instance Instance 1030 * @uses bbp_parse_args() To merge widget settings into defaults 1031 */ 1032 public function parse_settings( $instance = array() ) { 1033 return bbp_parse_args( $instance, array( 1034 'title' => '' 1035 ), 1036 'stats_widget_settings' ); 900 1037 } 901 1038 } … … 961 1098 public function widget( $args, $instance ) { 962 1099 1100 // Get widget settings 1101 $settings = $this->parse_settings( $instance ); 1102 963 1103 // Typical WordPress filter 964 $ title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );1104 $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 965 1105 966 1106 // bbPress filter 967 $title = apply_filters( 'bbp_replies_widget_title', $instance['title'], $instance, $this->id_base ); 968 $max_shown = !empty( $instance['max_shown'] ) ? $instance['max_shown'] : '5'; 969 $show_date = !empty( $instance['show_date'] ) ? 'on' : false; 970 $show_user = !empty( $instance['show_user'] ) ? 'on' : false; 971 $post_types = !empty( $instance['post_type'] ) ? array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) : bbp_get_reply_post_type(); 1107 $settings['title'] = apply_filters( 'bbp_replies_widget_title', $settings['title'], $instance, $this->id_base ); 972 1108 973 1109 // Note: private and hidden forums will be excluded via the 974 1110 // bbp_pre_get_posts_exclude_forums filter and function. 975 1111 $widget_query = new WP_Query( array( 976 'post_type' => $post_types, 977 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), 978 'posts_per_page' => $max_shown, 979 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) ) 1112 'post_type' => bbp_get_reply_post_type(), 1113 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 1114 'posts_per_page' => (int) $settings['max_shown'] 980 1115 ) ); 981 1116 982 // Get replies and display them 983 if ( $widget_query->have_posts() ) : 984 985 echo $args['before_widget']; 986 echo $args['before_title'] . $title . $args['after_title']; ?> 987 988 <ul> 989 990 <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?> 991 992 <li> 993 994 <?php 995 996 $reply_id = bbp_get_reply_id( $widget_query->post->ID ); 997 $author_link = bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) ); 998 $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>'; 999 1000 // Reply author, link, and timestamp 1001 if ( ( 'on' == $show_date ) && ( 'on' == $show_user ) ) : 1002 1003 // translators: 1: reply author, 2: reply link, 3: reply timestamp 1004 printf( _x( '%1$s on %2$s %3$s', 'widgets', 'bbpress' ), $author_link, $reply_link, '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>' ); 1005 1006 // Reply link and timestamp 1007 elseif ( $show_date == 'on' ) : 1008 1009 // translators: 1: reply link, 2: reply timestamp 1010 printf( _x( '%1$s %2$s', 'widgets', 'bbpress' ), $reply_link, '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>' ); 1011 1012 // Reply author and title 1013 elseif ( $show_user == 'on' ) : 1014 1015 // translators: 1: reply author, 2: reply link 1016 printf( _x( '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link ); 1017 1018 // Only the reply title 1019 else : 1020 1021 // translators: 1: reply link 1022 printf( _x( '%1$s', 'widgets', 'bbpress' ), $reply_link ); 1023 1024 endif; 1025 1026 ?> 1027 1028 </li> 1029 1030 <?php endwhile; ?> 1031 1032 </ul> 1033 1034 <?php echo $args['after_widget']; 1035 1036 // Reset the $post global 1037 wp_reset_postdata(); 1038 1039 endif; 1117 // Bail if no replies 1118 if ( ! $widget_query->have_posts() ) { 1119 return; 1120 } 1121 1122 echo $args['before_widget']; 1123 1124 if ( !empty( $settings['title'] ) ) { 1125 echo $args['before_title'] . $settings['title'] . $args['after_title']; 1126 } ?> 1127 1128 <ul> 1129 1130 <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?> 1131 1132 <li> 1133 1134 <?php 1135 1136 $reply_id = bbp_get_reply_id( $widget_query->post->ID ); 1137 $author_link = bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) ); 1138 $reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url( $reply_id ) ) . '" title="' . esc_attr( bbp_get_reply_excerpt( $reply_id, 50 ) ) . '">' . bbp_get_reply_topic_title( $reply_id ) . '</a>'; 1139 1140 // Reply author, link, and timestamp 1141 if ( ( 'on' == $settings['show_date'] ) && ( 'on' == $settings['show_user'] ) ) : 1142 1143 // translators: 1: reply author, 2: reply link, 3: reply timestamp 1144 printf( _x( '%1$s on %2$s %3$s', 'widgets', 'bbpress' ), $author_link, $reply_link, '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>' ); 1145 1146 // Reply link and timestamp 1147 elseif ( $settings['show_date'] == 'on' ) : 1148 1149 // translators: 1: reply link, 2: reply timestamp 1150 printf( _x( '%1$s %2$s', 'widgets', 'bbpress' ), $reply_link, '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>' ); 1151 1152 // Reply author and title 1153 elseif ( $settings['show_user'] == 'on' ) : 1154 1155 // translators: 1: reply author, 2: reply link 1156 printf( _x( '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link ); 1157 1158 // Only the reply title 1159 else : 1160 1161 // translators: 1: reply link 1162 printf( _x( '%1$s', 'widgets', 'bbpress' ), $reply_link ); 1163 1164 endif; 1165 1166 ?> 1167 1168 </li> 1169 1170 <?php endwhile; ?> 1171 1172 </ul> 1173 1174 <?php echo $args['after_widget']; 1175 1176 // Reset the $post global 1177 wp_reset_postdata(); 1040 1178 } 1041 1179 … … 1048 1186 * @param array $old_instance The old instance options 1049 1187 */ 1050 public function update( $new_instance , $old_instance) {1188 public function update( $new_instance = array(), $old_instance = array() ) { 1051 1189 $instance = $old_instance; 1052 $instance['title'] = strip_tags( $new_instance['title'] 1053 $instance[' max_shown'] = strip_tags( $new_instance['max_shown'] );1054 $instance['show_ date'] = strip_tags( $new_instance['show_date'] );1055 $instance[' show_user'] = strip_tags( $new_instance['show_user'] );1190 $instance['title'] = strip_tags( $new_instance['title'] ); 1191 $instance['show_date'] = (bool) $new_instance['show_date']; 1192 $instance['show_user'] = (bool) $new_instance['show_user']; 1193 $instance['max_shown'] = (int) $new_instance['max_shown']; 1056 1194 1057 1195 return $instance; … … 1067 1205 * @uses BBP_Replies_Widget::get_field_name() To output the field name 1068 1206 */ 1069 public function form( $instance ) { 1070 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; 1071 $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : ''; 1072 $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; 1073 $show_user = !empty( $instance['show_user'] ) ? esc_attr( $instance['show_user'] ) : ''; ?> 1074 1075 <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> 1076 <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> 1077 <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> 1078 <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show reply author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $show_user ); ?> /></label></p> 1207 public function form( $instance = array() ) { 1208 1209 // Get widget settings 1210 $settings = $this->parse_settings( $instance ); ?> 1211 1212 <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 esc_attr( $settings['title'] ); ?>" /></label></p> 1213 <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 esc_attr( $settings['max_shown'] ); ?>" /></label></p> 1214 <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', $settings['show_date'] ); ?> /></label></p> 1215 <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show reply author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $settings['show_user'] ); ?> /></label></p> 1079 1216 1080 1217 <?php 1081 1218 } 1219 1220 /** 1221 * Merge the widget settings into defaults array. 1222 * 1223 * @since bbPress (r4802) 1224 * 1225 * @param $instance Instance 1226 * @uses bbp_parse_args() To merge widget settings into defaults 1227 */ 1228 public function parse_settings( $instance = array() ) { 1229 return bbp_parse_args( $instance , array( 1230 'title' => '', 1231 'max_shown' => 5, 1232 'show_date' => false, 1233 'show_user' => false 1234 ), 1235 'replies_widget_settings' ); 1236 } 1082 1237 }
Note: See TracChangeset
for help on using the changeset viewer.