Make WordPress Core

Changeset 12735 for trunk/xmlrpc.php


Ignore:
Timestamp:
01/15/2010 11:40:29 PM (17 years ago)
Author:
ryan
Message:

Coding style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r12672 r12735  
    295295                global $wpdb;
    296296
    297                 if(!is_array($array)) {
     297                if (!is_array($array)) {
    298298                        return($wpdb->escape($array));
    299                 }
    300                 else {
     299                } else {
    301300                        foreach ( (array) $array as $k => $v ) {
    302                                 if (is_array($v)) {
     301                                if ( is_array($v) ) {
    303302                                        $this->escape($array[$k]);
    304                                 } else if (is_object($v)) {
     303                                } else if ( is_object($v) ) {
    305304                                        //skip
    306305                                } else {
    … …  
    444443        function wp_getUsersBlogs( $args ) {
    445444                // If this isn't on WPMU then just use blogger_getUsersBlogs
    446                 if( !is_multisite() ) {
     445                if ( !is_multisite() ) {
    447446                        array_unshift( $args, 1 );
    448447                        return $this->blogger_getUsersBlogs( $args );
    … …  
    463462                $struct = array( );
    464463
    465                 foreach( $blogs as $blog ) {
     464                foreach ( $blogs as $blog ) {
    466465                        // 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 )
    468467                                continue;
    469468
    … …  
    506505                }
    507506
    508                 if( !current_user_can( 'edit_page', $page_id ) )
     507                if ( !current_user_can( 'edit_page', $page_id ) )
    509508                        return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) );
    510509
    … …  
    515514
    516515                // 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") ) {
    518517                        // Get all of the page content and link.
    519518                        $full_page = get_extended($page->post_content);
    … …  
    522521                        // Get info the page parent if there is one.
    523522                        $parent_title = "";
    524                         if(!empty($page->post_parent)) {
     523                        if ( !empty($page->post_parent) ) {
    525524                                $parent = get_page($page->post_parent);
    526525                                $parent_title = $parent->post_title;
    … …  
    536535
    537536                        // For drafts use the GMT version of the date
    538                         if ( $page->post_status == 'draft' ) {
     537                        if ( $page->post_status == 'draft' )
    539538                                $page_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page->post_date ), 'Ymd\TH:i:s' );
    540                         }
    541539
    542540                        // Pull the categories info together.
    543541                        $categories = array();
    544                         foreach(wp_get_post_categories($page->ID) as $cat_id) {
     542                        foreach ( wp_get_post_categories($page->ID) as $cat_id ) {
    545543                                $categories[] = get_cat_name($cat_id);
    546544                        }
    … …  
    550548
    551549                        $page_template = get_post_meta( $page->ID, '_wp_page_template', true );
    552                         if( empty( $page_template ) )
     550                        if ( empty( $page_template ) )
    553551                                $page_template = 'default';
    554552
    … …  
    604602                $num_pages      = isset($args[3]) ? (int) $args[3] : 10;
    605603
    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' ) )
    611608                        return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) );
    612609
    … …  
    617614
    618615                // If we have pages, put together their info.
    619                 if($num_pages >= 1) {
     616                if ( $num_pages >= 1 ) {
    620617                        $pages_struct = array();
    621618
    622                         for($i = 0; $i < $num_pages; $i++) {
     619                        for ( $i = 0; $i < $num_pages; $i++ ) {
    623620                                $page = wp_xmlrpc_server::wp_getPage(array(
    624621                                        $blog_id, $pages[$i]->ID, $username, $password
    … …  
    650647                $publish        = $args[4];
    651648
    652                 if ( !$user = $this->login($username, $password) ) {
    653                         return $this->error;
    654                 }
     649                if ( !$user = $this->login($username, $password) )
     650                        return $this->error;
    655651
    656652                do_action('xmlrpc_call', 'wp.newPage');
    657653
    658654                // Make sure the user is allowed to add new pages.
    659                 if(!current_user_can("publish_pages")) {
     655                if ( !current_user_can("publish_pages") )
    660656                        return(new IXR_Error(401, __("Sorry, you cannot add new pages.")));
    661                 }
    662657
    663658                // Mark this as content for a page.
    … …  
    684679                $page_id        = (int) $args[3];
    685680
    686                 if ( !$user = $this->login($username, $password) ) {
    687                         return $this->error;
    688                 }
     681                if ( !$user = $this->login($username, $password) )
     682                        return $this->error;
    689683
    690684                do_action('xmlrpc_call', 'wp.deletePage');
    … …  
    693687                // make sure it is a page and not a post.
    694688                $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") )
    699690                        return(new IXR_Error(404, __("Sorry, no such page.")));
    700                 }
    701691
    702692                // 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) )
    704694                        return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page.")));
    705                 }
    706695
    707696                // Attempt to delete the page.
    708697                $result = wp_delete_post($page_id);
    709                 if(!$result) {
     698                if ( !$result )
    710699                        return(new IXR_Error(500, __("Failed to delete the page.")));
    711                 }
    712700
    713701                return(true);
    … …  
    731719                $publish        = $args[5];
    732720
    733                 if ( !$user = $this->login($username, $password) ) {
    734                         return $this->error;
    735                 }
     721                if ( !$user = $this->login($username, $password) )
     722                        return $this->error;
    736723
    737724                do_action('xmlrpc_call', 'wp.editPage');
    … …  
    739726                // Get the page data and make sure it is a page.
    740727                $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") )
    745729                        return(new IXR_Error(404, __("Sorry, no such page.")));
    746                 }
    747730
    748731                // 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) )
    750733                        return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page.")));
    751                 }
    752734
    753735                // Mark this as content for a page.
    … …  
    784766                $password                               = $args[2];
    785767
    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' ) )
    791772                        return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) );
    792773
    … …  
    808789                // The date needs to be formated properly.
    809790                $num_pages = count($page_list);
    810                 for($i = 0; $i < $num_pages; $i++) {
     791                for ( $i = 0; $i < $num_pages; $i++ ) {
    811792                        $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date, false);
    812793                        $post_date_gmt = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt, false);
    … …  
    845826                $password       = $args[2];
    846827
    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") )
    852832                        return(new IXR_Error(401, __("Sorry, you cannot edit posts on this blog.")));
    853                 }
    854833
    855834                do_action('xmlrpc_call', 'wp.getAuthors');
    856835
    857836                $authors = array();
    858                 foreach( (array) get_users_of_blog() as $row ) {
     837                foreach ( (array) get_users_of_blog() as $row ) {
    859838                        $authors[] = array(
    860839                                "user_id"       => $row->user_id,
    … …  
    882861                $password               = $args[2];
    883862
    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' ) )
    889867                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view tags.' ) );
    890                 }
    891868
    892869                do_action( 'xmlrpc_call', 'wp.getKeywords' );
    … …  
    894871                $tags = array( );
    895872
    896                 if( $all_tags = get_tags( ) ) {
     873                if ( $all_tags = get_tags() ) {
    897874                        foreach( (array) $all_tags as $tag ) {
    898875                                $struct['tag_id']                       = $tag->term_id;
    … …  
    926903                $category                               = $args[3];
    927904
    928                 if ( !$user = $this->login($username, $password) ) {
    929                         return $this->error;
    930                 }
     905                if ( !$user = $this->login($username, $password) )
     906                        return $this->error;
    931907
    932908                do_action('xmlrpc_call', 'wp.newCategory');
    933909
    934910                // Make sure the user is allowed to add a category.
    935                 if(!current_user_can("manage_categories")) {
     911                if ( !current_user_can("manage_categories") )
    936912                        return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
    937                 }
    938913
    939914                // If no slug was provided make it empty so that
    940915                // WordPress will generate one.
    941                 if(empty($category["slug"])) {
     916                if ( empty($category["slug"]) )
    942917                        $category["slug"] = "";
    943                 }
    944918
    945919                // If no parent_id was provided make it empty
    … …  
    949923
    950924                // If no description was provided make it empty.
    951                 if(empty($category["description"])) {
     925                if ( empty($category["description"]) )
    952926                        $category["description"] = "";
    953                 }
    954927
    955928                $new_category = array(
    … …  
    961934
    962935                $cat_id = wp_insert_category($new_category);
    963                 if(!$cat_id) {
     936                if ( !$cat_id )
    964937                        return(new IXR_Error(500, __("Sorry, the new category failed.")));
    965                 }
    966938
    967939                return($cat_id);
    … …  
    984956                $category_id    = (int) $args[3];
    985957
    986                 if ( !$user = $this->login($username, $password) ) {
    987                         return $this->error;
    988                 }
     958                if ( !$user = $this->login($username, $password) )
     959                        return $this->error;
    989960
    990961                do_action('xmlrpc_call', 'wp.deleteCategory');
    991962
    992                 if( !current_user_can("manage_categories") ) {
     963                if ( !current_user_can("manage_categories") )
    993964                        return new IXR_Error( 401, __( "Sorry, you do not have the right to delete a category." ) );
    994                 }
    995965
    996966                return wp_delete_category( $category_id );
    … …  
    1014984                $max_results                    = (int) $args[4];
    1015985
    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' ) )
    1021990                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this blog in order to view categories.' ) );
    1022991
    … …  
    10511020                $comment_id     = (int) $args[3];
    10521021
    1053                 if ( !$user = $this->login($username, $password) ) {
    1054                         return $this->error;
    1055                 }
     1022                if ( !$user = $this->login($username, $password) )
     1023                        return $this->error;
    10561024
    10571025                if ( !current_user_can( 'moderate_comments' ) )
    … …  
    11141082                $struct         = $args[3];
    11151083
    1116                 if ( !$user = $this->login($username, $password) ) {
    1117                         return $this->error;
    1118                 }
     1084                if ( !$user = $this->login($username, $password) )
     1085                        return $this->error;
    11191086
    11201087                if ( !current_user_can( 'moderate_comments' ) )
    … …  
    11741141                $comment_ID     = (int) $args[3];
    11751142
    1176                 if ( !$user = $this->login($username, $password) ) {
    1177                         return $this->error;
    1178                 }
     1143                if ( !$user = $this->login($username, $password) )
     1144                        return $this->error;
    11791145
    11801146                if ( !current_user_can( 'moderate_comments' ) )
    … …  
    12061172                $content_struct = $args[4];
    12071173
    1208                 if ( !$user = $this->login($username, $password) ) {
    1209                         return $this->error;
    1210                 }
     1174                if ( !$user = $this->login($username, $password) )
     1175                        return $this->error;
    12111176
    12121177                if ( !current_user_can( 'moderate_comments' ) )
    … …  
    13571322                $password       = $args[2];
    13581323
    1359                 if ( !$user = $this->login($username, $password) ) {
    1360                         return $this->error;
    1361                 }
     1324                if ( !$user = $this->login($username, $password) )
     1325                        return $this->error;
    13621326
    13631327                if ( !current_user_can( 'moderate_comments' ) )
    … …  
    13851349                $post_id        = (int) $args[3];
    13861350
    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' ) )
    13921355                        return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) );
    1393                 }
    13941356
    13951357                do_action('xmlrpc_call', 'wp.getCommentCount');
    … …  
    14191381                $password       = $args[2];
    14201382
    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' ) )
    14261387                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
    1427                 }
    14281388
    14291389                do_action('xmlrpc_call', 'wp.getPostStatusList');
    … …  
    14471407                $password       = $args[2];
    14481408
    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' ) )
    14541413                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
    1455                 }
    14561414
    14571415                do_action('xmlrpc_call', 'wp.getPageStatusList');
    … …  
    14751433                $password       = $args[2];
    14761434
    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' ) )
    14821439                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
    1483                 }
    14841440
    14851441                $templates = get_page_templates( );
    … …  
    15051461                $options        = (array) $args[3];
    15061462
    1507                 if ( !$user = $this->login($username, $password) ) {
    1508                         return $this->error;
    1509                 }
     1463                if ( !$user = $this->login($username, $password) )
     1464                        return $this->error;
    15101465
    15111466                // If no specific options where asked for, return all of them
    1512                 if (count( $options ) == 0 ) {
     1467                if ( count( $options ) == 0 )
    15131468                        $options = array_keys($this->blog_options);
    1514                 }
    15151469
    15161470                return $this->_getOptions($options);
    … …  
    15251479         * @return array
    15261480         */
    1527         function _getOptions($options)
    1528         {
     1481        function _getOptions($options) {
    15291482                $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 ) ) {
    15331485                                $data[$option] = $this->blog_options[$option];
    15341486                                //Is the value static or dynamic?
    1535                                 if( isset( $data[$option]['option'] ) ) {
     1487                                if ( isset( $data[$option]['option'] ) ) {
    15361488                                        $data[$option]['value'] = get_option( $data[$option]['option'] );
    15371489                                        unset($data[$option]['option']);
    … …  
    15591511                $options        = (array) $args[3];
    15601512
    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' ) )
    15661517                        return new IXR_Error( 403, __( 'You are not allowed to update options.' ) );
    15671518
    1568                 foreach( $options as $o_name => $o_value ) {
     1519                foreach ( $options as $o_name => $o_value ) {
    15691520                        $option_names[] = $o_name;
    1570                         if( !array_key_exists( $o_name, $this->blog_options ) )
     1521                        if ( !array_key_exists( $o_name, $this->blog_options ) )
    15711522                                continue;
    15721523
    1573                         if( $this->blog_options[$o_name]['readonly'] == true )
     1524                        if ( $this->blog_options[$o_name]['readonly'] == true )
    15741525                                continue;
    15751526
    … …  
    16021553                $password  = $args[2];
    16031554
    1604                 if ( !$user = $this->login($username, $password) ) {
    1605                         return $this->error;
    1606                 }
     1555                if ( !$user = $this->login($username, $password) )
     1556                        return $this->error;
    16071557
    16081558                do_action('xmlrpc_call', 'blogger.getUsersBlogs');
    … …  
    16381588                $password  = $args[2];
    16391589
    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' ) )
    16451594                        return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this blog.' ) );
    16461595
    … …  
    16741623                $password  = $args[3];
    16751624
    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 ) )
    16811629                        return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
    16821630
    … …  
    17181666                $num_posts  = $args[4];
    17191667
    1720                 if ( !$user = $this->login($username, $password) ) {
    1721                         return $this->error;
    1722                 }
     1668                if ( !$user = $this->login($username, $password) )
     1669                        return $this->error;
    17231670
    17241671                do_action('xmlrpc_call', 'blogger.getRecentPosts');
    … …  
    17261673                $posts_list = wp_get_recent_posts($num_posts);
    17271674
    1728                 if (!$posts_list) {
     1675                if ( !$posts_list ) {
    17291676                        $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.'));
    17301677                        return $this->error;
    … …  
    17321679
    17331680                foreach ($posts_list as $entry) {
    1734                         if( !current_user_can( 'edit_post', $entry['ID'] ) )
     1681                        if ( !current_user_can( 'edit_post', $entry['ID'] ) )
    17351682                                continue;
    17361683
    … …  
    17521699
    17531700                $recent_posts = array();
    1754                 for ($j=0; $j<count($struct); $j++) {
     1701                for ( $j=0; $j<count($struct); $j++ ) {
    17551702                        array_push($recent_posts, $struct[$j]);
    17561703                }
    … …  
    17761723                $template   = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
    17771724
    1778                 if ( !$user = $this->login($username, $password) ) {
    1779                         return $this->error;
    1780                 }
     1725                if ( !$user = $this->login($username, $password) )
     1726                        return $this->error;
    17811727
    17821728                do_action('xmlrpc_call', 'blogger.getTemplate');
    17831729
    1784                 if ( !current_user_can('edit_themes') ) {
     1730                if ( !current_user_can('edit_themes') )
    17851731                        return new IXR_Error(401, __('Sorry, this user can not edit the template.'));
    1786                 }
    17871732
    17881733                /* warning: here we make the assumption that the blog's URL is on the same server */
    … …  
    18181763                $template   = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
    18191764
    1820                 if ( !$user = $this->login($username, $password) ) {
    1821                         return $this->error;
    1822                 }
     1765                if ( !$user = $this->login($username, $password) )
     1766                        return $this->error;
    18231767
    18241768                do_action('xmlrpc_call', 'blogger.setTemplate');
    18251769
    1826                 if ( !current_user_can('edit_themes') ) {
     1770                if ( !current_user_can('edit_themes') )
    18271771                        return new IXR_Error(401, __('Sorry, this user cannot edit the template.'));
    1828                 }
    18291772
    18301773                /* warning: here we make the assumption that the blog's URL is on the same server */
    … …  
    18601803                $publish    = $args[5];
    18611804
    1862                 if ( !$user = $this->login($username, $password) ) {
    1863                         return $this->error;
    1864                 }
     1805                if ( !$user = $this->login($username, $password) )
     1806                        return $this->error;
    18651807
    18661808                do_action('xmlrpc_call', 'blogger.newPost');
    … …  
    18871829                        return new IXR_Error(500, $post_ID->get_error_message());
    18881830
    1889                 if (!$post_ID)
     1831                if ( !$post_ID )
    18901832                        return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
    18911833
    … …  
    19151857                $publish     = $args[5];
    19161858
    1917                 if ( !$user = $this->login($username, $password) ) {
    1918                         return $this->error;
    1919                 }
     1859                if ( !$user = $this->login($username, $password) )
     1860                        return $this->error;
    19201861
    19211862                do_action('xmlrpc_call', 'blogger.editPost');
    … …  
    19231864                $actual_post = wp_get_single_post($post_ID,ARRAY_A);
    19241865
    1925                 if (!$actual_post || $actual_post['post_type'] != 'post') {
     1866                if ( !$actual_post || $actual_post['post_type'] != 'post' )
    19261867                        return new IXR_Error(404, __('Sorry, no such post.'));
    1927                 }
    19281868
    19291869                $this->escape($actual_post);
    … …  
    19451885                $result = wp_update_post($postdata);
    19461886
    1947                 if (!$result) {
     1887                if ( !$result )
    19481888                        return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.'));
    1949                 }
     1889
    19501890                $this->attach_uploads( $ID, $post_content );
    19511891
    … …  
    19691909                $publish     = $args[4];
    19701910
    1971                 if ( !$user = $this->login($username, $password) ) {
    1972                         return $this->error;
    1973                 }
     1911                if ( !$user = $this->login($username, $password) )
     1912                        return $this->error;
    19741913
    19751914                do_action('xmlrpc_call', 'blogger.deletePost');
    … …  
    19771916                $actual_post = wp_get_single_post($post_ID,ARRAY_A);
    19781917
    1979                 if (!$actual_post || $actual_post['post_type'] != 'post') {
     1918                if ( !$actual_post || $actual_post['post_type'] != 'post' )
    19801919                        return new IXR_Error(404, __('Sorry, no such post.'));
    1981                 }
    19821920
    19831921                if ( !current_user_can('edit_post', $post_ID) )
    … …  
    19861924                $result = wp_delete_post($post_ID);
    19871925
    1988                 if (!$result) {
     1926                if ( !$result )
    19891927                        return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.'));
    1990                 }
    19911928
    19921929                return true;
    … …  
    20141951                $publish     = $args[4];
    20151952
    2016                 if ( !$user = $this->login($username, $password) ) {
    2017                         return $this->error;
    2018                 }
     1953                if ( !$user = $this->login($username, $password) )
     1954                        return $this->error;
    20191955
    20201956                do_action('xmlrpc_call', 'metaWeblog.newPost');
    … …  
    20241960                $post_type = 'post';
    20251961                $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' ) {
    20281964                                $cap = ( $publish ) ? 'publish_pages' : 'edit_pages';
    20291965                                $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' );
    20301966                                $post_type = 'page';
    2031                                 if( !empty( $content_struct['wp_page_template'] ) )
     1967                                if ( !empty( $content_struct['wp_page_template'] ) )
    20321968                                        $page_template = $content_struct['wp_page_template'];
    2033                         }
    2034                         elseif( $content_struct['post_type'] == 'post' ) {
     1969                        } elseif ( $content_struct['post_type'] == 'post' ) {
    20351970                                // This is the default, no changes needed
    2036                         }
    2037                         else {
     1971                        } else {
    20381972                                // No other post_type values are allowed here
    20391973                                return new IXR_Error( 401, __( 'Invalid post type.' ) );
    … …  
    20411975                }
    20421976
    2043                 if( !current_user_can( $cap ) ) {
     1977                if ( !current_user_can( $cap ) )
    20441978                        return new IXR_Error( 401, $error_message );
    2045                 }
    20461979
    20471980                // Let WordPress generate the post_name (slug) unless
    20481981                // one has been provided.
    20491982                $post_name = "";
    2050                 if(isset($content_struct["wp_slug"])) {
     1983                if ( isset($content_struct["wp_slug"]) )
    20511984                        $post_name = $content_struct["wp_slug"];
    2052                 }
    20531985
    20541986                // Only use a password if one was given.
    2055                 if(isset($content_struct["wp_password"])) {
     1987                if ( isset($content_struct["wp_password"]) )
    20561988                        $post_password = $content_struct["wp_password"];
    2057                 }
    20581989
    20591990                // 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"]) )
    20611992                        $post_parent = $content_struct["wp_page_parent_id"];
    2062                 }
    20631993
    20641994                // 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"]) )
    20661996                        $menu_order = $content_struct["wp_page_order"];
    2067                 }
    20681997
    20691998                $post_author = $user->ID;
    20701999
    20712000                // 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 ) {
    20772003                                case "post":
    2078                                         if(!current_user_can("edit_others_posts")) {
     2004                                        if ( !current_user_can("edit_others_posts") )
    20792005                                                return(new IXR_Error(401, __("You are not allowed to post as this user")));
    2080                                         }
    20812006                                        break;
    20822007                                case "page":
    2083                                         if(!current_user_can("edit_others_pages")) {
     2008                                        if ( !current_user_can("edit_others_pages") )
    20842009                                                return(new IXR_Error(401, __("You are not allowed to create pages as this user")));
    2085                                         }
    20862010                                        break;
    20872011                                default:
    … …  
    20972021                $post_status = $publish ? 'publish' : 'draft';
    20982022
    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"] ) {
    21012025                                case 'draft':
    21022026                                case 'private':
    … …  
    21062030                                case 'pending':
    21072031                                        // Pending is only valid for posts, not pages.
    2108                                         if( $post_type === 'post' ) {
     2032                                        if ( $post_type === 'post' )
    21092033                                                $post_status = $content_struct["{$post_type}_status"];
    2110                                         }
    21112034                                        break;
    21122035                                default:
    … …  
    21212044                $tags_input = $content_struct['mt_keywords'];
    21222045
    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"] ) {
    21262049                                        case "closed":
    21272050                                                $comment_status = "closed";
    … …  
    21342057                                                break;
    21352058                                }
    2136                         }
    2137                         else {
    2138                                 switch((int) $content_struct["mt_allow_comments"]) {
     2059                        } else {
     2060                                switch ( (int) $content_struct["mt_allow_comments"] ) {
    21392061                                        case 0:
    21402062                                        case 2:
    … …  
    21492071                                }
    21502072                        }
    2151                 }
    2152                 else {
     2073                } else {
    21532074                        $comment_status = get_option("default_comment_status");
    21542075                }
    21552076
    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'] ) {
    21592080                                        case "closed":
    21602081                                                $ping_status = "closed";
    … …  
    21672088                                                break;
    21682089                                }
    2169                         }
    2170                         else {
    2171                                 switch((int) $content_struct["mt_allow_pings"]) {
     2090                        } else {
     2091                                switch ( (int) $content_struct["mt_allow_pings"] ) {
    21722092                                        case 0:
    21732093                                                $ping_status = "closed";
    … …  
    21812101                                }
    21822102                        }
    2183                 }
    2184                 else {
     2103                } else {
    21852104                        $ping_status = get_option("default_ping_status");
    21862105                }
    21872106
    2188                 if ($post_more) {
     2107                if ( $post_more )
    21892108                        $post_content = $post_content . "<!--more-->" . $post_more;
    2190                 }
    2191 
     2109 
    21922110                $to_ping = $content_struct['mt_tb_ping_urls'];
    21932111                if ( is_array($to_ping) )
    … …  
    22122130                $post_category = array();
    22132131
    2214                 if (is_array($catnames)) {
     2132                if ( is_array($catnames) ) {
    22152133                        foreach ($catnames as $cat) {
    22162134                                $post_category[] = get_cat_ID($cat);
    … …  
    22252143                        return new IXR_Error(500, $post_ID->get_error_message());
    22262144
    2227                 if (!$post_ID) {
     2145                if ( !$post_ID )
    22282146                        return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
    2229                 }
    22302147
    22312148                // Only posts can be sticky
    2232                 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) )
     2149                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    22332150                        if ( $content_struct['sticky'] == true )
    22342151                                stick_post( $post_ID );
    22352152                        elseif ( $content_struct['sticky'] == false )
    22362153                                unstick_post( $post_ID );
    2237 
    2238                 if ( isset($content_struct['custom_fields']) ) {
     2154                }
     2155
     2156                if ( isset($content_struct['custom_fields']) )
    22392157                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    2240                 }
    22412158
    22422159                // Handle enclosures
    … …  
    22512168
    22522169        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'] ) ) {
    22542171
    22552172                        $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'];
    … …  
    22652182                                }
    22662183                        }
    2267                         if (!$found) {
     2184                        if (!$found)
    22682185                                add_post_meta( $post_ID, 'enclosure', $encstring );
    2269                         }
    22702186                }
    22712187        }
    … …  
    22842200                // find any unattached files
    22852201                $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 )
    22892205                                        $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) );
    2290                                 }
    22912206                        }
    22922207                }
    … …  
    23112226                $publish     = $args[4];
    23122227
    2313                 if ( !$user = $this->login($username, $password) ) {
    2314                         return $this->error;
    2315                 }
     2228                if ( !$user = $this->login($username, $password) )
     2229                        return $this->error;
    23162230
    23172231                do_action('xmlrpc_call', 'metaWeblog.editPost');
    … …  
    23212235                $post_type = 'post';
    23222236                $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' ) {
    23252239                                $cap = ( $publish ) ? 'publish_pages' : 'edit_pages';
    23262240                                $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' );
    23272241                                $post_type = 'page';
    2328                                 if( !empty( $content_struct['wp_page_template'] ) )
     2242                                if ( !empty( $content_struct['wp_page_template'] ) )
    23292243                                        $page_template = $content_struct['wp_page_template'];
    2330                         }
    2331                         elseif( $content_struct['post_type'] == 'post' ) {
     2244                        } elseif( $content_struct['post_type'] == 'post' ) {
    23322245                                // This is the default, no changes needed
    2333                         }
    2334                         else {
     2246                        } else {
    23352247                                // No other post_type values are allowed here
    23362248                                return new IXR_Error( 401, __( 'Invalid post type.' ) );
    … …  
    23382250                }
    23392251
    2340                 if( !current_user_can( $cap ) ) {
     2252                if ( !current_user_can( $cap ) )
    23412253                        return new IXR_Error( 401, $error_message );
    2342                 }
    23432254
    23442255                $postdata = wp_get_single_post($post_ID, ARRAY_A);
    … …  
    23472258                // now and return an error.  Other wise a new post will be
    23482259                // created (which was the old behavior).
    2349                 if(empty($postdata["ID"])) {
     2260                if ( empty($postdata["ID"]) )
    23502261                        return(new IXR_Error(404, __("Invalid post ID.")));
    2351                 }
    23522262
    23532263                $this->escape($postdata);
    … …  
    23562266                // Let WordPress manage slug if none was provided.
    23572267                $post_name = "";
    2358                 if(isset($content_struct["wp_slug"])) {
     2268                if ( isset($content_struct["wp_slug"]) )
    23592269                        $post_name = $content_struct["wp_slug"];
    2360                 }
    23612270
    23622271                // Only use a password if one was given.
    2363                 if(isset($content_struct["wp_password"])) {
     2272                if ( isset($content_struct["wp_password"]) )
    23642273                        $post_password = $content_struct["wp_password"];
    2365                 }
    23662274
    23672275                // 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"]) )
    23692277                        $post_parent = $content_struct["wp_page_parent_id"];
    2370                 }
    23712278
    23722279                // 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"]) )
    23742281                        $menu_order = $content_struct["wp_page_order"];
    2375                 }
    23762282
    23772283                $post_author = $postdata["post_author"];
    23782284
    23792285                // 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 ) {
    23852288                                case "post":
    2386                                         if(!current_user_can("edit_others_posts")) {
     2289                                        if ( !current_user_can("edit_others_posts") )
    23872290                                                return(new IXR_Error(401, __("You are not allowed to change the post author as this user.")));
    2388                                         }
    23892291                                        break;
    23902292                                case "page":
    2391                                         if(!current_user_can("edit_others_pages")) {
     2293                                        if ( !current_user_can("edit_others_pages") )
    23922294                                                return(new IXR_Error(401, __("You are not allowed to change the page author as this user.")));
    2393                                         }
    23942295                                        break;
    23952296                                default:
    … …  
    24002301                }
    24012302
    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"] ) {
    24052306                                        case "closed":
    24062307                                                $comment_status = "closed";
    … …  
    24132314                                                break;
    24142315                                }
    2415                         }
    2416                         else {
    2417                                 switch((int) $content_struct["mt_allow_comments"]) {
     2316                        } else {
     2317                                switch ( (int) $content_struct["mt_allow_comments"] ) {
    24182318                                        case 0:
    24192319                                        case 2:
    … …  
    24302330                }
    24312331
    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"] ) {
    24352335                                        case "closed":
    24362336                                                $ping_status = "closed";
    … …  
    24432343                                                break;
    24442344                                }
    2445                         }
    2446                         else {
    2447                                 switch((int) $content_struct["mt_allow_pings"]) {
     2345                        } else {
     2346                                switch ( (int) $content_struct["mt_allow_pings"] ) {
    24482347                                        case 0:
    24492348                                                $ping_status = "closed";
    … …  
    24652364                $post_category = array();
    24662365
    2467                 if (is_array($catnames)) {
     2366                if ( is_array($catnames) ) {
    24682367                        foreach ($catnames as $cat) {
    24692368                                $post_category[] = get_cat_ID($cat);
    … …  
    24752374
    24762375                $post_status = $publish ? 'publish' : 'draft';
    2477                 if( isset( $content_struct["{$post_type}_status"] ) ) {
     2376                if ( isset( $content_struct["{$post_type}_status"] ) ) {
    24782377                        switch( $content_struct["{$post_type}_status"] ) {
    24792378                                case 'draft':
    … …  
    24842383                                case 'pending':
    24852384                                        // Pending is only valid for posts, not pages.
    2486                                         if( $post_type === 'post' ) {
     2385                                        if ( $post_type === 'post' )
    24872386                                                $post_status = $content_struct["{$post_type}_status"];
    2488                                         }
    24892387                                        break;
    24902388                                default:
    … …  
    25032401                }
    25042402
    2505                 if ($post_more) {
     2403                if ( $post_more )
    25062404                        $post_content = $post_content . "<!--more-->" . $post_more;
    2507                 }
    25082405
    25092406                $to_ping = $content_struct['mt_tb_ping_urls'];
    … …  
    25322429                        return new IXR_Error(500, $result->get_error_message());
    25332430
    2534                 if (!$result) {
     2431                if ( !$result )
    25352432                        return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
    2536                 }
    25372433
    25382434                // Only posts can be sticky
    2539                 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) )
     2435                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    25402436                        if ( $content_struct['sticky'] == true )
    25412437                                stick_post( $post_ID );
    25422438                        elseif ( $content_struct['sticky'] == false )
    25432439                                unstick_post( $post_ID );
    2544 
    2545                 if ( isset($content_struct['custom_fields']) ) {
     2440                }
     2441
     2442                if ( isset($content_struct['custom_fields']) )
    25462443                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    2547                 }
    25482444
    25492445                // Handle enclosures
    … …  
    25732469                $password   = $args[2];
    25742470
    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 ) )
    25802475                        return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
    25812476
    … …  
    25892484
    25902485                        // For drafts use the GMT version of the post date
    2591                         if ( $postdata['post_status'] == 'draft' ) {
     2486                        if ( $postdata['post_status'] == 'draft' )
    25922487                                $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s' );
    2593                         }
    25942488
    25952489                        $categories = array();
    … …  
    26182512
    26192513                        // Consider future posts as published
    2620                         if( $postdata['post_status'] === 'future' ) {
     2514                        if ( $postdata['post_status'] === 'future' )
    26212515                                $postdata['post_status'] = 'publish';
    2622                         }
    26232516
    26242517                        $sticky = false;
    … …  
    26652558                        );
    26662559
    2667                         if (!empty($enclosure)) $resp['enclosure'] = $enclosure;
     2560                        if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure;
    26682561
    26692562                        return $resp;
    … …  
    26902583                $num_posts   = (int) $args[3];
    26912584
    2692                 if ( !$user = $this->login($username, $password) ) {
    2693                         return $this->error;
    2694                 }
     2585                if ( !$user = $this->login($username, $password) )
     2586                        return $this->error;
    26952587
    26962588                do_action('xmlrpc_call', 'metaWeblog.getRecentPosts');
    … …  
    26982590                $posts_list = wp_get_recent_posts($num_posts);
    26992591
    2700                 if (!$posts_list) {
     2592                if ( !$posts_list )
    27012593                        return array( );
    2702                 }
    27032594
    27042595                foreach ($posts_list as $entry) {
    2705                         if( !current_user_can( 'edit_post', $entry['ID'] ) )
     2596                        if ( !current_user_can( 'edit_post', $entry['ID'] ) )
    27062597                                continue;
    27072598
    … …  
    27102601
    27112602                        // For drafts use the GMT version of the date
    2712                         if ( $entry['post_status'] == 'draft' ) {
     2603                        if ( $entry['post_status'] == 'draft' )
    27132604                                $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' );
    2714                         }
    27152605
    27162606                        $categories = array();
    27172607                        $catids = wp_get_post_categories($entry['ID']);
    2718                         foreach($catids as $catid) {
     2608                        foreach( $catids as $catid )
    27192609                                $categories[] = get_cat_name($catid);
    2720                         }
    27212610
    27222611                        $tagnames = array();
    … …  
    27412630
    27422631                        // Consider future posts as published
    2743                         if( $entry['post_status'] === 'future' ) {
     2632                        if ( $entry['post_status'] === 'future' )
    27442633                                $entry['post_status'] = 'publish';
    2745                         }
    27462634
    27472635                        $struct[] = array(
    … …  
    27732661
    27742662                $recent_posts = array();
    2775                 for ($j=0; $j<count($struct); $j++) {
     2663                for ( $j=0; $j<count($struct); $j++ ) {
    27762664                        array_push($recent_posts, $struct[$j]);
    27772665                }
    … …  
    27962684                $password   = $args[2];
    27972685
    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' ) )
    28032690                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) );
    28042691
    … …  
    28502737                logIO('O', '(MW) Received '.strlen($bits).' bytes');
    28512738
    2852                 if ( !$user = $this->login($username, $password) ) {
    2853                         return $this->error;
    2854                 }
     2739                if ( !$user = $this->login($username, $password) )
     2740                        return $this->error;
    28552741
    28562742                do_action('xmlrpc_call', 'metaWeblog.newMediaObject');
    … …  
    28652751                        return new IXR_Error(500, $upload_err);
    28662752
    2867                 if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) {
     2753                if ( !empty($data["overwrite"]) && ($data["overwrite"] == true) ) {
    28682754                        // Get postmeta info on the object.
    28692755                        $old_file = $wpdb->get_row("
    … …  
    29292815                $num_posts   = (int) $args[3];
    29302816
    2931                 if ( !$user = $this->login($username, $password) ) {
    2932                         return $this->error;
    2933                 }
     2817                if ( !$user = $this->login($username, $password) )
     2818                        return $this->error;
    29342819
    29352820                do_action('xmlrpc_call', 'mt.getRecentPostTitles');
    … …  
    29372822                $posts_list = wp_get_recent_posts($num_posts);
    29382823
    2939                 if (!$posts_list) {
     2824                if ( !$posts_list ) {
    29402825                        $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.'));
    29412826                        return $this->error;
    … …  
    29502835
    29512836                        // For drafts use the GMT version of the date
    2952                         if ( $entry['post_status'] == 'draft' ) {
     2837                        if ( $entry['post_status'] == 'draft' )
    29532838                                $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' );
    2954                         }
    29552839
    29562840                        $struct[] = array(
    … …  
    29652849
    29662850                $recent_posts = array();
    2967                 for ($j=0; $j<count($struct); $j++) {
     2851                for ( $j=0; $j<count($struct); $j++ ) {
    29682852                        array_push($recent_posts, $struct[$j]);
    29692853                }
    … …  
    29882872                $password   = $args[2];
    29892873
    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' ) )
    29952878                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) );
    29962879
    … …  
    30002883
    30012884                if ( $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0)) ) {
    3002                         foreach ($cats as $cat) {
     2885                        foreach ( $cats as $cat ) {
    30032886                                $struct['categoryId'] = $cat->term_id;
    30042887                                $struct['categoryName'] = $cat->name;
    … …  
    30272910                $password   = $args[2];
    30282911
    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 ) )
    30342916                        return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) );
    30352917
    … …  
    30402922                // first listed category will be the primary category
    30412923                $isPrimary = true;
    3042                 foreach($catids as $catid) {
     2924                foreach ( $catids as $catid ) {
    30432925                        $categories[] = array(
    30442926                                'categoryName' => get_cat_name($catid),
    … …  
    30692951                $categories  = $args[3];
    30702952
    3071                 if ( !$user = $this->login($username, $password) ) {
    3072                         return $this->error;
    3073                 }
     2953                if ( !$user = $this->login($username, $password) )
     2954                        return $this->error;
    30742955
    30752956                do_action('xmlrpc_call', 'mt.setPostCategories');
    … …  
    30782959                        return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
    30792960
    3080                 foreach($categories as $cat) {
     2961                foreach ( $categories as $cat ) {
    30812962                        $catids[] = $cat['categoryId'];
    30822963                }
    … …  
    31002981
    31012982                $supported_methods = array();
    3102                 foreach($this->methods as $key=>$value) {
     2983                foreach ( $this->methods as $key => $value ) {
    31032984                        $supported_methods[] = $key;
    31042985                }
    … …  
    31373018                $actual_post = wp_get_single_post($post_ID, ARRAY_A);
    31383019
    3139                 if (!$actual_post) {
     3020                if ( !$actual_post )
    31403021                        return new IXR_Error(404, __('Sorry, no such post.'));
    3141                 }
    31423022
    31433023                $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) );
    31443024
    3145                 if (!$comments) {
     3025                if ( !$comments )
    31463026                        return array();
    3147                 }
    31483027
    31493028                $trackback_pings = array();
    3150                 foreach($comments as $comment) {
     3029                foreach ( $comments as $comment ) {
    31513030                        if ( 'trackback' == $comment->comment_type ) {
    31523031                                $content = $comment->comment_content;
    … …  
    31573036                                        'pingIP'    => $comment->comment_author_IP
    31583037                                );
    3159                 }
     3038                        }
    31603039                }
    31613040
    … …  
    31793058                $password   = $args[2];
    31803059
    3181                 if ( !$user = $this->login($username, $password) ) {
    3182                         return $this->error;
    3183                 }
     3060                if ( !$user = $this->login($username, $password) )
     3061                        return $this->error;
    31843062
    31853063                do_action('xmlrpc_call', 'mt.publishPost');
    … …  
    32323110                // Check if the page linked to is in our site
    32333111                $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home')));
    3234                 if( !$pos1 )
     3112                if ( !$pos1 )
    32353113                        return new IXR_Error(0, __('Is there no link to us?'));
    32363114
    … …  
    32393117                //        if so, then let's use it and drop the old code.
    32403118                $urltest = parse_url($pagelinkedto);
    3241                 if ($post_ID = url_to_postid($pagelinkedto)) {
     3119                if ( $post_ID = url_to_postid($pagelinkedto) ) {
    32423120                        $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) ) {
    32443122                        // the path defines the post_ID (archives/p/XXXX)
    32453123                        $blah = explode('/', $match[0]);
    32463124                        $post_ID = (int) $blah[1];
    32473125                        $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) ) {
    32493127                        // the querystring defines the post_ID (?p=XXXX)
    32503128                        $blah = explode('=', $match[0]);
    32513129                        $post_ID = (int) $blah[1];
    32523130                        $way = 'from the querystring';
    3253                 } elseif (isset($urltest['fragment'])) {
     3131                } elseif ( isset($urltest['fragment']) ) {
    32543132                        // an #anchor is there, it's either...
    3255                         if (intval($urltest['fragment'])) {
     3133                        if ( intval($urltest['fragment']) ) {
    32563134                                // ...an integer #XXXX (simpliest case)
    32573135                                $post_ID = (int) $urltest['fragment'];
    32583136                                $way = 'from the fragment (numeric)';
    3259                         } elseif (preg_match('/post-[0-9]+/',$urltest['fragment'])) {
     3137                        } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) {
    32603138                                // ...a post id in the form 'post-###'
    32613139                                $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']);
    32623140                                $way = 'from the fragment (post-###)';
    3263                         } elseif (is_string($urltest['fragment'])) {
     3141                        } elseif ( is_string($urltest['fragment']) ) {
    32643142                                // ...or a string #title, a little more complicated
    32653143                                $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']);
    … …  
    33963274
    33973275                $post_ID = url_to_postid($url);
    3398                 if (!$post_ID) {
     3276                if ( !$post_ID ) {
    33993277                        // We aren't sure that the resource is available and/or pingback enabled
    34003278                        return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.'));
    … …  
    34033281                $actual_post = wp_get_single_post($post_ID, ARRAY_A);
    34043282
    3405                 if (!$actual_post) {
     3283                if ( !$actual_post ) {
    34063284                        // No such post = resource not found
    34073285                        return new IXR_Error(32, __('The specified target URL does not exist.'));
    … …  
    34103288                $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) );
    34113289
    3412                 if (!$comments) {
     3290                if ( !$comments )
    34133291                        return array();
    3414                 }
    34153292
    34163293                $pingbacks = array();
    3417                 foreach($comments as $comment) {
     3294                foreach ( $comments as $comment ) {
    34183295                        if ( 'pingback' == $comment->comment_type )
    34193296                                $pingbacks[] = $comment->comment_author_url;
Note: See TracChangeset for help on using the changeset viewer.