@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhameBlogFeedController extends PhameBlogController {
4
5 public function shouldRequireLogin() {
6 return false;
7 }
8
9 public function handleRequest(AphrontRequest $request) {
10 $viewer = $request->getViewer();
11 $id = $request->getURIData('id');
12
13 $blog = id(new PhameBlogQuery())
14 ->setViewer($viewer)
15 ->withIDs(array($id))
16 ->executeOne();
17 if (!$blog) {
18 return new Aphront404Response();
19 }
20
21 $posts = id(new PhamePostQuery())
22 ->setViewer($viewer)
23 ->withBlogPHIDs(array($blog->getPHID()))
24 ->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED))
25 ->execute();
26
27 $blog_feed_uri = PhabricatorEnv::getProductionURI($blog->getFeedURI());
28 $blog_view_uri = PhabricatorEnv::getProductionURI($blog->getViewURI());
29 $content = array();
30 $content[] = phutil_tag('title', array(), $blog->getName());
31 $content[] = phutil_tag('id', array(), $blog_feed_uri);
32 $content[] = phutil_tag('link',
33 array(
34 'rel' => 'self',
35 'type' => 'application/atom+xml',
36 'href' => $blog_feed_uri,
37 ));
38 $content[] = phutil_tag('link',
39 array(
40 'rel' => 'alternate',
41 'type' => 'text/html',
42 'href' => $blog_view_uri,
43 'title' => $blog->getName(),
44 ));
45
46 $updated = $blog->getDateModified();
47 if ($posts) {
48 $updated = max($updated, max(mpull($posts, 'getDateModified')));
49 }
50 $content[] = phutil_tag('updated', array(), date('c', $updated));
51
52 $description = $blog->getDescription();
53 if ($description != '') {
54 $content[] = phutil_tag('subtitle', array(), $description);
55 }
56
57 $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer);
58 foreach ($posts as $post) {
59 $engine->addObject($post, PhamePost::MARKUP_FIELD_BODY);
60 }
61 $engine->process();
62
63 $blogger_phids = mpull($posts, 'getBloggerPHID');
64 $bloggers = id(new PhabricatorHandleQuery())
65 ->setViewer($viewer)
66 ->withPHIDs($blogger_phids)
67 ->execute();
68
69 foreach ($posts as $post) {
70 $content[] = hsprintf('<entry>');
71 $content[] = phutil_tag('title', array(), $post->getTitle());
72 $content[] = phutil_tag('link', array('href' => $post->getLiveURI()));
73
74 $content[] = phutil_tag('id', array(), PhabricatorEnv::getProductionURI(
75 '/phame/post/view/'.$post->getID().'/'));
76
77 $content[] = hsprintf(
78 '<author><name>%s</name></author>',
79 $bloggers[$post->getBloggerPHID()]->getFullName());
80
81 $content[] = phutil_tag(
82 'published',
83 array(),
84 date('c', $post->getDatePublished()));
85
86 $content[] = phutil_tag(
87 'updated',
88 array(),
89 date('c', $post->getDateModified()));
90
91 $content[] = hsprintf(
92 '<content type="xhtml">'.
93 '<div xmlns="http://www.w3.org/1999/xhtml">%s</div>'.
94 '</content>',
95 $engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY));
96
97 $content[] = hsprintf('</entry>');
98 }
99
100 $content = phutil_tag(
101 'feed',
102 array('xmlns' => 'http://www.w3.org/2005/Atom'),
103 $content);
104
105 return id(new AphrontFileResponse())
106 ->setMimeType('application/xml')
107 ->setContent($content);
108 }
109
110}