Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/skins/PhameBasicBlogSkin.php
| Show All 10 Lines | abstract class PhameBasicBlogSkin extends PhameBlogSkin { | ||||
| private $description; | private $description; | ||||
| private $oGType; | private $oGType; | ||||
| private $uriPath; | private $uriPath; | ||||
| public function setURIPath($uri_path) { | public function setURIPath($uri_path) { | ||||
| $this->uriPath = $uri_path; | $this->uriPath = $uri_path; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getURIPath() { | public function getURIPath() { | ||||
| return $this->uriPath; | return $this->uriPath; | ||||
| } | } | ||||
| protected function setOGType($og_type) { | protected function setOGType($og_type) { | ||||
| $this->oGType = $og_type; | $this->oGType = $og_type; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getOGType() { | protected function getOGType() { | ||||
| return $this->oGType; | return $this->oGType; | ||||
| } | } | ||||
| protected function setDescription($description) { | protected function setDescription($description) { | ||||
| $this->description = $description; | $this->description = $description; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getDescription() { | protected function getDescription() { | ||||
| return $this->description; | return $this->description; | ||||
| } | } | ||||
| protected function setTitle($title) { | protected function setTitle($title) { | ||||
| $this->title = $title; | $this->title = $title; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getTitle() { | protected function getTitle() { | ||||
| return $this->title; | return $this->title; | ||||
| } | } | ||||
| public function processRequest() { | public function handleRequest(AphrontRequest $request) { | ||||
| $request = $this->getRequest(); | |||||
| $content = $this->renderContent($request); | $content = $this->renderContent($request); | ||||
| if (!$content) { | if (!$content) { | ||||
| $content = $this->render404Page(); | $content = $this->render404Page(); | ||||
| } | } | ||||
| $content = array( | $content = array( | ||||
| $this->renderHeader(), | $this->renderHeader(), | ||||
| $content, | $content, | ||||
| $this->renderFooter(), | $this->renderFooter(), | ||||
| ); | ); | ||||
| $view = id(new PhabricatorBarePageView()) | $view = id(new PhabricatorBarePageView()) | ||||
| ->setRequest($request) | ->setRequest($request) | ||||
| ->setController($this) | ->setController($this) | ||||
| ->setDeviceReady(true) | ->setDeviceReady(true) | ||||
| ->setTitle($this->getBlog()->getName()); | ->setTitle($this->getBlog()->getName()); | ||||
| if ($this->getPreview()) { | if ($this->getPreview()) { | ||||
| $view->setFrameable(true); | $view->setFrameable(true); | ||||
| } | } | ||||
| $view->appendChild($content); | $view->appendChild($content); | ||||
| $response = new AphrontWebpageResponse(); | $response = new AphrontWebpageResponse(); | ||||
| $response->setContent($view->render()); | $response->setContent($view->render()); | ||||
| return $response; | return $response; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | |||||
| /* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| protected function renderContent(AphrontRequest $request) { | protected function renderContent(AphrontRequest $request) { | ||||
| $user = $request->getUser(); | $viewer = $request->getViewer(); | ||||
| $matches = null; | $matches = null; | ||||
| $path = $request->getPath(); | $path = $request->getPath(); | ||||
| // default to the blog-wide values | // default to the blog-wide values | ||||
| $this->setTitle($this->getBlog()->getName()); | $this->setTitle($this->getBlog()->getName()); | ||||
| $this->setDescription($this->getBlog()->getDescription()); | $this->setDescription($this->getBlog()->getDescription()); | ||||
| $this->setOGType('website'); | $this->setOGType('website'); | ||||
| $this->setURIPath(''); | $this->setURIPath(''); | ||||
| if (preg_match('@^/post/(?P<name>.*)$@', $path, $matches)) { | if (preg_match('@^/post/(?P<name>.*)$@', $path, $matches)) { | ||||
| $post = id(new PhamePostQuery()) | $post = id(new PhamePostQuery()) | ||||
| ->setViewer($user) | ->setViewer($viewer) | ||||
| ->withBlogPHIDs(array($this->getBlog()->getPHID())) | ->withBlogPHIDs(array($this->getBlog()->getPHID())) | ||||
| ->withPhameTitles(array($matches['name'])) | ->withPhameTitles(array($matches['name'])) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if ($post) { | if ($post) { | ||||
| $description = $post->getMarkupText(PhamePost::MARKUP_FIELD_SUMMARY); | $description = $post->getMarkupText(PhamePost::MARKUP_FIELD_SUMMARY); | ||||
| $this->setTitle($post->getTitle()); | $this->setTitle($post->getTitle()); | ||||
| $this->setDescription($description); | $this->setDescription($description); | ||||
| Show All 13 Lines | if (preg_match('@^/post/(?P<name>.*)$@', $path, $matches)) { | ||||
| // Just show the first page. | // Just show the first page. | ||||
| } else { | } else { | ||||
| return null; | return null; | ||||
| } | } | ||||
| $pager->setPageSize($this->getPageSize()); | $pager->setPageSize($this->getPageSize()); | ||||
| $posts = id(new PhamePostQuery()) | $posts = id(new PhamePostQuery()) | ||||
| ->setViewer($user) | ->setViewer($viewer) | ||||
| ->withBlogPHIDs(array($this->getBlog()->getPHID())) | ->withBlogPHIDs(array($this->getBlog()->getPHID())) | ||||
| ->executeWithCursorPager($pager); | ->executeWithCursorPager($pager); | ||||
| $this->pager = $pager; | $this->pager = $pager; | ||||
| if ($posts) { | if ($posts) { | ||||
| $views = $this->buildPostViews($posts); | $views = $this->buildPostViews($posts); | ||||
| return $this->renderPostList($views); | return $this->renderPostList($views); | ||||
| } | } | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| private function buildPostViews(array $posts) { | private function buildPostViews(array $posts) { | ||||
| assert_instances_of($posts, 'PhamePost'); | assert_instances_of($posts, 'PhamePost'); | ||||
| $user = $this->getRequest()->getUser(); | $viewer = $this->getViewer(); | ||||
| $engine = id(new PhabricatorMarkupEngine()) | $engine = id(new PhabricatorMarkupEngine()) | ||||
| ->setViewer($user); | ->setViewer($viewer); | ||||
| $phids = array(); | $phids = array(); | ||||
| foreach ($posts as $post) { | foreach ($posts as $post) { | ||||
| $engine->addObject($post, PhamePost::MARKUP_FIELD_BODY); | $engine->addObject($post, PhamePost::MARKUP_FIELD_BODY); | ||||
| $engine->addObject($post, PhamePost::MARKUP_FIELD_SUMMARY); | $engine->addObject($post, PhamePost::MARKUP_FIELD_SUMMARY); | ||||
| $phids[] = $post->getBloggerPHID(); | $phids[] = $post->getBloggerPHID(); | ||||
| } | } | ||||
| $handles = id(new PhabricatorHandleQuery()) | $handles = id(new PhabricatorHandleQuery()) | ||||
| ->setViewer($user) | ->setViewer($viewer) | ||||
| ->withPHIDs($phids) | ->withPHIDs($phids) | ||||
| ->execute(); | ->execute(); | ||||
| $engine->process(); | $engine->process(); | ||||
| $views = array(); | $views = array(); | ||||
| foreach ($posts as $post) { | foreach ($posts as $post) { | ||||
| $view = id(new PhamePostView()) | $view = id(new PhamePostView()) | ||||
| ->setUser($user) | ->setUser($viewer) | ||||
| ->setSkin($this) | ->setSkin($this) | ||||
| ->setPost($post) | ->setPost($post) | ||||
| ->setBody($engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY)) | ->setBody($engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY)) | ||||
| ->setSummary($engine->getOutput($post, PhamePost::MARKUP_FIELD_SUMMARY)) | ->setSummary($engine->getOutput($post, PhamePost::MARKUP_FIELD_SUMMARY)) | ||||
| ->setAuthor($handles[$post->getBloggerPHID()]); | ->setAuthor($handles[$post->getBloggerPHID()]); | ||||
| $post->makeEphemeral(); | $post->makeEphemeral(); | ||||
| if (!$post->getDatePublished()) { | if (!$post->getDatePublished()) { | ||||
| Show All 10 Lines | |||||