Changeset 10356 for trunk/src/bp-core/bp-core-moderation.php
- Timestamp:
- 11/15/2015 07:57:03 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-moderation.php
r10108 r10356 27 27 * 28 28 * @param int $user_id User id to check for flood. 29 *30 29 * @return bool True if there is no flooding, false if there is. 31 30 */ … … 37 36 } 38 37 39 // Bail if no user ID passed 38 // Bail if no user ID passed. 40 39 if ( empty( $user_id ) ) { 41 40 return false; … … 62 61 * @param string $title The title of the content. 63 62 * @param string $content The content being posted. 64 *65 63 * @return bool True if test is passed, false if fail. 66 64 */ … … 81 79 } 82 80 83 // Bail if super admin is author 81 // Bail if super admin is author. 84 82 if ( is_super_admin( $user_id ) ) { 85 83 return true; 86 84 } 87 85 88 // Define local variable(s) 86 // Define local variable(s). 89 87 $_post = array(); 90 88 $match_out = ''; 91 89 92 /** User Data *************************************************************/ 90 /** User Data ************************************************************ 91 */ 93 92 94 93 if ( ! empty( $user_id ) ) { 95 94 96 // Get author data 95 // Get author data. 97 96 $user = get_userdata( $user_id ); 98 97 99 // If data exists, map it 98 // If data exists, map it. 100 99 if ( ! empty( $user ) ) { 101 100 $_post['author'] = $user->display_name; … … 105 104 } 106 105 107 // Current user IP and user agent 106 // Current user IP and user agent. 108 107 $_post['user_ip'] = bp_core_current_user_ip(); 109 108 $_post['user_ua'] = bp_core_current_user_ua(); 110 109 111 // Post title and content 110 // Post title and content. 112 111 $_post['title'] = $title; 113 112 $_post['content'] = $content; 114 113 115 /** Max Links *************************************************************/ 114 /** Max Links ************************************************************ 115 */ 116 116 117 117 $max_links = get_option( 'comment_max_links' ); … … 121 121 $num_links = preg_match_all( '/(http|ftp|https):\/\//i', $content, $match_out ); 122 122 123 // Allow for bumping the max to include the user's URL 123 // Allow for bumping the max to include the user's URL. 124 124 if ( ! empty( $_post['url'] ) ) { 125 125 … … 141 141 } 142 142 143 /** Blacklist *************************************************************/ 144 145 // Get the moderation keys 143 /** Blacklist ************************************************************ 144 */ 145 146 // Get the moderation keys. 146 147 $blacklist = trim( get_option( 'moderation_keys' ) ); 147 148 148 // Bail if blacklist is empty 149 // Bail if blacklist is empty. 149 150 if ( ! empty( $blacklist ) ) { 150 151 151 // Get words separated by new lines 152 // Get words separated by new lines. 152 153 $words = explode( "\n", $blacklist ); 153 154 154 // Loop through words 155 // Loop through words. 155 156 foreach ( (array) $words as $word ) { 156 157 157 // Trim the whitespace from the word 158 // Trim the whitespace from the word. 158 159 $word = trim( $word ); 159 160 160 // Skip empty lines 161 // Skip empty lines. 161 162 if ( empty( $word ) ) { 162 163 continue; … … 164 165 165 166 // Do some escaping magic so that '#' chars in the 166 // spam words don't break things :167 // spam words don't break things. 167 168 $word = preg_quote( $word, '#' ); 168 169 $pattern = "#$word#i"; 169 170 170 // Loop through post data 171 // Loop through post data. 171 172 foreach ( $_post as $post_data ) { 172 173 173 // Check each user data for current word 174 // Check each user data for current word. 174 175 if ( preg_match( $pattern, $post_data ) ) { 175 176 176 // Post does not pass 177 // Post does not pass. 177 178 return false; 178 179 } … … 181 182 } 182 183 183 // Check passed successfully 184 // Check passed successfully. 184 185 return true; 185 186 } … … 197 198 * @param string $title The title of the content. 198 199 * @param string $content The content being posted. 199 *200 200 * @return bool True if test is passed, false if fail. 201 201 */ … … 216 216 } 217 217 218 // Bail if super admin is author 218 // Bail if super admin is author. 219 219 if ( is_super_admin( $user_id ) ) { 220 220 return true; 221 221 } 222 222 223 // Define local variable 223 // Define local variable. 224 224 $_post = array(); 225 225 226 /** Blacklist *************************************************************/ 227 228 // Get the moderation keys 226 /** Blacklist ************************************************************ 227 */ 228 229 // Get the moderation keys. 229 230 $blacklist = trim( get_option( 'blacklist_keys' ) ); 230 231 231 // Bail if blacklist is empty 232 // Bail if blacklist is empty. 232 233 if ( empty( $blacklist ) ) { 233 234 return true; 234 235 } 235 236 236 /** User Data *************************************************************/ 237 238 // Map current user data 237 /** User Data ************************************************************ 238 */ 239 240 // Map current user data. 239 241 if ( ! empty( $user_id ) ) { 240 242 241 // Get author data 243 // Get author data. 242 244 $user = get_userdata( $user_id ); 243 245 244 // If data exists, map it 246 // If data exists, map it. 245 247 if ( ! empty( $user ) ) { 246 248 $_post['author'] = $user->display_name; … … 250 252 } 251 253 252 // Current user IP and user agent 254 // Current user IP and user agent. 253 255 $_post['user_ip'] = bp_core_current_user_ip(); 254 256 $_post['user_ua'] = bp_core_current_user_ua(); 255 257 256 // Post title and content 258 // Post title and content. 257 259 $_post['title'] = $title; 258 260 $_post['content'] = $content; 259 261 260 /** Words *****************************************************************/ 261 262 // Get words separated by new lines 262 /** Words **************************************************************** 263 */ 264 265 // Get words separated by new lines. 263 266 $words = explode( "\n", $blacklist ); 264 267 265 // Loop through words 268 // Loop through words. 266 269 foreach ( (array) $words as $word ) { 267 270 268 // Trim the whitespace from the word 271 // Trim the whitespace from the word. 269 272 $word = trim( $word ); 270 273 271 // Skip empty lines 274 // Skip empty lines. 272 275 if ( empty( $word ) ) { continue; } 273 276 274 277 // Do some escaping magic so that '#' chars in the 275 // spam words don't break things :278 // spam words don't break things. 276 279 $word = preg_quote( $word, '#' ); 277 280 $pattern = "#$word#i"; 278 281 279 // Loop through post data 282 // Loop through post data. 280 283 foreach( $_post as $post_data ) { 281 284 282 // Check each user data for current word 285 // Check each user data for current word. 283 286 if ( preg_match( $pattern, $post_data ) ) { 284 287 285 // Post does not pass 288 // Post does not pass. 286 289 return false; 287 290 } … … 289 292 } 290 293 291 // Check passed successfully 294 // Check passed successfully. 292 295 return true; 293 296 } … … 322 325 function bp_core_current_user_ua() { 323 326 324 // Sanity check the user agent 327 // Sanity check the user agent. 325 328 if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { 326 329 $retval = substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 );
Note: See TracChangeset
for help on using the changeset viewer.