2012-04-12 22:09:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhameController extends PhabricatorController {
|
|
|
|
|
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');
|
|
|
|
|
2015-03-30 16:55:33 +02:00
|
|
|
$handle_phids = array();
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
$handle_phids[] = $post->getBloggerPHID();
|
|
|
|
if ($post->getBlog()) {
|
|
|
|
$handle_phids[] = $post->getBlog()->getPHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$handles = $viewer->loadHandles($handle_phids);
|
2012-10-15 23:50:12 +02:00
|
|
|
|
2015-03-30 16:55:33 +02:00
|
|
|
$stories = array();
|
2012-10-15 23:50:12 +02:00
|
|
|
foreach ($posts as $post) {
|
2015-03-30 16:55:33 +02:00
|
|
|
$blogger = $handles[$post->getBloggerPHID()]->renderLink();
|
|
|
|
$blogger_uri = $handles[$post->getBloggerPHID()]->getURI();
|
|
|
|
$blogger_image = $handles[$post->getBloggerPHID()]->getImageURI();
|
2012-12-13 19:59:29 +01:00
|
|
|
|
|
|
|
$blog = null;
|
|
|
|
if ($post->getBlog()) {
|
2015-03-30 16:55:33 +02:00
|
|
|
$blog = $handles[$post->getBlog()->getPHID()]->renderLink();
|
2012-12-13 19:59:29 +01:00
|
|
|
}
|
|
|
|
|
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()) {
|
2015-05-22 09:27:56 +02:00
|
|
|
$title = pht(
|
|
|
|
'%s drafted a blog post on %s.',
|
|
|
|
$blogger,
|
|
|
|
$blog);
|
2013-05-22 00:32:17 +02:00
|
|
|
$title = phutil_tag('em', array(), $title);
|
|
|
|
} else {
|
2015-05-22 09:27:56 +02:00
|
|
|
$title = pht(
|
|
|
|
'%s wrote a blog post on %s.',
|
|
|
|
$blogger,
|
|
|
|
$blog);
|
2013-05-22 00:32:17 +02:00
|
|
|
}
|
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)
|
2015-01-25 23:14:41 +01:00
|
|
|
->setAppIcon('fa-star')
|
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)) {
|
2015-07-02 01:06:47 +02:00
|
|
|
return id(new PHUIBoxView())
|
|
|
|
->appendChild($nodata)
|
|
|
|
->addClass('mlt mlb msr msl');
|
2014-04-30 22:19:14 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|