[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-forums/ -> bp-forums-filters.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Forums Filters.
   4   *
   5   * @package BuddyPress
   6   * @subpackage ForumsFilters
   7   * @since 1.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /* Apply WordPress defined filters */
  14  add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
  15  add_filter( 'bp_forums_bbconfig_location', 'esc_attr', 1 );
  16  
  17  add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
  18  add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
  19  add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
  20  
  21  add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
  22  add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
  23  add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
  24  
  25  add_filter( 'bp_get_the_topic_title', 'wptexturize' );
  26  add_filter( 'bp_get_the_topic_poster_name', 'wptexturize' );
  27  add_filter( 'bp_get_the_topic_last_poster_name', 'wptexturize' );
  28  add_filter( 'bp_get_the_topic_post_content', 'wptexturize' );
  29  add_filter( 'bp_get_the_topic_post_poster_name', 'wptexturize' );
  30  
  31  add_filter( 'bp_get_the_topic_title', 'convert_smilies' );
  32  add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_smilies' );
  33  add_filter( 'bp_get_the_topic_post_content', 'convert_smilies' );
  34  
  35  add_filter( 'bp_get_the_topic_title', 'convert_chars' );
  36  add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_chars' );
  37  add_filter( 'bp_get_the_topic_post_content', 'convert_chars' );
  38  
  39  add_filter( 'bp_get_the_topic_post_content', 'wpautop' );
  40  add_filter( 'bp_get_the_topic_latest_post_excerpt', 'wpautop' );
  41  
  42  add_filter( 'bp_get_the_topic_post_content', 'stripslashes_deep' );
  43  add_filter( 'bp_get_the_topic_title', 'stripslashes_deep' );
  44  add_filter( 'bp_get_the_topic_latest_post_excerpt', 'stripslashes_deep' );
  45  add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
  46  add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
  47  add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' );
  48  
  49  add_filter( 'bp_get_the_topic_post_content', 'make_clickable', 9 );
  50  
  51  add_filter( 'bp_get_forum_topic_count_for_user', 'bp_core_number_format' );
  52  add_filter( 'bp_get_forum_topic_count', 'bp_core_number_format' );
  53  
  54  add_filter( 'bp_get_the_topic_title', 'bp_forums_make_nofollow_filter' );
  55  add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
  56  add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
  57  
  58  /**
  59   * Custom KSES filter for the Forums component.
  60   *
  61   * @since 1.2.0
  62   *
  63   * @param string $content Content to sanitize.
  64   * @return string Sanitized string.
  65   */
  66  function bp_forums_filter_kses( $content ) {
  67      global $allowedtags;
  68  
  69      $forums_allowedtags = $allowedtags;
  70      $forums_allowedtags['span'] = array();
  71      $forums_allowedtags['span']['class'] = array();
  72      $forums_allowedtags['div'] = array();
  73      $forums_allowedtags['div']['class'] = array();
  74      $forums_allowedtags['div']['id'] = array();
  75      $forums_allowedtags['a']['class'] = array();
  76      $forums_allowedtags['img'] = array();
  77      $forums_allowedtags['br'] = array();
  78      $forums_allowedtags['p'] = array();
  79      $forums_allowedtags['img']['src'] = array();
  80      $forums_allowedtags['img']['alt'] = array();
  81      $forums_allowedtags['img']['class'] = array();
  82      $forums_allowedtags['img']['width'] = array();
  83      $forums_allowedtags['img']['height'] = array();
  84      $forums_allowedtags['img']['class'] = array();
  85      $forums_allowedtags['img']['id'] = array();
  86      $forums_allowedtags['code'] = array();
  87      $forums_allowedtags['blockquote'] = array();
  88  
  89      /**
  90       * Filters the allowed HTML tags for forum posts.
  91       *
  92       * @since 1.2.0
  93       *
  94       * @param array $forums_allowedtags Array of allowed HTML tags.
  95       */
  96      $forums_allowedtags = apply_filters( 'bp_forums_allowed_tags', $forums_allowedtags );
  97      return wp_kses( $content, $forums_allowedtags );
  98  }
  99  
 100  /**
 101   * Get a link for a forum topic tags directory.
 102   *
 103   * @since 1.1.0
 104   *
 105   * @param string $link    Link passed from filter.
 106   * @param string $tag     Name of the tag.
 107   * @param string $page    Page number, passed from the filter.
 108   * @param string $context Passed from the filter but unused here.
 109   * @return string Link of the form http://example.com/forums/tag/tagname/.
 110   */
 111  function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
 112      /**
 113       * Filters the link for a forum topic tags directory.
 114       *
 115       * @since 1.1.0
 116       *
 117       * @param string $value Link for the forum topic tag directory.
 118       */
 119      return apply_filters( 'bp_forums_filter_tag_link', bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/tag/' . $tag . '/' );
 120  }
 121  add_filter( 'bb_get_tag_link', 'bp_forums_filter_tag_link', 10, 4);
 122  
 123  /**
 124   * Add rel="nofollow" to bbPress content.
 125   *
 126   * @since 1.2.1
 127   *
 128   * @param string $text Post content.
 129   * @return string Modified post content.
 130   */
 131  function bp_forums_make_nofollow_filter( $text ) {
 132      return preg_replace_callback( '|<a (.+?)>|i', 'bp_forums_make_nofollow_filter_callback', $text );
 133  }
 134      /**
 135       * Callback for preg_replace_callback() in bp_forums_make_nofollow_filter().
 136       *
 137       * @since 1.2.1
 138       *
 139       * @param array $matches Regex matches from {@link bp_forums_make_nofollow_filter()}.
 140       * @return string Text with nofollow links.
 141       */
 142  	function bp_forums_make_nofollow_filter_callback( $matches ) {
 143          $text = $matches[1];
 144          $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
 145          return "<a $text rel=\"nofollow\">";
 146      }
 147  
 148  /**
 149   * Append forum topic to page title.
 150   *
 151   * @since 1.2.6
 152   *
 153   * @see bp_modify_page_title()
 154   *
 155   * @param string $title          New page title; see {@link bp_modify_page_title()}.
 156   * @param string $original_title Original page title.
 157   * @param string $sep            How to separate the various items within the page title.
 158   * @param string $seplocation    Direction to display title.
 159   * @return string Page title with forum topic title appended.
 160   */
 161  function bp_forums_add_forum_topic_to_page_title( $title, $original_title, $sep, $seplocation  ) {
 162  
 163      if ( bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) )
 164          if ( bp_has_forum_topic_posts() )
 165              $title .= bp_get_the_topic_title() . " $sep ";
 166  
 167      return $title;
 168  }
 169  add_filter( 'bp_modify_page_title', 'bp_forums_add_forum_topic_to_page_title', 9, 4 );
 170  
 171  /**
 172   * Remove the anchor tag autogenerated for at-mentions when forum topics and posts are edited.
 173   *
 174   * Prevents embedded anchor tags.
 175   *
 176   * @since 1.5.0
 177   *
 178   * @param string $content Edited post content.
 179   * @return string $content Sanitized post content.
 180   */
 181  function bp_forums_strip_mentions_on_post_edit( $content ) {
 182      $content   = htmlspecialchars_decode( $content );
 183      $directory = bp_get_members_directory_permalink();
 184      $pattern   = "|<a href=&#039;{$directory}[A-Za-z0-9-_\.]+/&#039; rel=&#039;nofollow&#039;>(@[A-Za-z0-9-_\.@]+)</a>|";
 185      $content   = preg_replace( $pattern, "$1", $content );
 186  
 187      return $content;
 188  }
 189  add_filter( 'bp_get_the_topic_post_edit_text', 'bp_forums_strip_mentions_on_post_edit' );
 190  add_filter( 'bp_get_the_topic_text',           'bp_forums_strip_mentions_on_post_edit' );
 191  
 192  /** "Replied to" SQL filters *************************************************/
 193  
 194  /**
 195   * Filter the get_topics_distinct portion of the Forums SQL when on a user's Replied To page.
 196   *
 197   * This filter is added in bp_has_forum_topics().
 198   *
 199   * @since 1.5.0
 200   *
 201   * @param string $sql SQL fragment.
 202   * @return string $sql SQL fragment of the form "DISTINCT t.topic_id, ".
 203   */
 204  function bp_forums_add_replied_distinct_sql( $sql ) {
 205      $sql = "DISTINCT t.topic_id, ";
 206  
 207      return $sql;
 208  }
 209  
 210  /**
 211   * Filter the get_topics_join portion of the Forums sql when on a user's Replied To page.
 212   *
 213   * This filter is added in bp_has_forum_topics().
 214   *
 215   * @since 1.5.0
 216   *
 217   * @global object $bbdb The bbPress database global.
 218   *
 219   * @param string $sql SQL statement.
 220   * @return string $sql SQL statement.
 221   */
 222  function bp_forums_add_replied_join_sql( $sql ) {
 223      global $bbdb;
 224  
 225      $sql .= " LEFT JOIN {$bbdb->posts} p ON p.topic_id = t.topic_id ";
 226  
 227      return $sql;
 228  }
 229  
 230  /**
 231   * Filter the get_topics_where portion of the Forums sql when on a user's Replied To page.
 232   *
 233   * This filter is added in bp_has_forum_topics().
 234   *
 235   * @since 1.5.0
 236   *
 237   * @global object $wpdb The WordPress database global.
 238   *
 239   * @param string $sql SQL fragment.
 240   * @return string $sql SQL fragment.
 241   */
 242  function bp_forums_add_replied_where_sql( $sql ) {
 243      global $wpdb;
 244  
 245      $sql .= $wpdb->prepare( " AND p.poster_id = %s ", bp_displayed_user_id() );
 246  
 247      // Remove any topic_author information.
 248      $sql = str_replace( " AND t.topic_poster = '" . bp_displayed_user_id() . "'", '', $sql );
 249  
 250      return $sql;
 251  }


Generated: Thu Dec 7 01:01:35 2017 Cross-referenced by PHPXref 0.7.1