Make WordPress Core

Changeset 20856


Ignore:
Timestamp:
05/23/2012 08:40:40 PM (12 years ago)
Author:
ryan
Message:

Introduce _prepare_comment(). Avoid repeated auth attempts. Props maxcutler. fixes #20703

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r20846 r20856  
    826826
    827827    /**
     828     * Prepares comment data for return in an XML-RPC object.
     829     *
     830     * @access protected
     831     *
     832     * @param object $comment The unprepared comment data
     833     * @return array The prepared comment data
     834     */
     835    protected function _prepare_comment( $comment ) {
     836        // Format page date.
     837        $comment_date = $this->_convert_date( $comment->comment_date );
     838        $comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date );
     839
     840        if ( '0' == $comment->comment_approved )
     841            $comment_status = 'hold';
     842        else if ( 'spam' == $comment->comment_approved )
     843            $comment_status = 'spam';
     844        else if ( '1' == $comment->comment_approved )
     845            $comment_status = 'approve';
     846        else
     847            $comment_status = $comment->comment_approved;
     848
     849        $_comment = array(
     850            'date_created_gmt' => $comment_date_gmt,
     851            'user_id'          => $comment->user_id,
     852            'comment_id'       => $comment->comment_ID,
     853            'parent'           => $comment->comment_parent,
     854            'status'           => $comment_status,
     855            'content'          => $comment->comment_content,
     856            'link'             => get_comment_link($comment),
     857            'post_id'          => $comment->comment_post_ID,
     858            'post_title'       => get_the_title($comment->comment_post_ID),
     859            'author'           => $comment->comment_author,
     860            'author_url'       => $comment->comment_author_url,
     861            'author_email'     => $comment->comment_author_email,
     862            'author_ip'        => $comment->comment_author_IP,
     863            'type'             => $comment->comment_type,
     864        );
     865
     866        return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment );
     867    }
     868
     869    /**
    828870     * Create a new post for any registered post type.
    829871     *
     
    23622404            return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
    23632405
    2364         // Format page date.
    2365         $comment_date = $this->_convert_date( $comment->comment_date );
    2366         $comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date );
    2367 
    2368         if ( '0' == $comment->comment_approved )
    2369             $comment_status = 'hold';
    2370         else if ( 'spam' == $comment->comment_approved )
    2371             $comment_status = 'spam';
    2372         else if ( '1' == $comment->comment_approved )
    2373             $comment_status = 'approve';
    2374         else
    2375             $comment_status = $comment->comment_approved;
    2376 
    2377         $link = get_comment_link($comment);
    2378 
    2379         $comment_struct = array(
    2380             'date_created_gmt'      => $comment_date_gmt,
    2381             'user_id'               => $comment->user_id,
    2382             'comment_id'            => $comment->comment_ID,
    2383             'parent'                => $comment->comment_parent,
    2384             'status'                => $comment_status,
    2385             'content'               => $comment->comment_content,
    2386             'link'                  => $link,
    2387             'post_id'               => $comment->comment_post_ID,
    2388             'post_title'            => get_the_title($comment->comment_post_ID),
    2389             'author'                => $comment->comment_author,
    2390             'author_url'            => $comment->comment_author_url,
    2391             'author_email'          => $comment->comment_author_email,
    2392             'author_ip'             => $comment->comment_author_IP,
    2393             'type'                  => $comment->comment_type,
    2394         );
    2395 
    2396         return $comment_struct;
     2406        return $this->_prepare_comment( $comment );
    23972407    }
    23982408
     
    24172427     */
    24182428    function wp_getComments($args) {
    2419         $raw_args = $args;
    24202429        $this->escape($args);
    24212430
     
    24232432        $username   = $args[1];
    24242433        $password   = $args[2];
    2425         $struct     = $args[3];
     2434        $struct     = isset( $args[3] ) ? $args[3] : array();
    24262435
    24272436        if ( !$user = $this->login($username, $password) )
     
    24512460
    24522461        $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
    2453         $num_comments = count($comments);
    2454 
    2455         if ( ! $num_comments )
    2456             return array();
    24572462
    24582463        $comments_struct = array();
    24592464
    2460         // FIXME: we already have the comments, why query them again?
    2461         for ( $i = 0; $i < $num_comments; $i++ ) {
    2462             $comment = wp_xmlrpc_server::wp_getComment(array(
    2463                 $raw_args[0], $raw_args[1], $raw_args[2], $comments[$i]->comment_ID,
    2464             ));
    2465             $comments_struct[] = $comment;
     2465        foreach ( $comments as $comment ) {
     2466            $comments_struct[] = $this->_prepare_comment( $comment );
    24662467        }
    24672468
Note: See TracChangeset for help on using the changeset viewer.