@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 recaptime-dev/main 59 lines 1.4 kB view raw
1<?php 2 3final class PhabricatorPDFDocumentEngine 4 extends PhabricatorDocumentEngine { 5 6 const ENGINEKEY = 'pdf'; 7 8 public function getViewAsLabel(PhabricatorDocumentRef $ref) { 9 return pht('View as PDF'); 10 } 11 12 protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) { 13 return 'fa-file-pdf-o'; 14 } 15 16 protected function canRenderDocumentType(PhabricatorDocumentRef $ref) { 17 $viewable_types = PhabricatorEnv::getEnvConfig('files.viewable-mime-types'); 18 $viewable_types = array_keys($viewable_types); 19 20 $pdf_types = array( 21 'application/pdf', 22 ); 23 24 return 25 $ref->hasAnyMimeType($viewable_types) && 26 $ref->hasAnyMimeType($pdf_types); 27 } 28 29 protected function newDocumentContent(PhabricatorDocumentRef $ref) { 30 $viewer = $this->getViewer(); 31 32 $file = $ref->getFile(); 33 if ($file) { 34 $source_uri = $file->getViewURI(); 35 } else { 36 throw new PhutilMethodNotImplementedException(); 37 } 38 39 $name = $ref->getName(); 40 $length = $ref->getByteLength(); 41 42 $link = id(new PhabricatorFileLinkView()) 43 ->setViewer($viewer) 44 ->setFileName($name) 45 ->setFileViewURI($source_uri) 46 ->setFileViewable(true) 47 ->setFileSize(phutil_format_bytes($length)); 48 49 $container = phutil_tag( 50 'div', 51 array( 52 'class' => 'document-engine-pdf', 53 ), 54 $link); 55 56 return $container; 57 } 58 59}