diff --git a/README.md b/README.md
index 1d5e528..cf54d02 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ The blog module allows you to post blogs on your SilverStripe. It includes the a
* Archive widget
* Blog management widget
* RSS widget (will likely move in future)
+* MetaWeblog API support. (posting new blog entries using Posterous, and other blogging services that use this API).
## Configuration Options
@@ -38,6 +39,8 @@ We have chosen to go with the following page types to include with the blog modu
* BlogEntry: This is simply an entry/post for the blog.
+In order to activate RSD you have to put $RSDLink in Page.ss, or BlogHolder.ss (if it is located in templates, and not Layout). After doing this, just point the blog service to the BlogHolder's url during that service's configuration.
+
## Simple form for adding a post
@@ -65,6 +68,14 @@ for example: mysite/blog/2007/6 would show blog entries for June 2007
or: mysite/blog/2007 would show blog entries for 2007
+
+## Setting up MetaWeblog and RSD (Really Simple Discovery)
+
+MetaWeblogController::$MODERATE_PUBLISHING - indicates whether blog entries posted via the API will need manual approvial via the CMS. (default: false)
+
+MetaWeblogController::$RESTRICT_POST_TO_OWNER - restrict postings to the user defined as 'owner' in the blog holder (default: false)
+
+
## Comments and Spam Protection
See [:pagecomment](/pagecomment) for creating Askimet-protected comments for every page.
diff --git a/code/BlogHolder.php b/code/BlogHolder.php
index b50d830..d071319 100644
--- a/code/BlogHolder.php
+++ b/code/BlogHolder.php
@@ -157,6 +157,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
'tag',
'date',
'metaweblog',
+ 'rsd',
'postblog' => 'BLOGMANAGEMENT',
'post' => 'BLOGMANAGEMENT',
'BlogEntryForm' => 'BLOGMANAGEMENT',
@@ -286,6 +287,36 @@ class BlogHolder_Controller extends BlogTree_Controller {
Director::redirect($this->Link());
}
+
+ public function RSDLink() {
+
+ $url = $this->BaseHref() . $this->URLSegment . '/rsd';
+
+ return '';
+ }
+
+ public function RSD() {
+ $homepage = Director::absoluteBaseURL();
+ $controller = $homepage . "metaweblog";
+ return <<
+
+
+ Silverstripe Blog
+ http://silverstripe.org/blog-module/
+ {$homepage}
+
+
+
+ This MetaWeblog implementation is currently limited. It is part of the Silverstripe Blog module
+
+
+
+
+
+
+RSD;
+ }
}
diff --git a/code/MetaWeblogController.php b/code/MetaWeblogController.php
index 0b4041e..bf258f9 100644
--- a/code/MetaWeblogController.php
+++ b/code/MetaWeblogController.php
@@ -7,7 +7,11 @@ require_once(BASE_PATH . '/blog/thirdparty/xmlrpc/xmlrpc_wrappers.php');
/**
* MetaWeblogController provides the MetaWeblog API for SilverStripe blogs.
*/
-class MetaWeblogController extends Controller {
+class MetaWeblogController extends Controller {
+
+ static $MODERATE_PUBLISHING = false;
+ static $RESTRICT_POST_TO_OWNER = false;
+
function index($request) {
Debug::log(Debug::text($request));
@@ -21,7 +25,10 @@ class MetaWeblogController extends Controller {
),
'metaWeblog.getCategories' => array(
'function' => array($this, 'getCategories')
- )
+ ),
+ 'metaWeblog.newPost' => array(
+ 'function' => array($this, 'newPost')
+ )
), false);
// Use nice php functions, and call the service
@@ -31,15 +38,49 @@ class MetaWeblogController extends Controller {
// Tell SilverStripe not to try render a template
return false;
}
+
+ /**
+ * Authenticate the user.
+ *
+ * If blogid is not null, make sure that the user is the author of the blog
+ *
+ * @param $username
+ * @param $password
+ * @param $blogid
+ * @return $member
+ */
+ private function authenticate($username, $password, $blogid=null) {
+
+ $member = MemberAuthenticator::authenticate(array(
+ 'Email' => $username,
+ 'Password' => $password,
+ ));
+
+ if (!$member){
+ Debug::log(Debug::text("Authentication Failed for " . $username));
+ return false;
+ }
+
+ Session::set("loggedInAs",$member->ID);
+
+ if ($blogid && self::$RESTRICT_POST_TO_OWNER) {
+ $blogHolder = DataObject::get_one("BlogHolder", "`BlogHolder`.`ID` = " . (int) $blogid);
+
+ if ($blogHolder->OwnerID == $member->ID){
+ return $member;
+ }
+ }else {
+ return $member;
+ }
+
+ return false;
+ }
/**
* Get a list of BlogHolders the user has access to.
*/
function getUsersBlogs($appkey, $username, $password) {
- $member = MemberAuthenticator::authenticate(array(
- 'Email' => $username,
- 'Password' => $password,
- ));
+ $member = $this->authenticate($username, $password);
// TODO Throw approriate error.
if(!$member) die();
@@ -66,10 +107,7 @@ class MetaWeblogController extends Controller {
* Get the most recent posts on a blog.
*/
function getRecentPosts($blogid, $username, $password, $numberOfPosts) {
- $member = MemberAuthenticator::authenticate(array(
- 'Email' => $username,
- 'Password' => $password,
- ));
+ $member = $this->authenticate($username, $password);
// TODO Throw approriate error.
if(!$member) die();
@@ -101,6 +139,37 @@ class MetaWeblogController extends Controller {
//TODO dummy function
return array();
}
+
+
+ /**
+ * Post a new Blog entry onto a Blog
+ *
+ * @param $blogid
+ * @param $username
+ * @param $password
+ * @param $struct
+ * @param $publish
+ * @return Boolean
+ */
+ public function newPost($blogid, $username, $password, $struct, $publish) {
+ $member = $this->authenticate($username, $password, $blogid);
+
+ // TODO Throw approriate error.
+ if (!$member) die();
+
+ $blogEntry = new BlogEntry();
+ $blogEntry->setField("Title", $struct['title']);
+ $blogEntry->setField("Content", $struct['description']);
+ $blogEntry->setField("ParentID", $blogid);
+
+ $blogEntry->write();
+
+ if($publish && !self::$MODERATE_PUBLISHING){
+ $blogEntry->doPublish();
+ }
+
+ return true;
+ }
}
?>