/wp-content/plugins/buddypress/bp-forums/bp-forums-filters.php

https://bitbucket.org/Red54/dianjihun · PHP · 204 lines · 104 code · 35 blank · 65 comment · 4 complexity · cc0c6a27967f79ac96207ae5d88743d3 MD5 · raw file

  1. <?php
  2. // Exit if accessed directly
  3. if ( !defined( 'ABSPATH' ) ) exit;
  4. /* Apply WordPress defined filters */
  5. add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
  6. add_filter( 'bp_forums_bbconfig_location', 'esc_attr', 1 );
  7. add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
  8. add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
  9. add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
  10. add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
  11. add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
  12. add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
  13. add_filter( 'bp_get_the_topic_title', 'wptexturize' );
  14. add_filter( 'bp_get_the_topic_poster_name', 'wptexturize' );
  15. add_filter( 'bp_get_the_topic_last_poster_name', 'wptexturize' );
  16. add_filter( 'bp_get_the_topic_post_content', 'wptexturize' );
  17. add_filter( 'bp_get_the_topic_post_poster_name', 'wptexturize' );
  18. add_filter( 'bp_get_the_topic_title', 'convert_smilies' );
  19. add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_smilies' );
  20. add_filter( 'bp_get_the_topic_post_content', 'convert_smilies' );
  21. add_filter( 'bp_get_the_topic_title', 'convert_chars' );
  22. add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_chars' );
  23. add_filter( 'bp_get_the_topic_post_content', 'convert_chars' );
  24. add_filter( 'bp_get_the_topic_post_content', 'wpautop' );
  25. add_filter( 'bp_get_the_topic_latest_post_excerpt', 'wpautop' );
  26. add_filter( 'bp_get_the_topic_post_content', 'stripslashes_deep' );
  27. add_filter( 'bp_get_the_topic_title', 'stripslashes_deep' );
  28. add_filter( 'bp_get_the_topic_latest_post_excerpt', 'stripslashes_deep' );
  29. add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
  30. add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
  31. add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' );
  32. add_filter( 'bp_get_the_topic_post_content', 'make_clickable', 9 );
  33. add_filter( 'bp_get_forum_topic_count_for_user', 'bp_core_number_format' );
  34. add_filter( 'bp_get_forum_topic_count', 'bp_core_number_format' );
  35. add_filter( 'bp_get_the_topic_title', 'bp_forums_make_nofollow_filter' );
  36. add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
  37. add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
  38. function bp_forums_filter_kses( $content ) {
  39. global $allowedtags;
  40. $forums_allowedtags = $allowedtags;
  41. $forums_allowedtags['span'] = array();
  42. $forums_allowedtags['span']['class'] = array();
  43. $forums_allowedtags['div'] = array();
  44. $forums_allowedtags['div']['class'] = array();
  45. $forums_allowedtags['div']['id'] = array();
  46. $forums_allowedtags['a']['class'] = array();
  47. $forums_allowedtags['img'] = array();
  48. $forums_allowedtags['br'] = array();
  49. $forums_allowedtags['p'] = array();
  50. $forums_allowedtags['img']['src'] = array();
  51. $forums_allowedtags['img']['alt'] = array();
  52. $forums_allowedtags['img']['class'] = array();
  53. $forums_allowedtags['img']['width'] = array();
  54. $forums_allowedtags['img']['height'] = array();
  55. $forums_allowedtags['img']['class'] = array();
  56. $forums_allowedtags['img']['id'] = array();
  57. $forums_allowedtags['code'] = array();
  58. $forums_allowedtags['blockquote'] = array();
  59. $forums_allowedtags = apply_filters( 'bp_forums_allowed_tags', $forums_allowedtags );
  60. return wp_kses( $content, $forums_allowedtags );
  61. }
  62. function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
  63. global $bp;
  64. return apply_filters( 'bp_forums_filter_tag_link', bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/tag/' . $tag . '/' );
  65. }
  66. add_filter( 'bb_get_tag_link', 'bp_forums_filter_tag_link', 10, 4);
  67. function bp_forums_make_nofollow_filter( $text ) {
  68. return preg_replace_callback( '|<a (.+?)>|i', 'bp_forums_make_nofollow_filter_callback', $text );
  69. }
  70. function bp_forums_make_nofollow_filter_callback( $matches ) {
  71. $text = $matches[1];
  72. $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
  73. return "<a $text rel=\"nofollow\">";
  74. }
  75. /**
  76. * bp_forums_add_forum_topic_to_page_title( $title )
  77. *
  78. * Append forum topic to page title
  79. *
  80. * @global object $bp
  81. * @param string $title New page title; see bp_modify_page_title()
  82. * @param string $title Original page title
  83. * @param string $sep How to separate the various items within the page title.
  84. * @param string $seplocation Direction to display title
  85. * @return string
  86. * @see bp_modify_page_title()
  87. */
  88. function bp_forums_add_forum_topic_to_page_title( $title, $original_title, $sep, $seplocation ) {
  89. global $bp;
  90. if ( bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) )
  91. if ( bp_has_forum_topic_posts() )
  92. $title .= bp_get_the_topic_title() . " $sep ";
  93. return $title;
  94. }
  95. add_filter( 'bp_modify_page_title', 'bp_forums_add_forum_topic_to_page_title', 9, 4 );
  96. /**
  97. * bp_forums_strip_mentions_on_post_edit( $title )
  98. *
  99. * Removes the anchor tag autogenerated for at-mentions when forum topics and posts are edited.
  100. * Prevents embedded anchor tags.
  101. *
  102. * @global object $bp
  103. * @param string $content
  104. * @return string $content
  105. */
  106. function bp_forums_strip_mentions_on_post_edit( $content ) {
  107. global $bp;
  108. $content = htmlspecialchars_decode( $content );
  109. $pattern = "|<a href=&#039;" . bp_get_root_domain() . "/" . bp_get_members_root_slug() . "/[A-Za-z0-9-_\.]+/&#039; rel=&#039;nofollow&#039;>(@[A-Za-z0-9-_\.@]+)</a>|";
  110. $content = preg_replace( $pattern, "$1", $content );
  111. return $content;
  112. }
  113. add_filter( 'bp_get_the_topic_post_edit_text', 'bp_forums_strip_mentions_on_post_edit' );
  114. add_filter( 'bp_get_the_topic_text', 'bp_forums_strip_mentions_on_post_edit' );
  115. /**
  116. * "REPLIED TO" SQL FILTERS
  117. */
  118. /**
  119. * Filters the get_topics_distinct portion of the Forums sql when on a user's Replied To page.
  120. *
  121. * This filter is added in bp_has_forum_topics()
  122. *
  123. * @package BuddyPress
  124. * @since BuddyPress (1.5)
  125. *
  126. * @param string $sql
  127. * @return string $sql
  128. */
  129. function bp_forums_add_replied_distinct_sql( $sql ) {
  130. $sql = "DISTINCT t.topic_id, ";
  131. return $sql;
  132. }
  133. /**
  134. * Filters the get_topics_join portion of the Forums sql when on a user's Replied To page.
  135. *
  136. * This filter is added in bp_has_forum_topics()
  137. *
  138. * @package BuddyPress
  139. * @since BuddyPress (1.5)
  140. *
  141. * @global object $bbdb The bbPress database global
  142. * @global object $wpdb The WordPress database global
  143. * @param string $sql
  144. * @return string $sql
  145. */
  146. function bp_forums_add_replied_join_sql( $sql ) {
  147. global $bbdb;
  148. $sql .= " LEFT JOIN {$bbdb->posts} p ON p.topic_id = t.topic_id ";
  149. return $sql;
  150. }
  151. /**
  152. * Filters the get_topics_where portion of the Forums sql when on a user's Replied To page.
  153. *
  154. * This filter is added in bp_has_forum_topics()
  155. *
  156. * @package BuddyPress
  157. * @since BuddyPress (1.5)
  158. *
  159. * @global object $wpdb The WordPress database global
  160. * @param string $sql
  161. * @return string $sql
  162. */
  163. function bp_forums_add_replied_where_sql( $sql ) {
  164. global $wpdb;
  165. $sql .= $wpdb->prepare( " AND p.poster_id = %s ", bp_displayed_user_id() );
  166. // Remove any topic_author information
  167. $sql = str_replace( " AND t.topic_poster = '" . bp_displayed_user_id() . "'", '', $sql );
  168. return $sql;
  169. }