Source for file Blogger.php
Documentation is available at Blogger.php
require_once 'Services/Blogging/Driver.php';
require_once 'Services/Blogging/Exception.php';
require_once 'Services/Blogging/MultipleBlogsInterface.php';
require_once 'Services/Blogging/XmlRpc.php';
require_once 'XML/RPC.php';
* Blogger API implementation.
* This class implements the Blogger XML-RPC API described at
* http://www.blogger.com/developers/api/1_docs/
* @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
* Requests shall be sent to here
* Id of the blog to be used.
* Some blogs support multiple blogs with one account.
* Internal list with user data.
* Constructor for the Blogger class that authenticates the user and sets class
* properties. It will return the userinfo if authentication was successful, an
* exception if authentication failed. The username, password, path to the
* XML-RPC client and server URI are passed as parameters.
* If $server and $path are set to NULL, the default
* blogger.com address is used.
* @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 = null , $path = null )
$server = self ::XML_RPC_SERVER;
$path = self ::XML_RPC_PATH;
'rpc_user' => new XML_RPC_Value ($user, 'string'),
'rpc_pass' => new XML_RPC_Value ($pass, 'string'),
'rpc_blogid'=> new XML_RPC_Value ('' , 'string'),
'rpc_key' => new XML_RPC_Value ('0123456789ABCDEF', 'string')
$authenticate = new XML_RPC_Message (
$this->rpc_client = new XML_RPC_Client (
//FIXME: store the userinfo somewhere and make it available
}//public function __construct($userid, $pass, $server = null, $path = null)
* 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 ('blogger.newPost',
new XML_RPC_Value (true , 'boolean')
//edit the post; it already exists
$request = new XML_RPC_Message ('blogger.editPost',
new XML_RPC_Value ($post->id , 'string'),
new XML_RPC_Value (true , 'boolean')
}//public function savePost(Services_Blogging_Post $post)
* @param mixed $post Services_Blogging_Post object to delete,
* or post id (integer) to delete
* @return boolean True if deleted, false if not.
$id = new XML_RPC_Value ($post->id , 'string');
$id = new XML_RPC_Value ($post, 'string');
$request = new XML_RPC_Message (
new XML_RPC_Value (true , 'boolean')
}//public function deletePost($post)
* 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)
* Sets the blog id to use (some blogging APIs support multiple
* blogs with one account)
* @param int $nBlogId Id of the blog to use
$this->userdata['rpc_blogid'] = new XML_RPC_Value ($nBlogId, 'string');
}//public function setBlogId($nBlogId)
* Returns the id of the currently used blog.
}//public function getBlogId()
* Returns an array of blogs for that account.
* @return array Array of Services_Blogging_Blog
$request = new XML_RPC_Message (
foreach ($blogs as $blog) {
}//public function getBlogs()
* Implements the blogger.getTemplate() method. The BlogID of the blog for which
* the template must be retrieved and the template type are passed as parameters.
* The template type is usually one of 'main' or 'archiveIndex'. The template in
* HTML format is returned.
* A template is the HTML code that represents the format of your blog. It is
* best to first examine the code that is returned by using this method;
* modifying it to suit your requirements, and then updating the template
* using the setTemplate() method.
* @param string $tempType The type of template to retrived. Usually either
* 'main' or 'archiveIndex'.
* @return string The template in HTML form.
if ($tempType != 'main' && $tempType != 'archiveIndex') {
self ::ERROR_UNKNOWN_TEMPLATE );
$request = new XML_RPC_Message (
new XML_RPC_Value ($tempType, 'string')
}//public function getTemplate($tempType)
* Implements the blogger.setTemplate() method. The BlogID of the blog for which
* the template is to be set, the template type (again: 'main' or 'archiveIndex')
* and the actual template in the HTML format are passed as parameters.
* See the docblock for the getTemplate() to find out what a template is.
* @param string $blogid The BlogID of the blog for which the template is
* to be set. (As returned by the getUsersBlogs()
* @param string $tempType The type of the template being set. Either 'main'
* @param string $template The actual template in the HTML format.
* @return boolean Whether or not the template was set.
if($tempType != 'main' && $tempType != 'archiveIndex') {
self ::ERROR_UNKNOWN_TEMPLATE );
$request = new XML_RPC_Message (
new XML_RPC_Value ($tempType, 'string'),
new XML_RPC_Value ($template, 'string')
}//public function setTemplate($tempType, $template)
return array ('main', 'archiveIndex');
}//public function getSupportedTemplates()
}//class Services_Blogging_Driver_Blogger extends Services_Blogging_Driver implements Services_Blogging_MultipleBlogsInterface
Documentation generated on Mon, 11 Mar 2019 14:57:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|