Implementation of the MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP.
1
2 <?php
3 /**
4 * Skeleton file for MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP
5 * Requires Keith Deven's XML-RPC Library http://keithdevens.com/software/xmlrpc and store it as xmlrpc.php in the same folder
6 * Written by Daniel Lorch, based heavily on Keith Deven's examples on the Blogger API.
7 */
8
9 require_once dirname(__FILE__) . '/xmlrpc.php';
10
11 function metaWeblog_newPost($params) {
12 list($blogid, $username, $password, $struct, $publish) = $params;
13 $title = $struct['title'];
14 $description = $struct['description'];
15
16
17 // YOUR CODE:
18 $post_id = 0; // id of the post you just created
19
20
21 XMLRPC_response(XMLRPC_prepare((string)$post_id), WEBLOG_XMLRPC_USERAGENT);
22 }
23
24 function metaWeblog_editPost($params) {
25 list($postid, $username, $password, $struct, $publish) = $params;
26
27
28 // YOUR CODE:
29 $result = false; // whether or not the action succeeded
30
31
32 XMLRPC_response(XMLRPC_prepare((boolean)$result), WEBLOG_XMLRPC_USERAGENT);
33 }
34
35 function metaWeblog_getPost($params) {
36 list($postid, $username, $password) = $params;
37 $post = array();
38
39
40 // YOUR CODE:
41 $post['userId'] = '1';
42 $post['dateCreated'] = XMLRPC_convert_timestamp_to_iso8601(time());
43 $post['title'] = 'Replace me';
44 $post['content'] = 'Replace me, too';
45 $post['postid'] = '1';
46
47
48 XMLRPC_response(XMLRPC_prepare($post), WEBLOG_XMLRPC_USERAGENT);
49 }
50
51 function XMLRPC_method_not_found($methodName) {
52 XMLRPC_error("2", "The method you requested, '$methodName', was not found.", WEBLOG_XMLRPC_USERAGENT);
53 }
54
55 $xmlrpc_methods = array(
56 'metaWeblog.newPost' => 'metaWeblog_newPost',
57 'metaWeblog.editPost' => 'metaWeblog_editPost',
58 'metaWeblog.getPost' => 'metaWeblog_getPost'
59 );
60
61 $xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);
62 $methodName = XMLRPC_getMethodName($xmlrpc_request);
63 $params = XMLRPC_getParams($xmlrpc_request);
64
65 if(!isset($xmlrpc_methods[$methodName])) {
66 XMLRPC_method_not_found($methodName);
67 } else {
68 $xmlrpc_methods[$methodName]($params);
69 }
70 ?>