2013-01-09 04:53:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhameBlogFeedController extends PhameController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function shouldRequireLogin() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$blog = id(new PhameBlogQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
if (!$blog) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$posts = id(new PhamePostQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withBlogPHIDs(array($blog->getPHID()))
|
|
|
|
->withVisibility(PhamePost::VISIBILITY_PUBLISHED)
|
|
|
|
->execute();
|
|
|
|
|
2013-04-12 01:10:09 +02:00
|
|
|
$blog_uri = PhabricatorEnv::getProductionURI(
|
|
|
|
$this->getApplicationURI('blog/feed/'.$blog->getID().'/'));
|
2013-01-09 04:53:34 +01:00
|
|
|
$content = array();
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = phutil_tag('title', array(), $blog->getName());
|
2013-04-12 01:10:09 +02:00
|
|
|
$content[] = phutil_tag('id', array(), $blog_uri);
|
|
|
|
$content[] = phutil_tag('link',
|
|
|
|
array(
|
|
|
|
'rel' => 'self',
|
|
|
|
'type' => 'application/atom+xml',
|
|
|
|
'href' => $blog_uri
|
|
|
|
));
|
2013-01-09 04:53:34 +01:00
|
|
|
|
|
|
|
$updated = $blog->getDateModified();
|
|
|
|
if ($posts) {
|
|
|
|
$updated = max($updated, max(mpull($posts, 'getDateModified')));
|
|
|
|
}
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = phutil_tag('updated', array(), date('c', $updated));
|
2013-01-09 04:53:34 +01:00
|
|
|
|
|
|
|
$description = $blog->getDescription();
|
|
|
|
if ($description != '') {
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = phutil_tag('subtitle', array(), $description);
|
2013-01-09 04:53:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$engine = id(new PhabricatorMarkupEngine())->setViewer($user);
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
$engine->addObject($post, PhamePost::MARKUP_FIELD_BODY);
|
|
|
|
}
|
|
|
|
$engine->process();
|
|
|
|
|
2013-09-11 21:27:28 +02:00
|
|
|
$blogger_phids = mpull($posts, 'getBloggerPHID');
|
|
|
|
$bloggers = id(new PhabricatorHandleQuery())
|
2013-01-09 04:53:34 +01:00
|
|
|
->setViewer($user)
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($blogger_phids)
|
|
|
|
->execute();
|
2013-01-09 04:53:34 +01:00
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = hsprintf('<entry>');
|
|
|
|
$content[] = phutil_tag('title', array(), $post->getTitle());
|
|
|
|
$content[] = phutil_tag('link', array('href' => $post->getViewURI()));
|
2013-01-09 04:53:34 +01:00
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = phutil_tag('id', array(), PhabricatorEnv::getProductionURI(
|
|
|
|
'/phame/post/view/'.$post->getID().'/'));
|
2013-01-09 04:53:34 +01:00
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = hsprintf(
|
2013-03-03 22:57:59 +01:00
|
|
|
'<author><name>%s</name></author>',
|
2013-02-08 21:07:44 +01:00
|
|
|
$bloggers[$post->getBloggerPHID()]->getFullName());
|
2013-01-09 04:53:34 +01:00
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = phutil_tag(
|
|
|
|
'updated',
|
|
|
|
array(),
|
|
|
|
date('c', $post->getDateModified()));
|
2013-01-09 04:53:34 +01:00
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = hsprintf(
|
2013-01-09 04:53:34 +01:00
|
|
|
'<content type="xhtml">'.
|
2013-02-08 21:07:44 +01:00
|
|
|
'<div xmlns="http://www.w3.org/1999/xhtml">%s</div>'.
|
|
|
|
'</content>',
|
|
|
|
$engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY));
|
2013-01-09 04:53:34 +01:00
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$content[] = hsprintf('</entry>');
|
2013-01-09 04:53:34 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$content = phutil_tag(
|
|
|
|
'feed',
|
|
|
|
array('xmlns' => 'http://www.w3.org/2005/Atom'),
|
|
|
|
$content);
|
2013-01-09 04:53:34 +01:00
|
|
|
|
|
|
|
return id(new AphrontFileResponse())
|
|
|
|
->setMimeType('application/xml')
|
2013-02-08 21:07:44 +01:00
|
|
|
->setContent($content);
|
2013-01-09 04:53:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|