mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Add a homepage for Phame
Summary: Sends `/phame/` to PhameHomeController, which is all published posts. Still some rough edges to work out for new posts, new blogs, but I think this is the right direction. Test Plan: go to Phame, see most recent posts, no drafts. click on find posts, see post list, click on find blogs, see blogs. {F1008800} Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9742 Differential Revision: https://secure.phabricator.com/D14618
This commit is contained in:
parent
2fba7e66e7
commit
4e6cd90e41
5 changed files with 217 additions and 62 deletions
|
@ -3312,6 +3312,7 @@ phutil_register_library_map(array(
|
|||
'PhameController' => 'applications/phame/controller/PhameController.php',
|
||||
'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php',
|
||||
'PhameDAO' => 'applications/phame/storage/PhameDAO.php',
|
||||
'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php',
|
||||
'PhamePost' => 'applications/phame/storage/PhamePost.php',
|
||||
'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php',
|
||||
'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php',
|
||||
|
@ -3319,6 +3320,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
|
||||
'PhamePostFramedController' => 'applications/phame/controller/post/PhamePostFramedController.php',
|
||||
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
|
||||
'PhamePostListView' => 'applications/phame/view/PhamePostListView.php',
|
||||
'PhamePostMailReceiver' => 'applications/phame/mail/PhamePostMailReceiver.php',
|
||||
'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php',
|
||||
'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php',
|
||||
|
@ -7632,6 +7634,7 @@ phutil_register_library_map(array(
|
|||
'PhameController' => 'PhabricatorController',
|
||||
'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod',
|
||||
'PhameDAO' => 'PhabricatorLiskDAO',
|
||||
'PhameHomeController' => 'PhamePostController',
|
||||
'PhamePost' => array(
|
||||
'PhameDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
|
@ -7649,6 +7652,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhamePostFramedController' => 'PhamePostController',
|
||||
'PhamePostListController' => 'PhamePostController',
|
||||
'PhamePostListView' => 'AphrontTagView',
|
||||
'PhamePostMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PhamePostNewController' => 'PhamePostController',
|
||||
'PhamePostNotLiveController' => 'PhamePostController',
|
||||
|
|
|
@ -38,7 +38,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
|
|||
public function getRoutes() {
|
||||
return array(
|
||||
'/phame/' => array(
|
||||
'' => 'PhamePostListController',
|
||||
'' => 'PhameHomeController',
|
||||
'live/(?P<id>[^/]+)/(?P<more>.*)' => 'PhameBlogLiveController',
|
||||
'post/' => array(
|
||||
'(?:(?P<filter>draft|all)/)?' => 'PhamePostListController',
|
||||
|
|
98
src/applications/phame/controller/PhameHomeController.php
Normal file
98
src/applications/phame/controller/PhameHomeController.php
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
final class PhameHomeController extends PhamePostController {
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$pager = id(new AphrontCursorPagerView())
|
||||
->readFromRequest($request);
|
||||
|
||||
$posts = id(new PhamePostQuery())
|
||||
->setViewer($viewer)
|
||||
->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
|
||||
->executeWithCursorPager($pager);
|
||||
|
||||
$actions = $this->renderActions($viewer);
|
||||
$action_button = id(new PHUIButtonView())
|
||||
->setTag('a')
|
||||
->setText(pht('Search'))
|
||||
->setHref('#')
|
||||
->setIconFont('fa-search')
|
||||
->addClass('phui-mobile-menu')
|
||||
->setDropdownMenu($actions);
|
||||
|
||||
$title = pht('Recent Posts');
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader($title)
|
||||
->addActionLink($action_button);
|
||||
|
||||
$post_list = id(new PhamePostListView())
|
||||
->setPosts($posts)
|
||||
->setViewer($viewer)
|
||||
->showBlog(true)
|
||||
->setNodata(pht('No Recent Visible Posts.'));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->setBorder(true);
|
||||
$crumbs->addTextCrumb(
|
||||
pht('Recent Posts'),
|
||||
$this->getApplicationURI('post/'));
|
||||
|
||||
$page = id(new PHUIDocumentViewPro())
|
||||
->setHeader($header)
|
||||
->appendChild($post_list);
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle($title)
|
||||
->setCrumbs($crumbs)
|
||||
->appendChild(
|
||||
array(
|
||||
$page,
|
||||
));
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function renderActions($viewer) {
|
||||
$actions = id(new PhabricatorActionListView())
|
||||
->setUser($viewer);
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setIcon('fa-pencil-square-o')
|
||||
->setHref($this->getApplicationURI('post/'))
|
||||
->setName(pht('Find Posts')));
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setIcon('fa-star')
|
||||
->setHref($this->getApplicationURI('blog/'))
|
||||
->setName(pht('Find Blogs')));
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
protected function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$can_create = $this->hasApplicationCapability(
|
||||
PhameBlogCreateCapability::CAPABILITY);
|
||||
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setName(pht('New Blog'))
|
||||
->setHref($this->getApplicationURI('/blog/new/'))
|
||||
->setIcon('fa-plus-square')
|
||||
->setDisabled(!$can_create)
|
||||
->setWorkflow(!$can_create));
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
}
|
|
@ -52,10 +52,10 @@ final class PhameBlogViewController extends PhameBlogController {
|
|||
->setStatus($header_icon, $header_color, $header_name)
|
||||
->addActionLink($action_button);
|
||||
|
||||
$post_list = $this->renderPostList(
|
||||
$posts,
|
||||
$viewer,
|
||||
pht('This blog has no visible posts.'));
|
||||
$post_list = id(new PhamePostListView())
|
||||
->setPosts($posts)
|
||||
->setViewer($viewer)
|
||||
->setNodata(pht('This blog has no visible posts.'));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->setBorder(true);
|
||||
|
@ -128,63 +128,6 @@ final class PhameBlogViewController extends PhameBlogController {
|
|||
return $view;
|
||||
}
|
||||
|
||||
protected function renderPostList(
|
||||
array $posts,
|
||||
PhabricatorUser $viewer,
|
||||
$nodata) {
|
||||
assert_instances_of($posts, 'PhamePost');
|
||||
|
||||
$handle_phids = array();
|
||||
foreach ($posts as $post) {
|
||||
$handle_phids[] = $post->getBloggerPHID();
|
||||
if ($post->getBlog()) {
|
||||
$handle_phids[] = $post->getBlog()->getPHID();
|
||||
}
|
||||
}
|
||||
$handles = $viewer->loadHandles($handle_phids);
|
||||
|
||||
$list = array();
|
||||
foreach ($posts as $post) {
|
||||
$blogger = $handles[$post->getBloggerPHID()]->renderLink();
|
||||
$blogger_uri = $handles[$post->getBloggerPHID()]->getURI();
|
||||
$blogger_image = $handles[$post->getBloggerPHID()]->getImageURI();
|
||||
|
||||
$phame_post = null;
|
||||
if ($post->getBody()) {
|
||||
$phame_post = PhabricatorMarkupEngine::summarize($post->getBody());
|
||||
$phame_post = new PHUIRemarkupView($viewer, $phame_post);
|
||||
} else {
|
||||
$phame_post = phutil_tag('em', array(), pht('Empty Post'));
|
||||
}
|
||||
|
||||
$blogger = phutil_tag('strong', array(), $blogger);
|
||||
$date = phabricator_datetime($post->getDatePublished(), $viewer);
|
||||
if ($post->isDraft()) {
|
||||
$subtitle = pht('Unpublished draft by %s.', $blogger);
|
||||
} else {
|
||||
$subtitle = pht('Written by %s on %s.', $blogger, $date);
|
||||
}
|
||||
|
||||
$item = id(new PHUIDocumentSummaryView())
|
||||
->setTitle($post->getTitle())
|
||||
->setHref($this->getApplicationURI('/post/view/'.$post->getID().'/'))
|
||||
->setSubtitle($subtitle)
|
||||
->setImage($blogger_image)
|
||||
->setImageHref($blogger_uri)
|
||||
->setSummary($phame_post)
|
||||
->setDraft($post->isDraft());
|
||||
|
||||
$list[] = $item;
|
||||
}
|
||||
|
||||
if (empty($list)) {
|
||||
$list = id(new PHUIInfoView())
|
||||
->appendChild($nodata);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
private function renderActions(PhameBlog $blog, PhabricatorUser $viewer) {
|
||||
$actions = id(new PhabricatorActionListView())
|
||||
->setObject($blog)
|
||||
|
|
110
src/applications/phame/view/PhamePostListView.php
Normal file
110
src/applications/phame/view/PhamePostListView.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
final class PhamePostListView extends AphrontTagView {
|
||||
|
||||
private $posts;
|
||||
private $nodata;
|
||||
private $viewer;
|
||||
private $showBlog = false;
|
||||
|
||||
public function setPosts($posts) {
|
||||
assert_instances_of($posts, 'PhamePost');
|
||||
$this->posts = $posts;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNodata($nodata) {
|
||||
$this->nodata = $nodata;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function showBlog($show) {
|
||||
$this->showBlog = $show;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setViewer($viewer) {
|
||||
$this->viewer = $viewer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getTagAttributes() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function getTagContent() {
|
||||
$viewer = $this->viewer;
|
||||
$posts = $this->posts;
|
||||
$nodata = $this->nodata;
|
||||
|
||||
$handle_phids = array();
|
||||
foreach ($posts as $post) {
|
||||
$handle_phids[] = $post->getBloggerPHID();
|
||||
if ($post->getBlog()) {
|
||||
$handle_phids[] = $post->getBlog()->getPHID();
|
||||
}
|
||||
}
|
||||
$handles = $viewer->loadHandles($handle_phids);
|
||||
|
||||
$list = array();
|
||||
foreach ($posts as $post) {
|
||||
$blogger = $handles[$post->getBloggerPHID()]->renderLink();
|
||||
$blogger_uri = $handles[$post->getBloggerPHID()]->getURI();
|
||||
$blogger_image = $handles[$post->getBloggerPHID()]->getImageURI();
|
||||
|
||||
$phame_post = null;
|
||||
if ($post->getBody()) {
|
||||
$phame_post = PhabricatorMarkupEngine::summarize($post->getBody());
|
||||
$phame_post = new PHUIRemarkupView($viewer, $phame_post);
|
||||
} else {
|
||||
$phame_post = phutil_tag('em', array(), pht('Empty Post'));
|
||||
}
|
||||
|
||||
$blogger = phutil_tag('strong', array(), $blogger);
|
||||
$date = phabricator_datetime($post->getDatePublished(), $viewer);
|
||||
|
||||
$blog = null;
|
||||
if ($post->getBlog()) {
|
||||
$blog = phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/phame/blog/view/'.$post->getBlog()->getID().'/',
|
||||
),
|
||||
$post->getBlog()->getName());
|
||||
}
|
||||
|
||||
if ($this->showBlog && $blog) {
|
||||
if ($post->isDraft()) {
|
||||
$subtitle = pht('Unpublished draft by %s in %s.', $blogger, $blog);
|
||||
} else {
|
||||
$subtitle = pht('By %s on %s in %s.', $blogger, $date, $blog);
|
||||
}
|
||||
} else {
|
||||
if ($post->isDraft()) {
|
||||
$subtitle = pht('Unpublished draft by %s.', $blogger);
|
||||
} else {
|
||||
$subtitle = pht('Written by %s on %s.', $blogger, $date);
|
||||
}
|
||||
}
|
||||
|
||||
$item = id(new PHUIDocumentSummaryView())
|
||||
->setTitle($post->getTitle())
|
||||
->setHref('/phame/post/view/'.$post->getID().'/')
|
||||
->setSubtitle($subtitle)
|
||||
->setImage($blogger_image)
|
||||
->setImageHref($blogger_uri)
|
||||
->setSummary($phame_post)
|
||||
->setDraft($post->isDraft());
|
||||
|
||||
$list[] = $item;
|
||||
}
|
||||
|
||||
if (empty($list)) {
|
||||
$list = id(new PHUIInfoView())
|
||||
->appendChild($nodata);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue