diff --git a/lib/Conversion/ConversionProvider.php b/lib/Conversion/ConversionProvider.php index 68dfb34e34..afc4221108 100644 --- a/lib/Conversion/ConversionProvider.php +++ b/lib/Conversion/ConversionProvider.php @@ -58,7 +58,11 @@ public function __construct( } public function getSupportedMimeTypes(): array { - $toPdf = array_merge( + $documents = self::MIME_TYPES['documents']; + $sheets = self::MIME_TYPES['sheets']; + $presentations = self::MIME_TYPES['presentations']; + + $pdfConversions = array_merge( [], self::MIME_TYPES['documents'], self::MIME_TYPES['sheets'], @@ -66,7 +70,48 @@ public function getSupportedMimeTypes(): array { self::MIME_TYPES['drawings'], ); - return [...$this->getMimeProvidersFor($toPdf, 'application/pdf')]; + $documentConversions = [ + // OpenDocument Text to Word Document + 'docx' => [$documents['odt']], + + // Word Document to OpenDocument Text + 'odt' => [$documents['doc'], $documents['docx']], + ]; + + $spreadsheetConversions = [ + // OpenDocument Spreadsheet to Excel Workbook + 'xlsx' => [$sheets['ods']], + + // Excel Workbook to OpenDocument Spreadsheet + 'ods' => [$sheets['xls'], $sheets['xlsx']], + ]; + + $presentationConversions = [ + // OpenDocument Presentation to PowerPoint Presentation + 'pptx' => [$presentations['odp']], + + // PowerPoint Presentation to OpenDocument Presentation + 'odp' => [$presentations['ppt'], $presentations['pptx']], + ]; + + + + return [ + // PDF conversions + ...$this->getMimeProvidersFor($toPdf, 'application/pdf'), + + // Document conversions + ...$this->getMimeProvidersFor($documentConversions['docx'], $documents['docx']), + ...$this->getMimeProvidersFor($documentConversions['odt'], $documents['odt']), + + // Spreadsheet conversions + ...$this->getMimeProvidersFor($spreadsheetConversions['xlsx'], $sheets['xlsx']), + ...$this->getMimeProvidersFor($spreadsheetConversions['ods'], $sheets['ods']), + + // Presentation conversions + ...$this->getMimeProvidersFor($presentationConversions['pptx'], $presentations['pptx']), + ...$this->getMimeProvidersFor($presentationConversions['odp'], $presentations['odp']), + ]; } public function convertFile(File $file, string $targetMimeType): mixed { @@ -113,18 +158,46 @@ private function getMimeInfoFor(string $targetMimeType): ?array { } private function getTargetMimeTypes(): array { + $documents = self::MIME_TYPES['documents']; + $sheets = self::MIME_TYPES['sheets']; + $presentations = self::MIME_TYPES['presentations']; + return [ 'application/pdf' => [ 'extension' => 'pdf', 'displayName' => $this->l10n->t('Portable Document Format (.pdf)'), ], + $documents['docx'] => [ + 'extension' => 'docx', + 'displayName' => $this->l10n->t('Word Document (.docx)'), + ], + $documents['odt'] => [ + 'extension' => 'odt', + 'displayName' => $this->l10n->t('OpenDocument Text (.odt)'), + ], + $sheets['xlsx'] => [ + 'extension' => 'xlsx', + 'displayName' => $this->l10n->t('Excel Workbook (.xlsx)'), + ], + $sheets['ods'] => [ + 'extension' => 'ods', + 'displayName' => $this->l10n->t('OpenDocument Spreadsheet (.ods)'), + ], + $presentations['pptx'] => [ + 'extension' => 'pptx', + 'displayName' => $this->l10n->t('PowerPoint Presentation (.pptx)'), + ], + $presentations['odp'] => [ + 'extension' => 'odp', + 'displayName' => $this->l10n->t('OpenDocument Presentation (.odp)'), + ], ]; } private function getExtensionForMimeType(string $mimeType): ?string { - foreach ($this->getTargetMimeTypes() as $targetMimeType) { - if ($targetMimeType['mime_type'] === $mimeType) { - return $targetMimeType['extension']; + foreach ($this->getTargetMimeTypes() as $targetMimeType => $targetMimeInfo) { + if ($targetMimeType === $mimeType) { + return $targetMimeInfo['extension']; } }