Path: blob/master/src/view/phui/PHUIFeedStoryView.php
12249 views
<?php12final class PHUIFeedStoryView extends AphrontView {34private $title;5private $image;6private $imageHref;7private $appIcon;8private $phid;9private $epoch;10private $viewed;11private $href;12private $pontification = null;13private $tokenBar = array();14private $projects = array();15private $actions = array();16private $chronologicalKey;17private $tags;18private $authorIcon;19private $showTimestamp = true;2021public function setTags($tags) {22$this->tags = $tags;23return $this;24}2526public function getTags() {27return $this->tags;28}2930public function setChronologicalKey($chronological_key) {31$this->chronologicalKey = $chronological_key;32return $this;33}3435public function getChronologicalKey() {36return $this->chronologicalKey;37}3839public function setTitle($title) {40$this->title = $title;41return $this;42}4344public function getTitle() {45return $this->title;46}4748public function setEpoch($epoch) {49$this->epoch = $epoch;50return $this;51}5253public function setImage($image) {54$this->image = $image;55return $this;56}5758public function getImage() {59return $this->image;60}6162public function setImageHref($image_href) {63$this->imageHref = $image_href;64return $this;65}6667public function setAppIcon($icon) {68$this->appIcon = $icon;69return $this;70}7172public function setViewed($viewed) {73$this->viewed = $viewed;74return $this;75}7677public function getViewed() {78return $this->viewed;79}8081public function setHref($href) {82$this->href = $href;83return $this;84}8586public function setAuthorIcon($author_icon) {87$this->authorIcon = $author_icon;88return $this;89}9091public function getAuthorIcon() {92return $this->authorIcon;93}9495public function setTokenBar(array $tokens) {96$this->tokenBar = $tokens;97return $this;98}99100public function setShowTimestamp($show_timestamp) {101$this->showTimestamp = $show_timestamp;102return $this;103}104105public function getShowTimestamp() {106return $this->showTimestamp;107}108109public function addProject($project) {110$this->projects[] = $project;111return $this;112}113114public function addAction(PHUIIconView $action) {115$this->actions[] = $action;116return $this;117}118119public function setPontification($text, $title = null) {120if ($title) {121$title = phutil_tag('h3', array(), $title);122}123$copy = phutil_tag(124'div',125array(126'class' => 'phui-feed-story-bigtext-post',127),128array(129$title,130$text,131));132$this->appendChild($copy);133return $this;134}135136public function getHref() {137return $this->href;138}139140public function renderNotification($user) {141$classes = array(142'phabricator-notification',143);144145if (!$this->viewed) {146$classes[] = 'phabricator-notification-unread';147}148149if ($this->getShowTimestamp()) {150if ($this->epoch) {151if ($user) {152$marker = id(new PHUIIconView())153->setIcon('fa-circle')154->addClass('phabricator-notification-status');155$date = phabricator_datetime($this->epoch, $user);156$foot = phutil_tag(157'span',158array(159'class' => 'phabricator-notification-date',160),161$date);162$foot = phutil_tag(163'div',164array(165'class' => 'phabricator-notification-foot',166),167array(168$marker,169$date,170));171} else {172$foot = null;173}174} else {175$foot = pht('No time specified.');176}177} else {178$foot = null;179}180181return javelin_tag(182'div',183array(184'class' => implode(' ', $classes),185'sigil' => 'notification',186'meta' => array(187'href' => $this->getHref(),188),189),190array($this->title, $foot));191}192193public function render() {194195require_celerity_resource('phui-feed-story-css');196Javelin::initBehavior('phui-hovercards');197198$body = null;199$foot = null;200201$actor = new PHUIIconView();202$actor->addClass('phui-feed-story-actor');203204$author_icon = $this->getAuthorIcon();205206if ($this->image) {207$actor->addClass('phui-feed-story-actor-image');208$actor->setImage($this->image);209} else if ($author_icon) {210$actor->addClass('phui-feed-story-actor-icon');211$actor->setIcon($author_icon);212}213214if ($this->imageHref) {215$actor->setHref($this->imageHref);216}217218if ($this->epoch) {219// TODO: This is really bad; when rendering through Conduit and via220// renderText() we don't have a user.221if ($this->hasViewer()) {222$foot = phabricator_datetime($this->epoch, $this->getViewer());223} else {224$foot = null;225}226} else {227$foot = pht('No time specified.');228}229230if ($this->chronologicalKey) {231$foot = phutil_tag(232'a',233array(234'href' => '/feed/'.$this->chronologicalKey.'/',235),236$foot);237}238239$icon = null;240if ($this->appIcon) {241$icon = id(new PHUIIconView())242->setIcon($this->appIcon);243}244245$action_list = array();246$icons = null;247foreach ($this->actions as $action) {248$action_list[] = phutil_tag(249'li',250array(251'class' => 'phui-feed-story-action-item',252),253$action);254}255if (!empty($action_list)) {256$icons = phutil_tag(257'ul',258array(259'class' => 'phui-feed-story-action-list',260),261$action_list);262}263264$head = phutil_tag(265'div',266array(267'class' => 'phui-feed-story-head',268),269array(270$actor,271nonempty($this->title, pht('Untitled Story')),272$icons,273));274275if (!empty($this->tokenBar)) {276$tokenview = phutil_tag(277'div',278array(279'class' => 'phui-feed-token-bar',280),281$this->tokenBar);282$this->appendChild($tokenview);283}284285$body_content = $this->renderChildren();286if ($body_content) {287$body = phutil_tag(288'div',289array(290'class' => 'phui-feed-story-body phabricator-remarkup',291),292$body_content);293}294295$tags = null;296if ($this->tags) {297$tags = array(298" \xC2\xB7 ",299$this->tags,300);301}302303$foot = phutil_tag(304'div',305array(306'class' => 'phui-feed-story-foot',307),308array(309$icon,310$foot,311$tags,312));313314$classes = array('phui-feed-story');315316return id(new PHUIBoxView())317->addClass(implode(' ', $classes))318->setBorder(true)319->addMargin(PHUI::MARGIN_MEDIUM_BOTTOM)320->appendChild(array($head, $body, $foot));321}322323}324325326