Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/phame/controller/PhameController.php b/src/applications/phame/controller/PhameController.php
index 1e485e07fe..2ce962e16b 100644
--- a/src/applications/phame/controller/PhameController.php
+++ b/src/applications/phame/controller/PhameController.php
@@ -1,191 +1,89 @@
<?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;
- private $showChrome = true;
- private $deviceReady = false;
- protected function setShowSideNav($value) {
- $this->showSideNav = (bool) $value;
- return $this;
- }
- private function showSideNav() {
- return $this->showSideNav;
- }
-
- 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;
- }
-
- public function buildStandardPageResponse($view, array $data) {
+ protected function renderSideNavFilterView() {
- $page = $this->buildStandardPageView();
+ $base_uri = new PhutilURI($this->getApplicationURI());
- $page->setApplicationName('Phame');
- $page->setBaseURI('/phame/');
- $page->setTitle(idx($data, 'title'));
- $page->setGlyph("\xe2\x9c\xa9");
- $page->setShowChrome($this->getShowChrome());
- $page->setDeviceReady($this->getDeviceReady());
-
- 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());
- }
-
- protected function renderSideNavFilterView($filter) {
- $base_uri = new PhutilURI('/phame/');
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI($base_uri);
+
$nav->addLabel('Create');
- $nav->addFilter('post/new', 'New Post');
- $nav->addFilter('blog/new', 'New Blog');
+ $nav->addFilter('post/new', 'New Post');
+ $nav->addFilter('blog/new', 'New Blog');
$nav->addSpacer();
+
$nav->addLabel('Posts');
- $nav->addFilter('post/draft',
- 'My Drafts');
- foreach ($this->getSideNavExtraDraftFilters() as $draft_filter) {
- $nav->addFilter($draft_filter['key'],
- $draft_filter['name'],
- idx($draft_filter, 'uri'));
- }
- $nav->addFilter('post/', 'My Posts');
- $nav->addFilter('post/all', 'All Posts');
- foreach ($this->getSideNavExtraPostFilters() as $post_filter) {
- $nav->addFilter($post_filter['key'],
- $post_filter['name'],
- idx($post_filter, 'uri'));
- }
+ $nav->addFilter('post/draft', 'My Drafts');
+ $nav->addFilter('post', 'My Posts');
+ $nav->addFilter('post/all', 'All Posts');
$nav->addSpacer();
+
$nav->addLabel('Blogs');
- foreach ($this->getSideNavBlogFilters() as $blog_filter) {
- $nav->addFilter($blog_filter['key'],
- $blog_filter['name'],
- idx($blog_filter, 'uri'));
- }
+ $nav->addFilter('blog/user', 'Joinable Blogs');
+ $nav->addFilter('blog/all', 'All Blogs');
- $nav->selectFilter($filter);
+ $nav->selectFilter(null);
return $nav;
}
- protected function getSideNavExtraDraftFilters() {
- return array();
- }
-
- protected function getSideNavExtraPostFilters() {
- return array();
- }
-
- protected function getSideNavBlogFilters() {
- return array(
- array(
- 'key' => 'blog/user',
- 'name' => 'My Blogs',
- ),
- array(
- 'key' => 'blog/all',
- 'name' => 'All Blogs',
- ),
- );
- }
-
- protected function getSideNavFilter() {
- return 'post';
- }
-
- 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;
- }
-
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())
->setHref($this->getApplicationURI('post/view/'.$post->getID().'/'))
->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));
}
$list->addItem($item);
}
return $list;
}
}
diff --git a/src/applications/phame/controller/blog/PhameBlogEditController.php b/src/applications/phame/controller/blog/PhameBlogEditController.php
index c3af88a262..35cddc9b52 100644
--- a/src/applications/phame/controller/blog/PhameBlogEditController.php
+++ b/src/applications/phame/controller/blog/PhameBlogEditController.php
@@ -1,203 +1,208 @@
<?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
*/
final class PhameBlogEditController
extends PhameController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if ($this->id) {
$blog = id(new PhameBlogQuery())
->setViewer($user)
->withIDs(array($this->id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT
))
->executeOne();
if (!$blog) {
return new Aphront404Response();
}
$submit_button = pht('Save Changes');
$page_title = pht('Edit Blog');
$cancel_uri = $this->getApplicationURI('blog/view/'.$blog->getID().'/');
} else {
$blog = id(new PhameBlog())
->setCreatorPHID($user->getPHID());
$blog->setViewPolicy(PhabricatorPolicies::POLICY_USER);
$blog->setEditPolicy(PhabricatorPolicies::POLICY_USER);
$blog->setJoinPolicy(PhabricatorPolicies::POLICY_USER);
$submit_button = pht('Create Blog');
$page_title = pht('Create Blog');
$cancel_uri = $this->getApplicationURI();
}
$e_name = true;
$e_custom_domain = null;
$errors = array();
if ($request->isFormPost()) {
$name = $request->getStr('name');
$description = $request->getStr('description');
$custom_domain = $request->getStr('custom_domain');
$skin = $request->getStr('skin');
if (empty($name)) {
$errors[] = 'You must give the blog a name.';
$e_name = 'Required';
} else {
$e_name = null;
}
$blog->setName($name);
$blog->setDescription($description);
$blog->setDomain($custom_domain);
$blog->setSkin($skin);
if (!empty($custom_domain)) {
$error = $blog->validateCustomDomain($custom_domain);
if ($error) {
$errors[] = $error;
$e_custom_domain = 'Invalid';
}
}
$blog->setViewPolicy($request->getStr('can_view'));
$blog->setEditPolicy($request->getStr('can_edit'));
$blog->setJoinPolicy($request->getStr('can_join'));
// Don't let users remove their ability to edit blogs.
PhabricatorPolicyFilter::mustRetainCapability(
$user,
$blog,
PhabricatorPolicyCapability::CAN_EDIT);
if (!$errors) {
try {
$blog->save();
return id(new AphrontRedirectResponse())
->setURI($this->getApplicationURI('blog/view/'.$blog->getID().'/'));
} catch (AphrontQueryDuplicateKeyException $ex) {
$errors[] = 'Domain must be unique.';
$e_custom_domain = 'Not Unique';
}
}
}
$policies = id(new PhabricatorPolicyQuery())
->setViewer($user)
->setObject($blog)
->execute();
$form = id(new AphrontFormView())
->setUser($user)
->setFlexible(true)
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Name')
->setName('name')
->setValue($blog->getName())
->setID('blog-name')
->setError($e_name)
)
->appendChild(
id(new PhabricatorRemarkupControl())
->setLabel('Description')
->setName('description')
->setValue($blog->getDescription())
->setID('blog-description')
)
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($blog)
->setPolicies($policies)
->setName('can_view'))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicyObject($blog)
->setPolicies($policies)
->setName('can_edit'))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setCapability(PhabricatorPolicyCapability::CAN_JOIN)
->setPolicyObject($blog)
->setPolicies($policies)
->setName('can_join'))
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Custom Domain')
->setName('custom_domain')
->setValue($blog->getDomain())
->setCaption('Must include at least one dot (.), e.g. '.
'blog.example.com')
->setError($e_custom_domain)
)
->appendChild(
id(new AphrontFormSelectControl())
->setLabel('Skin')
->setName('skin')
->setValue($blog->getSkin())
->setOptions(PhameBlog::getSkinOptionsForSelect())
)
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri)
->setValue($submit_button)
);
if ($errors) {
$error_view = id(new AphrontErrorView())
->setTitle('Form Errors')
->setErrors($errors);
} else {
$error_view = null;
}
- $nav = $this->renderSideNavFilterView(null);
+ $header = id(new PhabricatorHeaderView())
+ ->setHeader($page_title);
+
+ $nav = $this->renderSideNavFilterView();
+ $nav->selectFilter($this->id ? null : 'blog/new');
$nav->appendChild(
array(
+ $header,
$error_view,
$form,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $page_title,
));
}
}
diff --git a/src/applications/phame/controller/blog/PhameBlogListController.php b/src/applications/phame/controller/blog/PhameBlogListController.php
index fb8665c1fa..d066f69666 100644
--- a/src/applications/phame/controller/blog/PhameBlogListController.php
+++ b/src/applications/phame/controller/blog/PhameBlogListController.php
@@ -1,105 +1,105 @@
<?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
*/
final class PhameBlogListController extends PhameController {
private $filter;
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$nav = $this->renderSideNavFilterView(null);
$filter = $nav->selectFilter('blog/'.$this->filter, 'blog/user');
$query = id(new PhameBlogQuery())
->setViewer($user);
switch ($filter) {
case 'blog/all':
- $title = 'All Blogs';
- $nodata = 'No blogs have been created.';
+ $title = pht('All Blogs');
+ $nodata = pht('No blogs have been created.');
break;
case 'blog/user':
- $title = 'My Blogs';
- $nodata = 'There are no blogs you can contribute to.';
+ $title = pht('Joinable Blogs');
+ $nodata = pht('There are no blogs you can contribute to.');
$query->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_JOIN,
));
break;
default:
throw new Exception("Unknown filter '{$filter}'!");
}
$pager = id(new AphrontPagerView())
->setURI($request->getRequestURI(), 'offset')
->setOffset($request->getInt('offset'));
$blogs = $query->executeWithOffsetPager($pager);
$header = id(new PhabricatorHeaderView())
->setHeader($title);
$blog_list = $this->renderBlogList($blogs, $user, $nodata);
$blog_list->setPager($pager);
$nav->appendChild(
array(
$header,
$blog_list,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
}
private function renderBlogList(
array $blogs,
PhabricatorUser $user,
$nodata) {
$view = new PhabricatorObjectItemListView();
$view->setNoDataString($nodata);
foreach ($blogs as $blog) {
$item = id(new PhabricatorObjectItemView())
->setHeader($blog->getName())
->setHref($this->getApplicationURI('blog/view/'.$blog->getID().'/'))
->addDetail(
- 'Custom Domain',
+ pht('Custom Domain'),
phutil_escape_html($blog->getDomain()));
$view->addItem($item);
}
return $view;
}
}
diff --git a/src/applications/phame/controller/post/PhamePostListController.php b/src/applications/phame/controller/post/PhamePostListController.php
index 3f926c9e98..ed437ebb5d 100644
--- a/src/applications/phame/controller/post/PhamePostListController.php
+++ b/src/applications/phame/controller/post/PhamePostListController.php
@@ -1,105 +1,109 @@
<?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
*/
final class PhamePostListController extends PhameController {
private $bloggername;
private $filter;
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter', 'blogger');
$this->bloggername = idx($data, 'bloggername');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$query = id(new PhamePostQuery())
->setViewer($user);
+ $nav = $this->renderSideNavFilterView();
+
switch ($this->filter) {
case 'draft':
$query->withBloggerPHIDs(array($user->getPHID()));
$query->withVisibility(PhamePost::VISIBILITY_DRAFT);
$nodata = pht('You have no unpublished drafts.');
$title = pht('Unpublished Drafts');
+ $nav->selectFilter('post/draft');
break;
case 'blogger':
if ($this->bloggername) {
$blogger = id(new PhabricatorUser())->loadOneWhere(
'username = %s',
$this->bloggername);
if (!$blogger) {
return new Aphront404Response();
}
} else {
$blogger = $user;
}
$query->withBloggerPHIDs(array($blogger->getPHID()));
if ($blogger->getPHID() == $user->getPHID()) {
+ $nav->selectFilter('post');
$nodata = pht('You have not written any posts.');
} else {
$nodata = pht('%s has not written any posts.', $blogger);
}
$title = pht('Posts By %s', $blogger);
break;
case 'all':
$nodata = pht('There are no visible posts.');
$title = pht('Posts');
+ $nav->selectFilter('post/all');
break;
default:
throw new Exception("Unknown filter '{$this->filter}'!");
}
$pager = id(new AphrontCursorPagerView())
->readFromRequest($request);
$posts = $query->executeWithCursorPager($pager);
$handle_phids = array_merge(
mpull($posts, 'getBloggerPHID'),
mpull($posts, 'getBlogPHID'));
$this->loadHandles($handle_phids);
$header = id(new PhabricatorHeaderView())
->setHeader($title);
$post_list = $this->renderPostList($posts, $user, $nodata);
- $nav = $this->renderSideNavFilterView(null);
$nav->appendChild(
array(
$header,
$post_list,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
}
}
diff --git a/src/applications/phame/controller/post/PhamePostNewController.php b/src/applications/phame/controller/post/PhamePostNewController.php
index f181cc4654..6393c2d9b0 100644
--- a/src/applications/phame/controller/post/PhamePostNewController.php
+++ b/src/applications/phame/controller/post/PhamePostNewController.php
@@ -1,70 +1,77 @@
<?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
*/
final class PhamePostNewController extends PhameController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$blogs = id(new PhameBlogQuery())
->setViewer($user)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_JOIN,
))
->execute();
- $nav = $this->renderSideNavFilterView(null);
+ $nav = $this->renderSideNavFilterView();
+ $nav->selectFilter('post/new');
$nav->appendChild(
id(new PhabricatorHeaderView())->setHeader(
pht('Create Post')));
if (!$blogs) {
+ $notification = id(new AphrontErrorView())
+ ->setSeverity(AphrontErrorView::SEVERITY_NODATA)
+ ->appendChild(
+ pht('You do not have permission to join any blogs. Create a blog '.
+ 'first, then you can post to it.'));
+ $nav->appendChild($notification);
} else {
$options = mpull($blogs, 'getName', 'getID');
$form = id(new AphrontFormView())
->setUser($user)
->setMethod('GET')
->setFlexible(true)
->setAction($this->getApplicationURI('post/edit/'))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel('Blog')
->setName('blog')
->setOptions($options))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Continue'));
$nav->appendChild($form);
}
return $this->buildApplicationPage(
$nav,
array(
'title' => 'Create Post',
'device' => true,
));
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 14, 8:36 AM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
336892
Default Alt Text
(22 KB)

Event Timeline