3 abstract class PhameLiveController
extends PhameController
{
10 public function shouldAllowPublic() {
14 protected function getIsExternal() {
15 return $this->isExternal
;
18 protected function getIsLive() {
22 protected function getBlog() {
26 protected function getPost() {
30 protected function setupLiveEnvironment() {
31 $request = $this->getRequest();
32 $viewer = $this->getViewer();
34 $site = $request->getSite();
35 $blog_id = $request->getURIData('blogID');
36 $post_id = $request->getURIData('id');
38 if ($site instanceof PhameBlogSite
) {
39 // This is a live page on a custom domain. We already looked up the blog
40 // in the Site handler by examining the domain, so we don't need to do
43 $blog = $site->getBlog();
46 } else if ($blog_id) {
47 // This is a blog detail view, an internal blog live view, or an
48 // internal post live view The internal post detail view is handled
52 if ($request->getURIData('live')) {
58 $blog_query = id(new PhameBlogQuery())
60 ->needProfileImage(true)
61 ->needHeaderImage(true)
62 ->withIDs(array($blog_id));
64 // If this is a live view, only show active blogs.
66 $blog_query->withStatuses(
68 PhameBlog
::STATUS_ACTIVE
,
72 $blog = $blog_query->executeOne();
74 $this->isExternal
= $is_external;
75 $this->isLive
= $is_live;
76 return new Aphront404Response();
80 // This is a post detail page, so we'll figure out the blog by loading
87 $this->isExternal
= $is_external;
88 $this->isLive
= $is_live;
90 if (strlen($post_id)) {
91 $post_query = id(new PhamePostQuery())
93 ->needHeaderImage(true)
94 ->withIDs(array($post_id));
96 // Only show published posts on external domains.
98 $post_query->withVisibility(
99 array(PhameConstants
::VISIBILITY_PUBLISHED
));
102 $post = $post_query->executeOne();
106 return new Aphront404Response();
109 // If this is a post detail page, the URI didn't come with a blog ID,
112 $blog = $post->getBlog();
121 // If we have a post, canonicalize the URI to the post's current slug and
122 // redirect the user if it isn't correct. Likewise, canonicalize the URI
123 // if the blog ID is wrong. See T13353.
125 $slug = $request->getURIData('slug');
127 $wrong_slug = ($post->getSlug() !== $slug);
128 $wrong_blog = ($post->getBlog()->getID() !== $blog->getID());
130 if ($wrong_slug ||
$wrong_blog) {
133 $uri = $post->getExternalLiveURI();
135 $uri = $post->getInternalLiveURI();
138 $uri = $post->getViewURI();
141 $response = id(new AphrontRedirectResponse())
145 $response->setIsExternal(true);
155 protected function buildApplicationCrumbs() {
156 $blog = $this->getBlog();
157 $post = $this->getPost();
159 $is_live = $this->getIsLive();
160 $is_external = $this->getIsExternal();
162 // If this is an external view, don't put the "Phame" crumb or the
163 // "Blogs" crumb into the crumbs list.
165 $crumbs = new PHUICrumbsView();
166 // Link back to parent site
167 if ($blog->getParentSite() && $blog->getParentDomain()) {
168 $crumbs->addTextCrumb(
169 $blog->getParentSite(),
170 $blog->getExternalParentURI());
173 $crumbs = parent
::buildApplicationCrumbs();
174 $crumbs->addTextCrumb(
176 $this->getApplicationURI('blog/'));
179 $crumbs->setBorder(true);
185 $blog_uri = $blog->getExternalLiveURI();
187 $blog_uri = $blog->getInternalLiveURI();
190 $blog_uri = $blog->getViewURI();
196 $crumbs->addTextCrumb($blog->getName(), $blog_uri);
201 $crumbs->addTextCrumb('J'.$post->getID());
208 public function willSendResponse(AphrontResponse
$response) {
209 if ($this->getIsExternal()) {
210 if ($response instanceof Aphront404Response
) {
211 $page = $this->newPage()
212 ->setCrumbs($this->buildApplicationCrumbs());
214 $response = id(new Phame404Response())
219 return parent
::willSendResponse($response);
222 public function newPage() {
223 $page = parent
::newPage();
225 if ($this->getIsLive()) {
227 ->addClass('phame-live-view')
228 ->setShowChrome(false)
229 ->setShowFooter(false);