Skip to content

Commit 7b8730d

Browse files
committed
feat: add more conversion possibilities
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
1 parent be5f99a commit 7b8730d

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

lib/Conversion/ConversionProvider.php

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,60 @@ public function __construct(
5858
}
5959

6060
public function getSupportedMimeTypes(): array {
61-
$toPdf = array_merge(
61+
$documents = self::MIME_TYPES['documents'];
62+
$sheets = self::MIME_TYPES['sheets'];
63+
$presentations = self::MIME_TYPES['presentations'];
64+
65+
$pdfConversions = array_merge(
6266
[],
6367
self::MIME_TYPES['documents'],
6468
self::MIME_TYPES['sheets'],
6569
self::MIME_TYPES['presentations'],
6670
self::MIME_TYPES['drawings'],
6771
);
6872

69-
return [...$this->getMimeProvidersFor($toPdf, 'application/pdf')];
73+
$documentConversions = [
74+
// OpenDocument Text to Word Document
75+
'docx' => [$documents['odt']],
76+
77+
// Word Document to OpenDocument Text
78+
'odt' => [$documents['doc'], $documents['docx']],
79+
];
80+
81+
$spreadsheetConversions = [
82+
// OpenDocument Spreadsheet to Excel Workbook
83+
'xlsx' => [$sheets['ods']],
84+
85+
// Excel Workbook to OpenDocument Spreadsheet
86+
'ods' => [$sheets['xls'], $sheets['xlsx']],
87+
];
88+
89+
$presentationConversions = [
90+
// OpenDocument Presentation to PowerPoint Presentation
91+
'pptx' => [$presentations['odp']],
92+
93+
// PowerPoint Presentation to OpenDocument Presentation
94+
'odp' => [$presentations['ppt'], $presentations['pptx']],
95+
];
96+
97+
98+
99+
return [
100+
// PDF conversions
101+
...$this->getMimeProvidersFor($toPdf, 'application/pdf'),
102+
103+
// Document conversions
104+
...$this->getMimeProvidersFor($documentConversions['docx'], $documents['docx']),
105+
...$this->getMimeProvidersFor($documentConversions['odt'], $documents['odt']),
106+
107+
// Spreadsheet conversions
108+
...$this->getMimeProvidersFor($spreadsheetConversions['xlsx'], $sheets['xlsx']),
109+
...$this->getMimeProvidersFor($spreadsheetConversions['ods'], $sheets['ods']),
110+
111+
// Presentation conversions
112+
...$this->getMimeProvidersFor($presentationConversions['pptx'], $presentations['pptx']),
113+
...$this->getMimeProvidersFor($presentationConversions['odp'], $presentations['odp']),
114+
];
70115
}
71116

72117
public function convertFile(File $file, string $targetMimeType): mixed {
@@ -113,18 +158,46 @@ private function getMimeInfoFor(string $targetMimeType): ?array {
113158
}
114159

115160
private function getTargetMimeTypes(): array {
161+
$documents = self::MIME_TYPES['documents'];
162+
$sheets = self::MIME_TYPES['sheets'];
163+
$presentations = self::MIME_TYPES['presentations'];
164+
116165
return [
117166
'application/pdf' => [
118167
'extension' => 'pdf',
119168
'displayName' => $this->l10n->t('Portable Document Format (.pdf)'),
120169
],
170+
$documents['docx'] => [
171+
'extension' => 'docx',
172+
'displayName' => $this->l10n->t('Word Document (.docx)'),
173+
],
174+
$documents['odt'] => [
175+
'extension' => 'odt',
176+
'displayName' => $this->l10n->t('OpenDocument Text (.odt)'),
177+
],
178+
$sheets['xlsx'] => [
179+
'extension' => 'xlsx',
180+
'displayName' => $this->l10n->t('Excel Workbook (.xlsx)'),
181+
],
182+
$sheets['ods'] => [
183+
'extension' => 'ods',
184+
'displayName' => $this->l10n->t('OpenDocument Spreadsheet (.ods)'),
185+
],
186+
$presentations['pptx'] => [
187+
'extension' => 'pptx',
188+
'displayName' => $this->l10n->t('PowerPoint Presentation (.pptx)'),
189+
],
190+
$presentations['odp'] => [
191+
'extension' => 'odp',
192+
'displayName' => $this->l10n->t('OpenDocument Presentation (.odp)'),
193+
],
121194
];
122195
}
123196

124197
private function getExtensionForMimeType(string $mimeType): ?string {
125-
foreach ($this->getTargetMimeTypes() as $targetMimeType) {
126-
if ($targetMimeType['mime_type'] === $mimeType) {
127-
return $targetMimeType['extension'];
198+
foreach ($this->getTargetMimeTypes() as $targetMimeType => $targetMimeInfo) {
199+
if ($targetMimeType === $mimeType) {
200+
return $targetMimeInfo['extension'];
128201
}
129202
}
130203

0 commit comments

Comments
 (0)