postPHID = $post_phid; return $this; } private function getPostPHID() { return $this->postPHID; } private function setPhameTitle($phame_title) { $this->phameTitle = $phame_title; return $this; } private function getPhameTitle() { return $this->phameTitle; } private function setBloggerName($blogger_name) { $this->bloggerName = $blogger_name; return $this; } private function getBloggerName() { return $this->bloggerName; } protected function getSideNavFilter() { $filter = 'post/view/'.$this->getPostPHID(); return $filter; } protected function getSideNavExtraPostFilters() { $filters = array( array('key' => $this->getSideNavFilter(), 'name' => $this->getPhameTitle()) ); return $filters; } public function willProcessRequest(array $data) { $this->setPostPHID(idx($data, 'phid')); $this->setPhameTitle(idx($data, 'phametitle')); $this->setBloggerName(idx($data, 'bloggername')); } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $post_phid = null; if ($this->getPostPHID()) { $post_phid = $this->getPostPHID(); if (!$post_phid) { return new Aphront404Response(); } $post = id(new PhamePost())->loadOneWhere( 'phid = %s', $post_phid); if ($post) { $this->setPhameTitle($post->getPhameTitle()); } $blogger = id(new PhabricatorUser())->loadOneWhere( 'phid = %s', $post->getBloggerPHID()); if (!$blogger) { return new Aphront404Response(); } } else if ($this->getBloggerName() && $this->getPhameTitle()) { $phame_title = $this->getPhameTitle(); $phame_title = PhabricatorSlug::normalize($phame_title); $blogger = id(new PhabricatorUser())->loadOneWhere( 'username = %s', $this->getBloggerName()); if (!$blogger) { return new Aphront404Response(); } $post = id(new PhamePost())->loadOneWhere( 'bloggerPHID = %s AND phameTitle = %s', $blogger->getPHID(), $phame_title); if ($post && $phame_title != $this->getPhameTitle()) { $uri = $post->getViewURI($this->getBloggerName()); return id(new AphrontRedirectResponse())->setURI($uri); } } if (!$post) { return new Aphront404Response(); } if ($post->isDraft() && $post->getBloggerPHID() != $user->getPHID()) { return new Aphront404Response(); } if ($post->isDraft()) { $notice = id(new AphrontErrorView()) ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) ->setTitle('You are previewing a draft.') ->setErrors(array( 'Only you can see this draft until you publish it.', 'If you chose a comment widget it will show up when you publish.', )); } else { $notice = null; } $page = id(new PhamePostDetailView()) ->setUser($user) ->setRequestURI($request->getRequestURI()) ->setBlogger($blogger) ->setPost($post); $this->setShowSideNav(false); return $this->buildStandardPageResponse( array( $notice, $page, ), array( 'title' => $post->getTitle(), )); } }