2012-10-22 19:06:56 -07:00
|
|
|
<?php
|
|
|
|
|
2017-01-03 10:50:12 -08:00
|
|
|
final class PhabricatorFileLinkView extends AphrontTagView {
|
2012-10-22 19:06:56 -07:00
|
|
|
|
|
|
|
private $fileName;
|
|
|
|
private $fileDownloadURI;
|
|
|
|
private $fileViewURI;
|
|
|
|
private $fileViewable;
|
|
|
|
private $filePHID;
|
2016-11-18 13:23:41 -08:00
|
|
|
private $fileMonogram;
|
2016-11-27 14:00:03 -08:00
|
|
|
private $fileSize;
|
2013-03-15 23:41:36 -07:00
|
|
|
private $customClass;
|
|
|
|
|
|
|
|
public function setCustomClass($custom_class) {
|
|
|
|
$this->customClass = $custom_class;
|
|
|
|
return $this;
|
|
|
|
}
|
2016-11-18 13:23:41 -08:00
|
|
|
|
2013-03-15 23:41:36 -07:00
|
|
|
public function getCustomClass() {
|
|
|
|
return $this->customClass;
|
|
|
|
}
|
2012-10-22 19:06:56 -07:00
|
|
|
|
|
|
|
public function setFilePHID($file_phid) {
|
|
|
|
$this->filePHID = $file_phid;
|
|
|
|
return $this;
|
|
|
|
}
|
2016-11-18 13:23:41 -08:00
|
|
|
|
2012-10-22 19:06:56 -07:00
|
|
|
private function getFilePHID() {
|
|
|
|
return $this->filePHID;
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:23:41 -08:00
|
|
|
public function setFileMonogram($monogram) {
|
|
|
|
$this->fileMonogram = $monogram;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getFileMonogram() {
|
|
|
|
return $this->fileMonogram;
|
|
|
|
}
|
|
|
|
|
2012-10-22 19:06:56 -07:00
|
|
|
public function setFileViewable($file_viewable) {
|
|
|
|
$this->fileViewable = $file_viewable;
|
|
|
|
return $this;
|
|
|
|
}
|
2016-11-18 13:23:41 -08:00
|
|
|
|
2012-10-22 19:06:56 -07:00
|
|
|
private function getFileViewable() {
|
|
|
|
return $this->fileViewable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFileViewURI($file_view_uri) {
|
|
|
|
$this->fileViewURI = $file_view_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
2016-11-18 13:23:41 -08:00
|
|
|
|
2012-10-22 19:06:56 -07:00
|
|
|
private function getFileViewURI() {
|
|
|
|
return $this->fileViewURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFileDownloadURI($file_download_uri) {
|
|
|
|
$this->fileDownloadURI = $file_download_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
2016-11-18 13:23:41 -08:00
|
|
|
|
2012-10-22 19:06:56 -07:00
|
|
|
private function getFileDownloadURI() {
|
|
|
|
return $this->fileDownloadURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFileName($file_name) {
|
|
|
|
$this->fileName = $file_name;
|
|
|
|
return $this;
|
|
|
|
}
|
2016-11-18 13:23:41 -08:00
|
|
|
|
2012-10-22 19:06:56 -07:00
|
|
|
private function getFileName() {
|
|
|
|
return $this->fileName;
|
|
|
|
}
|
|
|
|
|
2016-11-27 14:00:03 -08:00
|
|
|
public function setFileSize($file_size) {
|
|
|
|
$this->fileSize = $file_size;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getFileSize() {
|
|
|
|
return $this->fileSize;
|
|
|
|
}
|
|
|
|
|
2016-11-28 11:08:38 -08:00
|
|
|
private function getFileIcon() {
|
|
|
|
return FileTypeIcon::getFileIcon($this->getFileName());
|
|
|
|
}
|
|
|
|
|
2017-01-03 10:50:12 -08:00
|
|
|
public function getMeta() {
|
2013-03-08 10:40:06 -08:00
|
|
|
return array(
|
|
|
|
'phid' => $this->getFilePHID(),
|
|
|
|
'viewable' => $this->getFileViewable(),
|
|
|
|
'uri' => $this->getFileViewURI(),
|
|
|
|
'dUri' => $this->getFileDownloadURI(),
|
|
|
|
'name' => $this->getFileName(),
|
2016-11-18 13:23:41 -08:00
|
|
|
'monogram' => $this->getFileMonogram(),
|
2016-11-28 11:08:38 -08:00
|
|
|
'icon' => $this->getFileIcon(),
|
|
|
|
'size' => $this->getFileSize(),
|
2013-03-08 10:40:06 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-03 10:50:12 -08:00
|
|
|
protected function getTagName() {
|
|
|
|
return 'div';
|
|
|
|
}
|
2012-10-22 19:06:56 -07:00
|
|
|
|
2017-01-03 10:50:12 -08:00
|
|
|
protected function getTagAttributes() {
|
2016-11-22 11:25:51 -08:00
|
|
|
$mustcapture = true;
|
|
|
|
$sigil = 'lightboxable';
|
2017-01-03 10:50:12 -08:00
|
|
|
$meta = $this->getMeta();
|
2012-10-22 19:06:56 -07:00
|
|
|
|
2013-03-15 23:41:36 -07:00
|
|
|
$class = 'phabricator-remarkup-embed-layout-link';
|
|
|
|
if ($this->getCustomClass()) {
|
|
|
|
$class = $this->getCustomClass();
|
|
|
|
}
|
|
|
|
|
2017-01-03 10:50:12 -08:00
|
|
|
return array(
|
|
|
|
'href' => $this->getFileViewURI(),
|
|
|
|
'class' => $class,
|
|
|
|
'sigil' => $sigil,
|
|
|
|
'meta' => $meta,
|
|
|
|
'mustcapture' => $mustcapture,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTagContent() {
|
|
|
|
require_celerity_resource('phabricator-remarkup-css');
|
|
|
|
require_celerity_resource('phui-lightbox-css');
|
|
|
|
|
2016-11-22 13:54:45 -08:00
|
|
|
$icon = id(new PHUIIconView())
|
2017-01-03 10:50:12 -08:00
|
|
|
->setIcon($this->getFileIcon())
|
|
|
|
->addClass('phabricator-remarkup-embed-layout-icon');
|
|
|
|
|
|
|
|
$dl_icon = id(new PHUIIconView())
|
|
|
|
->setIcon('fa-download');
|
|
|
|
|
|
|
|
$download_form = phabricator_form(
|
|
|
|
$this->getViewer(),
|
|
|
|
array(
|
|
|
|
'action' => $this->getFileDownloadURI(),
|
|
|
|
'method' => 'POST',
|
|
|
|
'class' => 'embed-download-form',
|
|
|
|
'sigil' => 'embed-download-form download',
|
|
|
|
),
|
|
|
|
phutil_tag(
|
|
|
|
'button',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-remarkup-embed-layout-download',
|
|
|
|
'type' => 'submit',
|
|
|
|
),
|
|
|
|
pht('Download')));
|
2016-11-27 14:00:03 -08:00
|
|
|
|
|
|
|
$info = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-remarkup-embed-layout-info',
|
|
|
|
),
|
|
|
|
$this->getFileSize());
|
|
|
|
|
|
|
|
$name = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-remarkup-embed-layout-name',
|
|
|
|
),
|
2016-11-28 11:08:38 -08:00
|
|
|
$this->getFileName());
|
2016-11-27 14:00:03 -08:00
|
|
|
|
|
|
|
$inner = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-remarkup-embed-layout-info-block',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$name,
|
|
|
|
$info,
|
|
|
|
));
|
2016-11-22 13:54:45 -08:00
|
|
|
|
2017-01-03 10:50:12 -08:00
|
|
|
return array(
|
|
|
|
$icon,
|
|
|
|
$inner,
|
|
|
|
$download_form,
|
|
|
|
);
|
2012-10-22 19:06:56 -07:00
|
|
|
}
|
|
|
|
}
|