]> git.mjollnir.org Git - s9y.git/commitdiff
patch xml-rpc, thanks to tim Putnam
authorgarvinhicking <garvinhicking>
Fri, 27 May 2005 09:01:35 +0000 (09:01 +0000)
committergarvinhicking <garvinhicking>
Fri, 27 May 2005 09:01:35 +0000 (09:01 +0000)
(http://www.fracsoft.com/serendipity/archives/12-More-Serendipity-xml-rpc-patching.html)

docs/NEWS
serendipity_xmlrpc.php

index a002da014a22ac2296ed5c4776bb0dd0744eb64c..59ca5d4c2216e019dd7e3619cb7d01ee04766aad 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 0.9 ()
 ------------------------------------------------------------------------
 
+    * Patched XML-RPC functions, thanks to Tim Putnam. This should enable
+      XML-RPC services to properly fetch existing articles and edit them.
+
     * Localized the string "Reply" which occured inside some templates.
       (s/Reply/{$CONST.REPLY}/) (garvinhicking)
 
index d82df223f68baea4d8483e25a8d4fb76fd393ffa..9883a269c853a0fc5f21e65310ef980251ba6401 100644 (file)
@@ -46,7 +46,7 @@ $dispatches = array(
                     'metaWeblog.newMediaObject' =>
                         array('function' => 'metaWeblog_newMediaObject'),
                     'metaWeblog.getRecentPosts' =>
-                        array('function' => 'mt_getRecentPostTitles'),
+                        array('function' => 'metaWeblog_getRecentPosts'),
                     'mt.getRecentPostTitles' =>
                         array('function' => 'mt_getRecentPostTitles'),
                     'mt.getCategoryList' =>
@@ -118,9 +118,10 @@ function blogger_getRecentPosts($message) {
             array(
                   'postid'      => new XML_RPC_Value($entry['id'], 'string'),
                   'title'       => new XML_RPC_Value($entry['title'], 'string'),
+                  'content'                    => new XML_RPC_Value($entry['body'], 'string'),
                   'userid'      => new XML_RPC_Value($entry['authorid'], 'string'),
-                  'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
-                  'postid'      => new XML_RPC_Value($entry['id'], 'string')), 'struct');
+                  'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601')
+                  ), 'struct');
     }
     $xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
     return new XML_RPC_Response($xml_entries);
@@ -168,6 +169,44 @@ function mt_getCategoryList($message) {
     return new XML_RPC_Response($xml_entries);
 }
 
+function metaWeblog_getRecentPosts($message) {
+    $val = $message->params[1];
+    $username = $val->getval();
+    $val = $message->params[2];
+    $password = $val->getval();
+    $val = $message->params[3];
+    $numposts = $val->getval();
+    if (!serendipity_authenticate_author($username, $password)) {
+        return new XML_RPC_Response('', 4, 'Authentication Failed');
+    }
+    $entries = serendipity_fetchEntries('', false, $numposts);
+    $xml_entries_vals = array();
+
+    foreach ($entries as $tentry) {
+        $entry = serendipity_fetchEntry('id', $tentry['id']);
+        $xml_entries_vals[] = new XML_RPC_Value(
+            array(
+                'dateCreated'       => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
+                'postid'            => new XML_RPC_Value($entry['id'], 'string'),
+                'userid'            => new XML_RPC_Value($entry['authorid'], 'string'),
+                'description'       => new XML_RPC_Value($entry['body'], 'string'),
+                'mt_excerpt'        => new XML_RPC_Value('', 'string'),
+                'mt_allow_comments' => new XML_RPC_Value(1, 'int'),
+                'mt_text_more'         => new XML_RPC_Value($entry['extended'], 'string' ),
+                'mt_allow_pings'    => new XML_RPC_Value(1, 'int'),
+                'mt_convert_breaks' => new XML_RPC_Value('', 'string'),
+                'mt_keywords'       => new XML_RPC_Value('', 'string'),
+                'title'             => new XML_RPC_Value($entry['title'],'string'),
+                'permalink'         => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])), 'string'),
+                'link'              => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])), 'string')
+             ),
+            'struct');
+            
+     }
+    $xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
+    return new XML_RPC_Response($xml_entries);
+
+}
 function mt_getRecentPostTitles($message) {
     $val = $message->params[1];
     $username = $val->getval();
@@ -186,8 +225,7 @@ function mt_getRecentPostTitles($message) {
                 'postid'      => new XML_RPC_Value($entry['id'], 'string'),
                 'title'       => new XML_RPC_Value($entry['title'], 'string'),
                 'userid'      => new XML_RPC_Value($entry['authorid'], 'string'),
-                'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
-                'postid'      => new XML_RPC_Value($entry['id'], 'string')
+                'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601')
             ),
             'struct');
     }
@@ -211,6 +249,12 @@ function blogger_newPost($message) {
     }
     $val = $message->params[4];
     $entry['body']  = $val->getval();
