Changeset 3447 for branches/plugin/bbp-includes/bbp-common-functions.php
- Timestamp:
- 08/23/2011 09:44:02 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-common-functions.php
r3435 r3447 806 806 } 807 807 808 /** 809 * Checks topics and replies against the discussion blacklist of blocked keys 810 * 811 * @since bbPress (r3446) 812 * 813 * @global bbPress $bbp 814 * @param array $anonymous_data Anonymous user data 815 * @param int $author_id Topic or reply author ID 816 * @param string $title The title of the content 817 * @param string $content The content being posted 818 * @uses is_super_admin() Allow super admins to bypass blacklist 819 * @uses bbp_current_author_ip() To get current user IP address 820 * @uses bbp_current_author_ua() To get current user agent 821 * @return bool True if test is passed, false if fail 822 */ 823 function bbp_check_for_blacklist( $anonymous_data = false, $author_id = 0, $title = '', $content = '' ) { 824 825 // Bail if super admin is author 826 if ( is_super_admin( $author_id ) ) 827 return true; 828 829 // Define local variable 830 $post = array(); 831 832 /** Blacklist *************************************************************/ 833 834 // Get the moderation keys 835 $blacklist = trim( get_option( 'blacklist_keys' ) ); 836 837 // Bail if blacklist is empty 838 if ( empty( $blacklist ) ) 839 return true; 840 841 /** User Data *************************************************************/ 842 843 // Map anonymous user data 844 if ( !empty( $anonymous_data ) ) { 845 $post['author'] = $anonymous_data['bbp_anonymous_name']; 846 $post['email'] = $anonymous_data['bbp_anonymous_email']; 847 $post['url'] = $anonymous_data['bbp_anonymous_website']; 848 849 // Map current user data 850 } elseif ( !empty( $author_id ) ) { 851 852 // Get author data 853 $user = get_userdata( $author_id ); 854 855 // If data exists, map it 856 if ( !empty( $user ) ) { 857 $post['author'] = $user->display_name; 858 $post['email'] = $user->user_email; 859 $post['url'] = $user->user_url; 860 } 861 } 862 863 // Current user IP and user agent 864 $post['user_ip'] = bbp_current_author_ip(); 865 $post['user_ua'] = bbp_current_author_ua(); 866 867 // Post title and content 868 $post['title'] = $title; 869 $post['content'] = $content; 870 871 /** Words *****************************************************************/ 872 873 // Get words separated by new lines 874 $words = explode( "\n", $blacklist ); 875 876 // Loop through words 877 foreach ( (array) $words as $word ) { 878 879 // Trim the whitespace from the word 880 $word = trim( $word ); 881 882 // Skip empty lines 883 if ( empty( $word ) ) { continue; } 884 885 // Do some escaping magic so that '#' chars in the 886 // spam words don't break things: 887 $word = preg_quote( $word, '#' ); 888 $pattern = "#$word#i"; 889 890 // Loop through post data 891 foreach( $post as $post_data ) { 892 893 // Check each user data for current word 894 if ( preg_match( $pattern, $post_data ) ) { 895 896 // Post does not pass 897 return false; 898 } 899 } 900 } 901 902 // Check passed successfully 903 return true; 904 } 905 808 906 /** Subscriptions *************************************************************/ 809 907
Note: See TracChangeset
for help on using the changeset viewer.