Ticket #7652: 7652-refresh.patch

File 7652-refresh.patch, 9.7 KB (added by kurtpayne, 15 months ago)

Refreshed for 3.4

  • wp-includes/class-feed.php

     
    9292                } 
    9393        } 
    9494} 
     95 
     96define('SIMPLEPIE_NAMESPACE_ATOMPUB', 'http://www.w3.org/2007/app'); 
     97 
     98/** 
     99 * SimplePie Helper for AtomPub 
     100 * 
     101 * @package WordPress 
     102 * @subpackage Publishing 
     103 * @since 3.1 
     104 */ 
     105class WP_SimplePieAtomPub_Item extends SimplePie_Item { 
     106        /** 
     107         * Constructor 
     108         */ 
     109        function WP_SimplePieAtomPub_Item($feed, $data) { 
     110                parent::SimplePie_Item($feed, $data); 
     111        } 
     112 
     113        /** 
     114         * Get the status of the entry 
     115         * 
     116         * @return bool True if the item is a draft, false otherwise 
     117         */ 
     118        function get_draft_status() { 
     119                $draft = false; 
     120                if (($control = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOMPUB, 'control')) && !empty($control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data'])) { 
     121                        $draft = ('yes' == $control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data']); 
     122                } 
     123                return $draft; 
     124        } 
     125 
     126        /** 
     127         * Get the GMT timestamp of the entry 
     128         * 
     129         * @param string $format date() format 
     130         * @return int|string|null 
     131         */ 
     132        function get_gmdate($format = 'j F Y, g:i a') { 
     133                return gmdate($format, $this->get_date('U')); 
     134        } 
     135 
     136        /** 
     137         * Get the updated timestamp of the entry 
     138         * 
     139         * AtomPub needs the distinction between "created" and "updated". 
     140         * @param string $format date() format 
     141         * @return string|int|null 
     142         */ 
     143        function get_updated($format = 'j F Y, g:i a') { 
     144                if ($updated = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) { 
     145                        $return = date('Y-m-d H:i:s', $updated[0]['data']); 
     146                } 
     147                else { 
     148                        return null; 
     149                } 
     150 
     151                if ($return) { 
     152                        $parser = SimplePie_Parse_Date::get(); 
     153                        $parsed = $parser->parse($return); 
     154                        $date_format = (string) $date_format; 
     155                        switch ($date_format) { 
     156                                case '': 
     157                                        return $this->sanitize($return, SIMPLEPIE_CONSTRUCT_TEXT); 
     158 
     159                                case 'U': 
     160                                        return $parsed; 
     161 
     162                                default: 
     163                                        return date($date_format, $parsed); 
     164                        } 
     165                } 
     166                else { 
     167                        return null; 
     168                } 
     169        } 
     170 
     171        /** 
     172         * Get the updated GMT timestamp of the entry 
     173         * 
     174         * @param string $format date() format 
     175         * @return int|string|null 
     176         */ 
     177        function get_gmupdated($format = 'j F Y, g:i a') { 
     178                return gmdate($format, $this->get_updated('U')); 
     179        } 
     180} 
  • wp-app.php

     
    1616require_once('./wp-load.php'); 
    1717 
    1818/** Atom Publishing Protocol Class */ 
    19 require_once(ABSPATH . WPINC . '/atomlib.php'); 
     19require_once(ABSPATH . WPINC . '/class-feed.php'); 
    2020 
    2121/** Admin Image API for metadata updating */ 
    2222require_once(ABSPATH . '/wp-admin/includes/image.php'); 
     
    259259         * @since 2.2.0 
    260260         */ 
    261261        function handle_request() { 
    262                 global $always_authenticate; 
    263  
    264262                if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) ) 
    265263                        $path = $_SERVER['ORIG_PATH_INFO']; 
    266264                else 
     
    295293                                        // authenticate regardless of the operation and set the current 
    296294                                        // user. each handler will decide if auth is required or not. 
    297295                                        if ( !$this->authenticate() ) { 
    298                                                 if ( $always_authenticate ) 
    299                                                         $this->auth_required('Credentials required.'); 
     296                                                $this->auth_required('Credentials required.'); 
    300297                                        } 
    301298 
    302299                                        array_shift($matches); 
     
    391388                global $user_ID; 
    392389                $this->get_accepted_content_type($this->atom_content_types); 
    393390 
    394                 $parser = new AtomParser(); 
    395                 if ( !$parser->parse() ) 
    396                         $this->client_error(); 
     391                $feed = $this->get_parser(); 
     392                $entry = $feed->get_item(0); 
    397393 
    398                 $entry = array_pop($parser->feed->entries); 
    399  
    400                 log_app('Received entry:', print_r($entry,true)); 
     394                log_app('Received entry:', $entry->get_title()); 
    401395 
    402396                $catnames = array(); 
    403                 if ( !empty( $entry->categories ) ) { 
    404                         foreach ( $entry->categories as $cat ) { 
    405                                 array_push($catnames, $cat["term"]); 
    406                         } 
     397                foreach ( (array) $entry->get_categories() as $category ) { 
     398                        array_push($catnames, $category->get_term()); 
    407399                } 
    408400 
    409401                $wp_cats = get_categories(array('hide_empty' => false)); 
     
    415407                                array_push($post_category, $cat->term_id); 
    416408                } 
    417409 
    418                 $publish = ! ( isset( $entry->draft ) && 'yes' == trim( $entry->draft ) ); 
     410                $publish = !$entry->get_draft_status(); 
    419411 
    420412                $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 
    421413 
     
    426418                $post_status = ($publish) ? 'publish' : 'draft'; 
    427419                $post_author = (int) $user_ID; 
    428420 
    429                 $post_title   = ''; 
    430                 $post_content = ''; 
    431                 $post_excerpt = ''; 
    432                 $pubtimes     = ''; 
    433                  
    434                 if ( isset( $entry->title ) && is_array( $entry->title ) && !empty( $entry->title[1] ) ) 
    435                         $post_title = (string) $entry->title[1]; 
    436                 if ( isset( $entry->content ) && is_array( $entry->content ) && !empty( $entry->content[1] ) ) 
    437                         $post_content = (string) $entry->content[1]; 
    438                 if ( isset( $entry->summary ) && is_array( $entry->summary ) && !empty( $entry->summary[1] ) ) 
    439                         $post_excerpt = (string) $entry->summary[1]; 
    440                 if ( !empty( $entry->published ) ) 
    441                         $pubtimes = (string) $entry->published; 
    442                  
    443                 $pubtimes = $this->get_publish_time( $pubtimes ); 
    444  
    445                 $post_date = $pubtimes[0]; 
    446                 $post_date_gmt = $pubtimes[1]; 
     421                $post_title = $entry->get_title(); 
     422                $post_content = $entry->get_content(); 
     423                $post_excerpt = $entry->get_description(); 
     424                $post_date = $entry->get_date('Y-m-d H:i:s'); 
     425                $post_date_gmt = $entry->get_gmdate('Y-m-d H:i:s'); 
    447426 
    448427                if ( isset( $_SERVER['HTTP_SLUG'] ) ) 
    449428                        $post_name = $_SERVER['HTTP_SLUG']; 
     
    506485                // quick check and exit 
    507486                $this->get_accepted_content_type($this->atom_content_types); 
    508487 
    509                 $parser = new AtomParser(); 
    510                 if ( !$parser->parse() ) 
    511                         $this->bad_request(); 
    512  
    513                 $parsed = array_pop($parser->feed->entries); 
     488                $feed = $this->get_parser(); 
     489                $parsed = $feed->get_item(0); 
    514490 
    515                 log_app('Received UPDATED entry:', print_r($parsed,true)); 
     491                log_app('Received UPDATED entry:', $parsed->get_title()); 
    516492 
    517493                // check for not found 
    518494                global $entry; 
     
    521497                if ( !current_user_can('edit_post', $entry['ID']) ) 
    522498                        $this->auth_required(__('Sorry, you do not have the right to edit this post.')); 
    523499 
    524                 $publish = ! ( isset($parsed->draft) && 'yes' == trim($parsed->draft) ); 
     500                $publish = !$parsed->get_draft_status(); 
    525501                $post_status = ($publish) ? 'publish' : 'draft'; 
    526502 
    527503                extract($entry); 
    528504 
    529                 $post_title = $parsed->title[1]; 
    530                 $post_content = $parsed->content[1]; 
    531                 $post_excerpt = $parsed->summary[1]; 
    532                 $pubtimes = $this->get_publish_time($entry->published); 
    533                 $post_date = $pubtimes[0]; 
    534                 $post_date_gmt = $pubtimes[1]; 
    535                 $pubtimes = $this->get_publish_time($parsed->updated); 
    536                 $post_modified = $pubtimes[0]; 
    537                 $post_modified_gmt = $pubtimes[1]; 
     505                $post_title = $parsed->get_title(); 
     506                $post_content = $parsed->get_content(); 
     507                $post_excerpt = $parsed->get_description(); 
     508 
     509                $post_date = $parsed->get_date('Y-m-d H:i:s'); 
     510                $post_date_gmt = $parsed->get_gmdate('Y-m-d H:i:s'); 
     511 
     512                $post_modified =  $parsed->get_updated('Y-m-d H:i:s'); 
     513                $post_modified_gmt =  $parsed->get_gmupdated('Y-m-d H:i:s'); 
    538514 
    539515                $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt'); 
    540516                $this->escape($postdata); 
     
    673649                // quick check and exit 
    674650                $this->get_accepted_content_type($this->atom_content_types); 
    675651 
    676                 $parser = new AtomParser(); 
    677                 if (!$parser->parse()) { 
    678                         $this->bad_request(); 
    679                 } 
    680  
    681                 $parsed = array_pop($parser->feed->entries); 
     652                $feed = $this->get_parser(); 
     653                $parsed = $feed->get_item(0); 
    682654 
    683655                // check for not found 
    684656                global $entry; 
     
    689661 
    690662                extract($entry); 
    691663 
    692                 $post_title = $parsed->title[1]; 
    693                 $post_content = $parsed->summary[1]; 
    694                 $pubtimes = $this->get_publish_time($parsed->updated); 
    695                 $post_modified = $pubtimes[0]; 
    696                 $post_modified_gmt = $pubtimes[1]; 
     664                $post_title = $parsed->get_title(); 
     665                $post_content = $parsed->get_description(); 
     666                $post_modified = $parsed->get_date('Y-m-d H:i:s'); 
     667                $post_modified_gmt = $parsed->get_gmdate('Y-m-d H:i:s'); 
    697668 
    698669                $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_modified', 'post_modified_gmt'); 
    699670                $this->escape($postdata); 
     
    12481219                log_app('Status','400: Bad Request'); 
    12491220                header('Content-Type: text/plain'); 
    12501221                status_header('400'); 
     1222                echo $msg; 
    12511223                exit; 
    12521224        } 
    12531225 
     
    13521324                log_app('Status','400: Client Error'); 
    13531325                header('Content-Type: text/plain'); 
    13541326                status_header('400'); 
     1327                echo $msg; 
    13551328                exit; 
    13561329        } 
    13571330 
     
    14641437         * @return bool 
    14651438         */ 
    14661439        function authenticate() { 
     1440                global $always_authenticate; 
     1441 
    14671442                log_app("authenticate()",print_r($_ENV, true)); 
    14681443 
    14691444                // if using mod_rewrite/ENV hack 
     
    14901465                        } 
    14911466                } 
    14921467 
     1468                // If we're forcing admin abilities 
     1469                if (!$always_authenticate) { 
     1470                        wp_set_current_user(1); 
     1471                        return true; 
     1472                } 
     1473 
    14931474                return false; 
    14941475        } 
    14951476 
     
    16141595                } 
    16151596        } 
    16161597 
     1598        /** 
     1599         * Create a SimplePie parser with POST data 
     1600         * 
     1601         * @return SimplePie 
     1602         */ 
     1603        function &get_parser() { 
     1604                $data = file_get_contents('php://input'); 
     1605                // SimplePie expects the feed element to be the top element 
     1606                // This could probably be improved 
     1607                if (strpos($data, '<feed') === false) { 
     1608                        $data = str_replace('<entry', '<feed xmlns="' . SIMPLEPIE_NAMESPACE_ATOM_10 . '"><entry', $data); 
     1609                        $data = str_replace('</entry>', '</entry></feed>', $data); 
     1610                } 
     1611                $feed = new SimplePie(); 
     1612                $feed->set_item_class('WP_SimplePieAtomPub_Item'); 
     1613                $feed->set_raw_data($data); 
     1614                $feed->init(); 
     1615                if ( $feed->error() ) 
     1616                        $this->bad_request($feed->error()); 
     1617                return $feed; 
     1618        } 
    16171619} 
    16181620 
    16191621/**