Changeset 10516 for trunk/src/bp-activity/bp-activity-akismet.php
- Timestamp:
- 02/05/2016 03:54:56 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/bp-activity/bp-activity-akismet.php ΒΆ
r10455 r10516 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Akismet support for the Activity component. 15 * 16 * @since 1.6.0 17 * @since 2.3.0 We only support Akismet 3+. 18 */ 19 class BP_Akismet { 20 21 /** 22 * The activity last marked as spam. 23 * 24 * @since 1.6.0 25 * @var BP_Activity_Activity 26 */ 27 protected $last_activity = null; 28 29 /** 30 * Constructor. 31 * 32 * @since 1.6.0 33 */ 34 public function __construct() { 35 $this->setup_actions(); 36 } 37 38 /** 39 * Hook Akismet into the activity stream. 40 * 41 * @since 1.6.0 42 */ 43 protected function setup_actions() { 44 // Add nonces to activity stream lists. 45 add_action( 'bp_after_activity_post_form', array( $this, 'add_activity_stream_nonce' ) ); 46 add_action( 'bp_activity_entry_comments', array( $this, 'add_activity_stream_nonce' ) ); 47 48 // Add a "mark as spam" button to individual activity items. 49 add_action( 'bp_activity_entry_meta', array( $this, 'add_activity_spam_button' ) ); 50 add_action( 'bp_activity_comment_options', array( $this, 'add_activity_comment_spam_button' ) ); 51 52 // Check activity for spam. 53 add_action( 'bp_activity_before_save', array( $this, 'check_activity' ), 4, 1 ); 54 55 // Tidy up member's latest (activity) update. 56 add_action( 'bp_activity_posted_update', array( $this, 'check_member_activity_update' ), 1, 3 ); 57 58 // Hooks to extend Activity core spam/ham functions for Akismet. 59 add_action( 'bp_activity_mark_as_spam', array( $this, 'mark_as_spam' ), 10, 2 ); 60 add_action( 'bp_activity_mark_as_ham', array( $this, 'mark_as_ham' ), 10, 2 ); 61 62 // Hook into the Activity wp-admin screen. 63 add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'comment_row_action' ), 10, 2 ); 64 add_action( 'bp_activity_admin_load', array( $this, 'add_history_metabox' ) ); 65 } 66 67 /** 68 * Add a history item to the hover links in an activity's row. 69 * 70 * This function lifted with love from the Akismet WordPress plugin's 71 * akismet_comment_row_action() function. Thanks! 72 * 73 * @since 1.6.0 74 * 75 * @param array $actions The hover links. 76 * @param array $activity The activity for the current row being processed. 77 * @return array The hover links. 78 */ 79 function comment_row_action( $actions, $activity ) { 80 $akismet_result = bp_activity_get_meta( $activity['id'], '_bp_akismet_result' ); 81 $user_result = bp_activity_get_meta( $activity['id'], '_bp_akismet_user_result' ); 82 $desc = ''; 83 84 if ( !$user_result || $user_result == $akismet_result ) { 85 // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same. 86 if ( 'true' == $akismet_result && $activity['is_spam'] ) 87 $desc = __( 'Flagged as spam by Akismet', 'buddypress' ); 88 89 elseif ( 'false' == $akismet_result && !$activity['is_spam'] ) 90 $desc = __( 'Cleared by Akismet', 'buddypress' ); 91 92 } else { 93 $who = bp_activity_get_meta( $activity['id'], '_bp_akismet_user' ); 94 95 if ( 'true' == $user_result ) 96 $desc = sprintf( __( 'Flagged as spam by %s', 'buddypress' ), $who ); 97 else 98 $desc = sprintf( __( 'Un-spammed by %s', 'buddypress' ), $who ); 99 } 100 101 // Add a History item to the hover links, just after Edit. 102 if ( $akismet_result ) { 103 $b = array(); 104 foreach ( $actions as $k => $item ) { 105 $b[ $k ] = $item; 106 if ( $k == 'edit' ) 107 $b['history'] = '<a href="' . esc_url( bp_get_admin_url( 'admin.php?page=bp-activity&action=edit&aid=' . $activity['id'] ) ) . '#bp_activity_history"> '. __( 'History', 'buddypress' ) . '</a>'; 108 } 109 110 $actions = $b; 111 } 112 113 if ( $desc ) 114 echo '<span class="akismet-status"><a href="' . esc_url( bp_get_admin_url( 'admin.php?page=bp-activity&action=edit&aid=' . $activity['id'] ) ) . '#bp_activity_history">' . htmlspecialchars( $desc ) . '</a></span>'; 115 116 /** 117 * Filters the list of actions for the current activity's row. 118 * 119 * @since 1.6.0 120 * 121 * @param array $actions Array of available actions for the current activity item's row. 122 */ 123 return apply_filters( 'bp_akismet_comment_row_action', $actions ); 124 } 125 126 /** 127 * Generate nonces for activity forms. 128 * 129 * These nonces appear in the member profile status form, as well as in 130 * the reply form of each activity item. The nonces are, in turn, used 131 * by Akismet to help detect spam activity. 132 * 133 * @since 1.6.0 134 * 135 * @see https://plugins.trac.wordpress.org/ticket/1232 136 */ 137 public function add_activity_stream_nonce() { 138 $form_id = '_bp_as_nonce'; 139 $value = '_bp_as_nonce_' . bp_loggedin_user_id(); 140 141 // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique. 142 if ( 'bp_activity_entry_comments' == current_filter() ) { 143 $form_id .= '_' . bp_get_activity_id(); 144 $value .= '_' . bp_get_activity_id(); 145 } 146 147 wp_nonce_field( $value, $form_id, false ); 148 } 149 150 /** 151 * Clean up the bp_latest_update usermeta in case of spamming. 152 * 153 * Run just after an update is posted, this method check to see whether 154 * the newly created update has been marked as spam by Akismet. If so, 155 * the cached update is cleared from the user's 'bp_latest_update' 156 * usermeta, ensuring that it won't appear in the member header and 157 * elsewhere in the theme. 158 * 159 * This can't be done in BP_Akismet::check_activity() due to the 160 * default AJAX implementation; see bp_dtheme_post_update(). 161 * 162 * @since 1.6.0 163 * 164 * @see bp_dtheme_post_update() 165 * 166 * @param string $content Activity update text. 167 * @param int $user_id User ID. 168 * @param int $activity_id Activity ID. 169 */ 170 public function check_member_activity_update( $content, $user_id, $activity_id ) { 171 // By default, only handle activity updates and activity comments. 172 if ( empty( $this->last_activity ) || !in_array( $this->last_activity->type, BP_Akismet::get_activity_types() ) ) 173 return; 174 175 // Was this $activity_id just marked as spam? If not, bail out. 176 if ( !$this->last_activity->id || $activity_id != $this->last_activity->id || 'false' == $this->last_activity->akismet_submission['bp_as_result'] ) 177 return; 178 179 // It was, so delete the member's latest activity update. 180 bp_delete_user_meta( $user_id, 'bp_latest_update' ); 181 } 182 183 /** 184 * Adds a "mark as spam" button to each activity item for site admins. 185 * 186 * This function is intended to be used inside the activity stream loop. 187 * 188 * @since 1.6.0 189 */ 190 public function add_activity_spam_button() { 191 if ( !bp_activity_user_can_mark_spam() ) 192 return; 193 194 // By default, only handle activity updates and activity comments. 195 if ( !in_array( bp_get_activity_type(), BP_Akismet::get_activity_types() ) ) 196 return; 197 198 bp_button( 199 array( 200 'block_self' => false, 201 'component' => 'activity', 202 'id' => 'activity_make_spam_' . bp_get_activity_id(), 203 'link_class' => 'bp-secondary-action spam-activity confirm button item-button', 204 'link_href' => wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . bp_get_activity_id() . '/', 'bp_activity_akismet_spam_' . bp_get_activity_id() ), 205 'link_text' => __( 'Spam', 'buddypress' ), 206 'wrapper' => false, 207 ) 208 ); 209 } 210 211 /** 212 * Adds a "mark as spam" button to each activity COMMENT item for site admins. 213 * 214 * This function is intended to be used inside the activity stream loop. 215 * 216 * @since 1.6.0 217 */ 218 public function add_activity_comment_spam_button() { 219 if ( !bp_activity_user_can_mark_spam() ) 220 return; 221 222 // By default, only handle activity updates and activity comments. 223 $current_comment = bp_activity_current_comment(); 224 if ( empty( $current_comment ) || !in_array( $current_comment->type, BP_Akismet::get_activity_types() ) ) 225 return; 226 227 bp_button( 228 array( 229 'block_self' => false, 230 'component' => 'activity', 231 'id' => 'activity_make_spam_' . bp_get_activity_comment_id(), 232 'link_class' => 'bp-secondary-action spam-activity-comment confirm', 233 'link_href' => wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . bp_get_activity_comment_id() . '/?cid=' . bp_get_activity_comment_id(), 'bp_activity_akismet_spam_' . bp_get_activity_comment_id() ), 234 'link_text' => __( 'Spam', 'buddypress' ), 235 'wrapper' => false, 236 ) 237 ); 238 } 239 240 /** 241 * Get a filterable list of activity types that Akismet should automatically check for spam. 242 * 243 * @since 1.6.0 244 * 245 * @static 246 * 247 * @return array $value List of activity types. 248 */ 249 public static function get_activity_types() { 250 251 /** 252 * Filters the list of activity types that Akismet should automatically check for spam. 253 * 254 * @since 1.6.0 255 * 256 * @param array $value Array of default activity types for Akismet to check. 257 */ 258 return apply_filters( 'bp_akismet_get_activity_types', array( 'activity_comment', 'activity_update' ) ); 259 } 260 261 /** 262 * Mark activity item as spam. 263 * 264 * @since 1.6.0 265 * 266 * @param BP_Activity_Activity $activity Activity item being spammed. 267 * @param string $source Either "by_a_person" (e.g. a person has 268 * manually marked the activity as spam) or 269 * "by_akismet" (automatically spammed). 270 */ 271 public function mark_as_spam( $activity, $source ) { 272 // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update(). 273 $this->last_activity = $activity; 274 275 /** 276 * Fires after marking an activity item has been marked as spam. 277 * 278 * @since 1.6.0 279 * 280 * @param BP_Activity_Activity $activity Activity object being marked as spam. 281 * @param string $source Source of the whom marked as spam. 282 * Either "by_a_person" (e.g. a person has 283 * manually marked the activity as spam) 284 * or "by_akismet". 285 */ 286 do_action( 'bp_activity_akismet_mark_as_spam', $activity, $source ); 287 } 288 289 /** 290 * Mark activity item as ham. 291 * 292 * @since 1.6.0 293 * 294 * @param BP_Activity_Activity $activity Activity item being hammed. 295 * @param string $source Either "by_a_person" (e.g. a person has 296 * manually marked the activity as ham) or 297 * "by_akismet" (automatically hammed). 298 */ 299 public function mark_as_ham( $activity, $source ) { 300 // If the activity was, originally, automatically marked as spam by Akismet, run the @mentions filter as it would have been skipped. 301 if ( 'true' == bp_activity_get_meta( $activity->id, '_bp_akismet_result' ) && !bp_activity_get_meta( $activity->id, '_bp_akismet_user_result' ) ) 302 $activity->content = bp_activity_at_name_filter( $activity->content, $activity->id ); 303 304 /** 305 * Fires after marking an activity item has been marked as ham. 306 * 307 * @since 1.6.0 308 * 309 * @param BP_Activity_Activity $activity Activity object being marked as ham. 310 * @param string $source Source of the whom marked as ham. 311 * Either "by_a_person" (e.g. a person has 312 * manually marked the activity as ham) or 313 * "by_akismet" (automatically hammed). 314 */ 315 do_action( 'bp_activity_akismet_mark_as_ham', $activity, $source ); 316 } 317 318 /** 319 * Build a data package for the Akismet service to inspect. 320 * 321 * @since 1.6.0 322 * 323 * @see http://akismet.com/development/api/#comment-check 324 * @static 325 * 326 * @param BP_Activity_Activity $activity Activity item data. 327 * @return array $activity_data 328 */ 329 public static function build_akismet_data_package( $activity ) { 330 $userdata = get_userdata( $activity->user_id ); 331 332 $activity_data = array(); 333 $activity_data['akismet_comment_nonce'] = 'inactive'; 334 $activity_data['comment_author'] = $userdata->display_name; 335 $activity_data['comment_author_email'] = $userdata->user_email; 336 $activity_data['comment_author_url'] = bp_core_get_userlink( $userdata->ID, false, true); 337 $activity_data['comment_content'] = $activity->content; 338 $activity_data['comment_type'] = $activity->type; 339 $activity_data['permalink'] = bp_activity_get_permalink( $activity->id, $activity ); 340 $activity_data['user_ID'] = $userdata->ID; 341 $activity_data['user_role'] = Akismet::get_user_roles( $userdata->ID ); 342 343 /** 344 * Get the nonce if the new activity was submitted through the "what's up, Paul?" form. 345 * This helps Akismet ensure that the update was a valid form submission. 346 */ 347 if ( !empty( $_POST['_bp_as_nonce'] ) ) 348 $activity_data['akismet_comment_nonce'] = wp_verify_nonce( $_POST['_bp_as_nonce'], "_bp_as_nonce_{$userdata->ID}" ) ? 'passed' : 'failed'; 349 350 /** 351 * If the new activity was a reply to an existing item, check the nonce with the activity parent ID. 352 * This helps Akismet ensure that the update was a valid form submission. 353 */ 354 elseif ( !empty( $activity->secondary_item_id ) && !empty( $_POST['_bp_as_nonce_' . $activity->secondary_item_id] ) ) 355 $activity_data['akismet_comment_nonce'] = wp_verify_nonce( $_POST["_bp_as_nonce_{$activity->secondary_item_id}"], "_bp_as_nonce_{$userdata->ID}_{$activity->secondary_item_id}" ) ? 'passed' : 'failed'; 356 357 /** 358 * Filters activity data before being sent to Akismet to inspect. 359 * 360 * @since 1.6.0 361 * 362 * @param array $activity_data Array of activity data for Akismet to inspect. 363 * @param BP_Activity_Activity $activity Activity item data. 364 */ 365 return apply_filters( 'bp_akismet_build_akismet_data_package', $activity_data, $activity ); 366 } 367 368 /** 369 * Check if the activity item is spam or ham. 370 * 371 * @since 1.6.0 372 * 373 * @see http://akismet.com/development/api/ 374 * @todo Spam counter? 375 * @todo Auto-delete old spam? 376 * 377 * @param BP_Activity_Activity $activity The activity item to check. 378 */ 379 public function check_activity( $activity ) { 380 // By default, only handle activity updates and activity comments. 381 if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) ) 382 return; 383 384 // Make sure last_activity is clear to avoid any confusion. 385 $this->last_activity = null; 386 387 // Build data package for Akismet. 388 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 389 390 // Check with Akismet to see if this is spam. 391 $activity_data = $this->send_akismet_request( $activity_data, 'check', 'spam' ); 392 393 // Record this item. 394 $this->last_activity = $activity; 395 396 // Store a copy of the data that was submitted to Akismet. 397 $this->last_activity->akismet_submission = $activity_data; 398 399 // Spam. 400 if ( 'true' == $activity_data['bp_as_result'] ) { 401 /** 402 * Fires after an activity item has been proven to be spam, but before officially being marked as spam. 403 * 404 * @since 1.6.0 405 * 406 * @param BP_Activity_Activity $activity The activity item proven to be spam. 407 * @param array $activity_data Array of activity data for item including 408 * Akismet check results data. 409 */ 410 do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) ); 411 412 // Mark as spam. 413 bp_activity_mark_as_spam( $activity, 'by_akismet' ); 414 } 415 416 // Update activity meta after a spam check. 417 add_action( 'bp_activity_after_save', array( $this, 'update_activity_akismet_meta' ), 1, 1 ); 418 } 419 420 /** 421 * Update activity meta after a manual spam change (user-initiated). 422 * 423 * @since 1.6.0 424 * 425 * @param BP_Activity_Activity $activity The activity to check. 426 */ 427 public function update_activity_spam_meta( $activity ) { 428 // By default, only handle activity updates and activity comments. 429 if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) ) 430 return; 431 432 $this->update_activity_history( $activity->id, sprintf( __( '%s reported this activity as spam', 'buddypress' ), bp_get_loggedin_user_username() ), 'report-spam' ); 433 bp_activity_update_meta( $activity->id, '_bp_akismet_user_result', 'true' ); 434 bp_activity_update_meta( $activity->id, '_bp_akismet_user', bp_get_loggedin_user_username() ); 435 } 436 437 /** 438 * Update activity meta after a manual ham change (user-initiated). 439 * 440 * @since 1.6.0 441 * 442 * @param BP_Activity_Activity $activity The activity to check. 443 */ 444 public function update_activity_ham_meta( $activity ) { 445 // By default, only handle activity updates and activity comments. 446 if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) ) 447 return; 448 449 $this->update_activity_history( $activity->id, sprintf( __( '%s reported this activity as not spam', 'buddypress' ), bp_get_loggedin_user_username() ), 'report-ham' ); 450 bp_activity_update_meta( $activity->id, '_bp_akismet_user_result', 'false' ); 451 bp_activity_update_meta( $activity->id, '_bp_akismet_user', bp_get_loggedin_user_username() ); 452 } 453 454 /** 455 * Update activity meta after an automatic spam check (not user-initiated). 456 * 457 * @since 1.6.0 458 * 459 * @param BP_Activity_Activity $activity The activity to check. 460 */ 461 public function update_activity_akismet_meta( $activity ) { 462 // Check we're dealing with what was last updated by Akismet. 463 if ( empty( $this->last_activity ) || !empty( $this->last_activity ) && $activity->id != $this->last_activity->id ) 464 return; 465 466 // By default, only handle activity updates and activity comments. 467 if ( !in_array( $this->last_activity->type, BP_Akismet::get_activity_types() ) ) 468 return; 469 470 // Spam. 471 if ( 'true' == $this->last_activity->akismet_submission['bp_as_result'] ) { 472 bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'true' ); 473 $this->update_activity_history( $activity->id, __( 'Akismet caught this item as spam', 'buddypress' ), 'check-spam' ); 474 475 // Not spam. 476 } elseif ( 'false' == $this->last_activity->akismet_submission['bp_as_result'] ) { 477 bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'false' ); 478 $this->update_activity_history( $activity->id, __( 'Akismet cleared this item', 'buddypress' ), 'check-ham' ); 479 480 // Uh oh, something's gone horribly wrong. Unexpected result. 481 } else { 482 bp_activity_update_meta( $activity->id, '_bp_akismet_error', bp_core_current_time() ); 483 $this->update_activity_history( $activity->id, sprintf( __( 'Akismet was unable to check this item (response: %s), will automatically retry again later.', 'buddypress' ), $this->last_activity->akismet_submission['bp_as_result'] ), 'check-error' ); 484 } 485 486 // Record the original data which was submitted to Akismet for checking. 487 bp_activity_update_meta( $activity->id, '_bp_akismet_submission', $this->last_activity->akismet_submission ); 488 } 489 490 /** 491 * Contact Akismet to check if this is spam or ham. 492 * 493 * Props to WordPress core Akismet plugin for a lot of this. 494 * 495 * @since 1.6.0 496 * 497 * @param array $activity_data Packet of information to submit to Akismet. 498 * @param string $check "check" or "submit". 499 * @param string $spam "spam" or "ham". 500 * @return array $activity_data Activity data, with Akismet data added. 501 */ 502 public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) { 503 $query_string = $path = ''; 504 505 $activity_data['blog'] = bp_get_option( 'home' ); 506 $activity_data['blog_charset'] = bp_get_option( 'blog_charset' ); 507 $activity_data['blog_lang'] = get_locale(); 508 $activity_data['referrer'] = $_SERVER['HTTP_REFERER']; 509 $activity_data['user_agent'] = bp_core_current_user_ua(); 510 $activity_data['user_ip'] = bp_core_current_user_ip(); 511 512 if ( Akismet::is_test_mode() ) 513 $activity_data['is_test'] = 'true'; 514 515 // Loop through _POST args and rekey strings. 516 foreach ( $_POST as $key => $value ) 517 if ( is_string( $value ) && 'cookie' != $key ) 518 $activity_data['POST_' . $key] = $value; 519 520 // Keys to ignore. 521 $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ); 522 523 // Loop through _SERVER args and remove whitelisted keys. 524 foreach ( $_SERVER as $key => $value ) { 525 526 // Key should not be ignored. 527 if ( !in_array( $key, $ignore ) && is_string( $value ) ) { 528 $activity_data[$key] = $value; 529 530 // Key should be ignored. 531 } else { 532 $activity_data[$key] = ''; 533 } 534 } 535 536 foreach ( $activity_data as $key => $data ) 537 $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&'; 538 539 if ( 'check' == $check ) 540 $path = 'comment-check'; 541 elseif ( 'submit' == $check ) 542 $path = 'submit-' . $spam; 543 544 // Send to Akismet. 545 add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) ); 546 $response = Akismet::http_post( $query_string, $path ); 547 remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) ); 548 549 // Get the response. 550 if ( ! empty( $response[1] ) && ! is_wp_error( $response[1] ) ) 551 $activity_data['bp_as_result'] = $response[1]; 552 else 553 $activity_data['bp_as_result'] = false; 554 555 // Perform a daily tidy up. 556 if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) ) 557 wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' ); 558 559 return $activity_data; 560 } 561 562 /** 563 * Filters user agent when sending to Akismet to add BuddyPress info. 564 * 565 * @since 1.6.0 566 * 567 * @param string $user_agent User agent string, as generated by Akismet. 568 * @return string $user_agent Modified user agent string. 569 */ 570 public function buddypress_ua( $user_agent ) { 571 $user_agent = 'BuddyPress/' . bp_get_version() . ' | Akismet/'. constant( 'AKISMET_VERSION' ); 572 return $user_agent; 573 } 574 575 /** 576 * Adds a "History" meta box to the activity edit screen. 577 * 578 * @since 1.6.0 579 * 580 * @param string $screen_action The type of screen that has been requested. 581 */ 582 function add_history_metabox( $screen_action ) { 583 // Only proceed if we're on the edit screen. 584 if ( 'edit' != $screen_action ) 585 return; 586 587 // Display meta box with a low priority (low position on screen by default). 588 add_meta_box( 'bp_activity_history', __( 'Activity History', 'buddypress' ), array( $this, 'history_metabox' ), get_current_screen()->id, 'normal', 'low' ); 589 } 590 591 /** 592 * History meta box for the Activity admin edit screen. 593 * 594 * @since 1.6.0 595 * 596 * @see https://buddypress.trac.wordpress.org/ticket/3907 597 * @todo Update activity meta to allow >1 record with the same key (iterate through $history). 598 * 599 * @param object $item Activity item. 600 */ 601 function history_metabox( $item ) { 602 $history = BP_Akismet::get_activity_history( $item->id ); 603 604 if ( empty( $history ) ) 605 return; 606 607 echo '<div class="akismet-history"><div>'; 608 printf( _x( '%1$s — %2$s', 'x hours ago - akismet cleared this item', 'buddypress' ), '<span>' . bp_core_time_since( $history[2] ) . '</span>', esc_html( $history[1] ) ); 609 echo '</div></div>'; 610 } 611 612 /** 613 * Update an activity item's Akismet history. 614 * 615 * @since 1.6.0 616 * 617 * @param int $activity_id Activity item ID. 618 * @param string $message Human-readable description of what's changed. 619 * @param string $event The type of check we were carrying out. 620 */ 621 public function update_activity_history( $activity_id = 0, $message = '', $event = '' ) { 622 $event = array( 623 'event' => $event, 624 'message' => $message, 625 'time' => Akismet::_get_microtime(), 626 'user' => bp_loggedin_user_id(), 627 ); 628 629 // Save the history data. 630 bp_activity_update_meta( $activity_id, '_bp_akismet_history', $event ); 631 } 632 633 /** 634 * Get an activity item's Akismet history. 635 * 636 * @since 1.6.0 637 * 638 * @param int $activity_id Activity item ID. 639 * @return array The activity item's Akismet history. 640 */ 641 public function get_activity_history( $activity_id = 0 ) { 642 $history = bp_activity_get_meta( $activity_id, '_bp_akismet_history' ); 643 if ( $history === false ) 644 $history = array(); 645 646 // Sort it by the time recorded. 647 usort( $history, 'akismet_cmp_time' ); 648 649 return $history; 650 } 651 } 13 require dirname( __FILE__ ) . '/classes/class-bp-akismet.php'; 652 14 653 15 /**
Note: See TracChangeset
for help on using the changeset viewer.