Give Phame blogs mutable interact policies
[phabricator.git] / src / applications / phame / controller / blog / PhameBlogFeedController.php
blobc0c6e60cc4955e06d453625a4ba2e40c08830f17
1 <?php
3 final class PhameBlogFeedController extends PhameBlogController {
5 public function shouldRequireLogin() {
6 return false;
9 public function handleRequest(AphrontRequest $request) {
10 $viewer = $request->getViewer();
11 $id = $request->getURIData('id');
13 $blog = id(new PhameBlogQuery())
14 ->setViewer($viewer)
15 ->withIDs(array($id))
16 ->executeOne();
17 if (!$blog) {
18 return new Aphront404Response();
21 $posts = id(new PhamePostQuery())
22 ->setViewer($viewer)
23 ->withBlogPHIDs(array($blog->getPHID()))
24 ->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED))
25 ->execute();
27 $blog_uri = PhabricatorEnv::getProductionURI(
28 $this->getApplicationURI('blog/feed/'.$blog->getID().'/'));
29 $content = array();
30 $content[] = phutil_tag('title', array(), $blog->getName());
31 $content[] = phutil_tag('id', array(), $blog_uri);
32 $content[] = phutil_tag('link',
33 array(
34 'rel' => 'self',
35 'type' => 'application/atom+xml',
36 'href' => $blog_uri,
37 ));
39 $updated = $blog->getDateModified();
40 if ($posts) {
41 $updated = max($updated, max(mpull($posts, 'getDateModified')));
43 $content[] = phutil_tag('updated', array(), date('c', $updated));
45 $description = $blog->getDescription();
46 if ($description != '') {
47 $content[] = phutil_tag('subtitle', array(), $description);
50 $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer);
51 foreach ($posts as $post) {
52 $engine->addObject($post, PhamePost::MARKUP_FIELD_BODY);
54 $engine->process();
56 $blogger_phids = mpull($posts, 'getBloggerPHID');
57 $bloggers = id(new PhabricatorHandleQuery())
58 ->setViewer($viewer)
59 ->withPHIDs($blogger_phids)
60 ->execute();
62 foreach ($posts as $post) {
63 $content[] = hsprintf('<entry>');
64 $content[] = phutil_tag('title', array(), $post->getTitle());
65 $content[] = phutil_tag('link', array('href' => $post->getLiveURI()));
67 $content[] = phutil_tag('id', array(), PhabricatorEnv::getProductionURI(
68 '/phame/post/view/'.$post->getID().'/'));
70 $content[] = hsprintf(
71 '<author><name>%s</name></author>',
72 $bloggers[$post->getBloggerPHID()]->getFullName());
74 $content[] = phutil_tag(
75 'updated',
76 array(),
77 date('c', $post->getDateModified()));
79 $content[] = hsprintf(
80 '<content type="xhtml">'.
81 '<div xmlns="http://www.w3.org/1999/xhtml">%s</div>'.
82 '</content>',
83 $engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY));
85 $content[] = hsprintf('</entry>');
88 $content = phutil_tag(
89 'feed',
90 array('xmlns' => 'http://www.w3.org/2005/Atom'),
91 $content);
93 return id(new AphrontFileResponse())
94 ->setMimeType('application/xml')
95 ->setContent($content);