Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/05/2011 09:38:08 PM (13 years ago)
Author:
djpaul
Message:

Add Akismet history information to the Activity admin page's items.
Use new wrapper functions to get user's UA and IP for Akismet calls.
Rename Activity admin page slug.

File:
1 edited

Legend:

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

    r5276 r5280  
    5555
    5656        // Hook into the Activity wp-admin screen
    57         //add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'add_activity_status_row' ), 10, 2 );
    58     }
     57        add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'comment_row_action' ), 10, 2 );
     58    }
     59
     60    /**
     61     * Add a history item to the hover links in an activity's row.
     62     *
     63     * This function lifted with love from the Akismet WordPress plugin's
     64     * akismet_comment_row_action() function. Thanks!
     65     *
     66     * @param array $actions The hover links
     67     * @param array $activity The activity for the current row being processed
     68     * @return array The hover links
     69     * @since 1.6
     70     */
     71    function comment_row_action( $actions, $activity ) {
     72        $akismet_result = bp_activity_get_meta( $activity['id'], '_bp_akismet_result' );
     73        $user_result    = bp_activity_get_meta( $activity['id'], '_bp_akismet_user_result' );
     74        $desc           = '';
     75
     76        if ( !$user_result || $user_result == $akismet_result ) {
     77            // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
     78            if ( $akismet_result == 'true' && $activity['is_spam'] )
     79                $desc = __( 'Flagged as spam by Akismet', 'buddypress' );
     80
     81            elseif ( $akismet_result == 'false' && !$activity['is_spam'] )
     82                $desc = __( 'Cleared by Akismet', 'buddypress' );
     83
     84        } else {
     85            $who = bp_activity_get_meta( $activity['id'], '_bp_akismet_user' );
     86
     87            if ( $user_result == 'true' )
     88                $desc = sprintf( __( 'Flagged as spam by %s', 'buddypress' ), $who );
     89            else
     90                $desc = sprintf( __( 'Un-spammed by %s', 'buddypress' ), $who );
     91        }
     92
     93        // add a History item to the hover links, just after Edit
     94        if ( $akismet_result ) {
     95            $b = array();
     96            foreach ( $actions as $k => $item ) {
     97                $b[ $k ] = $item;
     98                if ( $k == 'edit' )
     99                    $b['history'] = '<a href="#"> '. __( 'History', 'buddypress' ) . '</a>';
     100            }
     101
     102            $actions = $b;
     103        }
     104
     105        if ( $desc )
     106            echo '<span class="akismet-status"><a href="#">' . htmlspecialchars( $desc ) . '</a></span>';
     107
     108        return apply_filters( 'bp_akismet_comment_row_action', $actions );
     109    }
     110
    59111
    60112    /**
     
    372424        $activity_data['blog_lang']    = get_locale();
    373425        $activity_data['referrer']     = $_SERVER['HTTP_REFERER'];
    374         $activity_data['user_agent']   = $_SERVER['HTTP_USER_AGENT'];
    375         $activity_data['user_ip']      = $_SERVER['REMOTE_ADDR'];
     426        $activity_data['user_agent']   = bp_core_current_user_ua();
     427        $activity_data['user_ip']      = bp_core_current_user_ip();
    376428
    377429        if ( akismet_test_mode() )
Note: See TracChangeset for help on using the changeset viewer.