[pLog-svn] r3991 - in plog/branches/lifetype-1.1.1: .
class/net/xmlrpc class/test/tests/net class/test/tests/net/xmlrpc
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Mon Sep 18 22:10:25 GMT 2006
Author: oscar
Date: 2006-09-18 22:10:25 +0000 (Mon, 18 Sep 2006)
New Revision: 3991
Added:
plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php
plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/
plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php
Modified:
plog/branches/lifetype-1.1.1/xmlrpc.php
Log:
fixing mantis issue 1047 (http://bugs.lifetype.net/view.php?id=1047) where the XML responses were not using the right character encoding proved to be a lot more difficult than I thought, so I ended up reorganizing the code that makes up the XMLRPC server a bit and moved it to its own class.
In order to make sure that everything still works as expected, I have written a full Blogger XMLRPC test suite and I am almost done with the metaWeblog one. These test suites have already proven invaluable as they helped detect plenty of inconsistencies in the API implementation and I was able to get rid of those nasty global objects once and for all.
Added: 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-18 22:04:10 UTC (rev 3990)
+++ plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php 2006-09-18 22:10:25 UTC (rev 3991)
@@ -0,0 +1,842 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php");
+ include_once( PLOG_CLASS_PATH."class/dao/article.class.php");
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php");
+ include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php");
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+ include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+
+ class XmlRpcServer extends IXR_Server
+ {
+ function XmlRpcServer()
+ {
+ $config =& Config::getConfig();
+ if ($config->getValue("xmlrpc_api_enabled"))
+ {
+ $this->IXR_Server(
+ array (
+ "blogger.newPost" => "this:newPost",
+ "blogger.getUserInfo" => "this:getUserInfo",
+ "blogger.getPost" => "this:getPost",
+ "blogger.editPost" => "this:editPost",
+ "blogger.deletePost" => "this:deletePost",
+ "blogger.getRecentPosts" => "this:getRecentPosts",
+ "blogger.getUserInfo" => "this:getUserInfo",
+ "blogger.getUsersBlogs" => "this:getUsersBlogs",
+ "metaWeblog.newPost" => "this:metaWeblogNewPost",
+ "metaWeblog.editPost" => "this:metaWeblogEditPost",
+ "metaWeblog.getPost" => "this:metaWeblogGetPost",
+ "metaWeblog.getRecentPosts" => "this:metaWeblogGetRecentPosts",
+ "metaWeblog.getCategories" => "this:metaWeblogGetCategories",
+ "metaWeblog.newMediaObject" => "this:metaWeblogNewMediaObject"
+ ));
+ }
+ else {
+ // xmlrpc_api disabled, no methods configured
+ $this->IXR_Server( Array ());
+ }
+ }
+
+ function newPost( $args )
+ {
+ $users = new Users();
+ $articles = new Articles();
+ $category = new ArticleCategories();
+ $blogsG = new Blogs();
+
+ $appkey = $args[0];
+ $blogid = $args[1];
+ $username = $args[2];
+ $password = $args[3];
+ $content = $args[4];
+ $publish = $args[5]; // true post&publish | false post only
+ /*
+ int postid
+ */
+
+ // -mhe todo security
+
+ $auth = $users->authenticateUser( $username, $password );
+
+ if ($auth)
+ {
+ if ($publish)
+ {
+ $status = POST_STATUS_PUBLISHED;
+ } else
+ {
+ $status = POST_STATUS_DRAFT;
+ }
+
+ // Get the default category
+ $cats = $category->getBlogCategories($blogid);
+
+ // some protection again blogs without categories
+ if( !$cats ) {
+ return new IXR_Error(-1, 'This blog does not have categories!');
+ }
+
+ foreach($cats as $cat)
+ {
+ $idCategory = $cat->getId();
+ // Stop here, we have a category
+ break;
+ }
+
+ // ecto sends the topic as <title>blah blah</title>rest of the body
+ if( preg_match( "/<title>(.*)<\/title>(.*)/i", $content, $matches )) {
+ $title = $matches[1];
+ $content = $matches[2];
+ }
+ else {
+ $dummy = explode("\n", $content);
+ if( count( $dummy ) == 1 ) {
+ $title = substr( $content, 0, 60 );
+ }
+ else {
+ $title = $dummy[0];
+ unset($dummy[0]);
+ $content = implode("\n", $dummy);
+ unset($dummy);
+ }
+ }
+
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ $article = new Article(
+ $title,
+ $content, // text
+ Array( $idCategory ), // catid
+ $userInfo->getId(), // userid
+ $blogid, // blogid
+ $status,
+ 0, // numread
+ Array( "comments_enabled" => true ) // enable comments
+ );
+
+ $article->setDate(date("YmdHis"));
+
+ $blogInfo = $blogsG->getBlogInfo( $blogid );
+
+ // Get the plugin manager
+ $plugMgr =& PluginManager::getPluginManager();
+ $plugMgr->setBlogInfo( $blogInfo);
+ $plugMgr->setUserInfo( $userInfo );
+ $plugMgr->loadPlugins();
+ // Send the PRE_POST_POST_ADD message
+ $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));
+
+ $postid = $articles->addArticle($article);
+
+ if ($postid != 0) {
+ // The post was successful
+ // Send the EVENT_POST_POST_ADD messages to the plugins
+ $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
+ CacheControl::resetBlogCache( $blogid );
+
+ $blogSettings = $blogInfo->getSettings();
+
+ // Add article notifcations if this is specified by the default setting.
+ if ($blogSettings->getValue( "default_send_notification" ))
+ {
+ require_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
+
+ $artNotifications = new ArticleNotifications();
+ $artNotifications->addNotification( $postid, $blogid, $userInfo->getId());
+ }
+
+ $this->setResponseCharset( $blogInfo );
+
+ return sprintf( "%d", $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');
+ }
+ }
+
+ /**
+ * @private
+ * sets the character set for responses
+ */
+ function setResponseCharset( $blog )
+ {
+ $locale = $blog->getLocale();
+ $this->defencoding = $locale->getCharset();
+ }
+
+
+ function metaWeblogGetCategories($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["description"] = $cat->getDescription();
+
+ // disable the generation of xhtml content or else the IXR_XMLRPC library will
+ // escape things twice!
+ $url->setXHTML( false );
+
+ $dummy["htmlUrl"] = $url->categoryLink( $cat );
+ $dummy["rssUrl"] = "http://";
+ $ret[$cat->getName()] = $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();
+ $articles = new Articles();
+
+ $appkey = $args[0];
+ $postid = $args[1];
+ $username = $args[2];
+ $password = $args[3];
+
+ /*
+ "userid" =>
+ "dateCreated" =>
+ "content" =>
+ "postid" =>
+ */
+
+ $auth = $users->authenticateUser($username,$password);
+ if ($auth)
+ {
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ $item = $articles->getBlogArticle($postid,
+ -1, // blogId
+ true, // includeHiddenFields
+ -1, // date
+ -1, // categoryId
+ $userInfo->getId());
+ $dateObject = $item->getDateObject();
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ // Get the unix time stamp
+ $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
+
+ $dummy = array();
+ $userInfo = $item->getUserInfo();
+ $dummy["userid"] = $userInfo->getId();
+ $dummy["dateCreated"] = new IXR_Date($time);
+ $dummy["content"] = $item->getTopic() . "\r\n" . $item->getText() . " ";
+ $dummy["postid"] = $item->getId();
+
+ $blogInfo = $item->getBlogInfo();
+
+ $this->setResponseCharset( $blogInfo );
+
+ return $dummy;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function metaWeblogGetPost($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());
+
+ $dateObject = $item->getDateObject();
+ // Get the unix time stamp
+ $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
+
+ $articleCat = $item->getCategory();
+
+ $blogId = $item->getBlog();
+ $blogs = new Blogs();
+ $blogInfo = $blogs->getBlogInfo( $blogId );
+ $url = $blogInfo->getBlogRequestGenerator();
+
+ $dummy = array();
+ $userInfo = $item->getUserInfo();
+ $dummy["userid"] = $userInfo->getId();
+ $dummy["dateCreated"] = new IXR_Date($time);
+ $dummy["title"] = $item->getTopic();
+ $dummy["description"] = $item->getText();
+ $dummy["postid"] = $item->getId();
+
+ $dummy["link"] = $url->postLink( $item );
+ $dummy["permaLink"] = $url->postPermalink( $item );
+
+ $catArray = array();
+ foreach( $item->getCategories() as $category ) {
+ $catArray[] = $category->getName();
+ }
+ $dummy["categories"] = $catArray;
+
+ $this->setResponseCharset( $blogInfo );
+
+ return $dummy;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function editPost($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+ $blogsG = new Blogs();
+
+ $appkey = $args[0];
+ $postid = $args[1];
+ $username = $args[2];
+ $password = $args[3];
+ $content = $args[4];
+ $publish = $args[5];
+
+ /*
+ boolean, true or false
+ */
+
+ $auth = $users->authenticateUser($username,$password);
+ if ($auth)
+ {
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ if ($publish)
+ {
+ $status = POST_STATUS_PUBLISHED;
+ } else
+ {
+ $status = POST_STATUS_DRAFT;
+ }
+
+ // fake topic
+ $dummy = explode("\n", $content);
+ if( count($dummy) == 1 ) {
+ $title = substr( $content, 0, 60 );
+ }
+ else {
+ $title = $dummy[0];
+ unset($dummy[0]);
+ $content = implode("\n", $dummy);
+ unset($dummy);
+ }
+
+ $article = $articles->getBlogArticle($postid,
+ -1, // blogId
+ true, // includeHiddenFields
+ -1, // date
+ -1, // categoryId
+ $userInfo->getId());
+ $article->setText($content);
+ $article->setTopic($title);
+ $article->setStatus($status);
+
+ // Get the plugin manager
+ $plugMgr =& PluginManager::getPluginManager();
+ $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
+ $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 ));
+
+ $blogid = $article->getBlog();
+ $blogInfo = $article->getBlogInfo();
+ CacheControl::resetBlogCache( $blogid );
+
+ $this->setResponseCharset( $blogInfo );
+
+ return true;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function metaWeblogEditPost($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+ $category = new ArticleCategories();
+
+ $postid = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $content = $args[3];
+ $publish = $args[4];
+
+ /*
+ boolean, true or false
+ */
+
+ $auth = $users->authenticateUser($username,$password);
+ if ($auth)
+ {
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ if ($publish)
+ {
+ $status = POST_STATUS_PUBLISHED;
+ } else
+ {
+ $status = POST_STATUS_DRAFT;
+ }
+
+ $title = $content["title"];
+ $body = $content["description"];
+
+ $article = $articles->getBlogArticle($postid,
+ -1, // blogId
+ true, // includeHiddenFields
+ -1, // date
+ -1, // categoryId
+ $userInfo->getId());
+
+ $catList = $content["categories"];
+ //
+ // :KLUDGE:
+ // not exactly the smartest and fastest bit of code ever but it seems to work :-)
+ //
+ $categories = Array();
+ $blogid = $article->getBlog();
+ $blogInfo = $article->getBlogInfo();
+ $cats = $category->getBlogCategories($blogid);
+ if ( $catList != NULL )
+ {
+ foreach( $catList as $categoryName ) {
+ foreach( $cats as $blogCategory ) {
+ $categoryName = trim($categoryName);
+ if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
+ {
+ $categories[] = $blogCategory->getId();
+ }
+ }
+ }
+ }
+ else {
+ // if no category, let's pick a random one
+ $blogCategory = array_pop( $cats );
+ $categories[] = $blogCategory->getId();
+ }
+
+ $article->setText($body);
+ $article->setTopic($title);
+ $article->setStatus($status);
+ $article->setCategoryIds( $categories );
+
+ // 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');
+ }
+ }
+
+ function deletePost($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+ $blogsG = new Blogs();
+
+ $appkey = $args[0];
+ $postid = $args[1];
+ $username = $args[2];
+ $password = $args[3];
+ $publish = $args[4];
+
+ // -mhe todo
+ $auth = $users->authenticateUser($username,$password);
+ if ($auth)
+ {
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ $article = $articles->getBlogArticle($postid,
+ -1, // blogId
+ true, // includeHiddenFields
+ -1, // date
+ -1, // categoryId
+ $userInfo->getId());
+
+ // Get the plugin manager
+ $plugMgr =& PluginManager::getPluginManager();
+ $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
+ $plugMgr->setUserInfo( $userInfo );
+ $plugMgr->loadPlugins();
+ // Send the EVENT_PRE_POST_DELETE message
+ $plugMgr->notifyEvent( EVENT_PRE_POST_DELETE, Array( "article" => &$article ));
+
+ $articles->deleteArticle(
+ $postid,
+ $userInfo->getId(), // userid
+ $article->getBlog()
+ );
+
+ // 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;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function getRecentPosts($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+ $blogs = new Blogs();
+
+ /*
+ "userid" =>
+ "dateCreated" =>
+ "content" =>
+ "postid" =>
+ */
+ $appkey = $args[0];
+ $blogid = $args[1];
+ $username = $args[2];
+ $password = $args[3];
+ $number = $args[4];
+
+ $auth = $users->authenticateUser($username,$password);
+ if ($auth)
+ {
+ $blogInfo = $blogs->getBlogInfo( $blogid );
+ if( !$blogInfo ) {
+ return new IXR_Error(-1, 'Incorrect blog id');
+ }
+
+ $ret = array();
+ $list = $articles->getBlogArticles(
+ $blogid,
+ -1,
+ $number,
+ -1
+ );
+
+ foreach($list as $item)
+ {
+ $dateObject = $item->getDateObject();
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ // Get the unix time stamp
+ $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
+
+ $dummy = array();
+ $userInfo = $item->getUserInfo();
+ $dummy["userid"] = $userInfo->getId();
+ $dummy["dateCreated"] = new IXR_Date($time);
+ $dummy["content"] = $item->getTopic() . "\r\n" . $item->getText() . " ";
+ $dummy["postid"] = $item->getId();
+
+ $ret[] = $dummy;
+ }
+
+ $this->setResponseCharset( $blogInfo );
+
+ return $ret;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function metaWeblogGetRecentPosts($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+
+ $blogid = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $number = $args[3];
+
+ $auth = $users->authenticateUser($username,$password);
+
+ if ($auth)
+ {
+ $ret = array();
+ $list = $articles->getBlogArticles(
+ $blogid,
+ -1, // date
+ $number, // number of articles
+ -1 // category id
+ );
+
+ foreach($list as $item)
+ {
+ $dateObject = $item->getDateObject();
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ // Get the unix time stamp
+ $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
+
+ $articleCat = $item->getCategory();
+
+ $dummy = array();
+ $userInfo = $item->getUserInfo();
+ $dummy["userid"] = $userInfo->getId();
+ $dummy["dateCreated"] = new IXR_Date($time);
+ $dummy["title"] = $item->getTopic();
+ $dummy["description"] = $item->getText();
+ $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;
+
+ $this->setResponseCharset( $blogInfo );
+
+ $ret[] = $dummy;
+ }
+ return $ret;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function metaWeblogNewMediaObject($args)
+ {
+ $users = new Users();
+ $articles = new Articles();
+ $blogsG = new Blogs();
+
+ $blogid = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $file = $args[3];
+
+ $auth = $users->authenticateUser($username,$password);
+ if ($auth)
+ {
+ // Save this file to the tmp directory
+
+ // Create a temp file
+ // Get the temp directory
+ /**if (!$tmp_dir = get_cfg_var('upload_tmp_dir')) {
+ $tmp_dir = dirname(tempnam('/tmp', ''));
+ }*/
+ $config =& Config::getConfig();
+ $tmp_dir = $config->getTempFolder();
+
+ // Remove all characters that would need to be urlencoded
+ // This may not be necessary, but this was causing problems when given file
+ // names with spaces in it.
+ $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name']));
+ // Make the tmp name
+ $tempFile = $tmp_dir . '/' . $tempFile;
+
+ // Open the file
+ if (!$handle = fopen( $tempFile, "wb" ) ) {
+ return new IXR_Error(-1, 'Could not open file');
+ }
+
+ // It appears that the data has already been decoded, no need to call base64_decode
+ $decodedBits = $file['bits'];
+ // Write the data to the file
+ if ( fwrite( $handle, $decodedBits ) === false ) {
+ return new IXR_Error(-1, 'Could not write to file');
+ }
+
+ // Close the file
+ fclose($handle);
+
+ // let the gallery library do its work...
+ $resources = new GalleryResources();
+
+ // Get the first album for this blog
+ $albums = new GalleryAlbums();
+ // get the list of albums for this blog
+ $albumArray = $albums->getUserAlbums( $blogid );
+ if ( $albumArray == NULL || count( $albumArray ) == 0 ) {
+ return new IXR_Error(-1, 'Could not find album');
+ }
+
+ // Add the resource to the first album
+ $resId = $resources->addResourceFromDisk( $blogid, $albumArray[0]->getId(),
+ basename($file['name']), $tempFile );
+ // Get the resource from the id
+ $resource = $resources->getResource( $resId, $blogid, $albumArray[0]->getId() );
+ // Now we need to get the url for the resource
+ $blogInfo = $blogsG->getBlogInfo( $blogid );
+ $url = $blogInfo->getBlogRequestGenerator();
+
+ $ret = $url->resourceDownloadLink( $resource );
+
+ $this->setResponseCharset( $blogInfo );
+
+ return $ret;
+ }
+ else {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function getUserInfo($args)
+ {
+ $appkeyp = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ $users = new Users();
+
+ $auth = $users->authenticateUser( $username, $password );
+
+ if ($auth)
+ {
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ $ret = array();
+ $ret["nickname"] = $userInfo->getUsername();
+ $ret["firstname"] = $userInfo->getUsername();
+ $ret["lastname"] = "";
+ $ret["email"] = $userInfo->getEmail();
+ $ret["userid"] = $userInfo->getId();
+ $ret["url"] = "";
+
+ // set the response encoding according to one of the blogs owned by this user
+ $blogs = $userInfo->getOwnBlogs();
+ if( count($blogs) > 0 ) {
+ $blogInfo = array_pop( $blogs );
+ $this->setResponseCharset( $blogInfo );
+ }
+
+ return $ret;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+
+ function getUsersBlogs($args)
+ {
+ $users = new Users();
+ $category = new ArticleCategories();
+
+ $appkey = $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ /*
+ "blogName" =>
+ "url" =>
+ "blogid" =>
+ */
+
+ $auth = $users->authenticateUser( $username, $password );
+
+ if ($auth)
+ {
+ $userInfo = $users->getUserInfoFromUsername( $username );
+
+ $blogs = $users->getUsersBlogs($userInfo->getId());
+ $ret = array();
+ foreach($blogs as $blog)
+ {
+ $dummy = array();
+ $dummy["blogid"] = $blog->_id;
+ $dummy["blogName"] = $blog->_blog;
+ $url = $blog->getBlogRequestGenerator();
+ $dummy["url"] = $url->blogLink();
+ $ret[] = $dummy;
+ }
+
+ // set the encoding as long as we've got at least one blog
+ if( count( $blogs ) > 0 ) {
+ $blogInfo = $blogs[0];
+ $this->setResponseCharset( $blogInfo );
+ }
+
+ return $ret;
+ } else
+ {
+ return new IXR_Error(-1, 'You did not provide the correct password');
+ }
+ }
+ }
+?>
\ No newline at end of file
Added: 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-18 22:04:10 UTC (rev 3990)
+++ plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php 2006-09-18 22:10:25 UTC (rev 3991)
@@ -0,0 +1,553 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/userstatus.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" );
+ include_once( PLOG_CLASS_PATH."class/net/url.class.php" );
+ include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
+
+ /**
+ * Unit test cases for xmlrpc.php
+ */
+ class XmlRpcServer_Test extends LifeTypeTestCase
+ {
+ /**
+ * dummy blog we'll be using during the tests
+ */
+ var $blog;
+
+ /**
+ * dummy blog owner
+ */
+ var $owner;
+
+ /**
+ * dummy category
+ */
+ var $cat;
+
+ /**
+ * URL pointing to this server's xmlrpc.php
+ */
+
+ function setUp()
+ {
+ // create the blog owner
+ $this->owner = new UserInfo( md5(time()), // name
+ "password", // password
+ "whatever at whatever.com", // email address
+ "", // about
+ "" );
+ $users = new Users();
+ if( !$users->addUser( $this->owner )) {
+ throw( new Exception( "Error adding test user" ));
+ die();
+ }
+
+ // load a UTF-8 locale
+ $zhLocale =& Locales::getLocale( "zh_CN" );
+
+ // create the test blog
+ $blogs = new Blogs();
+ $this->blog = null;
+ $this->blog = new BlogInfo( "test blog",
+ $this->owner->getId(),
+ "",
+ new BlogSettings());
+ $this->blog->setLocale( $zhLocale );
+ if( !$blogs->addBlog( $this->blog )) {
+ throw( new Exception( "Error adding test blog!" ));
+ die();
+ }
+
+ // add a default category
+ $this->cat = new ArticleCategory( "General",
+ "Description for category General",
+ $this->blog->getId(),
+ true );
+ $cats = new ArticleCategories();
+ if( !$cats->addArticleCategory( $this->cat )) {
+ throw( new Exception( "Error adding test category!" ));
+ die();
+ }
+
+ // get the URL pointing to xmlrpc.php
+ $config =& Config::getConfig();
+ $this->url = $config->getValue( "base_url" )."/xmlrpc.php";
+ }
+
+ function tearDown()
+ {
+ $users = new Users();
+ $users->deleteUser( $this->owner->getId());
+
+ $blogs = new Blogs();
+ $blogs->deleteBlog( $this->blog->getId());
+
+ $cats = new ArticleCategories();
+ $cats->deleteCategory( $this->cat->getId(), $this->blog->getId());
+ }
+
+ /**
+ * test the blogger.newPost method call
+ */
+ function testBloggerNewPost()
+ {
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "blogger.newPost",
+ "appkey",
+ $this->blog->getId(),
+ $this->owner->getUsername(),
+ "password",
+ "blah blah",
+ 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( "blah blah", $article->getText());
+ $this->assertEquals( "blah blah", $article->getTopic());
+
+ // 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!" );
+
+ /** test the embedded topic feature **/
+ $res = $c->query( "blogger.newPost",
+ "appkey",
+ $this->blog->getId(),
+ $this->owner->getUsername(),
+ "password",
+ "topic\nblah blah",
+ 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( "blah blah", $article->getText());
+ $this->assertEquals( "topic", $article->getTopic());
+
+ // 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!" );
+
+ }
+
+ /**
+ * test the blogger.getUserInfo method cal
+ */
+ function testBloggerGetUserInfo()
+ {
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "blogger.getUserInfo",
+ "appkey",
+ $this->owner->getUsername(),
+ "password" );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUserInfo" );
+
+ // and check the data in the response
+ $userData = $c->getResponse();
+
+ $this->assertEquals( $this->owner->getUsername(), $userData["nickname"], "The user nickname did not match!" );
+ $this->assertEquals( $this->owner->getUsername(), $userData["firstname"], "The user firstname did not match!" );
+ $this->assertEquals( $this->owner->getEmail(), $userData["email"], "The user email address did not match!" );
+ $this->assertEquals( $this->owner->getId(), $userData["userid"], "The user id 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!" );
+ }
+
+ /**
+ * test the blogger.getUserInfo method call
+ */
+ function testBloggerGetUsersBlogs()
+ {
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "blogger.getUsersBlogs",
+ "appkey",
+ $this->owner->getUsername(),
+ "password" );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUsersBlogs" );
+
+ // and check the data in the response
+ $blogs = $c->getResponse();
+ // there should be only one blog
+ $this->assertEquals( $this->blog->getId(), $blogs[0]["blogid"] );
+ $this->assertEquals( $this->blog->getBlog(), $blogs[0]["blogName"] );
+ $url = $this->blog->getBlogRequestGenerator();
+ $this->assertEquals( $url->blogLink(), $blogs[0]["url"] );
+
+ // 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!" );
+ }
+
+ /**
+ * test the blogger.editPost method call
+ */
+ function testBloggerEditPost()
+ {
+ // 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 article" );
+
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "blogger.editPost",
+ "appkey",
+ $article->getId(),
+ $this->owner->getUsername(),
+ "password",
+ "updated text",
+ true );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.editPost" );
+
+ // check the data in the response and make sure we got a 'true'
+ $success = $c->getResponse();
+ $this->assertTrue( $success, "XMLRPC server returned error while updating the post" );
+
+ // check that the post was successfully updated
+ $updatedArticle = $articles->getArticle( $article->getId());
+ // check that the text is the updated version
+ $this->assertEquals( "updated text", $updatedArticle->getText());
+ $this->assertEquals( "updated text", $updatedArticle->getTopic());
+
+ // 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!" );
+
+ /*** test the embedded topic feature ***/
+
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "blogger.editPost",
+ "appkey",
+ $article->getId(),
+ $this->owner->getUsername(),
+ "password",
+ "topic\nupdated text",
+ true );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.editPost" );
+
+ // check the data in the response and make sure we got a 'true'
+ $success = $c->getResponse();
+ $this->assertTrue( $success, "XMLRPC server returned error while updating the post" );
+
+ // check that the post was successfully updated
+ $updatedArticle = $articles->getArticle( $article->getId());
+ // check that the text is the updated version
+ $this->assertEquals( "updated text", $updatedArticle->getText(), "Article text did not mach the expected text!" );
+ $this->assertEquals( "topic", $updatedArticle->getTopic(), "Article topic was not set correctly" );
+
+ // 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!" );
+
+ // delete the post
+ $articles->deleteArticle( $updatedArticle->getId(), $this->owner->getId(), $this->blog->getId());
+ }
+
+ /**
+ * Test case the blogger.deletePost method call
+ */
+ function testBloggerDeletePost()
+ {
+ // 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( "blogger.deletePost",
+ "appkey",
+ $article->getId(),
+ $this->owner->getUsername(),
+ "password",
+ true );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.deletePost" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "blogger.deletePost did not return true" );
+
+ // check that the post was marked as 'deleted' in the database
+ $updatedArticle = $articles->getArticle( $article->getId());
+ $this->assertEquals( $updatedArticle->getStatus(),
+ POST_STATUS_DELETED,
+ "Article was not properly deleted after calling blogger.deletePost" );
+
+ // 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!" );
+ }
+
+ /**
+ * test case for blogger.getRecentPosts
+ */
+ function testBloggerGetRecentPosts()
+ {
+ // 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 the first tet article" );
+ $article2 = new Article(
+ "topic 2",
+ "text 2",
+ Array( $this->cat->getId()),
+ $this->owner->getId(),
+ $this->blog->getId(),
+ POST_STATUS_PUBLISHED,
+ 0
+ );
+ $this->assertTrue( $articles->addArticle( $article ), "Unable to add the second test article" );
+
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "blogger.getRecentPosts",
+ "appkey",
+ $this->blog->getId(),
+ $this->owner->getUsername(),
+ "password",
+ 10 );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getRecentPosts" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "blogger.getRecentPosts did not return a valid response" );
+ // and make sure that we got two articles
+ $this->assertEquals( 2, count($response), "The number of articles returned by blogger.getRecentPosts is not correct" );
+
+ // 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!" );
+
+ // delete the articles
+ $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true );
+ $articles->deleteArticle( $article2->getId(), $this->owner->getId(), $this->blog->getId(), true );
+ }
+
+ /**
+ * test case for blogger.getPost
+ */
+ function testBloggerGetPost()
+ {
+ // 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( "blogger.getPost",
+ "appkey",
+ $article->getId(),
+ $this->owner->getUsername(),
+ "password" );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getPost" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "blogger.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\ntext", $response["content"] );
+ $this->assertEquals( $article->getId(), $response["postid"] );
+
+ $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!" );
+ }
+
+ /**
+ * test case for the metaWeblog.getPost method call
+ */
+ function testMetaWeblogGetPost()
+ {
+ // 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( "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", $article->getTopic(), "The topic of the post does not match" );
+ $this->assertEquals( "text", $article->getText(), "The text of the article 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!" );
+ }
+
+ /**
+ * Test the metaWeblog.getCategories
+ */
+ function testMetaWeblogGetCategories()
+ {
+ // make the method call
+ $c = new IXR_Client( $this->url );
+ $res = $c->query( "metaWeblog.getCategories",
+ $this->blog->getId(),
+ $this->owner->getUsername(),
+ "password" );
+
+ // see that the call was successful
+ $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getCategories" );
+
+ // make sure that the call returned ok
+ $response = $c->getResponse();
+ $this->assertTrue( $response, "metaWeblog.getCategories 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 metaWeblog.getCategories" );
+
+ // check that the category settings are correct
+ $this->assertEquals( $this->cat->getName(), key($response), "The category name did not match" );
+ $this->assertEquals( $this->cat->getDescription(), $response["General"]["description"], "The category description did not match" );
+ $url = $this->blog->getBlogRequestGenerator();
+ $url->setXHTML( false );
+ $this->assertEquals( $url->categoryLink( $this->cat ), $response["General"]["htmlUrl"], "The category link 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()
+ {
+
+ }
+
+ /**
+ * @private
+ */
+ function checkResponseEncoding( $response, $blog )
+ {
+ // check the character encoding in the response
+ $numMatches = preg_match( "/<\\?xml.*version=\"1.0\".*encoding=\"(.*)\".*\?>.*/i",
+ $response,
+ $matches );
+ if( $numMatches != 1 )
+ return false;
+
+ $encoding = $matches[1];
+
+ // check that the blog encoding and what we got in the response is the same
+ $locale = $this->blog->getLocale();
+ $blogEncoding = $locale->getCharSet();
+
+ return( $locale->getCharset() == $encoding );
+ }
+ }
+?>
\ No newline at end of file
Modified: plog/branches/lifetype-1.1.1/xmlrpc.php
===================================================================
--- plog/branches/lifetype-1.1.1/xmlrpc.php 2006-09-18 22:04:10 UTC (rev 3990)
+++ plog/branches/lifetype-1.1.1/xmlrpc.php 2006-09-18 22:10:25 UTC (rev 3991)
@@ -4,946 +4,8 @@
define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
}
-
- // include required classes, dont know what, but it works for me :-)
-
- include_once( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" );
- include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
- include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
- include_once( PLOG_CLASS_PATH."class/dao/users.class.php");
- include_once( PLOG_CLASS_PATH."class/dao/article.class.php");
- include_once( PLOG_CLASS_PATH."class/dao/articles.class.php");
- include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php");
- include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
- include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
- include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
- include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
- include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
- include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/xmlrpc/xmlrpcserver.class.php" );
+ $server = new XmlRpcServer();
- // init database
- $_db = new Db;
- $adodb = $_db->getDb();
-
- // config object
- $config =& Config::getConfig();
-
- // users object
- $users = new Users;
-
- // articles object
- $articles = new Articles;
-
- // category object
- $category = new ArticleCategories;
-
- // blog object
- $blogsG = new Blogs;
-
-
-
- function newPost($args)
- {
- global $users, $articles, $category, $blogsG;
- $appkey = $args[0];
- $blogid = $args[1];
- $username = $args[2];
- $password = $args[3];
- $content = $args[4];
- $publish = $args[5]; // true post&publish | false post only
- /*
- int postid
- */
-
- // -mhe todo security
-
- $auth = $users->authenticateUser( $username, $password );
-
- if ($auth)
- {
- if ($publish)
- {
- $status = POST_STATUS_PUBLISHED;
- } else
- {
- $status = POST_STATUS_DRAFT;
- }
-
- // Get the default category
- $cats = $category->getBlogCategories($blogid);
-
- // some protection again blogs without categories
- if( !$cats ) {
- return new IXR_Error(-1, 'This blog does not have categories!');
- }
-
- foreach($cats as $cat)
- {
- $idCategory = $cat->getId();
- // Stop here, we have a category
- break;
- }
-
- // ecto sends the topic as <title>blah blah</title>rest of the body
- if( preg_match( "/<title>(.*)<\/title>(.*)/i", $content, $matches )) {
- $title = $matches[1];
- $content = $matches[2];
- }
- else {
- $dummy = explode("\n", $content);
- $title = $dummy[0];
- unset($dummy[0]);
- $content = implode("\n", $dummy);
- unset($dummy);
- }
-
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- $article = new Article(
- $title,
- $content, // text
- Array( $idCategory ), // catid
- $userInfo->getId(), // userid
- $blogid, // blogid
- $status,
- 0, // numread
- Array( "comments_enabled" => true ) // enable comments
- );
-
- $article->setDate(date("YmdHis"));
-
- $blogInfo = $blogsG->getBlogInfo( $blogid );
-
- // Get the plugin manager
- $plugMgr =& PluginManager::getPluginManager();
- $plugMgr->setBlogInfo( $blogInfo);
- $plugMgr->setUserInfo( $userInfo );
- $plugMgr->loadPlugins();
- // Send the PRE_POST_POST_ADD message
- $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));
-
- $postid = $articles->addArticle($article);
-
- if ($postid != 0) {
- // The post was successful
- // Send the EVENT_POST_POST_ADD messages to the plugins
- $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
- CacheControl::resetBlogCache( $blogid );
-
- $blogSettings = $blogInfo->getSettings();
-
- // Add article notifcations if this is specified by the default setting.
- if ($blogSettings->getValue( "default_send_notification" ))
- {
- require_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
-
- $artNotifications = new ArticleNotifications();
- $artNotifications->addNotification( $postid, $blogid, $userInfo->getId());
- }
-
-
- return sprintf( "%d", $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');
- }
- }
-
- function metaWeblogNewPost($args)
- {
- global $users, $articles, $category, $blogsG;
- $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
-
- $auth = $users->authenticateUser( $username, $password);
-
- if ($auth)
- {
- if ($publish)
- {
- $status = POST_STATUS_PUBLISHED;
- } else
- {
- $status = POST_STATUS_DRAFT;
- }
-
- // Get the default category
- //$cats = $category->getBlogCategories($blogid);
- //foreach($cats as $cat)
- //{
- // $idCategory = $cat->_id;
- // // Stop here, we have a category
- // break;
- //}
-
- $title = $content["title"];
- $body = $content["description"];
- $catList = $content["categories"];
- $categoryName = NULL;
-
- //
- // :KLUDGE:
- // not exactly the smartest and fastest bit of code ever but it seems to work :-)
- //
- $categories = Array();
- $cats = $category->getBlogCategories($blogid);
-
- // some protection again blogs without categories
- if( !$cats ) {
- return new IXR_Error(-1, 'This blog does not have categories!');
- }
-
- if ( $catList != NULL )
- {
- foreach( $catList as $categoryName ) {
- foreach( $cats as $blogCategory ) {
- $categoryName = trim($categoryName);
- if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
- {
- $categories[] = $blogCategory->getId();
- }
- }
- }
- }
- else {
- // if no category, let's pick a random one
- $blogCategory = array_pop( $cats );
- $categories[] = $blogCategory->getId();
- }
-
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- $article = new Article(
- $title,
- $body, // text
- $categories, // catid
- $userInfo->getId(), // userid
- $blogid, // blogid
- $status,
- 0, // numread
- Array( "comments_enabled" => true ) // enable comments
- );
-
- $dateCreated = $content['dateCreated'];
-
- // there must be a bug in the xmlrpc library, we're getting an object in $dateCreated
- // that does not have a type or anyhting, but it still is an object... kinda weird. Anyway,
- // clients like ecto do not allow to change the time an article is posted so this is not
- // too annoying, *yet*
- if (!empty($dateCreated))
- {
- // Convert the UTC time to local time, since articleDate is in local time
- $ar = localtime ( $dateCreated->getTimestamp() );
- $ar[5] += 1900; $ar[4]++;
- $localTimeStamp = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], $ar[8] );
- $articleDate = date("YmdHis", $localTimeStamp);
- } else
- {
- $articleDate = date("YmdHis");
- }
-
- $article->setDate($articleDate);
-
- $blogInfo = $blogsG->getBlogInfo( $blogid );
-
-
- // Get the plugin manager
- $plugMgr =& PluginManager::getPluginManager();
- $plugMgr->setBlogInfo( $blogInfo );
- $plugMgr->setUserInfo( $userInfo );
- $plugMgr->loadPlugins();
- // Send the PRE_POST_POST_ADD message
- $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));
-
- $postid = $articles->addArticle($article);
- if ($postid != 0)
- {
- // The post was successful
-
- // Send the EVENT_POST_POST_ADD messages to the plugins
- $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
-
- CacheControl::resetBlogCache( $blogid );
-
- $blogSettings = $blogInfo->getSettings();
-
- // Add article notifcations if this is specified by the default setting.
- if ($blogSettings->getValue( "default_send_notification" ))
- {
- require_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
-
- $artNotifications = new ArticleNotifications();
- $artNotifications->addNotification( $postid, $blogid, $userInfo->getId());
- }
-
- return sprintf( "%d", $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');
- }
- }
-
- function metaWeblogGetCategories($args)
- {
- global $users, $category, $blogsG;
- $blogid = $args[0];
- $username = $args[1];
- $password = $args[2];
- /*
- "description" =>
- "htmlUrl" =>
- "rssUrl" =>
- */
-
-
- $auth = $users->authenticateUser( $username, $password );
-
- if ($auth)
- {
- $cats = $category->getBlogCategories($blogid);
- $ret = array();
- foreach($cats as $cat)
- {
- $dummy = array();
- $dummy["description"] = $cat->_name;
-
- // We can't use $cat->_url becuase it is not set, so
- // we have to do this in long way
- $blogInfo = $blogsG->getBlogInfo( $blogid );
- $url = $blogInfo->getBlogRequestGenerator();
- // disable the generation of xhtml content or else the IXR_XMLRPC library will
- // escape things twice!
- $url->setXHTML( false );
-
- $dummy["htmlUrl"] = $url->categoryLink( $cat );
- $dummy["rssUrl"] = "http://";
- $ret[$cat->_name] = $dummy;
- }
- return $ret;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
-
- function getPost($args)
- {
- global $users, $articles;
- $appkey = $args[0];
- $postid = $args[1];
- $username = $args[2];
- $password = $args[3];
-
- /*
- "userid" =>
- "dateCreated" =>
- "content" =>
- "postid" =>
- */
-
- $auth = $users->authenticateUser($username,$password);
- if ($auth)
- {
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- $item = $articles->getBlogArticle($postid,
- -1, // blogId
- true, // includeHiddenFields
- -1, // date
- -1, // categoryId
- $userInfo->getId());
- $dateObject = $item->getDateObject();
- include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
- // Get the unix time stamp
- $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
-
- $dummy = array();
- $dummy["userid"] = $item->_userInfo->_id;
- $dummy["dateCreated"] = new IXR_Date($time);
- $dummy["content"] = $item->_topic . "\r\n" . $item->_text . " ";
- $dummy["postid"] = $item->_id;
- return $dummy;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function metaWeblogGetPost($args)
- {
- global $users, $articles;
- $postid = $args[0];
- $username = $args[1];
- $password = $args[2];
-
- /*
- "userid" =>
- "dateCreated" =>
- "content" =>
- "postid" =>
- */
-
- $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());
-
- $dateObject = $item->getDateObject();
- // Get the unix time stamp
- $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
-
- $articleCat = $item->getCategory();
-
- $blogId = $item->getBlog();
- $blogs = new Blogs();
- $blogInfo = $blogs->getBlogInfo( $blogId );
- $url = $blogInfo->getBlogRequestGenerator();
-
- $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;
-
- $dummy["link"] = $url->postLink( $item );
- $dummy["permaLink"] = $url->postPermalink( $item );
-
- $catArray = array();
- foreach( $item->getCategories() as $category ) {
- $catArray[] = $category->getName();
- }
- $dummy["categories"] = $catArray;
- return $dummy;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function editPost($args)
- {
- global $users, $articles, $blogsG;
-
- $appkey = $args[0];
- $postid = $args[1];
- $username = $args[2];
- $password = $args[3];
- $content = $args[4];
- $publish = $args[5];
-
- /*
- boolean, true or false
- */
-
- $auth = $users->authenticateUser($username,$password);
- if ($auth)
- {
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- if ($publish)
- {
- $status = POST_STATUS_PUBLISHED;
- } else
- {
- $status = POST_STATUS_DRAFT;
- }
-
- // fake topic
- $dummy = explode("\n", $content);
- $title = $dummy[0];
- unset($dummy[0]);
- $content = implode("\n", $dummy);
- unset($dummy);
-
- $article = $articles->getBlogArticle($postid,
- -1, // blogId
- true, // includeHiddenFields
- -1, // date
- -1, // categoryId
- $userInfo->getId());
- $article->setText($content);
- $article->setTopic($title);
- $article->setStatus($status);
-
- // Get the plugin manager
- $plugMgr =& PluginManager::getPluginManager();
- $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
- $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 ));
-
- $blogid = $article->getBlog();
- CacheControl::resetBlogCache( $blogid );
-
- return true;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function metaWeblogEditPost($args)
- {
- global $users, $articles, $category, $blogsG;
-
- $postid = $args[0];
- $username = $args[1];
- $password = $args[2];
- $content = $args[3];
- $publish = $args[4];
-
- /*
- boolean, true or false
- */
-
- $auth = $users->authenticateUser($username,$password);
- if ($auth)
- {
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- if ($publish)
- {
- $status = POST_STATUS_PUBLISHED;
- } else
- {
- $status = POST_STATUS_DRAFT;
- }
-
- $title = $content["title"];
- $body = $content["description"];
-
- $article = $articles->getBlogArticle($postid,
- -1, // blogId
- true, // includeHiddenFields
- -1, // date
- -1, // categoryId
- $userInfo->getId());
-
- $catList = $content["categories"];
- //
- // :KLUDGE:
- // not exactly the smartest and fastest bit of code ever but it seems to work :-)
- //
- $categories = Array();
- $blogid = $article->getBlog();
- $cats = $category->getBlogCategories($blogid);
- if ( $catList != NULL )
- {
- foreach( $catList as $categoryName ) {
- foreach( $cats as $blogCategory ) {
- $categoryName = trim($categoryName);
- if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
- {
- $categories[] = $blogCategory->getId();
- }
- }
- }
- }
- else {
- // if no category, let's pick a random one
- $blogCategory = array_pop( $cats );
- $categories[] = $blogCategory->getId();
- }
-
- $article->setText($body);
- $article->setTopic($title);
- $article->setStatus($status);
- $article->setCategoryIds( $categories );
-
- // Get the plugin manager
- $plugMgr =& PluginManager::getPluginManager();
- $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $blogid ) );
- $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 );
-
- return true;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function deletePost($args)
- {
- global $users, $articles, $blogsG;
-
- $appkey = $args[0];
- $postid = $args[1];
- $username = $args[2];
- $password = $args[3];
- $publish = $args[4];
-
- // -mhe todo
- $auth = $users->authenticateUser($username,$password);
- if ($auth)
- {
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- $article = $articles->getBlogArticle($postid,
- -1, // blogId
- true, // includeHiddenFields
- -1, // date
- -1, // categoryId
- $userInfo->getId());
-
- // Get the plugin manager
- $plugMgr =& PluginManager::getPluginManager();
- $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
- $plugMgr->setUserInfo( $userInfo );
- $plugMgr->loadPlugins();
- // Send the EVENT_PRE_POST_DELETE message
- $plugMgr->notifyEvent( EVENT_PRE_POST_DELETE, Array( "article" => &$article ));
-
- $articles->deleteArticle(
- $postid,
- $userInfo->getId(), // userid
- $article->getBlog()
- );
-
- // 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 );
-
- return true;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function getRecentPosts($args)
- {
- global $users, $articles;
- /*
- "userid" =>
- "dateCreated" =>
- "content" =>
- "postid" =>
- */
- $appkey = $args[0];
- $blogid = $args[1];
- $username = $args[2];
- $password = $args[3];
- $number = $args[4];
-
- $auth = $users->authenticateUser($username,$password);
- if ($auth)
- {
- $ret = array();
- $list = $articles->getBlogArticles(
- $blogid,
- -1,
- $number,
- -1
- );
-
- foreach($list as $item)
- {
- $dateObject = $item->getDateObject();
- include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
- // Get the unix time stamp
- $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
-
- $dummy = array();
- $dummy["userid"] = $item->_userInfo->_id;
- $dummy["dateCreated"] = new IXR_Date($time);
- $dummy["content"] = $item->_topic . "\r\n" . $item->_text . " ";
- $dummy["postid"] = $item->_id;
-
- $ret[] = $dummy;
- }
- return $ret;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function metaWeblogGetRecentPosts($args)
- {
- global $users, $articles;
- /*
- "userid" =>
- "dateCreated" =>
- "content" =>
- "postid" =>
- */
- $blogid = $args[0];
- $username = $args[1];
- $password = $args[2];
- $number = $args[3];
-
- $auth = $users->authenticateUser($username,$password);
-
- if ($auth)
- {
- $ret = array();
- $list = $articles->getBlogArticles(
- $blogid,
- -1, // date
- $number, // number of articles
- -1 // category id
- );
-
- foreach($list as $item)
- {
- $dateObject = $item->getDateObject();
- include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
- // Get the unix time stamp
- $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
-
- $articleCat = $item->getCategory();
-
- $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;
-
- $blogId = $item->getBlog();
- $blogs = new Blogs();
- $blogInfo = $blogs->getBlogInfo( $blogId );
- $url = $blogInfo->getBlogRequestGenerator();
- $dummy["link"] = $url->postLink( $item );
- $dummy["permaLink"] = $url->postPermalink( $item );
-
- $catArray = array();
- $catArray[] = $articleCat->getName();
- $dummy["categories"] = $catArray;
-
- $ret[] = $dummy;
- }
- return $ret;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function metaWeblogNewMediaObject($args)
- {
- global $users, $articles, $blogsG;
- /*
- "userid" =>
- "dateCreated" =>
- "content" =>
- "postid" =>
- */
- $blogid = $args[0];
- $username = $args[1];
- $password = $args[2];
- $file = $args[3];
-
- $auth = $users->authenticateUser($username,$password);
- if ($auth)
- {
- // Save this file to the tmp directory
-
- // Create a temp file
- // Get the temp directory
- /**if (!$tmp_dir = get_cfg_var('upload_tmp_dir')) {
- $tmp_dir = dirname(tempnam('/tmp', ''));
- }*/
- $config =& Config::getConfig();
- $tmp_dir = $config->getTempFolder();
-
- // Remove all characters that would need to be urlencoded
- // This may not be necessary, but this was causing problems when given file
- // names with spaces in it.
- $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name']));
- // Make the tmp name
- $tempFile = $tmp_dir . '/' . $tempFile;
-
- // Open the file
- if (!$handle = fopen( $tempFile, "wb" ) ) {
- return new IXR_Error(-1, 'Could not open file');
- }
-
- // It appears that the data has already been decoded, no need to call base64_decode
- $decodedBits = $file['bits'];
- // Write the data to the file
- if ( fwrite( $handle, $decodedBits ) === false ) {
- return new IXR_Error(-1, 'Could not write to file');
- }
-
- // Close the file
- fclose($handle);
-
- // let the gallery library do its work...
- $resources = new GalleryResources();
-
- // Get the first album for this blog
- $albums = new GalleryAlbums();
- // get the list of albums for this blog
- $albumArray = $albums->getUserAlbums( $blogid );
- if ( $albumArray == NULL || count( $albumArray ) == 0 ) {
- return new IXR_Error(-1, 'Could not find album');
- }
-
- // Add the resource to the first album
- $resId = $resources->addResourceFromDisk( $blogid, $albumArray[0]->getId(),
- basename($file['name']), $tempFile );
- // Get the resource from the id
- $resource = $resources->getResource( $resId, $blogid, $albumArray[0]->getId() );
- // Now we need to get the url for the resource
- $blogInfo = $blogsG->getBlogInfo( $blogid );
- $url = $blogInfo->getBlogRequestGenerator();
-
- $ret = $url->resourceDownloadLink( $resource );
-
- return $ret;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function getUserInfo($args)
- {
- $appkeyp = $args[0];
- $username = $args[1];
- $password = $args[2];
- /*
- "nickname" =>
- "firstname" =>
- "lastname" =>
- "email" =>
- "userid" =>
- "url" =>
- */
-
- $users = new Users();
-
- $auth = $users->authenticateUser( $username, $password );
-
- if ($auth)
- {
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- $ret = array();
- $ret["nickname"] = $userInfo->getUsername();
- $ret["firstname"] = $userInfo->getUsername();
- $ret["lastname"] = "";
- $ret["email"] = $userInfo->getEmail();
- $ret["userid"] = $userInfo->getId();
- $ret["url"] = "";
- return $ret;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- function getUsersBlogs($args)
- {
- global $users, $category;
- $appkey = $args[0];
- $username = $args[1];
- $password = $args[2];
- /*
- "blogName" =>
- "url" =>
- "blogid" =>
- */
-
- $auth = $users->authenticateUser( $username, $password );
-
- if ($auth)
- {
- $userInfo = $users->getUserInfoFromUsername( $username );
-
- $blogs = $users->getUsersBlogs($userInfo->getId());
- $ret = array();
- foreach($blogs as $blog)
- {
- $dummy = array();
- $dummy["blogid"] = $blog->_id;
- $dummy["blogName"] = $blog->_blog;
- $url = $blog->getBlogRequestGenerator();
- $dummy["url"] = $url->blogLink();
- $ret[] = $dummy;
- }
- return $ret;
- } else
- {
- return new IXR_Error(-1, 'You did not provide the correct password');
- }
- }
-
- if ($config->getValue("xmlrpc_api_enabled"))
- {
- $xmlrpc = new IXR_Server(
- array (
- "blogger.newPost" => "newPost",
- "blogger.getUserInfo" => "getUserInfo",
- "blogger.getPost" => "getPost",
- "blogger.editPost" => "editPost",
- "blogger.deletePost" => "deletePost",
- "blogger.getRecentPosts" => "getRecentPosts",
- "blogger.getUserInfo" => "getUserInfo",
- "blogger.getUsersBlogs" => "getUsersBlogs",
- "metaWeblog.newPost" => "metaWeblogNewPost",
- "metaWeblog.editPost" => "metaWeblogEditPost",
- "metaWeblog.getPost" => "metaWeblogGetPost",
- "metaWeblog.getRecentPosts" => "metaWeblogGetRecentPosts",
- "metaWeblog.getCategories" => "metaWeblogGetCategories",
- "metaWeblog.newMediaObject" => "metaWeblogNewMediaObject"
- )
- );
- } else
- {
- // xmlrpc_api disabled, no methods configured
- $xmlrpc = new IXR_Server(
- array (
- )
- );
-
- }
?>
More information about the pLog-svn
mailing list