3131namespace OC ;
3232
3333use OC \AppFramework \Bootstrap \Coordinator ;
34+ use OC \Preview \EMF ;
3435use OC \Preview \Generator ;
3536use OC \Preview \GeneratorHelper ;
3637use OC \Preview \IMagickSupport ;
38+ use OC \Preview \MSOffice2003 ;
39+ use OC \Preview \MSOffice2007 ;
40+ use OC \Preview \MSOfficeDoc ;
41+ use OC \Preview \OpenDocument ;
42+ use OC \Preview \StarOffice ;
3743use OCP \AppFramework \QueryException ;
3844use OCP \EventDispatcher \IEventDispatcher ;
3945use OCP \Files \File ;
@@ -366,7 +372,7 @@ protected function registerCoreProviders() {
366372 $ this ->registerCoreProvider (Preview \OpenDocument::class, '/application\/vnd.oasis.opendocument.*/ ' );
367373 $ this ->registerCoreProvider (Preview \Imaginary::class, Preview \Imaginary::supportedMimeTypes ());
368374
369- // SVG, Office and Bitmap require imagick
375+ // SVG and Bitmap require imagick
370376 if ($ this ->imagickSupport ->hasExtension ()) {
371377 $ imagickProviders = [
372378 'SVG ' => ['mimetype ' => '/image\/svg\+xml/ ' , 'class ' => Preview \SVG ::class],
@@ -391,28 +397,10 @@ protected function registerCoreProviders() {
391397 $ this ->registerCoreProvider ($ class , $ provider ['mimetype ' ]);
392398 }
393399 }
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- }
414400 }
415401
402+ $ this ->registerCoreProvidersOffice ();
403+
416404 // Video requires avconv or ffmpeg
417405 if (in_array (Preview \Movie::class, $ this ->getEnabledDefaultProvider ())) {
418406 $ movieBinary = $ this ->config ->getSystemValue ('preview_ffmpeg_path ' , null );
@@ -430,6 +418,43 @@ protected function registerCoreProviders() {
430418 }
431419 }
432420
421+ private function registerCoreProvidersOffice (): void {
422+ $ officeProviders = [
423+ ['mimetype ' => '/application\/msword/ ' , 'class ' => Preview \MSOfficeDoc::class],
424+ ['mimetype ' => '/application\/vnd.ms-.*/ ' , 'class ' => Preview \MSOffice2003::class],
425+ ['mimetype ' => '/application\/vnd.openxmlformats-officedocument.*/ ' , 'class ' => Preview \MSOffice2007::class],
426+ ['mimetype ' => '/application\/vnd.oasis.opendocument.*/ ' , 'class ' => Preview \OpenDocument::class],
427+ ['mimetype ' => '/application\/vnd.sun.xml.*/ ' , 'class ' => Preview \StarOffice::class],
428+ ['mimetype ' => '/image\/emf/ ' , 'class ' => Preview \EMF ::class],
429+ ];
430+
431+ $ findBinary = true ;
432+ $ officeBinary = false ;
433+
434+ foreach ($ officeProviders as $ provider ) {
435+ $ class = $ provider ['class ' ];
436+ if (!in_array (trim ($ class , '\\' ), $ this ->getEnabledDefaultProvider ())) {
437+ continue ;
438+ }
439+
440+ if ($ findBinary ) {
441+ // Office requires openoffice or libreoffice
442+ $ officeBinary = $ this ->config ->getSystemValue ('preview_libreoffice_path ' , false );
443+ if ($ officeBinary === false ) {
444+ $ officeBinary = $ this ->binaryFinder ->findBinaryPath ('libreoffice ' );
445+ }
446+ if ($ officeBinary === false ) {
447+ $ officeBinary = $ this ->binaryFinder ->findBinaryPath ('openoffice ' );
448+ }
449+ $ findBinary = false ;
450+ }
451+
452+ if ($ officeBinary ) {
453+ $ this ->registerCoreProvider ($ class , $ provider ['mimetype ' ], ['officeBinary ' => $ officeBinary ]);
454+ }
455+ }
456+ }
457+
433458 private function registerBootstrapProviders (): void {
434459 $ context = $ this ->bootstrapCoordinator ->getRegistrationContext ();
435460
0 commit comments