@@ -366,7 +366,7 @@ protected function registerCoreProviders() {
366366 $ this ->registerCoreProvider (Preview \OpenDocument::class, '/application\/vnd.oasis.opendocument.*/ ' );
367367 $ this ->registerCoreProvider (Preview \Imaginary::class, Preview \Imaginary::supportedMimeTypes ());
368368
369- // SVG, Office and Bitmap require imagick
369+ // SVG and Bitmap require imagick
370370 if ($ this ->imagickSupport ->hasExtension ()) {
371371 $ imagickProviders = [
372372 'SVG ' => ['mimetype ' => '/image\/svg\+xml/ ' , 'class ' => Preview \SVG ::class],
@@ -391,28 +391,10 @@ protected function registerCoreProviders() {
391391 $ this ->registerCoreProvider ($ class , $ provider ['mimetype ' ]);
392392 }
393393 }
394-
395- if ($ this ->imagickSupport ->supportsFormat ('PDF ' )) {
396- // Office requires openoffice or libreoffice
397- $ officeBinary = $ this ->config ->getSystemValue ('preview_libreoffice_path ' , null );
398- if (!is_string ($ officeBinary )) {
399- $ officeBinary = $ this ->binaryFinder ->findBinaryPath ('libreoffice ' );
400- }
401- if (!is_string ($ officeBinary )) {
402- $ officeBinary = $ this ->binaryFinder ->findBinaryPath ('openoffice ' );
403- }
404-
405- if (is_string ($ officeBinary )) {
406- $ this ->registerCoreProvider (Preview \MSOfficeDoc::class, '/application\/msword/ ' , ["officeBinary " => $ officeBinary ]);
407- $ this ->registerCoreProvider (Preview \MSOffice2003::class, '/application\/vnd.ms-.*/ ' , ["officeBinary " => $ officeBinary ]);
408- $ this ->registerCoreProvider (Preview \MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/ ' , ["officeBinary " => $ officeBinary ]);
409- $ this ->registerCoreProvider (Preview \OpenDocument::class, '/application\/vnd.oasis.opendocument.*/ ' , ["officeBinary " => $ officeBinary ]);
410- $ this ->registerCoreProvider (Preview \StarOffice::class, '/application\/vnd.sun.xml.*/ ' , ["officeBinary " => $ officeBinary ]);
411- $ this ->registerCoreProvider (Preview \EMF ::class, '/image\/emf/ ' , ['officeBinary ' => $ officeBinary ]);
412- }
413- }
414394 }
415395
396+ $ this ->registerCoreProvidersOffice ();
397+
416398 // Video requires avconv or ffmpeg
417399 if (in_array (Preview \Movie::class, $ this ->getEnabledDefaultProvider ())) {
418400 $ movieBinary = $ this ->config ->getSystemValue ('preview_ffmpeg_path ' , null );
@@ -430,6 +412,43 @@ protected function registerCoreProviders() {
430412 }
431413 }
432414
415+ private function registerCoreProvidersOffice (): void {
416+ $ officeProviders = [
417+ ['mimetype ' => '/application\/msword/ ' , 'class ' => Preview \MSOfficeDoc::class],
418+ ['mimetype ' => '/application\/vnd.ms-.*/ ' , 'class ' => Preview \MSOffice2003::class],
419+ ['mimetype ' => '/application\/vnd.openxmlformats-officedocument.*/ ' , 'class ' => Preview \MSOffice2007::class],
420+ ['mimetype ' => '/application\/vnd.oasis.opendocument.*/ ' , 'class ' => Preview \OpenDocument::class],
421+ ['mimetype ' => '/application\/vnd.sun.xml.*/ ' , 'class ' => Preview \StarOffice::class],
422+ ['mimetype ' => '/image\/emf/ ' , 'class ' => Preview \EMF ::class],
423+ ];
424+
425+ $ findBinary = true ;
426+ $ officeBinary = false ;
427+
428+ foreach ($ officeProviders as $ provider ) {
429+ $ class = $ provider ['class ' ];
430+ if (!in_array (trim ($ class , '\\' ), $ this ->getEnabledDefaultProvider ())) {
431+ continue ;
432+ }
433+
434+ if ($ findBinary ) {
435+ // Office requires openoffice or libreoffice
436+ $ officeBinary = $ this ->config ->getSystemValue ('preview_libreoffice_path ' , false );
437+ if ($ officeBinary === false ) {
438+ $ officeBinary = $ this ->binaryFinder ->findBinaryPath ('libreoffice ' );
439+ }
440+ if ($ officeBinary === false ) {
441+ $ officeBinary = $ this ->binaryFinder ->findBinaryPath ('openoffice ' );
442+ }
443+ $ findBinary = false ;
444+ }
445+
446+ if ($ officeBinary ) {
447+ $ this ->registerCoreProvider ($ class , $ provider ['mimetype ' ], ['officeBinary ' => $ officeBinary ]);
448+ }
449+ }
450+ }
451+
433452 private function registerBootstrapProviders (): void {
434453 $ context = $ this ->bootstrapCoordinator ->getRegistrationContext ();
435454
0 commit comments