2012-04-12 13:09:04 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group phame
|
|
|
|
|
*/
|
2012-10-15 14:50:04 -07:00
|
|
|
final class PhamePostViewController extends PhameController {
|
2012-04-12 13:09:04 -07:00
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
private $id;
|
2012-07-05 15:43:14 -07:00
|
|
|
|
2012-04-12 13:09:04 -07:00
|
|
|
public function willProcessRequest(array $data) {
|
2012-10-15 14:50:45 -07:00
|
|
|
$this->id = $data['id'];
|
2012-04-12 13:09:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
2012-10-15 14:50:45 -07:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$user = $request->getUser();
|
2012-04-12 13:09:04 -07:00
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
$post = id(new PhamePostQuery())
|
|
|
|
|
->setViewer($user)
|
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
|
->executeOne();
|
2012-04-12 13:09:04 -07:00
|
|
|
|
|
|
|
|
if (!$post) {
|
|
|
|
|
return new Aphront404Response();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-16 09:44:43 -07:00
|
|
|
$nav = $this->renderSideNavFilterView();
|
|
|
|
|
|
2013-04-14 08:02:29 -07:00
|
|
|
$this->loadHandles(
|
|
|
|
|
array(
|
|
|
|
|
$post->getBlogPHID(),
|
|
|
|
|
$post->getBloggerPHID(),
|
|
|
|
|
));
|
|
|
|
|
$actions = $this->renderActions($post, $user);
|
2013-10-11 07:53:56 -07:00
|
|
|
$properties = $this->renderProperties($post, $user, $actions);
|
2013-04-14 08:02:29 -07:00
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
|
$crumbs->setActionList($actions);
|
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
|
->setName($post->getTitle())
|
|
|
|
|
->setHref($this->getApplicationURI('post/view/'.$post->getID().'/')));
|
|
|
|
|
|
|
|
|
|
$nav->appendChild($crumbs);
|
2013-09-28 15:55:38 -07:00
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
2013-09-18 16:27:24 -07:00
|
|
|
->setHeader($post->getTitle())
|
2013-09-19 11:56:58 -07:00
|
|
|
->setUser($user)
|
2013-09-28 15:55:38 -07:00
|
|
|
->setPolicyObject($post);
|
|
|
|
|
|
|
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
|
->setHeader($header)
|
2013-10-11 07:53:56 -07:00
|
|
|
->addPropertyList($properties);
|
2012-10-16 09:44:43 -07:00
|
|
|
|
2012-04-12 13:09:04 -07:00
|
|
|
if ($post->isDraft()) {
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box->appendChild(
|
2012-10-16 09:44:43 -07:00
|
|
|
id(new AphrontErrorView())
|
|
|
|
|
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
|
|
|
|
|
->setTitle(pht('Draft Post'))
|
|
|
|
|
->appendChild(
|
|
|
|
|
pht('Only you can see this draft until you publish it. '.
|
|
|
|
|
'Use "Preview / Publish" to publish this post.')));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$post->getBlog()) {
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box->appendChild(
|
2012-10-16 09:44:43 -07:00
|
|
|
id(new AphrontErrorView())
|
|
|
|
|
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
|
|
|
|
|
->setTitle(pht('Not On A Blog'))
|
|
|
|
|
->appendChild(
|
|
|
|
|
pht('This post is not associated with a blog (the blog may have '.
|
|
|
|
|
'been deleted). Use "Move Post" to move it to a new blog.')));
|
2012-04-12 13:09:04 -07:00
|
|
|
}
|
|
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
$nav->appendChild(
|
2012-04-12 13:09:04 -07:00
|
|
|
array(
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box,
|
2012-10-15 14:50:45 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
$nav,
|
2012-04-12 13:09:04 -07:00
|
|
|
array(
|
2013-04-14 08:02:29 -07:00
|
|
|
'title' => $post->getTitle(),
|
|
|
|
|
'device' => true,
|
2012-04-12 13:09:04 -07:00
|
|
|
));
|
|
|
|
|
}
|
2012-10-15 14:50:45 -07:00
|
|
|
|
|
|
|
|
private function renderActions(
|
|
|
|
|
PhamePost $post,
|
|
|
|
|
PhabricatorUser $user) {
|
|
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
|
->setObject($post)
|
2013-07-12 11:39:47 -07:00
|
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
2012-10-15 14:50:45 -07:00
|
|
|
->setUser($user);
|
|
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
|
$user,
|
|
|
|
|
$post,
|
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
|
|
$id = $post->getID();
|
|
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setIcon('edit')
|
|
|
|
|
->setHref($this->getApplicationURI('post/edit/'.$id.'/'))
|
2013-04-14 08:02:29 -07:00
|
|
|
->setName(pht('Edit Post'))
|
2012-10-15 14:50:45 -07:00
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
2012-10-16 09:44:43 -07:00
|
|
|
->setIcon('move')
|
|
|
|
|
->setHref($this->getApplicationURI('post/move/'.$id.'/'))
|
2013-04-14 08:02:29 -07:00
|
|
|
->setName(pht('Move Post'))
|
2012-10-16 09:44:43 -07:00
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(!$can_edit));
|
2012-10-15 14:50:45 -07:00
|
|
|
|
|
|
|
|
if ($post->isDraft()) {
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
2012-10-16 09:44:43 -07:00
|
|
|
->setIcon('preview')
|
2012-10-15 14:50:45 -07:00
|
|
|
->setHref($this->getApplicationURI('post/publish/'.$id.'/'))
|
|
|
|
|
->setName(pht('Preview / Publish')));
|
|
|
|
|
} else {
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
2012-10-16 09:44:43 -07:00
|
|
|
->setIcon('unpublish')
|
2012-10-15 14:50:45 -07:00
|
|
|
->setHref($this->getApplicationURI('post/unpublish/'.$id.'/'))
|
|
|
|
|
->setName(pht('Unpublish'))
|
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setIcon('delete')
|
|
|
|
|
->setHref($this->getApplicationURI('post/delete/'.$id.'/'))
|
2013-04-14 08:02:29 -07:00
|
|
|
->setName(pht('Delete Post'))
|
2012-10-15 14:50:45 -07:00
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
|
2012-10-16 09:44:43 -07:00
|
|
|
$blog = $post->getBlog();
|
|
|
|
|
$can_view_live = $blog && !$post->isDraft();
|
2013-06-26 06:12:23 -07:00
|
|
|
$must_use_form = $blog && $blog->getDomain();
|
2012-10-16 09:44:43 -07:00
|
|
|
|
|
|
|
|
if ($can_view_live) {
|
|
|
|
|
$live_uri = 'live/'.$blog->getID().'/post/'.$post->getPhameTitle();
|
|
|
|
|
} else {
|
|
|
|
|
$live_uri = 'post/notlive/'.$post->getID().'/';
|
|
|
|
|
}
|
|
|
|
|
$live_uri = $this->getApplicationURI($live_uri);
|
|
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
2013-02-19 16:04:54 -08:00
|
|
|
->setUser($user)
|
2012-10-16 09:44:43 -07:00
|
|
|
->setIcon('world')
|
|
|
|
|
->setHref($live_uri)
|
|
|
|
|
->setName(pht('View Live'))
|
2013-06-26 06:12:23 -07:00
|
|
|
->setRenderAsForm($must_use_form)
|
2012-10-16 09:44:43 -07:00
|
|
|
->setDisabled(!$can_view_live)
|
|
|
|
|
->setWorkflow(!$can_view_live));
|
|
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
return $actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function renderProperties(
|
|
|
|
|
PhamePost $post,
|
2013-10-11 07:53:56 -07:00
|
|
|
PhabricatorUser $user,
|
|
|
|
|
PhabricatorActionListView $actions) {
|
2012-10-15 14:50:45 -07:00
|
|
|
|
2013-10-11 07:53:56 -07:00
|
|
|
$properties = id(new PHUIPropertyListView())
|
2013-05-09 14:40:43 -07:00
|
|
|
->setUser($user)
|
2013-10-11 07:53:56 -07:00
|
|
|
->setObject($post)
|
|
|
|
|
->setActionList($actions);
|
2012-10-15 14:50:45 -07:00
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
|
pht('Blog'),
|
|
|
|
|
$post->getBlogPHID()
|
|
|
|
|
? $this->getHandle($post->getBlogPHID())->renderLink()
|
|
|
|
|
: null);
|
|
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
|
pht('Blogger'),
|
|
|
|
|
$this->getHandle($post->getBloggerPHID())->renderLink());
|
|
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
|
pht('Published'),
|
|
|
|
|
$post->isDraft()
|
|
|
|
|
? pht('Draft')
|
|
|
|
|
: phabricator_datetime($post->getDatePublished(), $user));
|
|
|
|
|
|
2012-10-15 14:51:04 -07:00
|
|
|
$engine = id(new PhabricatorMarkupEngine())
|
|
|
|
|
->setViewer($user)
|
|
|
|
|
->addObject($post, PhamePost::MARKUP_FIELD_BODY)
|
|
|
|
|
->process();
|
|
|
|
|
|
2013-05-09 14:40:43 -07:00
|
|
|
$properties->invokeWillRenderEvent();
|
|
|
|
|
|
2012-10-15 14:51:04 -07:00
|
|
|
$properties->addTextContent(
|
2013-01-29 11:01:47 -08:00
|
|
|
phutil_tag(
|
|
|
|
|
'div',
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'phabricator-remarkup',
|
|
|
|
|
),
|
|
|
|
|
$engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY)));
|
2012-10-15 14:51:04 -07:00
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
return $properties;
|
|
|
|
|
}
|
2012-04-12 13:09:04 -07:00
|
|
|
}
|