| 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 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /*---------------------------------------------------------------------------------*/ |
|---|
| 20 | /* Online Users Widget */ |
|---|
| 21 | /*---------------------------------------------------------------------------------*/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | class BBP_Online_Widget extends WP_Widget { |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | function register_widget() { |
|---|
| 29 | register_widget('BBP_Online_Widget'); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | function BBP_Online_Widget() |
|---|
| 34 | { |
|---|
| 35 | $widget_ops = apply_filters( 'bbp_online_widget_options', array( |
|---|
| 36 | 'classname' => 'bbp_widget_online', |
|---|
| 37 | 'description' => __( 'The online users widget.', 'bbpress' ) |
|---|
| 38 | ) ); |
|---|
| 39 | |
|---|
| 40 | parent::WP_Widget( false, __( 'bbPress Online Widget', 'bbpress' ), $widget_ops ); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /** @see WP_Widget::widget */ |
|---|
| 44 | function widget( $args, $instance ) { |
|---|
| 45 | global $wpdb, $current_user, $bbp, $online_users_init; |
|---|
| 46 | |
|---|
| 47 | extract( $args ); |
|---|
| 48 | $time = $instance['time']; |
|---|
| 49 | |
|---|
| 50 | $title = apply_filters('widget_title', empty($instance['title']) ? __('BBP Online Users') : $instance['title'], $instance, $this->id_base); |
|---|
| 51 | echo $before_widget; |
|---|
| 52 | |
|---|
| 53 | if ( $title ) { |
|---|
| 54 | echo $before_title . $title . $after_title; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | if($bbp){ |
|---|
| 58 | echo '<ul>'; |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | if($bbp){ |
|---|
| 63 | if(is_user_logged_in()) { |
|---|
| 64 | $get_user_last_time = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %s AND meta_key = 'last_time' ", $current_user->ID ) ); |
|---|
| 65 | |
|---|
| 66 | if($get_user_last_time == '') { |
|---|
| 67 | $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $current_user->ID, "last_time", time() ) ); |
|---|
| 68 | } else { |
|---|
| 69 | $wpdb->update( $wpdb->usermeta, array( 'meta_value' => time()), array('meta_key' => 'last_time', 'user_id' => $current_user->ID ) ); |
|---|
| 70 | } |
|---|
| 71 | //echo $get_user_last_time; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | $users_online = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE meta_key = 'last_time' " ) ); |
|---|
| 75 | |
|---|
| 76 | //print_r($users_online); |
|---|
| 77 | |
|---|
| 78 | foreach($users_online as $user_umeta) { |
|---|
| 79 | |
|---|
| 80 | $get_user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE umeta_id = %s ", $user_umeta ) ); |
|---|
| 81 | $get_user_lat_time = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->usermeta WHERE umeta_id = %s ", $user_umeta ) ); |
|---|
| 82 | |
|---|
| 83 | if(time() - $get_user_lat_time < $time) { |
|---|
| 84 | //echo "User " . $get_user_id . " is online<br>"; |
|---|
| 85 | $avatar = get_avatar( $get_user_id, 14 ); |
|---|
| 86 | echo '<span><a href="' . bbp_get_user_profile_url($get_user_id) . '"> ' . $avatar . '</a>' . '<a href="' . bbp_get_user_profile_url($get_user_id) . '"> ' . get_the_author_meta( 'user_login', $get_user_id ). '</a></span>'; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | echo '</ul>'; |
|---|
| 92 | } else { |
|---|
| 93 | echo "<p>bbPress plugin not installed!</p>"; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | echo $after_widget; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | /** @see WP_Widget::update */ |
|---|
| 100 | function update( $new_instance, $old_instance ) { |
|---|
| 101 | $instance = $old_instance; |
|---|
| 102 | $instance['title'] = strip_tags($new_instance['title']); |
|---|
| 103 | $instance['time'] = strip_tags($new_instance['time']); |
|---|
| 104 | return $instance; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /** @see WP_Widget::form */ |
|---|
| 108 | function form( $instance ) { |
|---|
| 109 | if ( $instance ) { |
|---|
| 110 | $title = esc_attr( $instance[ 'title' ] ); |
|---|
| 111 | $time = esc_attr( $instance[ 'time' ] ); |
|---|
| 112 | } |
|---|
| 113 | else { |
|---|
| 114 | $title = __( 'Online Users', 'bbpress' ); |
|---|
| 115 | $time = '180'; |
|---|
| 116 | } |
|---|
| 117 | ?> |
|---|
| 118 | <p> |
|---|
| 119 | <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
|---|
| 120 | <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; ?>" /> |
|---|
| 121 | <label for="<?php echo $this->get_field_id('time'); ?>"><?php _e('Time (in seconds):'); ?></label> |
|---|
| 122 | <input class="widefat" id="<?php echo $this->get_field_id('time'); ?>" name="<?php echo $this->get_field_name('time'); ?>" type="text" value="<?php echo $time; ?>" /> |
|---|
| 123 | </p> |
|---|
| 124 | <?php |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | /** |
|---|
| 139 | * bbPress Login Widget |
|---|
| 140 | * |
|---|
| 141 | * Adds a widget which displays the login form |
|---|
| 142 | * |
|---|
| 143 | * @since bbPress (r2827) |
|---|
| 144 | * |
|---|
| 145 | * @uses WP_Widget |
|---|
| 146 | */ |
|---|
| 147 | class BBP_Login_Widget extends WP_Widget { |
|---|
| 148 | |
|---|
| 149 | /** |
|---|
| 150 | * Register the widget |
|---|
| 151 | * |
|---|
| 152 | * @since bbPress (r3389) |
|---|
| 153 | * |
|---|
| 154 | * @uses register_widget() |
|---|
| 155 | */ |
|---|
| 156 | function register_widget() { |
|---|
| 157 | register_widget( 'BBP_Login_Widget' ); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /** |
|---|
| 161 | * bbPress Login Widget |
|---|
| 162 | * |
|---|
| 163 | * Registers the login widget |
|---|
| 164 | * |
|---|
| 165 | * @since bbPress (r2827) |
|---|
| 166 | * |
|---|
| 167 | * @uses apply_filters() Calls 'bbp_login_widget_options' with the |
|---|
| 168 | * widget options |
|---|
| 169 | */ |
|---|
| 170 | function BBP_Login_Widget() { |
|---|
| 171 | $widget_ops = apply_filters( 'bbp_login_widget_options', array( |
|---|
| 172 | 'classname' => 'bbp_widget_login', |
|---|
| 173 | 'description' => __( 'The login widget.', 'bbpress' ) |
|---|
| 174 | ) ); |
|---|
| 175 | |
|---|
| 176 | parent::WP_Widget( false, __( 'bbPress Login Widget', 'bbpress' ), $widget_ops ); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | /** |
|---|
| 180 | * Displays the output, the login form |
|---|
| 181 | * |
|---|
| 182 | * @since bbPress (r2827) |
|---|
| 183 | * |
|---|
| 184 | * @param mixed $args Arguments |
|---|
| 185 | * @param array $instance Instance |
|---|
| 186 | * @uses apply_filters() Calls 'bbp_login_widget_title' with the title |
|---|
| 187 | * @uses get_template_part() To get the login/logged in form |
|---|
| 188 | */ |
|---|
| 189 | function widget( $args, $instance ) { |
|---|
| 190 | extract( $args ); |
|---|
| 191 | |
|---|
| 192 | $title = apply_filters( 'bbp_login_widget_title', $instance['title'] ); |
|---|
| 193 | $register = apply_filters( 'bbp_login_widget_register', $instance['register'] ); |
|---|
| 194 | $lostpass = apply_filters( 'bbp_login_widget_lostpass', $instance['lostpass'] ); |
|---|
| 195 | |
|---|
| 196 | echo $before_widget; |
|---|
| 197 | |
|---|
| 198 | if ( !empty( $title ) ) |
|---|
| 199 | echo $before_title . $title . $after_title; |
|---|
| 200 | |
|---|
| 201 | if ( !is_user_logged_in() ) : ?> |
|---|
| 202 | |
|---|
| 203 | <form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form"> |
|---|
| 204 | <fieldset> |
|---|
| 205 | <legend><?php _e( 'Log In', 'bbpress' ); ?></legend> |
|---|
| 206 | |
|---|
| 207 | <div class="bbp-username"> |
|---|
| 208 | <label for="user_login"><?php _e( 'Username', 'bbpress' ); ?>: </label> |
|---|
| 209 | <input type="text" name="log" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" id="user_login" tabindex="<?php bbp_tab_index(); ?>" /> |
|---|
| 210 | </div> |
|---|
| 211 | |
|---|
| 212 | <div class="bbp-password"> |
|---|
| 213 | <label for="user_pass"><?php _e( 'Password', 'bbpress' ); ?>: </label> |
|---|
| 214 | <input type="password" name="pwd" value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" tabindex="<?php bbp_tab_index(); ?>" /> |
|---|
| 215 | </div> |
|---|
| 216 | |
|---|
| 217 | <div class="bbp-remember-me"> |
|---|
| 218 | <input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ), true, true ); ?> id="rememberme" tabindex="<?php bbp_tab_index(); ?>" /> |
|---|
| 219 | <label for="rememberme"><?php _e( 'Remember Me', 'bbpress' ); ?></label> |
|---|
| 220 | </div> |
|---|
| 221 | |
|---|
| 222 | <div class="bbp-submit-wrapper"> |
|---|
| 223 | |
|---|
| 224 | <?php do_action( 'login_form' ); ?> |
|---|
| 225 | |
|---|
| 226 | <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> |
|---|
| 227 | |
|---|
| 228 | <?php bbp_user_login_fields(); ?> |
|---|
| 229 | |
|---|
| 230 | </div> |
|---|
| 231 | |
|---|
| 232 | <?php if ( !empty( $register ) || !empty( $lostpass ) ) : ?> |
|---|
| 233 | |
|---|
| 234 | <div class="bbp-login-links"> |
|---|
| 235 | |
|---|
| 236 | <?php if ( !empty( $register ) ) : ?> |
|---|
| 237 | |
|---|
| 238 | <a href="<?php echo esc_url( $register ); ?>" title="<?php _e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php _e( 'Register', 'bbpress' ); ?></a> |
|---|
| 239 | |
|---|
| 240 | <?php endif; ?> |
|---|
| 241 | |
|---|
| 242 | <?php if ( !empty( $lostpass ) ) : ?> |
|---|
| 243 | |
|---|
| 244 | <a href="<?php echo esc_url( $lostpass ); ?>" title="<?php _e( 'Lost Password', 'bbpress' ); ?>" class="bbp-lostpass-link"><?php _e( 'Lost Password', 'bbpress' ); ?></a> |
|---|
| 245 | |
|---|
| 246 | <?php endif; ?> |
|---|
| 247 | |
|---|
| 248 | </div> |
|---|
| 249 | |
|---|
| 250 | <?php endif; ?> |
|---|
| 251 | |
|---|
| 252 | </fieldset> |
|---|
| 253 | </form> |
|---|
| 254 | |
|---|
| 255 | <?php else : ?> |
|---|
| 256 | |
|---|
| 257 | <div class="bbp-logged-in"> |
|---|
| 258 | <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> |
|---|
| 259 | <h4><?php bbp_user_profile_link( bbp_get_current_user_id() ); ?></h4> |
|---|
| 260 | |
|---|
| 261 | <?php bbp_logout_link(); ?> |
|---|
| 262 | </div> |
|---|
| 263 | |
|---|
| 264 | <?php endif; |
|---|
| 265 | |
|---|
| 266 | echo $after_widget; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | /** |
|---|
| 270 | * Update the login widget options |
|---|
| 271 | * |
|---|
| 272 | * @since bbPress (r2827) |
|---|
| 273 | * |
|---|
| 274 | * @param array $new_instance The new instance options |
|---|
| 275 | * @param array $old_instance The old instance options |
|---|
| 276 | */ |
|---|
| 277 | function update( $new_instance, $old_instance ) { |
|---|
| 278 | $instance = $old_instance; |
|---|
| 279 | $instance['title'] = strip_tags( $new_instance['title'] ); |
|---|
| 280 | $instance['register'] = esc_url( $new_instance['register'] ); |
|---|
| 281 | $instance['lostpass'] = esc_url( $new_instance['lostpass'] ); |
|---|
| 282 | |
|---|
| 283 | return $instance; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | /** |
|---|
| 287 | * Output the login widget options form |
|---|
| 288 | * |
|---|
| 289 | * @since bbPress (r2827) |
|---|
| 290 | * |
|---|
| 291 | * @param $instance Instance |
|---|
| 292 | * @uses BBP_Login_Widget::get_field_id() To output the field id |
|---|
| 293 | * @uses BBP_Login_Widget::get_field_name() To output the field name |
|---|
| 294 | */ |
|---|
| 295 | function form( $instance ) { |
|---|
| 296 | |
|---|
| 297 | // Form values |
|---|
| 298 | $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|---|
| 299 | $register = !empty( $instance['register'] ) ? esc_attr( $instance['register'] ) : ''; |
|---|
| 300 | $lostpass = !empty( $instance['lostpass'] ) ? esc_attr( $instance['lostpass'] ) : ''; |
|---|
| 301 | |
|---|
| 302 | ?> |
|---|
| 303 | |
|---|
| 304 | <p> |
|---|
| 305 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> |
|---|
| 306 | <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> |
|---|
| 307 | </p> |
|---|
| 308 | |
|---|
| 309 | <p> |
|---|
| 310 | <label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php _e( 'Register URI:', 'bbpress' ); ?> |
|---|
| 311 | <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> |
|---|
| 312 | </p> |
|---|
| 313 | |
|---|
| 314 | <p> |
|---|
| 315 | <label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php _e( 'Lost Password URI:', 'bbpress' ); ?> |
|---|
| 316 | <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> |
|---|
| 317 | </p> |
|---|
| 318 | |
|---|
| 319 | <?php |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | /** |
|---|
| 324 | * bbPress Views Widget |
|---|
| 325 | * |
|---|
| 326 | * Adds a widget which displays the view list |
|---|
| 327 | * |
|---|
| 328 | * @since bbPress (r3020) |
|---|
| 329 | * |
|---|
| 330 | * @uses WP_Widget |
|---|
| 331 | */ |
|---|
| 332 | class BBP_Views_Widget extends WP_Widget { |
|---|
| 333 | |
|---|
| 334 | /** |
|---|
| 335 | * Register the widget |
|---|
| 336 | * |
|---|
| 337 | * @since bbPress (r3389) |
|---|
| 338 | * |
|---|
| 339 | * @uses register_widget() |
|---|
| 340 | */ |
|---|
| 341 | function register_widget() { |
|---|
| 342 | register_widget( 'BBP_Views_Widget' ); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | /** |
|---|
| 346 | * bbPress View Widget |
|---|
| 347 | * |
|---|
| 348 | * Registers the view widget |
|---|
| 349 | * |
|---|
| 350 | * @since bbPress (r3020) |
|---|
| 351 | * |
|---|
| 352 | * @uses apply_filters() Calls 'bbp_views_widget_options' with the |
|---|
| 353 | * widget options |
|---|
| 354 | */ |
|---|
| 355 | function BBP_Views_Widget() { |
|---|
| 356 | $widget_ops = apply_filters( 'bbp_views_widget_options', array( |
|---|
| 357 | 'classname' => 'widget_display_views', |
|---|
| 358 | 'description' => __( 'A list of views.', 'bbpress' ) |
|---|
| 359 | ) ); |
|---|
| 360 | |
|---|
| 361 | parent::WP_Widget( false, __( 'bbPress View List', 'bbpress' ), $widget_ops ); |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | /** |
|---|
| 365 | * Displays the output, the view list |
|---|
| 366 | * |
|---|
| 367 | * @since bbPress (r3020) |
|---|
| 368 | * |
|---|
| 369 | * @param mixed $args Arguments |
|---|
| 370 | * @param array $instance Instance |
|---|
| 371 | * @uses apply_filters() Calls 'bbp_view_widget_title' with the title |
|---|
| 372 | * @uses bbp_get_views() To get the views |
|---|
| 373 | * @uses bbp_view_url() To output the view url |
|---|
| 374 | * @uses bbp_view_title() To output the view title |
|---|
| 375 | */ |
|---|
| 376 | function widget( $args, $instance ) { |
|---|
| 377 | |
|---|
| 378 | // Only output widget contents if views exist |
|---|
| 379 | if ( bbp_get_views() ) : |
|---|
| 380 | |
|---|
| 381 | extract( $args ); |
|---|
| 382 | |
|---|
| 383 | $title = apply_filters( 'bbp_view_widget_title', $instance['title'] ); |
|---|
| 384 | |
|---|
| 385 | echo $before_widget; |
|---|
| 386 | echo $before_title . $title . $after_title; ?> |
|---|
| 387 | |
|---|
| 388 | <ul> |
|---|
| 389 | |
|---|
| 390 | <?php foreach ( bbp_get_views() as $view => $args ) : ?> |
|---|
| 391 | |
|---|
| 392 | <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> |
|---|
| 393 | |
|---|
| 394 | <?php endforeach; ?> |
|---|
| 395 | |
|---|
| 396 | </ul> |
|---|
| 397 | |
|---|
| 398 | <?php echo $after_widget; |
|---|
| 399 | |
|---|
| 400 | endif; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | /** |
|---|
| 404 | * Update the view widget options |
|---|
| 405 | * |
|---|
| 406 | * @since bbPress (r3020) |
|---|
| 407 | * |
|---|
| 408 | * @param array $new_instance The new instance options |
|---|
| 409 | * @param array $old_instance The old instance options |
|---|
| 410 | */ |
|---|
| 411 | function update( $new_instance, $old_instance ) { |
|---|
| 412 | $instance = $old_instance; |
|---|
| 413 | $instance['title'] = strip_tags( $new_instance['title'] ); |
|---|
| 414 | |
|---|
| 415 | return $instance; |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | /** |
|---|
| 419 | * Output the view widget options form |
|---|
| 420 | * |
|---|
| 421 | * @since bbPress (r3020) |
|---|
| 422 | * |
|---|
| 423 | * @param $instance Instance |
|---|
| 424 | * @uses BBP_Views_Widget::get_field_id() To output the field id |
|---|
| 425 | * @uses BBP_Views_Widget::get_field_name() To output the field name |
|---|
| 426 | */ |
|---|
| 427 | function form( $instance ) { |
|---|
| 428 | $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?> |
|---|
| 429 | |
|---|
| 430 | <p> |
|---|
| 431 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> |
|---|
| 432 | <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; ?>" /> |
|---|
| 433 | </label> |
|---|
| 434 | </p> |
|---|
| 435 | |
|---|
| 436 | <?php |
|---|
| 437 | } |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | /** |
|---|
| 441 | * bbPress Forum Widget |
|---|
| 442 | * |
|---|
| 443 | * Adds a widget which displays the forum list |
|---|
| 444 | * |
|---|
| 445 | * @since bbPress (r2653) |
|---|
| 446 | * |
|---|
| 447 | * @uses WP_Widget |
|---|
| 448 | */ |
|---|
| 449 | class BBP_Forums_Widget extends WP_Widget { |
|---|
| 450 | |
|---|
| 451 | /** |
|---|
| 452 | * Register the widget |
|---|
| 453 | * |
|---|
| 454 | * @since bbPress (r3389) |
|---|
| 455 | * |
|---|
| 456 | * @uses register_widget() |
|---|
| 457 | */ |
|---|
| 458 | function register_widget() { |
|---|
| 459 | register_widget( 'BBP_Forums_Widget' ); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | /** |
|---|
| 463 | * bbPress Forum Widget |
|---|
| 464 | * |
|---|
| 465 | * Registers the forum widget |
|---|
| 466 | * |
|---|
| 467 | * @since bbPress (r2653) |
|---|
| 468 | * |
|---|
| 469 | * @uses apply_filters() Calls 'bbp_forums_widget_options' with the |
|---|
| 470 | * widget options |
|---|
| 471 | */ |
|---|
| 472 | function BBP_Forums_Widget() { |
|---|
| 473 | $widget_ops = apply_filters( 'bbp_forums_widget_options', array( |
|---|
| 474 | 'classname' => 'widget_display_forums', |
|---|
| 475 | 'description' => __( 'A list of forums.', 'bbpress' ) |
|---|
| 476 | ) ); |
|---|
| 477 | |
|---|
| 478 | parent::WP_Widget( false, __( 'bbPress Forum List', 'bbpress' ), $widget_ops ); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | /** |
|---|
| 482 | * Displays the output, the forum list |
|---|
| 483 | * |
|---|
| 484 | * @since bbPress (r2653) |
|---|
| 485 | * |
|---|
| 486 | * @param mixed $args Arguments |
|---|
| 487 | * @param array $instance Instance |
|---|
| 488 | * @uses apply_filters() Calls 'bbp_forum_widget_title' with the title |
|---|
| 489 | * @uses get_option() To get the forums per page option |
|---|
| 490 | * @uses current_user_can() To check if the current user can read |
|---|
| 491 | * private() To resety name |
|---|
| 492 | * @uses bbp_set_query_name() To set the query name to 'bbp_widget' |
|---|
| 493 | * @uses bbp_reset_query_name() To reset the query name |
|---|
| 494 | * @uses bbp_has_forums() The main forum loop |
|---|
| 495 | * @uses bbp_forums() To check whether there are more forums available |
|---|
| 496 | * in the loop |
|---|
| 497 | * @uses bbp_the_forum() Loads up the current forum in the loop |
|---|
| 498 | * @uses bbp_forum_permalink() To display the forum permalink |
|---|
| 499 | * @uses bbp_forum_title() To display the forum title |
|---|
| 500 | */ |
|---|
| 501 | function widget( $args, $instance ) { |
|---|
| 502 | extract( $args ); |
|---|
| 503 | |
|---|
| 504 | $title = apply_filters( 'bbp_forum_widget_title', $instance['title'] ); |
|---|
| 505 | $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : '0'; |
|---|
| 506 | |
|---|
| 507 | $forums_query = array( |
|---|
| 508 | 'post_parent' => $parent_forum, |
|---|
| 509 | 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ), |
|---|
| 510 | 'orderby' => 'menu_order', |
|---|
| 511 | 'order' => 'ASC' |
|---|
| 512 | ); |
|---|
| 513 | |
|---|
| 514 | bbp_set_query_name( 'bbp_widget' ); |
|---|
| 515 | |
|---|
| 516 | if ( bbp_has_forums( $forums_query ) ) : |
|---|
| 517 | |
|---|
| 518 | echo $before_widget; |
|---|
| 519 | echo $before_title . $title . $after_title; ?> |
|---|
| 520 | |
|---|
| 521 | <ul> |
|---|
| 522 | |
|---|
| 523 | <?php while ( bbp_forums() ) : bbp_the_forum(); ?> |
|---|
| 524 | |
|---|
| 525 | <li><a class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>" title="<?php bbp_forum_title(); ?>"><?php bbp_forum_title(); ?></a></li> |
|---|
| 526 | |
|---|
| 527 | <?php endwhile; ?> |
|---|
| 528 | |
|---|
| 529 | </ul> |
|---|
| 530 | |
|---|
| 531 | <?php echo $after_widget; |
|---|
| 532 | |
|---|
| 533 | endif; |
|---|
| 534 | |
|---|
| 535 | bbp_reset_query_name(); |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | /** |
|---|
| 539 | * Update the forum widget options |
|---|
| 540 | * |
|---|
| 541 | * @since bbPress (r2653) |
|---|
| 542 | * |
|---|
| 543 | * @param array $new_instance The new instance options |
|---|
| 544 | * @param array $old_instance The old instance options |
|---|
| 545 | */ |
|---|
| 546 | function update( $new_instance, $old_instance ) { |
|---|
| 547 | $instance = $old_instance; |
|---|
| 548 | $instance['title'] = strip_tags( $new_instance['title'] ); |
|---|
| 549 | $instance['parent_forum'] = $new_instance['parent_forum']; |
|---|
| 550 | |
|---|
| 551 | // Force to any |
|---|
| 552 | if ( !empty( $instance['parent_forum'] ) && !is_numeric( $instance['parent_forum'] ) ) { |
|---|
| 553 | $instance['parent_forum'] = 'any'; |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | return $instance; |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | /** |
|---|
| 560 | * Output the forum widget options form |
|---|
| 561 | * |
|---|
| 562 | * @since bbPress (r2653) |
|---|
| 563 | * |
|---|
| 564 | * @param $instance Instance |
|---|
| 565 | * @uses BBP_Forums_Widget::get_field_id() To output the field id |
|---|
| 566 | * @uses BBP_Forums_Widget::get_field_name() To output the field name |
|---|
| 567 | */ |
|---|
| 568 | function form( $instance ) { |
|---|
| 569 | $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|---|
| 570 | $parent_forum = !empty( $instance['parent_forum'] ) ? esc_attr( $instance['parent_forum'] ) : '0'; ?> |
|---|
| 571 | |
|---|
| 572 | <p> |
|---|
| 573 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> |
|---|
| 574 | <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; ?>" /> |
|---|
| 575 | </label> |
|---|
| 576 | </p> |
|---|
| 577 | |
|---|
| 578 | <p> |
|---|
| 579 | <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?> |
|---|
| 580 | <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; ?>" /> |
|---|
| 581 | </label> |
|---|
| 582 | |
|---|
| 583 | <br /> |
|---|
| 584 | |
|---|
| 585 | <small><?php _e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small> |
|---|
| 586 | </p> |
|---|
| 587 | |
|---|
| 588 | <?php |
|---|
| 589 | } |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | /** |
|---|
| 593 | * bbPress Topic Widget |
|---|
| 594 | * |
|---|
| 595 | * Adds a widget which displays the topic list |
|---|
| 596 | * |
|---|
| 597 | * @since bbPress (r2653) |
|---|
| 598 | * |
|---|
| 599 | * @uses WP_Widget |
|---|
| 600 | */ |
|---|
| 601 | class BBP_Topics_Widget extends WP_Widget { |
|---|
| 602 | |
|---|
| 603 | /** |
|---|
| 604 | * Register the widget |
|---|
| 605 | * |
|---|
| 606 | * @since bbPress (r3389) |
|---|
| 607 | * |
|---|
| 608 | * @uses register_widget() |
|---|
| 609 | */ |
|---|
| 610 | function register_widget() { |
|---|
| 611 | register_widget( 'BBP_Topics_Widget' ); |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | /** |
|---|
| 615 | * bbPress Topic Widget |
|---|
| 616 | * |
|---|
| 617 | * Registers the topic widget |
|---|
| 618 | * |
|---|
| 619 | * @since bbPress (r2653) |
|---|
| 620 | * |
|---|
| 621 | * @uses apply_filters() Calls 'bbp_topics_widget_options' with the |
|---|
| 622 | * widget options |
|---|
| 623 | */ |
|---|
| 624 | function BBP_Topics_Widget() { |
|---|
| 625 | $widget_ops = apply_filters( 'bbp_topics_widget_options', array( |
|---|
| 626 | 'classname' => 'widget_display_topics', |
|---|
| 627 | 'description' => __( 'A list of recent topics, sorted by popularity or freshness.', 'bbpress' ) |
|---|
| 628 | ) ); |
|---|
| 629 | |
|---|
| 630 | parent::WP_Widget( false, __( 'bbPress Topics List', 'bbpress' ), $widget_ops ); |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | /** |
|---|
| 634 | * Displays the output, the topic list |
|---|
| 635 | * |
|---|
| 636 | * @since bbPress (r2653) |
|---|
| 637 | * |
|---|
| 638 | * @param mixed $args |
|---|
| 639 | * @param array $instance |
|---|
| 640 | * @uses apply_filters() Calls 'bbp_topic_widget_title' with the title |
|---|
| 641 | * @uses bbp_set_query_name() To set the query name to 'bbp_widget' |
|---|
| 642 | * @uses bbp_reset_query_name() To reset the query name |
|---|
| 643 | * @uses bbp_has_topics() The main topic loop |
|---|
| 644 | * @uses bbp_topics() To check whether there are more topics available |
|---|
| 645 | * in the loop |
|---|
| 646 | * @uses bbp_the_topic() Loads up the current topic in the loop |
|---|
| 647 | * @uses bbp_topic_permalink() To display the topic permalink |
|---|
| 648 | * @uses bbp_topic_title() To display the topic title |
|---|
| 649 | * @uses bbp_get_topic_last_active_time() To get the topic last active |
|---|
| 650 | * time |
|---|
| 651 | * @uses bbp_get_topic_id() To get the topic id |
|---|
| 652 | * @uses bbp_get_topic_reply_count() To get the topic reply count |
|---|
| 653 | */ |
|---|
| 654 | function widget( $args, $instance ) { |
|---|
| 655 | |
|---|
| 656 | extract( $args ); |
|---|
| 657 | |
|---|
| 658 | $title = apply_filters( 'bbp_topic_widget_title', $instance['title'] ); |
|---|
| 659 | $max_shown = !empty( $instance['max_shown'] ) ? (int) $instance['max_shown'] : 5; |
|---|
| 660 | $show_date = !empty( $instance['show_date'] ) ? 'on' : false; |
|---|
| 661 | $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 'any'; |
|---|
| 662 | $pop_check = ( $instance['pop_check'] < $max_shown || empty( $instance['pop_check'] ) ) ? -1 : $instance['pop_check']; |
|---|
| 663 | |
|---|
| 664 | // Query defaults |
|---|
| 665 | $topics_query = array( |
|---|
| 666 | 'author' => 0, |
|---|
| 667 | 'post_parent' => $parent_forum, |
|---|
| 668 | 'posts_per_page' => $max_shown > $pop_check ? $max_shown : $pop_check, |
|---|
| 669 | 'posts_per_page' => $max_shown, |
|---|
| 670 | 'show_stickies' => false, |
|---|
| 671 | 'order' => 'DESC', |
|---|
| 672 | ); |
|---|
| 673 | |
|---|
| 674 | bbp_set_query_name( 'bbp_widget' ); |
|---|
| 675 | |
|---|
| 676 | // Topics exist |
|---|
| 677 | if ( bbp_has_topics( $topics_query ) ) : |
|---|
| 678 | |
|---|
| 679 | // Sort by time |
|---|
| 680 | if ( $pop_check < $max_shown ) : |
|---|
| 681 | |
|---|
| 682 | echo $before_widget; |
|---|
| 683 | echo $before_title . $title . $after_title; ?> |
|---|
| 684 | |
|---|
| 685 | <ul> |
|---|
| 686 | |
|---|
| 687 | <?php while ( bbp_topics() ) : bbp_the_topic(); ?> |
|---|
| 688 | |
|---|
| 689 | <li> |
|---|
| 690 | <a class="bbp-forum-title" href="<?php bbp_topic_permalink(); ?>" title="<?php bbp_topic_title(); ?>"><?php bbp_topic_title(); ?></a><?php if ( $show_date == 'on' ) printf( __( ', %s ago', 'bbpress' ), bbp_get_topic_last_active_time() ); ?> |
|---|
| 691 | </li> |
|---|
| 692 | |
|---|
| 693 | <?php endwhile; ?> |
|---|
| 694 | |
|---|
| 695 | </ul> |
|---|
| 696 | |
|---|
| 697 | <?php echo $after_widget; |
|---|
| 698 | |
|---|
| 699 | // Sort by popularity |
|---|
| 700 | elseif ( $pop_check >= $max_shown ) : |
|---|
| 701 | |
|---|
| 702 | echo $before_widget; |
|---|
| 703 | echo $before_title . $title . $after_title; |
|---|
| 704 | |
|---|
| 705 | while ( bbp_topics() ) { |
|---|
| 706 | bbp_the_topic(); |
|---|
| 707 | $topics[bbp_get_topic_id()] = bbp_get_topic_reply_count(); |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | arsort( $topics ); |
|---|
| 711 | $topic_count = 1; |
|---|
| 712 | |
|---|
| 713 | ?> |
|---|
| 714 | |
|---|
| 715 | <ul> |
|---|
| 716 | |
|---|
| 717 | <?php foreach ( $topics as $topic_id => $topic_reply_count ) : ?> |
|---|
| 718 | |
|---|
| 719 | <li><a class="bbp-topic-title" href="<?php bbp_topic_permalink( $topic_id ); ?>" title="<?php bbp_topic_title( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a><?php if ( $show_date == 'on' ) printf( __( ', %s ago', 'bbpress' ), bbp_get_topic_last_active_time( $topic_id ) ); ?></li> |
|---|
| 720 | |
|---|
| 721 | <?php |
|---|
| 722 | |
|---|
| 723 | $topic_count++; |
|---|
| 724 | |
|---|
| 725 | if ( $topic_count > $max_shown ) |
|---|
| 726 | break; |
|---|
| 727 | |
|---|
| 728 | endforeach; ?> |
|---|
| 729 | |
|---|
| 730 | </ul> |
|---|
| 731 | |
|---|
| 732 | <?php echo $after_widget; |
|---|
| 733 | |
|---|
| 734 | endif; |
|---|
| 735 | endif; |
|---|
| 736 | |
|---|
| 737 | bbp_reset_query_name(); |
|---|
| 738 | |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | /** |
|---|
| 742 | * Update the forum widget options |
|---|
| 743 | * |
|---|
| 744 | * @since bbPress (r2653) |
|---|
| 745 | * |
|---|
| 746 | * @param array $new_instance The new instance options |
|---|
| 747 | * @param array $old_instance The old instance options |
|---|
| 748 | */ |
|---|
| 749 | function update( $new_instance, $old_instance ) { |
|---|
| 750 | $instance = $old_instance; |
|---|
| 751 | $instance['title'] = strip_tags( $new_instance['title'] ); |
|---|
| 752 | $instance['max_shown'] = strip_tags( $new_instance['max_shown'] ); |
|---|
| 753 | $instance['show_date'] = strip_tags( $new_instance['show_date'] ); |
|---|
| 754 | $instance['pop_check'] = strip_tags( $new_instance['pop_check'] ); |
|---|
| 755 | |
|---|
| 756 | return $instance; |
|---|
| 757 | } |
|---|
| 758 | |
|---|
| 759 | /** |
|---|
| 760 | * Output the topic widget options form |
|---|
| 761 | * |
|---|
| 762 | * @since bbPress (r2653) |
|---|
| 763 | * |
|---|
| 764 | * @param $instance Instance |
|---|
| 765 | * @uses BBP_Topics_Widget::get_field_id() To output the field id |
|---|
| 766 | * @uses BBP_Topics_Widget::get_field_name() To output the field name |
|---|
| 767 | */ |
|---|
| 768 | function form( $instance ) { |
|---|
| 769 | $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|---|
| 770 | $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : ''; |
|---|
| 771 | $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; |
|---|
| 772 | $pop_check = !empty( $instance['pop_check'] ) ? esc_attr( $instance['pop_check'] ) : ''; ?> |
|---|
| 773 | |
|---|
| 774 | <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> |
|---|
| 775 | <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> |
|---|
| 776 | <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> |
|---|
| 777 | <p> |
|---|
| 778 | <label for="<?php echo $this->get_field_id( 'pop_check' ); ?>"><?php _e( 'Popularity check:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'pop_check' ); ?>" name="<?php echo $this->get_field_name( 'pop_check' ); ?>" type="text" value="<?php echo $pop_check; ?>" /></label> |
|---|
| 779 | <br /><small><?php _e( 'Number of topics back to check reply count to determine popularity. A number less than the maximum number of topics to show disables the check.', 'bbpress' ); ?></small> |
|---|
| 780 | </p> |
|---|
| 781 | |
|---|
| 782 | <?php |
|---|
| 783 | } |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | /** |
|---|
| 787 | * bbPress Replies Widget |
|---|
| 788 | * |
|---|
| 789 | * Adds a widget which displays the replies list |
|---|
| 790 | * |
|---|
| 791 | * @since bbPress (r2653) |
|---|
| 792 | * |
|---|
| 793 | * @uses WP_Widget |
|---|
| 794 | */ |
|---|
| 795 | class BBP_Replies_Widget extends WP_Widget { |
|---|
| 796 | |
|---|
| 797 | /** |
|---|
| 798 | * Register the widget |
|---|
| 799 | * |
|---|
| 800 | * @since bbPress (r3389) |
|---|
| 801 | * |
|---|
| 802 | * @uses register_widget() |
|---|
| 803 | */ |
|---|
| 804 | function register_widget() { |
|---|
| 805 | register_widget( 'BBP_Replies_Widget' ); |
|---|
| 806 | } |
|---|
| 807 | |
|---|
| 808 | /** |
|---|
| 809 | * bbPress Replies Widget |
|---|
| 810 | * |
|---|
| 811 | * Registers the replies widget |
|---|
| 812 | * |
|---|
| 813 | * @since bbPress (r2653) |
|---|
| 814 | * |
|---|
| 815 | * @uses apply_filters() Calls 'bbp_replies_widget_options' with the |
|---|
| 816 | * widget options |
|---|
| 817 | */ |
|---|
| 818 | function BBP_Replies_Widget() { |
|---|
| 819 | $widget_ops = apply_filters( 'bbp_replies_widget_options', array( |
|---|
| 820 | 'classname' => 'widget_display_replies', |
|---|
| 821 | 'description' => __( 'A list of bbPress recent replies.', 'bbpress' ) |
|---|
| 822 | ) ); |
|---|
| 823 | |
|---|
| 824 | parent::WP_Widget( false, 'bbPress Reply List', $widget_ops ); |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | /** |
|---|
| 828 | * Displays the output, the replies list |
|---|
| 829 | * |
|---|
| 830 | * @since bbPress (r2653) |
|---|
| 831 | * |
|---|
| 832 | * @param mixed $args |
|---|
| 833 | * @param array $instance |
|---|
| 834 | * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title |
|---|
| 835 | * @uses bbp_set_query_name() To set the query name to 'bbp_widget' |
|---|
| 836 | * @uses bbp_reset_query_name() To reset the query name |
|---|
| 837 | * @uses bbp_has_replies() The main reply loop |
|---|
| 838 | * @uses bbp_replies() To check whether there are more replies available |
|---|
| 839 | * in the loop |
|---|
| 840 | * @uses bbp_the_reply() Loads up the current reply in the loop |
|---|
| 841 | * @uses bbp_get_reply_author_link() To get the reply author link |
|---|
| 842 | * @uses bbp_get_reply_author() To get the reply author name |
|---|
| 843 | * @uses bbp_get_reply_id() To get the reply id |
|---|
| 844 | * @uses bbp_get_reply_url() To get the reply url |
|---|
| 845 | * @uses bbp_get_reply_excerpt() To get the reply excerpt |
|---|
| 846 | * @uses bbp_get_reply_topic_title() To get the reply topic title |
|---|
| 847 | * @uses get_the_date() To get the date of the reply |
|---|
| 848 | * @uses get_the_time() To get the time of the reply |
|---|
| 849 | */ |
|---|
| 850 | function widget( $args, $instance ) { |
|---|
| 851 | |
|---|
| 852 | extract( $args ); |
|---|
| 853 | |
|---|
| 854 | $title = apply_filters( 'bbp_replies_widget_title', $instance['title'] ); |
|---|
| 855 | $max_shown = !empty( $instance['max_shown'] ) ? $instance['max_shown'] : '5'; |
|---|
| 856 | $show_date = !empty( $instance['show_date'] ) ? 'on' : false; |
|---|
| 857 | |
|---|
| 858 | // Query defaults |
|---|
| 859 | $replies_query = array( |
|---|
| 860 | 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), |
|---|
| 861 | 'posts_per_page' => $max_shown, |
|---|
| 862 | 'order' => 'DESC' |
|---|
| 863 | ); |
|---|
| 864 | |
|---|
| 865 | // Set the query name |
|---|
| 866 | bbp_set_query_name( 'bbp_widget' ); |
|---|
| 867 | |
|---|
| 868 | // Get replies and display them |
|---|
| 869 | if ( bbp_has_replies( $replies_query ) ) : |
|---|
| 870 | |
|---|
| 871 | echo $before_widget; |
|---|
| 872 | echo $before_title . $title . $after_title; ?> |
|---|
| 873 | |
|---|
| 874 | <ul> |
|---|
| 875 | |
|---|
| 876 | <?php while ( bbp_replies() ) : bbp_the_reply(); ?> |
|---|
| 877 | |
|---|
| 878 | <li> |
|---|
| 879 | |
|---|
| 880 | <?php |
|---|
| 881 | $author_link = bbp_get_reply_author_link( array( 'type' => 'both', 'size' => 14 ) ); |
|---|
| 882 | $reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url() ) . '" title="' . bbp_get_reply_excerpt( bbp_get_reply_id(), 50 ) . '">' . bbp_get_reply_topic_title() . '</a>'; |
|---|
| 883 | |
|---|
| 884 | /* translators: bbpress replies widget: 1: reply author, 2: reply link, 3: reply date, 4: reply time */ |
|---|
| 885 | printf( _x( $show_date == 'on' ? '%1$s on %2$s, %3$s, %4$s' : '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link, get_the_date(), get_the_time() ); |
|---|
| 886 | ?> |
|---|
| 887 | |
|---|
| 888 | </li> |
|---|
| 889 | |
|---|
| 890 | <?php endwhile; ?> |
|---|
| 891 | |
|---|
| 892 | </ul> |
|---|
| 893 | |
|---|
| 894 | <?php echo $after_widget; |
|---|
| 895 | |
|---|
| 896 | endif; |
|---|
| 897 | |
|---|
| 898 | bbp_reset_query_name(); |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | /** |
|---|
| 902 | * Update the forum widget options |
|---|
| 903 | * |
|---|
| 904 | * @since bbPress (r2653) |
|---|
| 905 | * |
|---|
| 906 | * @param array $new_instance The new instance options |
|---|
| 907 | * @param array $old_instance The old instance options |
|---|
| 908 | */ |
|---|
| 909 | function update( $new_instance, $old_instance ) { |
|---|
| 910 | $instance = $old_instance; |
|---|
| 911 | $instance['title'] = strip_tags( $new_instance['title'] ); |
|---|
| 912 | $instance['max_shown'] = strip_tags( $new_instance['max_shown'] ); |
|---|
| 913 | $instance['show_date'] = strip_tags( $new_instance['show_date'] ); |
|---|
| 914 | |
|---|
| 915 | return $instance; |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | /** |
|---|
| 919 | * Output the reply widget options form |
|---|
| 920 | * |
|---|
| 921 | * @since bbPress (r2653) |
|---|
| 922 | * |
|---|
| 923 | * @param $instance Instance |
|---|
| 924 | * @uses BBP_Replies_Widget::get_field_id() To output the field id |
|---|
| 925 | * @uses BBP_Replies_Widget::get_field_name() To output the field name |
|---|
| 926 | */ |
|---|
| 927 | function form( $instance ) { |
|---|
| 928 | $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|---|
| 929 | $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : ''; |
|---|
| 930 | $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; ?> |
|---|
| 931 | |
|---|
| 932 | <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> |
|---|
| 933 | <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> |
|---|
| 934 | <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> |
|---|
| 935 | |
|---|
| 936 | <?php |
|---|
| 937 | } |
|---|
| 938 | } |
|---|
| 939 | |
|---|
| 940 | ?> |
|---|