Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / view / phui / PHUIFeedStoryView.php
blobf0acd4820147e8b128569494b0f1f874e1d93590
1 <?php
3 final class PHUIFeedStoryView extends AphrontView {
5 private $title;
6 private $image;
7 private $imageHref;
8 private $appIcon;
9 private $phid;
10 private $epoch;
11 private $viewed;
12 private $href;
13 private $pontification = null;
14 private $tokenBar = array();
15 private $projects = array();
16 private $actions = array();
17 private $chronologicalKey;
18 private $tags;
19 private $authorIcon;
20 private $showTimestamp = true;
22 public function setTags($tags) {
23 $this->tags = $tags;
24 return $this;
27 public function getTags() {
28 return $this->tags;
31 public function setChronologicalKey($chronological_key) {
32 $this->chronologicalKey = $chronological_key;
33 return $this;
36 public function getChronologicalKey() {
37 return $this->chronologicalKey;
40 public function setTitle($title) {
41 $this->title = $title;
42 return $this;
45 public function getTitle() {
46 return $this->title;
49 public function setEpoch($epoch) {
50 $this->epoch = $epoch;
51 return $this;
54 public function setImage($image) {
55 $this->image = $image;
56 return $this;
59 public function getImage() {
60 return $this->image;
63 public function setImageHref($image_href) {
64 $this->imageHref = $image_href;
65 return $this;
68 public function setAppIcon($icon) {
69 $this->appIcon = $icon;
70 return $this;
73 public function setViewed($viewed) {
74 $this->viewed = $viewed;
75 return $this;
78 public function getViewed() {
79 return $this->viewed;
82 public function setHref($href) {
83 $this->href = $href;
84 return $this;
87 public function setAuthorIcon($author_icon) {
88 $this->authorIcon = $author_icon;
89 return $this;
92 public function getAuthorIcon() {
93 return $this->authorIcon;
96 public function setTokenBar(array $tokens) {
97 $this->tokenBar = $tokens;
98 return $this;
101 public function setShowTimestamp($show_timestamp) {
102 $this->showTimestamp = $show_timestamp;
103 return $this;
106 public function getShowTimestamp() {
107 return $this->showTimestamp;
110 public function addProject($project) {
111 $this->projects[] = $project;
112 return $this;
115 public function addAction(PHUIIconView $action) {
116 $this->actions[] = $action;
117 return $this;
120 public function setPontification($text, $title = null) {
121 if ($title) {
122 $title = phutil_tag('h3', array(), $title);
124 $copy = phutil_tag(
125 'div',
126 array(
127 'class' => 'phui-feed-story-bigtext-post',
129 array(
130 $title,
131 $text,
133 $this->appendChild($copy);
134 return $this;
137 public function getHref() {
138 return $this->href;
141 public function renderNotification($user) {
142 $classes = array(
143 'phabricator-notification',
146 if (!$this->viewed) {
147 $classes[] = 'phabricator-notification-unread';
150 if ($this->getShowTimestamp()) {
151 if ($this->epoch) {
152 if ($user) {
153 $marker = id(new PHUIIconView())
154 ->setIcon('fa-circle')
155 ->addClass('phabricator-notification-status');
156 $date = phabricator_datetime($this->epoch, $user);
157 $foot = phutil_tag(
158 'span',
159 array(
160 'class' => 'phabricator-notification-date',
162 $date);
163 $foot = phutil_tag(
164 'div',
165 array(
166 'class' => 'phabricator-notification-foot',
168 array(
169 $marker,
170 $date,
172 } else {
173 $foot = null;
175 } else {
176 $foot = pht('No time specified.');
178 } else {
179 $foot = null;
182 return javelin_tag(
183 'div',
184 array(
185 'class' => implode(' ', $classes),
186 'sigil' => 'notification',
187 'meta' => array(
188 'href' => $this->getHref(),
191 array($this->title, $foot));
194 public function render() {
196 require_celerity_resource('phui-feed-story-css');
197 Javelin::initBehavior('phui-hovercards');
199 $body = null;
200 $foot = null;
202 $actor = new PHUIIconView();
203 $actor->addClass('phui-feed-story-actor');
205 $author_icon = $this->getAuthorIcon();
207 if ($this->image) {
208 $actor->addClass('phui-feed-story-actor-image');
209 $actor->setImage($this->image);
210 } else if ($author_icon) {
211 $actor->addClass('phui-feed-story-actor-icon');
212 $actor->setIcon($author_icon);
215 if ($this->imageHref) {
216 $actor->setHref($this->imageHref);
219 if ($this->epoch) {
220 // TODO: This is really bad; when rendering through Conduit and via
221 // renderText() we don't have a user.
222 if ($this->hasViewer()) {
223 $foot = phabricator_datetime($this->epoch, $this->getViewer());
224 } else {
225 $foot = null;
227 } else {
228 $foot = pht('No time specified.');
231 if ($this->chronologicalKey) {
232 $foot = phutil_tag(
233 'a',
234 array(
235 'href' => '/feed/'.$this->chronologicalKey.'/',
237 $foot);
240 $icon = null;
241 if ($this->appIcon) {
242 $icon = id(new PHUIIconView())
243 ->setIcon($this->appIcon);
246 $action_list = array();
247 $icons = null;
248 foreach ($this->actions as $action) {
249 $action_list[] = phutil_tag(
250 'li',
251 array(
252 'class' => 'phui-feed-story-action-item',
254 $action);
256 if (!empty($action_list)) {
257 $icons = phutil_tag(
258 'ul',
259 array(
260 'class' => 'phui-feed-story-action-list',
262 $action_list);
265 $head = phutil_tag(
266 'div',
267 array(
268 'class' => 'phui-feed-story-head',
270 array(
271 $actor,
272 nonempty($this->title, pht('Untitled Story')),
273 $icons,
276 if (!empty($this->tokenBar)) {
277 $tokenview = phutil_tag(
278 'div',
279 array(
280 'class' => 'phui-feed-token-bar',
282 $this->tokenBar);
283 $this->appendChild($tokenview);
286 $body_content = $this->renderChildren();
287 if ($body_content) {
288 $body = phutil_tag(
289 'div',
290 array(
291 'class' => 'phui-feed-story-body phabricator-remarkup',
293 $body_content);
296 $tags = null;
297 if ($this->tags) {
298 $tags = array(
299 " \xC2\xB7 ",
300 $this->tags,
304 $foot = phutil_tag(
305 'div',
306 array(
307 'class' => 'phui-feed-story-foot',
309 array(
310 $icon,
311 $foot,
312 $tags,
315 $classes = array('phui-feed-story');
317 return id(new PHUIBoxView())
318 ->addClass(implode(' ', $classes))
319 ->setBorder(true)
320 ->addMargin(PHUI::MARGIN_MEDIUM_BOTTOM)
321 ->appendChild(array($head, $body, $foot));