id = $data['id']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $post = id(new PhamePostQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->executeOne(); if (!$post) { return new Aphront404Response(); } if ($post->isDraft()) { $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.' ); } else if ($request->getExists('saved')) { $new_link = phutil_render_tag( 'a', array( 'href' => '/phame/post/new/', 'class' => 'button green', ), 'write another blog post' ); $notice = array( 'title' => 'Saved post successfully.', 'body' => 'Seek even more phame and '.$new_link.'.' ); } else { $notice = array(); } $this->loadHandles( array( $post->getBlogPHID(), $post->getBloggerPHID(), )); $nav = $this->renderSideNavFilterView(null); $header = id(new PhabricatorHeaderView())->setHeader($post->getTitle()); $actions = $this->renderActions($post, $user); $properties = $this->renderProperties($post, $user); $nav->appendChild( array( $header, $actions, $properties, )); return $this->buildApplicationPage( $nav, array( 'title' => $post->getTitle(), 'device' => true, )); } 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; } }