Changeset 12735 for trunk/xmlrpc.php
- Timestamp:
- 01/15/2010 11:40:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/xmlrpc.php
r12672 r12735 295 295 global $wpdb; 296 296 297 if (!is_array($array)) {297 if (!is_array($array)) { 298 298 return($wpdb->escape($array)); 299 } 300 else { 299 } else { 301 300 foreach ( (array) $array as $k => $v ) { 302 if ( is_array($v)) {301 if ( is_array($v) ) { 303 302 $this->escape($array[$k]); 304 } else if ( is_object($v)) {303 } else if ( is_object($v) ) { 305 304 //skip 306 305 } else { … … 444 443 function wp_getUsersBlogs( $args ) { 445 444 // If this isn't on WPMU then just use blogger_getUsersBlogs 446 if ( !is_multisite() ) {445 if ( !is_multisite() ) { 447 446 array_unshift( $args, 1 ); 448 447 return $this->blogger_getUsersBlogs( $args ); … … 463 462 $struct = array( ); 464 463 465 foreach ( $blogs as $blog ) {464 foreach ( $blogs as $blog ) { 466 465 // Don't include blogs that aren't hosted at this site 467 if ( $blog->site_id != $current_site->id )466 if ( $blog->site_id != $current_site->id ) 468 467 continue; 469 468 … … 506 505 } 507 506 508 if ( !current_user_can( 'edit_page', $page_id ) )507 if ( !current_user_can( 'edit_page', $page_id ) ) 509 508 return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) ); 510 509 … … 515 514 516 515 // If we found the page then format the data. 517 if ($page->ID && ($page->post_type == "page")) {516 if ( $page->ID && ($page->post_type == "page") ) { 518 517 // Get all of the page content and link. 519 518 $full_page = get_extended($page->post_content); … … 522 521 // Get info the page parent if there is one. 523 522 $parent_title = ""; 524 if (!empty($page->post_parent)) {523 if ( !empty($page->post_parent) ) { 525 524 $parent = get_page($page->post_parent); 526 525 $parent_title = $parent->post_title; … … 536 535 537 536 // For drafts use the GMT version of the date 538 if ( $page->post_status == 'draft' ) {537 if ( $page->post_status == 'draft' ) 539 538 $page_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page->post_date ), 'Ymd\TH:i:s' ); 540 }541 539 542 540 // Pull the categories info together. 543 541 $categories = array(); 544 foreach (wp_get_post_categories($page->ID) as $cat_id) {542 foreach ( wp_get_post_categories($page->ID) as $cat_id ) { 545 543 $categories[] = get_cat_name($cat_id); 546 544 } … … 550 548 551 549 $page_template = get_post_meta( $page->ID, '_wp_page_template', true ); 552 if ( empty( $page_template ) )550 if ( empty( $page_template ) ) 553 551 $page_template = 'default'; 554 552 … … 604 602 $num_pages = isset($args[3]) ? (int) $args[3] : 10; 605 603 606 if ( !$user = $this->login($username, $password) ) { 607 return $this->error; 608 } 609 610 if( !current_user_can( 'edit_pages' ) ) 604 if ( !$user = $this->login($username, $password) ) 605 return $this->error; 606 607 if ( !current_user_can( 'edit_pages' ) ) 611 608 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); 612 609 … … 617 614 618 615 // If we have pages, put together their info. 619 if ($num_pages >= 1) {616 if ( $num_pages >= 1 ) { 620 617 $pages_struct = array(); 621 618 622 for ($i = 0; $i < $num_pages; $i++) {619 for ( $i = 0; $i < $num_pages; $i++ ) { 623 620 $page = wp_xmlrpc_server::wp_getPage(array( 624 621 $blog_id, $pages[$i]->ID, $username, $password … … 650 647 $publish = $args[4]; 651 648 652 if ( !$user = $this->login($username, $password) ) { 653 return $this->error; 654 } 649 if ( !$user = $this->login($username, $password) ) 650 return $this->error; 655 651 656 652 do_action('xmlrpc_call', 'wp.newPage'); 657 653 658 654 // Make sure the user is allowed to add new pages. 659 if (!current_user_can("publish_pages")) {655 if ( !current_user_can("publish_pages") ) 660 656 return(new IXR_Error(401, __("Sorry, you cannot add new pages."))); 661 }662 657 663 658 // Mark this as content for a page. … … 684 679 $page_id = (int) $args[3]; 685 680 686 if ( !$user = $this->login($username, $password) ) { 687 return $this->error; 688 } 681 if ( !$user = $this->login($username, $password) ) 682 return $this->error; 689 683 690 684 do_action('xmlrpc_call', 'wp.deletePage'); … … 693 687 // make sure it is a page and not a post. 694 688 $actual_page = wp_get_single_post($page_id, ARRAY_A); 695 if( 696 !$actual_page 697 || ($actual_page["post_type"] != "page") 698 ) { 689 if ( !$actual_page || ($actual_page["post_type"] != "page") ) 699 690 return(new IXR_Error(404, __("Sorry, no such page."))); 700 }701 691 702 692 // Make sure the user can delete pages. 703 if (!current_user_can("delete_page", $page_id)) {693 if ( !current_user_can("delete_page", $page_id) ) 704 694 return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page."))); 705 }706 695 707 696 // Attempt to delete the page. 708 697 $result = wp_delete_post($page_id); 709 if (!$result) {698 if ( !$result ) 710 699 return(new IXR_Error(500, __("Failed to delete the page."))); 711 }712 700 713 701 return(true); … … 731 719 $publish = $args[5]; 732 720 733 if ( !$user = $this->login($username, $password) ) { 734 return $this->error; 735 } 721 if ( !$user = $this->login($username, $password) ) 722 return $this->error; 736 723 737 724 do_action('xmlrpc_call', 'wp.editPage'); … … 739 726 // Get the page data and make sure it is a page. 740 727 $actual_page = wp_get_single_post($page_id, ARRAY_A); 741 if( 742 !$actual_page 743 || ($actual_page["post_type"] != "page") 744 ) { 728 if ( !$actual_page || ($actual_page["post_type"] != "page") ) 745 729 return(new IXR_Error(404, __("Sorry, no such page."))); 746 }747 730 748 731 // Make sure the user is allowed to edit pages. 749 if (!current_user_can("edit_page", $page_id)) {732 if ( !current_user_can("edit_page", $page_id) ) 750 733 return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page."))); 751 }752 734 753 735 // Mark this as content for a page. … … 784 766 $password = $args[2]; 785 767 786 if ( !$user = $this->login($username, $password) ) { 787 return $this->error; 788 } 789 790 if( !current_user_can( 'edit_pages' ) ) 768 if ( !$user = $this->login($username, $password) ) 769 return $this->error; 770 771 if ( !current_user_can( 'edit_pages' ) ) 791 772 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); 792 773 … … 808 789 // The date needs to be formated properly. 809 790 $num_pages = count($page_list); 810 for ($i = 0; $i < $num_pages; $i++) {791 for ( $i = 0; $i < $num_pages; $i++ ) { 811 792 $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date, false); 812 793 $post_date_gmt = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt, false); … … 845 826 $password = $args[2]; 846 827 847 if ( !$user = $this->login($username, $password) ) { 848 return $this->error; 849 } 850 851 if(!current_user_can("edit_posts")) { 828 if ( !$user = $this->login($username, $password) ) 829 return $this->error; 830 831 if ( !current_user_can("edit_posts") ) 852 832 return(new IXR_Error(401, __("Sorry, you cannot edit posts on this blog."))); 853 }854 833 855 834 do_action('xmlrpc_call', 'wp.getAuthors'); 856 835 857 836 $authors = array(); 858 foreach ( (array) get_users_of_blog() as $row ) {837 foreach ( (array) get_users_of_blog() as $row ) { 859 838 $authors[] = array( 860 839 "user_id" => $row->user_id, … … 882 861 $password = $args[2]; 883 862 884 if ( !$user = $this->login($username, $password) ) { 885 return $this->error; 886 } 887 888 if( !current_user_can( 'edit_posts' ) ) { 863 if ( !$user = $this->login($username, $password) ) 864 return $this->error; 865 866 if ( !current_user_can( 'edit_posts' ) ) 889 867 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view tags.' ) ); 890 }891 868 892 869 do_action( 'xmlrpc_call', 'wp.getKeywords' ); … … 894 871 $tags = array( ); 895 872 896 if ( $all_tags = get_tags() ) {873 if ( $all_tags = get_tags() ) { 897 874 foreach( (array) $all_tags as $tag ) { 898 875 $struct['tag_id'] = $tag->term_id; … … 926 903 $category = $args[3]; 927 904 928 if ( !$user = $this->login($username, $password) ) { 929 return $this->error; 930 } 905 if ( !$user = $this->login($username, $password) ) 906 return $this->error; 931 907 932 908 do_action('xmlrpc_call', 'wp.newCategory'); 933 909 934 910 // Make sure the user is allowed to add a category. 935 if (!current_user_can("manage_categories")) {911 if ( !current_user_can("manage_categories") ) 936 912 return(new IXR_Error(401, __("Sorry, you do not have the right to add a category."))); 937 }938 913 939 914 // If no slug was provided make it empty so that 940 915 // WordPress will generate one. 941 if (empty($category["slug"])) {916 if ( empty($category["slug"]) ) 942 917 $category["slug"] = ""; 943 }944 918 945 919 // If no parent_id was provided make it empty … … 949 923 950 924 // If no description was provided make it empty. 951 if (empty($category["description"])) {925 if ( empty($category["description"]) ) 952 926 $category["description"] = ""; 953 }954 927 955 928 $new_category = array( … … 961 934 962 935 $cat_id = wp_insert_category($new_category); 963 if (!$cat_id) {936 if ( !$cat_id ) 964 937 return(new IXR_Error(500, __("Sorry, the new category failed."))); 965 }966 938 967 939 return($cat_id); … … 984 956 $category_id = (int) $args[3]; 985 957 986 if ( !$user = $this->login($username, $password) ) { 987 return $this->error; 988 } 958 if ( !$user = $this->login($username, $password) ) 959 return $this->error; 989 960 990 961 do_action('xmlrpc_call', 'wp.deleteCategory'); 991 962 992 if ( !current_user_can("manage_categories") ) {963 if ( !current_user_can("manage_categories") ) 993 964 return new IXR_Error( 401, __( "Sorry, you do not have the right to delete a category." ) ); 994 }995 965 996 966 return wp_delete_category( $category_id ); … … 1014 984 $max_results = (int) $args[4]; 1015 985 1016 if ( !$user = $this->login($username, $password) ) { 1017 return $this->error; 1018 } 1019 1020 if( !current_user_can( 'edit_posts' ) ) 986 if ( !$user = $this->login($username, $password) ) 987 return $this->error; 988 989 if ( !current_user_can( 'edit_posts' ) ) 1021 990 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this blog in order to view categories.' ) ); 1022 991 … … 1051 1020 $comment_id = (int) $args[3]; 1052 1021 1053 if ( !$user = $this->login($username, $password) ) { 1054 return $this->error; 1055 } 1022 if ( !$user = $this->login($username, $password) ) 1023 return $this->error; 1056 1024 1057 1025 if ( !current_user_can( 'moderate_comments' ) ) … … 1114 1082 $struct = $args[3]; 1115 1083 1116 if ( !$user = $this->login($username, $password) ) { 1117 return $this->error; 1118 } 1084 if ( !$user = $this->login($username, $password) ) 1085 return $this->error; 1119 1086 1120 1087 if ( !current_user_can( 'moderate_comments' ) ) … … 1174 1141 $comment_ID = (int) $args[3]; 1175 1142 1176 if ( !$user = $this->login($username, $password) ) { 1177 return $this->error; 1178 } 1143 if ( !$user = $this->login($username, $password) ) 1144 return $this->error; 1179 1145 1180 1146 if ( !current_user_can( 'moderate_comments' ) ) … … 1206 1172 $content_struct = $args[4]; 1207 1173 1208 if ( !$user = $this->login($username, $password) ) { 1209 return $this->error; 1210 } 1174 if ( !$user = $this->login($username, $password) ) 1175 return $this->error; 1211 1176 1212 1177 if ( !current_user_can( 'moderate_comments' ) ) … … 1357 1322 $password = $args[2]; 1358 1323 1359 if ( !$user = $this->login($username, $password) ) { 1360 return $this->error; 1361 } 1324 if ( !$user = $this->login($username, $password) ) 1325 return $this->error; 1362 1326 1363 1327 if ( !current_user_can( 'moderate_comments' ) ) … … 1385 1349 $post_id = (int) $args[3]; 1386 1350 1387 if ( !$user = $this->login($username, $password) ) { 1388 return $this->error; 1389 } 1390 1391 if( !current_user_can( 'edit_posts' ) ) { 1351 if ( !$user = $this->login($username, $password) ) 1352 return $this->error; 1353 1354 if ( !current_user_can( 'edit_posts' ) ) 1392 1355 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) ); 1393 }1394 1356 1395 1357 do_action('xmlrpc_call', 'wp.getCommentCount'); … … 1419 1381 $password = $args[2]; 1420 1382 1421 if ( !$user = $this->login($username, $password) ) { 1422 return $this->error; 1423 } 1424 1425 if( !current_user_can( 'edit_posts' ) ) { 1383 if ( !$user = $this->login($username, $password) ) 1384 return $this->error; 1385 1386 if ( !current_user_can( 'edit_posts' ) ) 1426 1387 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 1427 }1428 1388 1429 1389 do_action('xmlrpc_call', 'wp.getPostStatusList'); … … 1447 1407 $password = $args[2]; 1448 1408 1449 if ( !$user = $this->login($username, $password) ) { 1450 return $this->error; 1451 } 1452 1453 if( !current_user_can( 'edit_posts' ) ) { 1409 if ( !$user = $this->login($username, $password) ) 1410 return $this->error; 1411 1412 if ( !current_user_can( 'edit_posts' ) ) 1454 1413 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 1455 }1456 1414 1457 1415 do_action('xmlrpc_call', 'wp.getPageStatusList'); … … 1475 1433 $password = $args[2]; 1476 1434 1477 if ( !$user = $this->login($username, $password) ) { 1478 return $this->error; 1479 } 1480 1481 if( !current_user_can( 'edit_pages' ) ) { 1435 if ( !$user = $this->login($username, $password) ) 1436 return $this->error; 1437 1438 if ( !current_user_can( 'edit_pages' ) ) 1482 1439 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 1483 }1484 1440 1485 1441 $templates = get_page_templates( ); … … 1505 1461 $options = (array) $args[3]; 1506 1462 1507 if ( !$user = $this->login($username, $password) ) { 1508 return $this->error; 1509 } 1463 if ( !$user = $this->login($username, $password) ) 1464 return $this->error; 1510 1465 1511 1466 // If no specific options where asked for, return all of them 1512 if ( count( $options ) == 0 ) {1467 if ( count( $options ) == 0 ) 1513 1468 $options = array_keys($this->blog_options); 1514 }1515 1469 1516 1470 return $this->_getOptions($options); … … 1525 1479 * @return array 1526 1480 */ 1527 function _getOptions($options) 1528 { 1481 function _getOptions($options) { 1529 1482 $data = array( ); 1530 foreach( $options as $option ) { 1531 if( array_key_exists( $option, $this->blog_options ) ) 1532 { 1483 foreach ( $options as $option ) { 1484 if ( array_key_exists( $option, $this->blog_options ) ) { 1533 1485 $data[$option] = $this->blog_options[$option]; 1534 1486 //Is the value static or dynamic? 1535 if ( isset( $data[$option]['option'] ) ) {1487 if ( isset( $data[$option]['option'] ) ) { 1536 1488 $data[$option]['value'] = get_option( $data[$option]['option'] ); 1537 1489 unset($data[$option]['option']); … … 1559 1511 $options = (array) $args[3]; 1560 1512 1561 if ( !$user = $this->login($username, $password) ) { 1562 return $this->error; 1563 } 1564 1565 if( !current_user_can( 'manage_options' ) ) 1513 if ( !$user = $this->login($username, $password) ) 1514 return $this->error; 1515 1516 if ( !current_user_can( 'manage_options' ) ) 1566 1517 return new IXR_Error( 403, __( 'You are not allowed to update options.' ) ); 1567 1518 1568 foreach ( $options as $o_name => $o_value ) {1519 foreach ( $options as $o_name => $o_value ) { 1569 1520 $option_names[] = $o_name; 1570 if ( !array_key_exists( $o_name, $this->blog_options ) )1521 if ( !array_key_exists( $o_name, $this->blog_options ) ) 1571 1522 continue; 1572 1523 1573 if ( $this->blog_options[$o_name]['readonly'] == true )1524 if ( $this->blog_options[$o_name]['readonly'] == true ) 1574 1525 continue; 1575 1526 … … 1602 1553 $password = $args[2]; 1603 1554 1604 if ( !$user = $this->login($username, $password) ) { 1605 return $this->error; 1606 } 1555 if ( !$user = $this->login($username, $password) ) 1556 return $this->error; 1607 1557 1608 1558 do_action('xmlrpc_call', 'blogger.getUsersBlogs'); … … 1638 1588 $password = $args[2]; 1639 1589 1640 if ( !$user = $this->login($username, $password) ) { 1641 return $this->error; 1642 } 1643 1644 if( !current_user_can( 'edit_posts' ) ) 1590 if ( !$user = $this->login($username, $password) ) 1591 return $this->error; 1592 1593 if ( !current_user_can( 'edit_posts' ) ) 1645 1594 return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this blog.' ) ); 1646 1595 … … 1674 1623 $password = $args[3]; 1675 1624 1676 if ( !$user = $this->login($username, $password) ) { 1677 return $this->error; 1678 } 1679 1680 if( !current_user_can( 'edit_post', $post_ID ) ) 1625 if ( !$user = $this->login($username, $password) ) 1626 return $this->error; 1627 1628 if ( !current_user_can( 'edit_post', $post_ID ) ) 1681 1629 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); 1682 1630 … … 1718 1666 $num_posts = $args[4]; 1719 1667 1720 if ( !$user = $this->login($username, $password) ) { 1721 return $this->error; 1722 } 1668 if ( !$user = $this->login($username, $password) ) 1669 return $this->error; 1723 1670 1724 1671 do_action('xmlrpc_call', 'blogger.getRecentPosts'); … … 1726 1673 $posts_list = wp_get_recent_posts($num_posts); 1727 1674 1728 if ( !$posts_list) {1675 if ( !$posts_list ) { 1729 1676 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); 1730 1677 return $this->error; … … 1732 1679 1733 1680 foreach ($posts_list as $entry) { 1734 if ( !current_user_can( 'edit_post', $entry['ID'] ) )1681 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) 1735 1682 continue; 1736 1683 … … 1752 1699 1753 1700 $recent_posts = array(); 1754 for ( $j=0; $j<count($struct); $j++) {1701 for ( $j=0; $j<count($struct); $j++ ) { 1755 1702 array_push($recent_posts, $struct[$j]); 1756 1703 } … … 1776 1723 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */ 1777 1724 1778 if ( !$user = $this->login($username, $password) ) { 1779 return $this->error; 1780 } 1725 if ( !$user = $this->login($username, $password) ) 1726 return $this->error; 1781 1727 1782 1728 do_action('xmlrpc_call', 'blogger.getTemplate'); 1783 1729 1784 if ( !current_user_can('edit_themes') ) {1730 if ( !current_user_can('edit_themes') ) 1785 1731 return new IXR_Error(401, __('Sorry, this user can not edit the template.')); 1786 }1787 1732 1788 1733 /* warning: here we make the assumption that the blog's URL is on the same server */ … … 1818 1763 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */ 1819 1764 1820 if ( !$user = $this->login($username, $password) ) { 1821 return $this->error; 1822 } 1765 if ( !$user = $this->login($username, $password) ) 1766 return $this->error; 1823 1767 1824 1768 do_action('xmlrpc_call', 'blogger.setTemplate'); 1825 1769 1826 if ( !current_user_can('edit_themes') ) {1770 if ( !current_user_can('edit_themes') ) 1827 1771 return new IXR_Error(401, __('Sorry, this user cannot edit the template.')); 1828 }1829 1772 1830 1773 /* warning: here we make the assumption that the blog's URL is on the same server */ … … 1860 1803 $publish = $args[5]; 1861 1804 1862 if ( !$user = $this->login($username, $password) ) { 1863 return $this->error; 1864 } 1805 if ( !$user = $this->login($username, $password) ) 1806 return $this->error; 1865 1807 1866 1808 do_action('xmlrpc_call', 'blogger.newPost'); … … 1887 1829 return new IXR_Error(500, $post_ID->get_error_message()); 1888 1830 1889 if ( !$post_ID)1831 if ( !$post_ID ) 1890 1832 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); 1891 1833 … … 1915 1857 $publish = $args[5]; 1916 1858 1917 if ( !$user = $this->login($username, $password) ) { 1918 return $this->error; 1919 } 1859 if ( !$user = $this->login($username, $password) ) 1860 return $this->error; 1920 1861 1921 1862 do_action('xmlrpc_call', 'blogger.editPost'); … … 1923 1864 $actual_post = wp_get_single_post($post_ID,ARRAY_A); 1924 1865 1925 if ( !$actual_post || $actual_post['post_type'] != 'post') {1866 if ( !$actual_post || $actual_post['post_type'] != 'post' ) 1926 1867 return new IXR_Error(404, __('Sorry, no such post.')); 1927 }1928 1868 1929 1869 $this->escape($actual_post); … … 1945 1885 $result = wp_update_post($postdata); 1946 1886 1947 if ( !$result) {1887 if ( !$result ) 1948 1888 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.')); 1949 } 1889 1950 1890 $this->attach_uploads( $ID, $post_content ); 1951 1891 … … 1969 1909 $publish = $args[4]; 1970 1910 1971 if ( !$user = $this->login($username, $password) ) { 1972 return $this->error; 1973 } 1911 if ( !$user = $this->login($username, $password) ) 1912 return $this->error; 1974 1913 1975 1914 do_action('xmlrpc_call', 'blogger.deletePost'); … … 1977 1916 $actual_post = wp_get_single_post($post_ID,ARRAY_A); 1978 1917 1979 if ( !$actual_post || $actual_post['post_type'] != 'post') {1918 if ( !$actual_post || $actual_post['post_type'] != 'post' ) 1980 1919 return new IXR_Error(404, __('Sorry, no such post.')); 1981 }1982 1920 1983 1921 if ( !current_user_can('edit_post', $post_ID) ) … … 1986 1924 $result = wp_delete_post($post_ID); 1987 1925 1988 if ( !$result) {1926 if ( !$result ) 1989 1927 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.')); 1990 }1991 1928 1992 1929 return true; … … 2014 1951 $publish = $args[4]; 2015 1952 2016 if ( !$user = $this->login($username, $password) ) { 2017 return $this->error; 2018 } 1953 if ( !$user = $this->login($username, $password) ) 1954 return $this->error; 2019 1955 2020 1956 do_action('xmlrpc_call', 'metaWeblog.newPost'); … … 2024 1960 $post_type = 'post'; 2025 1961 $page_template = ''; 2026 if ( !empty( $content_struct['post_type'] ) ) {2027 if ( $content_struct['post_type'] == 'page' ) {1962 if ( !empty( $content_struct['post_type'] ) ) { 1963 if ( $content_struct['post_type'] == 'page' ) { 2028 1964 $cap = ( $publish ) ? 'publish_pages' : 'edit_pages'; 2029 1965 $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' ); 2030 1966 $post_type = 'page'; 2031 if ( !empty( $content_struct['wp_page_template'] ) )1967 if ( !empty( $content_struct['wp_page_template'] ) ) 2032 1968 $page_template = $content_struct['wp_page_template']; 2033 } 2034 elseif( $content_struct['post_type'] == 'post' ) { 1969 } elseif ( $content_struct['post_type'] == 'post' ) { 2035 1970 // This is the default, no changes needed 2036 } 2037 else { 1971 } else { 2038 1972 // No other post_type values are allowed here 2039 1973 return new IXR_Error( 401, __( 'Invalid post type.' ) ); … … 2041 1975 } 2042 1976 2043 if ( !current_user_can( $cap ) ) {1977 if ( !current_user_can( $cap ) ) 2044 1978 return new IXR_Error( 401, $error_message ); 2045 }2046 1979 2047 1980 // Let WordPress generate the post_name (slug) unless 2048 1981 // one has been provided. 2049 1982 $post_name = ""; 2050 if (isset($content_struct["wp_slug"])) {1983 if ( isset($content_struct["wp_slug"]) ) 2051 1984 $post_name = $content_struct["wp_slug"]; 2052 }2053 1985 2054 1986 // Only use a password if one was given. 2055 if (isset($content_struct["wp_password"])) {1987 if ( isset($content_struct["wp_password"]) ) 2056 1988 $post_password = $content_struct["wp_password"]; 2057 }2058 1989 2059 1990 // Only set a post parent if one was provided. 2060 if (isset($content_struct["wp_page_parent_id"])) {1991 if ( isset($content_struct["wp_page_parent_id"]) ) 2061 1992 $post_parent = $content_struct["wp_page_parent_id"]; 2062 }2063 1993 2064 1994 // Only set the menu_order if it was provided. 2065 if (isset($content_struct["wp_page_order"])) {1995 if ( isset($content_struct["wp_page_order"]) ) 2066 1996 $menu_order = $content_struct["wp_page_order"]; 2067 }2068 1997 2069 1998 $post_author = $user->ID; 2070 1999 2071 2000 // If an author id was provided then use it instead. 2072 if( 2073 isset($content_struct["wp_author_id"]) 2074 && ($user->ID != $content_struct["wp_author_id"]) 2075 ) { 2076 switch($post_type) { 2001 if ( isset($content_struct["wp_author_id"]) && ($user->ID != $content_struct["wp_author_id"]) ) { 2002 switch ( $post_type ) { 2077 2003 case "post": 2078 if (!current_user_can("edit_others_posts")) {2004 if ( !current_user_can("edit_others_posts") ) 2079 2005 return(new IXR_Error(401, __("You are not allowed to post as this user"))); 2080 }2081 2006 break; 2082 2007 case "page": 2083 if (!current_user_can("edit_others_pages")) {2008 if ( !current_user_can("edit_others_pages") ) 2084 2009 return(new IXR_Error(401, __("You are not allowed to create pages as this user"))); 2085 }2086 2010 break; 2087 2011 default: … … 2097 2021 $post_status = $publish ? 'publish' : 'draft'; 2098 2022 2099 if ( isset( $content_struct["{$post_type}_status"] ) ) {2100 switch ( $content_struct["{$post_type}_status"] ) {2023 if ( isset( $content_struct["{$post_type}_status"] ) ) { 2024 switch ( $content_struct["{$post_type}_status"] ) { 2101 2025 case 'draft': 2102 2026 case 'private': … … 2106 2030 case 'pending': 2107 2031 // Pending is only valid for posts, not pages. 2108 if ( $post_type === 'post' ) {2032 if ( $post_type === 'post' ) 2109 2033 $post_status = $content_struct["{$post_type}_status"]; 2110 }2111 2034 break; 2112 2035 default: … … 2121 2044 $tags_input = $content_struct['mt_keywords']; 2122 2045 2123 if (isset($content_struct["mt_allow_comments"])) {2124 if (!is_numeric($content_struct["mt_allow_comments"])) {2125 switch ($content_struct["mt_allow_comments"]) {2046 if ( isset($content_struct["mt_allow_comments"]) ) { 2047 if ( !is_numeric($content_struct["mt_allow_comments"]) ) { 2048 switch ( $content_struct["mt_allow_comments"] ) { 2126 2049 case "closed": 2127 2050 $comment_status = "closed"; … … 2134 2057 break; 2135 2058 } 2136 } 2137 else { 2138 switch((int) $content_struct["mt_allow_comments"]) { 2059 } else { 2060 switch ( (int) $content_struct["mt_allow_comments"] ) { 2139 2061 case 0: 2140 2062 case 2: … … 2149 2071 } 2150 2072 } 2151 } 2152 else { 2073 } else { 2153 2074 $comment_status = get_option("default_comment_status"); 2154 2075 } 2155 2076 2156 if (isset($content_struct["mt_allow_pings"])) {2157 if (!is_numeric($content_struct["mt_allow_pings"])) {2158 switch ($content_struct['mt_allow_pings']) {2077 if ( isset($content_struct["mt_allow_pings"]) ) { 2078 if ( !is_numeric($content_struct["mt_allow_pings"]) ) { 2079 switch ( $content_struct['mt_allow_pings'] ) { 2159 2080 case "closed": 2160 2081 $ping_status = "closed"; … … 2167 2088 break; 2168 2089 } 2169 } 2170 else { 2171 switch((int) $content_struct["mt_allow_pings"]) { 2090 } else { 2091 switch ( (int) $content_struct["mt_allow_pings"] ) { 2172 2092 case 0: 2173 2093 $ping_status = "closed"; … … 2181 2101 } 2182 2102 } 2183 } 2184 else { 2103 } else { 2185 2104 $ping_status = get_option("default_ping_status"); 2186 2105 } 2187 2106 2188 if ( $post_more) {2107 if ( $post_more ) 2189 2108 $post_content = $post_content . "<!--more-->" . $post_more; 2190 } 2191 2109 2192 2110 $to_ping = $content_struct['mt_tb_ping_urls']; 2193 2111 if ( is_array($to_ping) ) … … 2212 2130 $post_category = array(); 2213 2131 2214 if ( is_array($catnames)) {2132 if ( is_array($catnames) ) { 2215 2133 foreach ($catnames as $cat) { 2216 2134 $post_category[] = get_cat_ID($cat); … … 2225 2143 return new IXR_Error(500, $post_ID->get_error_message()); 2226 2144 2227 if ( !$post_ID) {2145 if ( !$post_ID ) 2228 2146 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); 2229 }2230 2147 2231 2148 // Only posts can be sticky 2232 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) 2149 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { 2233 2150 if ( $content_struct['sticky'] == true ) 2234 2151 stick_post( $post_ID ); 2235 2152 elseif ( $content_struct['sticky'] == false ) 2236 2153 unstick_post( $post_ID ); 2237 2238 if ( isset($content_struct['custom_fields']) ) { 2154 } 2155 2156 if ( isset($content_struct['custom_fields']) ) 2239 2157 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 2240 }2241 2158 2242 2159 // Handle enclosures … … 2251 2168 2252 2169 function add_enclosure_if_new($post_ID, $enclosure) { 2253 if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) {2170 if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { 2254 2171 2255 2172 $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type']; … … 2265 2182 } 2266 2183 } 2267 if (!$found) {2184 if (!$found) 2268 2185 add_post_meta( $post_ID, 'enclosure', $encstring ); 2269 }2270 2186 } 2271 2187 } … … 2284 2200 // find any unattached files 2285 2201 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); 2286 if ( is_array( $attachments ) ) {2287 foreach ( $attachments as $file ) {2288 if ( strpos( $post_content, $file->guid ) !== false ) {2202 if ( is_array( $attachments ) ) { 2203 foreach ( $attachments as $file ) { 2204 if ( strpos( $post_content, $file->guid ) !== false ) 2289 2205 $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) ); 2290 }2291 2206 } 2292 2207 } … … 2311 2226 $publish = $args[4]; 2312 2227 2313 if ( !$user = $this->login($username, $password) ) { 2314 return $this->error; 2315 } 2228 if ( !$user = $this->login($username, $password) ) 2229 return $this->error; 2316 2230 2317 2231 do_action('xmlrpc_call', 'metaWeblog.editPost'); … … 2321 2235 $post_type = 'post'; 2322 2236 $page_template = ''; 2323 if ( !empty( $content_struct['post_type'] ) ) {2324 if ( $content_struct['post_type'] == 'page' ) {2237 if ( !empty( $content_struct['post_type'] ) ) { 2238 if ( $content_struct['post_type'] == 'page' ) { 2325 2239 $cap = ( $publish ) ? 'publish_pages' : 'edit_pages'; 2326 2240 $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' ); 2327 2241 $post_type = 'page'; 2328 if ( !empty( $content_struct['wp_page_template'] ) )2242 if ( !empty( $content_struct['wp_page_template'] ) ) 2329 2243 $page_template = $content_struct['wp_page_template']; 2330 } 2331 elseif( $content_struct['post_type'] == 'post' ) { 2244 } elseif( $content_struct['post_type'] == 'post' ) { 2332 2245 // This is the default, no changes needed 2333 } 2334 else { 2246 } else { 2335 2247 // No other post_type values are allowed here 2336 2248 return new IXR_Error( 401, __( 'Invalid post type.' ) ); … … 2338 2250 } 2339 2251 2340 if ( !current_user_can( $cap ) ) {2252 if ( !current_user_can( $cap ) ) 2341 2253 return new IXR_Error( 401, $error_message ); 2342 }2343 2254 2344 2255 $postdata = wp_get_single_post($post_ID, ARRAY_A); … … 2347 2258 // now and return an error. Other wise a new post will be 2348 2259 // created (which was the old behavior). 2349 if (empty($postdata["ID"])) {2260 if ( empty($postdata["ID"]) ) 2350 2261 return(new IXR_Error(404, __("Invalid post ID."))); 2351 }2352 2262 2353 2263 $this->escape($postdata); … … 2356 2266 // Let WordPress manage slug if none was provided. 2357 2267 $post_name = ""; 2358 if (isset($content_struct["wp_slug"])) {2268 if ( isset($content_struct["wp_slug"]) ) 2359 2269 $post_name = $content_struct["wp_slug"]; 2360 }2361 2270 2362 2271 // Only use a password if one was given. 2363 if (isset($content_struct["wp_password"])) {2272 if ( isset($content_struct["wp_password"]) ) 2364 2273 $post_password = $content_struct["wp_password"]; 2365 }2366 2274 2367 2275 // Only set a post parent if one was given. 2368 if (isset($content_struct["wp_page_parent_id"])) {2276 if ( isset($content_struct["wp_page_parent_id"]) ) 2369 2277 $post_parent = $content_struct["wp_page_parent_id"]; 2370 }2371 2278 2372 2279 // Only set the menu_order if it was given. 2373 if (isset($content_struct["wp_page_order"])) {2280 if ( isset($content_struct["wp_page_order"]) ) 2374 2281 $menu_order = $content_struct["wp_page_order"]; 2375 }2376 2282 2377 2283 $post_author = $postdata["post_author"]; 2378 2284 2379 2285 // Only set the post_author if one is set. 2380 if( 2381 isset($content_struct["wp_author_id"]) 2382 && ($user->ID != $content_struct["wp_author_id"]) 2383 ) { 2384 switch($post_type) { 2286 if ( isset($content_struct["wp_author_id"]) && ($user->ID != $content_struct["wp_author_id"]) ) { 2287 switch ( $post_type ) { 2385 2288 case "post": 2386 if (!current_user_can("edit_others_posts")) {2289 if ( !current_user_can("edit_others_posts") ) 2387 2290 return(new IXR_Error(401, __("You are not allowed to change the post author as this user."))); 2388 }2389 2291 break; 2390 2292 case "page": 2391 if (!current_user_can("edit_others_pages")) {2293 if ( !current_user_can("edit_others_pages") ) 2392 2294 return(new IXR_Error(401, __("You are not allowed to change the page author as this user."))); 2393 }2394 2295 break; 2395 2296 default: … … 2400 2301 } 2401 2302 2402 if (isset($content_struct["mt_allow_comments"])) {2403 if (!is_numeric($content_struct["mt_allow_comments"])) {2404 switch ($content_struct["mt_allow_comments"]) {2303 if ( isset($content_struct["mt_allow_comments"]) ) { 2304 if ( !is_numeric($content_struct["mt_allow_comments"]) ) { 2305 switch ( $content_struct["mt_allow_comments"] ) { 2405 2306 case "closed": 2406 2307 $comment_status = "closed"; … … 2413 2314 break; 2414 2315 } 2415 } 2416 else { 2417 switch((int) $content_struct["mt_allow_comments"]) { 2316 } else { 2317 switch ( (int) $content_struct["mt_allow_comments"] ) { 2418 2318 case 0: 2419 2319 case 2: … … 2430 2330 } 2431 2331 2432 if (isset($content_struct["mt_allow_pings"])) {2433 if (!is_numeric($content_struct["mt_allow_pings"])) {2434 switch ($content_struct["mt_allow_pings"]) {2332 if ( isset($content_struct["mt_allow_pings"]) ) { 2333 if ( !is_numeric($content_struct["mt_allow_pings"]) ) { 2334 switch ( $content_struct["mt_allow_pings"] ) { 2435 2335 case "closed": 2436 2336 $ping_status = "closed"; … … 2443 2343 break; 2444 2344 } 2445 } 2446 else { 2447 switch((int) $content_struct["mt_allow_pings"]) { 2345 } else { 2346 switch ( (int) $content_struct["mt_allow_pings"] ) { 2448 2347 case 0: 2449 2348 $ping_status = "closed"; … … 2465 2364 $post_category = array(); 2466 2365 2467 if ( is_array($catnames)) {2366 if ( is_array($catnames) ) { 2468 2367 foreach ($catnames as $cat) { 2469 2368 $post_category[] = get_cat_ID($cat); … … 2475 2374 2476 2375 $post_status = $publish ? 'publish' : 'draft'; 2477 if ( isset( $content_struct["{$post_type}_status"] ) ) {2376 if ( isset( $content_struct["{$post_type}_status"] ) ) { 2478 2377 switch( $content_struct["{$post_type}_status"] ) { 2479 2378 case 'draft': … … 2484 2383 case 'pending': 2485 2384 // Pending is only valid for posts, not pages. 2486 if ( $post_type === 'post' ) {2385 if ( $post_type === 'post' ) 2487 2386 $post_status = $content_struct["{$post_type}_status"]; 2488 }2489 2387 break; 2490 2388 default: … … 2503 2401 } 2504 2402 2505 if ( $post_more) {2403 if ( $post_more ) 2506 2404 $post_content = $post_content . "<!--more-->" . $post_more; 2507 }2508 2405 2509 2406 $to_ping = $content_struct['mt_tb_ping_urls']; … … 2532 2429 return new IXR_Error(500, $result->get_error_message()); 2533 2430 2534 if ( !$result) {2431 if ( !$result ) 2535 2432 return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.')); 2536 }2537 2433 2538 2434 // Only posts can be sticky 2539 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) 2435 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { 2540 2436 if ( $content_struct['sticky'] == true ) 2541 2437 stick_post( $post_ID ); 2542 2438 elseif ( $content_struct['sticky'] == false ) 2543 2439 unstick_post( $post_ID ); 2544 2545 if ( isset($content_struct['custom_fields']) ) { 2440 } 2441 2442 if ( isset($content_struct['custom_fields']) ) 2546 2443 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 2547 }2548 2444 2549 2445 // Handle enclosures … … 2573 2469 $password = $args[2]; 2574 2470 2575 if ( !$user = $this->login($username, $password) ) { 2576 return $this->error; 2577 } 2578 2579 if( !current_user_can( 'edit_post', $post_ID ) ) 2471 if ( !$user = $this->login($username, $password) ) 2472 return $this->error; 2473 2474 if ( !current_user_can( 'edit_post', $post_ID ) ) 2580 2475 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); 2581 2476 … … 2589 2484 2590 2485 // For drafts use the GMT version of the post date 2591 if ( $postdata['post_status'] == 'draft' ) {2486 if ( $postdata['post_status'] == 'draft' ) 2592 2487 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s' ); 2593 }2594 2488 2595 2489 $categories = array(); … … 2618 2512 2619 2513 // Consider future posts as published 2620 if ( $postdata['post_status'] === 'future' ) {2514 if ( $postdata['post_status'] === 'future' ) 2621 2515 $postdata['post_status'] = 'publish'; 2622 }2623 2516 2624 2517 $sticky = false; … … 2665 2558 ); 2666 2559 2667 if ( !empty($enclosure)) $resp['enclosure'] = $enclosure;2560 if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure; 2668 2561 2669 2562 return $resp; … … 2690 2583 $num_posts = (int) $args[3]; 2691 2584 2692 if ( !$user = $this->login($username, $password) ) { 2693 return $this->error; 2694 } 2585 if ( !$user = $this->login($username, $password) ) 2586 return $this->error; 2695 2587 2696 2588 do_action('xmlrpc_call', 'metaWeblog.getRecentPosts'); … … 2698 2590 $posts_list = wp_get_recent_posts($num_posts); 2699 2591 2700 if ( !$posts_list) {2592 if ( !$posts_list ) 2701 2593 return array( ); 2702 }2703 2594 2704 2595 foreach ($posts_list as $entry) { 2705 if ( !current_user_can( 'edit_post', $entry['ID'] ) )2596 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) 2706 2597 continue; 2707 2598 … … 2710 2601 2711 2602 // For drafts use the GMT version of the date 2712 if ( $entry['post_status'] == 'draft' ) {2603 if ( $entry['post_status'] == 'draft' ) 2713 2604 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' ); 2714 }2715 2605 2716 2606 $categories = array(); 2717 2607 $catids = wp_get_post_categories($entry['ID']); 2718 foreach( $catids as $catid) {2608 foreach( $catids as $catid ) 2719 2609 $categories[] = get_cat_name($catid); 2720 }2721 2610 2722 2611 $tagnames = array(); … … 2741 2630 2742 2631 // Consider future posts as published 2743 if ( $entry['post_status'] === 'future' ) {2632 if ( $entry['post_status'] === 'future' ) 2744 2633 $entry['post_status'] = 'publish'; 2745 }2746 2634 2747 2635 $struct[] = array( … … 2773 2661 2774 2662 $recent_posts = array(); 2775 for ( $j=0; $j<count($struct); $j++) {2663 for ( $j=0; $j<count($struct); $j++ ) { 2776 2664 array_push($recent_posts, $struct[$j]); 2777 2665 } … … 2796 2684 $password = $args[2]; 2797 2685 2798 if ( !$user = $this->login($username, $password) ) { 2799 return $this->error; 2800 } 2801 2802 if( !current_user_can( 'edit_posts' ) ) 2686 if ( !$user = $this->login($username, $password) ) 2687 return $this->error; 2688 2689 if ( !current_user_can( 'edit_posts' ) ) 2803 2690 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) ); 2804 2691 … … 2850 2737 logIO('O', '(MW) Received '.strlen($bits).' bytes'); 2851 2738 2852 if ( !$user = $this->login($username, $password) ) { 2853 return $this->error; 2854 } 2739 if ( !$user = $this->login($username, $password) ) 2740 return $this->error; 2855 2741 2856 2742 do_action('xmlrpc_call', 'metaWeblog.newMediaObject'); … … 2865 2751 return new IXR_Error(500, $upload_err); 2866 2752 2867 if (!empty($data["overwrite"]) && ($data["overwrite"] == true)) {2753 if ( !empty($data["overwrite"]) && ($data["overwrite"] == true) ) { 2868 2754 // Get postmeta info on the object. 2869 2755 $old_file = $wpdb->get_row(" … … 2929 2815 $num_posts = (int) $args[3]; 2930 2816 2931 if ( !$user = $this->login($username, $password) ) { 2932 return $this->error; 2933 } 2817 if ( !$user = $this->login($username, $password) ) 2818 return $this->error; 2934 2819 2935 2820 do_action('xmlrpc_call', 'mt.getRecentPostTitles'); … … 2937 2822 $posts_list = wp_get_recent_posts($num_posts); 2938 2823 2939 if ( !$posts_list) {2824 if ( !$posts_list ) { 2940 2825 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); 2941 2826 return $this->error; … … 2950 2835 2951 2836 // For drafts use the GMT version of the date 2952 if ( $entry['post_status'] == 'draft' ) {2837 if ( $entry['post_status'] == 'draft' ) 2953 2838 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' ); 2954 }2955 2839 2956 2840 $struct[] = array( … … 2965 2849 2966 2850 $recent_posts = array(); 2967 for ( $j=0; $j<count($struct); $j++) {2851 for ( $j=0; $j<count($struct); $j++ ) { 2968 2852 array_push($recent_posts, $struct[$j]); 2969 2853 } … … 2988 2872 $password = $args[2]; 2989 2873 2990 if ( !$user = $this->login($username, $password) ) { 2991 return $this->error; 2992 } 2993 2994 if( !current_user_can( 'edit_posts' ) ) 2874 if ( !$user = $this->login($username, $password) ) 2875 return $this->error; 2876 2877 if ( !current_user_can( 'edit_posts' ) ) 2995 2878 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) ); 2996 2879 … … 3000 2883 3001 2884 if ( $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0)) ) { 3002 foreach ( $cats as $cat) {2885 foreach ( $cats as $cat ) { 3003 2886 $struct['categoryId'] = $cat->term_id; 3004 2887 $struct['categoryName'] = $cat->name; … … 3027 2910 $password = $args[2]; 3028 2911 3029 if ( !$user = $this->login($username, $password) ) { 3030 return $this->error; 3031 } 3032 3033 if( !current_user_can( 'edit_post', $post_ID ) ) 2912 if ( !$user = $this->login($username, $password) ) 2913 return $this->error; 2914 2915 if ( !current_user_can( 'edit_post', $post_ID ) ) 3034 2916 return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) ); 3035 2917 … … 3040 2922 // first listed category will be the primary category 3041 2923 $isPrimary = true; 3042 foreach ($catids as $catid) {2924 foreach ( $catids as $catid ) { 3043 2925 $categories[] = array( 3044 2926 'categoryName' => get_cat_name($catid), … … 3069 2951 $categories = $args[3]; 3070 2952 3071 if ( !$user = $this->login($username, $password) ) { 3072 return $this->error; 3073 } 2953 if ( !$user = $this->login($username, $password) ) 2954 return $this->error; 3074 2955 3075 2956 do_action('xmlrpc_call', 'mt.setPostCategories'); … … 3078 2959 return new IXR_Error(401, __('Sorry, you cannot edit this post.')); 3079 2960 3080 foreach ($categories as $cat) {2961 foreach ( $categories as $cat ) { 3081 2962 $catids[] = $cat['categoryId']; 3082 2963 } … … 3100 2981 3101 2982 $supported_methods = array(); 3102 foreach ($this->methods as $key=>$value) {2983 foreach ( $this->methods as $key => $value ) { 3103 2984 $supported_methods[] = $key; 3104 2985 } … … 3137 3018 $actual_post = wp_get_single_post($post_ID, ARRAY_A); 3138 3019 3139 if ( !$actual_post) {3020 if ( !$actual_post ) 3140 3021 return new IXR_Error(404, __('Sorry, no such post.')); 3141 }3142 3022 3143 3023 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); 3144 3024 3145 if ( !$comments) {3025 if ( !$comments ) 3146 3026 return array(); 3147 }3148 3027 3149 3028 $trackback_pings = array(); 3150 foreach ($comments as $comment) {3029 foreach ( $comments as $comment ) { 3151 3030 if ( 'trackback' == $comment->comment_type ) { 3152 3031 $content = $comment->comment_content; … … 3157 3036 'pingIP' => $comment->comment_author_IP 3158 3037 ); 3159 }3038 } 3160 3039 } 3161 3040 … … 3179 3058 $password = $args[2]; 3180 3059 3181 if ( !$user = $this->login($username, $password) ) { 3182 return $this->error; 3183 } 3060 if ( !$user = $this->login($username, $password) ) 3061 return $this->error; 3184 3062 3185 3063 do_action('xmlrpc_call', 'mt.publishPost'); … … 3232 3110 // Check if the page linked to is in our site 3233 3111 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home'))); 3234 if ( !$pos1 )3112 if ( !$pos1 ) 3235 3113 return new IXR_Error(0, __('Is there no link to us?')); 3236 3114 … … 3239 3117 // if so, then let's use it and drop the old code. 3240 3118 $urltest = parse_url($pagelinkedto); 3241 if ( $post_ID = url_to_postid($pagelinkedto)) {3119 if ( $post_ID = url_to_postid($pagelinkedto) ) { 3242 3120 $way = 'url_to_postid()'; 3243 } elseif ( preg_match('#p/[0-9]{1,}#', $urltest['path'], $match)) {3121 } elseif ( preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) { 3244 3122 // the path defines the post_ID (archives/p/XXXX) 3245 3123 $blah = explode('/', $match[0]); 3246 3124 $post_ID = (int) $blah[1]; 3247 3125 $way = 'from the path'; 3248 } elseif ( preg_match('#p=[0-9]{1,}#', $urltest['query'], $match)) {3126 } elseif ( preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) { 3249 3127 // the querystring defines the post_ID (?p=XXXX) 3250 3128 $blah = explode('=', $match[0]); 3251 3129 $post_ID = (int) $blah[1]; 3252 3130 $way = 'from the querystring'; 3253 } elseif ( isset($urltest['fragment'])) {3131 } elseif ( isset($urltest['fragment']) ) { 3254 3132 // an #anchor is there, it's either... 3255 if ( intval($urltest['fragment'])) {3133 if ( intval($urltest['fragment']) ) { 3256 3134 // ...an integer #XXXX (simpliest case) 3257 3135 $post_ID = (int) $urltest['fragment']; 3258 3136 $way = 'from the fragment (numeric)'; 3259 } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment'])) {3137 } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) { 3260 3138 // ...a post id in the form 'post-###' 3261 3139 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']); 3262 3140 $way = 'from the fragment (post-###)'; 3263 } elseif ( is_string($urltest['fragment'])) {3141 } elseif ( is_string($urltest['fragment']) ) { 3264 3142 // ...or a string #title, a little more complicated 3265 3143 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); … … 3396 3274 3397 3275 $post_ID = url_to_postid($url); 3398 if ( !$post_ID) {3276 if ( !$post_ID ) { 3399 3277 // We aren't sure that the resource is available and/or pingback enabled 3400 3278 return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.')); … … 3403 3281 $actual_post = wp_get_single_post($post_ID, ARRAY_A); 3404 3282 3405 if ( !$actual_post) {3283 if ( !$actual_post ) { 3406 3284 // No such post = resource not found 3407 3285 return new IXR_Error(32, __('The specified target URL does not exist.')); … … 3410 3288 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); 3411 3289 3412 if ( !$comments) {3290 if ( !$comments ) 3413 3291 return array(); 3414 }3415 3292 3416 3293 $pingbacks = array(); 3417 foreach ($comments as $comment) {3294 foreach ( $comments as $comment ) { 3418 3295 if ( 'pingback' == $comment->comment_type ) 3419 3296 $pingbacks[] = $comment->comment_author_url;
Note: See TracChangeset
for help on using the changeset viewer.