Make WordPress Core

Changeset 1671


Ignore:
Timestamp:
09/16/2004 02:54:25 PM (21 years ago)
Author:
michelvaldrighi
Message:

now with complete MT API support -- TEST TEST TEST THIS (here it worked fine with Ecto 2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r1670 r1671  
    7575
    7676    function wp_xmlrpc_server() {
    77         $this->IXR_Server(array(
     77        $this->methods = array(
    7878          // Blogger API
    7979          'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
     
    8787          'blogger.deletePost' => 'this:blogger_deletePost',
    8888
    89           // MetaWeblog API
     89          // MetaWeblog API (with MT extensions to structs)
    9090          'metaWeblog.newPost' => 'this:mw_newPost',
    9191          'metaWeblog.editPost' => 'this:mw_editPost',
     
    102102          'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
    103103
     104          // MovableType API
     105          'mt.getCategoryList' => 'this:mt_getCategoryList',
     106          'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
     107          'mt.getPostCategories' => 'this:mt_getPostCategories',
     108          'mt.setPostCategories' => 'this:mt_setPostCategories',
     109          'mt.supportedMethods' => 'this:mt_supportedMethods',
     110          'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
     111          'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
     112          'mt.publishPost' => 'this:mt_publishPost',
     113
    104114          // PingBack
    105115          'pingback.ping' => 'this:pingback_ping',
     
    107117          'demo.sayHello' => 'this:sayHello',
    108118          'demo.addTwoNumbers' => 'this:addTwoNumbers'
    109         ));
     119        );
     120        $this->IXR_Server($this->methods);
    110121    }
    111122
     
    666677          'link' => $link,
    667678          'permaLink' => $link,
    668 // commented out because no other tool seems to use them
     679// commented out because no other tool seems to use this
    669680//        'content' => $entry['post_content'],
    670 //        'categories' => $categories
     681          'categories' => $categories,
    671682          'mt_excerpt' => $postdata['post_excerpt'],
    672683          'mt_text_more' => $post['extended'],
     
    724735          'link' => $link,
    725736          'permaLink' => $link,
    726 // commented out because no other tool seems to use them
     737// commented out because no other tool seems to use this
    727738//        'content' => $entry['post_content'],
    728 //        'categories' => $categories
     739          'categories' => $categories,
    729740          'mt_excerpt' => $entry['post_excerpt'],
    730741          'mt_text_more' => $post['extended'],
     
    924935
    925936      return $categories_struct;
     937    }
     938
     939
     940    /* mt.getPostCategories ...returns a post's categories */
     941    function mt_getPostCategories($args) {
     942
     943      $post_ID     = $args[0];
     944      $user_login  = $args[1];
     945      $user_pass   = $args[2];
     946
     947      if (!$this->login_pass_ok($user_login, $user_pass)) {
     948        return $this->error;
     949      }
     950
     951      $categories = array();
     952      $catids = wp_get_post_cats('', intval($post_ID));
     953      // first listed category will be the primary category
     954      $isPrimary = true;
     955      foreach($catids as $catid) {
     956        $categories[] = array(
     957          'categoryName' => get_cat_name($catid),
     958          'categoryId' => $catid,
     959          'isPrimary' => $isPrimary
     960        );
     961        $isPrimary = false;
     962      }
     963 
     964      return $categories;
     965    }
     966
     967
     968    /* mt.setPostCategories ...sets a post's categories */
     969    function mt_setPostCategories($args) {
     970
     971      $post_ID     = $args[0];
     972      $user_login  = $args[1];
     973      $user_pass   = $args[2];
     974      $categories  = $args[3];
     975
     976      if (!$this->login_pass_ok($user_login, $user_pass)) {
     977        return $this->error;
     978      }
     979
     980      $user_data = get_userdatabylogin($user_login);
     981      if (!user_can_edit_post($user_data->ID, $post_ID)) {
     982        return new IXR_Error(401, 'Sorry, you can not edit this post.');
     983      }
     984
     985      foreach($categories as $cat) {
     986        $catids[] = $cat['categoryId'];
     987      }
     988   
     989      wp_set_post_cats('', $post_ID, $catids);
     990
     991      return true;
     992    }
     993
     994
     995    /* mt.supportedMethods ...returns an array of methods supported by this server */
     996    function mt_supportedMethods($args) {
     997
     998      $supported_methods = array();
     999      foreach($this->methods as $key=>$value) {
     1000        $supported_methods[] = $key;
     1001      }
     1002
     1003      return $supported_methods;
     1004    }
     1005
     1006
     1007    /* mt.supportedTextFilters ...returns an empty array because we don't
     1008       support per-post text filters yet */
     1009    function mt_supportedTextFilters($args) {
     1010      return array();
     1011    }
     1012
     1013
     1014    /* mt.getTrackbackPings ...returns trackbacks sent to a given post */
     1015    function mt_getTrackbackPings($args) {
     1016
     1017      global $wpdb;
     1018
     1019      $post_ID = intval($args[0]);
     1020
     1021      $actual_post = wp_get_single_post($post_ID, ARRAY_A);
     1022
     1023      if (!$actual_post) {
     1024        return new IXR_Error(404, 'Sorry, no such post.');
     1025      }
     1026
     1027      $comments = $wpdb->get_results("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = $post_ID");
     1028
     1029      if (!$comments) {
     1030        return array();
     1031      }
     1032
     1033      $trackback_pings = array();
     1034      foreach($comments as $comment) {
     1035        if ((strpos($comment->comment_content, '<trackback />') === 0)
     1036            || ('trackback' == $comment->comment_type)) {
     1037          // FIXME: would be nicer to have a comment_title field?
     1038          // FIXME: assumption: here we make the assumption that trackback
     1039          //        titles are stored as <strong>title</strong>
     1040          $content = str_replace('<trackback />', '', $comment->comment_content);
     1041          $title = substr($content, 8, (strpos($content, '</strong>') - 8));
     1042          $trackback_pings[] = array(
     1043            'pingTitle' => $title,
     1044            'pingURL'   => $comment->comment_author_url,
     1045            'pingIP'    => $comment->comment_author_IP
     1046          );
     1047        }
     1048      }
     1049
     1050      return $trackback_pings;
     1051    }
     1052
     1053
     1054    /* mt.publishPost ...sets a post's publish status to 'publish' */
     1055    function mt_publishPost($args) {
     1056
     1057      $post_ID     = $args[0];
     1058      $user_login  = $args[1];
     1059      $user_pass   = $args[2];
     1060
     1061      if (!$this->login_pass_ok($user_login, $user_pass)) {
     1062        return $this->error;
     1063      }
     1064
     1065      $user_data = get_userdatabylogin($user_login);
     1066      if (!user_can_edit_post($user_data->ID, $post_ID)) {
     1067        return new IXR_Error(401, 'Sorry, you can not edit this post.');
     1068      }
     1069
     1070      $postdata = wp_get_single_post($post_ID,ARRAY_A);
     1071
     1072      $postdata['post_status'] = 'publish';
     1073
     1074      // retain old cats
     1075      $cats = wp_get_post_cats('',$post_ID);
     1076      $postdata['post_category'] = $cats;
     1077
     1078      $result = wp_update_post($postdata);
     1079
     1080      return $result;
    9261081    }
    9271082
Note: See TracChangeset for help on using the changeset viewer.