Restore highlighting when jumping to transactions using URI anchors
[phabricator/blender.git] / src / view / layout / PhabricatorFileLinkView.php
blob49320c4b8cd74cb8d946bac44bdf71fc914d710a
1 <?php
3 final class PhabricatorFileLinkView extends AphrontTagView {
5 private $fileName;
6 private $fileDownloadURI;
7 private $fileViewURI;
8 private $fileViewable;
9 private $filePHID;
10 private $fileMonogram;
11 private $fileSize;
12 private $customClass;
14 public function setCustomClass($custom_class) {
15 $this->customClass = $custom_class;
16 return $this;
19 public function getCustomClass() {
20 return $this->customClass;
23 public function setFilePHID($file_phid) {
24 $this->filePHID = $file_phid;
25 return $this;
28 private function getFilePHID() {
29 return $this->filePHID;
32 public function setFileMonogram($monogram) {
33 $this->fileMonogram = $monogram;
34 return $this;
37 private function getFileMonogram() {
38 return $this->fileMonogram;
41 public function setFileViewable($file_viewable) {
42 $this->fileViewable = $file_viewable;
43 return $this;
46 private function getFileViewable() {
47 return $this->fileViewable;
50 public function setFileViewURI($file_view_uri) {
51 $this->fileViewURI = $file_view_uri;
52 return $this;
55 private function getFileViewURI() {
56 return $this->fileViewURI;
59 public function setFileDownloadURI($file_download_uri) {
60 $this->fileDownloadURI = $file_download_uri;
61 return $this;
64 private function getFileDownloadURI() {
65 return $this->fileDownloadURI;
68 public function setFileName($file_name) {
69 $this->fileName = $file_name;
70 return $this;
73 private function getFileName() {
74 return $this->fileName;
77 public function setFileSize($file_size) {
78 $this->fileSize = $file_size;
79 return $this;
82 private function getFileSize() {
83 return $this->fileSize;
86 private function getFileIcon() {
87 return FileTypeIcon::getFileIcon($this->getFileName());
90 public function getMeta() {
91 return array(
92 'phid' => $this->getFilePHID(),
93 'viewable' => $this->getFileViewable(),
94 'uri' => $this->getFileViewURI(),
95 'dUri' => $this->getFileDownloadURI(),
96 'name' => $this->getFileName(),
97 'monogram' => $this->getFileMonogram(),
98 'icon' => $this->getFileIcon(),
99 'size' => $this->getFileSize(),
103 protected function getTagName() {
104 if ($this->getFileDownloadURI()) {
105 return 'div';
106 } else {
107 return 'a';
111 protected function getTagAttributes() {
112 $class = 'phabricator-remarkup-embed-layout-link';
113 if ($this->getCustomClass()) {
114 $class = $this->getCustomClass();
117 $attributes = array(
118 'href' => $this->getFileViewURI(),
119 'target' => '_blank',
120 'rel' => 'noreferrer',
121 'class' => $class,
124 if ($this->getFilePHID()) {
125 $mustcapture = true;
126 $sigil = 'lightboxable';
127 $meta = $this->getMeta();
129 $attributes += array(
130 'sigil' => $sigil,
131 'meta' => $meta,
132 'mustcapture' => $mustcapture,
136 return $attributes;
139 protected function getTagContent() {
140 require_celerity_resource('phabricator-remarkup-css');
141 require_celerity_resource('phui-lightbox-css');
143 $icon = id(new PHUIIconView())
144 ->setIcon($this->getFileIcon())
145 ->addClass('phabricator-remarkup-embed-layout-icon');
147 $download_link = null;
149 $download_uri = $this->getFileDownloadURI();
150 if ($download_uri) {
151 $dl_icon = id(new PHUIIconView())
152 ->setIcon('fa-download');
154 $download_link = phutil_tag(
155 'a',
156 array(
157 'class' => 'phabricator-remarkup-embed-layout-download',
158 'href' => $download_uri,
160 pht('Download'));
163 $info = phutil_tag(
164 'span',
165 array(
166 'class' => 'phabricator-remarkup-embed-layout-info',
168 $this->getFileSize());
170 $name = phutil_tag(
171 'span',
172 array(
173 'class' => 'phabricator-remarkup-embed-layout-name',
175 $this->getFileName());
177 $inner = phutil_tag(
178 'span',
179 array(
180 'class' => 'phabricator-remarkup-embed-layout-info-block',
182 array(
183 $name,
184 $info,
187 return array(
188 $icon,
189 $inner,
190 $download_link,