diff --git a/config/config.sample.php b/config/config.sample.php index 71d22fbe2b400..9e5f7b6baf6d4 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -989,7 +989,6 @@ * - OC\Preview\MSOffice2003 * - OC\Preview\MSOffice2007 * - OC\Preview\MSOfficeDoc - * - OC\Preview\OpenDocument * - OC\Preview\PDF * - OC\Preview\Photoshop * - OC\Preview\Postscript @@ -998,14 +997,6 @@ * - OC\Preview\TIFF * - OC\Preview\Font * - * The following providers are not available in Microsoft Windows: - * - * - OC\Preview\Movie - * - OC\Preview\MSOfficeDoc - * - OC\Preview\MSOffice2003 - * - OC\Preview\MSOffice2007 - * - OC\Preview\OpenDocument - * - OC\Preview\StarOffice * * Defaults to the following providers: * @@ -1018,6 +1009,8 @@ * - OC\Preview\PNG * - OC\Preview\TXT * - OC\Preview\XBitmap + * - OC\Preview\OpenDocument + * - OC\Preview\Krita */ 'enabledPreviewProviders' => [ 'OC\Preview\PNG', @@ -1028,7 +1021,9 @@ 'OC\Preview\XBitmap', 'OC\Preview\MP3', 'OC\Preview\TXT', - 'OC\Preview\MarkDown' + 'OC\Preview\MarkDown', + 'OC\Preview\OpenDocument', + 'OC\Preview\Krita', ], /** diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8fb6196497e6a..c600c15068ddd 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1124,6 +1124,7 @@ 'OC\\Preview\\BMP' => $baseDir . '/lib/private/Preview/BMP.php', 'OC\\Preview\\BackgroundCleanupJob' => $baseDir . '/lib/private/Preview/BackgroundCleanupJob.php', 'OC\\Preview\\Bitmap' => $baseDir . '/lib/private/Preview/Bitmap.php', + 'OC\\Preview\\Bundled' => $baseDir . '/lib/private/Preview/Bundled.php', 'OC\\Preview\\Font' => $baseDir . '/lib/private/Preview/Font.php', 'OC\\Preview\\GIF' => $baseDir . '/lib/private/Preview/GIF.php', 'OC\\Preview\\Generator' => $baseDir . '/lib/private/Preview/Generator.php', @@ -1132,6 +1133,7 @@ 'OC\\Preview\\Illustrator' => $baseDir . '/lib/private/Preview/Illustrator.php', 'OC\\Preview\\Image' => $baseDir . '/lib/private/Preview/Image.php', 'OC\\Preview\\JPEG' => $baseDir . '/lib/private/Preview/JPEG.php', + 'OC\\Preview\\Krita' => $baseDir . '/lib/private/Preview/Krita.php', 'OC\\Preview\\MP3' => $baseDir . '/lib/private/Preview/MP3.php', 'OC\\Preview\\MSOffice2003' => $baseDir . '/lib/private/Preview/MSOffice2003.php', 'OC\\Preview\\MSOffice2007' => $baseDir . '/lib/private/Preview/MSOffice2007.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 4748ad2b97844..87a9460f77b00 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1153,6 +1153,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Preview\\BMP' => __DIR__ . '/../../..' . '/lib/private/Preview/BMP.php', 'OC\\Preview\\BackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Preview/BackgroundCleanupJob.php', 'OC\\Preview\\Bitmap' => __DIR__ . '/../../..' . '/lib/private/Preview/Bitmap.php', + 'OC\\Preview\\Bundled' => __DIR__ . '/../../..' . '/lib/private/Preview/Bundled.php', 'OC\\Preview\\Font' => __DIR__ . '/../../..' . '/lib/private/Preview/Font.php', 'OC\\Preview\\GIF' => __DIR__ . '/../../..' . '/lib/private/Preview/GIF.php', 'OC\\Preview\\Generator' => __DIR__ . '/../../..' . '/lib/private/Preview/Generator.php', @@ -1161,6 +1162,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Preview\\Illustrator' => __DIR__ . '/../../..' . '/lib/private/Preview/Illustrator.php', 'OC\\Preview\\Image' => __DIR__ . '/../../..' . '/lib/private/Preview/Image.php', 'OC\\Preview\\JPEG' => __DIR__ . '/../../..' . '/lib/private/Preview/JPEG.php', + 'OC\\Preview\\Krita' => __DIR__ . '/../../..' . '/lib/private/Preview/Krita.php', 'OC\\Preview\\MP3' => __DIR__ . '/../../..' . '/lib/private/Preview/MP3.php', 'OC\\Preview\\MSOffice2003' => __DIR__ . '/../../..' . '/lib/private/Preview/MSOffice2003.php', 'OC\\Preview\\MSOffice2007' => __DIR__ . '/../../..' . '/lib/private/Preview/MSOffice2007.php', diff --git a/lib/private/Preview/Bundled.php b/lib/private/Preview/Bundled.php new file mode 100644 index 0000000000000..afd286d895b5a --- /dev/null +++ b/lib/private/Preview/Bundled.php @@ -0,0 +1,56 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OC\Preview; + +use OC\Archive\ZIP; +use OCP\Files\File; +use OCP\IImage; + +/** + * Extracts a preview from files that embed them in an ZIP archive + */ +abstract class Bundled extends ProviderV2 { + + protected function extractThumbnail(File $file, $path): ?IImage { + $sourceTmp = \OC::$server->getTempManager()->getTemporaryFile(); + $targetTmp = \OC::$server->getTempManager()->getTemporaryFile(); + + try { + $content = $file->fopen('r'); + file_put_contents($sourceTmp, $content); + + $zip = new ZIP($sourceTmp); + $zip->extractFile($path, $targetTmp); + + $image = new \OC_Image(); + $image->loadFromFile($targetTmp); + $image->fixOrientation(); + + return $image; + } catch (\Exception $e) { + return null; + } + } + +} diff --git a/lib/private/Preview/Krita.php b/lib/private/Preview/Krita.php new file mode 100644 index 0000000000000..39449145a14e9 --- /dev/null +++ b/lib/private/Preview/Krita.php @@ -0,0 +1,52 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OC\Preview; + +use OCP\Files\File; +use OCP\IImage; + +class Krita extends Bundled { + /** + * {@inheritDoc} + */ + public function getMimeType(): string { + return '/application\/x-krita/'; + } + + + /** + * @inheritDoc + */ + public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { + $image = $this->extractThumbnail($file, 'mergedimage.png'); + if ($image->valid()) { + return $image; + } + $image = $this->extractThumbnail($file, 'preview.png'); + if ($image->valid()) { + return $image; + } + return null; + } +} diff --git a/lib/private/Preview/OpenDocument.php b/lib/private/Preview/OpenDocument.php index b795441d83774..1db7b0be521cb 100644 --- a/lib/private/Preview/OpenDocument.php +++ b/lib/private/Preview/OpenDocument.php @@ -25,11 +25,26 @@ namespace OC\Preview; //.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt -class OpenDocument extends Office { +use OCP\Files\File; +use OCP\IImage; + +class OpenDocument extends Bundled { /** * {@inheritDoc} */ public function getMimeType(): string { return '/application\/vnd.oasis.opendocument.*/'; } + + + /** + * @inheritDoc + */ + public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { + $image = $this->extractThumbnail($file, 'Thumbnails/thumbnail.png'); + if ($image->valid()) { + return $image; + } + return null; + } } diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index 652a442deec56..adfc04199e3c5 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -293,13 +293,15 @@ protected function getEnabledDefaultProvider() { Preview\GIF::class, Preview\BMP::class, Preview\HEIC::class, - Preview\XBitmap::class + Preview\XBitmap::class, + Preview\Krita::class, ]; $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ Preview\MarkDown::class, Preview\MP3::class, Preview\TXT::class, + Preview\OpenDocument::class, ], $imageProviders)); if (in_array(Preview\Image::class, $this->defaultProviders)) { @@ -339,7 +341,9 @@ protected function registerCoreProviders() { $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/'); $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); + $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); + $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); // SVG, Office and Bitmap require imagick if (extension_loaded('imagick')) {