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