Ticket #7652: 7652-refresh.patch
| File 7652-refresh.patch, 9.7 KB (added by kurtpayne, 15 months ago) |
|---|
-
wp-includes/class-feed.php
92 92 } 93 93 } 94 94 } 95 96 define('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 */ 105 class 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
16 16 require_once('./wp-load.php'); 17 17 18 18 /** Atom Publishing Protocol Class */ 19 require_once(ABSPATH . WPINC . '/ atomlib.php');19 require_once(ABSPATH . WPINC . '/class-feed.php'); 20 20 21 21 /** Admin Image API for metadata updating */ 22 22 require_once(ABSPATH . '/wp-admin/includes/image.php'); … … 259 259 * @since 2.2.0 260 260 */ 261 261 function handle_request() { 262 global $always_authenticate;263 264 262 if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) ) 265 263 $path = $_SERVER['ORIG_PATH_INFO']; 266 264 else … … 295 293 // authenticate regardless of the operation and set the current 296 294 // user. each handler will decide if auth is required or not. 297 295 if ( !$this->authenticate() ) { 298 if ( $always_authenticate ) 299 $this->auth_required('Credentials required.'); 296 $this->auth_required('Credentials required.'); 300 297 } 301 298 302 299 array_shift($matches); … … 391 388 global $user_ID; 392 389 $this->get_accepted_content_type($this->atom_content_types); 393 390 394 $parser = new AtomParser(); 395 if ( !$parser->parse() ) 396 $this->client_error(); 391 $feed = $this->get_parser(); 392 $entry = $feed->get_item(0); 397 393 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()); 401 395 402 396 $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()); 407 399 } 408 400 409 401 $wp_cats = get_categories(array('hide_empty' => false)); … … 415 407 array_push($post_category, $cat->term_id); 416 408 } 417 409 418 $publish = ! ( isset( $entry->draft ) && 'yes' == trim( $entry->draft ));410 $publish = !$entry->get_draft_status(); 419 411 420 412 $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 421 413 … … 426 418 $post_status = ($publish) ? 'publish' : 'draft'; 427 419 $post_author = (int) $user_ID; 428 420 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'); 447 426 448 427 if ( isset( $_SERVER['HTTP_SLUG'] ) ) 449 428 $post_name = $_SERVER['HTTP_SLUG']; … … 506 485 // quick check and exit 507 486 $this->get_accepted_content_type($this->atom_content_types); 508 487 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); 514 490 515 log_app('Received UPDATED entry:', print_r($parsed,true));491 log_app('Received UPDATED entry:', $parsed->get_title()); 516 492 517 493 // check for not found 518 494 global $entry; … … 521 497 if ( !current_user_can('edit_post', $entry['ID']) ) 522 498 $this->auth_required(__('Sorry, you do not have the right to edit this post.')); 523 499 524 $publish = ! ( isset($parsed->draft) && 'yes' == trim($parsed->draft));500 $publish = !$parsed->get_draft_status(); 525 501 $post_status = ($publish) ? 'publish' : 'draft'; 526 502 527 503 extract($entry); 528 504 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 = $p ubtimes[0];534 $post_date_gmt = $p ubtimes[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'); 538 514 539 515 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt'); 540 516 $this->escape($postdata); … … 673 649 // quick check and exit 674 650 $this->get_accepted_content_type($this->atom_content_types); 675 651 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); 682 654 683 655 // check for not found 684 656 global $entry; … … 689 661 690 662 extract($entry); 691 663 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'); 697 668 698 669 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_modified', 'post_modified_gmt'); 699 670 $this->escape($postdata); … … 1248 1219 log_app('Status','400: Bad Request'); 1249 1220 header('Content-Type: text/plain'); 1250 1221 status_header('400'); 1222 echo $msg; 1251 1223 exit; 1252 1224 } 1253 1225 … … 1352 1324 log_app('Status','400: Client Error'); 1353 1325 header('Content-Type: text/plain'); 1354 1326 status_header('400'); 1327 echo $msg; 1355 1328 exit; 1356 1329 } 1357 1330 … … 1464 1437 * @return bool 1465 1438 */ 1466 1439 function authenticate() { 1440 global $always_authenticate; 1441 1467 1442 log_app("authenticate()",print_r($_ENV, true)); 1468 1443 1469 1444 // if using mod_rewrite/ENV hack … … 1490 1465 } 1491 1466 } 1492 1467 1468 // If we're forcing admin abilities 1469 if (!$always_authenticate) { 1470 wp_set_current_user(1); 1471 return true; 1472 } 1473 1493 1474 return false; 1494 1475 } 1495 1476 … … 1614 1595 } 1615 1596 } 1616 1597 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 } 1617 1619 } 1618 1620 1619 1621 /**
