Skip to:
Content

BuddyPress.org

Changeset 9396


Ignore:
Timestamp:
01/21/2015 11:51:57 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Bring BuddyPress core moderation and blacklist functions up to date with bbPress's. See r9392 & r9395.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-moderation.php

    r9395 r9396  
    6565function bp_core_check_for_moderation( $user_id = 0, $title = '', $content = '' ) {
    6666
     67    // Allow for moderation check to be skipped
     68    if ( apply_filters( 'bp_bypass_check_for_moderation', false, $user_id, $title, $content ) ) {
     69        return true;
     70    }
     71
    6772    // Bail if super admin is author
    6873    if ( is_super_admin( $user_id ) ) {
     
    7176
    7277    // Define local variable(s)
    73     $post      = array();
     78    $_post     = array();
    7479    $match_out = '';
    7580
     
    8388        // If data exists, map it
    8489        if ( ! empty( $user ) ) {
    85             $post['author'] = $user->display_name;
    86             $post['email']  = $user->user_email;
    87             $post['url']    = $user->user_url;
     90            $_post['author'] = $user->display_name;
     91            $_post['email']  = $user->user_email;
     92            $_post['url']    = $user->user_url;
    8893        }
    8994    }
    9095
    9196    // Current user IP and user agent
    92     $post['user_ip'] = bp_core_current_user_ip();
    93     $post['user_ua'] = bp_core_current_user_ua();
     97    $_post['user_ip'] = bp_core_current_user_ip();
     98    $_post['user_ua'] = bp_core_current_user_ua();
    9499
    95100    // Post title and content
    96     $post['title']   = $title;
    97     $post['content'] = $content;
     101    $_post['title']   = $title;
     102    $_post['content'] = $content;
    98103
    99104    /** Max Links *************************************************************/
     
    103108
    104109        // How many links?
    105         $num_links = preg_match_all( '/<a [^>]*href/i', $content, $match_out );
     110        $num_links = preg_match_all( '/(http|ftp|https):\/\//i', $content, $match_out );
    106111
    107112        // Allow for bumping the max to include the user's URL
    108         if ( ! empty( $post['url'] ) ) {
    109             $num_links = apply_filters( 'comment_max_links_url', $num_links, $post['url'] );
     113        if ( ! empty( $_post['url'] ) ) {
     114            $num_links = apply_filters( 'comment_max_links_url', $num_links, $_post['url'] );
    110115        }
    111116
     
    122127
    123128    // Bail if blacklist is empty
     129    if ( ! empty( $blacklist ) ) {
     130
     131        // Get words separated by new lines
     132        $words = explode( "\n", $blacklist );
     133
     134        // Loop through words
     135        foreach ( (array) $words as $word ) {
     136
     137            // Trim the whitespace from the word
     138            $word = trim( $word );
     139
     140            // Skip empty lines
     141            if ( empty( $word ) ) {
     142                continue;
     143            }
     144
     145            // Do some escaping magic so that '#' chars in the
     146            // spam words don't break things:
     147            $word    = preg_quote( $word, '#' );
     148            $pattern = "#$word#i";
     149
     150            // Loop through post data
     151            foreach ( $_post as $post_data ) {
     152
     153                // Check each user data for current word
     154                if ( preg_match( $pattern, $post_data ) ) {
     155
     156                    // Post does not pass
     157                    return false;
     158                }
     159            }
     160        }
     161    }
     162
     163    // Check passed successfully
     164    return true;
     165}
     166
     167/**
     168 * Check for blocked keys.
     169 *
     170 * @since BuddyPress (1.6.0)
     171 *
     172 * @uses bp_current_author_ip() To get current user IP address.
     173 * @uses bp_current_author_ua() To get current user agent.
     174 * @uses bp_current_user_can() Allow super admins to bypass blacklist.
     175 *
     176 * @param int $user_id Topic or reply author ID.
     177 * @param string $title The title of the content.
     178 * @param string $content The content being posted.
     179 * @return bool True if test is passed, false if fail.
     180 */
     181function bp_core_check_for_blacklist( $user_id = 0, $title = '', $content = '' ) {
     182
     183    // Allow for blacklist check to be skipped
     184    if ( apply_filters( 'bp_bypass_check_for_blacklist', false, $user_id, $title, $content ) ) {
     185        return true;
     186    }
     187
     188    // Bail if super admin is author
     189    if ( is_super_admin( $user_id ) ) {
     190        return true;
     191    }
     192
     193    // Define local variable
     194    $_post = array();
     195
     196    /** Blacklist *************************************************************/
     197
     198    // Get the moderation keys
     199    $blacklist = trim( get_option( 'blacklist_keys' ) );
     200
     201    // Bail if blacklist is empty
    124202    if ( empty( $blacklist ) ) {
    125203        return true;
    126204    }
     205
     206    /** User Data *************************************************************/
     207
     208    // Map current user data
     209    if ( ! empty( $user_id ) ) {
     210
     211        // Get author data
     212        $user = get_userdata( $user_id );
     213
     214        // If data exists, map it
     215        if ( ! empty( $user ) ) {
     216            $_post['author'] = $user->display_name;
     217            $_post['email']  = $user->user_email;
     218            $_post['url']    = $user->user_url;
     219        }
     220    }
     221
     222    // Current user IP and user agent
     223    $_post['user_ip'] = bp_core_current_user_ip();
     224    $_post['user_ua'] = bp_core_current_user_ua();
     225
     226    // Post title and content
     227    $_post['title']   = $title;
     228    $_post['content'] = $content;
    127229
    128230    /** Words *****************************************************************/
     
    146248
    147249        // Loop through post data
    148         foreach( $post as $post_data ) {
    149 
    150             // Check each user data for current word
    151             if ( preg_match( $pattern, $post_data ) ) {
    152 
    153                 // Post does not pass
    154                 return false;
    155             }
    156         }
    157     }
    158 
    159     // Check passed successfully
    160     return true;
    161 }
    162 
    163 /**
    164  * Check for blocked keys.
    165  *
    166  * @since BuddyPress (1.6.0)
    167  *
    168  * @uses bp_current_author_ip() To get current user IP address.
    169  * @uses bp_current_author_ua() To get current user agent.
    170  * @uses bp_current_user_can() Allow super admins to bypass blacklist.
    171  *
    172  * @param int $user_id Topic or reply author ID.
    173  * @param string $title The title of the content.
    174  * @param string $content The content being posted.
    175  * @return bool True if test is passed, false if fail.
    176  */
    177 function bp_core_check_for_blacklist( $user_id = 0, $title = '', $content = '' ) {
    178 
    179     // Bail if super admin is author
    180     if ( is_super_admin( $user_id ) ) {
    181         return true;
    182     }
    183 
    184     // Define local variable
    185     $post = array();
    186 
    187     /** Blacklist *************************************************************/
    188 
    189     // Get the moderation keys
    190     $blacklist = trim( get_option( 'blacklist_keys' ) );
    191 
    192     // Bail if blacklist is empty
    193     if ( empty( $blacklist ) ) {
    194         return true;
    195     }
    196 
    197     /** User Data *************************************************************/
    198 
    199     // Map current user data
    200     if ( ! empty( $user_id ) ) {
    201 
    202         // Get author data
    203         $user = get_userdata( $user_id );
    204 
    205         // If data exists, map it
    206         if ( ! empty( $user ) ) {
    207             $post['author'] = $user->display_name;
    208             $post['email']  = $user->user_email;
    209             $post['url']    = $user->user_url;
    210         }
    211     }
    212 
    213     // Current user IP and user agent
    214     $post['user_ip'] = bp_core_current_user_ip();
    215     $post['user_ua'] = bp_core_current_user_ua();
    216 
    217     // Post title and content
    218     $post['title']   = $title;
    219     $post['content'] = $content;
    220 
    221     /** Words *****************************************************************/
    222 
    223     // Get words separated by new lines
    224     $words = explode( "\n", $blacklist );
    225 
    226     // Loop through words
    227     foreach ( (array) $words as $word ) {
    228 
    229         // Trim the whitespace from the word
    230         $word = trim( $word );
    231 
    232         // Skip empty lines
    233         if ( empty( $word ) ) { continue; }
    234 
    235         // Do some escaping magic so that '#' chars in the spam words don't break things:
    236         $word    = preg_quote( $word, '#' );
    237         $pattern = "#$word#i";
    238 
    239         // Loop through post data
    240         foreach( $post as $post_data ) {
     250        foreach( $_post as $post_data ) {
    241251
    242252            // Check each user data for current word
Note: See TracChangeset for help on using the changeset viewer.