Ticket #17169: class-wp-xmlrpc-server.diff
File class-wp-xmlrpc-server.diff, 24.5 KB (added by , 13 years ago) |
---|
-
wp-includes/class-wp-xmlrpc-server.php
470 470 $page = get_page($page_id); 471 471 472 472 // If we found the page then format the data. 473 if ( $page->ID && ($page->post_type == "page") ) {473 if ( $page->ID && ($page->post_type == 'page') ) { 474 474 // Get all of the page content and link. 475 475 $full_page = get_extended($page->post_content); 476 476 $link = post_permalink($page->ID); … … 487 487 $allow_pings = pings_open($page->ID) ? 1 : 0; 488 488 489 489 // Format page date. 490 $page_date = mysql2date( "Ymd\TH:i:s", $page->post_date, false);491 $page_date_gmt = mysql2date( "Ymd\TH:i:s", $page->post_date_gmt, false);490 $page_date = mysql2date('Ymd\TH:i:s', $page->post_date, false); 491 $page_date_gmt = mysql2date('Ymd\TH:i:s', $page->post_date_gmt, false); 492 492 493 493 // For drafts use the GMT version of the date 494 494 if ( $page->post_status == 'draft' ) … … 508 508 $page_template = 'default'; 509 509 510 510 $page_struct = array( 511 "dateCreated"=> new IXR_Date($page_date),512 "userid"=> $page->post_author,513 "page_id"=> $page->ID,514 "page_status"=> $page->post_status,515 "description" => $full_page["main"],516 "title"=> $page->post_title,517 "link"=> $link,518 "permaLink"=> $link,519 "categories"=> $categories,520 "excerpt"=> $page->post_excerpt,521 "text_more" => $full_page["extended"],522 "mt_allow_comments"=> $allow_comments,523 "mt_allow_pings"=> $allow_pings,524 "wp_slug"=> $page->post_name,525 "wp_password"=> $page->post_password,526 "wp_author"=> $author->display_name,527 "wp_page_parent_id"=> $page->post_parent,528 "wp_page_parent_title"=> $parent_title,529 "wp_page_order"=> $page->menu_order,530 "wp_author_id"=> $author->ID,531 "wp_author_display_name"=> $author->display_name,532 "date_created_gmt"=> new IXR_Date($page_date_gmt),533 "custom_fields"=> $this->get_custom_fields($page_id),534 "wp_page_template"=> $page_template511 'dateCreated' => new IXR_Date($page_date), 512 'userid' => $page->post_author, 513 'page_id' => $page->ID, 514 'page_status' => $page->post_status, 515 'description' => $full_page['main'], 516 'title' => $page->post_title, 517 'link' => $link, 518 'permaLink' => $link, 519 'categories' => $categories, 520 'excerpt' => $page->post_excerpt, 521 'text_more' => $full_page['extended'], 522 'mt_allow_comments' => $allow_comments, 523 'mt_allow_pings' => $allow_pings, 524 'wp_slug' => $page->post_name, 525 'wp_password' => $page->post_password, 526 'wp_author' => $author->display_name, 527 'wp_page_parent_id' => $page->post_parent, 528 'wp_page_parent_title' => $parent_title, 529 'wp_page_order' => $page->menu_order, 530 'wp_author_id' => $author->ID, 531 'wp_author_display_name' => $author->display_name, 532 'date_created_gmt' => new IXR_Date($page_date_gmt), 533 'custom_fields' => $this->get_custom_fields($page_id), 534 'wp_page_template' => $page_template 535 535 ); 536 536 537 537 return($page_struct); 538 538 } 539 539 // If the page doesn't exist indicate that. 540 540 else { 541 return(new IXR_Error(404, __( "Sorry, no such page.")));541 return(new IXR_Error(404, __('Sorry, no such page.'))); 542 542 } 543 543 } 544 544 … … 613 613 do_action('xmlrpc_call', 'wp.newPage'); 614 614 615 615 // Make sure the user is allowed to add new pages. 616 if ( !current_user_can( "publish_pages") )617 return(new IXR_Error(401, __( "Sorry, you cannot add new pages.")));616 if ( !current_user_can('publish_pages') ) 617 return(new IXR_Error(401, __('Sorry, you cannot add new pages.'))); 618 618 619 619 // Mark this as content for a page. 620 $args[3]["post_type"] = "page";620 $args[3]["post_type"] = 'page'; 621 621 622 622 // Let mw_newPost do all of the heavy lifting. 623 623 return($this->mw_newPost($args)); … … 647 647 // Get the current page based on the page_id and 648 648 // make sure it is a page and not a post. 649 649 $actual_page = wp_get_single_post($page_id, ARRAY_A); 650 if ( !$actual_page || ($actual_page[ "post_type"] != "page") )651 return(new IXR_Error(404, __( "Sorry, no such page.")));650 if ( !$actual_page || ($actual_page['post_type'] != 'page') ) 651 return(new IXR_Error(404, __('Sorry, no such page.'))); 652 652 653 653 // Make sure the user can delete pages. 654 if ( !current_user_can( "delete_page", $page_id) )655 return(new IXR_Error(401, __( "Sorry, you do not have the right to delete this page.")));654 if ( !current_user_can('delete_page', $page_id) ) 655 return(new IXR_Error(401, __('Sorry, you do not have the right to delete this page.'))); 656 656 657 657 // Attempt to delete the page. 658 658 $result = wp_delete_post($page_id); 659 659 if ( !$result ) 660 return(new IXR_Error(500, __( "Failed to delete the page.")));660 return(new IXR_Error(500, __('Failed to delete the page.'))); 661 661 662 662 return(true); 663 663 } … … 686 686 687 687 // Get the page data and make sure it is a page. 688 688 $actual_page = wp_get_single_post($page_id, ARRAY_A); 689 if ( !$actual_page || ($actual_page[ "post_type"] != "page") )690 return(new IXR_Error(404, __( "Sorry, no such page.")));689 if ( !$actual_page || ($actual_page['post_type'] != 'page') ) 690 return(new IXR_Error(404, __('Sorry, no such page.'))); 691 691 692 692 // Make sure the user is allowed to edit pages. 693 if ( !current_user_can( "edit_page", $page_id) )694 return(new IXR_Error(401, __( "Sorry, you do not have the right to edit this page.")));693 if ( !current_user_can('edit_page', $page_id) ) 694 return(new IXR_Error(401, __('Sorry, you do not have the right to edit this page.'))); 695 695 696 696 // Mark this as content for a page. 697 $content[ "post_type"] = "page";697 $content['post_type'] = 'page'; 698 698 699 699 // Arrange args in the way mw_editPost understands. 700 700 $args = array( … … 750 750 // The date needs to be formated properly. 751 751 $num_pages = count($page_list); 752 752 for ( $i = 0; $i < $num_pages; $i++ ) { 753 $post_date = mysql2date( "Ymd\TH:i:s", $page_list[$i]->post_date, false);754 $post_date_gmt = mysql2date( "Ymd\TH:i:s", $page_list[$i]->post_date_gmt, false);753 $post_date = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date, false); 754 $post_date_gmt = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date_gmt, false); 755 755 756 756 $page_list[$i]->dateCreated = new IXR_Date($post_date); 757 757 $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt); … … 789 789 if ( !$user = $this->login($username, $password) ) 790 790 return $this->error; 791 791 792 if ( !current_user_can( "edit_posts") )793 return(new IXR_Error(401, __( "Sorry, you cannot edit posts on this site.")));792 if ( !current_user_can('edit_posts') ) 793 return(new IXR_Error(401, __('Sorry, you cannot edit posts on this site.'))); 794 794 795 795 do_action('xmlrpc_call', 'wp.getAuthors'); 796 796 797 797 $authors = array(); 798 798 foreach ( get_users( array( 'fields' => array('ID','user_login','display_name') ) ) as $user ) { 799 799 $authors[] = array( 800 "user_id"=> $user->ID,801 "user_login"=> $user->user_login,802 "display_name"=> $user->display_name800 'user_id' => $user->ID, 801 'user_login' => $user->user_login, 802 'display_name' => $user->display_name 803 803 ); 804 804 } 805 805 … … 869 869 do_action('xmlrpc_call', 'wp.newCategory'); 870 870 871 871 // Make sure the user is allowed to add a category. 872 if ( !current_user_can( "manage_categories") )873 return(new IXR_Error(401, __( "Sorry, you do not have the right to add a category.")));872 if ( !current_user_can('manage_categories') ) 873 return(new IXR_Error(401, __('Sorry, you do not have the right to add a category.'))); 874 874 875 875 // If no slug was provided make it empty so that 876 876 // WordPress will generate one. 877 if ( empty($category[ "slug"]) )878 $category[ "slug"] = "";877 if ( empty($category['slug']) ) 878 $category['slug'] = ''; 879 879 880 880 // If no parent_id was provided make it empty 881 881 // so that it will be a top level page (no parent). 882 if ( !isset($category[ "parent_id"]) )883 $category[ "parent_id"] = "";882 if ( !isset($category['parent_id']) ) 883 $category['parent_id'] = ''; 884 884 885 885 // If no description was provided make it empty. 886 886 if ( empty($category["description"]) ) 887 887 $category["description"] = ""; 888 888 889 889 $new_category = array( 890 "cat_name" => $category["name"],891 "category_nicename" => $category["slug"],892 "category_parent" => $category["parent_id"],893 "category_description" => $category["description"]890 'cat_name' => $category['name'], 891 'category_nicename' => $category['slug'], 892 'category_parent' => $category['parent_id'], 893 'category_description' => $category['description'] 894 894 ); 895 895 896 896 $cat_id = wp_insert_category($new_category, true); … … 898 898 if ( 'term_exists' == $cat_id->get_error_code() ) 899 899 return (int) $cat_id->get_error_data(); 900 900 else 901 return(new IXR_Error(500, __( "Sorry, the new category failed.")));901 return(new IXR_Error(500, __('Sorry, the new category failed.'))); 902 902 } elseif ( ! $cat_id ) { 903 return(new IXR_Error(500, __( "Sorry, the new category failed.")));903 return(new IXR_Error(500, __('Sorry, the new category failed.'))); 904 904 } 905 905 906 906 return($cat_id); … … 927 927 928 928 do_action('xmlrpc_call', 'wp.deleteCategory'); 929 929 930 if ( !current_user_can( "manage_categories") )931 return new IXR_Error( 401, __( "Sorry, you do not have the right to delete a category.") );930 if ( !current_user_can('manage_categories') ) 931 return new IXR_Error( 401, __( 'Sorry, you do not have the right to delete a category.' ) ); 932 932 933 933 return wp_delete_term( $category_id, 'category' ); 934 934 } … … 962 962 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category); 963 963 foreach ( (array) get_categories($args) as $cat ) { 964 964 $category_suggestions[] = array( 965 "category_id"=> $cat->term_id,966 "category_name"=> $cat->name965 'category_id' => $cat->term_id, 966 'category_name' => $cat->name 967 967 ); 968 968 } 969 969 … … 998 998 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); 999 999 1000 1000 // Format page date. 1001 $comment_date = mysql2date( "Ymd\TH:i:s", $comment->comment_date, false);1002 $comment_date_gmt = mysql2date( "Ymd\TH:i:s", $comment->comment_date_gmt, false);1001 $comment_date = mysql2date('Ymd\TH:i:s', $comment->comment_date, false); 1002 $comment_date_gmt = mysql2date('Ymd\TH:i:s', $comment->comment_date_gmt, false); 1003 1003 1004 1004 if ( '0' == $comment->comment_approved ) 1005 1005 $comment_status = 'hold'; … … 1013 1013 $link = get_comment_link($comment); 1014 1014 1015 1015 $comment_struct = array( 1016 "date_created_gmt"=> new IXR_Date($comment_date_gmt),1017 "user_id"=> $comment->user_id,1018 "comment_id"=> $comment->comment_ID,1019 "parent"=> $comment->comment_parent,1020 "status"=> $comment_status,1021 "content"=> $comment->comment_content,1022 "link"=> $link,1023 "post_id"=> $comment->comment_post_ID,1024 "post_title"=> get_the_title($comment->comment_post_ID),1025 "author"=> $comment->comment_author,1026 "author_url"=> $comment->comment_author_url,1027 "author_email"=> $comment->comment_author_email,1028 "author_ip"=> $comment->comment_author_IP,1029 "type"=> $comment->comment_type,1016 'date_created_gmt' => new IXR_Date($comment_date_gmt), 1017 'user_id' => $comment->user_id, 1018 'comment_id' => $comment->comment_ID, 1019 'parent' => $comment->comment_parent, 1020 'status' => $comment_status, 1021 'content' => $comment->comment_content, 1022 'link' => $link, 1023 'post_id' => $comment->comment_post_ID, 1024 'post_title' => get_the_title($comment->comment_post_ID), 1025 'author' => $comment->comment_author, 1026 'author_url' => $comment->comment_author_url, 1027 'author_email' => $comment->comment_author_email, 1028 'author_ip' => $comment->comment_author_IP, 1029 'type' => $comment->comment_type, 1030 1030 ); 1031 1031 1032 1032 return $comment_struct; … … 1368 1368 1369 1369 $count = wp_count_comments( $post_id ); 1370 1370 return array( 1371 "approved"=> $count->approved,1372 "awaiting_moderation"=> $count->moderated,1373 "spam"=> $count->spam,1374 "total_comments"=> $count->total_comments1371 'approved' => $count->approved, 1372 'awaiting_moderation' => $count->moderated, 1373 'spam' => $count->spam, 1374 'total_comments' => $count->total_comments 1375 1375 ); 1376 1376 } 1377 1377 … … 1581 1581 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 1582 1582 1583 1583 // Format page date. 1584 $attachment_date = mysql2date( "Ymd\TH:i:s", $attachment->post_date, false);1585 $attachment_date_gmt = mysql2date( "Ymd\TH:i:s", $attachment->post_date_gmt, false);1584 $attachment_date = mysql2date('Ymd\TH:i:s', $attachment->post_date, false); 1585 $attachment_date_gmt = mysql2date('Ymd\TH:i:s', $attachment->post_date_gmt, false); 1586 1586 1587 1587 $link = wp_get_attachment_url($attachment->ID); 1588 1588 $thumbnail_link = wp_get_attachment_thumb_url($attachment->ID); 1589 1589 1590 1590 $attachment_struct = array( 1591 "date_created_gmt"=> new IXR_Date($attachment_date_gmt),1592 "parent"=> $attachment->post_parent,1593 "link"=> $link,1594 "thumbnail"=> $thumbnail_link,1595 "title"=> $attachment->post_title,1596 "caption"=> $attachment->post_excerpt,1597 "description"=> $attachment->post_content,1598 "metadata"=> wp_get_attachment_metadata($attachment->ID),1591 'date_created_gmt' => new IXR_Date($attachment_date_gmt), 1592 'parent' => $attachment->post_parent, 1593 'link' => $link, 1594 'thumbnail' => $thumbnail_link, 1595 'title' => $attachment->post_title, 1596 'caption' => $attachment->post_excerpt, 1597 'description' => $attachment->post_content, 1598 'metadata' => wp_get_attachment_metadata($attachment->ID), 1599 1599 ); 1600 1600 1601 1601 return $attachment_struct; … … 2238 2238 // Let WordPress generate the post_name (slug) unless 2239 2239 // one has been provided. 2240 2240 $post_name = ""; 2241 if ( isset($content_struct[ "wp_slug"]) )2242 $post_name = $content_struct[ "wp_slug"];2241 if ( isset($content_struct['wp_slug']) ) 2242 $post_name = $content_struct['wp_slug']; 2243 2243 2244 2244 // Only use a password if one was given. 2245 if ( isset($content_struct[ "wp_password"]) )2246 $post_password = $content_struct[ "wp_password"];2245 if ( isset($content_struct['wp_password']) ) 2246 $post_password = $content_struct['wp_password']; 2247 2247 2248 2248 // Only set a post parent if one was provided. 2249 if ( isset($content_struct[ "wp_page_parent_id"]) )2250 $post_parent = $content_struct[ "wp_page_parent_id"];2249 if ( isset($content_struct['wp_page_parent_id']) ) 2250 $post_parent = $content_struct['wp_page_parent_id']; 2251 2251 2252 2252 // Only set the menu_order if it was provided. 2253 if ( isset($content_struct[ "wp_page_order"]) )2254 $menu_order = $content_struct[ "wp_page_order"];2253 if ( isset($content_struct['wp_page_order']) ) 2254 $menu_order = $content_struct['wp_page_order']; 2255 2255 2256 2256 $post_author = $user->ID; 2257 2257 2258 2258 // If an author id was provided then use it instead. 2259 if ( isset($content_struct[ "wp_author_id"]) && ($user->ID != $content_struct["wp_author_id"]) ) {2259 if ( isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id']) ) { 2260 2260 switch ( $post_type ) { 2261 2261 case "post": 2262 if ( !current_user_can( "edit_others_posts") )2263 return(new IXR_Error(401, __( "You are not allowed to post as this user")));2262 if ( !current_user_can('edit_others_posts') ) 2263 return(new IXR_Error(401, __('You are not allowed to post as this user'))); 2264 2264 break; 2265 2265 case "page": 2266 if ( !current_user_can( "edit_others_pages") )2267 return(new IXR_Error(401, __( "You are not allowed to create pages as this user")));2266 if ( !current_user_can('edit_others_pages') ) 2267 return(new IXR_Error(401, __('You are not allowed to create pages as this user'))); 2268 2268 break; 2269 2269 default: 2270 return(new IXR_Error(401, __( "Invalid post type.")));2270 return(new IXR_Error(401, __('Invalid post type.'))); 2271 2271 break; 2272 2272 } 2273 $post_author = $content_struct[ "wp_author_id"];2273 $post_author = $content_struct['wp_author_id']; 2274 2274 } 2275 2275 2276 2276 $post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null; … … 2297 2297 2298 2298 $tags_input = isset($content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null; 2299 2299 2300 if ( isset($content_struct[ "mt_allow_comments"]) ) {2301 if ( !is_numeric($content_struct[ "mt_allow_comments"]) ) {2302 switch ( $content_struct[ "mt_allow_comments"] ) {2303 case "closed":2304 $comment_status = "closed";2300 if ( isset($content_struct['mt_allow_comments']) ) { 2301 if ( !is_numeric($content_struct['mt_allow_comments']) ) { 2302 switch ( $content_struct['mt_allow_comments'] ) { 2303 case 'closed': 2304 $comment_status = 'closed'; 2305 2305 break; 2306 case "open":2307 $comment_status = "open";2306 case 'open': 2307 $comment_status = 'open'; 2308 2308 break; 2309 2309 default: 2310 $comment_status = get_option( "default_comment_status");2310 $comment_status = get_option('default_comment_status'); 2311 2311 break; 2312 2312 } 2313 2313 } else { 2314 switch ( (int) $content_struct[ "mt_allow_comments"] ) {2314 switch ( (int) $content_struct['mt_allow_comments'] ) { 2315 2315 case 0: 2316 2316 case 2: 2317 $comment_status = "closed";2317 $comment_status = 'closed'; 2318 2318 break; 2319 2319 case 1: 2320 $comment_status = "open";2320 $comment_status = 'open'; 2321 2321 break; 2322 2322 default: 2323 $comment_status = get_option( "default_comment_status");2323 $comment_status = get_option('default_comment_status'); 2324 2324 break; 2325 2325 } 2326 2326 } 2327 2327 } else { 2328 $comment_status = get_option( "default_comment_status");2328 $comment_status = get_option('default_comment_status'); 2329 2329 } 2330 2330 2331 if ( isset($content_struct[ "mt_allow_pings"]) ) {2332 if ( !is_numeric($content_struct[ "mt_allow_pings"]) ) {2331 if ( isset($content_struct['mt_allow_pings']) ) { 2332 if ( !is_numeric($content_struct['mt_allow_pings']) ) { 2333 2333 switch ( $content_struct['mt_allow_pings'] ) { 2334 case "closed":2335 $ping_status = "closed";2334 case 'closed': 2335 $ping_status = 'closed'; 2336 2336 break; 2337 case "open":2338 $ping_status = "open";2337 case 'open': 2338 $ping_status = 'open'; 2339 2339 break; 2340 2340 default: 2341 $ping_status = get_option( "default_ping_status");2341 $ping_status = get_option('default_ping_status'); 2342 2342 break; 2343 2343 } 2344 2344 } else { 2345 switch ( (int) $content_struct[ "mt_allow_pings"] ) {2345 switch ( (int) $content_struct['mt_allow_pings'] ) { 2346 2346 case 0: 2347 $ping_status = "closed";2347 $ping_status = 'closed'; 2348 2348 break; 2349 2349 case 1: 2350 $ping_status = "open";2350 $ping_status = 'open'; 2351 2351 break; 2352 2352 default: 2353 $ping_status = get_option( "default_ping_status");2353 $ping_status = get_option('default_ping_status'); 2354 2354 break; 2355 2355 } 2356 2356 } 2357 2357 } else { 2358 $ping_status = get_option( "default_ping_status");2358 $ping_status = get_option('default_ping_status'); 2359 2359 } 2360 2360 2361 2361 if ( $post_more ) 2362 $post_content = $post_content . "<!--more-->". $post_more;2362 $post_content = $post_content . '<!--more-->' . $post_more; 2363 2363 2364 2364 $to_ping = null; 2365 2365 if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { … … 2546 2546 // now and return an error. Other wise a new post will be 2547 2547 // created (which was the old behavior). 2548 2548 if ( empty($postdata["ID"]) ) 2549 return(new IXR_Error(404, __( "Invalid post ID.")));2549 return(new IXR_Error(404, __('Invalid post ID.'))); 2550 2550 2551 2551 $this->escape($postdata); 2552 2552 extract($postdata, EXTR_SKIP); … … 2554 2554 // Let WordPress manage slug if none was provided. 2555 2555 $post_name = ""; 2556 2556 $post_name = $postdata['post_name']; 2557 if ( isset($content_struct[ "wp_slug"]) )2558 $post_name = $content_struct[ "wp_slug"];2557 if ( isset($content_struct['wp_slug']) ) 2558 $post_name = $content_struct['wp_slug']; 2559 2559 2560 2560 // Only use a password if one was given. 2561 if ( isset($content_struct[ "wp_password"]) )2562 $post_password = $content_struct[ "wp_password"];2561 if ( isset($content_struct['wp_password']) ) 2562 $post_password = $content_struct['wp_password']; 2563 2563 2564 2564 // Only set a post parent if one was given. 2565 if ( isset($content_struct[ "wp_page_parent_id"]) )2566 $post_parent = $content_struct[ "wp_page_parent_id"];2565 if ( isset($content_struct['wp_page_parent_id']) ) 2566 $post_parent = $content_struct['wp_page_parent_id']; 2567 2567 2568 2568 // Only set the menu_order if it was given. 2569 if ( isset($content_struct[ "wp_page_order"]) )2570 $menu_order = $content_struct[ "wp_page_order"];2569 if ( isset($content_struct['wp_page_order']) ) 2570 $menu_order = $content_struct['wp_page_order']; 2571 2571 2572 $post_author = $postdata[ "post_author"];2572 $post_author = $postdata['post_author']; 2573 2573 2574 2574 // Only set the post_author if one is set. 2575 if ( isset($content_struct[ "wp_author_id"]) && ($user->ID != $content_struct["wp_author_id"]) ) {2575 if ( isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id']) ) { 2576 2576 switch ( $post_type ) { 2577 case "post":2578 if ( !current_user_can( "edit_others_posts") )2579 return(new IXR_Error(401, __( "You are not allowed to change the post author as this user.")));2577 case 'post': 2578 if ( !current_user_can('edit_others_posts') ) 2579 return(new IXR_Error(401, __('You are not allowed to change the post author as this user.'))); 2580 2580 break; 2581 case "page":2582 if ( !current_user_can( "edit_others_pages") )2583 return(new IXR_Error(401, __( "You are not allowed to change the page author as this user.")));2581 case 'page': 2582 if ( !current_user_can('edit_others_pages') ) 2583 return(new IXR_Error(401, __('You are not allowed to change the page author as this user.'))); 2584 2584 break; 2585 2585 default: 2586 return(new IXR_Error(401, __( "Invalid post type.")));2586 return(new IXR_Error(401, __('Invalid post type.'))); 2587 2587 break; 2588 2588 } 2589 $post_author = $content_struct[ "wp_author_id"];2589 $post_author = $content_struct['wp_author_id']; 2590 2590 } 2591 2591 2592 if ( isset($content_struct[ "mt_allow_comments"]) ) {2593 if ( !is_numeric($content_struct[ "mt_allow_comments"]) ) {2594 switch ( $content_struct[ "mt_allow_comments"] ) {2595 case "closed":2596 $comment_status = "closed";2592 if ( isset($content_struct['mt_allow_comments']) ) { 2593 if ( !is_numeric($content_struct['mt_allow_comments']) ) { 2594 switch ( $content_struct['mt_allow_comments'] ) { 2595 case 'closed': 2596 $comment_status = 'closed'; 2597 2597 break; 2598 case "open":2599 $comment_status = "open";2598 case 'open': 2599 $comment_status = 'open'; 2600 2600 break; 2601 2601 default: 2602 $comment_status = get_option( "default_comment_status");2602 $comment_status = get_option('default_comment_status'); 2603 2603 break; 2604 2604 } 2605 2605 } else { 2606 switch ( (int) $content_struct[ "mt_allow_comments"] ) {2606 switch ( (int) $content_struct['mt_allow_comments'] ) { 2607 2607 case 0: 2608 2608 case 2: 2609 $comment_status = "closed";2609 $comment_status = 'closed'; 2610 2610 break; 2611 2611 case 1: 2612 $comment_status = "open";2612 $comment_status = 'open'; 2613 2613 break; 2614 2614 default: 2615 $comment_status = get_option( "default_comment_status");2615 $comment_status = get_option('default_comment_status'); 2616 2616 break; 2617 2617 } 2618 2618 } 2619 2619 } 2620 2620 2621 if ( isset($content_struct[ "mt_allow_pings"]) ) {2622 if ( !is_numeric($content_struct[ "mt_allow_pings"]) ) {2623 switch ( $content_struct[ "mt_allow_pings"] ) {2624 case "closed":2625 $ping_status = "closed";2621 if ( isset($content_struct['mt_allow_pings']) ) { 2622 if ( !is_numeric($content_struct['mt_allow_pings']) ) { 2623 switch ( $content_struct['mt_allow_pings'] ) { 2624 case 'closed': 2625 $ping_status = 'closed'; 2626 2626 break; 2627 case "open":2628 $ping_status = "open";2627 case 'open': 2628 $ping_status = 'open'; 2629 2629 break; 2630 2630 default: 2631 $ping_status = get_option( "default_ping_status");2631 $ping_status = get_option('default_ping_status'); 2632 2632 break; 2633 2633 } 2634 2634 } else { 2635 2635 switch ( (int) $content_struct["mt_allow_pings"] ) { 2636 2636 case 0: 2637 $ping_status = "closed";2637 $ping_status = 'closed'; 2638 2638 break; 2639 2639 case 1: 2640 $ping_status = "open";2640 $ping_status = 'open'; 2641 2641 break; 2642 2642 default: 2643 $ping_status = get_option( "default_ping_status");2643 $ping_status = get_option('default_ping_status'); 2644 2644 break; 2645 2645 } 2646 2646 } … … 3057 3057 return $this->error; 3058 3058 } 3059 3059 3060 if ( $upload_err = apply_filters( "pre_upload_error", false ) )3060 if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) 3061 3061 return new IXR_Error(500, $upload_err); 3062 3062 3063 if ( !empty($data[ "overwrite"]) && ($data["overwrite"] == true) ) {3063 if ( !empty($data['overwrite']) && ($data['overwrite'] == true) ) { 3064 3064 // Get postmeta info on the object. 3065 3065 $old_file = $wpdb->get_row(" 3066 3066 SELECT ID … … 3074 3074 3075 3075 // Make sure the new name is different by pre-pending the 3076 3076 // previous post id. 3077 $filename = preg_replace( "/^wpid\d+-/", "", $name);3077 $filename = preg_replace('/^wpid\d+-/', '', $name); 3078 3078 $name = "wpid{$old_file->ID}-{$filename}"; 3079 3079 } 3080 3080