| 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 | |