@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
1<?php
2
3final class PhabricatorFileLinkView extends AphrontTagView {
4
5 private $fileName;
6 private $fileDownloadURI;
7 private $fileViewURI;
8 private $fileViewable;
9 private $filePHID;
10 private $fileMonogram;
11 private $fileSize;
12 private $customClass;
13
14 public function setCustomClass($custom_class) {
15 $this->customClass = $custom_class;
16 return $this;
17 }
18
19 public function getCustomClass() {
20 return $this->customClass;
21 }
22
23 public function setFilePHID($file_phid) {
24 $this->filePHID = $file_phid;
25 return $this;
26 }
27
28 private function getFilePHID() {
29 return $this->filePHID;
30 }
31
32 public function setFileMonogram($monogram) {
33 $this->fileMonogram = $monogram;
34 return $this;
35 }
36
37 private function getFileMonogram() {
38 return $this->fileMonogram;
39 }
40
41 public function setFileViewable($file_viewable) {
42 $this->fileViewable = $file_viewable;
43 return $this;
44 }
45
46 private function getFileViewable() {
47 return $this->fileViewable;
48 }
49
50 public function setFileViewURI($file_view_uri) {
51 $this->fileViewURI = $file_view_uri;
52 return $this;
53 }
54
55 private function getFileViewURI() {
56 return $this->fileViewURI;
57 }
58
59 public function setFileDownloadURI($file_download_uri) {
60 $this->fileDownloadURI = $file_download_uri;
61 return $this;
62 }
63
64 private function getFileDownloadURI() {
65 return $this->fileDownloadURI;
66 }
67
68 public function setFileName($file_name) {
69 $this->fileName = $file_name;
70 return $this;
71 }
72
73 private function getFileName() {
74 return $this->fileName;
75 }
76
77 public function setFileSize($file_size) {
78 $this->fileSize = $file_size;
79 return $this;
80 }
81
82 private function getFileSize() {
83 return $this->fileSize;
84 }
85
86 private function getFileIcon() {
87 return FileTypeIcon::getFileIcon($this->getFileName());
88 }
89
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(),
100 );
101 }
102
103 protected function getTagName() {
104 if ($this->getFileDownloadURI()) {
105 return 'div';
106 } else {
107 return 'a';
108 }
109 }
110
111 protected function getTagAttributes() {
112 $class = 'phabricator-remarkup-embed-layout-link';
113 if ($this->getCustomClass()) {
114 $class = $this->getCustomClass();
115 }
116
117 $attributes = array(
118 'href' => $this->getFileViewURI(),
119 'target' => '_blank',
120 'rel' => 'noreferrer',
121 'class' => $class,
122 );
123
124 if ($this->getFilePHID()) {
125 $mustcapture = true;
126 $sigil = 'lightboxable';
127 $meta = $this->getMeta();
128
129 $attributes += array(
130 'sigil' => $sigil,
131 'meta' => $meta,
132 'mustcapture' => $mustcapture,
133 );
134 }
135
136 return $attributes;
137 }
138
139 protected function getTagContent() {
140 require_celerity_resource('phabricator-remarkup-css');
141 require_celerity_resource('phui-lightbox-css');
142
143 $icon = id(new PHUIIconView())
144 ->setIcon($this->getFileIcon())
145 ->addClass('phabricator-remarkup-embed-layout-icon');
146
147 $download_link = null;
148
149 $download_uri = $this->getFileDownloadURI();
150 if ($download_uri) {
151 $dl_icon = id(new PHUIIconView())
152 ->setIcon('fa-download');
153
154 $download_link = phutil_tag(
155 'a',
156 array(
157 'class' => 'phabricator-remarkup-embed-layout-download',
158 'href' => $download_uri,
159 ),
160 pht('Download'));
161 }
162
163 $info = phutil_tag(
164 'span',
165 array(
166 'class' => 'phabricator-remarkup-embed-layout-info',
167 ),
168 $this->getFileSize());
169
170 $name = phutil_tag(
171 'span',
172 array(
173 'class' => 'phabricator-remarkup-embed-layout-name',
174 ),
175 $this->getFileName());
176
177 $inner = phutil_tag(
178 'span',
179 array(
180 'class' => 'phabricator-remarkup-embed-layout-info-block',
181 ),
182 array(
183 $name,
184 $info,
185 ));
186
187 return array(
188 $icon,
189 $inner,
190 $download_link,
191 );
192 }
193}