| | 459 | |
|---|
| | 460 | |
|---|
| | 461 | /* MetaWeblog API functions |
|---|
| | 462 | * specs on wherever Dave Winer wants them to be |
|---|
| | 463 | */ |
|---|
| | 464 | |
|---|
| | 465 | /* metaweblog.newPost creates a post */ |
|---|
| | 466 | function mw_newPost($args) { |
|---|
| | 467 | |
|---|
| | 468 | global $wpdb; |
|---|
| | 469 | |
|---|
| | 470 | $blog_ID = $args[0]; // we will support this in the near future |
|---|
| | 471 | $user_login = $args[1]; |
|---|
| | 472 | $user_pass = $args[2]; |
|---|
| | 473 | $content_struct = $args[3]; |
|---|
| | 474 | $publish = $args[4]; |
|---|
| | 475 | |
|---|
| | 476 | if (!$this->login_pass_ok($user_login, $user_pass)) { |
|---|
| | 477 | return $this->error; |
|---|
| | 478 | } |
|---|
| | 479 | |
|---|
| | 480 | $user_data = get_userdatabylogin($user_login); |
|---|
| | 481 | if (!user_can_create_post($user_data->ID, $blog_ID)) { |
|---|
| | 482 | return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.'); |
|---|
| | 483 | } |
|---|
| | 484 | |
|---|
| | 485 | $post_author = $userdata->ID; |
|---|
| | 486 | |
|---|
| | 487 | $post_title = $content_struct['title']; |
|---|
| | 488 | $post_content = format_to_post($content_struct['description']); |
|---|
| | 489 | $post_status = $publish ? 'publish' : 'draft'; |
|---|
| | 490 | |
|---|
| | 491 | $post_excerpt = $content_struct['mt_excerpt']; |
|---|
| | 492 | $post_more = $content_struct['mt_text_more']; |
|---|
| | 493 | |
|---|
| | 494 | $comment_status = $content_struct['mt_allow_comments'] ? 'open' : 'closed'; |
|---|
| | 495 | $ping_status = $content_struct['mt_allow_pings'] ? 'open' : 'closed'; |
|---|
| | 496 | |
|---|
| | 497 | if ($post_more) { |
|---|
| | 498 | $post_content = $post_content . "\n<!--more-->\n" . $post_more; |
|---|
| | 499 | } |
|---|
| | 500 | |
|---|
| | 501 | // Do some timestamp voodoo |
|---|
| | 502 | $dateCreated = $content_struct['dateCreated']; |
|---|
| | 503 | if (!empty($dateCreated)) { |
|---|
| | 504 | $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
|---|
| | 505 | $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); |
|---|
| | 506 | } else { |
|---|
| | 507 | $post_date = current_time('mysql'); |
|---|
| | 508 | $post_date_gmt = current_time('mysql', 1); |
|---|
| | 509 | } |
|---|
| | 510 | |
|---|
| | 511 | $catnames = $content_struct['categories']; |
|---|
| | 512 | // FIXME: commented until a fix to print_r is found: logio('O', 'Post cats: ' . print_r($catnames,true)); |
|---|
| | 513 | $post_category = array(); |
|---|
| | 514 | |
|---|
| | 515 | if ($catnames) { |
|---|
| | 516 | foreach ($catnames as $cat) { |
|---|
| | 517 | $post_category[] = get_cat_ID($cat); |
|---|
| | 518 | } |
|---|
| | 519 | } else { |
|---|
| | 520 | $post_category[] = 1; |
|---|
| | 521 | } |
|---|
| | 522 | |
|---|
| | 523 | // We've got all the data -- post it: |
|---|
| | 524 | $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status'); |
|---|
| | 525 | |
|---|
| | 526 | $post_ID = wp_insert_post($postdata); |
|---|
| | 527 | |
|---|
| | 528 | if (!$post_ID) { |
|---|
| | 529 | return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); |
|---|
| | 530 | } |
|---|
| | 531 | |
|---|
| | 532 | logIO('O', "Posted ! ID: $post_ID"); |
|---|
| | 533 | |
|---|
| | 534 | // FIXME: do we pingback always? pingback($content, $post_ID); |
|---|
| | 535 | trackback_url_list($content_struct['mt_tb_ping_urls'],$post_ID); |
|---|
| | 536 | |
|---|
| | 537 | return $post_ID; |
|---|
| | 538 | } |
|---|
| | 539 | |
|---|
| | 540 | |
|---|
| | 541 | /* metaweblog.editPost ...edits a post */ |
|---|
| | 542 | function mw_editPost($args) { |
|---|
| | 543 | |
|---|
| | 544 | global $wpdb; |
|---|
| | 545 | |
|---|
| | 546 | $post_ID = $args[0]; |
|---|
| | 547 | $user_login = $args[1]; |
|---|
| | 548 | $user_pass = $args[2]; |
|---|
| | 549 | $content_struct = $args[3]; |
|---|
| | 550 | $publish = $args[4]; |
|---|
| | 551 | |
|---|
| | 552 | if (!$this->login_pass_ok($user_login, $user_pass)) { |
|---|
| | 553 | return $this->error; |
|---|
| | 554 | } |
|---|
| | 555 | |
|---|
| | 556 | $user_data = get_userdatabylogin($user_login); |
|---|
| | 557 | if (!user_can_edit_post($user_data->ID, $post_ID)) { |
|---|
| | 558 | return new IXR_Error(401, 'Sorry, you can not edit this post.'); |
|---|
| | 559 | } |
|---|
| | 560 | |
|---|
| | 561 | extract($postdata); |
|---|
| | 562 | |
|---|
| | 563 | $post_title = $content_struct['title']; |
|---|
| | 564 | $post_content = format_to_post($content_struct['description']); |
|---|
| | 565 | $catnames = $content_struct['categories']; |
|---|
| | 566 | |
|---|
| | 567 | if ($catnames) { |
|---|
| | 568 | foreach ($catnames as $cat) { |
|---|
| | 569 | $post_category[] = get_cat_ID($cat); |
|---|
| | 570 | } |
|---|
| | 571 | } |
|---|
| | 572 | |
|---|
| | 573 | $post_excerpt = $content_struct['mt_excerpt']; |
|---|
| | 574 | $post_more = $content_struct['mt_text_more']; |
|---|
| | 575 | $post_status = $publish ? 'publish' : 'draft'; |
|---|
| | 576 | |
|---|
| | 577 | if ($post_more) { |
|---|
| | 578 | $post_content = $post_content . "\n<!--more-->\n" . $post_more; |
|---|
| | 579 | } |
|---|
| | 580 | |
|---|
| | 581 | $comment_status = (1 == $content_struct['mt_allow_comments']) ? 'open' : 'closed'; |
|---|
| | 582 | $ping_status = $content_struct['mt_allow_pings'] ? 'open' : 'closed'; |
|---|
| | 583 | |
|---|
| | 584 | // Do some timestamp voodoo |
|---|
| | 585 | $dateCreated = $content_struct['dateCreated']; |
|---|
| | 586 | if (!empty($dateCreated)) { |
|---|
| | 587 | $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
|---|
| | 588 | $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); |
|---|
| | 589 | } else { |
|---|
| | 590 | $post_date = $postdata['post_date']; |
|---|
| | 591 | $post_date_gmt = $postdata['post_date_gmt']; |
|---|
| | 592 | } |
|---|
| | 593 | |
|---|
| | 594 | // We've got all the data -- post it: |
|---|
| | 595 | $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt'); |
|---|
| | 596 | |
|---|
| | 597 | $post_ID = wp_update_post($newpost); |
|---|
| | 598 | if (!$post_ID) { |
|---|
| | 599 | return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.'); |
|---|
| | 600 | } |
|---|
| | 601 | |
|---|
| | 602 | logIO('O',"(MW) Edited ! ID: $post_ID"); |
|---|
| | 603 | |
|---|
| | 604 | // FIXME: do we pingback always? pingback($content, $post_ID); |
|---|
| | 605 | trackback_url_list($content_struct['mt_tb_ping_urls'], $post_ID); |
|---|
| | 606 | |
|---|
| | 607 | return $post_ID; |
|---|
| | 608 | } |
|---|
| | 609 | |
|---|
| | 610 | |
|---|
| | 611 | /* metaweblog.getPost ...returns a post */ |
|---|
| | 612 | function mw_getPost($args) { |
|---|
| | 613 | |
|---|
| | 614 | global $wpdb; |
|---|
| | 615 | |
|---|
| | 616 | $post_ID = $args[0]; |
|---|
| | 617 | $user_login = $args[1]; |
|---|
| | 618 | $user_pass = $args[2]; |
|---|
| | 619 | |
|---|
| | 620 | if (!$this->login_pass_ok($user_login, $user_pass)) { |
|---|
| | 621 | return $this->error; |
|---|
| | 622 | } |
|---|
| | 623 | |
|---|
| | 624 | $postdata = wp_get_single_post($post_ID, ARRAY_A); |
|---|
| | 625 | |
|---|
| | 626 | if ($postdata['post_date'] != '') { |
|---|
| | 627 | |
|---|
| | 628 | $post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']); |
|---|
| | 629 | |
|---|
| | 630 | $catids = wp_get_post_cats('', $post_ID); |
|---|
| | 631 | foreach($catids as $catid) { |
|---|
| | 632 | $catname = get_cat_name($catid); |
|---|
| | 633 | $catnameenc = new xmlrpcval($catname); |
|---|
| | 634 | $catlist[] = $catnameenc; |
|---|
| | 635 | } |
|---|
| | 636 | $post = get_extended($postdata['post_content']); |
|---|
| | 637 | $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0; |
|---|
| | 638 | $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0; |
|---|
| | 639 | |
|---|
| | 640 | $resp = array( |
|---|
| | 641 | 'link' => post_permalink($post_ID), |
|---|
| | 642 | 'title' => $postdata['post_title'], |
|---|
| | 643 | 'description' => $post['main'], |
|---|
| | 644 | 'dateCreated' => new IXR_Date($post_date), |
|---|
| | 645 | 'userid' => $postdata['post_author'], |
|---|
| | 646 | 'postid' => $postdata['ID'], |
|---|
| | 647 | 'content' => $postdata['post_content'], |
|---|
| | 648 | 'permalink' => post_permalink($post_ID), |
|---|
| | 649 | 'categories' => $catlist, |
|---|
| | 650 | 'mt_excerpt' => $postdata['post_excerpt'], |
|---|
| | 651 | 'mt_allow_comments' => $allow_comments, |
|---|
| | 652 | 'mt_allow_pings' => $allow_pings, |
|---|
| | 653 | 'mt_text_more' => $post['extended'] |
|---|
| | 654 | ); |
|---|
| | 655 | |
|---|
| | 656 | return $resp; |
|---|
| | 657 | } else { |
|---|
| | 658 | return new IXR_Error(404, 'Sorry, no such post.'); |
|---|
| | 659 | } |
|---|
| | 660 | } |
|---|
| | 661 | |
|---|