@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 242 lines 5.1 kB view raw
1<?php 2 3final class PHUICurtainObjectRefView 4 extends AphrontTagView { 5 6 private $handle; 7 private $epoch; 8 private $highlighted; 9 private $exiled; 10 private $hovercarded = true; 11 private $exileNote = false; 12 13 public function setHandle(PhabricatorObjectHandle $handle) { 14 $this->handle = $handle; 15 return $this; 16 } 17 18 public function setEpoch($epoch) { 19 $this->epoch = $epoch; 20 return $this; 21 } 22 23 public function setHighlighted($highlighted) { 24 $this->highlighted = $highlighted; 25 return $this; 26 } 27 28 public function setExiled($is_exiled, $note = false) { 29 $this->exiled = $is_exiled; 30 $this->exileNote = $note; 31 return $this; 32 } 33 34 public function setHovercarded($hovercarded) { 35 $this->hovercarded = $hovercarded; 36 return $this; 37 } 38 39 protected function getTagAttributes() { 40 $classes = array(); 41 $classes[] = 'phui-curtain-object-ref-view'; 42 43 if ($this->highlighted) { 44 $classes[] = 'phui-curtain-object-ref-view-highlighted'; 45 } 46 47 if ($this->exiled) { 48 $classes[] = 'phui-curtain-object-ref-view-exiled'; 49 } 50 51 $classes = implode(' ', $classes); 52 53 return array( 54 'class' => $classes, 55 ); 56 } 57 58 protected function getTagContent() { 59 require_celerity_resource('phui-curtain-object-ref-view-css'); 60 61 $viewer = $this->getViewer(); 62 $handle = $this->handle; 63 64 $more_rows = array(); 65 66 $epoch = $this->epoch; 67 if ($epoch !== null) { 68 $epoch_view = phabricator_dual_datetime($epoch, $viewer); 69 70 $epoch_cells = array(); 71 72 $epoch_cells[] = phutil_tag( 73 'td', 74 array( 75 'class' => 'phui-curtain-object-ref-view-epoch-cell', 76 ), 77 $epoch_view); 78 79 $more_rows[] = phutil_tag('tr', array(), $epoch_cells); 80 } 81 82 if ($this->exiled) { 83 if ($this->exileNote !== false) { 84 $exile_note = $this->exileNote; 85 } else { 86 $exile_note = pht('No View Permission'); 87 } 88 89 $exiled_view = array( 90 id(new PHUIIconView())->setIcon('fa-eye-slash red'), 91 ' ', 92 $exile_note, 93 ); 94 95 $exiled_cells = array(); 96 $exiled_cells[] = phutil_tag( 97 'td', 98 array( 99 'class' => 'phui-curtain-object-ref-view-exiled-cell', 100 ), 101 $exiled_view); 102 103 $more_rows[] = phutil_tag('tr', array(), $exiled_cells); 104 } 105 106 $header_cells = array(); 107 108 $image_view = $this->newImage(); 109 110 if ($more_rows) { 111 $row_count = 1 + count($more_rows); 112 } else { 113 $row_count = null; 114 } 115 116 $header_cells[] = phutil_tag( 117 'td', 118 array( 119 'rowspan' => $row_count, 120 'class' => 'phui-curtain-object-ref-view-image-cell', 121 ), 122 $image_view); 123 124 $title_view = $this->newTitle(); 125 126 $header_cells[] = phutil_tag( 127 'td', 128 array( 129 'class' => 'phui-curtain-object-ref-view-title-cell', 130 ), 131 $title_view); 132 133 $rows = array(); 134 135 if (!$more_rows) { 136 $title_row_class = 'phui-curtain-object-ref-view-without-content'; 137 } else { 138 $title_row_class = 'phui-curtain-object-ref-view-with-content'; 139 } 140 141 $rows[] = phutil_tag( 142 'tr', 143 array( 144 'class' => $title_row_class, 145 ), 146 $header_cells); 147 148 $body = phutil_tag( 149 'tbody', 150 array(), 151 array( 152 $rows, 153 $more_rows, 154 )); 155 156 return phutil_tag('table', array(), $body); 157 } 158 159 private function newTitle() { 160 $title_view = null; 161 $handle = $this->handle; 162 163 if ($handle) { 164 if ($this->hovercarded) { 165 $title_view = $handle->renderHovercardLink(); 166 } else { 167 $title_view = $handle->renderLink(); 168 } 169 } 170 171 return $title_view; 172 } 173 174 private function newImage() { 175 $image_uri = $this->getImageURI(); 176 $target_uri = $this->getTargetURI(); 177 178 $icon_view = null; 179 if ($image_uri == null) { 180 $icon_view = $this->newIconView(); 181 } 182 183 if ($image_uri !== null) { 184 $image_view = javelin_tag( 185 'a', 186 array( 187 'style' => sprintf('background-image: url(%s)', $image_uri), 188 'href' => $target_uri, 189 'aural' => false, 190 )); 191 } else if ($icon_view !== null) { 192 $image_view = javelin_tag( 193 'a', 194 array( 195 'href' => $target_uri, 196 'class' => 'phui-curtain-object-ref-view-icon-image', 197 'aural' => false, 198 ), 199 $icon_view); 200 } else { 201 $image_view = null; 202 } 203 204 return $image_view; 205 } 206 207 private function getTargetURI() { 208 $target_uri = null; 209 $handle = $this->handle; 210 211 if ($handle) { 212 $target_uri = $handle->getURI(); 213 } 214 215 return $target_uri; 216 } 217 218 private function getImageURI() { 219 $image_uri = null; 220 $handle = $this->handle; 221 222 if ($handle) { 223 $image_uri = $handle->getImageURI(); 224 } 225 226 return $image_uri; 227 } 228 229 private function newIconView() { 230 $icon_view = null; 231 $handle = $this->handle; 232 233 if ($handle) { 234 $icon_view = id(new PHUIIconView()) 235 ->setIcon($handle->getIcon()); 236 } 237 238 return $icon_view; 239 } 240 241 242}