@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 upstream/main 246 lines 6.7 kB view raw
1<?php 2 3final class ConpherenceTransactionView extends AphrontView { 4 5 private $conpherenceThread; 6 private $conpherenceTransaction; 7 private $handles; 8 private $markupEngine; 9 private $classes = array(); 10 private $searchResult; 11 private $timeOnly; 12 13 public function setConpherenceThread(ConpherenceThread $t) { 14 $this->conpherenceThread = $t; 15 return $this; 16 } 17 18 private function getConpherenceThread() { 19 return $this->conpherenceThread; 20 } 21 22 public function setConpherenceTransaction(ConpherenceTransaction $tx) { 23 $this->conpherenceTransaction = $tx; 24 return $this; 25 } 26 27 private function getConpherenceTransaction() { 28 return $this->conpherenceTransaction; 29 } 30 31 /** 32 * @param array<PhabricatorObjectHandle> $handles 33 */ 34 public function setHandles(array $handles) { 35 assert_instances_of($handles, PhabricatorObjectHandle::class); 36 $this->handles = $handles; 37 return $this; 38 } 39 40 public function getHandles() { 41 return $this->handles; 42 } 43 44 public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) { 45 $this->markupEngine = $markup_engine; 46 return $this; 47 } 48 49 private function getMarkupEngine() { 50 return $this->markupEngine; 51 } 52 53 public function addClass($class) { 54 $this->classes[] = $class; 55 return $this; 56 } 57 58 public function setSearchResult($result) { 59 $this->searchResult = $result; 60 return $this; 61 } 62 63 public function render() { 64 $viewer = $this->getUser(); 65 if (!$viewer) { 66 throw new PhutilInvalidStateException('setUser'); 67 } 68 69 require_celerity_resource('conpherence-transaction-css'); 70 71 $transaction = $this->getConpherenceTransaction(); 72 switch ($transaction->getTransactionType()) { 73 case ConpherenceThreadDateMarkerTransaction::TRANSACTIONTYPE: 74 return javelin_tag( 75 'div', 76 array( 77 'class' => 'conpherence-transaction-view date-marker', 78 'sigil' => 'conpherence-transaction-view', 79 'meta' => array( 80 'id' => $transaction->getID() + 0.5, 81 ), 82 ), 83 array( 84 phutil_tag( 85 'span', 86 array( 87 'class' => 'date', 88 ), 89 phabricator_format_local_time( 90 $transaction->getDateCreated(), 91 $viewer, 92 'M jS, Y')), 93 )); 94 } 95 96 $info = $this->renderTransactionInfo(); 97 $actions = $this->renderTransactionActions(); 98 $image = $this->renderTransactionImage(); 99 $content = $this->renderTransactionContent(); 100 $classes = implode(' ', $this->classes); 101 $transaction_dom_id = 'anchor-'.$transaction->getID(); 102 103 $header = phutil_tag_div( 104 'conpherence-transaction-header grouped', 105 array($actions, $info)); 106 107 return javelin_tag( 108 'div', 109 array( 110 'class' => 'conpherence-transaction-view '.$classes, 111 'id' => $transaction_dom_id, 112 'sigil' => 'conpherence-transaction-view', 113 'meta' => array( 114 'id' => $transaction->getID(), 115 ), 116 ), 117 array( 118 $image, 119 phutil_tag_div('conpherence-transaction-detail grouped', 120 array($header, $content)), 121 )); 122 } 123 124 private function renderTransactionInfo() { 125 $viewer = $this->getUser(); 126 $thread = $this->getConpherenceThread(); 127 $transaction = $this->getConpherenceTransaction(); 128 $info = array(); 129 130 Javelin::initBehavior('phabricator-tooltips'); 131 $tip = phabricator_datetime($transaction->getDateCreated(), $viewer); 132 $label = phabricator_time($transaction->getDateCreated(), $viewer); 133 $width = 360; 134 135 Javelin::initBehavior('phabricator-watch-anchor'); 136 $anchor = id(new PhabricatorAnchorView()) 137 ->setAnchorName($transaction->getID()) 138 ->render(); 139 140 if ($this->searchResult) { 141 $uri = $thread->getMonogram(); 142 $info[] = hsprintf( 143 '%s', 144 javelin_tag( 145 'a', 146 array( 147 'href' => '/'.$uri.'#'.$transaction->getID(), 148 'class' => 'transaction-date', 149 'sigil' => 'conpherence-search-result-jump', 150 ), 151 $tip)); 152 } else { 153 $info[] = hsprintf( 154 '%s%s', 155 $anchor, 156 javelin_tag( 157 'a', 158 array( 159 'href' => '#'.$transaction->getID(), 160 'class' => 'transaction-date anchor-link', 161 'sigil' => 'has-tooltip', 162 'meta' => array( 163 'tip' => $tip, 164 'size' => $width, 165 ), 166 ), 167 $label)); 168 } 169 170 return phutil_tag( 171 'span', 172 array( 173 'class' => 'conpherence-transaction-info', 174 ), 175 $info); 176 } 177 178 private function renderTransactionActions() { 179 $transaction = $this->getConpherenceTransaction(); 180 181 switch ($transaction->getTransactionType()) { 182 case PhabricatorTransactions::TYPE_COMMENT: 183 $handles = $this->getHandles(); 184 $author = $handles[$transaction->getAuthorPHID()]; 185 $actions = array($author->renderLink()); 186 break; 187 default: 188 $actions = null; 189 break; 190 } 191 192 return $actions; 193 } 194 195 private function renderTransactionImage() { 196 $image = null; 197 $transaction = $this->getConpherenceTransaction(); 198 switch ($transaction->getTransactionType()) { 199 case PhabricatorTransactions::TYPE_COMMENT: 200 $handles = $this->getHandles(); 201 $author = $handles[$transaction->getAuthorPHID()]; 202 $image_uri = $author->getImageURI(); 203 $image = phutil_tag( 204 'span', 205 array( 206 'class' => 'conpherence-transaction-image', 207 'style' => 'background-image: url('.$image_uri.');', 208 )); 209 break; 210 } 211 return $image; 212 } 213 214 private function renderTransactionContent() { 215 $transaction = $this->getConpherenceTransaction(); 216 $content = null; 217 $content_class = null; 218 $content = null; 219 $handles = $this->getHandles(); 220 switch ($transaction->getTransactionType()) { 221 case PhabricatorTransactions::TYPE_COMMENT: 222 $this->addClass('conpherence-comment'); 223 $author = $handles[$transaction->getAuthorPHID()]; 224 $comment = $transaction->getComment(); 225 $content = $this->getMarkupEngine()->getOutput( 226 $comment, 227 PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 228 $content_class = 'conpherence-message'; 229 break; 230 default: 231 $content = $transaction->getTitle(); 232 $this->addClass('conpherence-edited'); 233 break; 234 } 235 236 $view = phutil_tag( 237 'div', 238 array( 239 'class' => $content_class, 240 ), 241 $content); 242 243 return phutil_tag_div('conpherence-transaction-content', $view); 244 } 245 246}