433 | | /** |
434 | | * Retrieve page. |
435 | | * |
436 | | * @since 2.2.0 |
437 | | * |
438 | | * @param array $args Method parameters. |
439 | | * @return array |
440 | | */ |
441 | | function wp_getPage($args) { |
442 | | $this->escape($args); |
| 433 | function wp_getPost($args, $mode = null) { |
| 434 | $this->escape($args); |
| 435 | |
| 436 | // Check if $args array has numeric keys |
| 437 | // Note: Deprecated since 3.1.1, use associative array with named keys instead |
| 438 | if(array_values($args) === $args) { |
| 439 | // _deprecated_argument( __FUNCTION__, '3.1.1', __( 'Passing an numeric array of arguments is deprecated. Pass an associative array instead.' ) ); |
| 440 | $args = array( |
| 441 | 'blog_id' => (int) $args[0], |
| 442 | 'post_id' => (int) $args[1], |
| 443 | 'username' => $args[2], |
| 444 | 'password' => $args[3] |
| 445 | ); |
| 446 | } |
449 | | if ( !$user = $this->login($username, $password) ) { |
450 | | return $this->error; |
451 | | } |
| 457 | $args = wp_parse_args($args, $defaults); |
| 458 | $args = (object) $args; |
| 459 | |
| 460 | if (! $user = $this->login($args->username, $args->password)) { |
| 461 | return $this->error; |
| 462 | } |
| 463 | |
| 464 | if (! post_type_exists($args->post_type)) { |
| 465 | return new IXR_Error(401, __('Sorry, the post type ' . $args->post_type . ' does not exist.')); |
| 466 | } |
| 467 | |
| 468 | // TODO: Capability must be mapped in register_posttype function, so we can test against it here |
| 469 | // e.g. current_user_can('edit_' . $args->post_type, $args->post_id) |
| 470 | // @see <http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types> for mapping example |
| 471 | if (! current_user_can('edit_post', $args->post_id)) { |
| 472 | return new IXR_Error(401, __('Sorry, you cannot edit the post type _' . $args->post_type . '_.')); |
| 473 | } |
| 474 | |
| 475 | do_action('xmlrpc_call', 'wp.getPost'); |
| 476 | |
| 477 | // Lookup post info. |
| 478 | $post = get_post($args->post_id); |
453 | | if ( !current_user_can( 'edit_page', $page_id ) ) |
454 | | return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) ); |
| 480 | // If we found the post then format the data. |
| 481 | if ($post->ID && $post->post_type == $args->post_type) { |
| 482 | // Format post date. |
| 483 | $post_date = mysql2date('Ymd\TH:i:s', $post->post_date, false); |
| 484 | $post_date_gmt = mysql2date('Ymd\TH:i:s', $post->post_date_gmt, false); |
| 485 | |
| 486 | // For drafts use the GMT version of the date |
| 487 | if ($post->post_status == 'draft') { |
| 488 | $post_date_gmt = get_gmt_from_date(mysql2date('Y-m-d H:i:s', $post->post_date), 'Ymd\TH:i:s'); |
| 489 | } |
| 490 | |
| 491 | if($args->with_taxonomies) { |
| 492 | $tax_ids = get_object_taxonomies($post); |
| 493 | $taxonomies = array(); |
| 494 | |
| 495 | foreach ($tax_ids as $tax_id) { |
| 496 | $terms[$tax_id] = get_object_term_cache($post->ID, $tax_id); |
| 497 | |
| 498 | if ( empty($terms[$tax_id]) ) { |
| 499 | $terms[$tax_id] = wp_get_object_terms($post->ID, $tax_id, $args, array('fields' => 'ids')); |
| 500 | } |
| 501 | |
| 502 | foreach ($terms[$tax_id] as $term) { |
| 503 | $term = (object) get_term($term, $tax_id); |
| 504 | $taxonomies[$tax_id][] = $term->name; |
| 505 | } |
| 506 | } |
| 507 | } |
456 | | do_action('xmlrpc_call', 'wp.getPage'); |
457 | | |
458 | | // Lookup page info. |
459 | | $page = get_page($page_id); |
460 | | |
461 | | // If we found the page then format the data. |
462 | | if ( $page->ID && ($page->post_type == "page") ) { |
463 | | // Get all of the page content and link. |
464 | | $full_page = get_extended($page->post_content); |
465 | | $link = post_permalink($page->ID); |
466 | | |
467 | | // Get info the page parent if there is one. |
468 | | $parent_title = ""; |
469 | | if ( !empty($page->post_parent) ) { |
470 | | $parent = get_page($page->post_parent); |
471 | | $parent_title = $parent->post_title; |
| 509 | // Get post tags |
| 510 | if(!empty($taxonomies['post_tag'])) { |
| 511 | $tagnames = implode(', ', $taxonomies['post_tag']); |
| 512 | } else { |
| 513 | $tagnames = ''; |
| 514 | } |
| 515 | |
| 516 | // Get categories |
| 517 | if(!empty($taxonomies['category'])) { |
| 518 | $categories = $taxonomies['category']; |
| 519 | } else { |
| 520 | $categories = array(); |
| 521 | } |
| 522 | |
| 523 | // Get all of the post content and link. |
| 524 | $full_post = get_extended($post->post_content); |
| 525 | $link = post_permalink($post->ID); |
| 526 | |
| 527 | // Get info the page parent if there is one. |
| 528 | $parent_title = ""; |
| 529 | if (! empty($post->post_parent)) { |
| 530 | $parent = get_post($post->post_parent); |
| 531 | $parent_title = $parent->post_title; |
| 532 | } |
| 533 | |
| 534 | // Determine comment and ping settings. |
| 535 | $allow_comments = comments_open($post->ID) ? 1 : 0; |
| 536 | $allow_pings = pings_open($post->ID) ? 1 : 0; |
| 537 | |
| 538 | // Get the author info. |
| 539 | $author = get_userdata($post->post_author); |
| 540 | |
| 541 | // Consider future posts as published |
| 542 | if ( $post->post_status === 'future' ) { |
| 543 | $post->post_status = 'publish'; |
| 545 | |
| 546 | // Get post format |
| 547 | $post_format = get_post_format( $post->ID); |
| 548 | if ( empty( $post_format ) ) |
| 549 | $post_format = 'standard'; |
| 550 | |
| 551 | $sticky = false; |
| 552 | if ( is_sticky( $post->ID) ) { |
| 553 | $sticky = true; |
| 554 | } |
| 555 | |
| 556 | // Get page template |
| 557 | $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
| 558 | if (empty($page_template)) { |
| 559 | $page_template = 'default'; |
| 560 | } |
| 561 | |
| 562 | $post_struct = array( |
| 563 | 'dateCreated' => new IXR_Date($post_date), |
| 564 | 'userid' => $post->post_author, |
| 565 | 'postid' => $post->ID, |
| 566 | 'post_status' => $post->post_status, |
| 567 | 'description' => $full_post['main'], |
| 568 | 'title' => $post->post_title, |
| 569 | 'link' => $link, |
| 570 | 'permaLink' => $link, |
| 571 | 'categories' => $categories, |
| 572 | 'excerpt' => $post->post_excerpt, |
| 573 | 'text_more' => $full_post['extended'], |
| 574 | 'mt_allow_comments' => $allow_comments, |
| 575 | 'mt_allow_pings' => $allow_pings, |
| 576 | 'mt_keywords' => $tagnames, |
| 577 | 'wp_slug' => $post->post_name, |
| 578 | 'wp_password' => $post->post_password, |
| 579 | 'wp_author' => $author->display_name, |
| 580 | 'wp_page_parent_id' => $post->post_parent, |
| 581 | 'wp_page_parent_title' => $parent_title, |
| 582 | 'wp_page_order' => $post->menu_order, |
| 583 | 'wp_author_id' => $author->ID, |
| 584 | 'wp_author_display_name' => $author->display_name, |
| 585 | 'date_created_gmt' => new IXR_Date($post_date_gmt), |
| 586 | 'custom_fields' => $this->get_custom_fields($args->post_id), |
| 587 | 'wp_page_template' => $page_template, |
| 588 | 'wp_post_format' => $post_format, |
| 589 | 'sticky' => $sticky, |
| 590 | 'post_type' => $post->post_type, |
| 591 | 'taxonomies' => $taxonomies |
| 592 | ); |
| 593 | |
| 594 | return $post_struct; |
| 595 | } else { |
| 596 | // If the post doesn't exist indicate that. |
| 597 | return new IXR_Error(404, __('Sorry, no such post in post type _' . $args->post_type . '_.')); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | function wp_getPosts($args) { |
| 602 | $this->escape($args); |
| 603 | |
| 604 | // Check if $args array has numeric keys |
| 605 | // Note: Deprecated since 3.1.1, use associative array with named keys instead |
| 606 | if(array_values($args) === $args) { |
| 607 | // _deprecated_argument( __FUNCTION__, '3.1.1', __( 'Passing an numeric array of arguments is deprecated. Pass an associative array instead.' ) ); |
| 608 | $args = array( |
| 609 | 'blog_id' => (int) $args[0], |
| 610 | 'username' => $args[1], |
| 611 | 'password' => $args[2] |
| 612 | ); |
| 613 | } |
| 614 | |
| 615 | $defaults = array( |
| 616 | 'blog_id' => 1, |
| 617 | 'username' => '', |
| 618 | 'password' => '', |
| 619 | 'post_type' => 'post', |
| 620 | 'num_posts' => 10, |
| 621 | 'post_status' => 'any', |
| 622 | 'with_taxonomies' => 1 |
| 623 | ); |
| 624 | |
| 625 | $args = wp_parse_args($args, $defaults); |
| 626 | $args = (object) $args; |
486 | | // Pull the categories info together. |
487 | | $categories = array(); |
488 | | foreach ( wp_get_post_categories($page->ID) as $cat_id ) { |
489 | | $categories[] = get_cat_name($cat_id); |
| 641 | // If we have pages, put together their info. |
| 642 | if ( $num_posts >= 1 ) { |
| 643 | $posts_struct = array(); |
| 644 | |
| 645 | for ( $i = 0; $i < $num_posts; $i++ ) { |
| 646 | // TODO: Capability must be mapped in register_posttype function, so we can test against it here |
| 647 | // e.g. current_user_can('edit_' . $args->post_type, $args->post_id) |
| 648 | // @see <http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types> for mapping example |
| 649 | if (! current_user_can('edit_posts', $posts[$i])) { |
| 650 | continue; |
| 651 | } |
| 652 | |
| 653 | $post = self::wp_getPost(array( |
| 654 | 'blog_id' => $args->blog_id, |
| 655 | 'post_id' => $posts[$i]->ID, |
| 656 | 'username' => $args->username, |
| 657 | 'password' => $args->password, |
| 658 | 'post_type'=> $args->post_type, |
| 659 | 'with_taxonomies' => $args->with_taxonomies |
| 660 | )); |
| 661 | |
| 662 | $posts_struct[] = $post; |
492 | | // Get the author info. |
493 | | $author = get_userdata($page->post_author); |
494 | | |
495 | | $page_template = get_post_meta( $page->ID, '_wp_page_template', true ); |
496 | | if ( empty( $page_template ) ) |
497 | | $page_template = 'default'; |
498 | | |
499 | | $page_struct = array( |
500 | | "dateCreated" => new IXR_Date($page_date), |
501 | | "userid" => $page->post_author, |
502 | | "page_id" => $page->ID, |
503 | | "page_status" => $page->post_status, |
504 | | "description" => $full_page["main"], |
505 | | "title" => $page->post_title, |
506 | | "link" => $link, |
507 | | "permaLink" => $link, |
508 | | "categories" => $categories, |
509 | | "excerpt" => $page->post_excerpt, |
510 | | "text_more" => $full_page["extended"], |
511 | | "mt_allow_comments" => $allow_comments, |
512 | | "mt_allow_pings" => $allow_pings, |
513 | | "wp_slug" => $page->post_name, |
514 | | "wp_password" => $page->post_password, |
515 | | "wp_author" => $author->display_name, |
516 | | "wp_page_parent_id" => $page->post_parent, |
517 | | "wp_page_parent_title" => $parent_title, |
518 | | "wp_page_order" => $page->menu_order, |
519 | | "wp_author_id" => $author->ID, |
520 | | "wp_author_display_name" => $author->display_name, |
521 | | "date_created_gmt" => new IXR_Date($page_date_gmt), |
522 | | "custom_fields" => $this->get_custom_fields($page_id), |
523 | | "wp_page_template" => $page_template |
524 | | ); |
525 | | |
526 | | return($page_struct); |
| 665 | return $posts_struct; |