Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/document/PhabricatorPDFDocumentEngine.php
12241 views
1
<?php
2
3
final 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
// Since we just render a link to the document anyway, we don't need to
18
// check anything fancy in config to see if the MIME type is actually
19
// viewable.
20
21
return $ref->hasAnyMimeType(
22
array(
23
'application/pdf',
24
));
25
}
26
27
protected function newDocumentContent(PhabricatorDocumentRef $ref) {
28
$viewer = $this->getViewer();
29
30
$file = $ref->getFile();
31
if ($file) {
32
$source_uri = $file->getViewURI();
33
} else {
34
throw new PhutilMethodNotImplementedException();
35
}
36
37
$name = $ref->getName();
38
$length = $ref->getByteLength();
39
40
$link = id(new PhabricatorFileLinkView())
41
->setViewer($viewer)
42
->setFileName($name)
43
->setFileViewURI($source_uri)
44
->setFileViewable(true)
45
->setFileSize(phutil_format_bytes($length));
46
47
$container = phutil_tag(
48
'div',
49
array(
50
'class' => 'document-engine-pdf',
51
),
52
$link);
53
54
return $container;
55
}
56
57
}
58
59