Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2890527
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/phame/skins/PhameBasicBlogSkin.php b/src/applications/phame/skins/PhameBasicBlogSkin.php
index addf25eedd..420a52ae85 100644
--- a/src/applications/phame/skins/PhameBasicBlogSkin.php
+++ b/src/applications/phame/skins/PhameBasicBlogSkin.php
@@ -1,269 +1,280 @@
<?php
/**
* @task paging Paging
* @task internal Internals
* @group phame
*/
abstract class PhameBasicBlogSkin extends PhameBlogSkin {
private $pager;
+ private $title;
+
+ protected function setTitle($title) {
+ $this->title = $title;
+ return $this;
+ }
+ protected function getTitle() {
+ return $this->title;
+ }
public function processRequest() {
$request = $this->getRequest();
$content = $this->renderContent($request);
if (!$content) {
$content = $this->render404Page();
}
$content = array(
$this->renderHeader(),
$content,
$this->renderFooter(),
);
$view = id(new PhabricatorBarePageView())
->setRequest($request)
->setController($this)
->setDeviceReady(true)
->setTitle($this->getBlog()->getName());
if ($this->getPreview()) {
$view->setFrameable(true);
}
$view->appendChild($content);
$response = new AphrontWebpageResponse();
$response->setContent($view->render());
return $response;
}
public function getSkinName() {
return get_class($this);
}
abstract protected function renderHeader();
abstract protected function renderFooter();
protected function renderPostDetail(PhamePostView $post) {
return $post;
}
protected function renderPostList(array $posts) {
$summaries = array();
foreach ($posts as $post) {
$summaries[] = $post->renderWithSummary();
}
$list = phutil_render_tag(
'div',
array(
'class' => 'phame-post-list',
),
id(new AphrontNullView())->appendChild($summaries)->render());
$pager = $this->renderOlderPageLink().$this->renderNewerPageLink();
if ($pager) {
$pager = phutil_render_tag(
'div',
array(
'class' => 'phame-pager',
));
}
return $list.$pager;
}
protected function render404Page() {
return '<h2>404 Not Found</h2>';
}
final public function getResourceURI($resource) {
$root = $this->getSpecification()->getRootDirectory();
$path = $root.DIRECTORY_SEPARATOR.$resource;
$data = Filesystem::readFile($path);
$hash = PhabricatorHash::digest($data);
$hash = substr($hash, 0, 6);
$id = $this->getBlog()->getID();
$uri = '/phame/r/'.$id.'/'.$hash.'/'.$resource;
$uri = PhabricatorEnv::getCDNURI($uri);
return $uri;
}
/* -( Paging )------------------------------------------------------------- */
/**
* @task paging
*/
public function getPageSize() {
return 100;
}
/**
* @task paging
*/
protected function getOlderPageURI() {
if ($this->pager) {
$next = $this->pager->getNextPageID();
if ($next) {
return $this->getURI('older/'.$next.'/');
}
}
return null;
}
/**
* @task paging
*/
protected function renderOlderPageLink() {
$uri = $this->getOlderPageURI();
if (!$uri) {
return null;
}
return phutil_render_tag(
'a',
array(
'class' => 'phame-page-link phame-page-older',
'href' => $uri,
),
pht("\xE2\x80\xB9 Older"));
}
/**
* @task paging
*/
protected function getNewerPageURI() {
if ($this->pager) {
- $next = $this->pager->getNextPageID();
+ $next = $this->pager->getPrevPageID();
if ($next) {
return $this->getURI('newer/'.$next.'/');
}
}
return null;
}
/**
* @task paging
*/
protected function renderNewerPageLink() {
$uri = $this->getNewerPageURI();
if (!$uri) {
return null;
}
return phutil_render_tag(
'a',
array(
'class' => 'phame-page-link phame-page-newer',
'href' => $uri,
),
pht("Newer \xE2\x80\xBA"));
}
/* -( Internals )---------------------------------------------------------- */
/**
* @task internal
*/
protected function renderContent(AphrontRequest $request) {
$user = $request->getUser();
$matches = null;
$path = $request->getPath();
+ $this->setTitle($this->getBlog()->getName());
if (preg_match('@^/post/(?P<name>.*)$@', $path, $matches)) {
$post = id(new PhamePostQuery())
->setViewer($user)
->withBlogPHIDs(array($this->getBlog()->getPHID()))
->withPhameTitles(array($matches['name']))
->executeOne();
if ($post) {
+ $this->setTitle($post->getTitle());
$view = head($this->buildPostViews(array($post)));
return $this->renderPostDetail($view);
}
} else {
$pager = new AphrontCursorPagerView();
if (preg_match('@^/older/(?P<before>\d+)/$@', $path, $matches)) {
- $pager->setBeforeID($matches['before']);
+ $pager->setAfterID($matches['before']);
} else if (preg_match('@^/newer/(?P<after>\d)/$@', $path, $matches)) {
- $pager->setAfterID($matches['after']);
+ $pager->setBeforeID($matches['after']);
} else if (preg_match('@^/$@', $path, $matches)) {
// Just show the first page.
} else {
return null;
}
$pager->setPageSize($this->getPageSize());
$posts = id(new PhamePostQuery())
->setViewer($user)
->withBlogPHIDs(array($this->getBlog()->getPHID()))
->executeWithCursorPager($pager);
$this->pager = $pager;
if ($posts) {
$views = $this->buildPostViews($posts);
return $this->renderPostList($views);
}
}
return null;
}
private function buildPostViews(array $posts) {
assert_instances_of($posts, 'PhamePost');
$user = $this->getRequest()->getUser();
$engine = id(new PhabricatorMarkupEngine())
->setViewer($user);
$phids = array();
foreach ($posts as $post) {
$engine->addObject($post, PhamePost::MARKUP_FIELD_BODY);
$engine->addObject($post, PhamePost::MARKUP_FIELD_SUMMARY);
$phids[] = $post->getBloggerPHID();
}
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
$engine->process();
$views = array();
foreach ($posts as $post) {
$view = id(new PhamePostView())
->setViewer($user)
->setSkin($this)
->setPost($post)
->setBody($engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY))
->setSummary($engine->getOutput($post, PhamePost::MARKUP_FIELD_SUMMARY))
->setAuthor($handles[$post->getBloggerPHID()]);
$post->makeEphemeral();
if (!$post->getDatePublished()) {
$post->setDatePublished(time());
}
$views[] = $view;
}
return $views;
}
}
diff --git a/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php b/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php
index 28ae0e99ea..23f94f71d0 100644
--- a/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php
+++ b/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php
@@ -1,123 +1,123 @@
<?php
/**
* @group phame
*/
final class PhameBasicTemplateBlogSkin extends PhameBasicBlogSkin {
private $cssResources;
public function processRequest() {
$root = dirname(phutil_get_library_root('phabricator'));
require_once $root.'/support/phame/libskin.php';
$css = $this->getPath('css/');
if (Filesystem::pathExists($css)) {
$this->cssResources = array();
foreach (Filesystem::listDirectory($css) as $path) {
if (!preg_match('/.css$/', $path)) {
continue;
}
$this->cssResources[] = phutil_render_tag(
'link',
array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => $this->getResourceURI('css/'.$path),
));
}
$this->cssResources = implode("\n", $this->cssResources);
}
$request = $this->getRequest();
$content = $this->renderContent($request);
if (!$content) {
$content = $this->render404Page();
}
$content = array(
$this->renderHeader(),
$content,
$this->renderFooter(),
);
$response = new AphrontWebpageResponse();
$response->setContent(implode("\n", $content));
return $response;
}
public function getCSSResources() {
return $this->cssResources;
}
public function getName() {
return $this->getSpecification()->getName();
}
public function getPath($to_file = null) {
$path = $this->getSpecification()->getRootDirectory();
if ($to_file) {
$path = $path.DIRECTORY_SEPARATOR.$to_file;
}
return $path;
}
private function renderTemplate($__template__, array $__scope__) {
chdir($this->getPath());
ob_start();
if (Filesystem::pathExists($this->getPath($__template__))) {
// Fool lint.
$__evil__ = 'extract';
$__evil__($__scope__ + $this->getDefaultScope());
require $this->getPath($__template__);
}
return ob_get_clean();
}
private function getDefaultScope() {
return array(
- 'skin' => $this,
- 'blog' => $this->getBlog(),
- 'uri' => $this->getURI(''),
+ 'skin' => $this,
+ 'blog' => $this->getBlog(),
+ 'uri' => $this->getURI(''),
+ 'title' => $this->getTitle(),
);
}
protected function renderHeader() {
return $this->renderTemplate(
'header.php',
- array(
- 'title' => $this->getBlog()->getName(),
- ));
+ array()
+ );
}
protected function renderFooter() {
return $this->renderTemplate('footer.php', array());
}
protected function render404Page() {
return $this->renderTemplate('404.php', array());
}
protected function renderPostDetail(PhamePostView $post) {
return $this->renderTemplate(
'post-detail.php',
array(
'post' => $post,
));
}
protected function renderPostList(array $posts) {
return $this->renderTemplate(
'post-list.php',
array(
'posts' => $posts,
- 'older' => $this->renderNewerPageLink(),
- 'newer' => $this->renderOlderPageLink(),
+ 'older' => $this->renderOlderPageLink(),
+ 'newer' => $this->renderNewerPageLink(),
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 13:43 (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1125181
Default Alt Text
(10 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment