Source for file LiveJournal.php
Documentation is available at LiveJournal.php
require_once 'Services/Blogging/ExtendedDriver.php';
require_once 'Services/Blogging/Exception.php';
require_once 'Services/Blogging/XmlRpc.php';
require_once 'XML/RPC.php';
* LiveJournal API implementation.
* This class implements the LiveJournal XML-RPC API described at
* http://www.livejournal.com/doc/server/ljp.csp.xml-rpc.protocol.html
* @package Services_Blogging
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* Requests shall be sent to here
* Internal list with user data.
Services_Blogging_Post ::TITLE ,
Services_Blogging_Post ::CONTENT ,
Services_Blogging_Post ::DATE ,
Services_Blogging_Post ::URL ,
* Constructor for the LiveJournal driver.
* 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'),
$this->rpc_client = new XML_RPC_Client (
$authenticate = new XML_RPC_Message (
'username' => $this->userdata['rpc_user'],
'auth_method' => new XML_RPC_Value ('challenge', 'string'),
'auth_challenge' => new XML_RPC_Value ($authdata['challenge'], 'string'),
'auth_response' => new XML_RPC_Value ($authdata['response'] , 'string'),
'clientversion' => new XML_RPC_Value ('PHP-Services_Blogging/0.0.1')
}//public function __construct($userid, $pass, $server = null, $path = null)
protected function md5_hex($string)
$md5 = md5($string, true ); //raw output
for ($nC = 0; $nC < strlen($md5); $nC++ ) {
}//protected function md5_hex($string)
//get challenge for authentication
$authenticate = new XML_RPC_Message ('LJ.XMLRPC.getchallenge', array ());
'challenge' => $response['challenge'],
}//protected function getAuthData()
* 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 ($time == '' || $time == 0 ) {
if ($post->id === null ) {
//post is new and has no Id => create new one
$request = new XML_RPC_Message ('LJ.XMLRPC.postevent',
'username' => $this->userdata['rpc_user'],
'auth_method' => new XML_RPC_Value ('challenge', 'string'),
'auth_challenge' => new XML_RPC_Value ($authdata['challenge'], 'string'),
'auth_response' => new XML_RPC_Value ($authdata['response'] , 'string'),
'lineendings' => new XML_RPC_Value ('pc'),
'year' => new XML_RPC_Value (date('Y', $time), 'int'),
'mon' => new XML_RPC_Value (date('n', $time), 'int'),
'day' => new XML_RPC_Value (date('j', $time), 'int'),
'hour' => new XML_RPC_Value (date('G', $time), 'int'),
'min' => new XML_RPC_Value (date('i', $time), 'int'),
$post->setId ($arData['itemid']);
//edit the post; it already exists
$request = new XML_RPC_Message ('LJ.XMLRPC.editevent',
'username' => $this->userdata['rpc_user'],
'auth_method' => new XML_RPC_Value ('challenge', 'string'),
'auth_challenge' => new XML_RPC_Value ($authdata['challenge'], 'string'),
'auth_response' => new XML_RPC_Value ($authdata['response'] , 'string'),
'itemid' => new XML_RPC_Value ($post->id , 'int'),
'lineendings' => new XML_RPC_Value ('pc'),
'year' => new XML_RPC_Value (date('Y', $time), 'int'),
'mon' => new XML_RPC_Value (date('n', $time), 'int'),
'day' => new XML_RPC_Value (date('j', $time), 'int'),
'hour' => new XML_RPC_Value (date('G', $time), 'int'),
'min' => new XML_RPC_Value (date('i', $time), 'int'),
}//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.
* In LiveJournal, posts are deleted by emptying
}//public function deletePost($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.
* @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 ('LJ.XMLRPC.getevents',
'username' => $this->userdata['rpc_user'],
'auth_method' => new XML_RPC_Value ('challenge', 'string'),
'auth_challenge' => new XML_RPC_Value ($authdata['challenge'], 'string'),
'auth_response' => new XML_RPC_Value ($authdata['response'] , 'string'),
'selecttype' => new XML_RPC_Value ('one', 'string'),
'itemid' => new XML_RPC_Value ($id, 'int')
if (count($arData['events']) == 0 ) {
}//public function getPost($id)
* 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 ('LJ.XMLRPC.getevents',
'username' => $this->userdata['rpc_user'],
'auth_method' => new XML_RPC_Value ('challenge', 'string'),
'auth_challenge' => new XML_RPC_Value ($authdata['challenge'], 'string'),
'auth_response' => new XML_RPC_Value ($authdata['response'] , 'string'),
'selecttype' => new XML_RPC_Value ('lastn', 'string'),
'howmany' => new XML_RPC_Value ($number, 'int')
foreach ($arData['events'] as $event) {
$arPosts[$post->id ] = $post;
}//public function getRecentPosts($number = 15)
* The getRecentPostTitles method is intended to retrieve the given number of
* post titles from a blog.
* The posts themselves can be retrieved with getPost() or getPosts().
* @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).
$request = new XML_RPC_Message ('LJ.XMLRPC.getevents',
'username' => $this->userdata['rpc_user'],
'auth_method' => new XML_RPC_Value ('challenge', 'string'),
'auth_challenge' => new XML_RPC_Value ($authdata['challenge'], 'string'),
'auth_response' => new XML_RPC_Value ($authdata['response'] , 'string'),
'selecttype' => new XML_RPC_Value ('lastn', 'string'),
'howmany' => new XML_RPC_Value ($number, 'int'),
'prefersubject' => new XML_RPC_Value (true , 'boolean'),
'truncate' => new XML_RPC_Value (50 , 'string'),
'noprops' => new XML_RPC_Value (true , 'boolean')
foreach ($arData['events'] as $event) {
$arTitles[$event['itemid']] = $event['event'];
}//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['eventtime'], 11 , 2 ),//hour
substr($arStruct['eventtime'], 14 , 2 ),//minute
substr($arStruct['eventtime'], 17 , 2 ),//second
substr($arStruct['eventtime'], 5 , 2 ),//month
substr($arStruct['eventtime'], 8 , 2 ),//day
substr($arStruct['eventtime'], 0 , 4 )//year
$post->setId ($arStruct['itemid']);
}//protected function convertStructToPost($arStruct)
}//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.
|