Skip to:
Content

BuddyPress.org

Ticket #6191: 6191.03.patch

File 6191.03.patch, 4.9 KB (added by r-a-y, 10 years ago)
  • src/bp-activity/bp-activity-actions.php

     
    712712 * Loads Akismet filtering for activity.
    713713 *
    714714 * @since BuddyPress (1.6.0)
     715 * @since BuddyPress (2.3.0) We only support Akismet 3+.
    715716 */
    716717function bp_activity_setup_akismet() {
    717718        $bp = buddypress();
    718719
    719720        // Bail if Akismet is not active
    720         if ( ! defined( 'AKISMET_VERSION' ) )
     721        if ( ! defined( 'AKISMET_VERSION' ) ) {
    721722                return;
     723        }
     724
     725        // Bail if older version of Akismet
     726        if ( ! class_exists( 'Akismet' ) ) {
     727                return;
     728        }
    722729
    723730        // Bail if no Akismet key is set
    724         if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) )
     731        if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) ) {
    725732                return;
     733        }
    726734
    727735        /**
    728736         * Filters if BuddyPress Activity Akismet support has been disabled by another plugin.
     
    731739         *
    732740         * @param bool $value Return value of bp_is_akismet_active boolean function.
    733741         */
    734         if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) )
     742        if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
    735743                return;
     744        }
    736745
    737746        // Instantiate Akismet for BuddyPress
    738747        $bp->activity->akismet = new BP_Akismet();
  • src/bp-activity/bp-activity-akismet.php

     
    1414 * Akismet support for the Activity component.
    1515 *
    1616 * @since BuddyPress (1.6.0)
     17 * @since BuddyPress (2.3.0) We only support Akismet 3+.
    1718 */
    1819class BP_Akismet {
    1920        /**
     
    339340                $activity_data['comment_type']          = $activity->type;
    340341                $activity_data['permalink']             = bp_activity_get_permalink( $activity->id, $activity );
    341342                $activity_data['user_ID']               = $userdata->ID;
    342                 $activity_data['user_role']             = akismet_get_user_roles( $userdata->ID );
     343                $activity_data['user_role']             = Akismet::get_user_roles( $userdata->ID );
    343344
    344345                /**
    345346                 * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
     
    495496         *
    496497         * @since BuddyPress (1.6.0)
    497498         *
    498          * @global string $akismet_api_host
    499          * @global string $akismet_api_port
    500          *
    501499         * @param array  $activity_data Packet of information to submit to Akismet.
    502500         * @param string $check         "check" or "submit".
    503501         * @param string $spam          "spam" or "ham".
     
    505503         * @return array $activity_data Activity data, with Akismet data added.
    506504         */
    507505        public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) {
    508                 global $akismet_api_host, $akismet_api_port;
    509 
    510                 // Check that host and port are set, if not, set them
    511                 if ( function_exists( 'akismet_init' ) && ( empty( $akismet_api_host ) || empty( $akismet_api_port ) ) )
    512                         akismet_init();
    513 
    514506                $query_string = $path = '';
    515507
    516508                $activity_data['blog']         = bp_get_option( 'home' );
     
    520512                $activity_data['user_agent']   = bp_core_current_user_ua();
    521513                $activity_data['user_ip']      = bp_core_current_user_ip();
    522514
    523                 if ( akismet_test_mode() )
     515                if ( Akismet::is_test_mode() )
    524516                        $activity_data['is_test'] = 'true';
    525517
    526518                // Loop through _POST args and rekey strings
     
    548540                        $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&';
    549541
    550542                if ( 'check' == $check )
    551                         $path = '/1.1/comment-check';
     543                        $path = 'comment-check';
    552544                elseif ( 'submit' == $check )
    553                         $path = '/1.1/submit-' . $spam;
     545                        $path = 'submit-' . $spam;
    554546
    555547                // Send to Akismet
    556548                add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
    557                 $response = akismet_http_post( $query_string, $akismet_api_host, $path, $akismet_api_port );
     549                $response = Akismet::http_post( $query_string, $path );
    558550                remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
    559551
    560552                // Get the response
     
    634626                $event = array(
    635627                        'event'   => $event,
    636628                        'message' => $message,
    637                         'time'    => akismet_microtime(),
     629                        'time'    => Akismet::_get_microtime(),
    638630                        'user'    => bp_loggedin_user_id(),
    639631                );
    640632
  • src/bp-activity/bp-activity-loader.php

     
    6262                $akismet_key = bp_get_option( 'wordpress_api_key' );
    6363
    6464                /** This filter is documented in bp-activity/bp-activity-actions.php */
    65                 if ( defined( 'AKISMET_VERSION' ) && ( !empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
     65                if ( defined( 'AKISMET_VERSION' ) && class_exists( 'Akismet' ) && ( ! empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
    6666                        $includes[] = 'akismet';
    6767                }
    6868