Ticket #7446: 7446.5.diff
File 7446.5.diff, 13.7 KB (added by , 16 years ago) |
---|
-
wp-includes/comment.php
3 3 * Manages WordPress comments 4 4 * 5 5 * @package WordPress 6 * @subpackage Comment 6 7 */ 7 8 8 9 /** … … 162 163 } 163 164 164 165 /** 165 * Retrieve a n array of comment data about comment $comment_ID.166 * Retrieve a list of comments 166 167 * 167 * get_comment() technically does the same thing as this function. This function 168 * also appears to reference variables and then not use them or not update them 169 * when needed. It is advised to switch to get_comment(), since this function 170 * might be deprecated in favor of using get_comment(). 168 * {@internal Missing Long Description}} 171 169 * 172 * @deprecated Use get_comment() 173 * @see get_comment() 174 * @since 0.71 170 * @package WordPress 171 * @subpackage Comment 172 * @since 1.5 173 * @uses $wpdb 175 174 * 176 * @uses $postc Comment cache, might not be used any more 177 * @uses $id 178 * @uses $wpdb Database Object 179 * 180 * @param int $comment_ID The ID of the comment 181 * @param int $no_cache Whether to use the cache or not (casted to bool) 182 * @param bool $include_unapproved Whether to include unapproved comments or not 183 * @return array The comment data 175 * @param mixed $args Optional. Array or string of options 176 * @return array List of comments matching defaults or $args 184 177 */ 185 function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { 186 global $postc, $wpdb; 187 if ( $no_cache ) { 188 $query = $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID = %d", $comment_ID); 189 if ( false == $include_unapproved ) 190 $query .= " AND comment_approved = '1'"; 191 $myrow = $wpdb->get_row($query, ARRAY_A); 178 function get_comments( $args = '' ) { 179 global $wpdb; 180 181 $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0); 182 183 $r = wp_parse_args( $args, $defaults ); 184 extract( $r, EXTR_SKIP ); 185 186 $post_id = absint($post_id); 187 188 if ( 'hold' == $status ) 189 $approved = "comment_approved = '0'"; 190 elseif ( 'approve' == $status ) 191 $approved = "comment_approved = '1'"; 192 elseif ( 'spam' == $status ) 193 $approved = "comment_approved = 'spam'"; 194 else 195 $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 196 197 if ( 'ASC' != $order ) 198 $order = 'DESC'; 199 200 $orderby = 'comment_date_gmt'; // Hard code for now 201 202 $number = absint($number); 203 $offset = absint($offset); 204 205 if ( !empty($number) ) { 206 if ( $offset ) 207 $number = 'LIMIT ' . $offset . ',' . $number; 208 else 209 $number = 'LIMIT ' . $number; 210 192 211 } else { 193 $myrow['comment_ID'] = $postc->comment_ID; 194 $myrow['comment_post_ID'] = $postc->comment_post_ID; 195 $myrow['comment_author'] = $postc->comment_author; 196 $myrow['comment_author_email'] = $postc->comment_author_email; 197 $myrow['comment_author_url'] = $postc->comment_author_url; 198 $myrow['comment_author_IP'] = $postc->comment_author_IP; 199 $myrow['comment_date'] = $postc->comment_date; 200 $myrow['comment_content'] = $postc->comment_content; 201 $myrow['comment_karma'] = $postc->comment_karma; 202 $myrow['comment_approved'] = $postc->comment_approved; 203 $myrow['comment_type'] = $postc->comment_type; 212 $number = ''; 204 213 } 205 return $myrow; 214 215 if ( ! empty($post_id) ) 216 $post_where = "comment_post_ID = $post_id AND"; 217 else 218 $post_where = ''; 219 220 return $wpdb->get_results( "SELECT * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $post_where $approved ORDER BY $orderby $order $number" ); 206 221 } 207 222 208 223 /** 224 * Retrieve all of the WordPress supported comment statuses. 225 * 226 * Comments have a limited set of valid status values, this provides the 227 * comment status values and descriptions. 228 * 229 * @package WordPress 230 * @subpackage Post 231 * @since 2.7 232 * 233 * @return array List of comment statuses. 234 */ 235 function get_comment_statuses( ) { 236 $status = array( 237 'hold' => __('Unapproved'), 238 'approve' => __('Approved'), 239 'spam' => __('Spam'), 240 ); 241 242 return $status; 243 } 244 245 246 /** 209 247 * The date the last comment was modified. 210 248 * 211 249 * {@internal Missing Long Description}} … … 822 860 823 861 $comment_date_gmt = get_gmt_from_date($comment_date); 824 862 863 if ( empty($comment_approved) ) 864 $comment_approved = 1; 865 else if ( 'hold' == $comment_approved ) 866 $comment_approved = 0; 867 else if ( 'approve' == $comment_approved ) 868 $comment_approved = 1; 869 825 870 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET 826 871 comment_content = %s, 827 872 comment_author = %s, -
wp-includes/comment-template.php
320 320 * @since 1.5 321 321 * @uses $comment 322 322 * 323 * @param object|string|int $comment Comment to retrieve. 323 324 * @return string The permalink to the current comment 324 325 */ 325 function get_comment_link( ) {326 global $comment;326 function get_comment_link($comment = null) { 327 $comment = get_comment($comment); 327 328 return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; 328 329 } 329 330 -
wp-includes/deprecated.php
1283 1283 function gzip_compression() { 1284 1284 return false; 1285 1285 } 1286 1287 /** 1288 * Retrieve an array of comment data about comment $comment_ID. 1289 * 1290 * @deprecated Use get_comment() 1291 * @see get_comment() 1292 * @since 0.71 1293 * 1294 * @uses $id 1295 * @uses $wpdb Database Object 1296 * 1297 * @param int $comment_ID The ID of the comment 1298 * @param int $no_cache Whether to use the cache or not (casted to bool) 1299 * @param bool $include_unapproved Whether to include unapproved comments or not 1300 * @return array The comment data 1301 */ 1302 function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { 1303 _deprecated_function( __FUNCTION__, '2.7', 'get_comment()' ); 1304 return get_comment($comment_ID, ARRAY_A); 1305 } 1306 1286 1307 ?> 1308 No newline at end of file -
xmlrpc.php
129 129 'wp.getPageTemplates' => 'this:wp_getPageTemplates', 130 130 'wp.getOptions' => 'this:wp_getOptions', 131 131 'wp.setOptions' => 'this:wp_setOptions', 132 'wp.getComment' => 'this:wp_getComment', 133 'wp.getComments' => 'this:wp_getComments', 134 'wp.deleteComment' => 'this:wp_deleteComment', 135 'wp.editComment' => 'this:wp_editComment', 136 'wp.newComment' => 'this:wp_newComment', 137 'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', 132 138 133 139 // Blogger API 134 140 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', … … 829 835 return($category_suggestions); 830 836 } 831 837 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 "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 $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 $this->escape($args); 1022 1023 $blog_id = (int) $args[0]; 1024 $username = $args[1]; 1025 $password = $args[2]; 1026 $content_struct = $args[3]; 1027 1028 // TODO Allow unregistered users to comment. Either built-in or provide plugin hooks. 1029 if ( !$this->login_pass_ok( $username, $password ) ) 1030 return $this->error; 1031 1032 set_current_user( 0, $username ); 1033 if ( !current_user_can( 'moderate_comments' ) ) 1034 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); 1035 1036 do_action('xmlrpc_call', 'wp.newComment'); 1037 1038 // TODO translate field names 1039 return wp_new_comment($content_struct); 1040 } 1041 1042 function wp_getCommentStatusList($args) { 1043 $this->escape( $args ); 1044 1045 $blog_id = (int) $args[0]; 1046 $username = $args[1]; 1047 $password = $args[2]; 1048 1049 if ( !$this->login_pass_ok( $username, $password ) ) 1050 return $this->error; 1051 1052 set_current_user( 0, $username ); 1053 if ( !current_user_can( 'moderate_comments' ) ) 1054 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 1055 1056 do_action('xmlrpc_call', 'wp.getCommentStatusList'); 1057 1058 return get_comment_statuses( ); 1059 } 1060 832 1061 function wp_getCommentCount( $args ) { 833 1062 $this->escape($args); 834 1063 … … 857 1086 ); 858 1087 } 859 1088 860 861 1089 function wp_getPostStatusList( $args ) { 862 1090 $this->escape( $args ); 863 1091