Make WordPress Core

Ticket #7446: 7446.2.diff

File 7446.2.diff, 8.2 KB (added by ryan, 16 years ago)

Drop separate method for setting comment status. Flesh out editComment.

  • wp-includes/comment.php

     
    206206}
    207207
    208208/**
     209 * Retrieve all of the WordPress supported comment statuses.
     210 *
     211 * Comments have a limited set of valid status values, this provides the
     212 * comment status values and descriptions.
     213 *
     214 * @package WordPress
     215 * @subpackage Post
     216 * @since 2.7
     217 *
     218 * @return array List of comment statuses.
     219 */
     220function get_comment_statuses( ) {
     221        $status = array(
     222                'hold'                  => __('Unapproved'),
     223                'approve'               => __('Approved'),
     224                'spam'          => __('Spam'),
     225        );
     226
     227        return $status;
     228}
     229
     230
     231/**
    209232 * The date the last comment was modified.
    210233 *
    211234 * {@internal Missing Long Description}}
  • wp-includes/comment-template.php

     
    320320 * @since 1.5
    321321 * @uses $comment
    322322 *
     323 * @param object|string|int $comment Comment to retrieve.
    323324 * @return string The permalink to the current comment
    324325 */
    325 function get_comment_link() {
    326         global $comment;
     326function get_comment_link($comment = null) {
     327        $comment = get_comment($comment);
    327328        return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
    328329}
    329330
  • xmlrpc.php

     
    829829                return($category_suggestions);
    830830        }
    831831
     832        function wp_getComment($args) {
     833                $this->escape($args);
     834
     835                $blog_id        = (int) $args[0];
     836                $username       = $args[1];
     837                $password       = $args[2];
     838                $comment_id     = (int) $args[3];
     839
     840                if ( !$this->login_pass_ok( $username, $password ) )
     841                        return $this->error;
     842
     843                set_current_user( 0, $username );
     844                if ( !current_user_can( 'moderate_comments' ) )
     845                        return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
     846
     847                if ( ! $comment = get_comment($comment_id) )
     848                        return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
     849
     850                // Format page date.
     851                $comment_date = mysql2date("Ymd\TH:i:s", $comment->comment_date);
     852                $comment_date_gmt = mysql2date("Ymd\TH:i:s", $comment->comment_date_gmt);
     853
     854                if ( 0 == $comment->comment_approved )
     855                        $comment_status = 'hold';
     856                else if ( 'spam' == $comment->comment_approved )
     857                        $comment_status = 'spam';
     858                else
     859                        $comment_status = 'approve';
     860
     861                $link = get_comment_link($comment);
     862
     863                $comment_struct = array(
     864                        "dateCreated"                   => new IXR_Date($comment_date),
     865                        "date_created_gmt"              => new IXR_Date($comment_date_gmt),
     866                        "userid"                                => $comment->user_id,
     867                        "comment_id"                    => $comment->comment_ID,
     868                        "parent"                                => $comment->comment_parent,
     869                        "status"                                => $comment_status,
     870                        "description"                   => $comment->content,
     871                        "link"                                  => $link,
     872                        "post_id"                               => $comment->comment_post_ID,
     873                        "post_title"                    => get_the_title($comment->comment_post_ID),
     874                        "author"                                => $author->comment_author,
     875                        "author_url"                    => $comment->comment_author_url,
     876                        "author_email"                  => $comment->comment_author_email,
     877                        "author_ip"                             => $comment->comment_author_IP,
     878                );
     879
     880                return $comment_struct;
     881        }
     882
     883        function wp_getComments($args) {
     884                $this->escape($args);
     885
     886                $blog_id        = (int) $args[0];
     887                $username       = $args[1];
     888                $password       = $args[2];
     889
     890                if ( !$this->login_pass_ok($username, $password) )
     891                        return($this->error);
     892
     893                set_current_user( 0, $username );
     894                if ( !current_user_can( 'moderate_comment' ) )
     895                        return new IXR_Error( 401, __( 'Sorry, you can not edit comments.' ) );
     896
     897                do_action('xmlrpc_call', 'wp.getComments');
     898
     899                //  TODO: Need to write get_comments()
     900                // $comments = get_comments();
     901                $num_comments = count($comments);
     902
     903                if ( ! $num_comments )
     904                        return array();
     905
     906                $comments_struct = array();
     907
     908                for ( $i = 0; $i < $num_comments; $i++ ) {
     909                        $comment = wp_xmlrpc_server::wp_getComment(array(
     910                                $blog_id, $username, $password, $comments[$i]->comment_ID,
     911                        ));
     912                        $comments_struct[] = $comment;
     913                }
     914
     915                return($comments_struct);
     916        }
     917
     918        function wp_deleteComment($args) {
     919                $this->escape($args);
     920
     921                $blog_id        = (int) $args[0];
     922                $username       = $args[1];
     923                $password       = $args[2];
     924                $comment_ID     = (int) $args[3];
     925
     926                if ( !$this->login_pass_ok( $username, $password ) )
     927                        return $this->error;
     928
     929                set_current_user( 0, $username );
     930                if ( !current_user_can( 'moderate_comments' ) )
     931                        return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
     932
     933                if ( ! get_comment($comment_ID) )
     934                        return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
     935
     936                return wp_delete_comment($comment_ID);
     937        }
     938
     939        function wp_editComment($args) {
     940                $this->escape($args);
     941
     942                $blog_id        = (int) $args[0];
     943                $username       = $args[1];
     944                $password       = $args[2];
     945                $comment_ID     = (int) $args[3];
     946                $content_struct = $args[4];
     947
     948                if ( !$this->login_pass_ok( $username, $password ) )
     949                        return $this->error;
     950
     951                set_current_user( 0, $username );
     952                if ( !current_user_can( 'moderate_comments' ) )
     953                        return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
     954
     955                if ( ! get_comment($comment_ID) )
     956                        return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
     957
     958                if ( isset($content_struct['status']) ) {
     959                        $statuses = get_comment_status();
     960                        $statuses = array_keys($statuses);
     961
     962                        if ( ! in_array($statuses, $status) )
     963                                return new IXR_Error( 401, __( 'Invalid comment status.' ) );
     964                        $comment_approved = $content_struct['status'];
     965                }
     966
     967                // Do some timestamp voodoo
     968                if ( !empty( $content_struct['date_created_gmt'] ) )
     969                        $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force
     970                elseif ( !empty( $content_struct['dateCreated']) )
     971                        $dateCreated = $content_struct['dateCreated']->getIso();
     972
     973                if ( !empty( $dateCreated ) ) {
     974                        $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
     975                        $comment_date_gmt = iso8601_to_datetime($dateCreated, GMT);
     976                }
     977
     978                if ( isset($content_struct['description']) )
     979                        $comment_content = $content_struct['description'];
     980
     981                if ( isset($content_struct['author']) )
     982                        $comment_author = $content_struct['author'];
     983
     984                if ( isset($content_struct['author_url']) )
     985                        $comment_author_url = $content_struct['author_url'];
     986
     987                if ( isset($content_struct['author_email']) )
     988                        $comment_author_email = $content_struct['author_email'];
     989
     990                // We've got all the data -- post it:
     991                $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url');
     992               
     993                $result = wp_update_comment($comment);
     994                if ( is_wp_error( $result ) )
     995                        return new IXR_Error(500, $result->get_error_message());
     996
     997                if ( !$result )
     998                        return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.'));
     999
     1000                return true;
     1001        }
     1002
     1003        function wp_newComment($args) {
     1004                $this->escape($args);
     1005
     1006                $blog_id        = (int) $args[0];
     1007                $username       = $args[1];
     1008                $password       = $args[2];
     1009                $content_struct = $args[3];
     1010
     1011                if ( !$this->login_pass_ok( $username, $password ) )
     1012                        return $this->error;
     1013
     1014                set_current_user( 0, $username );
     1015                if ( !current_user_can( 'moderate_comments' ) )
     1016                        return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
     1017
     1018                return wp_new_comment($content_struct);
     1019        }
     1020
     1021        function wp_getCommentStatusList($args) {
     1022                $this->escape( $args );
     1023
     1024                $blog_id        = (int) $args[0];
     1025                $username       = $args[1];
     1026                $password       = $args[2];
     1027
     1028                if ( !$this->login_pass_ok( $username, $password ) )
     1029                        return $this->error;
     1030
     1031                set_current_user( 0, $username );
     1032                if ( !current_user_can( 'moderate_comments' ) )
     1033                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
     1034
     1035                do_action('xmlrpc_call', 'wp.getCommentStatusList');
     1036
     1037                return get_comment_statuses( );
     1038        }
     1039
    8321040        function wp_getCommentCount( $args ) {
    8331041                $this->escape($args);
    8341042
     
    8571065                );
    8581066        }
    8591067
    860 
    8611068        function wp_getPostStatusList( $args ) {
    8621069                $this->escape( $args );
    8631070