forked from UB-Mannheim/PalMA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileHandler.class.php
143 lines (112 loc) · 3.94 KB
/
FileHandler.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
// Copyright (C) 2014 Universitätsbibliothek Mannheim
// See file LICENSE for license details.
// Authors: Alexander Wagner, Stefan Weil
// Test whether the script was called directly (used for unit test).
if (!isset($unittest)) {
$unittest = array();
}
$unittest[__FILE__] = (sizeof(get_included_files()) == 1);
class EogHandler extends FileHandler {
function getControls() {
return FileHandler::CURSOR | FileHandler::ZOOM;
}
function show($path) {
}
}
class LibreOfficeHandler extends FileHandler {
function getControls() {
return FileHandler::CURSOR | FileHandler::ZOOM;
}
function show($path) {
}
}
class NetsurfHandler extends FileHandler {
function getControls() {
return FileHandler::CURSOR | FileHandler::ZOOM;
}
function show($path) {
}
}
class VlcHandler extends FileHandler {
function getControls() {
return FileHandler::CURSOR | FileHandler::ZOOM;
}
function show($path) {
}
}
class ZathuraHandler extends FileHandler {
function getControls() {
return FileHandler::CURSOR | FileHandler::ZOOM |
FileHandler::HOME | FileHandler::END |
FileHandler::PRIOR | FileHandler::NEXT |
FileHandler::DOWNLOAD;
}
function show($path) {
}
}
abstract class FileHandler {
// Constants for allowed controls.
const UP = 1;
const DOWN = 2;
const LEFT = 4;
const RIGHT = 8;
const ZOOMIN = 16;
const ZOOMOUT = 32;
const HOME = 64;
const END = 128;
const PRIOR = 256;
const NEXT = 512;
const DOWNLOAD = 1024;
// Shortcuts for combinations of controls.
const CURSOR = 15; // UP | DOWN | LEFT | RIGHT
const ZOOM = 48; // ZOOMIN | ZOOMOUT
const ALL = 2047;
// up down left right zoomin zoomout home end prior next download
// protected $FILES = array();
// protected $UPLOAD_PATH;
abstract protected function getControls();
abstract protected function show($path);
public static function getFileHandler($file) {
$ftype = pathinfo($file, PATHINFO_EXTENSION);
$fhandler = "";
// $params;
// echo $ftype;
if($ftype==='pdf') {
$fhandler='/usr/bin/zathura';
} else if ($ftype==='gif' || $ftype==='jpg' || $ftype==='png') {
$fhandler='/usr/bin/eog';
} else if ($ftype==='doc' || $ftype==='docx' || $ftype==='odt' || $ftype==='txt') {
$fhandler='/usr/bin/libreoffice --writer -o -n --nologo --norestore --view';
} else if ($ftype==='ppt' || $ftype==='pptx' || $ftype==='pps' || $ftype==='ppsx' || $ftype==='odp') {
// optional --show (presentation mode)
$fhandler='/usr/bin/libreoffice --impress -o -n --nologo --norestore --view';
} else if ($ftype==='xls' || $ftype==='xlsx' || $ftype==='ods') {
$fhandler='/usr/bin/libreoffice --calc -o -n --nologo --norestore --view';
} else if ($ftype==='html' || $ftype==='url') {
$fhandler='/usr/bin/netsurf';
} else if ($ftype==='mpg' || $ftype==='mpeg' || $ftype==='avi' ||
$ftype==='mp3' || $ftype=="mp4") {
$fhandler='/usr/bin/vlc --no-audio';
}
/*
alternatively with mime-types
// $ftype = mime_content_type($this->UPLOAD_PATH.$file);
// if($ftype=='application/pdf')
// if($ftype=='image/gif' || $ftype=='image/jpg' || $ftype=='image/png' )
// if($ftype=='html' || $ftype=='url' || $ftype="text/plain")
// (...)
*/
return $fhandler;
}
}
if ($unittest[__FILE__]) {
// Run unit test.
$netsurfHandler = new NetsurfHandler;
$zathuraHandler = new ZathuraHandler;
echo("DOWNLOAD =" . FileHandler::DOWNLOAD . "\n");
echo("filehandler=" . FileHandler::getFileHandler("test.txt") . "\n");
$handler = ${'netsurf' . 'Handler'};
echo("controls =" . $handler->getControls() . "\n");
}
?>