|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* balloon |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com) |
|
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Balloon\App\Wopi; |
|
13
|
|
|
|
|
14
|
|
|
class Template |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* templates. |
|
18
|
|
|
*/ |
|
19
|
|
|
const TEMPLATES = [ |
|
20
|
|
|
'xlsx' => 'Office Open XML Spreadsheet', |
|
21
|
|
|
'xls' => 'Microsoft Excel 97-2003', |
|
22
|
|
|
'xlt' => 'Microsoft Excel 97-2003 Template', |
|
23
|
|
|
'csv' => 'Text CSV', |
|
24
|
|
|
'ods' => 'ODF Spreadsheet', |
|
25
|
|
|
'ots' => 'ODF Spreadsheet Template', |
|
26
|
|
|
'docx' => 'Office Open XML Text', |
|
27
|
|
|
'doc' => 'Microsoft Word 97-2003', |
|
28
|
|
|
'dot' => 'Microsoft Word 97-2003 Template', |
|
29
|
|
|
'odt' => 'ODF Textdocument', |
|
30
|
|
|
'ott' => 'ODF Textdocument Template', |
|
31
|
|
|
'pptx' => 'Office Open XML Presentation', |
|
32
|
|
|
'ppt' => 'Microsoft Powerpoint 97-2003', |
|
33
|
|
|
'potm' => 'Microsoft Powerpoint 97-2003 Template', |
|
34
|
|
|
'odp' => 'ODF Presentation', |
|
35
|
|
|
'otp' => 'ODF Presentation Template', |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Type. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $type; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Open template. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(string $type) |
|
49
|
|
|
{ |
|
50
|
|
|
if (!array_key_exists($type, self::TEMPLATES)) { |
|
51
|
|
|
throw new Exception\UnsupportedType('unsupported file type'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->type = $type; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get template size. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getSize(): int |
|
61
|
|
|
{ |
|
62
|
|
|
return filesize($this->getTemplate()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Open template stream. |
|
67
|
|
|
* |
|
68
|
|
|
* @return resource |
|
69
|
|
|
*/ |
|
70
|
|
|
public function get() |
|
71
|
|
|
{ |
|
72
|
|
|
return fopen($this->getTemplate(), 'r'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get path to template. |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function getTemplate(): string |
|
79
|
|
|
{ |
|
80
|
|
|
return __DIR__.DIRECTORY_SEPARATOR.'assets' |
|
81
|
|
|
.DIRECTORY_SEPARATOR.'template.'.$this->type; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|