This commit is contained in:
Glenn Bautista 2012-07-30 21:15:21 -07:00
commit efc4bff959
3 changed files with 122 additions and 10 deletions

View File

@ -23,6 +23,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
@ -69,6 +70,17 @@ 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)
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.
Another note: Please make sure that this module's main directory is named 'blog'. MetaWeblog won't work otherwise.
## Comments and Spam Protection
See [:pagecomment](/pagecomment) for creating Askimet-protected comments for every page.

View File

@ -159,6 +159,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
'tag',
'date',
'metaweblog',
'rsd',
'postblog' => 'BLOGMANAGEMENT',
'post' => 'BLOGMANAGEMENT',
'BlogEntryForm' => 'BLOGMANAGEMENT',
@ -291,6 +292,36 @@ class BlogHolder_Controller extends BlogTree_Controller {
$this->redirect($this->Link());
}
public function RSDLink() {
$url = $this->BaseHref() . $this->URLSegment . '/rsd';
return '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . $url . '" />';
}
public function RSD() {
$homepage = Director::absoluteBaseURL();
$controller = $homepage . "metaweblog";
return <<<RSD
<?xml version="1.0" ?>
<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd" >
<service>
<engineName>Silverstripe Blog</engineName>
<engineLink>http://silverstripe.org/blog-module/</engineLink>
<homePageLink>{$homepage}</homePageLink>
<apis>
<api name="MetaWeblog" preferred="true" apiLink="{$controller}" blogID="{$this->ID}" >
<settings>
<notes>This MetaWeblog implementation is currently limited. It is part of the Silverstripe Blog module</notes>
</settings>
</api>
</apis>
</service>
</rsd>
RSD;
}
}

View File

@ -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) {
// Create an xmlrpc server, and set up the method calls
@ -20,7 +24,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
@ -30,15 +37,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 <string> $username
* @param <string> $password
* @param <int> $blogid
* @return <DataObject> $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();
@ -65,10 +106,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();
@ -100,6 +138,37 @@ class MetaWeblogController extends Controller {
//TODO dummy function
return array();
}
/**
* Post a new Blog entry onto a Blog
*
* @param <int> $blogid
* @param <string> $username
* @param <string> $password
* @param <array> $struct
* @param <boolean> $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;
}
}
?>