| 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 | "user_id" => $comment->user_id, |
| 874 | "comment_id" => $comment->comment_ID, |
| 875 | "parent" => $comment->comment_parent, |
| 876 | "status" => $comment_status, |
| 877 | "content" => $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 | $struct = $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 | if ( isset($struct['status']) ) |
| 908 | $status = $struct['status']; |
| 909 | else |
| 910 | $status = ''; |
| 911 | |
| 912 | if ( isset($struct['post_id']) ) |
| 913 | $post_id = $struct['post_id']; |
| 914 | else |
| 915 | $post_id = ''; |
| 916 | |
| 917 | $comments = get_comments(array('status' => $status, 'post_id' => $post_id)); |
| 918 | $num_comments = count($comments); |
| 919 | |
| 920 | if ( ! $num_comments ) |
| 921 | return array(); |
| 922 | |
| 923 | $comments_struct = array(); |
| 924 | |
| 925 | for ( $i = 0; $i < $num_comments; $i++ ) { |
| 926 | $comment = wp_xmlrpc_server::wp_getComment(array( |
| 927 | $blog_id, $username, $password, $comments[$i]->comment_ID, |
| 928 | )); |
| 929 | $comments_struct[] = $comment; |
| 930 | } |
| 931 | |
| 932 | return $comments_struct; |
| 933 | } |
| 934 | |
| 935 | function wp_deleteComment($args) { |
| 936 | $this->escape($args); |
| 937 | |
| 938 | $blog_id = (int) $args[0]; |
| 939 | $username = $args[1]; |
| 940 | $password = $args[2]; |
| 941 | $comment_ID = (int) $args[3]; |
| 942 | |
| 943 | if ( !$this->login_pass_ok( $username, $password ) ) |
| 944 | return $this->error; |
| 945 | |
| 946 | set_current_user( 0, $username ); |
| 947 | if ( !current_user_can( 'moderate_comments' ) ) |
| 948 | return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); |
| 949 | |
| 950 | do_action('xmlrpc_call', 'wp.deleteComment'); |
| 951 | |
| 952 | if ( ! get_comment($comment_ID) ) |
| 953 | return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
| 954 | |
| 955 | return wp_delete_comment($comment_ID); |
| 956 | } |
| 957 | |
| 958 | function wp_editComment($args) { |
| 959 | $this->escape($args); |
| 960 | |
| 961 | $blog_id = (int) $args[0]; |
| 962 | $username = $args[1]; |
| 963 | $password = $args[2]; |
| 964 | $comment_ID = (int) $args[3]; |
| 965 | $content_struct = $args[4]; |
| 966 | |
| 967 | if ( !$this->login_pass_ok( $username, $password ) ) |
| 968 | return $this->error; |
| 969 | |
| 970 | set_current_user( 0, $username ); |
| 971 | if ( !current_user_can( 'moderate_comments' ) ) |
| 972 | return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); |
| 973 | |
| 974 | do_action('xmlrpc_call', 'wp.editComment'); |
| 975 | |
| 976 | if ( ! get_comment($comment_ID) ) |
| 977 | return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
| 978 | |
| 979 | if ( isset($content_struct['status']) ) { |
| 980 | $statuses = get_comment_statuses(); |
| 981 | $statuses = array_keys($statuses); |
| 982 | |
| 983 | if ( ! in_array($content_struct['status'], $statuses) ) |
| 984 | return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
| 985 | $comment_approved = $content_struct['status']; |
| 986 | } |
| 987 | |
| 988 | // Do some timestamp voodoo |
| 989 | if ( !empty( $content_struct['date_created_gmt'] ) ) { |
| 990 | $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 |
| 991 | $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
| 992 | $comment_date_gmt = iso8601_to_datetime($dateCreated, GMT); |
| 993 | } |
| 994 | |
| 995 | if ( isset($content_struct['description']) ) |
| 996 | $comment_content = $content_struct['description']; |
| 997 | |
| 998 | if ( isset($content_struct['author']) ) |
| 999 | $comment_author = $content_struct['author']; |
| 1000 | |
| 1001 | if ( isset($content_struct['author_url']) ) |
| 1002 | $comment_author_url = $content_struct['author_url']; |
| 1003 | |
| 1004 | if ( isset($content_struct['author_email']) ) |
| 1005 | $comment_author_email = $content_struct['author_email']; |
| 1006 | |
| 1007 | // We've got all the data -- post it: |
| 1008 | $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url'); |
| 1009 | |
| 1010 | $result = wp_update_comment($comment); |
| 1011 | if ( is_wp_error( $result ) ) |
| 1012 | return new IXR_Error(500, $result->get_error_message()); |
| 1013 | |
| 1014 | if ( !$result ) |
| 1015 | return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.')); |
| 1016 | |
| 1017 | return true; |
| 1018 | } |
| 1019 | |
| 1020 | function wp_newComment($args) { |
| 1021 | global $wpdb; |
| 1022 | |
| 1023 | $this->escape($args); |
| 1024 | |
| 1025 | $blog_id = (int) $args[0]; |
| 1026 | $username = $args[1]; |
| 1027 | $password = $args[2]; |
| 1028 | $post_id = absint($args[3]); |
| 1029 | $content_struct = $args[4]; |
| 1030 | |
| 1031 | // TODO Allow unregistered users to comment. Either built-in or provide plugin hooks. |
| 1032 | if ( !$this->login_pass_ok( $username, $password ) ) |
| 1033 | return $this->error; |
| 1034 | |
| 1035 | set_current_user( 0, $username ); |
| 1036 | if ( !current_user_can( 'moderate_comments' ) ) |
| 1037 | return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); |
| 1038 | |
| 1039 | if ( ! get_post($post_id) ) |
| 1040 | return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
| 1041 | |
| 1042 | $comment['comment_post_ID'] = $post_id; |
| 1043 | |
| 1044 | $user = wp_get_current_user(); |
| 1045 | $comment['comment_author'] = $wpdb->escape( $user->display_name ); |
| 1046 | $comment['comment_author_email'] = $wpdb->escape( $user->user_email ); |
| 1047 | $comment['comment_author_url'] = $wpdb->escape( $user->user_url ); |
| 1048 | |
| 1049 | $comment['comment_content'] = $content_struct['content']; |
| 1050 | |
| 1051 | do_action('xmlrpc_call', 'wp.newComment'); |
| 1052 | |
| 1053 | return wp_new_comment($comment); |
| 1054 | } |
| 1055 | |
| 1056 | function wp_getCommentStatusList($args) { |
| 1057 | $this->escape( $args ); |
| 1058 | |
| 1059 | $blog_id = (int) $args[0]; |
| 1060 | $username = $args[1]; |
| 1061 | $password = $args[2]; |
| 1062 | |
| 1063 | if ( !$this->login_pass_ok( $username, $password ) ) |
| 1064 | return $this->error; |
| 1065 | |
| 1066 | set_current_user( 0, $username ); |
| 1067 | if ( !current_user_can( 'moderate_comments' ) ) |
| 1068 | return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); |
| 1069 | |
| 1070 | do_action('xmlrpc_call', 'wp.getCommentStatusList'); |
| 1071 | |
| 1072 | return get_comment_statuses( ); |
| 1073 | } |
| 1074 | |