<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: php code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Tue, 07 Oct 2008 18:37:19 GMT</pubDate>
    <description>DZone Snippets: php code</description>
    <item>
      <title>MetaWeblog API in PHP</title>
      <link>http://snippets.dzone.com/posts/show/4816</link>
      <description>Implementation of the MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;/**&lt;br /&gt; * Skeleton file for MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP&lt;br /&gt; * Requires Keith Deven's XML-RPC Library http://keithdevens.com/software/xmlrpc and store it as xmlrpc.php in the same folder&lt;br /&gt; * Written by Daniel Lorch, based heavily on Keith Deven's examples on the Blogger API.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;require_once dirname(__FILE__) . '/xmlrpc.php';&lt;br /&gt;&lt;br /&gt;function metaWeblog_newPost($params) {&lt;br /&gt;  list($blogid, $username, $password, $struct, $publish) = $params;&lt;br /&gt;  $title = $struct['title'];&lt;br /&gt;  $description = $struct['description'];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // YOUR CODE:&lt;br /&gt;  $post_id = 0; // id of the post you just created&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  XMLRPC_response(XMLRPC_prepare((string)$post_id), WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function metaWeblog_editPost($params) {&lt;br /&gt;  list($postid, $username, $password, $struct, $publish) = $params;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // YOUR CODE:&lt;br /&gt;  $result = false; // whether or not the action succeeded&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  XMLRPC_response(XMLRPC_prepare((boolean)$result), WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function metaWeblog_getPost($params) {&lt;br /&gt;  list($postid, $username, $password) = $params;&lt;br /&gt;  $post = array();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // YOUR CODE:&lt;br /&gt;  $post['userId'] = '1';&lt;br /&gt;  $post['dateCreated'] = XMLRPC_convert_timestamp_to_iso8601(time());&lt;br /&gt;  $post['title'] = 'Replace me';&lt;br /&gt;  $post['content'] = 'Replace me, too';&lt;br /&gt;  $post['postid'] = '1';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  XMLRPC_response(XMLRPC_prepare($post), WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function XMLRPC_method_not_found($methodName) {&lt;br /&gt;  XMLRPC_error("2", "The method you requested, '$methodName', was not found.", WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$xmlrpc_methods = array(&lt;br /&gt;  'metaWeblog.newPost'  =&gt; 'metaWeblog_newPost',&lt;br /&gt;  'metaWeblog.editPost' =&gt; 'metaWeblog_editPost',&lt;br /&gt;  'metaWeblog.getPost'  =&gt; 'metaWeblog_getPost'&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);&lt;br /&gt;$methodName = XMLRPC_getMethodName($xmlrpc_request);&lt;br /&gt;$params = XMLRPC_getParams($xmlrpc_request);&lt;br /&gt;&lt;br /&gt;if(!isset($xmlrpc_methods[$methodName])) {&lt;br /&gt;  XMLRPC_method_not_found($methodName);&lt;br /&gt;} else {&lt;br /&gt;  $xmlrpc_methods[$methodName]($params);&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 25 Nov 2007 18:34:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4816</guid>
      <author>danielsanII (Daniel Lorch)</author>
    </item>
  </channel>
</rss>
