[pLog-svn] r4041 - in plog/branches/lifetype-1.1.1/class:
net/xmlrpc test/tests/net/xmlrpc
pwestbro at devel.lifetype.net
pwestbro at devel.lifetype.net
Sun Sep 24 22:16:15 GMT 2006
Author: pwestbro
Date: 2006-09-24 22:16:14 +0000 (Sun, 24 Sep 2006)
New Revision: 4041
Modified:
plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php
plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php
Log:
Added support for the MovableType xmlrpc api. This allows the extended text
to be specified for posts, without having to manually type the
POST_EXTENDED_TEXT_MODIFIER string.
Also, once LifeType natively supports tags, the protocol to make a new post
can include the "keywords".
But since we need continue supoprt for Blogger and metaWeblog, I didn't want
to disable having the extended text appended to the description, with the
POST_EXTENDED_TEXT_MODIFIER. So the "xmlrpc_movabletype_enabled" setting
can be used to change the behavior.
I am hoping that tonight I can write a quick plugin to allow the users to
enable/disable this behavior.
Modified: plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php 2006-09-24 21:06:00 UTC (rev 4040)
+++ plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php 2006-09-24 22:16:14 UTC (rev 4041)
@@ -36,7 +36,11 @@
"metaWeblog.getPost" => "this:metaWeblogGetPost",
"metaWeblog.getRecentPosts" => "this:metaWeblogGetRecentPosts",
"metaWeblog.getCategories" => "this:metaWeblogGetCategories",
- "metaWeblog.newMediaObject" => "this:metaWeblogNewMediaObject"
+ "metaWeblog.newMediaObject" => "this:metaWeblogNewMediaObject",
+ "mt.getCategoryList" => "this:mtGetCategoryList",
+ "mt.supportedTextFilters" => "this:mtSupportedTextFilters",
+ "mt.getPostCategories" => "this:mtGetPostCategories",
+ "mt.setPostCategories" => "this:mtSetPostCategories"
));
}
else {
@@ -206,7 +210,20 @@
//}
$title = $content["title"];
- $body = $content["description"];
+
+ // Check to see if the MovableType extnensions have been added
+ $mt_excerpt = $content["mt_excerpt"];
+ $mt_text_more = $content["mt_text_more"];
+ $mt_allow_comments = $content["mt_allow_comments"];
+
+ if ( $mt_text_more != NULL && trim($mt_text_more != ""))
+ {
+ $body = $content["description"] . POST_EXTENDED_TEXT_MODIFIER . $mt_text_more;
+ }
+ else
+ {
+ $body = $content["description"];
+ }
$catList = $content["categories"];
$categoryName = NULL;
@@ -242,6 +259,16 @@
$userInfo = $users->getUserInfoFromUsername( $username );
+ // Initially assume that comments are enabled
+ $enableComments = true;
+
+ // Was a setting specified in the MovableType fields?
+ if ($mt_allow_comments != NULL)
+ {
+ $enableComments = $mt_allow_comments;
+ }
+
+
$article = new Article(
$title,
$body, // text
@@ -250,7 +277,7 @@
$blogid, // blogid
$status,
0, // numread
- Array( "comments_enabled" => true ) // enable comments
+ Array( "comments_enabled" => $enableComments )
);
$dateCreated = $content['dateCreated'];
@@ -375,6 +402,46 @@
}
}
+ function mtGetCategoryList($args)
+ {
+ $users = new Users();
+ $category = new ArticleCategories();
+ $blogsG = new Blogs();
+
+ $blogid = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ $auth = $users->authenticateUser( $username, $password );
+
+ if ($auth)
+ {
+ $blogInfo = $blogsG->getBlogInfo( $blogid );
+ if( !$blogInfo ) {
+ return new IXR_Error(-1, 'Incorrect blog id');
+ }
+
+ $cats = $category->getBlogCategories($blogid);
+ $url = $blogInfo->getBlogRequestGenerator();
+ $ret = array();
+ foreach($cats as $cat)
+ {
+ $dummy = array();
+ $dummy["categoryId"] = $cat->getId();
+ $dummy["categoryName"] = $cat->getName();
+
+ $ret[] = $dummy;
+ }
+
+ $this->setResponseCharset( $blogInfo );
+
+ return $ret;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
function getPost($args)
{
$users = new Users();
@@ -466,7 +533,18 @@
$dummy["userid"] = $userInfo->getId();
$dummy["dateCreated"] = new IXR_Date($time);
$dummy["title"] = $item->getTopic();
- $dummy["description"] = $item->getText(false);
+
+ $blogSettings = $blogInfo->getSettings();
+
+ $useMovableType = $blogSettings->getValue( "xmlrpc_movabletype_enabled" );
+ if ( $useMovableType )
+ {
+ $dummy["description"] = $item->getIntroText();
+ }
+ else
+ {
+ $dummy["description"] = $item->getText(false);
+ }
$dummy["postid"] = $item->getId();
$dummy["link"] = $url->postLink( $item );
@@ -477,6 +555,11 @@
$catArray[] = $category->getName();
}
$dummy["categories"] = $catArray;
+
+ // The MovableType Extensions
+ $dummy["mt_text_more"] = $item->getExtendedText();
+ $dummy["mt_allow_comments"] = $item->getCommentsEnabled();
+
$this->setResponseCharset( $blogInfo );
@@ -594,8 +677,21 @@
$status = POST_STATUS_DRAFT;
}
- $title = $content["title"];
- $body = $content["description"];
+ $title = $content["title"];
+
+ // Check to see if the MovableType extnensions have been added
+ $mt_excerpt = $content["mt_excerpt"];
+ $mt_text_more = $content["mt_text_more"];
+ $mt_allow_comments = $content["mt_allow_comments"];
+
+ if ( $mt_text_more != NULL && trim($mt_text_more) != "")
+ {
+ $body = $content["description"] . POST_EXTENDED_TEXT_MODIFIER . $mt_text_more;
+ }
+ else
+ {
+ $body = $content["description"];
+ }
$article = $articles->getBlogArticle($postid,
-1, // blogId
@@ -624,17 +720,21 @@
}
}
}
+ $article->setCategoryIds( $categories );
}
- else {
+ else if ( count($article->getCategories()) == 0) {
+ // Only assign a new category if there isn't one
+
// if no category, let's pick a random one
$blogCategory = array_pop( $cats );
$categories[] = $blogCategory->getId();
+
+ $article->setCategoryIds( $categories );
}
$article->setText($body);
$article->setTopic($title);
$article->setStatus($status);
- $article->setCategoryIds( $categories );
// Get the plugin manager
$plugMgr =& PluginManager::getPluginManager();
@@ -693,6 +793,9 @@
// Send the EVENT_PRE_POST_DELETE message
$plugMgr->notifyEvent( EVENT_PRE_POST_DELETE, Array( "article" => &$article ));
+ $blogid = $article->getBlog();
+ $blogInfo = $article->getBlogInfo();
+
$articles->deleteArticle(
$postid,
$userInfo->getId(), // userid
@@ -702,10 +805,8 @@
// Send the EVENT_POST_POST_DELETE messages to the plugins
$plugMgr->notifyEvent( EVENT_POST_POST_DELETE, Array( "article" => &$article ));
- $blogid = $article->getBlog();
CacheControl::resetBlogCache( $blogid );
- $blogInfo = $article->getBlogInfo();
$this->setResponseCharset( $blogInfo );
return true;
@@ -797,6 +898,14 @@
-1 // category id
);
+ $blogs = new Blogs();
+ $blogInfo = $blogs->getBlogInfo( $blogid );
+ $url = $blogInfo->getBlogRequestGenerator();
+
+ $blogSettings = $blogInfo->getSettings();
+
+ $useMovableType = $blogSettings->getValue( "xmlrpc_movabletype_enabled" );
+
foreach($list as $item)
{
$dateObject = $item->getDateObject();
@@ -811,17 +920,30 @@
$dummy["userid"] = $userInfo->getId();
$dummy["dateCreated"] = new IXR_Date($time);
$dummy["title"] = $item->getTopic();
- $dummy["description"] = $item->getText(false);
+
+ if ( $useMovableType )
+ {
+ $dummy["description"] = $item->getIntroText();
+ }
+ else
+ {
+ $dummy["description"] = $item->getText(false);
+ }
$dummy["postid"] = $item->getId();
- $blogInfo = $item->getBlogInfo();
- $url = $blogInfo->getBlogRequestGenerator();
$dummy["link"] = $url->postLink( $item );
$dummy["permaLink"] = $url->postPermalink( $item );
$catArray = array();
- $catArray[] = $articleCat->getName();
- $dummy["categories"] = $catArray;
+ foreach( $item->getCategories() as $category ) {
+ $catArray[] = $category->getName();
+ }
+ $dummy["categories"] = $catArray;
+
+ // The MovableType Extensions
+ $dummy["mt_text_more"] = $item->getExtendedText();
+ $dummy["mt_allow_comments"] = $item->getCommentsEnabled();
+
$this->setResponseCharset( $blogInfo );
@@ -993,5 +1115,127 @@
return new IXR_Error(-1, 'You did not provide the correct password');
}
}
+
+ function mtSupportedTextFilters($args)
+ {
+ $ret = array();
+
+ return $ret;
+ }
+
+ function mtGetPostCategories($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+
+ $postid = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ $auth = $users->authenticateUser($username,$password);
+
+ if ($auth)
+ {
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ $item = $articles->getBlogArticle($postid,
+ -1, // blogId
+ true, // includeHiddenFields
+ -1, // date
+ -1, // categoryId
+ $userInfo->getId());
+
+ $blogId = $item->getBlog();
+ $blogs = new Blogs();
+ $blogInfo = $blogs->getBlogInfo( $blogId );
+
+ $catArray = array();
+ foreach( $item->getCategories() as $category ) {
+ $dummy = array();
+ $dummy["categoryId"] = $category->getId();
+ $dummy["categoryName"] = $category->getName();
+
+ $catArray[] = $dummy;
+
+ }
+
+ $this->setResponseCharset( $blogInfo );
+
+ return $catArray;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function mtSetPostCategories($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+
+ $postid = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $categories = $args[3];
+
+ $auth = $users->authenticateUser($username,$password);
+
+ if ($auth)
+ {
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ $article = $articles->getBlogArticle($postid,
+ -1, // blogId
+ true, // includeHiddenFields
+ -1, // date
+ -1, // categoryId
+ $userInfo->getId());
+
+ $blogId = $article->getBlog();
+ $blogInfo = $article->getBlogInfo();
+
+ $articleCategories = new ArticleCategories();
+
+
+ $catArray = Array();
+
+ if ( $categories != NULL )
+ {
+ foreach( $categories as $category ) {
+ // Get the category object for the category
+ $catArray[] = $category["categoryId"];
+ }
+ }
+
+ $article->setCategoryIds($catArray);
+
+ // Get the plugin manager
+ $plugMgr =& PluginManager::getPluginManager();
+ $plugMgr->setBlogInfo( $blogInfo );
+ $plugMgr->setUserInfo( $userInfo );
+ $plugMgr->loadPlugins();
+ // Send the EVENT_PRE_POST_UPDATE message
+ $plugMgr->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$article ));
+
+ $articles->updateArticle($article);
+
+ // Send the EVENT_POST_POST_UPDATE messages to the plugins
+ $plugMgr->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$article ));
+
+ CacheControl::resetBlogCache( $blogId );
+
+ $this->setResponseCharset( $blogInfo );
+
+ return true;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
}
?>
\ No newline at end of file
Modified: plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php 2006-09-24 21:06:00 UTC (rev 4040)
+++ plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php 2006-09-24 22:16:14 UTC (rev 4041)
@@ -590,6 +590,42 @@
$this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog),
"The blog encoding and the response of the XMLRPC request did not match!" );
+ /** test the extended text feature through MovableType**/
+ $content = array();
+ $content["title"] = "topic";
+ $content["description"] = "Intro text";
+ $content["mt_text_more"] = "Extended text";
+ $res = $c->query( "metaWeblog.newPost",
+ $this->blog->getId(),
+ $this->owner->getUsername(),
+ "password",
+ $content,
+ true );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" );
+
+ // get the post id and check it in the db
+ $artId = $c->getResponse();
+ $articles = new Articles();
+ $article = $articles->getArticle( $artId );
+ $this->assertTrue( $article, "Could not load article with id = ".$artId );
+ if( !$article )
+ return;
+ // check that the post has the expected values
+ $this->assertEquals( "topic", $article->getTopic());
+ $this->assertEquals( "Intro textExtended text", $article->getText());
+ $this->assertEquals( "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", $article->getText(false));
+ $this->assertEquals( "Intro text", $article->getIntroText());
+ $this->assertEquals( "Extended text", $article->getExtendedText());
+
+ // delete the article
+ $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true );
+
+ // get the response and see that it has the right encoding
+ $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog),
+ "The blog encoding and the response of the XMLRPC request did not match!" );
+
}
@@ -688,6 +724,67 @@
"The blog encoding and the response of the XMLRPC request did not match!" );
+
+ // EXTENDED TEXT, with extended text in mt_more_text
+ // create a new post first
+ $article = new Article(
+ "topic",
+ "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text",
+ Array( $this->cat->getId()),
+ $this->owner->getId(),
+ $this->blog->getId(),
+ POST_STATUS_PUBLISHED,
+ 0
+ );
+
+ // Store the setting that mt_more_text should be used
+ $blogSettings = $this->blog->getSettings();
+ $blogSettings->setValue( "xmlrpc_movabletype_enabled", true );
+ $this->blog->setSettings( $blogSettings );
+ $blogs = new Blogs();
+ $blogs->updateBlog( $this->blog );
+
+
+ $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" );
+
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "metaWeblog.getPost",
+ $article->getId(),
+ $this->owner->getUsername(),
+ "password" );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getPost" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "metaWeblog.getPost did not return a valid response" );
+
+ // and now compare that the returned values match with what we expected
+ $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" );
+ $this->assertEquals( "topic", $response["title"], "The topic of the post does not match" );
+ $this->assertEquals( "Intro text", $response["description"], "The text of the article does not match" );
+ $this->assertEquals( "Extended text", $response["mt_text_more"], "The text of the extended text does not match" );
+ $this->assertEquals( $article->getId(), $response["postid"] );
+ $url = $this->blog->getBlogRequestGenerator();
+ $this->assertEquals( $url->postLink( $article ), $response["link"], "The post permalink does not match" );
+ $this->assertEquals( $url->postPermalink( $article ), $response["permaLink"], "The post permalink does not match" );
+
+ $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ),
+ "Error deleting article" );
+
+ // get the response and see that it has the right encoding
+ $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ),
+ "The blog encoding and the response of the XMLRPC request did not match!" );
+
+ // Restore the setting
+ $blogSettings = $this->blog->getSettings();
+ $blogSettings->setValue( "xmlrpc_movabletype_enabled", false );
+ $this->blog->setSettings( $blogSettings );
+ $blogs->updateBlog( $this->blog );
+
+
}
/**
@@ -724,6 +821,34 @@
"The blog encoding and the response of the XMLRPC request did not match!" );
}
+ function testMTGetCategoryList()
+ {
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "mt.getCategoryList",
+ $this->blog->getId(),
+ $this->owner->getUsername(),
+ "password" );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.getCategoryList" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "mt.getCategoryList did not return a valid response" );
+
+ // there should only be one category
+ $this->assertTrue(( count( $response ) == 1 ), "There should only be one category returned by mt.getCategoryList" );
+
+ // check that the category settings are correct
+ $this->assertEquals( $this->cat->getName(), $response[0]["categoryName"], "The category name did not match" );
+ $this->assertEquals( $this->cat->getId(), $response[0]["categoryId"], "The category description did not match" );
+
+ // get the response and see that it has the right encoding
+ $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ),
+ "The blog encoding and the response of the XMLRPC request did not match!" );
+ }
+
function testMetaWeblogGetRecentPosts()
{
// create a new post first
@@ -776,6 +901,119 @@
}
+
+ function testMTSupportedTextFilters()
+ {
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "mt.supportedTextFilters");
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.supportedTextFilters" );
+
+ // make sure that the call returned ok
+ // there should be no filters
+ $response = $c->getResponse();
+ $this->assertFalse( $response, "mt.supportedTextFilters return an unexpected response" );
+
+ }
+
+ function testMTGetPostCategories()
+ {
+ // create a new post first
+ $article = new Article(
+ "topic",
+ "text",
+ Array( $this->cat->getId()),
+ $this->owner->getId(),
+ $this->blog->getId(),
+ POST_STATUS_PUBLISHED,
+ 0
+ );
+ $articles = new Articles();
+ $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" );
+
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "mt.getPostCategories",
+ $article->getId(),
+ $this->owner->getUsername(),
+ "password" );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.getPostCategories" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "mt.getPostCategories did not return a valid response" );
+
+
+ // There should only be one category
+ $this->assertEquals( 1, count($response), "The number of categories returned by mt.getPostCategories is not correct" );
+
+ // and now compare that the returned values match with what we expected
+ $this->assertEquals( $this->cat->getName(), $response[0]["categoryName"], "The category name did not match" );
+ $this->assertEquals( $this->cat->getId(), $response[0]["categoryId"], "The category description did not match" );
+
+ $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ),
+ "Error deleting article" );
+
+ // get the response and see that it has the right encoding
+ $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ),
+ "The blog encoding and the response of the XMLRPC request did not match!" );
+ }
+
+
+ function testMTSetPostCategories()
+ {
+ // create a new post first, with no category
+ $article = new Article(
+ "topic",
+ "text",
+ Array(),
+ $this->owner->getId(),
+ $this->blog->getId(),
+ POST_STATUS_PUBLISHED,
+ 0
+ );
+ $articles = new Articles();
+ $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" );
+
+ // Construct the Category Struct
+ $categories = Array();
+ $theCategory = Array();
+ $theCategory["categoryName"] = $this->cat->getName();
+ $theCategory["categoryId"] = $this->cat->getId();
+ $categories[] = $theCategory;
+
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "mt.setPostCategories",
+ $article->getId(),
+ $this->owner->getUsername(),
+ "password",
+ $categories
+ );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.setPostCategories" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "mt.setPostCategories did not return a valid response" );
+
+
+ // check that the post was successfully updated
+ $updatedArticle = $articles->getArticle( $article->getId());
+ $this->assertEquals( $this->cat->getId(), $updatedArticle->_categoryIds[0]);
+
+ // get the response and see that it has the right encoding
+ $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ),
+ "The blog encoding and the response of the XMLRPC request did not match!" );
+ }
+
+
+
/**
* @private
*/
More information about the pLog-svn
mailing list