Source for file MetaWeblog.php
Documentation is available at MetaWeblog.php
require_once 'Services/Blogging/Exception.php';
require_once 'Services/Blogging/ExtendedDriver.php';
require_once 'Services/Blogging/Post.php';
require_once 'Services/Blogging/XmlRpc.php';
require_once 'XML/RPC.php';
* metaWeblog API implementation.
* http://www.xmlrpc.com/metaWeblogApi
* http://www.movabletype.org/mt-static/docs/mtmanual_programmatic.html
* @package Services_Blogging
* @author Anant Narayanan <anant@php.net>
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* Internal list with user data.
Services_Blogging_Post ::TITLE ,
Services_Blogging_Post ::CONTENT ,
Services_Blogging_Post ::DATE ,
Services_Blogging_Post ::URL ,
Services_Blogging_Post ::CATEGORIES ,
* Constructor for the metaWeblog driver class.
* @param string $user The username of the blog account.
* @param string $pass The password of the blog account.
* @param string $server The URI of the server to connect to.
* @param string $path The path to the XML-RPC server script.
* @throws Services_Blogging_Exception If authentication fails
public function __construct($user, $pass, $server, $path)
'rpc_user' => new XML_RPC_Value ($user, 'string'),
'rpc_pass' => new XML_RPC_Value ($pass, 'string'),
'rpc_blogid'=> new XML_RPC_Value ($user, 'string'),
$this->rpc_client = new XML_RPC_Client (
// $this->rpc_client->setDebug(true);
}//public function __construct($userid, $pass, $server, $path)
* Save a new post into the blog.
* @param Services_Blogging_Post $post Post object to put online
* @throws Services_Blogging_Exception If an error occured
public function savePost(Services_Blogging_Post $post)
if ($post->id === null ) {
//post is new and has no Id => create new one
$request = new XML_RPC_Message ('metaWeblog.newPost',
self ::convertPostToStruct ($post),
new XML_RPC_Value (true , 'boolean')
//edit the post; it already exists
$request = new XML_RPC_Message ('metaWeblog.editPost',
new XML_RPC_Value ($post->id , 'string'),
self ::convertPostToStruct ($post),
new XML_RPC_Value (true , 'boolean')
}//public function savePost(Services_Blogging_Post $post)
* The getPost method is intended to retrive a given post as an object of
* the Services_Blogging_Post class; given the unique post id which is passed
* as a parameter to the function.
* @param string $id The PostID of the post to be retrieved. (As
* returned by newPost() defined in
* Services_Blogging_driver).
* @return Services_Blogging_Post The elements of the post returned as an
* object of the Services_Blogging_Post class.
* @throws Services_Blogging_Exception If the post does not exist
$request = new XML_RPC_Message ('metaWeblog.getPost',
new XML_RPC_Value ($id, 'int'),
}//public function getPost($id)
* The deletePost method in metaWeblog is just
* an alias to the deletePost blogger method
* @param mixed $post Services_Blogging_Post object to delete,
* or post id (integer) to delete
* @return boolean True if deleted, false if not.
$request = new XML_RPC_Message ('metaWeblog.deletePost',
new XML_RPC_Value ('0123456789ABCDEF', 'string'),
new XML_RPC_Value ($post->id , 'int'),
new XML_RPC_Value (true , 'boolean')
}//public function deletePost($post)
* Returns an array of recent posts as Services_Blogging_Post objects
* @param int $number The number of posts to be retrieved.
* @return Array An array of objects of the Services_Blogging_Post class that
* correspond to the number of posts requested.
$request = new XML_RPC_Message ('metaWeblog.getRecentPosts',
new XML_RPC_Value ($number, 'int')
foreach ($arData as $data) {
$arPosts[$post->id ] = $post;
}//public function getRecentPosts($number = 15)
* The getRecentPostTitles method is intended to retrieve the given number of
* posts titles from a blog.
* The posts themselves can be retrieved with getPost() or getRecentPosts().
* There is no direct getRecentPostTitles method in metaWeblog. So
* we internally call getRecentPosts() and strip out ids and titles of
* the post. So this method is slow here, because all post data needs
* @param int $number The number of posts to be retrieved.
* @return Array An array of int => strings representing the
* post ids (key) and their title (value).
foreach ($arPosts as $post) {
}//public function getRecentPostTitles($number = 15)
* Returns an array of strings thay define
* the properties that a post to this blog may
* @return array Array of strings
}//public function getSupportedPostProperties()
* Checks if the given property name/id is supported
* @param string $strProperty Property name/id to check
* @return boolean If the property is supported
}//public function isPostPropertySupported($strProperty)
* Converts a struct returned by the webservice to
* a Services_Blogging_Post object
* @param array $arStruct Struct to convert
* @return Services_Blogging_Post Converted post
substr($arStruct['dateCreated'], 9 , 2 ),//hour
substr($arStruct['dateCreated'], 12 , 2 ),//minute
substr($arStruct['dateCreated'], 15 , 2 ),//second
substr($arStruct['dateCreated'], 4 , 2 ),//month
substr($arStruct['dateCreated'], 6 , 2 ),//day
substr($arStruct['dateCreated'], 0 , 4 )//year
if (!isset ($arStruct['categories'])) {
$arStruct['categories'] = array ();
$post->setId ($arStruct['postid']);
}//protected function convertStructToPost($arStruct)
* Converts Services_Blogging_Post object to
* an XML-RPC struct that can be sent to the server.
* @param Services_Blogging_Post $post Post object to convert
* @param XML_RPC_Value Struct to send
if ($time == '' || $time == 0 ) {
foreach ($catstr as $cat) {
$categories[] = new XML_RPC_Value ($cat, 'string');
return new XML_RPC_Value (
'categories' => new XML_RPC_Value ($categories, 'array'),
'dateCreated' => new XML_RPC_Value (date('Ymd\\TH:i:s', $time), 'dateTime.iso8601'),
}//protected function convertPostToStruct($post)
}//class Services_Blogging_Driver_MetaWeblog extends Services_Blogging_ExtendedDriver
Documentation generated on Mon, 11 Mar 2019 14:57:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|