mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add Atom export to Phame
Summary: There's no link to this yet, I'll add it to some skin. Fixes T2272. Test Plan: http://validator.w3.org/appc/ Reviewers: btrahan, epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2272 Differential Revision: https://secure.phabricator.com/D4366
This commit is contained in:
parent
7ad3147b3b
commit
fc30a6eb33
7 changed files with 122 additions and 50 deletions
|
@ -1292,6 +1292,7 @@ phutil_register_library_map(array(
|
|||
'PhameBlog' => 'applications/phame/storage/PhameBlog.php',
|
||||
'PhameBlogDeleteController' => 'applications/phame/controller/blog/PhameBlogDeleteController.php',
|
||||
'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php',
|
||||
'PhameBlogFeedController' => 'applications/phame/controller/blog/PhameBlogFeedController.php',
|
||||
'PhameBlogListController' => 'applications/phame/controller/blog/PhameBlogListController.php',
|
||||
'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php',
|
||||
'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php',
|
||||
|
@ -2609,6 +2610,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'PhameBlogDeleteController' => 'PhameController',
|
||||
'PhameBlogEditController' => 'PhameController',
|
||||
'PhameBlogFeedController' => 'PhameController',
|
||||
'PhameBlogListController' => 'PhameController',
|
||||
'PhameBlogLiveController' => 'PhameController',
|
||||
'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -53,12 +53,9 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication {
|
|||
'delete/(?P<id>[^/]+)/' => 'PhameBlogDeleteController',
|
||||
'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController',
|
||||
'view/(?P<id>[^/]+)/' => 'PhameBlogViewController',
|
||||
'feed/(?P<id>[^/]+)/' => 'PhameBlogFeedController',
|
||||
'new/' => 'PhameBlogEditController',
|
||||
),
|
||||
'posts/' => array(
|
||||
'(?P<bloggername>\w+)/(?P<phametitle>.+/)'
|
||||
=> 'PhamePostViewController',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<?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)
|
||||
->withPublishedAfter(strtotime('-1 month'))
|
||||
->execute();
|
||||
|
||||
$content = array();
|
||||
$content[] = '<feed xmlns="http://www.w3.org/2005/Atom">';
|
||||
$content[] = '<title>'.phutil_escape_html($blog->getName()).'</title>';
|
||||
$content[] = '<id>'.phutil_escape_html(PhabricatorEnv::getProductionURI(
|
||||
'/phame/blog/view/'.$blog->getID().'/')).'</id>';
|
||||
|
||||
$updated = $blog->getDateModified();
|
||||
if ($posts) {
|
||||
$updated = max($updated, max(mpull($posts, 'getDateModified')));
|
||||
}
|
||||
$content[] = '<updated>'.date('c', $updated).'</updated>';
|
||||
|
||||
$description = $blog->getDescription();
|
||||
if ($description != '') {
|
||||
$content[] = '<subtitle>'.phutil_escape_html($description).'</subtitle>';
|
||||
}
|
||||
|
||||
$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[] = '<entry>';
|
||||
$content[] = '<title>'.phutil_escape_html($post->getTitle()).'</title>';
|
||||
$content[] = '<link href="'.phutil_escape_html($post->getViewURI()).'"/>';
|
||||
|
||||
$content[] = '<id>'.phutil_escape_html(PhabricatorEnv::getProductionURI(
|
||||
'/phame/post/view/'.$post->getID().'/')).'</id>';
|
||||
|
||||
$content[] =
|
||||
'<author>'.
|
||||
'<name>'.
|
||||
phutil_escape_html($bloggers[$post->getBloggerPHID()]->getFullName()).
|
||||
'</name>'.
|
||||
'</author>';
|
||||
|
||||
$content[] = '<updated>'.date('c', $post->getDateModified()).'</updated>';
|
||||
|
||||
$content[] =
|
||||
'<content type="xhtml">'.
|
||||
'<div xmlns="http://www.w3.org/1999/xhtml">'.
|
||||
$engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY).
|
||||
'</div>'.
|
||||
'</content>';
|
||||
|
||||
$content[] = '</entry>';
|
||||
}
|
||||
|
||||
$content[] = '</feed>';
|
||||
|
||||
return id(new AphrontFileResponse())
|
||||
->setMimeType('application/xml')
|
||||
->setContent(implode('', $content));
|
||||
}
|
||||
|
||||
}
|
|
@ -54,10 +54,7 @@ final class PhamePostNotLiveController extends PhameController {
|
|||
|
||||
// No reason this can't go live, maybe an old link. Kick them live and see
|
||||
// what happens.
|
||||
|
||||
$blog = $post->getBlog();
|
||||
$live_uri = 'http://'.$blog->getDomain().'/'.$post->getPhameTitle();
|
||||
|
||||
$live_uri = $post->getViewURI();
|
||||
return id(new AphrontRedirectResponse())->setURI($live_uri);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
private $bloggerPHIDs;
|
||||
private $phameTitles;
|
||||
private $visibility;
|
||||
private $publishedAfter;
|
||||
private $phids;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
|
@ -42,6 +43,11 @@ final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withPublishedAfter($time) {
|
||||
$this->publishedAfter = $time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new PhamePost();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
@ -116,6 +122,13 @@ final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
$this->visibility);
|
||||
}
|
||||
|
||||
if ($this->publishedAfter !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'p.datePublished > %d',
|
||||
$this->publishedAfter);
|
||||
}
|
||||
|
||||
if ($this->blogPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
|
|
|
@ -178,26 +178,6 @@ final class PhameBlog extends PhameDAO
|
|||
return ipull($classes, 'name', 'name');
|
||||
}
|
||||
|
||||
public function getPostListURI() {
|
||||
return $this->getActionURI('posts');
|
||||
}
|
||||
|
||||
public function getEditURI() {
|
||||
return $this->getActionURI('edit');
|
||||
}
|
||||
|
||||
public function getEditFilter() {
|
||||
return 'blog/edit/'.$this->getPHID();
|
||||
}
|
||||
|
||||
public function getDeleteURI() {
|
||||
return $this->getActionURI('delete');
|
||||
}
|
||||
|
||||
private function getActionURI($action) {
|
||||
return '/phame/blog/'.$action.'/'.$this->getPHID().'/';
|
||||
}
|
||||
|
||||
public static function setRequestBlog(PhameBlog $blog) {
|
||||
self::$requestBlog = $blog;
|
||||
}
|
||||
|
|
|
@ -34,31 +34,15 @@ final class PhamePost extends PhameDAO
|
|||
return $this->blog;
|
||||
}
|
||||
|
||||
public function getViewURI($blogger_name = '') {
|
||||
public function getViewURI() {
|
||||
// go for the pretty uri if we can
|
||||
if ($blogger_name) {
|
||||
$domain = ($this->blog ? $this->blog->getDomain() : '');
|
||||
if ($domain) {
|
||||
$phame_title = PhabricatorSlug::normalize($this->getPhameTitle());
|
||||
$uri = phutil_escape_uri('/phame/posts/'.$blogger_name.'/'.$phame_title);
|
||||
} else {
|
||||
$uri = $this->getActionURI('view');
|
||||
return 'http://'.$domain.'/post/'.$phame_title;
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public function getEditURI() {
|
||||
return $this->getActionURI('edit');
|
||||
}
|
||||
|
||||
public function getDeleteURI() {
|
||||
return $this->getActionURI('delete');
|
||||
}
|
||||
|
||||
public function getChangeVisibilityURI() {
|
||||
return $this->getActionURI('changevisibility');
|
||||
}
|
||||
|
||||
private function getActionURI($action) {
|
||||
return '/phame/post/'.$action.'/'.$this->getPHID().'/';
|
||||
$uri = '/phame/post/view/'.$this->getID().'/';
|
||||
return PhabricatorEnv::getProductionURI($uri);
|
||||
}
|
||||
|
||||
public function isDraft() {
|
||||
|
|
Loading…
Reference in a new issue