2012-07-19 18:03:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group phame
|
|
|
|
*/
|
2012-10-15 23:50:04 +02:00
|
|
|
final class PhameBlogViewController extends PhameController {
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
private $id;
|
2012-07-19 18:03:10 +02:00
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
2012-10-15 23:50:12 +02:00
|
|
|
$this->id = $data['id'];
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2012-10-15 23:50:04 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2012-10-15 23:49:52 +02:00
|
|
|
$blog = id(new PhameBlogQuery())
|
|
|
|
->setViewer($user)
|
2012-10-15 23:50:12 +02:00
|
|
|
->withIDs(array($this->id))
|
2012-10-15 23:49:52 +02:00
|
|
|
->executeOne();
|
2012-07-19 18:03:10 +02:00
|
|
|
if (!$blog) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
$pager = id(new AphrontCursorPagerView())
|
|
|
|
->readFromRequest($request);
|
|
|
|
|
2012-10-15 23:50:04 +02:00
|
|
|
$posts = id(new PhamePostQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withBlogPHIDs(array($blog->getPHID()))
|
2012-10-15 23:50:12 +02:00
|
|
|
->executeWithCursorPager($pager);
|
|
|
|
|
|
|
|
$nav = $this->renderSideNavFilterView(null);
|
|
|
|
|
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader($blog->getName());
|
|
|
|
|
2012-10-15 23:50:37 +02:00
|
|
|
$handle_phids = array_merge(
|
|
|
|
mpull($posts, 'getBloggerPHID'),
|
|
|
|
mpull($posts, 'getBlogPHID'));
|
|
|
|
$this->loadHandles($handle_phids);
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
$actions = $this->renderActions($blog, $user);
|
|
|
|
$properties = $this->renderProperties($blog, $user);
|
|
|
|
$post_list = $this->renderPostList(
|
|
|
|
$posts,
|
|
|
|
$user,
|
|
|
|
pht('This blog has no visible posts.'));
|
|
|
|
|
|
|
|
$nav->appendChild(
|
2012-07-19 18:03:10 +02:00
|
|
|
array(
|
2012-10-15 23:50:12 +02:00
|
|
|
$header,
|
|
|
|
$actions,
|
|
|
|
$properties,
|
|
|
|
$post_list,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$nav,
|
2012-07-19 18:03:10 +02:00
|
|
|
array(
|
2012-10-15 23:50:12 +02:00
|
|
|
'device' => true,
|
|
|
|
'title' => $blog->getName(),
|
2012-07-19 18:03:10 +02:00
|
|
|
));
|
|
|
|
}
|
2012-10-15 23:50:12 +02:00
|
|
|
|
|
|
|
private function renderProperties(PhameBlog $blog, PhabricatorUser $user) {
|
|
|
|
$properties = new PhabricatorPropertyListView();
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Skin'),
|
2013-01-29 20:01:47 +01:00
|
|
|
$blog->getSkin());
|
2012-10-15 23:50:12 +02:00
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Domain'),
|
2013-01-29 20:01:47 +01:00
|
|
|
$blog->getDomain());
|
2012-10-15 23:50:12 +02:00
|
|
|
|
|
|
|
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
|
|
|
|
$user,
|
|
|
|
$blog);
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Visible To'),
|
|
|
|
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Editable By'),
|
|
|
|
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Joinable By'),
|
|
|
|
$descriptions[PhabricatorPolicyCapability::CAN_JOIN]);
|
|
|
|
|
2012-10-15 23:51:04 +02:00
|
|
|
$engine = id(new PhabricatorMarkupEngine())
|
|
|
|
->setViewer($user)
|
|
|
|
->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)
|
|
|
|
->process();
|
|
|
|
|
|
|
|
$properties->addTextContent(
|
2013-01-29 20:01:47 +01:00
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-remarkup',
|
|
|
|
),
|
|
|
|
$engine->getOutput($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)));
|
2012-10-15 23:51:04 +02:00
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderActions(PhameBlog $blog, PhabricatorUser $user) {
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setObject($blog)
|
|
|
|
->setUser($user);
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$user,
|
|
|
|
$blog,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$can_join = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$user,
|
|
|
|
$blog,
|
|
|
|
PhabricatorPolicyCapability::CAN_JOIN);
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('new')
|
2012-10-16 18:44:43 +02:00
|
|
|
->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID()))
|
2012-10-15 23:50:12 +02:00
|
|
|
->setName(pht('Write Post'))
|
|
|
|
->setDisabled(!$can_join)
|
|
|
|
->setWorkflow(!$can_join));
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('world')
|
2012-10-15 23:51:30 +02:00
|
|
|
->setHref($this->getApplicationURI('live/'.$blog->getID().'/'))
|
|
|
|
->setName(pht('View Live')));
|
2012-10-15 23:50:12 +02:00
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('edit')
|
|
|
|
->setHref($this->getApplicationURI('blog/edit/'.$blog->getID().'/'))
|
|
|
|
->setName('Edit Blog')
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('delete')
|
|
|
|
->setHref($this->getApplicationURI('blog/delete/'.$blog->getID().'/'))
|
|
|
|
->setName('Delete Blog')
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|