| 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 | $post_id = ''; |
| 913 | if ( isset($struct['post_id']) ) |
| 914 | $post_id = absint($struct['post_id']); |
| 915 | |
| 916 | $offset = 0; |
| 917 | if ( isset($struct['offset']) ) |
| 918 | $offset = absint($struct['offset']); |
| 919 | |
| 920 | $number = 10; |
| 921 | if ( isset($struct['number']) ) |
| 922 | $number = absint($struct['number']); |
| 923 | |
| 924 | $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) ); |
| 925 | $num_comments = count($comments); |
| 926 | |
| 927 | if ( ! $num_comments ) |
| 928 | return array(); |
| 929 | |
| 930 | $comments_struct = array(); |
| 931 | |
| 932 | for ( $i = 0; $i < $num_comments; $i++ ) { |
| 933 | $comment = wp_xmlrpc_server::wp_getComment(array( |
| 934 | $blog_id, $username, $password, $comments[$i]->comment_ID, |
| 935 | )); |
| 936 | $comments_struct[] = $comment; |
| 937 | } |
| 938 | |
| 939 | return $comments_struct; |
| 940 | } |
| 941 | |
| 942 | function wp_deleteComment($args) { |
| 943 | $this->escape($args); |
| 944 | |
| 945 | $blog_id = (int) $args[0]; |
| 946 | $username = $args[1]; |
| 947 | $password = $args[2]; |
| 948 | $comment_ID = (int) $args[3]; |
| 949 | |
| 950 | if ( !$this->login_pass_ok( $username, $password ) ) |
| 951 | return $this->error; |
| 952 | |
| 953 | set_current_user( 0, $username ); |
| 954 | if ( !current_user_can( 'moderate_comments' ) ) |
| 955 | return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); |
| 956 | |
| 957 | do_action('xmlrpc_call', 'wp.deleteComment'); |
| 958 | |
| 959 | if ( ! get_comment($comment_ID) ) |
| 960 | return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
| 961 | |
| 962 | return wp_delete_comment($comment_ID); |
| 963 | } |
| 964 | |
| 965 | function wp_editComment($args) { |
| 966 | $this->escape($args); |
| 967 | |
| 968 | $blog_id = (int) $args[0]; |
| 969 | $username = $args[1]; |
| 970 | $password = $args[2]; |
| 971 | $comment_ID = (int) $args[3]; |
| 972 | $content_struct = $args[4]; |
| 973 | |
| 974 | if ( !$this->login_pass_ok( $username, $password ) ) |
| 975 | return $this->error; |
| 976 | |
| 977 | set_current_user( 0, $username ); |
| 978 | if ( !current_user_can( 'moderate_comments' ) ) |
| 979 | return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); |
| 980 | |
| 981 | do_action('xmlrpc_call', 'wp.editComment'); |
| 982 | |
| 983 | if ( ! get_comment($comment_ID) ) |
| 984 | return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
| 985 | |
| 986 | if ( isset($content_struct['status']) ) { |
| 987 | $statuses = get_comment_statuses(); |
| 988 | $statuses = array_keys($statuses); |
| 989 | |
| 990 | if ( ! in_array($content_struct['status'], $statuses) ) |
| 991 | return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
| 992 | $comment_approved = $content_struct['status']; |
| 993 | } |
| 994 | |
| 995 | // Do some timestamp voodoo |
| 996 | if ( !empty( $content_struct['date_created_gmt'] ) ) { |
| 997 | $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 |
| 998 | $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
| 999 | $comment_date_gmt = iso8601_to_datetime($dateCreated, GMT); |
| 1000 | } |
| 1001 | |
| 1002 | if ( isset($content_struct['description']) ) |
| 1003 | $comment_content = $content_struct['description']; |
| 1004 | |
| 1005 | if ( isset($content_struct['author']) ) |
| 1006 | $comment_author = $content_struct['author']; |
| 1007 | |
| 1008 | if ( isset($content_struct['author_url']) ) |
| 1009 | $comment_author_url = $content_struct['author_url']; |
| 1010 | |
| 1011 | if ( isset($content_struct['author_email']) ) |
| 1012 | $comment_author_email = $content_struct['author_email']; |
| 1013 | |
| 1014 | // We've got all the data -- post it: |
| 1015 | $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url'); |
| 1016 | |
| 1017 | $result = wp_update_comment($comment); |
| 1018 | if ( is_wp_error( $result ) ) |
| 1019 | return new IXR_Error(500, $result->get_error_message()); |
| 1020 | |
| 1021 | if ( !$result ) |
| 1022 | return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.')); |
| 1023 | |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
| 1027 | function wp_newComment($args) { |
| 1028 | global $wpdb; |
| 1029 | |
| 1030 | $this->escape($args); |
| 1031 | |
| 1032 | $blog_id = (int) $args[0]; |
| 1033 | $username = $args[1]; |
| 1034 | $password = $args[2]; |
| 1035 | $post = $args[3]; |
| 1036 | $content_struct = $args[4]; |
| 1037 | |
| 1038 | $allow_anon = apply_filters('xmlrpc_allow_anonymous_comments', false); |
| 1039 | |
| 1040 | if ( !$this->login_pass_ok( $username, $password ) ) { |
| 1041 | $logged_in = false; |
| 1042 | if ( $allow_anon && get_option('comment_registration') ) |
| 1043 | return new IXR_Error( 403, __( 'You must be registered to comment' ) ); |
| 1044 | else if ( !$allow_anon ) |
| 1045 | return $this->error; |
| 1046 | } else { |
| 1047 | $logged_in = true; |
| 1048 | set_current_user( 0, $username ); |
| 1049 | if ( !current_user_can( 'moderate_comments' ) ) |
| 1050 | return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); |
| 1051 | } |
| 1052 | |
| 1053 | if ( is_numeric($post) ) |
| 1054 | $post_id = absint($post); |
| 1055 | else |
| 1056 | $post_id = url_to_postid($post); |
| 1057 | |
| 1058 | if ( ! $post_id ) |
| 1059 | return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
| 1060 | |
| 1061 | if ( ! get_post($post_id) ) |
| 1062 | return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
| 1063 | |
| 1064 | $comment['comment_post_ID'] = $post_id; |
| 1065 | |
| 1066 | if ( $logged_in ) { |
| 1067 | $user = wp_get_current_user(); |
| 1068 | $comment['comment_author'] = $wpdb->escape( $user->display_name ); |
| 1069 | $comment['comment_author_email'] = $wpdb->escape( $user->user_email ); |
| 1070 | $comment['comment_author_url'] = $wpdb->escape( $user->user_url ); |
| 1071 | $comment['user_ID'] = $user->ID; |
| 1072 | } else { |
| 1073 | $comment['comment_author'] = ''; |
| 1074 | if ( isset($content_struct['author']) ) |
| 1075 | $comment['comment_author'] = $content_struct['author']; |
| 1076 | $comment['comment_author_email'] = ''; |
| 1077 | if ( isset($content_struct['author']) ) |
| 1078 | $comment['comment_author_email'] = $content_struct['author_email']; |
| 1079 | $comment['comment_author_url'] = ''; |
| 1080 | if ( isset($content_struct['author']) ) |
| 1081 | $comment['comment_author_url'] = $content_struct['author_url']; |
| 1082 | $comment['user_ID'] = 0; |
| 1083 | |
| 1084 | if ( get_option('require_name_email') ) { |
| 1085 | if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] ) |
| 1086 | return new IXR_Error( 403, __( 'Comment author name and email are required' ) ); |
| 1087 | elseif ( !is_email($comment['comment_author_email']) ) |
| 1088 | return new IXR_Error( 403, __( 'A valid email address is required' ) ); |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | $comment['comment_content'] = $content_struct['content']; |
| 1093 | |
| 1094 | do_action('xmlrpc_call', 'wp.newComment'); |
| 1095 | |
| 1096 | return wp_new_comment($comment); |
| 1097 | } |
| 1098 | |
| 1099 | function wp_getCommentStatusList($args) { |
| 1100 | $this->escape( $args ); |
| 1101 | |
| 1102 | $blog_id = (int) $args[0]; |
| 1103 | $username = $args[1]; |
| 1104 | $password = $args[2]; |
| 1105 | |
| 1106 | if ( !$this->login_pass_ok( $username, $password ) ) |
| 1107 | return $this->error; |
| 1108 | |
| 1109 | set_current_user( 0, $username ); |
| 1110 | if ( !current_user_can( 'moderate_comments' ) ) |
| 1111 | return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); |
| 1112 | |
| 1113 | do_action('xmlrpc_call', 'wp.getCommentStatusList'); |
| 1114 | |
| 1115 | return get_comment_statuses( ); |
| 1116 | } |
| 1117 | |