Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/12/2015 05:45:14 AM (11 years ago)
Author:
tw2113
Message:

Further documentation cleanup for Activity Component.

See #6396.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-akismet.php

    r10248 r10253  
    33 * Akismet support for BuddyPress' Activity Stream.
    44 *
    5  * @since 1.6.0
    65 * @package BuddyPress
    76 * @subpackage ActivityAkismet
     7 * @since 1.6.0
    88 */
    99
    10 // Exit if accessed directly
     10// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    1212
    … …  
    1818 */
    1919class BP_Akismet {
     20
    2021        /**
    2122         * The activity last marked as spam.
    2223         *
     24         * @since 1.6.0
     25         *
    2326         * @var BP_Activity_Activity
    24          * @since 1.6.0
    2527         */
    2628        protected $last_activity = null;
    … …  
    4143         */
    4244        protected function setup_actions() {
    43                 // Add nonces to activity stream lists
     45                // Add nonces to activity stream lists.
    4446                add_action( 'bp_after_activity_post_form', array( $this, 'add_activity_stream_nonce' ) );
    4547                add_action( 'bp_activity_entry_comments',  array( $this, 'add_activity_stream_nonce' ) );
    4648
    47                 // Add a "mark as spam" button to individual activity items
     49                // Add a "mark as spam" button to individual activity items.
    4850                add_action( 'bp_activity_entry_meta',      array( $this, 'add_activity_spam_button' ) );
    4951                add_action( 'bp_activity_comment_options', array( $this, 'add_activity_comment_spam_button' ) );
    5052
    51                 // Check activity for spam
     53                // Check activity for spam.
    5254                add_action( 'bp_activity_before_save',     array( $this, 'check_activity' ), 4, 1 );
    5355
    54                 // Tidy up member's latest (activity) update
     56                // Tidy up member's latest (activity) update.
    5557                add_action( 'bp_activity_posted_update',   array( $this, 'check_member_activity_update' ), 1, 3 );
    5658
    57                 // Hooks to extend Activity core spam/ham functions for Akismet
     59                // Hooks to extend Activity core spam/ham functions for Akismet.
    5860                add_action( 'bp_activity_mark_as_spam',    array( $this, 'mark_as_spam' ), 10, 2 );
    5961                add_action( 'bp_activity_mark_as_ham',     array( $this, 'mark_as_ham' ),  10, 2 );
    6062
    61                 // Hook into the Activity wp-admin screen
     63                // Hook into the Activity wp-admin screen.
    6264                add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'comment_row_action' ), 10, 2 );
    6365                add_action( 'bp_activity_admin_load',                array( $this, 'add_history_metabox' ) );
    … …  
    7476         * @param array $actions  The hover links.
    7577         * @param array $activity The activity for the current row being processed.
    76          *
    7778         * @return array The hover links.
    7879         */
    … …  
    8384
    8485                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                        // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same.
    8687                        if ( 'true' == $akismet_result && $activity['is_spam'] )
    8788                                $desc = __( 'Flagged as spam by Akismet', 'buddypress' );
    … …  
    99100                }
    100101
    101                 // add a History item to the hover links, just after Edit
     102                // Add a History item to the hover links, just after Edit.
    102103                if ( $akismet_result ) {
    103104                        $b = array();
    … …  
    139140                $value   = '_bp_as_nonce_' . bp_loggedin_user_id();
    140141
    141                 // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique
     142                // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique.
    142143                if ( 'bp_activity_entry_comments' == current_filter() ) {
    143144                        $form_id .= '_' . bp_get_activity_id();
    … …  
    245246         * @static
    246247         *
    247          * @return array List of activity types.
     248         * @return array $value List of activity types.
    248249         */
    249250        public static function get_activity_types() {
    … …  
    270271         */
    271272        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                // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update().
    273274                $this->last_activity = $activity;
    274275
    … …  
    325326         *
    326327         * @param BP_Activity_Activity $activity Activity item data.
    327          *
    328          * @return array
     328         * @return array $activity_data
    329329         */
    330330        public static function build_akismet_data_package( $activity ) {
    … …  
    383383                        return;
    384384
    385                 // Make sure last_activity is clear to avoid any confusion
     385                // Make sure last_activity is clear to avoid any confusion.
    386386                $this->last_activity = null;
    387387
    388                 // Build data package for Akismet
     388                // Build data package for Akismet.
    389389                $activity_data = BP_Akismet::build_akismet_data_package( $activity );
    390390
    391                 // Check with Akismet to see if this is spam
     391                // Check with Akismet to see if this is spam.
    392392                $activity_data = $this->send_akismet_request( $activity_data, 'check', 'spam' );
    393393
    394                 // Record this item
     394                // Record this item.
    395395                $this->last_activity = $activity;
    396396
    397                 // Store a copy of the data that was submitted to Akismet
     397                // Store a copy of the data that was submitted to Akismet.
    398398                $this->last_activity->akismet_submission = $activity_data;
    399399
    400                 // Spam
     400                // Spam.
    401401                if ( 'true' == $activity_data['bp_as_result'] ) {
    402402                        /**
    … …  
    411411                        do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) );
    412412
    413                         // Mark as spam
     413                        // Mark as spam.
    414414                        bp_activity_mark_as_spam( $activity, 'by_akismet' );
    415415                }
    416416
    417                 // Update activity meta after a spam check
     417                // Update activity meta after a spam check.
    418418                add_action( 'bp_activity_after_save', array( $this, 'update_activity_akismet_meta' ), 1, 1 );
    419419        }
    … …  
    461461         */
    462462        public function update_activity_akismet_meta( $activity ) {
    463                 // Check we're dealing with what was last updated by Akismet
     463                // Check we're dealing with what was last updated by Akismet.
    464464                if ( empty( $this->last_activity ) || !empty( $this->last_activity ) && $activity->id != $this->last_activity->id )
    465465                        return;
    … …  
    469469                        return;
    470470
    471                 // Spam
     471                // Spam.
    472472                if ( 'true' == $this->last_activity->akismet_submission['bp_as_result'] ) {
    473473                        bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'true' );
    474474                        $this->update_activity_history( $activity->id, __( 'Akismet caught this item as spam', 'buddypress' ), 'check-spam' );
    475475
    476                 // Not spam
     476                // Not spam.
    477477                } elseif ( 'false' == $this->last_activity->akismet_submission['bp_as_result'] ) {
    478478                        bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'false' );
    … …  
    485485                }
    486486
    487                 // Record the original data which was submitted to Akismet for checking
     487                // Record the original data which was submitted to Akismet for checking.
    488488                bp_activity_update_meta( $activity->id, '_bp_akismet_submission', $this->last_activity->akismet_submission );
    489489        }
    … …  
    499499         * @param string $check         "check" or "submit".
    500500         * @param string $spam          "spam" or "ham".
    501          *
    502501         * @return array $activity_data Activity data, with Akismet data added.
    503502         */
    … …  
    515514                        $activity_data['is_test'] = 'true';
    516515
    517                 // Loop through _POST args and rekey strings
     516                // Loop through _POST args and rekey strings.
    518517                foreach ( $_POST as $key => $value )
    519518                        if ( is_string( $value ) && 'cookie' != $key )
    520519                                $activity_data['POST_' . $key] = $value;
    521520
    522                 // Keys to ignore
     521                // Keys to ignore.
    523522                $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
    524523
    525                 // Loop through _SERVER args and remove whitelisted keys
     524                // Loop through _SERVER args and remove whitelisted keys.
    526525                foreach ( $_SERVER as $key => $value ) {
    527526
    528                         // Key should not be ignored
     527                        // Key should not be ignored.
    529528                        if ( !in_array( $key, $ignore ) && is_string( $value ) ) {
    530529                                $activity_data[$key] = $value;
    531530
    532                         // Key should be ignored
     531                        // Key should be ignored.
    533532                        } else {
    534533                                $activity_data[$key] = '';
    … …  
    544543                        $path = 'submit-' . $spam;
    545544
    546                 // Send to Akismet
     545                // Send to Akismet.
    547546                add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
    548547                $response = Akismet::http_post( $query_string, $path );
    549548                remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
    550549
    551                 // Get the response
     550                // Get the response.
    552551                if ( ! empty( $response[1] ) && ! is_wp_error( $response[1] ) )
    553552                        $activity_data['bp_as_result'] = $response[1];
    … …  
    555554                        $activity_data['bp_as_result'] = false;
    556555
    557                 // Perform a daily tidy up
     556                // Perform a daily tidy up.
    558557                if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) )
    559558                        wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' );
    … …  
    568567         *
    569568         * @param string $user_agent User agent string, as generated by Akismet.
    570          *
    571569         * @return string $user_agent Modified user agent string.
    572570         */
    … …  
    584582         */
    585583        function add_history_metabox( $screen_action ) {
    586                 // Only proceed if we're on the edit screen
     584                // Only proceed if we're on the edit screen.
    587585                if ( 'edit' != $screen_action )
    588586                        return;
    589587
    590                 // Display meta box with a low priority (low position on screen by default)
     588                // Display meta box with a low priority (low position on screen by default).
    591589                add_meta_box( 'bp_activity_history',  __( 'Activity History', 'buddypress' ), array( $this, 'history_metabox' ), get_current_screen()->id, 'normal', 'low' );
    592590        }
    … …  
    630628                );
    631629
    632                 // Save the history data
     630                // Save the history data.
    633631                bp_activity_update_meta( $activity_id, '_bp_akismet_history', $event );
    634632        }
    … …  
    640638         *
    641639         * @param int $activity_id Activity item ID.
    642          *
    643640         * @return array The activity item's Akismet history.
    644641         */
    … …  
    648645                        $history = array();
    649646
    650                 // Sort it by the time recorded
     647                // Sort it by the time recorded.
    651648                usort( $history, 'akismet_cmp_time' );
    652649
    … …  
    679676        $interval = apply_filters( 'bp_activity_akismet_delete_meta_interval', 15 );
    680677
    681         // Enforce a minimum of 1 day
     678        // Enforce a minimum of 1 day.
    682679        $interval = max( 1, absint( $interval ) );
    683680
Note: See TracChangeset for help on using the changeset viewer.