2012-04-12 22:09:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhameController extends PhabricatorController {
|
|
|
|
|
2012-10-16 02:55:57 +02:00
|
|
|
protected function renderSideNavFilterView() {
|
2012-10-13 01:01:33 +02:00
|
|
|
|
2012-10-16 02:55:57 +02:00
|
|
|
$base_uri = new PhutilURI($this->getApplicationURI());
|
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-16 02:55:57 +02:00
|
|
|
|
2013-04-14 17:02:29 +02:00
|
|
|
$nav->addLabel(pht('Create'));
|
|
|
|
$nav->addFilter('post/new', pht('New Post'));
|
|
|
|
$nav->addFilter('blog/new', pht('New Blog'));
|
2012-10-15 23:50:12 +02:00
|
|
|
|
2013-04-14 17:02:29 +02:00
|
|
|
$nav->addLabel(pht('Posts'));
|
|
|
|
$nav->addFilter('post/draft', pht('My Drafts'));
|
|
|
|
$nav->addFilter('post', pht('My Posts'));
|
|
|
|
$nav->addFilter('post/all', pht('All Posts'));
|
2012-04-12 22:09:04 +02:00
|
|
|
|
2013-04-14 17:02:29 +02:00
|
|
|
$nav->addLabel(pht('Blogs'));
|
|
|
|
$nav->addFilter('blog/user', pht('Joinable Blogs'));
|
|
|
|
$nav->addFilter('blog/all', pht('All Blogs'));
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2012-10-16 02:55:57 +02:00
|
|
|
$nav->selectFilter(null);
|
2012-04-12 22:09:04 +02:00
|
|
|
|
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
protected function renderPostList(
|
|
|
|
array $posts,
|
2014-04-30 22:19:14 +02:00
|
|
|
PhabricatorUser $viewer,
|
2012-10-15 23:50:12 +02:00
|
|
|
$nodata) {
|
|
|
|
assert_instances_of($posts, 'PhamePost');
|
|
|
|
|
2013-05-22 00:32:17 +02:00
|
|
|
$stories = array();
|
2012-10-15 23:50:12 +02:00
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
2012-12-13 19:59:29 +01:00
|
|
|
$blogger = $this->getHandle($post->getBloggerPHID())->renderLink();
|
2015-01-02 23:11:41 +01:00
|
|
|
$blogger_uri = $this->getHandle($post->getBloggerPHID())->getURI();
|
|
|
|
$blogger_image = $this->getHandle($post->getBloggerPHID())->getImageURI();
|
2012-12-13 19:59:29 +01:00
|
|
|
|
|
|
|
$blog = null;
|
|
|
|
if ($post->getBlog()) {
|
|
|
|
$blog = $this->getHandle($post->getBlog()->getPHID())->renderLink();
|
|
|
|
}
|
|
|
|
|
2013-05-22 00:32:17 +02:00
|
|
|
$phame_post = '';
|
|
|
|
if ($post->getBody()) {
|
|
|
|
$phame_post = PhabricatorMarkupEngine::summarize($post->getBody());
|
2012-12-13 19:59:29 +01:00
|
|
|
}
|
|
|
|
|
2013-05-22 00:32:17 +02:00
|
|
|
$blog_view = $post->getViewURI();
|
|
|
|
$phame_title = phutil_tag('a', array('href' => $blog_view),
|
|
|
|
$post->getTitle());
|
|
|
|
|
|
|
|
$blogger = phutil_tag('strong', array(), $blogger);
|
|
|
|
if ($post->isDraft()) {
|
|
|
|
$title = pht('%s drafted a blog post on %s.',
|
|
|
|
$blogger, $blog);
|
|
|
|
$title = phutil_tag('em', array(), $title);
|
|
|
|
} else {
|
|
|
|
$title = pht('%s wrote a blog post on %s.',
|
|
|
|
$blogger, $blog);
|
|
|
|
}
|
2012-12-13 19:59:29 +01:00
|
|
|
|
2013-09-09 23:14:34 +02:00
|
|
|
$item = id(new PHUIObjectItemView())
|
2012-12-13 19:59:29 +01:00
|
|
|
->setObject($post)
|
2012-10-15 23:50:12 +02:00
|
|
|
->setHeader($post->getTitle())
|
2012-12-13 19:59:29 +01:00
|
|
|
->setHref($this->getApplicationURI('post/view/'.$post->getID().'/'));
|
|
|
|
|
2013-05-22 00:32:17 +02:00
|
|
|
$story = id(new PHUIFeedStoryView())
|
|
|
|
->setTitle($title)
|
2015-01-02 23:11:41 +01:00
|
|
|
->setImage($blogger_image)
|
|
|
|
->setImageHref($blogger_uri)
|
2013-05-22 00:32:17 +02:00
|
|
|
->setAppIcon('phame-dark')
|
2014-04-30 22:19:14 +02:00
|
|
|
->setUser($viewer)
|
2013-05-22 00:32:17 +02:00
|
|
|
->setPontification($phame_post, $phame_title);
|
2012-12-13 19:59:29 +01:00
|
|
|
|
2014-04-30 22:19:14 +02:00
|
|
|
if (PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$post,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT)) {
|
|
|
|
|
|
|
|
$story->addAction(id(new PHUIIconView())
|
|
|
|
->setHref($this->getApplicationURI('post/edit/'.$post->getID().'/'))
|
|
|
|
->setIconFont('fa-pencil'));
|
|
|
|
}
|
|
|
|
|
2013-05-22 00:32:17 +02:00
|
|
|
if ($post->getDatePublished()) {
|
|
|
|
$story->setEpoch($post->getDatePublished());
|
2012-10-15 23:50:37 +02:00
|
|
|
}
|
2014-04-30 22:19:14 +02:00
|
|
|
|
2013-05-22 00:32:17 +02:00
|
|
|
$stories[] = $story;
|
2012-10-15 23:50:12 +02:00
|
|
|
}
|
|
|
|
|
2014-04-30 22:19:14 +02:00
|
|
|
if (empty($stories)) {
|
|
|
|
return id(new AphrontErrorView())
|
|
|
|
->setSeverity(AphrontErrorView::SEVERITY_NODATA)
|
|
|
|
->appendChild($nodata);
|
|
|
|
}
|
|
|
|
|
2013-05-22 00:32:17 +02:00
|
|
|
return $stories;
|
2012-10-15 23:50:12 +02:00
|
|
|
}
|
2013-04-14 17:02:29 +02:00
|
|
|
|
|
|
|
public function buildApplicationMenu() {
|
|
|
|
return $this->renderSideNavFilterView()->getMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildApplicationCrumbs() {
|
|
|
|
$crumbs = parent::buildApplicationCrumbs();
|
|
|
|
$crumbs->addAction(
|
2013-06-05 17:41:43 +02:00
|
|
|
id(new PHUIListItemView())
|
2013-04-14 17:02:29 +02:00
|
|
|
->setName(pht('New Blog'))
|
|
|
|
->setHref($this->getApplicationURI('/blog/new'))
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-plus-square'));
|
2013-04-14 17:02:29 +02:00
|
|
|
$crumbs->addAction(
|
2013-06-05 17:41:43 +02:00
|
|
|
id(new PHUIListItemView())
|
2013-04-14 17:02:29 +02:00
|
|
|
->setName(pht('New Post'))
|
|
|
|
->setHref($this->getApplicationURI('/post/new'))
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-pencil'));
|
2013-04-14 17:02:29 +02:00
|
|
|
return $crumbs;
|
|
|
|
}
|
2012-04-12 22:09:04 +02:00
|
|
|
}
|