Ticket #7652: 7652-separate.diff
File 7652-separate.diff, 9.2 KB (added by , 14 years ago) |
---|
-
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'); … … 258 258 * @since 2.2.0 259 259 */ 260 260 function handle_request() { 261 global $always_authenticate;262 263 261 if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) ) 264 262 $path = $_SERVER['ORIG_PATH_INFO']; 265 263 else … … 294 292 // authenticate regardless of the operation and set the current 295 293 // user. each handler will decide if auth is required or not. 296 294 if ( !$this->authenticate() ) { 297 if ( $always_authenticate ) 298 $this->auth_required('Credentials required.'); 295 $this->auth_required('Credentials required.'); 299 296 } 300 297 301 298 array_shift($matches); … … 390 387 global $user_ID; 391 388 $this->get_accepted_content_type($this->atom_content_types); 392 389 393 $parser = new AtomParser(); 394 if ( !$parser->parse() ) 395 $this->client_error(); 390 $feed = $this->get_parser(); 391 $entry = $feed->get_item(0); 396 392 397 $entry = array_pop($parser->feed->entries);393 log_app('Received entry:', $entry->get_title()); 398 394 399 log_app('Received entry:', print_r($entry,true));400 401 395 $catnames = array(); 402 foreach ( $entry->categories as $cat) {403 array_push($catnames, $cat ["term"]);396 foreach ( (array) $entry->get_categories() as $category ) { 397 array_push($catnames, $category->get_term()); 404 398 } 405 399 406 400 $wp_cats = get_categories(array('hide_empty' => false)); … … 412 406 array_push($post_category, $cat->term_id); 413 407 } 414 408 415 $publish = ! ( isset( $entry->draft ) && 'yes' == trim( $entry->draft ));409 $publish = !$entry->get_draft_status(); 416 410 417 411 $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 418 412 … … 422 416 $blog_ID = get_current_blog_id(); 423 417 $post_status = ($publish) ? 'publish' : 'draft'; 424 418 $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]; 419 $post_title = $entry->get_title(); 420 $post_content = $entry->get_content(); 421 $post_excerpt = $entry->get_description(); 422 $post_date = $entry->get_date('Y-m-d H:i:s'); 423 $post_date_gmt = $entry->get_gmdate('Y-m-d H:i:s'); 431 424 432 425 if ( isset( $_SERVER['HTTP_SLUG'] ) ) 433 426 $post_name = $_SERVER['HTTP_SLUG']; … … 490 483 // quick check and exit 491 484 $this->get_accepted_content_type($this->atom_content_types); 492 485 493 $parser = new AtomParser(); 494 if ( !$parser->parse() ) 495 $this->bad_request(); 486 $feed = $this->get_parser(); 487 $parsed = $feed->get_item(0); 496 488 497 $parsed = array_pop($parser->feed->entries);489 log_app('Received UPDATED entry:', $parsed->get_title()); 498 490 499 log_app('Received UPDATED entry:', print_r($parsed,true));500 501 491 // check for not found 502 492 global $entry; 503 493 $this->set_current_entry($postID); … … 505 495 if ( !current_user_can('edit_post', $entry['ID']) ) 506 496 $this->auth_required(__('Sorry, you do not have the right to edit this post.')); 507 497 508 $publish = ! ( isset($parsed->draft) && 'yes' == trim($parsed->draft));498 $publish = !$parsed->get_draft_status(); 509 499 $post_status = ($publish) ? 'publish' : 'draft'; 510 500 511 501 extract($entry); 512 502 513 $post_title = $parsed->title[1]; 514 $post_content = $parsed->content[1]; 515 $post_excerpt = $parsed->summary[1]; 516 $pubtimes = $this->get_publish_time($entry->published); 517 $post_date = $pubtimes[0]; 518 $post_date_gmt = $pubtimes[1]; 519 $pubtimes = $this->get_publish_time($parsed->updated); 520 $post_modified = $pubtimes[0]; 521 $post_modified_gmt = $pubtimes[1]; 503 $post_title = $parsed->get_title(); 504 $post_content = $parsed->get_content(); 505 $post_excerpt = $parsed->get_description(); 522 506 507 $post_date = $parsed->get_date('Y-m-d H:i:s'); 508 $post_date_gmt = $parsed->get_gmdate('Y-m-d H:i:s'); 509 510 $post_modified = $parsed->get_updated('Y-m-d H:i:s'); 511 $post_modified_gmt = $parsed->get_gmupdated('Y-m-d H:i:s'); 512 523 513 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt'); 524 514 $this->escape($postdata); 525 515 … … 657 647 // quick check and exit 658 648 $this->get_accepted_content_type($this->atom_content_types); 659 649 660 $parser = new AtomParser(); 661 if (!$parser->parse()) { 662 $this->bad_request(); 663 } 650 $feed = $this->get_parser(); 651 $parsed = $feed->get_item(0); 664 652 665 $parsed = array_pop($parser->feed->entries);666 667 653 // check for not found 668 654 global $entry; 669 655 $this->set_current_entry($postID); … … 673 659 674 660 extract($entry); 675 661 676 $post_title = $parsed->title[1]; 677 $post_content = $parsed->summary[1]; 678 $pubtimes = $this->get_publish_time($parsed->updated); 679 $post_modified = $pubtimes[0]; 680 $post_modified_gmt = $pubtimes[1]; 662 $post_title = $parsed->get_title(); 663 $post_content = $parsed->get_description(); 664 $post_modified = $parsed->get_date('Y-m-d H:i:s'); 665 $post_modified_gmt = $parsed->get_gmdate('Y-m-d H:i:s'); 681 666 682 667 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_modified', 'post_modified_gmt'); 683 668 $this->escape($postdata); … … 1232 1217 log_app('Status','400: Bad Request'); 1233 1218 header('Content-Type: text/plain'); 1234 1219 status_header('400'); 1220 echo $msg; 1235 1221 exit; 1236 1222 } 1237 1223 … … 1336 1322 log_app('Status','400: Client Error'); 1337 1323 header('Content-Type: text/plain'); 1338 1324 status_header('400'); 1325 echo $msg; 1339 1326 exit; 1340 1327 } 1341 1328 … … 1448 1435 * @return bool 1449 1436 */ 1450 1437 function authenticate() { 1438 global $always_authenticate; 1439 1451 1440 log_app("authenticate()",print_r($_ENV, true)); 1452 1441 1453 1442 // if using mod_rewrite/ENV hack … … 1474 1463 } 1475 1464 } 1476 1465 1466 // If we're forcing admin abilities 1467 if (!$always_authenticate) { 1468 wp_set_current_user(1); 1469 return true; 1470 } 1471 1477 1472 return false; 1478 1473 } 1479 1474 … … 1598 1593 } 1599 1594 } 1600 1595 1596 /** 1597 * Create a SimplePie parser with POST data 1598 * 1599 * @return SimplePie 1600 */ 1601 function &get_parser() { 1602 $data = file_get_contents('php://input'); 1603 // SimplePie expects the feed element to be the top element 1604 // This could probably be improved 1605 if (strpos($data, '<feed') === false) { 1606 $data = str_replace('<entry', '<feed xmlns="' . SIMPLEPIE_NAMESPACE_ATOM_10 . '"><entry', $data); 1607 $data = str_replace('</entry>', '</entry></feed>', $data); 1608 } 1609 $feed = new SimplePie(); 1610 $feed->set_item_class('WP_SimplePieAtomPub_Item'); 1611 $feed->set_raw_data($data); 1612 $feed->init(); 1613 if ( $feed->error() ) 1614 $this->bad_request($feed->error()); 1615 return $feed; 1616 } 1601 1617 } 1602 1618 1603 1619 /** -
wp-includes/class-feed.php
100 100 } 101 101 } 102 102 } 103 } 104 105 define('SIMPLEPIE_NAMESPACE_ATOMPUB', 'http://www.w3.org/2007/app'); 106 107 /** 108 * SimplePie Helper for AtomPub 109 * 110 * @package WordPress 111 * @subpackage Publishing 112 * @since 3.1 113 */ 114 class WP_SimplePieAtomPub_Item extends SimplePie_Item { 115 /** 116 * Constructor 117 */ 118 function WP_SimplePieAtomPub_Item($feed, $data) { 119 parent::SimplePie_Item($feed, $data); 120 } 121 122 /** 123 * Get the status of the entry 124 * 125 * @return bool True if the item is a draft, false otherwise 126 */ 127 function get_draft_status() { 128 $draft = false; 129 if (($control = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOMPUB, 'control')) && !empty($control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data'])) { 130 $draft = ('yes' == $control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data']); 131 } 132 return $draft; 133 } 134 135 /** 136 * Get the GMT timestamp of the entry 137 * 138 * @param string $format date() format 139 * @return int|string|null 140 */ 141 function get_gmdate($format = 'j F Y, g:i a') { 142 return gmdate($format, $this->get_date('U')); 143 } 144 145 /** 146 * Get the updated timestamp of the entry 147 * 148 * AtomPub needs the distinction between "created" and "updated". 149 * @param string $format date() format 150 * @return string|int|null 151 */ 152 function get_updated($format = 'j F Y, g:i a') { 153 if ($updated = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) { 154 $return = date('Y-m-d H:i:s', $updated[0]['data']); 155 } 156 else { 157 return null; 158 } 159 160 if ($return) { 161 $parser = SimplePie_Parse_Date::get(); 162 $parsed = $parser->parse($return); 163 $date_format = (string) $date_format; 164 switch ($date_format) { 165 case '': 166 return $this->sanitize($return, SIMPLEPIE_CONSTRUCT_TEXT); 167 168 case 'U': 169 return $parsed; 170 171 default: 172 return date($date_format, $parsed); 173 } 174 } 175 else { 176 return null; 177 } 178 } 179 180 /** 181 * Get the updated GMT timestamp of the entry 182 * 183 * @param string $format date() format 184 * @return int|string|null 185 */ 186 function get_gmupdated($format = 'j F Y, g:i a') { 187 return gmdate($format, $this->get_updated('U')); 188 } 103 189 } 190 No newline at end of file