2012-04-12 13:09:04 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012 Facebook, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($post->isDraft()) {
|
2012-10-12 16:01:33 -07:00
|
|
|
$notice = array(
|
|
|
|
|
'title' => 'You are previewing a draft.',
|
|
|
|
|
'body' => 'Only you can see this draft until you publish it. '.
|
|
|
|
|
'If you chose a comment widget it will show up when '.
|
|
|
|
|
'you publish.'
|
|
|
|
|
);
|
2012-07-19 09:03:10 -07:00
|
|
|
} else if ($request->getExists('saved')) {
|
|
|
|
|
$new_link = phutil_render_tag(
|
|
|
|
|
'a',
|
|
|
|
|
array(
|
|
|
|
|
'href' => '/phame/post/new/',
|
|
|
|
|
'class' => 'button green',
|
|
|
|
|
),
|
|
|
|
|
'write another blog post'
|
|
|
|
|
);
|
2012-10-12 16:01:33 -07:00
|
|
|
$notice = array(
|
|
|
|
|
'title' => 'Saved post successfully.',
|
|
|
|
|
'body' => 'Seek even more phame and '.$new_link.'.'
|
|
|
|
|
);
|
2012-04-12 13:09:04 -07:00
|
|
|
} else {
|
2012-10-12 16:01:33 -07:00
|
|
|
$notice = array();
|
2012-04-12 13:09:04 -07:00
|
|
|
}
|
|
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
$this->loadHandles(
|
|
|
|
|
array(
|
|
|
|
|
$post->getBlogPHID(),
|
|
|
|
|
$post->getBloggerPHID(),
|
|
|
|
|
));
|
2012-10-12 16:01:33 -07:00
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
$nav = $this->renderSideNavFilterView(null);
|
2012-10-15 14:50:12 -07:00
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
$header = id(new PhabricatorHeaderView())->setHeader($post->getTitle());
|
2012-04-12 13:09:04 -07:00
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
$actions = $this->renderActions($post, $user);
|
|
|
|
|
$properties = $this->renderProperties($post, $user);
|
2012-10-12 16:01:33 -07:00
|
|
|
|
2012-10-15 14:50:45 -07:00
|
|
|
$nav->appendChild(
|
2012-04-12 13:09:04 -07:00
|
|
|
array(
|
2012-10-15 14:50:45 -07:00
|
|
|
$header,
|
|
|
|
|
$actions,
|
|
|
|
|
$properties,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
$nav,
|
2012-04-12 13:09:04 -07:00
|
|
|
array(
|
2012-05-01 11:50:51 +02:00
|
|
|
'title' => $post->getTitle(),
|
2012-10-15 14:50:45 -07:00
|
|
|
'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)
|
|
|
|
|
->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.'/'))
|
|
|
|
|
->setName('Edit Post')
|
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
|
|
$can_view_live = $post->getBlog() && !$post->isDraft();
|
|
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setIcon('world')
|
|
|
|
|
->setHref($this->getApplicationURI('post/live/'.$id.'/'))
|
|
|
|
|
->setName(pht('View Live'))
|
|
|
|
|
->setDisabled(!$can_view_live)
|
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
|
|
|
|
|
if ($post->isDraft()) {
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setIcon('world')
|
|
|
|
|
->setHref($this->getApplicationURI('post/publish/'.$id.'/'))
|
|
|
|
|
->setName(pht('Preview / Publish')));
|
|
|
|
|
} else {
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setIcon('delete')
|
|
|
|
|
->setHref($this->getApplicationURI('post/unpublish/'.$id.'/'))
|
|
|
|
|
->setName(pht('Unpublish'))
|
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setIcon('delete')
|
|
|
|
|
->setHref($this->getApplicationURI('post/delete/'.$id.'/'))
|
|
|
|
|
->setName('Delete Post')
|
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function renderProperties(
|
|
|
|
|
PhamePost $post,
|
|
|
|
|
PhabricatorUser $user) {
|
|
|
|
|
|
|
|
|
|
$properties = new PhabricatorPropertyListView();
|
|
|
|
|
|
|
|
|
|
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
|
|
|
|
|
$user,
|
|
|
|
|
$post);
|
|
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
|
pht('Blog'),
|
|
|
|
|
$post->getBlogPHID()
|
|
|
|
|
? $this->getHandle($post->getBlogPHID())->renderLink()
|
|
|
|
|
: null);
|
|
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
|
pht('Blogger'),
|
|
|
|
|
$this->getHandle($post->getBloggerPHID())->renderLink());
|
|
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
|
pht('Visible To'),
|
|
|
|
|
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
|
|
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
|
pht('Published'),
|
|
|
|
|
$post->isDraft()
|
|
|
|
|
? pht('Draft')
|
|
|
|
|
: phabricator_datetime($post->getDatePublished(), $user));
|
|
|
|
|
|
|
|
|
|
return $properties;
|
|
|
|
|
}
|
2012-04-12 13:09:04 -07:00
|
|
|
}
|