| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * bbPress Formatting. | |
| 4 | + * bbPress Formatting | |
| 5 | 5 | * |
| 6 | 6 | * @package bbPress |
| 7 | 7 | * @subpackage Formatting |
| 8 | 8 | */ |
| @@ -12,15 +12,15 @@ | ||
| 12 | 12 | |
| 13 | 13 | /** Kses **********************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Custom allowed tags for forum topics and replies. | |
| 16 | + * Custom allowed tags for forum topics and replies | |
| 17 | 17 | * |
| 18 | - * Allows all users to post links, quotes, code, formatting, lists, and images. | |
| 18 | + * Allows all users to post links, quotes, code, formatting, lists, and images | |
| 19 | 19 | * |
| 20 | 20 | * @since 2.3.0 bbPress (r4603) |
| 21 | 21 | * |
| 22 | - * @return array Associative array of allowed tags and attributes. | |
| 22 | + * @return array Associative array of allowed tags and attributes | |
| 23 | 23 | */ |
| 24 | 24 | function bbp_kses_allowed_tags() { |
| 25 | 25 | |
| 26 | 26 | // Filter & return |
| @@ -78,14 +78,14 @@ | ||
| 78 | 78 | ); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | - * Custom kses filter for forum topics and replies, for filtering incoming data. | |
| 82 | + * Custom kses filter for forum topics and replies, for filtering incoming data | |
| 83 | 83 | * |
| 84 | 84 | * @since 2.3.0 bbPress (r4603) |
| 85 | 85 | * |
| 86 | - * @param string $data Content to filter, expected to be escaped with slashes. | |
| 87 | - * @return string Filtered content. | |
| 86 | + * @param string $data Content to filter, expected to be escaped with slashes | |
| 87 | + * @return string Filtered content | |
| 88 | 88 | */ |
| 89 | 89 | function bbp_filter_kses( $data = '' ) { |
| 90 | 90 | return wp_slash( wp_kses( wp_unslash( $data ), bbp_kses_allowed_tags() ) ); |
| 91 | 91 | } |
| @@ -90,14 +90,14 @@ | ||
| 90 | 90 | return wp_slash( wp_kses( wp_unslash( $data ), bbp_kses_allowed_tags() ) ); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * Custom kses filter for forum topics and replies, for raw data. | |
| 94 | + * Custom kses filter for forum topics and replies, for raw data | |
| 95 | 95 | * |
| 96 | 96 | * @since 2.3.0 bbPress (r4603) |
| 97 | 97 | * |
| 98 | - * @param string $data Content to filter, expected to not be escaped. | |
| 99 | - * @return string Filtered content. | |
| 98 | + * @param string $data Content to filter, expected to not be escaped | |
| 99 | + * @return string Filtered content | |
| 100 | 100 | */ |
| 101 | 101 | function bbp_kses_data( $data = '' ) { |
| 102 | 102 | return wp_kses( $data, bbp_kses_allowed_tags() ); |
| 103 | 103 | } |
| @@ -104,14 +104,14 @@ | ||
| 104 | 104 | |
| 105 | 105 | /** Formatting ****************************************************************/ |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | - * Filter the topic or reply content and output code and pre tags. | |
| 108 | + * Filter the topic or reply content and output code and pre tags | |
| 109 | 109 | * |
| 110 | 110 | * @since 2.3.0 bbPress (r4641) |
| 111 | 111 | * |
| 112 | - * @param string $content Topic and reply content. | |
| 113 | - * @return string Partially encoded content. | |
| 112 | + * @param string $content Topic and reply content | |
| 113 | + * @return string Partially encoded content | |
| 114 | 114 | */ |
| 115 | 115 | function bbp_code_trick( $content = '' ) { |
| 116 | 116 | $content = str_replace( array( "\r\n", "\r" ), "\n", $content ); |
| 117 | 117 | $content = preg_replace_callback('|(`)(.*?)`|', 'bbp_encode_callback', $content ); |
| @@ -125,10 +125,10 @@ | ||
| 125 | 125 | * contains the correct editable content. |
| 126 | 126 | * |
| 127 | 127 | * @since 2.3.0 bbPress (r4641) |
| 128 | 128 | * |
| 129 | - * @param string $content Topic and reply content. | |
| 130 | - * @return string Partially encoded content. | |
| 129 | + * @param string $content Topic and reply content | |
| 130 | + * @return string Partially encoded content | |
| 131 | 131 | */ |
| 132 | 132 | function bbp_code_trick_reverse( $content = '' ) { |
| 133 | 133 | |
| 134 | 134 | // Setup variables |
| @@ -145,14 +145,14 @@ | ||
| 145 | 145 | return $content; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | - * Filter the content and encode any bad HTML tags. | |
| 149 | + * Filter the content and encode any bad HTML tags | |
| 150 | 150 | * |
| 151 | 151 | * @since 2.3.0 bbPress (r4641) |
| 152 | 152 | * |
| 153 | - * @param string $content Topic and reply content. | |
| 154 | - * @return string Partially encoded content. | |
| 153 | + * @param string $content Topic and reply content | |
| 154 | + * @return string Partially encoded content | |
| 155 | 155 | */ |
| 156 | 156 | function bbp_encode_bad( $content = '' ) { |
| 157 | 157 | |
| 158 | 158 | // Setup variables |
| @@ -188,9 +188,9 @@ | ||
| 188 | 188 | |
| 189 | 189 | /** Code Callbacks ************************************************************/ |
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | - * Callback to encode the tags in topic or reply content. | |
| 192 | + * Callback to encode the tags in topic or reply content | |
| 193 | 193 | * |
| 194 | 194 | * @since 2.3.0 bbPress (r4641) |
| 195 | 195 | * |
| 196 | 196 | * @param array $matches |
| @@ -224,9 +224,9 @@ | ||
| 224 | 224 | return $content; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
| 228 | - * Callback to decode the tags in topic or reply content. | |
| 228 | + * Callback to decode the tags in topic or reply content | |
| 229 | 229 | * |
| 230 | 230 | * @since 2.3.0 bbPress (r4641) |
| 231 | 231 | * |
| 232 | 232 | * @param array $matches |
| @@ -253,9 +253,9 @@ | ||
| 253 | 253 | return '`' . $content . '`'; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
| 257 | - * Callback to replace empty HTML tags in a content string. | |
| 257 | + * Callback to replace empty HTML tags in a content string | |
| 258 | 258 | * |
| 259 | 259 | * @since 2.3.0 bbPress (r4641) |
| 260 | 260 | * |
| 261 | 261 | * @internal Used by bbp_encode_bad() |
| @@ -269,9 +269,9 @@ | ||
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | - * Callback to replace normal HTML tags in a content string. | |
| 273 | + * Callback to replace normal HTML tags in a content string | |
| 274 | 274 | * |
| 275 | 275 | * @since 2.3.0 bbPress (r4641) |
| 276 | 276 | * |
| 277 | 277 | * @internal Used by bbp_encode_bad() |
| @@ -288,14 +288,14 @@ | ||
| 288 | 288 | |
| 289 | 289 | /** No Follow *****************************************************************/ |
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | - * Catches links so rel=nofollow can be added (on output, not save). | |
| 292 | + * Catches links so rel=nofollow can be added (on output, not save) | |
| 293 | 293 | * |
| 294 | 294 | * @since 2.3.0 bbPress (r4866) |
| 295 | 295 | * |
| 296 | - * @param string $text Post text. | |
| 297 | - * @return string $text Text with rel=nofollow added to any links. | |
| 296 | + * @param string $text Post text | |
| 297 | + * @return string $text Text with rel=nofollow added to any links | |
| 298 | 298 | */ |
| 299 | 299 | function bbp_rel_nofollow( $text = '' ) { |
| 300 | 300 | return preg_replace_callback( '|<a (.+?)>|i', 'bbp_rel_nofollow_callback', $text ); |
| 301 | 301 | } |
| @@ -300,15 +300,15 @@ | ||
| 300 | 300 | return preg_replace_callback( '|<a (.+?)>|i', 'bbp_rel_nofollow_callback', $text ); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
| 304 | - * Adds rel=nofollow to a link. | |
| 304 | + * Adds rel=nofollow to a link | |
| 305 | 305 | * |
| 306 | 306 | * @since 2.3.0 bbPress (r4866) |
| 307 | 307 | * @since 2.6.17 Use the WordPress link relationship callback. |
| 308 | 308 | * |
| 309 | 309 | * @param array $matches |
| 310 | - * @return string $text Link with rel=nofollow added. | |
| 310 | + * @return string $text Link with rel=nofollow added | |
| 311 | 311 | */ |
| 312 | 312 | function bbp_rel_nofollow_callback( $matches = array() ) { |
| 313 | 313 | return wp_rel_callback( $matches, 'nofollow' ); |
| 314 | 314 | } |
| @@ -369,9 +369,9 @@ | ||
| 369 | 369 | return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a>([^<]*)</a>#i', '$1$3$4</a>', $r ); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Make URLs clickable in content areas. | |
| 373 | + * Make URLs clickable in content areas | |
| 374 | 374 | * |
| 375 | 375 | * @since 2.6.0 bbPress (r6014) |
| 376 | 376 | * |
| 377 | 377 | * @param string $text |
| @@ -397,9 +397,9 @@ | ||
| 397 | 397 | return preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $text ); |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | - * Make FTP clickable in content areas. | |
| 401 | + * Make FTP clickable in content areas | |
| 402 | 402 | * |
| 403 | 403 | * @since 2.6.0 bbPress (r6014) |
| 404 | 404 | * |
| 405 | 405 | * @see make_clickable() |
| @@ -411,9 +411,9 @@ | ||
| 411 | 411 | return preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $text ); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
| 415 | - * Make emails clickable in content areas. | |
| 415 | + * Make emails clickable in content areas | |
| 416 | 416 | * |
| 417 | 417 | * @since 2.6.0 bbPress (r6014) |
| 418 | 418 | * |
| 419 | 419 | * @see make_clickable() |
| @@ -425,12 +425,10 @@ | ||
| 425 | 425 | return preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $text ); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
| 429 | - * Make mentions clickable in content areas. | |
| 429 | + * Make mentions clickable in content areas | |
| 430 | 430 | * |
| 431 | - * Allows ' ', '>', '[', and '(' before as '@' username mention. | |
| 432 | - * | |
| 433 | 431 | * @since 2.6.0 bbPress (r6014) |
| 434 | 432 | * |
| 435 | 433 | * @see make_clickable() |
| 436 | 434 | * |
| @@ -437,13 +435,9 @@ | ||
| 437 | 435 | * @param string $text |
| 438 | 436 | * @return string |
| 439 | 437 | */ |
| 440 | 438 | function bbp_make_mentions_clickable( $text = '' ) { |
| 441 | - return preg_replace_callback( | |
| 442 | - '#([\s>\[\(])\@([0-9a-zA-Z\-_]+)#i', | |
| 443 | - 'bbp_make_mentions_clickable_callback', | |
| 444 | - $text | |
| 445 | - ); | |
| 439 | + return preg_replace_callback( '#([\s>])@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text ); | |
| 446 | 440 | } |
| 447 | 441 | |
| 448 | 442 | /** |
| 449 | 443 | * Callback to convert mention matches to HTML A tag. |
| @@ -486,12 +480,11 @@ | ||
| 486 | 480 | ? ' class="' . esc_attr( $class_str ) . '"' |
| 487 | 481 | : ''; |
| 488 | 482 | |
| 489 | 483 | // Create the link to the user's profile |
| 490 | - $html = '<a href="%1$s"%2$s>%3$s</a>'; | |
| 491 | - $url = bbp_get_user_profile_url( $user->ID ); | |
| 492 | - $mention = '@' . $matches[2]; | |
| 493 | - $anchor = sprintf( $html, esc_url( $url ), $class, esc_html( $mention ) ); | |
| 484 | + $html = '<a href="%1$s"' . $class . '>%2$s</a>'; | |
| 485 | + $url = bbp_get_user_profile_url( $user->ID ); | |
| 486 | + $anchor = sprintf( $html, esc_url( $url ), esc_html( $matches[0] ) ); | |
| 494 | 487 | |
| 495 | 488 | // Prevent this link from being followed by bots |
| 496 | 489 | $link = bbp_rel_nofollow( $anchor ); |
| 497 | 490 | |
| @@ -514,9 +507,8 @@ | ||
| 514 | 507 | function bbp_number_not_negative( $number = 0 ) { |
| 515 | 508 | |
| 516 | 509 | // Protect against formatted strings |
| 517 | 510 | if ( is_string( $number ) ) { |
| 518 | - // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags | |
| 519 | 511 | $number = strip_tags( $number ); // No HTML |
| 520 | 512 | $number = preg_replace( '/[^0-9-]/', '', $number ); // No number-format |
| 521 | 513 | |
| 522 | 514 | // Protect against objects, arrays, scalars, etc... |
| @@ -534,16 +526,16 @@ | ||
| 534 | 526 | return (int) apply_filters( 'bbp_number_not_negative', $not_less_than_zero, $int, $number ); |
| 535 | 527 | } |
| 536 | 528 | |
| 537 | 529 | /** |
| 538 | - * A bbPress specific method of formatting numeric values. | |
| 530 | + * A bbPress specific method of formatting numeric values | |
| 539 | 531 | * |
| 540 | 532 | * @since 2.0.0 bbPress (r2486) |
| 541 | 533 | * |
| 542 | - * @param string $number Number to format. | |
| 543 | - * @param string $decimals Optional. Display decimals. | |
| 534 | + * @param string $number Number to format | |
| 535 | + * @param string $decimals Optional. Display decimals | |
| 544 | 536 | * |
| 545 | - * @return string Formatted string. | |
| 537 | + * @return string Formatted string | |
| 546 | 538 | */ |
| 547 | 539 | function bbp_number_format( $number = 0, $decimals = false, $dec_point = '.', $thousands_sep = ',' ) { |
| 548 | 540 | |
| 549 | 541 | // If empty, set $number to (int) 0 |
| @@ -555,16 +547,16 @@ | ||
| 555 | 547 | return apply_filters( 'bbp_number_format', number_format( $number, $decimals, $dec_point, $thousands_sep ), $number, $decimals, $dec_point, $thousands_sep ); |
| 556 | 548 | } |
| 557 | 549 | |
| 558 | 550 | /** |
| 559 | - * A bbPress specific method of formatting numeric values. | |
| 551 | + * A bbPress specific method of formatting numeric values | |
| 560 | 552 | * |
| 561 | 553 | * @since 2.1.0 bbPress (r3857) |
| 562 | 554 | * |
| 563 | - * @param string $number Number to format. | |
| 564 | - * @param string $decimals Optional. Display decimals. | |
| 555 | + * @param string $number Number to format | |
| 556 | + * @param string $decimals Optional. Display decimals | |
| 565 | 557 | * |
| 566 | - * @return string Formatted string. | |
| 558 | + * @return string Formatted string | |
| 567 | 559 | */ |
| 568 | 560 | function bbp_number_format_i18n( $number = 0, $decimals = false ) { |
| 569 | 561 | |
| 570 | 562 | // If empty, set $number to (int) 0 |
| @@ -587,9 +579,9 @@ | ||
| 587 | 579 | * @param string $d Optional. Default is 'U'. Either 'G', 'U', or php date |
| 588 | 580 | * format |
| 589 | 581 | * @param bool $translate Optional. Default is false. Whether to translate the |
| 590 | 582 | * |
| 591 | - * @return string Returns timestamp. | |
| 583 | + * @return string Returns timestamp | |
| 592 | 584 | */ |
| 593 | 585 | function bbp_convert_date( $time, $d = 'U', $translate = false ) { |
| 594 | 586 | $new_time = mysql2date( $d, $time, $translate ); |
| 595 | 587 | |
| @@ -700,9 +692,9 @@ | ||
| 700 | 692 | $seconds = $chunks[ $i ][0]; |
| 701 | 693 | |
| 702 | 694 | // Finding the biggest chunk (if the chunk fits, break) |
| 703 | 695 | $count = floor( $since / $seconds ); |
| 704 | - if ( ! empty( $count ) ) { | |
| 696 | + if ( 0 != $count ) { | |
| 705 | 697 | break; |
| 706 | 698 | } |
| 707 | 699 | } |
| 708 | 700 | |
| @@ -720,9 +712,9 @@ | ||
| 720 | 712 | $seconds2 = $chunks[ $i + 1 ][0]; |
| 721 | 713 | $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ); |
| 722 | 714 | |
| 723 | 715 | // Add to output var |
| 724 | - if ( ! empty( $count2 ) ) { | |
| 716 | + if ( 0 != $count2 ) { | |
| 725 | 717 | $output .= _x( ',', 'Separator in time since', 'bbpress' ) . ' '; |
| 726 | 718 | $output .= sprintf( translate_nooped_plural( $chunks[ $i + 1 ][1], $count2, 'bbpress' ), bbp_number_format_i18n( $count2 ) ); |
| 727 | 719 | } |
| 728 | 720 | } |
| @@ -734,9 +726,9 @@ | ||
| 734 | 726 | } |
| 735 | 727 | } |
| 736 | 728 | |
| 737 | 729 | // Append 'ago' to the end of time-since if not 'right now' |
| 738 | - if ( $output !== $right_now_text ) { | |
| 730 | + if ( $output != $right_now_text ) { | |
| 739 | 731 | $output = sprintf( $ago_text, $output ); |
| 740 | 732 | } |
| 741 | 733 | |
| 742 | 734 | // Filter & return |
| @@ -784,15 +776,17 @@ | ||
| 784 | 776 | |
| 785 | 777 | /** |
| 786 | 778 | * Format the display name of a user. |
| 787 | 779 | * |
| 788 | - * Abstracts mbstring library check and fallback to utf8_encode(). | |
| 780 | + * Prefers wp_is_valid_utf8() from WordPress 6.9, falls back to mbstring | |
| 781 | + * library, and uses seems_utf8() & utf8_encode() as a last resort. | |
| 789 | 782 | * |
| 790 | 783 | * @link https://bbpress.trac.wordpress.org/ticket/2141 |
| 791 | 784 | * |
| 792 | 785 | * @since 2.6.14 |
| 793 | 786 | * |
| 794 | - * @param string $display_name The author display. | |
| 787 | + * @param string $display_name The author display name | |
| 788 | + * | |
| 795 | 789 | * @return string |
| 796 | 790 | */ |
| 797 | 791 | function bbp_format_user_display_name( $display_name = '' ) { |
| 798 | 792 | |