Skip to:
Content

BuddyPress.org

Ticket #6191: 6191.02.patch

File 6191.02.patch, 2.7 KB (added by r-a-y, 10 years ago)
  • src/bp-activity/bp-activity-akismet.php

     
    326326                $activity_data['comment_type']          = $activity->type;
    327327                $activity_data['permalink']             = bp_activity_get_permalink( $activity->id, $activity );
    328328                $activity_data['user_ID']               = $userdata->ID;
    329                 $activity_data['user_role']             = akismet_get_user_roles( $userdata->ID );
     329                $activity_data['user_role']             = self::call_api( 'get_user_roles', $userdata->ID );
    330330
    331331                /**
    332332                 * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
     
    505505                $activity_data['user_agent']   = bp_core_current_user_ua();
    506506                $activity_data['user_ip']      = bp_core_current_user_ip();
    507507
    508                 if ( akismet_test_mode() )
     508                if ( self::call_api( 'test_mode' ) ) {
    509509                        $activity_data['is_test'] = 'true';
     510                }
    510511
    511512                // Loop through _POST args and rekey strings
    512513                foreach ( $_POST as $key => $value )
     
    539540
    540541                // Send to Akismet
    541542                add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
    542                 $response = akismet_http_post( $query_string, $akismet_api_host, $path, $akismet_api_port );
     543                $response = self::call_api( 'http_post', $query_string, $akismet_api_host, $path, $akismet_api_port );
    543544                remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
    544545
    545546                // Get the response
     
    618619                $event = array(
    619620                        'event'   => $event,
    620621                        'message' => $message,
    621                         'time'    => akismet_microtime(),
     622                        'time'    => self::call_api( 'microtime' ),
    622623                        'user'    => bp_loggedin_user_id(),
    623624                );
    624625
     
    644645
    645646                return $history;
    646647        }
     648
     649        /**
     650         * Call various native Akismet functions.
     651         *
     652         * This was created to support older Akismet versions... unfortunately.
     653         *
     654         * @since BuddyPress (2.3.0)
     655         *
     656         * @param  string $function_name The function or method name to call.
     657         * @param  mixed  $args,...      The arguments supported by $function_name.
     658         * @return mixed
     659         */
     660        public static function call_api( $function_name = '' ) {
     661                $args = func_get_args();
     662                array_shift( $args );
     663
     664                // Akismet >= 3.0
     665                if ( class_exists( 'Akismet' ) ) {
     666                        if ( 'microtime' === $function_name ) {
     667                                $function_name = '_get_microtime';
     668                        } elseif ( 'test_mode' === $function_name ) {
     669                                $function_name = 'is_test_mode';
     670                        } elseif ( 'http_post' === $function_name ) {
     671                                $args = array(
     672                                        $args[0],
     673                                        str_replace( '/1.1/', '', $args[2] )
     674                                );
     675                        }
     676
     677                        $callback = array( 'Akismet', $function_name );
     678
     679                // Akismet < 3.0
     680                } else {
     681                        $callback = "akismet_{$function_name}";
     682                }
     683
     684                return call_user_func_array( $callback, $args );
     685        }
    647686}
    648687
    649688/**