mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-16 03:42:41 +01:00
649f5cc178
Summary: we need a link with type=self to pass xml validation. Note we will always fail validation until we remove any sigil-related stuff from the resultant HTML since we just made that up for our purposes. Also serves up the feed link on the blog view controller, complete with tooltip about how the custom domain stuff isn't supported. Test Plan: viewed a blog page and liked the feed uri property. viewed a feed and verified the new link self stuff. post push I'll try the validator again. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, vrana Differential Revision: https://secure.phabricator.com/D5667
106 lines
2.9 KiB
PHP
106 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group phame
|
|
*/
|
|
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();
|
|
|
|
$blog_uri = PhabricatorEnv::getProductionURI(
|
|
$this->getApplicationURI('blog/feed/'.$blog->getID().'/'));
|
|
$content = array();
|
|
$content[] = phutil_tag('title', array(), $blog->getName());
|
|
$content[] = phutil_tag('id', array(), $blog_uri);
|
|
$content[] = phutil_tag('link',
|
|
array(
|
|
'rel' => 'self',
|
|
'type' => 'application/atom+xml',
|
|
'href' => $blog_uri
|
|
));
|
|
|
|
$updated = $blog->getDateModified();
|
|
if ($posts) {
|
|
$updated = max($updated, max(mpull($posts, 'getDateModified')));
|
|
}
|
|
$content[] = phutil_tag('updated', array(), date('c', $updated));
|
|
|
|
$description = $blog->getDescription();
|
|
if ($description != '') {
|
|
$content[] = phutil_tag('subtitle', array(), $description);
|
|
}
|
|
|
|
$engine = id(new PhabricatorMarkupEngine())->setViewer($user);
|
|
foreach ($posts as $post) {
|
|
$engine->addObject($post, PhamePost::MARKUP_FIELD_BODY);
|
|
}
|
|
$engine->process();
|
|
|
|
$bloggers = mpull($posts, 'getBloggerPHID');
|
|
$bloggers = id(new PhabricatorObjectHandleData($bloggers))
|
|
->setViewer($user)
|
|
->loadHandles();
|
|
|
|
foreach ($posts as $post) {
|
|
$content[] = hsprintf('<entry>');
|
|
$content[] = phutil_tag('title', array(), $post->getTitle());
|
|
$content[] = phutil_tag('link', array('href' => $post->getViewURI()));
|
|
|
|
$content[] = phutil_tag('id', array(), PhabricatorEnv::getProductionURI(
|
|
'/phame/post/view/'.$post->getID().'/'));
|
|
|
|
$content[] = hsprintf(
|
|
'<author><name>%s</name></author>',
|
|
$bloggers[$post->getBloggerPHID()]->getFullName());
|
|
|
|
$content[] = phutil_tag(
|
|
'updated',
|
|
array(),
|
|
date('c', $post->getDateModified()));
|
|
|
|
$content[] = hsprintf(
|
|
'<content type="xhtml">'.
|
|
'<div xmlns="http://www.w3.org/1999/xhtml">%s</div>'.
|
|
'</content>',
|
|
$engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY));
|
|
|
|
$content[] = hsprintf('</entry>');
|
|
}
|
|
|
|
$content = phutil_tag(
|
|
'feed',
|
|
array('xmlns' => 'http://www.w3.org/2005/Atom'),
|
|
$content);
|
|
|
|
return id(new AphrontFileResponse())
|
|
->setMimeType('application/xml')
|
|
->setContent($content);
|
|
}
|
|
|
|
}
|