2012-04-12 22:09:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group phame
|
|
|
|
*/
|
|
|
|
abstract class PhameController extends PhabricatorController {
|
|
|
|
private $showSideNav;
|
2012-10-13 01:01:33 +02:00
|
|
|
private $showChrome = true;
|
|
|
|
private $deviceReady = false;
|
2012-04-12 22:09:04 +02:00
|
|
|
|
|
|
|
protected function setShowSideNav($value) {
|
|
|
|
$this->showSideNav = (bool) $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
private function showSideNav() {
|
|
|
|
return $this->showSideNav;
|
|
|
|
}
|
|
|
|
|
2012-10-13 01:01:33 +02:00
|
|
|
protected function setShowChrome($show_chrome) {
|
|
|
|
$this->showChrome = $show_chrome;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
private function getShowChrome() {
|
|
|
|
return $this->showChrome;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDeviceReady($device_ready) {
|
|
|
|
$this->deviceReady = $device_ready;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getDeviceReady() {
|
|
|
|
return $this->deviceReady;
|
|
|
|
}
|
|
|
|
|
2012-04-12 22:09:04 +02:00
|
|
|
public function buildStandardPageResponse($view, array $data) {
|
|
|
|
|
|
|
|
$page = $this->buildStandardPageView();
|
|
|
|
|
|
|
|
$page->setApplicationName('Phame');
|
|
|
|
$page->setBaseURI('/phame/');
|
|
|
|
$page->setTitle(idx($data, 'title'));
|
|
|
|
$page->setGlyph("\xe2\x9c\xa9");
|
2012-10-13 01:01:33 +02:00
|
|
|
$page->setShowChrome($this->getShowChrome());
|
|
|
|
$page->setDeviceReady($this->getDeviceReady());
|
2012-04-12 22:09:04 +02:00
|
|
|
|
|
|
|
if ($this->showSideNav()) {
|
|
|
|
$nav = $this->renderSideNavFilterView($this->getSideNavFilter());
|
|
|
|
$nav->appendChild($view);
|
|
|
|
$page->appendChild($nav);
|
|
|
|
} else {
|
|
|
|
$page->appendChild($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = new AphrontWebpageResponse();
|
|
|
|
return $response->setContent($page->render());
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
protected function renderSideNavFilterView($filter) {
|
2012-07-06 00:43:14 +02:00
|
|
|
$base_uri = new PhutilURI('/phame/');
|
2012-04-12 22:09:04 +02:00
|
|
|
$nav = new AphrontSideNavFilterView();
|
2012-07-06 00:43:14 +02:00
|
|
|
$nav->setBaseURI($base_uri);
|
2012-10-15 23:50:12 +02:00
|
|
|
$nav->addLabel('Create');
|
2012-10-15 23:50:45 +02:00
|
|
|
$nav->addFilter('post/new', 'New Post');
|
2012-10-15 23:50:12 +02:00
|
|
|
$nav->addFilter('blog/new', 'New Blog');
|
|
|
|
|
|
|
|
$nav->addSpacer();
|
|
|
|
$nav->addLabel('Posts');
|
2012-10-15 23:50:37 +02:00
|
|
|
$nav->addFilter('post/draft',
|
2012-04-12 22:09:04 +02:00
|
|
|
'My Drafts');
|
2012-07-19 18:03:10 +02:00
|
|
|
foreach ($this->getSideNavExtraDraftFilters() as $draft_filter) {
|
|
|
|
$nav->addFilter($draft_filter['key'],
|
|
|
|
$draft_filter['name'],
|
|
|
|
idx($draft_filter, 'uri'));
|
|
|
|
}
|
2012-10-15 23:50:37 +02:00
|
|
|
$nav->addFilter('post/', 'My Posts');
|
|
|
|
$nav->addFilter('post/all', 'All Posts');
|
2012-04-12 22:09:04 +02:00
|
|
|
foreach ($this->getSideNavExtraPostFilters() as $post_filter) {
|
|
|
|
$nav->addFilter($post_filter['key'],
|
2012-07-06 00:43:14 +02:00
|
|
|
$post_filter['name'],
|
|
|
|
idx($post_filter, 'uri'));
|
2012-04-12 22:09:04 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
$nav->addSpacer();
|
|
|
|
$nav->addLabel('Blogs');
|
|
|
|
foreach ($this->getSideNavBlogFilters() as $blog_filter) {
|
|
|
|
$nav->addFilter($blog_filter['key'],
|
|
|
|
$blog_filter['name'],
|
|
|
|
idx($blog_filter, 'uri'));
|
|
|
|
}
|
|
|
|
|
2012-07-06 00:43:14 +02:00
|
|
|
$nav->selectFilter($filter);
|
2012-04-12 22:09:04 +02:00
|
|
|
|
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
protected function getSideNavExtraDraftFilters() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2012-04-12 22:09:04 +02:00
|
|
|
protected function getSideNavExtraPostFilters() {
|
|
|
|
return array();
|
|
|
|
}
|
2012-07-19 18:03:10 +02:00
|
|
|
|
|
|
|
protected function getSideNavBlogFilters() {
|
|
|
|
return array(
|
|
|
|
array(
|
2012-10-15 23:50:12 +02:00
|
|
|
'key' => 'blog/user',
|
2012-07-19 18:03:10 +02:00
|
|
|
'name' => 'My Blogs',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'key' => 'blog/all',
|
|
|
|
'name' => 'All Blogs',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-12 22:09:04 +02:00
|
|
|
protected function getSideNavFilter() {
|
|
|
|
return 'post';
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
protected function getPager() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
$page_size = 50;
|
|
|
|
$pager->setURI($request->getRequestURI(), 'offset');
|
|
|
|
$pager->setPageSize($page_size);
|
|
|
|
$pager->setOffset($request->getInt('offset'));
|
|
|
|
|
|
|
|
return $pager;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildNoticeView() {
|
|
|
|
$notice_view = id(new AphrontErrorView())
|
|
|
|
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
|
|
|
|
->setTitle('Meta thoughts and feelings');
|
|
|
|
return $notice_view;
|
|
|
|
}
|
2012-10-15 23:50:12 +02:00
|
|
|
|
|
|
|
protected function renderPostList(
|
|
|
|
array $posts,
|
|
|
|
PhabricatorUser $user,
|
|
|
|
$nodata) {
|
|
|
|
assert_instances_of($posts, 'PhamePost');
|
|
|
|
|
|
|
|
$list = id(new PhabricatorObjectItemListView())
|
|
|
|
->setNoDataString($nodata);
|
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
$item = id(new PhabricatorObjectItemView())
|
|
|
|
->setHeader($post->getTitle())
|
2012-10-15 23:50:45 +02:00
|
|
|
->setHref($this->getApplicationURI('post/view/'.$post->getID().'/'))
|
2012-10-15 23:50:37 +02:00
|
|
|
->addDetail(
|
|
|
|
pht('Blogger'),
|
|
|
|
$this->getHandle($post->getBloggerPHID())->renderLink())
|
|
|
|
->addDetail(
|
|
|
|
pht('Blog'),
|
|
|
|
$post->getBlog()
|
|
|
|
? $this->getHandle($post->getBlog()->getPHID())->renderLink()
|
|
|
|
: '-');
|
|
|
|
|
|
|
|
if ($post->isDraft()) {
|
|
|
|
$item->addAttribute(pht('Draft'));
|
|
|
|
} else {
|
|
|
|
$date_published = phabricator_datetime(
|
|
|
|
$post->getDatePublished(),
|
|
|
|
$user);
|
|
|
|
$item->addAttribute(pht('Published on %s', $date_published));
|
|
|
|
}
|
2012-10-15 23:50:12 +02:00
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
2012-04-12 22:09:04 +02:00
|
|
|
}
|