Path: blob/master/src/view/layout/PhabricatorFileLinkView.php
12241 views
<?php12final class PhabricatorFileLinkView extends AphrontTagView {34private $fileName;5private $fileDownloadURI;6private $fileViewURI;7private $fileViewable;8private $filePHID;9private $fileMonogram;10private $fileSize;11private $customClass;1213public function setCustomClass($custom_class) {14$this->customClass = $custom_class;15return $this;16}1718public function getCustomClass() {19return $this->customClass;20}2122public function setFilePHID($file_phid) {23$this->filePHID = $file_phid;24return $this;25}2627private function getFilePHID() {28return $this->filePHID;29}3031public function setFileMonogram($monogram) {32$this->fileMonogram = $monogram;33return $this;34}3536private function getFileMonogram() {37return $this->fileMonogram;38}3940public function setFileViewable($file_viewable) {41$this->fileViewable = $file_viewable;42return $this;43}4445private function getFileViewable() {46return $this->fileViewable;47}4849public function setFileViewURI($file_view_uri) {50$this->fileViewURI = $file_view_uri;51return $this;52}5354private function getFileViewURI() {55return $this->fileViewURI;56}5758public function setFileDownloadURI($file_download_uri) {59$this->fileDownloadURI = $file_download_uri;60return $this;61}6263private function getFileDownloadURI() {64return $this->fileDownloadURI;65}6667public function setFileName($file_name) {68$this->fileName = $file_name;69return $this;70}7172private function getFileName() {73return $this->fileName;74}7576public function setFileSize($file_size) {77$this->fileSize = $file_size;78return $this;79}8081private function getFileSize() {82return $this->fileSize;83}8485private function getFileIcon() {86return FileTypeIcon::getFileIcon($this->getFileName());87}8889public function getMeta() {90return array(91'phid' => $this->getFilePHID(),92'viewable' => $this->getFileViewable(),93'uri' => $this->getFileViewURI(),94'dUri' => $this->getFileDownloadURI(),95'name' => $this->getFileName(),96'monogram' => $this->getFileMonogram(),97'icon' => $this->getFileIcon(),98'size' => $this->getFileSize(),99);100}101102protected function getTagName() {103if ($this->getFileDownloadURI()) {104return 'div';105} else {106return 'a';107}108}109110protected function getTagAttributes() {111$class = 'phabricator-remarkup-embed-layout-link';112if ($this->getCustomClass()) {113$class = $this->getCustomClass();114}115116$attributes = array(117'href' => $this->getFileViewURI(),118'target' => '_blank',119'rel' => 'noreferrer',120'class' => $class,121);122123if ($this->getFilePHID()) {124$mustcapture = true;125$sigil = 'lightboxable';126$meta = $this->getMeta();127128$attributes += array(129'sigil' => $sigil,130'meta' => $meta,131'mustcapture' => $mustcapture,132);133}134135return $attributes;136}137138protected function getTagContent() {139require_celerity_resource('phabricator-remarkup-css');140require_celerity_resource('phui-lightbox-css');141142$icon = id(new PHUIIconView())143->setIcon($this->getFileIcon())144->addClass('phabricator-remarkup-embed-layout-icon');145146$download_link = null;147148$download_uri = $this->getFileDownloadURI();149if ($download_uri) {150$dl_icon = id(new PHUIIconView())151->setIcon('fa-download');152153$download_link = phutil_tag(154'a',155array(156'class' => 'phabricator-remarkup-embed-layout-download',157'href' => $download_uri,158),159pht('Download'));160}161162$info = phutil_tag(163'span',164array(165'class' => 'phabricator-remarkup-embed-layout-info',166),167$this->getFileSize());168169$name = phutil_tag(170'span',171array(172'class' => 'phabricator-remarkup-embed-layout-name',173),174$this->getFileName());175176$inner = phutil_tag(177'span',178array(179'class' => 'phabricator-remarkup-embed-layout-info-block',180),181array(182$name,183$info,184));185186return array(187$icon,188$inner,189$download_link,190);191}192}193194195