Make WordPress Core

Ticket #7652: 7652.diff

File 7652.diff, 3.9 KB (added by rmccue, 14 years ago)

First pass at the APP create_post() conversion

  • wp-app.php

     
    1717
    1818/** Atom Publishing Protocol Class */
    1919require_once(ABSPATH . WPINC . '/atomlib.php');
     20require_once(ABSPATH . WPINC . '/class-simplepie.php');
    2021
    2122/** Admin Image API for metadata updating */
    2223require_once(ABSPATH . '/wp-admin/includes/image.php');
     
    3839 * @var int|bool
    3940 * @todo Should be an option somewhere
    4041 */
    41 $always_authenticate = 1;
     42$always_authenticate = 0;
    4243
    4344/**
    4445 * Writes logging info to a file.
     
    258259         * @since 2.2.0
    259260         */
    260261        function handle_request() {
    261                 global $always_authenticate;
    262 
    263262                if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) )
    264263                        $path = $_SERVER['ORIG_PATH_INFO'];
    265264                else
     
    294293                                        // authenticate regardless of the operation and set the current
    295294                                        // user. each handler will decide if auth is required or not.
    296295                                        if ( !$this->authenticate() ) {
    297                                                 if ( $always_authenticate )
    298                                                         $this->auth_required('Credentials required.');
     296                                                $this->auth_required('Credentials required.');
    299297                                        }
    300298
    301299                                        array_shift($matches);
     
    390388                global $user_ID;
    391389                $this->get_accepted_content_type($this->atom_content_types);
    392390
    393                 $parser = new AtomParser();
    394                 if ( !$parser->parse() )
    395                         $this->client_error();
     391                $data = file_get_contents('php://input');
     392                // SimplePie expects the feed element to be the top element
     393                if (strpos($data, '<feed') === false) {
     394                        $data = str_replace('<entry', '<feed xmlns="' . SIMPLEPIE_NAMESPACE_ATOM_10 . '"><entry', $data);
     395                        $data = str_replace('</entry>', '</entry></feed>', $data);
     396                }
     397                $feed = new SimplePie();
     398                $feed->set_raw_data($data);
     399                $feed->init();
     400                if ( $feed->error() )
     401                        $this->client_error($feed->error());
    396402
    397                 $entry = array_pop($parser->feed->entries);
     403                $entry = $feed->get_item(0);
    398404
    399                 log_app('Received entry:', print_r($entry,true));
     405                log_app('Received entry:', $entry->get_title());
    400406
    401407                $catnames = array();
    402                 foreach ( $entry->categories as $cat ) {
    403                         array_push($catnames, $cat["term"]);
     408                foreach ( (array) $entry->get_categories() as $category ) {
     409                        array_push($catnames, $category->get_term());
    404410                }
    405411
    406412                $wp_cats = get_categories(array('hide_empty' => false));
     
    412418                                array_push($post_category, $cat->term_id);
    413419                }
    414420
    415                 $publish = ! ( isset( $entry->draft ) && 'yes' == trim( $entry->draft ) );
     421                $publish = true;
     422                if (($control = $entry->get_item_tags($this->ATOMPUB_NS, 'control')) && !empty($control[0]['child'][$this->ATOMPUB_NS]['draft'][0]['data'])) {
     423                        $publish = ('no' == $control[0]['child'][$this->ATOMPUB_NS]['draft'][0]['data']);
     424                }
    416425
    417426                $cap = ($publish) ? 'publish_posts' : 'edit_posts';
    418427
     
    422431                $blog_ID = get_current_blog_id();
    423432                $post_status = ($publish) ? 'publish' : 'draft';
    424433                $post_author = (int) $user_ID;
    425                 $post_title = $entry->title[1];
    426                 $post_content = $entry->content[1];
    427                 $post_excerpt = $entry->summary[1];
    428                 $pubtimes = $this->get_publish_time($entry->published);
    429                 $post_date = $pubtimes[0];
    430                 $post_date_gmt = $pubtimes[1];
     434                $post_title = $entry->get_title();
     435                $post_content = $entry->get_content();
     436                $post_excerpt = $entry->get_description();
     437                $post_date = $entry->get_date('Y-m-d H:i:s');
     438                $post_date_gmt = gmdate('Y-m-d H:i:s', $entry->get_date('U'));
    431439
    432440                if ( isset( $_SERVER['HTTP_SLUG'] ) )
    433441                        $post_name = $_SERVER['HTTP_SLUG'];
     
    13361344                log_app('Status','400: Client Error');
    13371345                header('Content-Type: text/plain');
    13381346                status_header('400');
     1347                echo $msg;
    13391348                exit;
    13401349        }
    13411350
     
    14481457         * @return bool
    14491458         */
    14501459        function authenticate() {
     1460                global $always_authenticate;
     1461
    14511462                log_app("authenticate()",print_r($_ENV, true));
    14521463
    14531464                // if using mod_rewrite/ENV hack
     
    14741485                        }
    14751486                }
    14761487
     1488                // If we're forcing admin abilities
     1489                if (!$always_authenticate) {
     1490                        wp_set_current_user(1);
     1491                        return true;
     1492                }
     1493
    14771494                return false;
    14781495        }
    14791496