Advertisement
ovizii

widgets.php

Jul 23rd, 2013
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 39.59 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * bbPress Widgets
  5.  *
  6.  * Contains the forum list, topic list, reply list and login form widgets.
  7.  *
  8.  * @package bbPress
  9.  * @subpackage Widgets
  10.  */
  11.  
  12. // Exit if accessed directly
  13. if ( !defined( 'ABSPATH' ) ) exit;
  14.  
  15. /**
  16.  * bbPress Login Widget
  17.  *
  18.  * Adds a widget which displays the login form
  19.  *
  20.  * @since bbPress (r2827)
  21.  *
  22.  * @uses WP_Widget
  23.  */
  24. class BBP_Login_Widget extends WP_Widget {
  25.  
  26.     /**
  27.      * bbPress Login Widget
  28.      *
  29.      * Registers the login widget
  30.      *
  31.      * @since bbPress (r2827)
  32.      *
  33.      * @uses apply_filters() Calls 'bbp_login_widget_options' with the
  34.      *                        widget options
  35.      */
  36.     public function __construct() {
  37.         $widget_ops = apply_filters( 'bbp_login_widget_options', array(
  38.             'classname'   => 'bbp_widget_login',
  39.             'description' => __( 'A simple login form with optional links to sign-up and lost password pages.', 'bbpress' )
  40.         ) );
  41.  
  42.         parent::__construct( false, __( '(bbPress) Login Widget', 'bbpress' ), $widget_ops );
  43.     }
  44.  
  45.     /**
  46.      * Register the widget
  47.      *
  48.      * @since bbPress (r3389)
  49.      *
  50.      * @uses register_widget()
  51.      */
  52.     public static function register_widget() {
  53.         register_widget( 'BBP_Login_Widget' );
  54.     }
  55.  
  56.     /**
  57.      * Displays the output, the login form
  58.      *
  59.      * @since bbPress (r2827)
  60.      *
  61.      * @param mixed $args Arguments
  62.      * @param array $instance Instance
  63.      * @uses apply_filters() Calls 'bbp_login_widget_title' with the title
  64.      * @uses get_template_part() To get the login/logged in form
  65.      */
  66.     public function widget( $args = array(), $instance = array() ) {
  67.  
  68.         // Get widget settings
  69.         $settings = $this->parse_settings( $instance );
  70.  
  71.         // Typical WordPress filter
  72.         $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
  73.  
  74.         // bbPress filters
  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 );
  78.  
  79.         echo $args['before_widget'];
  80.  
  81.         if ( !empty( $settings['title'] ) ) {
  82.             echo $args['before_title'] . $settings['title'] . $args['after_title'];
  83.         }
  84.  
  85.         if ( !is_user_logged_in() ) : ?>
  86.  
  87.             <form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form">
  88.                 <fieldset>
  89.                     <legend><?php _e( 'Log In', 'bbpress' ); ?></legend>
  90.  
  91.                     <div class="bbp-username">
  92.                         <label for="user_login"><?php _e( 'Username', 'bbpress' ); ?>: </label>
  93.                         <input type="text" name="log" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" id="user_login" tabindex="<?php bbp_tab_index(); ?>" />
  94.                     </div>
  95.  
  96.                     <div class="bbp-password">
  97.                         <label for="user_pass"><?php _e( 'Password', 'bbpress' ); ?>: </label>
  98.                         <input type="password" name="pwd" value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" tabindex="<?php bbp_tab_index(); ?>" />
  99.                     </div>
  100.  
  101.                     <div class="bbp-remember-me">
  102.                         <input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ), true, true ); ?> id="rememberme" tabindex="<?php bbp_tab_index(); ?>" />
  103.                         <label for="rememberme"><?php _e( 'Remember Me', 'bbpress' ); ?></label>
  104.                     </div>
  105.  
  106.                     <div class="bbp-submit-wrapper">
  107.  
  108.                         <?php do_action( 'login_form' ); ?>
  109.  
  110.                         <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>
  111.  
  112.                         <?php bbp_user_login_fields(); ?>
  113.  
  114.                     </div>
  115.  
  116.                     <?php if ( !empty( $settings['register'] ) || !empty( $settings['lostpass'] ) ) : ?>
  117.  
  118.                         <div class="bbp-login-links">
  119.  
  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>
  123.  
  124.                             <?php endif; ?>
  125.  
  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>
  129.  
  130.                             <?php endif; ?>
  131.  
  132.                         </div>
  133.  
  134.                     <?php endif; ?>
  135.  
  136.                 </fieldset>
  137.             </form>
  138.  
  139.         <?php else : ?>
  140.  
  141.             <div class="bbp-logged-in">
  142.                 <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>
  143.                 <h4><?php bbp_user_profile_link( bbp_get_current_user_id() ); ?></h4>
  144.  
  145.                 <?php bbp_logout_link(); ?>
  146.             </div>
  147.  
  148.         <?php endif;
  149.  
  150.         echo $args['after_widget'];
  151.     }
  152.  
  153.     /**
  154.      * Update the login widget options
  155.      *
  156.      * @since bbPress (r2827)
  157.      *
  158.      * @param array $new_instance The new instance options
  159.      * @param array $old_instance The old instance options
  160.      */
  161.     public function update( $new_instance, $old_instance ) {
  162.         $instance             = $old_instance;
  163.         $instance['title']    = strip_tags( $new_instance['title'] );
  164.         $instance['register'] = esc_url_raw( $new_instance['register'] );
  165.         $instance['lostpass'] = esc_url_raw( $new_instance['lostpass'] );
  166.  
  167.         return $instance;
  168.     }
  169.  
  170.     /**
  171.      * Output the login widget options form
  172.      *
  173.      * @since bbPress (r2827)
  174.      *
  175.      * @param $instance Instance
  176.      * @uses BBP_Login_Widget::get_field_id() To output the field id
  177.      * @uses BBP_Login_Widget::get_field_name() To output the field name
  178.      */
  179.     public function form( $instance = array() ) {
  180.  
  181.         // Get widget settings
  182.         $settings = $this->parse_settings( $instance ); ?>
  183.  
  184.         <p>
  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 esc_attr( $settings['title'] ); ?>" /></label>
  187.         </p>
  188.  
  189.         <p>
  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 esc_url( $settings['register'] ); ?>" /></label>
  192.         </p>
  193.  
  194.         <p>
  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 esc_url( $settings['lostpass'] ); ?>" /></label>
  197.         </p>
  198.  
  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' );
  216.     }
  217. }
  218.  
  219. /**
  220.  * bbPress Views Widget
  221.  *
  222.  * Adds a widget which displays the view list
  223.  *
  224.  * @since bbPress (r3020)
  225.  *
  226.  * @uses WP_Widget
  227.  */
  228. class BBP_Views_Widget extends WP_Widget {
  229.  
  230.     /**
  231.      * bbPress View Widget
  232.      *
  233.      * Registers the view widget
  234.      *
  235.      * @since bbPress (r3020)
  236.      *
  237.      * @uses apply_filters() Calls 'bbp_views_widget_options' with the
  238.      *                        widget options
  239.      */
  240.     public function __construct() {
  241.         $widget_ops = apply_filters( 'bbp_views_widget_options', array(
  242.             'classname'   => 'widget_display_views',
  243.             'description' => __( 'A list of registered optional topic views.', 'bbpress' )
  244.         ) );
  245.  
  246.         parent::__construct( false, __( '(bbPress) Topic Views List', 'bbpress' ), $widget_ops );
  247.     }
  248.  
  249.     /**
  250.      * Register the widget
  251.      *
  252.      * @since bbPress (r3389)
  253.      *
  254.      * @uses register_widget()
  255.      */
  256.     public static function register_widget() {
  257.         register_widget( 'BBP_Views_Widget' );
  258.     }
  259.  
  260.     /**
  261.      * Displays the output, the view list
  262.      *
  263.      * @since bbPress (r3020)
  264.      *
  265.      * @param mixed $args Arguments
  266.      * @param array $instance Instance
  267.      * @uses apply_filters() Calls 'bbp_view_widget_title' with the title
  268.      * @uses bbp_get_views() To get the views
  269.      * @uses bbp_view_url() To output the view url
  270.      * @uses bbp_view_title() To output the view title
  271.      */
  272.     public function widget( $args = array(), $instance = array() ) {
  273.  
  274.         // Only output widget contents if views exist
  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'];
  305.     }
  306.  
  307.     /**
  308.      * Update the view widget options
  309.      *
  310.      * @since bbPress (r3020)
  311.      *
  312.      * @param array $new_instance The new instance options
  313.      * @param array $old_instance The old instance options
  314.      */
  315.     public function update( $new_instance = array(), $old_instance = array() ) {
  316.         $instance          = $old_instance;
  317.         $instance['title'] = strip_tags( $new_instance['title'] );
  318.  
  319.         return $instance;
  320.     }
  321.  
  322.     /**
  323.      * Output the view widget options form
  324.      *
  325.      * @since bbPress (r3020)
  326.      *
  327.      * @param $instance Instance
  328.      * @uses BBP_Views_Widget::get_field_id() To output the field id
  329.      * @uses BBP_Views_Widget::get_field_name() To output the field name
  330.      */
  331.     public function form( $instance = array() ) {
  332.  
  333.         // Get widget settings
  334.         $settings = $this->parse_settings( $instance ); ?>
  335.  
  336.         <p>
  337.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
  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'] ); ?>" />
  339.             </label>
  340.         </p>
  341.  
  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' );
  357.     }
  358. }
  359.  
  360. /**
  361.  * bbPress Search Widget
  362.  *
  363.  * Adds a widget which displays the forum search form
  364.  *
  365.  * @since bbPress (r4579)
  366.  *
  367.  * @uses WP_Widget
  368.  */
  369. class BBP_Search_Widget extends WP_Widget {
  370.  
  371.     /**
  372.      * bbPress Search Widget
  373.      *
  374.      * Registers the search widget
  375.      *
  376.      * @since bbPress (r4579)
  377.      *
  378.      * @uses apply_filters() Calls 'bbp_search_widget_options' with the
  379.      *                        widget options
  380.      */
  381.     public function __construct() {
  382.         $widget_ops = apply_filters( 'bbp_search_widget_options', array(
  383.             'classname'   => 'widget_display_search',
  384.             'description' => __( 'The bbPress forum search form.', 'bbpress' )
  385.         ) );
  386.  
  387.         parent::__construct( false, __( '(bbPress) Forum Search Form', 'bbpress' ), $widget_ops );
  388.     }
  389.  
  390.     /**
  391.      * Register the widget
  392.      *
  393.      * @since bbPress (r4579)
  394.      *
  395.      * @uses register_widget()
  396.      */
  397.     public static function register_widget() {
  398.         register_widget( 'BBP_Search_Widget' );
  399.     }
  400.  
  401.     /**
  402.      * Displays the output, the search form
  403.      *
  404.      * @since bbPress (r4579)
  405.      *
  406.      * @uses apply_filters() Calls 'bbp_search_widget_title' with the title
  407.      * @uses get_template_part() To get the search form
  408.      */
  409.     public function widget( $args, $instance ) {
  410.  
  411.         // Get widget settings
  412.         $settings = $this->parse_settings( $instance );
  413.  
  414.         // Typical WordPress filter
  415.         $settings['title'] = apply_filters( 'widget_title',            $settings['title'], $instance, $this->id_base );
  416.  
  417.         // bbPress filter
  418.         $settings['title'] = apply_filters( 'bbp_search_widget_title', $settings['title'], $instance, $this->id_base );
  419.  
  420.         echo $args['before_widget'];
  421.  
  422.         if ( !empty( $settings['title'] ) ) {
  423.             echo $args['before_title'] . $settings['title'] . $args['after_title'];
  424.         }
  425.  
  426.         bbp_get_template_part( 'form', 'search' );
  427.  
  428.         echo $args['after_widget'];
  429.     }
  430.  
  431.     /**
  432.      * Update the widget options
  433.      *
  434.      * @since bbPress (r4579)
  435.      *
  436.      * @param array $new_instance The new instance options
  437.      * @param array $old_instance The old instance options
  438.      */
  439.     public function update( $new_instance, $old_instance ) {
  440.         $instance          = $old_instance;
  441.         $instance['title'] = strip_tags( $new_instance['title'] );
  442.  
  443.         return $instance;
  444.     }
  445.  
  446.     /**
  447.      * Output the search widget options form
  448.      *
  449.      * @since bbPress (r4579)
  450.      *
  451.      * @param $instance Instance
  452.      * @uses BBP_Search_Widget::get_field_id() To output the field id
  453.      * @uses BBP_Search_Widget::get_field_name() To output the field name
  454.      */
  455.     public function form( $instance ) {
  456.  
  457.         // Get widget settings
  458.         $settings = $this->parse_settings( $instance ); ?>
  459.  
  460.         <p>
  461.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
  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'] ); ?>" />
  463.             </label>
  464.         </p>
  465.  
  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' => __( 'Search Forums', 'bbpress' )
  480.         ), 'search_widget_settings' );
  481.     }
  482. }
  483.  
  484. /**
  485.  * bbPress Forum Widget
  486.  *
  487.  * Adds a widget which displays the forum list
  488.  *
  489.  * @since bbPress (r2653)
  490.  *
  491.  * @uses WP_Widget
  492.  */
  493. class BBP_Forums_Widget extends WP_Widget {
  494.  
  495.     /**
  496.      * bbPress Forum Widget
  497.      *
  498.      * Registers the forum widget
  499.      *
  500.      * @since bbPress (r2653)
  501.      *
  502.      * @uses apply_filters() Calls 'bbp_forums_widget_options' with the
  503.      *                        widget options
  504.      */
  505.     public function __construct() {
  506.         $widget_ops = apply_filters( 'bbp_forums_widget_options', array(
  507.             'classname'   => 'widget_display_forums',
  508.             'description' => __( 'A list of forums with an option to set the parent.', 'bbpress' )
  509.         ) );
  510.  
  511.         parent::__construct( false, __( '(bbPress) Forums List', 'bbpress' ), $widget_ops );
  512.     }
  513.  
  514.     /**
  515.      * Register the widget
  516.      *
  517.      * @since bbPress (r3389)
  518.      *
  519.      * @uses register_widget()
  520.      */
  521.     public static function register_widget() {
  522.         register_widget( 'BBP_Forums_Widget' );
  523.     }
  524.  
  525.     /**
  526.      * Displays the output, the forum list
  527.      *
  528.      * @since bbPress (r2653)
  529.      *
  530.      * @param mixed $args Arguments
  531.      * @param array $instance Instance
  532.      * @uses apply_filters() Calls 'bbp_forum_widget_title' with the title
  533.      * @uses get_option() To get the forums per page option
  534.      * @uses current_user_can() To check if the current user can read
  535.      *                           private() To resety name
  536.      * @uses bbp_has_forums() The main forum loop
  537.      * @uses bbp_forums() To check whether there are more forums available
  538.      *                     in the loop
  539.      * @uses bbp_the_forum() Loads up the current forum in the loop
  540.      * @uses bbp_forum_permalink() To display the forum permalink
  541.      * @uses bbp_forum_title() To display the forum title
  542.      */
  543.     public function widget( $args, $instance ) {
  544.  
  545.         // Get widget settings
  546.         $settings = $this->parse_settings( $instance );
  547.  
  548.         // Typical WordPress filter
  549.         $settings['title'] = apply_filters( 'widget_title',           $settings['title'], $instance, $this->id_base );
  550.  
  551.         // bbPress filter
  552.         $settings['title'] = apply_filters( 'bbp_forum_widget_title', $settings['title'], $instance, $this->id_base );
  553.  
  554.         // Note: private and hidden forums will be excluded via the
  555.         // bbp_pre_get_posts_exclude_forums filter and function.
  556.         $widget_query = new WP_Query( array(
  557.             'post_type'      => bbp_get_forum_post_type(),
  558.             'post_parent'    => $settings['parent_forum'],
  559.             'post_status'    => bbp_get_public_status_id(),
  560.             'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
  561.             'orderby'        => 'menu_order',
  562.             'order'          => 'ASC'
  563.         ) );
  564.  
  565.         // Bail if no posts
  566.         if ( ! $widget_query->have_posts() ) {
  567.             return;
  568.         }
  569.  
  570.         echo $args['before_widget'];
  571.  
  572.         if ( !empty( $settings['title'] ) ) {
  573.             echo $args['before_title'] . $settings['title'] . $args['after_title'];
  574.         } ?>
  575.  
  576.         <ul>
  577.  
  578.             <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?>
  579.  
  580.                 <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>
  581.  
  582.             <?php endwhile; ?>
  583.  
  584.         </ul>
  585.  
  586.         <?php echo $args['after_widget'];
  587.  
  588.         // Reset the $post global
  589.         wp_reset_postdata();
  590.     }
  591.  
  592.     /**
  593.      * Update the forum widget options
  594.      *
  595.      * @since bbPress (r2653)
  596.      *
  597.      * @param array $new_instance The new instance options
  598.      * @param array $old_instance The old instance options
  599.      */
  600.     public function update( $new_instance, $old_instance ) {
  601.         $instance                 = $old_instance;
  602.         $instance['title']        = strip_tags( $new_instance['title'] );
  603.         $instance['parent_forum'] = sanitize_text_field( $new_instance['parent_forum'] );
  604.  
  605.         // Force to any
  606.         if ( !empty( $instance['parent_forum'] ) && !is_numeric( $instance['parent_forum'] ) ) {
  607.             $instance['parent_forum'] = 'any';
  608.         }
  609.  
  610.         return $instance;
  611.     }
  612.  
  613.     /**
  614.      * Output the forum widget options form
  615.      *
  616.      * @since bbPress (r2653)
  617.      *
  618.      * @param $instance Instance
  619.      * @uses BBP_Forums_Widget::get_field_id() To output the field id
  620.      * @uses BBP_Forums_Widget::get_field_name() To output the field name
  621.      */
  622.     public function form( $instance ) {
  623.  
  624.         // Get widget settings
  625.         $settings = $this->parse_settings( $instance ); ?>
  626.  
  627.         <p>
  628.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
  629.                 <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'] ); ?>" />
  630.             </label>
  631.         </p>
  632.  
  633.         <p>
  634.             <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?>
  635.                 <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'] ); ?>" />
  636.             </label>
  637.  
  638.             <br />
  639.  
  640.             <small><?php _e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small>
  641.         </p>
  642.  
  643.         <?php
  644.     }
  645.  
  646.     /**
  647.      * Merge the widget settings into defaults array.
  648.      *
  649.      * @since bbPress (r4802)
  650.      *
  651.      * @param $instance Instance
  652.      * @uses bbp_parse_args() To merge widget settings into defaults
  653.      */
  654.     public function parse_settings( $instance = array() ) {
  655.         return bbp_parse_args( $instance, array(
  656.             'title'        => __( 'Forums', 'bbpress' ),
  657.             'parent_forum' => 0
  658.         ), 'forum_widget_settings' );
  659.     }
  660. }
  661.  
  662. /**
  663.  * bbPress Topic Widget
  664.  *
  665.  * Adds a widget which displays the topic list
  666.  *
  667.  * @since bbPress (r2653)
  668.  *
  669.  * @uses WP_Widget
  670.  */
  671. class BBP_Topics_Widget extends WP_Widget {
  672.  
  673.     /**
  674.      * bbPress Topic Widget
  675.      *
  676.      * Registers the topic widget
  677.      *
  678.      * @since bbPress (r2653)
  679.      *
  680.      * @uses apply_filters() Calls 'bbp_topics_widget_options' with the
  681.      *                        widget options
  682.      */
  683.     public function __construct() {
  684.         $widget_ops = apply_filters( 'bbp_topics_widget_options', array(
  685.             'classname'   => 'widget_display_topics',
  686.             'description' => __( 'A list of recent topics, sorted by popularity or freshness.', 'bbpress' )
  687.         ) );
  688.  
  689.         parent::__construct( false, __( '(bbPress) Recent Topics', 'bbpress' ), $widget_ops );
  690.     }
  691.  
  692.     /**
  693.      * Register the widget
  694.      *
  695.      * @since bbPress (r3389)
  696.      *
  697.      * @uses register_widget()
  698.      */
  699.     public static function register_widget() {
  700.         register_widget( 'BBP_Topics_Widget' );
  701.     }
  702.  
  703.     /**
  704.      * Displays the output, the topic list
  705.      *
  706.      * @since bbPress (r2653)
  707.      *
  708.      * @param mixed $args
  709.      * @param array $instance
  710.      * @uses apply_filters() Calls 'bbp_topic_widget_title' with the title
  711.      * @uses bbp_topic_permalink() To display the topic permalink
  712.      * @uses bbp_topic_title() To display the topic title
  713.      * @uses bbp_get_topic_last_active_time() To get the topic last active
  714.      *                                         time
  715.      * @uses bbp_get_topic_id() To get the topic id
  716.      */
  717.     public function widget( $args = array(), $instance = array() ) {
  718.  
  719.         // Get widget settings
  720.         $settings = $this->parse_settings( $instance );
  721.  
  722.         // Typical WordPress filter
  723.         $settings['title'] = apply_filters( 'widget_title',           $settings['title'], $instance, $this->id_base );
  724.  
  725.         // bbPress filter
  726.         $settings['title'] = apply_filters( 'bbp_topic_widget_title', $settings['title'], $instance, $this->id_base );
  727.  
  728.         // How do we want to order our results?
  729.         switch ( $settings['order_by'] ) {
  730.  
  731.             // Order by most recent replies
  732.             case 'freshness' :
  733.                 $topics_query = array(
  734.                     'post_type'      => bbp_get_topic_post_type(),
  735.                     'post_parent'    => $settings['parent_forum'],
  736.                     'posts_per_page' => (int) $settings['max_shown'],
  737.                     'post_status'    => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
  738.                     'show_stickies'  => false,
  739.                     'meta_key'       => '_bbp_last_active_time',
  740.                     'orderby'        => 'meta_value',
  741.                     'order'          => 'DESC',
  742.                 );
  743.                 break;
  744.  
  745.             // Order by total number of replies
  746.             case 'popular' :
  747.                 $topics_query = array(
  748.                     'post_type'      => bbp_get_topic_post_type(),
  749.                     'post_parent'    => $settings['parent_forum'],
  750.                     'posts_per_page' => (int) $settings['max_shown'],
  751.                     'post_status'    => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
  752.                     'show_stickies'  => false,
  753.                     'meta_key'       => '_bbp_reply_count',
  754.                     'orderby'        => 'meta_value',
  755.                     'order'          => 'DESC'
  756.                 );
  757.                 break;
  758.  
  759.             // Order by which topic was created most recently
  760.             case 'newness' :
  761.             default :
  762.                 $topics_query = array(
  763.                     'post_type'      => bbp_get_topic_post_type(),
  764.                     'post_parent'    => $settings['parent_forum'],
  765.                     'posts_per_page' => (int) $settings['max_shown'],
  766.                     'post_status'    => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
  767.                     'show_stickies'  => false,
  768.                     'order'          => 'DESC'
  769.                 );
  770.                 break;
  771.         }
  772.  
  773.         // Note: private and hidden forums will be excluded via the
  774.         // bbp_pre_get_posts_exclude_forums filter and function.
  775.         $widget_query = new WP_Query( $topics_query );
  776.  
  777.         // Bail if no topics are found
  778.         if ( ! $widget_query->have_posts() ) {
  779.             return;
  780.         }
  781.  
  782.         echo $args['before_widget'];
  783.  
  784.         if ( !empty( $settings['title'] ) ) {
  785.             echo $args['before_title'] . $settings['title'] . $args['after_title'];
  786.         } ?>
  787.  
  788.         <ul>
  789.  
  790.             <?php while ( $widget_query->have_posts() ) :
  791.  
  792.                 $widget_query->the_post();
  793.                 $topic_id    = bbp_get_topic_id( $widget_query->post->ID );
  794.                 $author_link = '';
  795.  
  796.                 // Maybe get the topic author
  797.                 if ( 'on' == $settings['show_user'] ) :
  798.                     $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) );
  799.                 endif; ?>
  800.  
  801.                 <li>
  802.                     <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>
  803.  
  804.                     <?php if ( ! empty( $author_link ) ) : ?>
  805.  
  806.                         <?php printf( _x( 'by %1$s', 'widgets', 'bbpress' ), '<span class="topic-author">' . $author_link . '</span>' ); ?>
  807.  
  808.                     <?php endif; ?>
  809.  
  810.                     <?php if ( 'on' == $settings['show_date'] ) : ?>
  811.  
  812.                         <div><?php bbp_topic_last_active_time( $topic_id ); ?></div>
  813.  
  814.                     <?php endif; ?>
  815.  
  816.                 </li>
  817.  
  818.             <?php endwhile; ?>
  819.  
  820.         </ul>
  821.  
  822.         <?php echo $args['after_widget'];
  823.  
  824.         // Reset the $post global
  825.         wp_reset_postdata();
  826.     }
  827.  
  828.     /**
  829.      * Update the topic widget options
  830.      *
  831.      * @since bbPress (r2653)
  832.      *
  833.      * @param array $new_instance The new instance options
  834.      * @param array $old_instance The old instance options
  835.      */
  836.     public function update( $new_instance = array(), $old_instance = array() ) {
  837.         $instance                 = $old_instance;
  838.         $instance['title']        = strip_tags( $new_instance['title'] );
  839.         $instance['order_by']     = strip_tags( $new_instance['order_by'] );
  840.         $instance['parent_forum'] = sanitize_text_field( $new_instance['parent_forum'] );
  841.         $instance['show_date']    = (bool) $new_instance['show_date'];
  842.         $instance['show_user']    = (bool) $new_instance['show_user'];
  843.         $instance['max_shown']    = (int) $new_instance['max_shown'];
  844.  
  845.         // Force to any
  846.         if ( !empty( $instance['parent_forum'] ) && !is_numeric( $instance['parent_forum'] ) ) {
  847.             $instance['parent_forum'] = 'any';
  848.         }
  849.  
  850.         return $instance;
  851.     }
  852.  
  853.     /**
  854.      * Output the topic widget options form
  855.      *
  856.      * @since bbPress (r2653)
  857.      *
  858.      * @param $instance Instance
  859.      * @uses BBP_Topics_Widget::get_field_id() To output the field id
  860.      * @uses BBP_Topics_Widget::get_field_name() To output the field name
  861.      */
  862.     public function form( $instance = array() ) {
  863.  
  864.         // Get widget settings
  865.         $settings = $this->parse_settings( $instance ); ?>
  866.  
  867.         <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>
  868.         <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>
  869.  
  870.         <p>
  871.             <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?>
  872.                 <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'] ); ?>" />
  873.             </label>
  874.  
  875.             <br />
  876.  
  877.             <small><?php _e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small>
  878.         </p>
  879.  
  880.         <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( true, $settings['show_date'] ); ?> value="1" /></label></p>
  881.         <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( true, $settings['show_user'] ); ?> value="1" /></label></p>
  882.  
  883.         <p>
  884.             <label for="<?php echo $this->get_field_id( 'order_by' ); ?>"><?php _e( 'Order By:',        'bbpress' ); ?></label>
  885.             <select name="<?php echo $this->get_field_name( 'order_by' ); ?>" id="<?php echo $this->get_field_name( 'order_by' ); ?>">
  886.                 <option <?php selected( $settings['order_by'], 'newness' );   ?> value="newness"><?php _e( 'Newest Topics',                'bbpress' ); ?></option>
  887.                 <option <?php selected( $settings['order_by'], 'popular' );   ?> value="popular"><?php _e( 'Popular Topics',               'bbpress' ); ?></option>
  888.                 <option <?php selected( $settings['order_by'], 'freshness' ); ?> value="freshness"><?php _e( 'Topics With Recent Replies', 'bbpress' ); ?></option>
  889.             </select>
  890.         </p>
  891.  
  892.         <?php
  893.     }
  894.  
  895.     /**
  896.      * Merge the widget settings into defaults array.
  897.      *
  898.      * @since bbPress (r4802)
  899.      *
  900.      * @param $instance Instance
  901.      * @uses bbp_parse_args() To merge widget options into defaults
  902.      */
  903.     public function parse_settings( $instance = array() ) {
  904.         return bbp_parse_args( $instance, array(
  905.             'title'        => __( 'Recent Topics', 'bbpress' ),
  906.             'max_shown'    => 5,
  907.             'show_date'    => false,
  908.             'show_user'    => false,
  909.             'parent_forum' => 'any',
  910.             'order_by'     => false
  911.         ), 'topic_widget_settings' );
  912.     }
  913. }
  914.  
  915. /**
  916.  * bbPress Stats Widget
  917.  *
  918.  * Adds a widget which displays the forum statistics
  919.  *
  920.  * @since bbPress (r4509)
  921.  *
  922.  * @uses WP_Widget
  923.  */
  924. class BBP_Stats_Widget extends WP_Widget {
  925.  
  926.     /**
  927.      * bbPress Stats Widget
  928.      *
  929.      * Registers the stats widget
  930.      *
  931.      * @since bbPress (r4509)
  932.      *
  933.      * @uses  apply_filters() Calls 'bbp_stats_widget_options' with the
  934.      *        widget options
  935.      */
  936.     public function __construct() {
  937.         $widget_ops = apply_filters( 'bbp_stats_widget_options', array(
  938.             'classname'   => 'widget_display_stats',
  939.             'description' => __( 'Some statistics from your forum.', 'bbpress' )
  940.         ) );
  941.  
  942.         parent::__construct( false, __( '(bbPress) Statistics', 'bbpress' ), $widget_ops );
  943.     }
  944.  
  945.     /**
  946.      * Register the widget
  947.      *
  948.      * @since bbPress (r4509)
  949.      *
  950.      * @uses register_widget()
  951.      */
  952.     public static function register_widget() {
  953.         register_widget( 'BBP_Stats_Widget' );
  954.     }
  955.  
  956.     /**
  957.      * Displays the output, the statistics
  958.      *
  959.      * @since bbPress (r4509)
  960.      *
  961.      * @param mixed $args     Arguments
  962.      * @param array $instance Instance
  963.      *
  964.      * @uses apply_filters() Calls 'bbp_stats_widget_title' with the title
  965.      * @uses bbp_get_template_part() To get the content-forum-statistics template
  966.      */
  967.     public function widget( $args = array(), $instance = array() ) {
  968.  
  969.         // Get widget settings
  970.         $settings = $this->parse_settings( $instance );
  971.  
  972.         // Typical WordPress filter
  973.         $settings['title'] = apply_filters( 'widget_title',           $settings['title'], $instance, $this->id_base );
  974.  
  975.         // bbPress widget title filter
  976.         $settings['title'] = apply_filters( 'bbp_stats_widget_title', $settings['title'], $instance, $this->id_base );
  977.  
  978.         echo $args['before_widget'];
  979.  
  980.         if ( !empty( $settings['title'] ) ) {
  981.             echo $args['before_title'] . $settings['title'] . $args['after_title'];
  982.         }
  983.  
  984.         bbp_get_template_part( 'content', 'statistics' );
  985.  
  986.         echo $args['after_widget'];
  987.     }
  988.  
  989.     /**
  990.      * Update the stats widget options
  991.      *
  992.      * @since bbPress (r4509)
  993.      *
  994.      * @param array $new_instance The new instance options
  995.      * @param array $old_instance The old instance options
  996.      *
  997.      * @return array
  998.      */
  999.     public function update( $new_instance, $old_instance ) {
  1000.         $instance          = $old_instance;
  1001.         $instance['title'] = strip_tags( $new_instance['title'] );
  1002.  
  1003.         return $instance;
  1004.     }
  1005.  
  1006.     /**
  1007.      * Output the stats widget options form
  1008.      *
  1009.      * @since bbPress (r4509)
  1010.      *
  1011.      * @param $instance
  1012.      *
  1013.      * @return string|void
  1014.      */
  1015.     public function form( $instance ) {
  1016.  
  1017.         // Get widget settings
  1018.         $settings = $this->parse_settings( $instance ); ?>
  1019.  
  1020.         <p>
  1021.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
  1022.                 <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'] ); ?>"/>
  1023.             </label>
  1024.         </p>
  1025.  
  1026.     <?php
  1027.     }
  1028.  
  1029.     /**
  1030.      * Merge the widget settings into defaults array.
  1031.      *
  1032.      * @since bbPress (r4802)
  1033.      *
  1034.      * @param $instance Instance
  1035.      * @uses bbp_parse_args() To merge widget settings into defaults
  1036.      */
  1037.     public function parse_settings( $instance = array() ) {
  1038.         return bbp_parse_args( $instance, array(
  1039.             'title' => __( 'Forum Statistics', 'bbpress' )
  1040.         ),
  1041.         'stats_widget_settings' );
  1042.     }
  1043. }
  1044.  
  1045. /**
  1046.  * bbPress Replies Widget
  1047.  *
  1048.  * Adds a widget which displays the replies list
  1049.  *
  1050.  * @since bbPress (r2653)
  1051.  *
  1052.  * @uses WP_Widget
  1053.  */
  1054. class BBP_Replies_Widget extends WP_Widget {
  1055.  
  1056.     /**
  1057.      * bbPress Replies Widget
  1058.      *
  1059.      * Registers the replies widget
  1060.      *
  1061.      * @since bbPress (r2653)
  1062.      *
  1063.      * @uses apply_filters() Calls 'bbp_replies_widget_options' with the
  1064.      *                        widget options
  1065.      */
  1066.     public function __construct() {
  1067.         $widget_ops = apply_filters( 'bbp_replies_widget_options', array(
  1068.             'classname'   => 'widget_display_replies',
  1069.             'description' => __( 'A list of the most recent replies.', 'bbpress' )
  1070.         ) );
  1071.  
  1072.         parent::__construct( false, __( '(bbPress) Recent Replies', 'bbpress' ), $widget_ops );
  1073.     }
  1074.  
  1075.     /**
  1076.      * Register the widget
  1077.      *
  1078.      * @since bbPress (r3389)
  1079.      *
  1080.      * @uses register_widget()
  1081.      */
  1082.     public static function register_widget() {
  1083.         register_widget( 'BBP_Replies_Widget' );
  1084.     }
  1085.  
  1086.     /**
  1087.      * Displays the output, the replies list
  1088.      *
  1089.      * @since bbPress (r2653)
  1090.      *
  1091.      * @param mixed $args
  1092.      * @param array $instance
  1093.      * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title
  1094.      * @uses bbp_get_reply_author_link() To get the reply author link
  1095.      * @uses bbp_get_reply_author() To get the reply author name
  1096.      * @uses bbp_get_reply_id() To get the reply id
  1097.      * @uses bbp_get_reply_url() To get the reply url
  1098.      * @uses bbp_get_reply_excerpt() To get the reply excerpt
  1099.      * @uses bbp_get_reply_topic_title() To get the reply topic title
  1100.      * @uses get_the_date() To get the date of the reply
  1101.      * @uses get_the_time() To get the time of the reply
  1102.      */
  1103.     public function widget( $args, $instance ) {
  1104.  
  1105.         // Get widget settings
  1106.         $settings = $this->parse_settings( $instance );
  1107.  
  1108.         // Typical WordPress filter
  1109.         $settings['title'] = apply_filters( 'widget_title',             $settings['title'], $instance, $this->id_base );
  1110.  
  1111.         // bbPress filter
  1112.         $settings['title'] = apply_filters( 'bbp_replies_widget_title', $settings['title'], $instance, $this->id_base );
  1113.  
  1114.         // Note: private and hidden forums will be excluded via the
  1115.         // bbp_pre_get_posts_exclude_forums filter and function.
  1116.         $widget_query = new WP_Query( array(
  1117.             'post_type'      => bbp_get_reply_post_type(),
  1118.             'post_status'    => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
  1119.             'posts_per_page' => (int) $settings['max_shown']
  1120.         ) );
  1121.  
  1122.         // Bail if no replies
  1123.         if ( ! $widget_query->have_posts() ) {
  1124.             return;
  1125.         }
  1126.  
  1127.         echo $args['before_widget'];
  1128.  
  1129.         if ( !empty( $settings['title'] ) ) {
  1130.             echo $args['before_title'] . $settings['title'] . $args['after_title'];
  1131.         } ?>
  1132.  
  1133.         <ul>
  1134.  
  1135.             <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?>
  1136.  
  1137.                 <li>
  1138.  
  1139.                     <?php
  1140.  
  1141.                     // Verify the reply ID
  1142.                     $reply_id   = bbp_get_reply_id( $widget_query->post->ID );
  1143.                     $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>';
  1144.  
  1145.                     // Only query user if showing them
  1146.                     if ( 'on' == $settings['show_user'] ) :
  1147.                         $author_link = bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) );
  1148.                     else :
  1149.                         $author_link = false;
  1150.                     endif;
  1151.  
  1152.                     // Reply author, link, and timestamp
  1153.                     if ( ( 'on' == $settings['show_date'] ) && !empty( $author_link ) ) :
  1154.  
  1155.                         // translators: 1: reply author, 2: reply link, 3: reply timestamp
  1156.                         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>' );
  1157.  
  1158.                     // Reply link and timestamp
  1159.                     elseif ( 'on' == $settings['show_date'] ) :
  1160.  
  1161.                         // translators: 1: reply link, 2: reply timestamp
  1162.                         printf( _x( '%1$s %2$s',         'widgets', 'bbpress' ), $reply_link,  '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>'              );
  1163.  
  1164.                     // Reply author and title
  1165.                     elseif ( !empty( $author_link ) ) :
  1166.  
  1167.                         // translators: 1: reply author, 2: reply link
  1168.                         printf( _x( '%1$s on %2$s',      'widgets', 'bbpress' ), $author_link, $reply_link                                                                 );
  1169.  
  1170.                     // Only the reply title
  1171.                     else :
  1172.  
  1173.                         // translators: 1: reply link
  1174.                         printf( _x( '%1$s',              'widgets', 'bbpress' ), $reply_link                                                                               );
  1175.  
  1176.                     endif;
  1177.  
  1178.                     ?>
  1179.  
  1180.                 </li>
  1181.  
  1182.             <?php endwhile; ?>
  1183.  
  1184.         </ul>
  1185.  
  1186.         <?php echo $args['after_widget'];
  1187.  
  1188.         // Reset the $post global
  1189.         wp_reset_postdata();
  1190.     }
  1191.  
  1192.     /**
  1193.      * Update the reply widget options
  1194.      *
  1195.      * @since bbPress (r2653)
  1196.      *
  1197.      * @param array $new_instance The new instance options
  1198.      * @param array $old_instance The old instance options
  1199.      */
  1200.     public function update( $new_instance = array(), $old_instance = array() ) {
  1201.         $instance              = $old_instance;
  1202.         $instance['title']     = strip_tags( $new_instance['title'] );
  1203.         $instance['show_date'] = (bool) $new_instance['show_date'];
  1204.         $instance['show_user'] = (bool) $new_instance['show_user'];
  1205.         $instance['max_shown'] = (int) $new_instance['max_shown'];
  1206.  
  1207.         return $instance;
  1208.     }
  1209.  
  1210.     /**
  1211.      * Output the reply widget options form
  1212.      *
  1213.      * @since bbPress (r2653)
  1214.      *
  1215.      * @param $instance Instance
  1216.      * @uses BBP_Replies_Widget::get_field_id() To output the field id
  1217.      * @uses BBP_Replies_Widget::get_field_name() To output the field name
  1218.      */
  1219.     public function form( $instance = array() ) {
  1220.  
  1221.         // Get widget settings
  1222.         $settings = $this->parse_settings( $instance ); ?>
  1223.  
  1224.         <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>
  1225.         <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>
  1226.         <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( true, $settings['show_date'] ); ?> value="1" /></label></p>
  1227.         <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( true, $settings['show_user'] ); ?> value="1" /></label></p>
  1228.  
  1229.         <?php
  1230.     }
  1231.  
  1232.     /**
  1233.      * Merge the widget settings into defaults array.
  1234.      *
  1235.      * @since bbPress (r4802)
  1236.      *
  1237.      * @param $instance Instance
  1238.      * @uses bbp_parse_args() To merge widget settings into defaults
  1239.      */
  1240.     public function parse_settings( $instance = array() ) {
  1241.         return bbp_parse_args( $instance, array(
  1242.             'title'     => __( 'Recent Replies', 'bbpress' ),
  1243.             'max_shown' => 5,
  1244.             'show_date' => false,
  1245.             'show_user' => false
  1246.         ),
  1247.         'replies_widget_settings' );
  1248.     }
  1249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement