Ticket #7446: 7446.4.diff
File 7446.4.diff, 13.4 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' => ''); 182 183 $r = wp_parse_args( $args, $defaults ); 184 extract( $r, EXTR_SKIP ); 185 186 if ( 'hold' == $status ) 187 $approved = "comment_approved = '0'"; 188 elseif ( 'approve' == $status ) 189 $approved = "comment_approved = '1'"; 190 elseif ( 'spam' == $status ) 191 $approved = "comment_approved = 'spam'"; 192 else 193 $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 194 195 if ( 'ASC' != $order ) 196 $order = 'DESC'; 197 198 $orderby = 'comment_date_gmt'; // Hard code for now 199 200 $number = absint($number); 201 $offset = absint($offset); 202 203 if ( !empty($number) ) { 204 if ( $offset ) 205 $number = 'LIMIT ' . $offset . ',' . $number; 206 else 207 $number = 'LIMIT ' . $number; 208 192 209 } 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; 210 $number = ''; 204 211 } 205 return $myrow; 212 213 return $wpdb->get_results( "SELECT * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $approved ORDER BY $orderby $order $number" ); 206 214 } 207 215 208 216 /** 217 * Retrieve all of the WordPress supported comment statuses. 218 * 219 * Comments have a limited set of valid status values, this provides the 220 * comment status values and descriptions. 221 * 222 * @package WordPress 223 * @subpackage Post 224 * @since 2.7 225 * 226 * @return array List of comment statuses. 227 */ 228 function get_comment_statuses( ) { 229 $status = array( 230 'hold' => __('Unapproved'), 231 'approve' => __('Approved'), 232 'spam' => __('Spam'), 233 ); 234 235 return $status; 236 } 237 238 239 /** 209 240 * The date the last comment was modified. 210 241 * 211 242 * {@internal Missing Long Description}} … … 822 853 823 854 $comment_date_gmt = get_gmt_from_date($comment_date); 824 855 856 if ( empty($comment_approved) ) 857 $comment_approved = 1; 858 else if ( 'hold' == $comment_approved ) 859 $comment_approved = 0; 860 else if ( 'approve' == $comment_approved ) 861 $comment_approved = 1; 862 825 863 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET 826 864 comment_content = %s, 827 865 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 "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 832 1051 function wp_getCommentCount( $args ) { 833 1052 $this->escape($args); 834 1053 … … 857 1076 ); 858 1077 } 859 1078 860 861 1079 function wp_getPostStatusList( $args ) { 862 1080 $this->escape( $args ); 863 1081