Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/controller/blog/PhameBlogViewController.php
<?php | <?php | ||||
final class PhameBlogViewController extends PhameBlogController { | final class PhameBlogViewController extends PhameLiveController { | ||||
private $blog; | public function handleRequest(AphrontRequest $request) { | ||||
$response = $this->setupLiveEnvironment(); | |||||
public function shouldAllowPublic() { | if ($response) { | ||||
return true; | return $response; | ||||
} | } | ||||
public function handleRequest(AphrontRequest $request) { | $viewer = $this->getViewer(); | ||||
$viewer = $request->getViewer(); | $blog = $this->getBlog(); | ||||
$id = $request->getURIData('id'); | |||||
$blog = id(new PhameBlogQuery()) | $is_live = $this->getIsLive(); | ||||
->setViewer($viewer) | $is_external = $this->getIsExternal(); | ||||
->withIDs(array($id)) | |||||
->needProfileImage(true) | |||||
->executeOne(); | |||||
if (!$blog) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$this->blog = $blog; | |||||
$pager = id(new AphrontCursorPagerView()) | $pager = id(new AphrontCursorPagerView()) | ||||
->readFromRequest($request); | ->readFromRequest($request); | ||||
$posts = id(new PhamePostQuery()) | $post_query = id(new PhamePostQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withBlogPHIDs(array($blog->getPHID())) | ->withBlogPHIDs(array($blog->getPHID())); | ||||
->executeWithCursorPager($pager); | |||||
if ($is_live) { | |||||
$post_query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED); | |||||
} | |||||
$posts = $post_query->executeWithCursorPager($pager); | |||||
$header = id(new PHUIHeaderView()) | |||||
->setHeader($blog->getName()) | |||||
->setUser($viewer); | |||||
if (!$is_external) { | |||||
if ($blog->isArchived()) { | if ($blog->isArchived()) { | ||||
$header_icon = 'fa-ban'; | $header_icon = 'fa-ban'; | ||||
$header_name = pht('Archived'); | $header_name = pht('Archived'); | ||||
$header_color = 'dark'; | $header_color = 'dark'; | ||||
} else { | } else { | ||||
$header_icon = 'fa-check'; | $header_icon = 'fa-check'; | ||||
$header_name = pht('Active'); | $header_name = pht('Active'); | ||||
$header_color = 'bluegrey'; | $header_color = 'bluegrey'; | ||||
} | } | ||||
$header->setStatus($header_icon, $header_color, $header_name); | |||||
$actions = $this->renderActions($blog, $viewer); | $actions = $this->renderActions($blog); | ||||
$action_button = id(new PHUIButtonView()) | $action_button = id(new PHUIButtonView()) | ||||
->setTag('a') | ->setTag('a') | ||||
->setText(pht('Actions')) | ->setText(pht('Actions')) | ||||
->setHref('#') | ->setHref('#') | ||||
->setIconFont('fa-bars') | ->setIconFont('fa-bars') | ||||
->addClass('phui-mobile-menu') | ->addClass('phui-mobile-menu') | ||||
->setDropdownMenu($actions); | ->setDropdownMenu($actions); | ||||
$header = id(new PHUIHeaderView()) | $header->addActionLink($action_button); | ||||
->setHeader($blog->getName()) | |||||
->setUser($viewer) | $header->setPolicyObject($blog); | ||||
->setPolicyObject($blog) | } | ||||
->setStatus($header_icon, $header_color, $header_name) | |||||
->addActionLink($action_button); | |||||
$post_list = id(new PhamePostListView()) | $post_list = id(new PhamePostListView()) | ||||
->setPosts($posts) | ->setPosts($posts) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setIsExternal($is_external) | |||||
->setIsLive($is_live) | |||||
->setNodata(pht('This blog has no visible posts.')); | ->setNodata(pht('This blog has no visible posts.')); | ||||
$crumbs = $this->buildApplicationCrumbs(); | |||||
$crumbs->setBorder(true); | |||||
$crumbs->addTextCrumb( | |||||
pht('Blogs'), | |||||
$this->getApplicationURI('blog/')); | |||||
$crumbs->addTextCrumb( | |||||
$blog->getName()); | |||||
$page = id(new PHUIDocumentViewPro()) | $page = id(new PHUIDocumentViewPro()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->appendChild($post_list); | ->appendChild($post_list); | ||||
$description = null; | $description = null; | ||||
if (strlen($blog->getDescription())) { | if (strlen($blog->getDescription())) { | ||||
$description = PhabricatorMarkupEngine::renderOneObject( | $description = new PHUIRemarkupView( | ||||
id(new PhabricatorMarkupOneOff())->setContent($blog->getDescription()), | $viewer, | ||||
'default', | $blog->getDescription()); | ||||
$viewer); | |||||
} else { | } else { | ||||
$description = phutil_tag('em', array(), pht('No description.')); | $description = phutil_tag('em', array(), pht('No description.')); | ||||
} | } | ||||
$about = id(new PhameDescriptionView()) | $about = id(new PhameDescriptionView()) | ||||
->setTitle(pht('About %s', $blog->getName())) | ->setTitle(pht('About %s', $blog->getName())) | ||||
->setDescription($description) | ->setDescription($description) | ||||
->setImage($blog->getProfileImageURI()); | ->setImage($blog->getProfileImageURI()); | ||||
return $this->newPage() | $crumbs = $this->buildApplicationCrumbs(); | ||||
$page = $this->newPage() | |||||
->setTitle($blog->getName()) | ->setTitle($blog->getName()) | ||||
->setPageObjectPHIDs(array($blog->getPHID())) | |||||
->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
->appendChild( | ->appendChild( | ||||
array( | array( | ||||
$page, | $page, | ||||
$about, | $about, | ||||
)); | )); | ||||
if ($is_live) { | |||||
$page | |||||
->setShowChrome(false) | |||||
->setShowFooter(false); | |||||
} | } | ||||
private function renderActions(PhameBlog $blog, PhabricatorUser $viewer) { | return $page; | ||||
} | |||||
private function renderActions(PhameBlog $blog) { | |||||
$viewer = $this->getViewer(); | |||||
$actions = id(new PhabricatorActionListView()) | $actions = id(new PhabricatorActionListView()) | ||||
->setObject($blog) | ->setObject($blog) | ||||
->setObjectURI($this->getRequest()->getRequestURI()) | ->setObjectURI($this->getRequest()->getRequestURI()) | ||||
->setUser($viewer); | ->setUser($viewer); | ||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
$viewer, | $viewer, | ||||
$blog, | $blog, | ||||
Show All 27 Lines |