Make WordPress Core

Changeset 6726 for trunk/xmlrpc.php


Ignore:
Timestamp:
02/05/2008 06:47:27 AM (19 years ago)
Author:
ryan
Message:

Trailing whitespace cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r6714 r6726  
    3232      <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
    3333      <api name="Blogger" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
    34       <api name="Atom" blogID="" preferred="false" apiLink="<?php echo apply_filters('atom_service_url', (get_bloginfo('url')."/wp-app.php/service"))?>" /> 
     34      <api name="Atom" blogID="" preferred="false" apiLink="<?php echo apply_filters('atom_service_url', (get_bloginfo('url')."/wp-app.php/service"))?>" />
    3535    </apis>
    3636  </service>
     
    175175        }
    176176
    177         function get_custom_fields($post_id) { 
    178                 $post_id = (int) $post_id; 
    179 
    180                 $custom_fields = array(); 
    181 
    182                 foreach ( (array) has_meta($post_id) as $meta ) { 
    183                         // Don't expose protected fields. 
    184                         if ( strpos($meta['meta_key'], '_wp_') === 0 ) { 
    185                                 continue; 
    186                         } 
    187 
    188                         $custom_fields[] = array( 
    189                                 "id"    => $meta['meta_id'], 
    190                                 "key"   => $meta['meta_key'], 
    191                                 "value" => $meta['meta_value'] 
    192                         ); 
    193                 } 
    194 
    195                 return $custom_fields; 
    196         } 
    197 
    198         function set_custom_fields($post_id, $fields) { 
    199                 $post_id = (int) $post_id; 
    200 
    201                 foreach ( (array) $fields as $meta ) { 
    202                         if ( isset($meta['id']) ) { 
    203                                 $meta['id'] = (int) $meta['id']; 
    204 
    205                                 if ( isset($meta['key']) ) { 
    206                                         update_meta($meta['id'], $meta['key'], $meta['value']); 
    207                                 } 
    208                                 else { 
    209                                         delete_meta($meta['id']); 
    210                                 } 
    211                         } 
    212                         else { 
    213                                 $_POST['metakeyinput'] = $meta['key']; 
    214                                 $_POST['metavalue'] = $meta['value']; 
    215                                 add_meta($post_id); 
    216                         } 
    217                 } 
    218         } 
     177        function get_custom_fields($post_id) {
     178                $post_id = (int) $post_id;
     179
     180                $custom_fields = array();
     181
     182                foreach ( (array) has_meta($post_id) as $meta ) {
     183                        // Don't expose protected fields.
     184                        if ( strpos($meta['meta_key'], '_wp_') === 0 ) {
     185                                continue;
     186                        }
     187
     188                        $custom_fields[] = array(
     189                                "id"    => $meta['meta_id'],
     190                                "key"   => $meta['meta_key'],
     191                                "value" => $meta['meta_value']
     192                        );
     193                }
     194
     195                return $custom_fields;
     196        }
     197
     198        function set_custom_fields($post_id, $fields) {
     199                $post_id = (int) $post_id;
     200
     201                foreach ( (array) $fields as $meta ) {
     202                        if ( isset($meta['id']) ) {
     203                                $meta['id'] = (int) $meta['id'];
     204
     205                                if ( isset($meta['key']) ) {
     206                                        update_meta($meta['id'], $meta['key'], $meta['value']);
     207                                }
     208                                else {
     209                                        delete_meta($meta['id']);
     210                                }
     211                        }
     212                        else {
     213                                $_POST['metakeyinput'] = $meta['key'];
     214                                $_POST['metavalue'] = $meta['value'];
     215                                add_meta($post_id);
     216                        }
     217                }
     218        }
    219219
    220220        /**
     
    662662
    663663                set_current_user(0, $username);
    664                 if( !current_user_can( 'edit_posts' ) ) 
     664                if( !current_user_can( 'edit_posts' ) )
    665665                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this blog in order to view categories.' ) );
    666666
     
    680680
    681681        function wp_getCommentCount( $args ) {
    682                 $this->escape($args); 
    683 
    684                 $blog_id        = (int) $args[0]; 
    685                 $username       = $args[1]; 
    686                 $password       = $args[2]; 
    687                 $post_id        = (int) $args[3]; 
    688 
    689                 if( !$this->login_pass_ok( $username, $password ) ) { 
    690                         return new IXR_Error( 403, __( 'Bad login/pass combination.' ) ); 
    691                 } 
    692 
    693                 set_current_user( 0, $username ); 
    694                 if( !current_user_can( 'edit_posts' ) ) { 
    695                         return new IXR_Error( 403, __( 'You are not allowed details about comments.' ) ); 
    696                 } 
     682                $this->escape($args);
     683
     684                $blog_id        = (int) $args[0];
     685                $username       = $args[1];
     686                $password       = $args[2];
     687                $post_id        = (int) $args[3];
     688
     689                if( !$this->login_pass_ok( $username, $password ) ) {
     690                        return new IXR_Error( 403, __( 'Bad login/pass combination.' ) );
     691                }
     692
     693                set_current_user( 0, $username );
     694                if( !current_user_can( 'edit_posts' ) ) {
     695                        return new IXR_Error( 403, __( 'You are not allowed details about comments.' ) );
     696                }
    697697
    698698                do_action('xmlrpc_call', 'wp.getCommentCount');
     
    792792
    793793                set_current_user( 0, $user_login );
    794                 if( !current_user_can( 'edit_posts' ) ) 
     794                if( !current_user_can( 'edit_posts' ) )
    795795                        return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this blog.' ) );
    796796
     
    825825
    826826                set_current_user( 0, $user_login );
    827                 if( !current_user_can( 'edit_post', $post_ID ) ) 
     827                if( !current_user_can( 'edit_post', $post_ID ) )
    828828                        return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) );
    829829
     
    986986                $content    = $args[4];
    987987                $publish    = $args[5];
    988                
     988
    989989                if (!$this->login_pass_ok($user_login, $user_pass)) {
    990990                        return $this->error;
     
    997997                if ( !current_user_can($cap) )
    998998                        return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.'));
    999                
     999
    10001000                $post_status = ($publish) ? 'publish' : 'draft';
    1001                
     1001
    10021002                $post_author = $user->ID;
    1003                
     1003
    10041004                $post_title = xmlrpc_getposttitle($content);
    10051005                $post_category = xmlrpc_getpostcategory($content);
    10061006                $post_content = xmlrpc_removepostdata($content);
    1007                
     1007
    10081008                $post_date = current_time('mysql');
    10091009                $post_date_gmt = current_time('mysql', 1);
    1010                
     1010
    10111011                $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
    1012                
     1012
    10131013                $post_ID = wp_insert_post($post_data);
    10141014                if ( is_wp_error( $post_ID ) )
     
    10291029
    10301030                $this->escape($args);
    1031                
     1031
    10321032                $post_ID     = (int) $args[1];
    10331033                $user_login  = $args[2];
     
    10351035                $content     = $args[4];
    10361036                $publish     = $args[5];
    1037                
     1037
    10381038                if (!$this->login_pass_ok($user_login, $user_pass)) {
    10391039                        return $this->error;
     
    10431043
    10441044                $actual_post = wp_get_single_post($post_ID,ARRAY_A);
    1045                
     1045
    10461046                if (!$actual_post) {
    10471047                        return new IXR_Error(404, __('Sorry, no such post.'));
    10481048                }
    1049                
     1049
    10501050                $this->escape($actual_post);
    1051                
     1051
    10521052                set_current_user(0, $user_login);
    10531053                if ( !current_user_can('edit_post', $post_ID) )
    10541054                        return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.'));
    1055                
     1055
    10561056                extract($actual_post, EXTR_SKIP);
    1057                
     1057
    10581058                if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
    10591059                        return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
    1060                
     1060
    10611061                $post_title = xmlrpc_getposttitle($content);
    10621062                $post_category = xmlrpc_getpostcategory($content);
    10631063                $post_content = xmlrpc_removepostdata($content);
    1064                
     1064
    10651065                $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');
    1066                
     1066
    10671067                $result = wp_update_post($postdata);
    1068                
     1068
    10691069                if (!$result) {
    10701070                        return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.'));
    10711071                }
    10721072                $this->attach_uploads( $ID, $post_content );
    1073                
     1073
    10741074                return true;
    10751075        }
     
    10791079        function blogger_deletePost($args) {
    10801080                $this->escape($args);
    1081                
     1081
    10821082                $post_ID     = (int) $args[1];
    10831083                $user_login  = $args[2];
    10841084                $user_pass   = $args[3];
    10851085                $publish     = $args[4];
    1086                
     1086
    10871087                if (!$this->login_pass_ok($user_login, $user_pass)) {
    10881088                        return $this->error;
     
    10921092
    10931093                $actual_post = wp_get_single_post($post_ID,ARRAY_A);
    1094                
     1094
    10951095                if (!$actual_post) {
    10961096                        return new IXR_Error(404, __('Sorry, no such post.'));
    10971097                }
    1098                
     1098
    10991099                set_current_user(0, $user_login);
    11001100                if ( !current_user_can('edit_post', $post_ID) )
    11011101                        return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.'));
    1102                
     1102
    11031103                $result = wp_delete_post($post_ID);
    1104                
     1104
    11051105                if (!$result) {
    11061106                        return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.'));
    11071107                }
    1108                
     1108
    11091109                return true;
    11101110        }
     
    11251125                $content_struct = $args[3];
    11261126                $publish     = $args[4];
    1127                
     1127
    11281128                if (!$this->login_pass_ok($user_login, $user_pass)) {
    11291129                        return $this->error;
     
    12251225                        }
    12261226                }
    1227                
     1227
    12281228                $post_excerpt = $content_struct['mt_excerpt'];
    12291229                $post_more = $content_struct['mt_text_more'];
     
    12991299                        $post_content = $post_content . "\n<!--more-->\n" . $post_more;
    13001300                }
    1301                
     1301
    13021302                $to_ping = $content_struct['mt_tb_ping_urls'];
    13031303                if ( is_array($to_ping) )
     
    13211321                logIO('O', 'Post cats: ' . var_export($catnames,true));
    13221322                $post_category = array();
    1323                
     1323
    13241324                if (is_array($catnames)) {
    13251325                        foreach ($catnames as $cat) {
     
    13301330                // We've got all the data -- post it:
    13311331                $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input');
    1332                
     1332
    13331333                $post_ID = wp_insert_post($postdata);
    13341334                if ( is_wp_error( $post_ID ) )
    13351335                        return new IXR_Error(500, $post_ID->get_error_message());
    1336                
     1336
    13371337                if (!$post_ID) {
    13381338                        return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
    13391339                }
    13401340
    1341                 if ( isset($content_struct['custom_fields']) ) { 
    1342                         $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 
    1343                 } 
    1344                
     1341                if ( isset($content_struct['custom_fields']) ) {
     1342                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
     1343                }
     1344
    13451345                $this->attach_uploads( $post_ID, $post_content );
    1346                
     1346
    13471347                logIO('O', "Posted ! ID: $post_ID");
    1348                
     1348
    13491349                return strval($post_ID);
    13501350        }
     
    13741374                $content_struct = $args[3];
    13751375                $publish     = $args[4];
    1376                
     1376
    13771377                if (!$this->login_pass_ok($user_login, $user_pass)) {
    13781378                        return $this->error;
     
    15241524                $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
    15251525                $catnames = $content_struct['categories'];
    1526                
     1526
    15271527                $post_category = array();
    1528                
     1528
    15291529                if (is_array($catnames)) {
    15301530                        foreach ($catnames as $cat) {
     
    15321532                        }
    15331533                }
    1534                
     1534
    15351535                $post_excerpt = $content_struct['mt_excerpt'];
    15361536                $post_more = $content_struct['mt_text_more'];
     
    15551555                        }
    15561556                }
    1557                
     1557
    15581558                $tags_input = $content_struct['mt_keywords'];
    15591559
     
    15641564                                return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
    15651565                }
    1566                
     1566
    15671567                if ($post_more) {
    15681568                        $post_content = $post_content . "\n<!--more-->\n" . $post_more;
     
    15891589                // We've got all the data -- post it:
    15901590                $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input');
    1591                
     1591
    15921592                $result = wp_update_post($newpost);
    15931593                if (!$result) {
     
    15951595                }
    15961596
    1597                 if ( isset($content_struct['custom_fields']) ) { 
    1598                         $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 
    1599                 } 
     1597                if ( isset($content_struct['custom_fields']) ) {
     1598                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
     1599                }
    16001600
    16011601                $this->attach_uploads( $ID, $post_content );
    1602                
     1602
    16031603                logIO('O',"(MW) Edited ! ID: $post_ID");
    1604                
     1604
    16051605                return true;
    16061606        }
     
    16111611
    16121612                $this->escape($args);
    1613                
     1613
    16141614                $post_ID     = (int) $args[0];
    16151615                $user_login  = $args[1];
    16161616                $user_pass   = $args[2];
    1617                
     1617
    16181618                if (!$this->login_pass_ok($user_login, $user_pass)) {
    16191619                        return $this->error;
     
    16271627
    16281628                $postdata = wp_get_single_post($post_ID, ARRAY_A);
    1629                
     1629
    16301630                if ($postdata['post_date'] != '') {
    16311631                        $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']);
    16321632                        $post_date_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_date_gmt']);
    1633                
     1633
    16341634                        $categories = array();
    16351635                        $catids = wp_get_post_categories($post_ID);
    16361636                        foreach($catids as $catid)
    16371637                                $categories[] = get_cat_name($catid);
    1638                        
     1638
    16391639                        $tagnames = array();
    16401640                        $tags = wp_get_post_tags( $post_ID );
     
    16461646                                $tagnames = '';
    16471647                        }
    1648                        
     1648
    16491649                        $post = get_extended($postdata['post_content']);
    16501650                        $link = post_permalink($postdata['ID']);
    1651                        
     1651
    16521652                        // Get the author info.
    16531653                        $author = get_userdata($postdata['post_author']);
    1654                        
     1654
    16551655                        $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
    16561656                        $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
     
    16601660                                $postdata['post_status'] = 'publish';
    16611661                        }
    1662                        
     1662
    16631663                        $resp = array(
    16641664                                'dateCreated' => new IXR_Date($post_date),
     
    16851685                                'custom_fields' => $this->get_custom_fields($post_ID)
    16861686                        );
    1687                        
     1687
    16881688                        return $resp;
    16891689                } else {
     
    19371937
    19381938                foreach ($posts_list as $entry) {
    1939                         if( !current_user_can( 'edit_post', $entry['ID'] ) ) 
     1939                        if( !current_user_can( 'edit_post', $entry['ID'] ) )
    19401940                                continue;
    19411941
Note: See TracChangeset for help on using the changeset viewer.