+    $val = $message->params[5];
+    $topublish = $val->getval();
+    if ($topublish == 1){
+        $entry['isdraft'] = 'false';
+    } else { $entry['isdraft'] = 'true'; }
+    
     $entry['allow_comments'] = $serendipity['allowCommentsDefault'];
     $entry['moderate_comments'] = $serendipity['moderateCommentsDefault'];
     $id = serendipity_updertEntry($entry);
@@ -244,9 +288,7 @@ function blogger_deletePost($message) {
     if (!serendipity_authenticate_author($username, $password)) {
         return new XML_RPC_Response('', 4, 'Authentication Failed');
     }
-    $val = $message->params[4];
-    $entry['body']  = $val->getval();
-    $entry['author'] = $username;
+    
     $id = serendipity_deleteEntry($entry['id']);
     return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
 }
@@ -289,13 +331,20 @@ function metaWeblog_newPost($message) {
     $val = $message->params[4];
     $publish = $val->getval();
 
+       
     $entry['categories']        = universal_fetchCategories($post_array['categories']);
     $entry['title']             = $post_array['title'];
     $entry['body']              = $post_array['description'];
     $entry['extended']          = $post_array['mt_text_more'];
     $entry['isdraft']           = ($publish == 0) ? 'true' : 'false';
-    $entry['allow_comments']    = $serendipity['allowCommentsDefault'];
+    if (isset($post_array['mt_allow_comments'])) {
+        $entry['allow_comments'] = $post_array['mt_allow_comments'];
+    } else {
+        $entry['allow_comments'] = $serendipity['allowCommentsDefault'];
+    }
+
     $entry['moderate_comments'] = $serendipity['moderateCommentsDefault'];
+    $entry['keywords'] = $post_array['mt_keywords'];
 
     $id = serendipity_updertEntry($entry);
 
@@ -342,7 +391,9 @@ function metaWeblog_editPost($message) {
     $val = $message->params[4];
     $publish = $val->getval();
 
-    $entry['categories']    = universal_fetchCategories($post_array['categories']);
+    if (isset($post_array['categories'])) {
+       $entry['categories'] = universal_fetchCategories($post_array['categories']);
+    }
     $entry['title']         = $post_array['title'];
     $entry['body']          = $post_array['description'];
     $entry['extended']      = $post_array['mt_text_more'];
@@ -355,6 +406,7 @@ function metaWeblog_editPost($message) {
     return new XML_RPC_Response(new XML_RPC_Value($id ? true : false, 'boolean'));
 }
 
+
 function metaWeblog_getPost($message) {
     global $serendipity;
     $val = $message->params[0];
@@ -368,9 +420,23 @@ function metaWeblog_getPost($message) {
     }
 
     $entry = serendipity_fetchEntry('id', $postid);
-    $entry = new XML_RPC_Value(metaWeblog_setEntry($entry), 'struct');
 
-    return new XML_RPC_Response($entry);
+    $tmp = new XML_RPC_Value(array(
+        'userid'            => new XML_RPC_Value($entry['authorid'], 'string'),
+        'dateCreated'       => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
+        'postid'            => new XML_RPC_Value($postid, 'string'),
+        'description'       => new XML_RPC_Value($entry['body'], 'string'),
+        'title'             => new XML_RPC_Value($entry['title'],'string'),
+        'link'              => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])), 'string'),
+        'permalink'         => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])), 'string'),
+        'mt_excerpt'        => new XML_RPC_Value($entry['excerpt'], 'string'),
+        'mt_text_more'      => new XML_RPC_Value($entry['extended'], 'string'),
+        'mt_allow_comments' => new XML_RPC_Value($entry['allow_comments'], 'int'),
+        'mt_allow_pings'    => new XML_RPC_Value($entry['mt_allow_pings'], 'int'),
+        'mt_convert_breaks' => new XML_RPC_Value($entry['mt_convert_breaks'], 'string'),
+        'mt_keywords'       => new XML_RPC_Value($entry['mt_keywords'], 'string')), 'struct');
+
+    return new XML_RPC_Response($tmp);
 }
 
 function metaWeblog_deletePost($message) {
@@ -405,7 +471,10 @@ function metaWeblog_setPostCategories($message) {
     }
 
     $category_ids = universal_fetchCategories($categories->getval(), true);
-    serendipity_updateEntryCategories($postid, $category_ids);
+    $entry = serendipity_fetchEntry ( 'id', $postid );
+    $entry['categories'] = $category_ids;
+    $entry = serendipity_updertEntry ( $entry );
+    //serendipity_updateEntryCategories($postid, $category_ids);
     return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
 }
 
@@ -459,7 +528,7 @@ function metaWeblog_newMediaObject($message) {
     }
 
     $fp = fopen($full, 'w');
-    fwrite($fp, base64_decode($struct['bits']));
+    fwrite($fp, $struct['bits']);
     fclose($fp);
     $path = $serendipity['baseURL'] . $serendipity['uploadPath'] . $struct['name'];
     return new XML_RPC_Response(new XML_RPC_Value(array('url' => new XML_RPC_Value($path, 'string')), 'struct'));