Saturday, November 13, 2004

Added metaWeblog support to plog

In a previous post, I mentioned how I was having problems getting ecto to work with plog. Since plog only implementsthe Blogger API, this does not have all of the features that I was looking for. I extended the xmlrpc.php file to include a partial metaWeblog support.


Here are the diffs:

142a143,201
> function metaWeblogNewPost($args)
> {
> global $users, $articles;
> $blogid = $args[0];

> $username = $args[1];

> $password = $args[2];

> $content = $args[3];

> $publish = $args[4]; // true post&publish | false post only

> /*
> int postid
> */
>
> // -mhe todo security
>
> $erg = $users->getUserInfo(
> $username,
> $password
> );
>
> if ($erg != false)
> {
> if ($publish)
> {
> $status = "published";
> } else
> {
> $status = "draft";
> }
>
> $title = $content["title"];

> $content = $content["description"];
>
>
>
> $article = new Article(
> $title,
> $content, // text
> _decode_category($blogid), // catid
> $erg->_id, // userid
> _decode_blogid($blogid), // blogid
> $status,
> 0, // numread
> Array( "comments_enabled" => true ) // enable comments
> );
> $article->setDate(date("YmdHis"));
> $postid = $articles->addArticle($article);
> if ($postid != 0)
> {
> return $postid;
> } else
> {
> return new IXR_Error(-1, 'Internal error occured creating your post!');
> }
> } else
> {
> return new IXR_Error(-1, 'You did not provide the correct password');
> }
> }
>
182a242,281
> function metaWeblogGetPost($args)
> {
> global $users, $articles;
> $postid = $args[0];
> $username = $args[1];
> $password = $args[2];

>
> /*
> "userid" =>
> "dateCreated" =>
> "content" =>
> "postid" =>
> */
>
> $erg = $users->getUserInfo($username,$password);
> if ($erg != false)
> {
> $item = $articles->getUserArticle($postid, $erg->_id);
> $time = mktime(
> substr($item->_date,8,2),
> substr($item->_date,10,2),
> substr($item->_date,12,2),
> substr($item->_date,4,2),
> substr($item->_date,6,2),
> substr($item->_date,0,4)
> );
>
> $dummy = array();
> $dummy["userid"] = $item->_userInfo->_id;
> $dummy["dateCreated"] = new IXR_Date($time);
> $dummy["title"] = $item->_topic;
> $dummy["description"] = $item->_text;

> $dummy["postid"] = $item->_id;
> return $dummy;
> } else
> {
> return new IXR_Error(-1, 'You did not provide the correct password');
> }
> }
>
229a329,370
> function metaWeblogEditPost($args)
> {
> global $users, $articles;
>
> $postid = $args[0];

> $username = $args[1];

> $password = $args[2];

> $content = $args[3];

> $publish = $args[4];

>
> /*
> boolean, true or false
> */
>
> $erg = $users->getUserInfo($username,$password);
> if ($erg != false)
> {
> if ($publish)
> {
> $status = "published";
> } else
> {
> $status = "draft";
> }
>
> $title = $content["title"];

> $content = $content["description"];
>
> $article = $articles->getUserArticle($postid);
> $article->setText($content);
> $article->setTopic($title);
> $article->setStatus($status);
>
> $articles->updateArticle($article);
>
> return true;
> } else
> {
> return new IXR_Error(-1, 'You did not provide the correct password');
> }
> }
>
311a453,505
> function metaWeblogGetRecentPosts($args)
> {
> global $users, $articles;
> /*
> "userid" =>
> "dateCreated" =>
> "content" =>
> "postid" =>
> */
> $blogid = $args[0];
> $username = $args[1];
> $password = $args[2];
> $number = $args[3];
>
> $erg = $users->getUserInfo($username,$password);
> if ($erg != false)
> {
> $ret = array();
> $list = $articles->getBlogArticles(
> _decode_blogid($blogid),
> -1,
> $number,
> _decode_category($blogid),
> 0
> );
>
> foreach($list as $item)
> {
> $time = mktime(
> substr($item->_date,8,2),
> substr($item->_date,10,2),
> substr($item->_date,12,2),
> substr($item->_date,4,2),
> substr($item->_date,6,2),
> substr($item->_date,0,4)
> );
>
> $dummy = array();
> $dummy["userid"] = $item->_userInfo->_id;
> $dummy["dateCreated"] = new IXR_Date($time);
> $dummy["title"] = $item->_topic;
> $dummy["description"] = $item->_text;

> $dummy["postid"] = $item->_id;
>
> $ret[] = $dummy;
> }
> return $ret;
> } else
> {
> return new IXR_Error(-1, 'You did not provide the correct password');
> }
> }
>
400c594,598
< "blogger.getUsersBlogs" => "getUsersBlogs"
---
> "blogger.getUsersBlogs" => "getUsersBlogs",
> &q


uot;metaWeblog.newPost" => "metaWeblogNewPost",
> "metaWeblog.editPost" => "metaWeblogEditPost",
> "metaWeblog.getPost" => "metaWeblogGetPost",
> "metaWeblog.getRecentPosts" => "metaWeblogGetRecentPosts"