Ticket #7652: 7652.diff
File 7652.diff, 3.9 KB (added by , 14 years ago) |
---|
-
wp-app.php
17 17 18 18 /** Atom Publishing Protocol Class */ 19 19 require_once(ABSPATH . WPINC . '/atomlib.php'); 20 require_once(ABSPATH . WPINC . '/class-simplepie.php'); 20 21 21 22 /** Admin Image API for metadata updating */ 22 23 require_once(ABSPATH . '/wp-admin/includes/image.php'); … … 38 39 * @var int|bool 39 40 * @todo Should be an option somewhere 40 41 */ 41 $always_authenticate = 1;42 $always_authenticate = 0; 42 43 43 44 /** 44 45 * Writes logging info to a file. … … 258 259 * @since 2.2.0 259 260 */ 260 261 function handle_request() { 261 global $always_authenticate;262 263 262 if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) ) 264 263 $path = $_SERVER['ORIG_PATH_INFO']; 265 264 else … … 294 293 // authenticate regardless of the operation and set the current 295 294 // user. each handler will decide if auth is required or not. 296 295 if ( !$this->authenticate() ) { 297 if ( $always_authenticate ) 298 $this->auth_required('Credentials required.'); 296 $this->auth_required('Credentials required.'); 299 297 } 300 298 301 299 array_shift($matches); … … 390 388 global $user_ID; 391 389 $this->get_accepted_content_type($this->atom_content_types); 392 390 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()); 396 402 397 $entry = array_pop($parser->feed->entries);403 $entry = $feed->get_item(0); 398 404 399 log_app('Received entry:', print_r($entry,true));405 log_app('Received entry:', $entry->get_title()); 400 406 401 407 $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()); 404 410 } 405 411 406 412 $wp_cats = get_categories(array('hide_empty' => false)); … … 412 418 array_push($post_category, $cat->term_id); 413 419 } 414 420 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 } 416 425 417 426 $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 418 427 … … 422 431 $blog_ID = get_current_blog_id(); 423 432 $post_status = ($publish) ? 'publish' : 'draft'; 424 433 $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')); 431 439 432 440 if ( isset( $_SERVER['HTTP_SLUG'] ) ) 433 441 $post_name = $_SERVER['HTTP_SLUG']; … … 1336 1344 log_app('Status','400: Client Error'); 1337 1345 header('Content-Type: text/plain'); 1338 1346 status_header('400'); 1347 echo $msg; 1339 1348 exit; 1340 1349 } 1341 1350 … … 1448 1457 * @return bool 1449 1458 */ 1450 1459 function authenticate() { 1460 global $always_authenticate; 1461 1451 1462 log_app("authenticate()",print_r($_ENV, true)); 1452 1463 1453 1464 // if using mod_rewrite/ENV hack … … 1474 1485 } 1475 1486 } 1476 1487 1488 // If we're forcing admin abilities 1489 if (!$always_authenticate) { 1490 wp_set_current_user(1); 1491 return true; 1492 } 1493 1477 1494 return false; 1478 1495 } 1479 1496