| | 43 | |
| | 44 | if ( ! current_user_can( 'moderate' ) ) { |
| | 45 | // Filter out hidden reply references from public views |
| | 46 | add_filter( 'bbp_get_topic_last_reply_id', array( $this, 'get_last_public_reply_id' ), 10, 2 ); |
| | 47 | add_filter( 'bbp_get_topic_last_active', array( $this, 'get_last_public_post_time' ), 10, 2 ); |
| | 48 | add_filter( 'bbp_get_topic_last_active_id', array( $this, 'get_last_public_post_id' ), 10, 2 ); |
| | 49 | add_filter( 'bbp_get_topic_reply_count_int', array( $this, 'get_public_reply_count' ), 10, 2 ); |
| | 50 | } else { |
| | 51 | // Append 'view=all' to topics with hidden replies |
| | 52 | add_filter( 'bbp_get_topic_permalink', array( $this, 'append_view_all_to_topic_permalink' ), 10, 2 ); |
| | 53 | add_filter( 'bbp_get_topic_last_reply_url', array( $this, 'append_view_all_to_last_reply_url' ), 10, 3 ); |
| | 54 | add_filter( 'paginate_links', array( $this, 'append_view_all_to_topic_pagination' ), 10, 1 ); |
| | 55 | } |
| | 344 | |
| | 345 | /** |
| | 346 | * Return the ID of the last public reply in a topic. |
| | 347 | * |
| | 348 | * @param int $reply_id Reply ID. |
| | 349 | * @param int $topic_id Topic ID. |
| | 350 | * @return int Last public reply ID. |
| | 351 | */ |
| | 352 | function get_last_public_reply_id( $reply_id, $topic_id ) { |
| | 353 | if ( 'publish' !== get_post_status( $reply_id ) ) { |
| | 354 | $reply_id = bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() ); |
| | 355 | } |
| | 356 | |
| | 357 | return $reply_id; |
| | 358 | } |
| | 359 | |
| | 360 | /** |
| | 361 | * Return last public activity time for a topic. |
| | 362 | * |
| | 363 | * @param string $last_active Last activity time. |
| | 364 | * @param int $topic_id Topic ID. |
| | 365 | * @return string Last public activity time. |
| | 366 | */ |
| | 367 | function get_last_public_post_time( $last_active, $topic_id ) { |
| | 368 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| | 369 | $reply_id = bbp_get_topic_last_reply_id( $topic_id ); |
| | 370 | |
| | 371 | $last_active = get_post_field( 'post_date', $reply_id ); |
| | 372 | $last_active = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; |
| | 373 | } |
| | 374 | |
| | 375 | return $last_active; |
| | 376 | } |
| | 377 | |
| | 378 | /** |
| | 379 | * Return the ID of the last public post in a topic. |
| | 380 | * |
| | 381 | * @param int $active_id Last post ID. |
| | 382 | * @param int $topic_id Topic ID. |
| | 383 | * @return int Last public post ID. |
| | 384 | */ |
| | 385 | function get_last_public_post_id( $active_id, $topic_id ) { |
| | 386 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| | 387 | $active_id = bbp_get_topic_last_reply_id( $topic_id ); |
| | 388 | } |
| | 389 | |
| | 390 | return $active_id; |
| | 391 | } |
| | 392 | |
| | 393 | /** |
| | 394 | * Return public reply counå for a topic. |
| | 395 | * |
| | 396 | * @param int $replies Reply count. |
| | 397 | * @param int $topic_id Topic ID. |
| | 398 | * @return int Public reply count. |
| | 399 | */ |
| | 400 | function get_public_reply_count( $replies, $topic_id ) { |
| | 401 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| | 402 | $replies = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() ); |
| | 403 | } |
| | 404 | |
| | 405 | return $replies; |
| | 406 | } |
| | 407 | |
| | 408 | /** |
| | 409 | * Append 'view=all' to topic permalink if the topic has hidden replies. |
| | 410 | * |
| | 411 | * @param string $topic_permalink Topic permalink. |
| | 412 | * @param int $topic_id Topic ID. |
| | 413 | * @return string Filtered topic permalink. |
| | 414 | */ |
| | 415 | function append_view_all_to_topic_permalink( $topic_permalink, $topic_id ) { |
| | 416 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| | 417 | $topic_permalink = add_query_arg( 'view', 'all', $topic_permalink ); |
| | 418 | } |
| | 419 | |
| | 420 | return $topic_permalink; |
| | 421 | } |
| | 422 | |
| | 423 | /** |
| | 424 | * Append 'view=all' to last reply URL if the topic has hidden replies. |
| | 425 | * |
| | 426 | * @param string $reply_url Reply URL. |
| | 427 | * @param int $topic_id Topic ID. |
| | 428 | * @param int $reply_id Reply ID. |
| | 429 | * @return string Filtered reply URL. |
| | 430 | */ |
| | 431 | function append_view_all_to_last_reply_url( $reply_url, $topic_id, $reply_id ) { |
| | 432 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| | 433 | $reply_url = add_query_arg( 'view', 'all', $reply_url ); |
| | 434 | } |
| | 435 | |
| | 436 | return $reply_url; |
| | 437 | } |
| | 438 | |
| | 439 | /** |
| | 440 | * Append 'view=all' to topic pagination if the topic has hidden replies. |
| | 441 | * |
| | 442 | * @param string $link Paginated link URL. |
| | 443 | * @return string Filtered link URL. |
| | 444 | */ |
| | 445 | function append_view_all_to_topic_pagination( $link ) { |
| | 446 | if ( bbp_get_topic_reply_count_hidden( bbp_get_topic_id() ) ) { |
| | 447 | $link = add_query_arg( 'view', 'all', $link ); |
| | 448 | } |
| | 449 | |
| | 450 | return $link; |
| | 451 | } |
| | 452 | |