PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/openfarmtech/weblog-content
PHP | 141 lines | 114 code | 23 blank | 4 comment | 2 complexity | a783e723b0221e47f600b52b32c24c52 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. /* Apply WordPress defined filters */
  3. add_filter( 'bp_get_activity_action', 'bp_activity_filter_kses', 1 );
  4. add_filter( 'bp_get_activity_content_body', 'bp_activity_filter_kses', 1 );
  5. add_filter( 'bp_get_activity_content', 'bp_activity_filter_kses', 1 );
  6. add_filter( 'bp_get_activity_parent_content', 'bp_activity_filter_kses', 1 );
  7. add_filter( 'bp_get_activity_latest_update', 'bp_activity_filter_kses', 1 );
  8. add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_filter_kses', 1 );
  9. add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
  10. add_filter( 'bp_activity_content_before_save', 'bp_activity_filter_kses', 1 );
  11. add_filter( 'bp_activity_action_before_save', 'bp_activity_filter_kses', 1 );
  12. add_filter( 'bp_get_activity_action', 'force_balance_tags' );
  13. add_filter( 'bp_get_activity_content_body', 'force_balance_tags' );
  14. add_filter( 'bp_get_activity_content', 'force_balance_tags' );
  15. add_filter( 'bp_get_activity_latest_update', 'force_balance_tags' );
  16. add_filter( 'bp_get_activity_latest_update_excerpt', 'force_balance_tags' );
  17. add_filter( 'bp_get_activity_feed_item_description', 'force_balance_tags' );
  18. add_filter( 'bp_get_activity_action', 'wptexturize' );
  19. add_filter( 'bp_get_activity_content_body', 'wptexturize' );
  20. add_filter( 'bp_get_activity_content', 'wptexturize' );
  21. add_filter( 'bp_get_activity_parent_content', 'wptexturize' );
  22. add_filter( 'bp_get_activity_latest_update', 'wptexturize' );
  23. add_filter( 'bp_get_activity_latest_update_excerpt', 'wptexturize' );
  24. add_filter( 'bp_get_activity_action', 'convert_smilies' );
  25. add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
  26. add_filter( 'bp_get_activity_content', 'convert_smilies' );
  27. add_filter( 'bp_get_activity_parent_content', 'convert_smilies' );
  28. add_filter( 'bp_get_activity_latest_update', 'convert_smilies' );
  29. add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_smilies' );
  30. add_filter( 'bp_get_activity_action', 'convert_chars' );
  31. add_filter( 'bp_get_activity_content_body', 'convert_chars' );
  32. add_filter( 'bp_get_activity_content', 'convert_chars' );
  33. add_filter( 'bp_get_activity_parent_content', 'convert_chars' );
  34. add_filter( 'bp_get_activity_latest_update', 'convert_chars' );
  35. add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_chars' );
  36. add_filter( 'bp_get_activity_action', 'wpautop' );
  37. add_filter( 'bp_get_activity_content_body', 'wpautop' );
  38. add_filter( 'bp_get_activity_content', 'wpautop' );
  39. add_filter( 'bp_get_activity_feed_item_description', 'wpautop' );
  40. add_filter( 'bp_get_activity_action', 'make_clickable' );
  41. add_filter( 'bp_get_activity_content_body', 'make_clickable' );
  42. add_filter( 'bp_get_activity_content', 'make_clickable' );
  43. add_filter( 'bp_get_activity_parent_content', 'make_clickable' );
  44. add_filter( 'bp_get_activity_latest_update', 'make_clickable' );
  45. add_filter( 'bp_get_activity_latest_update_excerpt', 'make_clickable' );
  46. add_filter( 'bp_get_activity_feed_item_description', 'make_clickable' );
  47. add_filter( 'bp_acomment_name', 'stripslashes_deep' );
  48. add_filter( 'bp_get_activity_action', 'stripslashes_deep' );
  49. add_filter( 'bp_get_activity_content', 'stripslashes_deep' );
  50. add_filter( 'bp_get_activity_content_body', 'stripslashes_deep' );
  51. add_filter( 'bp_get_activity_parent_content', 'stripslashes_deep' );
  52. add_filter( 'bp_get_activity_latest_update', 'stripslashes_deep' );
  53. add_filter( 'bp_get_activity_latest_update_excerpt', 'stripslashes_deep' );
  54. add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep' );
  55. add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
  56. add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
  57. add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
  58. add_filter( 'bp_get_activity_latest_update', 'bp_activity_make_nofollow_filter' );
  59. add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
  60. add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
  61. add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
  62. /* Allow shortcodes in activity posts */
  63. add_filter( 'bp_get_activity_content', 'do_shortcode' );
  64. add_filter( 'bp_get_activity_content_body', 'do_shortcode' );
  65. function bp_activity_filter_kses( $content ) {
  66. global $allowedtags;
  67. $activity_allowedtags = $allowedtags;
  68. $activity_allowedtags['span'] = array();
  69. $activity_allowedtags['span']['class'] = array();
  70. $activity_allowedtags['div'] = array();
  71. $activity_allowedtags['div']['class'] = array();
  72. $activity_allowedtags['div']['id'] = array();
  73. $activity_allowedtags['a']['class'] = array();
  74. $activity_allowedtags['img'] = array();
  75. $activity_allowedtags['img']['src'] = array();
  76. $activity_allowedtags['img']['alt'] = array();
  77. $activity_allowedtags['img']['class'] = array();
  78. $activity_allowedtags['img']['width'] = array();
  79. $activity_allowedtags['img']['height'] = array();
  80. $activity_allowedtags['img']['class'] = array();
  81. $activity_allowedtags['img']['id'] = array();
  82. $activity_allowedtags['img']['title'] = array();
  83. $activity_allowedtags['code'] = array();
  84. $activity_allowedtags = apply_filters( 'bp_activity_allowed_tags', $activity_allowedtags );
  85. return wp_kses( $content, $activity_allowedtags );
  86. }
  87. function bp_activity_at_name_filter( $content ) {
  88. include_once( ABSPATH . WPINC . '/registration.php' );
  89. $pattern = '/[@]+([A-Za-z0-9-_]+)/';
  90. preg_match_all( $pattern, $content, $usernames );
  91. /* Make sure there's only one instance of each username */
  92. if ( !$usernames = array_unique( $usernames[1] ) )
  93. return $content;
  94. foreach( (array)$usernames as $username ) {
  95. if ( !$user_id = username_exists( $username ) )
  96. continue;
  97. /* Increase the number of new @ mentions for the user */
  98. $new_mention_count = (int)get_usermeta( $user_id, 'bp_new_mention_count' );
  99. update_usermeta( $user_id, 'bp_new_mention_count', $new_mention_count + 1 );
  100. $content = str_replace( "@$username", "<a href='" . bp_core_get_user_domain( bp_core_get_userid( $username ) ) . "' rel='nofollow'>@$username</a>", $content );
  101. }
  102. return $content;
  103. }
  104. add_filter( 'bp_activity_new_update_content', 'bp_activity_at_name_filter' );
  105. add_filter( 'groups_activity_new_update_content', 'bp_activity_at_name_filter' );
  106. add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' );
  107. add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
  108. add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' );
  109. add_filter( 'bp_activity_comment_content', 'bp_activity_at_name_filter' );
  110. function bp_activity_make_nofollow_filter( $text ) {
  111. return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
  112. }
  113. function bp_activity_make_nofollow_filter_callback( $matches ) {
  114. $text = $matches[1];
  115. $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
  116. return "<a $text rel=\"nofollow\">";
  117. }
  118. ?>