Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/controller/post/PhamePostViewController.php
| <?php | <?php | ||||
| final class PhamePostViewController extends PhamePostController { | final class PhamePostViewController | ||||
| extends PhameLiveController { | |||||
| public function shouldAllowPublic() { | public function handleRequest(AphrontRequest $request) { | ||||
| return true; | $response = $this->setupLiveEnvironment(); | ||||
| if ($response) { | |||||
| return $response; | |||||
| } | } | ||||
| public function handleRequest(AphrontRequest $request) { | |||||
| $viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
| $moved = $request->getStr('moved'); | $moved = $request->getStr('moved'); | ||||
| $post = id(new PhamePostQuery()) | $post = $this->getPost(); | ||||
| ->setViewer($viewer) | $blog = $this->getBlog(); | ||||
| ->withIDs(array($request->getURIData('id'))) | |||||
| ->executeOne(); | |||||
| if (!$post) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| $blog = $post->getBlog(); | $is_live = $this->getIsLive(); | ||||
| $is_external = $this->getIsExternal(); | |||||
| $crumbs = $this->buildApplicationCrumbs(); | $header = id(new PHUIHeaderView()) | ||||
| $crumbs->addTextCrumb( | ->setHeader($post->getTitle()) | ||||
| pht('Blogs'), | ->setUser($viewer); | ||||
| $this->getApplicationURI('blog/')); | |||||
| $crumbs->addTextCrumb( | |||||
| $blog->getName(), | |||||
| $this->getApplicationURI('blog/view/'.$blog->getID().'/')); | |||||
| $crumbs->addTextCrumb( | |||||
| $post->getTitle(), | |||||
| $this->getApplicationURI('post/view/'.$post->getID().'/')); | |||||
| $crumbs->setBorder(true); | |||||
| $actions = $this->renderActions($post, $viewer); | if (!$is_external) { | ||||
| $actions = $this->renderActions($post); | |||||
| $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->setPolicyObject($post); | ||||
| ->setHeader($post->getTitle()) | $header->addActionLink($action_button); | ||||
| ->setUser($viewer) | } | ||||
| ->setPolicyObject($post) | |||||
| ->addActionLink($action_button); | |||||
| $document = id(new PHUIDocumentViewPro()) | $document = id(new PHUIDocumentViewPro()) | ||||
| ->setHeader($header); | ->setHeader($header); | ||||
| if ($moved) { | if ($moved) { | ||||
| $document->appendChild( | $document->appendChild( | ||||
| id(new PHUIInfoView()) | id(new PHUIInfoView()) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ||||
| ->appendChild(pht('Post moved successfully.'))); | ->appendChild(pht('Post moved successfully.'))); | ||||
| } | } | ||||
| if ($post->isDraft()) { | if ($post->isDraft()) { | ||||
| $document->appendChild( | $document->appendChild( | ||||
| id(new PHUIInfoView()) | id(new PHUIInfoView()) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ||||
| ->setTitle(pht('Draft Post')) | ->setTitle(pht('Draft Post')) | ||||
| ->appendChild( | ->appendChild( | ||||
| pht('Only you can see this draft until you publish it. '. | pht('Only you can see this draft until you publish it. '. | ||||
| 'Use "Preview" or "Publish" to publish this post.'))); | 'Use "Publish" to publish this post.'))); | ||||
| } | } | ||||
| if (!$post->getBlog()) { | if (!$post->getBlog()) { | ||||
| $document->appendChild( | $document->appendChild( | ||||
| id(new PHUIInfoView()) | id(new PHUIInfoView()) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ||||
| ->setTitle(pht('Not On A Blog')) | ->setTitle(pht('Not On A Blog')) | ||||
| ->appendChild( | ->appendChild( | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | $about = id(new PhameDescriptionView()) | ||||
| ->setImageHref('/p/'.$blogger->getUsername()); | ->setImageHref('/p/'.$blogger->getUsername()); | ||||
| $timeline = $this->buildTransactionTimeline( | $timeline = $this->buildTransactionTimeline( | ||||
| $post, | $post, | ||||
| id(new PhamePostTransactionQuery()) | id(new PhamePostTransactionQuery()) | ||||
| ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))); | ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))); | ||||
| $timeline = phutil_tag_div('phui-document-view-pro-box', $timeline); | $timeline = phutil_tag_div('phui-document-view-pro-box', $timeline); | ||||
| if ($is_external) { | |||||
| $add_comment = null; | |||||
| } else { | |||||
| $add_comment = $this->buildCommentForm($post); | $add_comment = $this->buildCommentForm($post); | ||||
| $add_comment = phutil_tag_div('mlb mlt', $add_comment); | $add_comment = phutil_tag_div('mlb mlt', $add_comment); | ||||
| } | |||||
| $properties = id(new PHUIPropertyListView()) | $properties = id(new PHUIPropertyListView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setObject($post); | ->setObject($post); | ||||
| $properties->invokeWillRenderEvent(); | $properties->invokeWillRenderEvent(); | ||||
| return $this->newPage() | $crumbs = $this->buildApplicationCrumbs(); | ||||
| $page = $this->newPage() | |||||
| ->setTitle($post->getTitle()) | ->setTitle($post->getTitle()) | ||||
| ->setPageObjectPHIDs(array($post->getPHID())) | ->setPageObjectPHIDs(array($post->getPHID())) | ||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->appendChild( | ->appendChild( | ||||
| array( | array( | ||||
| $document, | $document, | ||||
| $about, | $about, | ||||
| $properties, | $properties, | ||||
| $timeline, | $timeline, | ||||
| $add_comment, | $add_comment, | ||||
| )); | )); | ||||
| if ($is_live) { | |||||
| $page | |||||
| ->setShowChrome(false) | |||||
| ->setShowFooter(false); | |||||
| } | } | ||||
| private function renderActions( | return $page; | ||||
| PhamePost $post, | } | ||||
| PhabricatorUser $viewer) { | |||||
| private function renderActions(PhamePost $post) { | |||||
| $viewer = $this->getViewer(); | |||||
| $actions = id(new PhabricatorActionListView()) | $actions = id(new PhabricatorActionListView()) | ||||
| ->setObject($post) | ->setObject($post) | ||||
| ->setObjectURI($this->getRequest()->getRequestURI()) | ->setObjectURI($this->getRequest()->getRequestURI()) | ||||
| ->setUser($viewer); | ->setUser($viewer); | ||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
| $viewer, | $viewer, | ||||
| $post, | $post, | ||||
| PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
| $id = $post->getID(); | $id = $post->getID(); | ||||
| Show All 18 Lines | $actions->addAction( | ||||
| ->setHref($this->getApplicationURI('post/history/'.$id.'/')) | ->setHref($this->getApplicationURI('post/history/'.$id.'/')) | ||||
| ->setName(pht('View History'))); | ->setName(pht('View History'))); | ||||
| if ($post->isDraft()) { | if ($post->isDraft()) { | ||||
| $actions->addAction( | $actions->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setIcon('fa-eye') | ->setIcon('fa-eye') | ||||
| ->setHref($this->getApplicationURI('post/publish/'.$id.'/')) | ->setHref($this->getApplicationURI('post/publish/'.$id.'/')) | ||||
| ->setDisabled(!$can_edit) | |||||
| ->setName(pht('Publish')) | ->setName(pht('Publish')) | ||||
| ->setWorkflow(true)); | |||||
| $actions->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setIcon('fa-desktop') | |||||
| ->setHref($this->getApplicationURI('post/preview/'.$id.'/')) | |||||
| ->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
| ->setName(pht('Preview in Skin'))); | ->setWorkflow(true)); | ||||
| } else { | } else { | ||||
| $actions->addAction( | $actions->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setIcon('fa-eye-slash') | ->setIcon('fa-eye-slash') | ||||
| ->setHref($this->getApplicationURI('post/unpublish/'.$id.'/')) | ->setHref($this->getApplicationURI('post/unpublish/'.$id.'/')) | ||||
| ->setName(pht('Unpublish')) | ->setName(pht('Unpublish')) | ||||
| ->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
| ->setWorkflow(true)); | ->setWorkflow(true)); | ||||
| } | } | ||||
| $blog = $post->getBlog(); | if ($post->isDraft()) { | ||||
| $can_view_live = $blog && !$post->isDraft(); | $live_name = pht('Preview'); | ||||
| if ($can_view_live) { | |||||
| $live_uri = $blog->getLiveURI($post); | |||||
| } else { | } else { | ||||
| $live_uri = 'post/notlive/'.$post->getID().'/'; | $live_name = pht('View Live'); | ||||
| $live_uri = $this->getApplicationURI($live_uri); | |||||
| } | } | ||||
| $actions->addAction( | $actions->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setIcon('fa-globe') | ->setIcon('fa-globe') | ||||
| ->setHref($live_uri) | ->setHref($post->getLiveURI()) | ||||
| ->setName(pht('View Live')) | ->setName($live_name)); | ||||
| ->setDisabled(!$can_view_live) | |||||
| ->setWorkflow(!$can_view_live)); | |||||
| return $actions; | return $actions; | ||||
| } | } | ||||
| private function buildCommentForm(PhamePost $post) { | private function buildCommentForm(PhamePost $post) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $draft = PhabricatorDraft::newFromUserAndKey( | $draft = PhabricatorDraft::newFromUserAndKey( | ||||
| Show All 14 Lines | |||||