2011-07-05 17:35:18 +02:00
|
|
|
<?php
|
|
|
|
|
2013-04-15 04:32:26 +02:00
|
|
|
final class PHUIFeedStoryView extends AphrontView {
|
2011-07-05 17:35:18 +02:00
|
|
|
|
2011-07-09 22:28:09 +02:00
|
|
|
private $title;
|
|
|
|
private $image;
|
2013-04-13 18:09:42 +02:00
|
|
|
private $imageHref;
|
|
|
|
private $appIcon;
|
2011-07-09 22:28:09 +02:00
|
|
|
private $phid;
|
|
|
|
private $epoch;
|
2012-12-08 01:25:23 +01:00
|
|
|
private $viewed;
|
2012-12-08 01:26:43 +01:00
|
|
|
private $href;
|
2013-04-25 00:18:58 +02:00
|
|
|
private $pontification = null;
|
|
|
|
private $tokenBar = array();
|
|
|
|
private $projects = array();
|
|
|
|
private $actions = array();
|
2013-07-13 02:04:02 +02:00
|
|
|
private $chronologicalKey;
|
2014-08-13 20:24:56 +02:00
|
|
|
private $tags;
|
|
|
|
|
|
|
|
public function setTags($tags) {
|
|
|
|
$this->tags = $tags;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTags() {
|
|
|
|
return $this->tags;
|
|
|
|
}
|
2013-07-13 02:04:02 +02:00
|
|
|
|
|
|
|
public function setChronologicalKey($chronological_key) {
|
|
|
|
$this->chronologicalKey = $chronological_key;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChronologicalKey() {
|
|
|
|
return $this->chronologicalKey;
|
|
|
|
}
|
2011-07-09 22:28:09 +02:00
|
|
|
|
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-06 20:48:38 +02:00
|
|
|
public function getTitle() {
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
2011-07-09 22:28:09 +02:00
|
|
|
public function setEpoch($epoch) {
|
|
|
|
$this->epoch = $epoch;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setImage($image) {
|
|
|
|
$this->image = $image;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-13 18:09:42 +02:00
|
|
|
public function setImageHref($image_href) {
|
|
|
|
$this->imageHref = $image_href;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAppIcon($icon) {
|
|
|
|
$this->appIcon = $icon;
|
2011-07-10 00:44:49 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:25:23 +01:00
|
|
|
public function setViewed($viewed) {
|
|
|
|
$this->viewed = $viewed;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewed() {
|
|
|
|
return $this->viewed;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:26:43 +01:00
|
|
|
public function setHref($href) {
|
|
|
|
$this->href = $href;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
public function setTokenBar(array $tokens) {
|
|
|
|
$this->tokenBar = $tokens;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addProject($project) {
|
|
|
|
$this->projects[] = $project;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addAction(PHUIIconView $action) {
|
|
|
|
$this->actions[] = $action;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPontification($text, $title = null) {
|
|
|
|
if ($title) {
|
|
|
|
$title = phutil_tag('h3', array(), $title);
|
|
|
|
}
|
|
|
|
$copy = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-story-bigtext-post',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$title,
|
2014-10-07 15:01:04 +02:00
|
|
|
$text,
|
|
|
|
));
|
2013-04-25 00:18:58 +02:00
|
|
|
$this->appendChild($copy);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:26:43 +01:00
|
|
|
public function getHref() {
|
|
|
|
return $this->href;
|
|
|
|
}
|
|
|
|
|
2014-01-23 05:09:32 +01:00
|
|
|
public function renderNotification($user) {
|
2012-12-08 01:25:23 +01:00
|
|
|
$classes = array(
|
|
|
|
'phabricator-notification',
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$this->viewed) {
|
|
|
|
$classes[] = 'phabricator-notification-unread';
|
|
|
|
}
|
2014-01-23 05:09:32 +01:00
|
|
|
if ($this->epoch) {
|
|
|
|
if ($user) {
|
|
|
|
$foot = phabricator_datetime($this->epoch, $user);
|
|
|
|
$foot = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phabricator-notification-date',
|
|
|
|
),
|
2014-01-23 05:09:32 +01:00
|
|
|
$foot);
|
|
|
|
} else {
|
|
|
|
$foot = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$foot = pht('No time specified.');
|
|
|
|
}
|
2012-12-08 01:25:23 +01:00
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return javelin_tag(
|
2012-12-08 01:25:23 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $classes),
|
2012-12-08 01:26:43 +01:00
|
|
|
'sigil' => 'notification',
|
|
|
|
'meta' => array(
|
|
|
|
'href' => $this->getHref(),
|
|
|
|
),
|
2012-12-08 01:25:23 +01:00
|
|
|
),
|
2014-01-23 05:09:32 +01:00
|
|
|
array($this->title, $foot));
|
2012-12-08 01:25:23 +01:00
|
|
|
}
|
|
|
|
|
2011-07-05 17:35:18 +02:00
|
|
|
public function render() {
|
2011-07-09 22:28:09 +02:00
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
require_celerity_resource('phui-feed-story-css');
|
2013-08-06 18:20:04 +02:00
|
|
|
Javelin::initBehavior('phabricator-hovercards');
|
2013-04-13 18:09:42 +02:00
|
|
|
|
2013-08-02 00:23:07 +02:00
|
|
|
$body = null;
|
|
|
|
$foot = null;
|
|
|
|
$image_style = null;
|
2013-04-13 18:09:42 +02:00
|
|
|
$actor = '';
|
2013-08-02 00:23:07 +02:00
|
|
|
|
2013-04-13 18:09:42 +02:00
|
|
|
if ($this->image) {
|
2013-04-20 02:44:20 +02:00
|
|
|
$actor = new PHUIIconView();
|
2013-04-13 18:09:42 +02:00
|
|
|
$actor->setImage($this->image);
|
2013-04-25 00:18:58 +02:00
|
|
|
$actor->addClass('phui-feed-story-actor-image');
|
2013-04-13 18:09:42 +02:00
|
|
|
if ($this->imageHref) {
|
|
|
|
$actor->setHref($this->imageHref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:23:07 +02:00
|
|
|
if ($this->epoch) {
|
|
|
|
// TODO: This is really bad; when rendering through Conduit and via
|
|
|
|
// renderText() we don't have a user.
|
|
|
|
if ($this->user) {
|
|
|
|
$foot = phabricator_datetime($this->epoch, $this->user);
|
|
|
|
} else {
|
|
|
|
$foot = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$foot = pht('No time specified.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->chronologicalKey) {
|
|
|
|
$foot = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/feed/'.$this->chronologicalKey.'/',
|
|
|
|
),
|
|
|
|
$foot);
|
|
|
|
}
|
|
|
|
|
|
|
|
$icon = null;
|
|
|
|
if ($this->appIcon) {
|
|
|
|
$icon = new PHUIIconView();
|
|
|
|
$icon->setSpriteIcon($this->appIcon);
|
|
|
|
$icon->setSpriteSheet(PHUIIconView::SPRITE_APPS);
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
$action_list = array();
|
|
|
|
$icons = null;
|
|
|
|
foreach ($this->actions as $action) {
|
|
|
|
$action_list[] = phutil_tag(
|
|
|
|
'li',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-feed-story-action-item',
|
|
|
|
),
|
|
|
|
$action);
|
2013-04-25 00:18:58 +02:00
|
|
|
}
|
|
|
|
if (!empty($action_list)) {
|
|
|
|
$icons = phutil_tag(
|
|
|
|
'ul',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-feed-story-action-list',
|
2013-04-25 00:18:58 +02:00
|
|
|
),
|
|
|
|
$action_list);
|
|
|
|
}
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$head = phutil_tag(
|
2011-07-09 22:28:09 +02:00
|
|
|
'div',
|
|
|
|
array(
|
2013-04-15 04:32:26 +02:00
|
|
|
'class' => 'phui-feed-story-head',
|
2011-07-09 22:28:09 +02:00
|
|
|
),
|
2013-04-13 18:09:42 +02:00
|
|
|
array(
|
2014-05-28 20:18:28 +02:00
|
|
|
$actor,
|
2013-04-13 18:09:42 +02:00
|
|
|
nonempty($this->title, pht('Untitled Story')),
|
2013-08-02 00:23:07 +02:00
|
|
|
$icons,
|
2013-04-13 18:09:42 +02:00
|
|
|
));
|
2011-07-09 22:28:09 +02:00
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
if (!empty($this->tokenBar)) {
|
|
|
|
$tokenview = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-feed-token-bar',
|
2013-04-25 00:18:58 +02:00
|
|
|
),
|
|
|
|
$this->tokenBar);
|
|
|
|
$this->appendChild($tokenview);
|
|
|
|
}
|
|
|
|
|
2013-04-15 22:07:54 +02:00
|
|
|
$body_content = $this->renderChildren();
|
|
|
|
if ($body_content) {
|
|
|
|
$body = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-11-05 18:19:30 +01:00
|
|
|
'class' => 'phui-feed-story-body phabricator-remarkup',
|
2013-04-15 22:07:54 +02:00
|
|
|
),
|
|
|
|
$body_content);
|
|
|
|
}
|
2011-07-10 00:44:49 +02:00
|
|
|
|
2014-08-13 20:24:56 +02:00
|
|
|
$tags = null;
|
|
|
|
if ($this->tags) {
|
|
|
|
$tags = array(
|
|
|
|
" \xC2\xB7 ",
|
2014-10-07 15:01:04 +02:00
|
|
|
$this->tags,
|
|
|
|
);
|
2014-08-13 20:24:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 20:18:28 +02:00
|
|
|
$foot = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-story-foot',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$icon,
|
2014-08-13 20:24:56 +02:00
|
|
|
$foot,
|
|
|
|
$tags,
|
|
|
|
));
|
2013-07-13 02:04:02 +02:00
|
|
|
|
2013-08-02 00:23:07 +02:00
|
|
|
$classes = array('phui-feed-story');
|
2011-07-09 22:28:09 +02:00
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
return id(new PHUIBoxView())
|
2013-08-02 00:23:07 +02:00
|
|
|
->addClass(implode(' ', $classes))
|
2014-02-11 01:04:42 +01:00
|
|
|
->setBorder(true)
|
2013-04-25 00:18:58 +02:00
|
|
|
->addMargin(PHUI::MARGIN_MEDIUM_BOTTOM)
|
|
|
|
->appendChild(array($head, $body, $foot));
|
2011-07-05 17:35:18 +02:00
|
|
|
}
|
2013-05-26 16:54:29 +02:00
|
|
|
|
|
|
|
public function setAppIconFromPHID($phid) {
|
2013-06-05 00:28:24 +02:00
|
|
|
switch (phid_get_type($phid)) {
|
2014-07-24 00:05:46 +02:00
|
|
|
case PholioMockPHIDType::TYPECONST:
|
2014-06-09 20:36:49 +02:00
|
|
|
$this->setAppIcon('pholio-dark');
|
2013-05-26 16:54:29 +02:00
|
|
|
break;
|
2014-07-24 00:05:46 +02:00
|
|
|
case PhabricatorMacroMacroPHIDType::TYPECONST:
|
2014-06-09 20:36:49 +02:00
|
|
|
$this->setAppIcon('macro-dark');
|
2013-05-26 16:54:29 +02:00
|
|
|
break;
|
2014-07-24 00:05:46 +02:00
|
|
|
case ManiphestTaskPHIDType::TYPECONST:
|
2014-05-28 20:18:28 +02:00
|
|
|
$this->setAppIcon('maniphest-dark');
|
|
|
|
break;
|
2014-07-24 00:05:46 +02:00
|
|
|
case DifferentialRevisionPHIDType::TYPECONST:
|
2014-05-28 20:18:28 +02:00
|
|
|
$this->setAppIcon('differential-dark');
|
|
|
|
break;
|
2014-07-24 00:05:46 +02:00
|
|
|
case PhabricatorCalendarEventPHIDType::TYPECONST:
|
2014-05-28 20:18:28 +02:00
|
|
|
$this->setAppIcon('calendar-dark');
|
|
|
|
break;
|
2013-05-26 16:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-05 17:35:18 +02:00
|
|
|
}
|