2013-09-04 23:45:11 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:07:57 +02:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-04-29 11:57:22 +02:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:07:57 +02:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2021-01-22 10:35:37 +01:00
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
2020-04-29 11:57:22 +02:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2015-03-26 11:44:34 +01:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2015-06-25 11:43:55 +02:00
|
|
|
* @author Olivier Paroz <github@oparoz.com>
|
2016-07-21 18:13:36 +02:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2017-11-06 15:56:42 +01:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2019-12-03 19:57:53 +01:00
|
|
|
* @author Sebastian Steinmetz <462714+steiny2k@users.noreply.github.com>
|
2015-03-26 11:44:34 +01:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, version 3,
|
2019-12-03 19:57:53 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-09-04 23:45:11 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
namespace OC;
|
|
|
|
|
2020-10-04 14:41:08 +02:00
|
|
|
use OC\AppFramework\Bootstrap\Coordinator;
|
2016-10-16 16:48:11 +02:00
|
|
|
use OC\Preview\Generator;
|
2016-10-17 21:53:23 +02:00
|
|
|
use OC\Preview\GeneratorHelper;
|
2023-02-08 11:48:33 +01:00
|
|
|
use OC\Preview\IMagickSupport;
|
2020-10-04 14:41:08 +02:00
|
|
|
use OCP\AppFramework\QueryException;
|
2022-10-25 12:53:10 +02:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2016-10-16 16:48:11 +02:00
|
|
|
use OCP\Files\File;
|
|
|
|
use OCP\Files\IAppData;
|
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
2022-08-18 10:47:49 +02:00
|
|
|
use OCP\IBinaryFinder;
|
2016-10-16 16:48:11 +02:00
|
|
|
use OCP\IConfig;
|
2013-09-04 23:45:11 +02:00
|
|
|
use OCP\IPreview;
|
2020-10-04 14:41:08 +02:00
|
|
|
use OCP\IServerContainer;
|
2019-07-03 12:02:31 +02:00
|
|
|
use OCP\Preview\IProviderV2;
|
2020-10-04 14:41:08 +02:00
|
|
|
use function array_key_exists;
|
2013-09-04 23:45:11 +02:00
|
|
|
|
|
|
|
class PreviewManager implements IPreview {
|
2022-08-18 10:47:49 +02:00
|
|
|
protected IConfig $config;
|
|
|
|
protected IRootFolder $rootFolder;
|
|
|
|
protected IAppData $appData;
|
2022-10-25 12:53:10 +02:00
|
|
|
protected IEventDispatcher $eventDispatcher;
|
2022-08-18 10:47:49 +02:00
|
|
|
private ?Generator $generator = null;
|
|
|
|
private GeneratorHelper $helper;
|
|
|
|
protected bool $providerListDirty = false;
|
|
|
|
protected bool $registeredCoreProviders = false;
|
|
|
|
protected array $providers = [];
|
2015-03-11 16:43:00 +01:00
|
|
|
|
2015-03-13 09:39:16 +01:00
|
|
|
/** @var array mime type => support status */
|
2022-08-18 10:47:49 +02:00
|
|
|
protected array $mimeTypeSupportMap = [];
|
|
|
|
protected ?array $defaultProviders = null;
|
|
|
|
protected ?string $userId;
|
|
|
|
private Coordinator $bootstrapCoordinator;
|
2020-10-04 14:41:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash map (without value) of loaded bootstrap providers
|
|
|
|
* @psalm-var array<string, null>
|
|
|
|
*/
|
2022-08-18 10:47:49 +02:00
|
|
|
private array $loadedBootstrapProviders = [];
|
|
|
|
private IServerContainer $container;
|
|
|
|
private IBinaryFinder $binaryFinder;
|
2023-02-08 11:48:33 +01:00
|
|
|
private IMagickSupport $imagickSupport;
|
2022-08-18 10:47:49 +02:00
|
|
|
|
|
|
|
public function __construct(
|
2022-10-25 12:53:10 +02:00
|
|
|
IConfig $config,
|
|
|
|
IRootFolder $rootFolder,
|
|
|
|
IAppData $appData,
|
|
|
|
IEventDispatcher $eventDispatcher,
|
|
|
|
GeneratorHelper $helper,
|
|
|
|
?string $userId,
|
|
|
|
Coordinator $bootstrapCoordinator,
|
|
|
|
IServerContainer $container,
|
2023-02-08 11:48:33 +01:00
|
|
|
IBinaryFinder $binaryFinder,
|
|
|
|
IMagickSupport $imagickSupport
|
2022-08-18 10:47:49 +02:00
|
|
|
) {
|
2015-03-12 12:08:31 +01:00
|
|
|
$this->config = $config;
|
2016-10-16 16:48:11 +02:00
|
|
|
$this->rootFolder = $rootFolder;
|
|
|
|
$this->appData = $appData;
|
2016-11-10 14:04:59 +01:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
2019-07-03 12:02:31 +02:00
|
|
|
$this->helper = $helper;
|
2017-01-04 16:51:44 +01:00
|
|
|
$this->userId = $userId;
|
2020-10-04 14:41:08 +02:00
|
|
|
$this->bootstrapCoordinator = $bootstrapCoordinator;
|
|
|
|
$this->container = $container;
|
2022-08-18 10:47:49 +02:00
|
|
|
$this->binaryFinder = $binaryFinder;
|
2023-02-08 11:48:33 +01:00
|
|
|
$this->imagickSupport = $imagickSupport;
|
2015-03-12 10:48:52 +01:00
|
|
|
}
|
|
|
|
|
2015-03-11 16:43:00 +01:00
|
|
|
/**
|
|
|
|
* In order to improve lazy loading a closure can be registered which will be
|
|
|
|
* called in case preview providers are actually requested
|
|
|
|
*
|
2019-06-04 15:25:25 +02:00
|
|
|
* $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2
|
2015-03-11 16:43:00 +01:00
|
|
|
*
|
|
|
|
* @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
|
|
|
|
* @param \Closure $callable
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-08-18 10:47:49 +02:00
|
|
|
public function registerProvider($mimeTypeRegex, \Closure $callable): void {
|
2023-04-05 12:50:08 +02:00
|
|
|
if (!$this->config->getSystemValueBool('enable_previews', true)) {
|
2015-03-12 10:48:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-11 16:43:00 +01:00
|
|
|
if (!isset($this->providers[$mimeTypeRegex])) {
|
|
|
|
$this->providers[$mimeTypeRegex] = [];
|
|
|
|
}
|
|
|
|
$this->providers[$mimeTypeRegex][] = $callable;
|
2015-03-13 09:55:13 +01:00
|
|
|
$this->providerListDirty = true;
|
2015-03-11 16:43:00 +01:00
|
|
|
}
|
|
|
|
|
2015-03-12 10:48:52 +01:00
|
|
|
/**
|
|
|
|
* Get all providers
|
|
|
|
*/
|
2022-08-18 10:47:49 +02:00
|
|
|
public function getProviders(): array {
|
2023-04-05 17:42:14 +02:00
|
|
|
if (!$this->config->getSystemValueBool('enable_previews', true)) {
|
2015-03-13 09:55:13 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2015-03-16 11:25:41 +01:00
|
|
|
$this->registerCoreProviders();
|
2020-10-04 14:41:08 +02:00
|
|
|
$this->registerBootstrapProviders();
|
2015-03-13 09:55:13 +01:00
|
|
|
if ($this->providerListDirty) {
|
|
|
|
$keys = array_map('strlen', array_keys($this->providers));
|
|
|
|
array_multisort($keys, SORT_DESC, $this->providers);
|
|
|
|
$this->providerListDirty = false;
|
|
|
|
}
|
2015-03-12 10:48:52 +01:00
|
|
|
|
|
|
|
return $this->providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the manager have any providers
|
|
|
|
*/
|
2022-08-18 10:47:49 +02:00
|
|
|
public function hasProviders(): bool {
|
2015-03-16 11:25:41 +01:00
|
|
|
$this->registerCoreProviders();
|
2015-03-12 10:48:52 +01:00
|
|
|
return !empty($this->providers);
|
|
|
|
}
|
|
|
|
|
2020-02-16 01:45:47 +01:00
|
|
|
private function getGenerator(): Generator {
|
|
|
|
if ($this->generator === null) {
|
|
|
|
$this->generator = new Generator(
|
|
|
|
$this->config,
|
|
|
|
$this,
|
|
|
|
$this->appData,
|
|
|
|
new GeneratorHelper(
|
|
|
|
$this->rootFolder,
|
|
|
|
$this->config
|
|
|
|
),
|
|
|
|
$this->eventDispatcher
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->generator;
|
|
|
|
}
|
|
|
|
|
2016-10-16 16:48:11 +02:00
|
|
|
/**
|
|
|
|
* Returns a preview of a file
|
|
|
|
*
|
|
|
|
* The cache is searched first and if nothing usable was found then a preview is
|
|
|
|
* generated by one of the providers
|
|
|
|
*
|
|
|
|
* @param File $file
|
|
|
|
* @param int $width
|
|
|
|
* @param int $height
|
|
|
|
* @param bool $crop
|
|
|
|
* @param string $mode
|
2016-10-16 20:42:35 +02:00
|
|
|
* @param string $mimeType
|
2016-10-16 16:48:11 +02:00
|
|
|
* @return ISimpleFile
|
|
|
|
* @throws NotFoundException
|
2017-05-01 23:35:47 +02:00
|
|
|
* @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
|
|
|
|
* @since 11.0.0 - \InvalidArgumentException was added in 12.0.0
|
2016-10-16 16:48:11 +02:00
|
|
|
*/
|
2016-10-16 20:42:35 +02:00
|
|
|
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
|
2022-10-30 13:43:22 +01:00
|
|
|
$previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
|
|
|
|
$sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
|
|
|
|
try {
|
|
|
|
$preview = $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType);
|
|
|
|
} finally {
|
|
|
|
Generator::unguardWithSemaphore($sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $preview;
|
2020-02-16 01:45:47 +01:00
|
|
|
}
|
2016-10-16 16:48:11 +02:00
|
|
|
|
2020-02-16 01:45:47 +01:00
|
|
|
/**
|
|
|
|
* Generates previews of a file
|
|
|
|
*
|
|
|
|
* @param File $file
|
|
|
|
* @param array $specifications
|
|
|
|
* @param string $mimeType
|
|
|
|
* @return ISimpleFile the last preview that was generated
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
|
|
|
|
* @since 19.0.0
|
|
|
|
*/
|
|
|
|
public function generatePreviews(File $file, array $specifications, $mimeType = null) {
|
|
|
|
return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
|
2016-10-16 16:48:11 +02:00
|
|
|
}
|
|
|
|
|
2013-09-04 23:45:11 +02:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* returns true if the passed mime type is supported
|
2014-07-30 16:29:18 +02:00
|
|
|
*
|
2013-09-04 23:45:11 +02:00
|
|
|
* @param string $mimeType
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2015-03-12 11:57:56 +01:00
|
|
|
public function isMimeSupported($mimeType = '*') {
|
2023-04-05 17:42:14 +02:00
|
|
|
if (!$this->config->getSystemValueBool('enable_previews', true)) {
|
2015-03-11 16:43:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-13 09:39:16 +01:00
|
|
|
if (isset($this->mimeTypeSupportMap[$mimeType])) {
|
|
|
|
return $this->mimeTypeSupportMap[$mimeType];
|
|
|
|
}
|
|
|
|
|
2015-03-16 11:25:41 +01:00
|
|
|
$this->registerCoreProviders();
|
2020-10-04 14:41:08 +02:00
|
|
|
$this->registerBootstrapProviders();
|
2015-03-11 16:43:00 +01:00
|
|
|
$providerMimeTypes = array_keys($this->providers);
|
|
|
|
foreach ($providerMimeTypes as $supportedMimeType) {
|
|
|
|
if (preg_match($supportedMimeType, $mimeType)) {
|
2015-03-13 09:39:16 +01:00
|
|
|
$this->mimeTypeSupportMap[$mimeType] = true;
|
2015-03-11 16:43:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-03-13 09:39:16 +01:00
|
|
|
$this->mimeTypeSupportMap[$mimeType] = false;
|
2015-03-11 16:43:00 +01:00
|
|
|
return false;
|
2013-09-04 23:45:11 +02:00
|
|
|
}
|
2014-07-30 16:29:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a preview can be generated for a file
|
|
|
|
*/
|
2022-08-18 10:47:49 +02:00
|
|
|
public function isAvailable(\OCP\Files\FileInfo $file): bool {
|
2023-04-05 17:42:14 +02:00
|
|
|
if (!$this->config->getSystemValueBool('enable_previews', true)) {
|
2015-03-11 16:43:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-16 11:25:41 +01:00
|
|
|
$this->registerCoreProviders();
|
2015-03-13 09:39:16 +01:00
|
|
|
if (!$this->isMimeSupported($file->getMimetype())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-11 16:43:00 +01:00
|
|
|
$mount = $file->getMountPoint();
|
2020-04-10 14:19:56 +02:00
|
|
|
if ($mount and !$mount->getOption('previews', true)) {
|
2015-03-11 16:43:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->providers as $supportedMimeType => $providers) {
|
|
|
|
if (preg_match($supportedMimeType, $file->getMimetype())) {
|
2019-07-03 12:02:31 +02:00
|
|
|
foreach ($providers as $providerClosure) {
|
|
|
|
$provider = $this->helper->getProvider($providerClosure);
|
|
|
|
if (!($provider instanceof IProviderV2)) {
|
2015-03-12 10:48:52 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-03-11 16:43:00 +01:00
|
|
|
if ($provider->isAvailable($file)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-30 16:29:18 +02:00
|
|
|
}
|
2015-03-12 10:48:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of enabled default providers
|
|
|
|
*
|
|
|
|
* The following providers are enabled by default:
|
2015-04-02 10:31:24 +02:00
|
|
|
* - OC\Preview\PNG
|
|
|
|
* - OC\Preview\JPEG
|
|
|
|
* - OC\Preview\GIF
|
|
|
|
* - OC\Preview\BMP
|
|
|
|
* - OC\Preview\XBitmap
|
2015-03-13 09:51:42 +01:00
|
|
|
* - OC\Preview\MarkDown
|
2015-03-12 10:48:52 +01:00
|
|
|
* - OC\Preview\MP3
|
|
|
|
* - OC\Preview\TXT
|
|
|
|
*
|
|
|
|
* The following providers are disabled by default due to performance or privacy concerns:
|
2015-03-13 09:51:42 +01:00
|
|
|
* - OC\Preview\Font
|
2021-07-21 09:14:20 +02:00
|
|
|
* - OC\Preview\HEIC
|
2015-03-13 09:51:42 +01:00
|
|
|
* - OC\Preview\Illustrator
|
|
|
|
* - OC\Preview\Movie
|
2015-03-12 10:48:52 +01:00
|
|
|
* - OC\Preview\MSOfficeDoc
|
|
|
|
* - OC\Preview\MSOffice2003
|
|
|
|
* - OC\Preview\MSOffice2007
|
|
|
|
* - OC\Preview\OpenDocument
|
2015-03-13 09:51:42 +01:00
|
|
|
* - OC\Preview\PDF
|
|
|
|
* - OC\Preview\Photoshop
|
|
|
|
* - OC\Preview\Postscript
|
2015-03-12 10:48:52 +01:00
|
|
|
* - OC\Preview\StarOffice
|
|
|
|
* - OC\Preview\SVG
|
|
|
|
* - OC\Preview\TIFF
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getEnabledDefaultProvider() {
|
|
|
|
if ($this->defaultProviders !== null) {
|
|
|
|
return $this->defaultProviders;
|
|
|
|
}
|
|
|
|
|
2015-04-02 10:31:24 +02:00
|
|
|
$imageProviders = [
|
2018-01-25 23:16:13 +01:00
|
|
|
Preview\PNG::class,
|
|
|
|
Preview\JPEG::class,
|
|
|
|
Preview\GIF::class,
|
|
|
|
Preview\BMP::class,
|
2020-04-05 11:01:40 +02:00
|
|
|
Preview\XBitmap::class,
|
|
|
|
Preview\Krita::class,
|
2021-01-17 21:09:31 +01:00
|
|
|
Preview\WebP::class,
|
2015-04-02 10:31:24 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([
|
2018-01-25 23:16:13 +01:00
|
|
|
Preview\MarkDown::class,
|
|
|
|
Preview\MP3::class,
|
|
|
|
Preview\TXT::class,
|
2020-04-05 11:00:57 +02:00
|
|
|
Preview\OpenDocument::class,
|
2015-04-02 10:31:24 +02:00
|
|
|
], $imageProviders));
|
|
|
|
|
2018-01-25 23:16:13 +01:00
|
|
|
if (in_array(Preview\Image::class, $this->defaultProviders)) {
|
2015-04-02 10:31:24 +02:00
|
|
|
$this->defaultProviders = array_merge($this->defaultProviders, $imageProviders);
|
|
|
|
}
|
|
|
|
$this->defaultProviders = array_unique($this->defaultProviders);
|
2015-03-12 10:48:52 +01:00
|
|
|
return $this->defaultProviders;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the default providers (if enabled)
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @param string $mimeType
|
|
|
|
*/
|
2015-03-12 12:08:31 +01:00
|
|
|
protected function registerCoreProvider($class, $mimeType, $options = []) {
|
2015-03-12 10:48:52 +01:00
|
|
|
if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
|
2015-03-12 12:08:31 +01:00
|
|
|
$this->registerProvider($mimeType, function () use ($class, $options) {
|
|
|
|
return new $class($options);
|
2015-03-12 10:48:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the default providers (if enabled)
|
|
|
|
*/
|
|
|
|
protected function registerCoreProviders() {
|
2015-03-16 11:25:41 +01:00
|
|
|
if ($this->registeredCoreProviders) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->registeredCoreProviders = true;
|
|
|
|
|
2018-01-25 23:16:13 +01:00
|
|
|
$this->registerCoreProvider(Preview\TXT::class, '/text\/plain/');
|
|
|
|
$this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/');
|
|
|
|
$this->registerCoreProvider(Preview\PNG::class, '/image\/png/');
|
|
|
|
$this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/');
|
|
|
|
$this->registerCoreProvider(Preview\GIF::class, '/image\/gif/');
|
|
|
|
$this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/');
|
|
|
|
$this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/');
|
2021-01-17 21:09:31 +01:00
|
|
|
$this->registerCoreProvider(Preview\WebP::class, '/image\/webp/');
|
2020-04-05 11:01:40 +02:00
|
|
|
$this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/');
|
2018-01-25 23:16:13 +01:00
|
|
|
$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/');
|
2020-04-05 11:00:57 +02:00
|
|
|
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
|
2020-11-16 22:16:34 +01:00
|
|
|
$this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes());
|
2015-03-12 10:48:52 +01:00
|
|
|
|
2023-11-13 21:35:22 +01:00
|
|
|
// SVG and Bitmap require imagick
|
2023-02-08 11:48:33 +01:00
|
|
|
if ($this->imagickSupport->hasExtension()) {
|
2015-03-12 10:48:52 +01:00
|
|
|
$imagickProviders = [
|
2020-10-05 15:12:57 +02:00
|
|
|
'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class],
|
|
|
|
'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class],
|
|
|
|
'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class],
|
|
|
|
'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class],
|
|
|
|
'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class],
|
|
|
|
'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class],
|
|
|
|
'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class],
|
|
|
|
'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class],
|
2021-01-22 10:35:37 +01:00
|
|
|
'TGA' => ['mimetype' => '/image\/t(ar)?ga/', 'class' => Preview\TGA::class],
|
|
|
|
'SGI' => ['mimetype' => '/image\/sgi/', 'class' => Preview\SGI::class],
|
2015-03-12 10:48:52 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($imagickProviders as $queryFormat => $provider) {
|
|
|
|
$class = $provider['class'];
|
|
|
|
if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-08 11:48:33 +01:00
|
|
|
if ($this->imagickSupport->supportsFormat($queryFormat)) {
|
2015-03-12 10:48:52 +01:00
|
|
|
$this->registerCoreProvider($class, $provider['mimetype']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-13 21:35:22 +01:00
|
|
|
$this->registerCoreProvidersOffice();
|
|
|
|
|
2016-07-08 15:55:17 +02:00
|
|
|
// Video requires avconv or ffmpeg
|
2018-01-25 23:16:13 +01:00
|
|
|
if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) {
|
2023-01-18 16:30:41 +01:00
|
|
|
$movieBinary = $this->config->getSystemValue('preview_ffmpeg_path', null);
|
2023-01-18 20:32:09 +01:00
|
|
|
if (!is_string($movieBinary)) {
|
2023-01-18 16:30:41 +01:00
|
|
|
$movieBinary = $this->binaryFinder->findBinaryPath('avconv');
|
|
|
|
if (!is_string($movieBinary)) {
|
|
|
|
$movieBinary = $this->binaryFinder->findBinaryPath('ffmpeg');
|
|
|
|
}
|
2021-04-13 01:17:28 +02:00
|
|
|
}
|
2015-03-12 10:48:52 +01:00
|
|
|
|
2023-01-18 16:30:41 +01:00
|
|
|
|
2021-04-13 01:17:28 +02:00
|
|
|
if (is_string($movieBinary)) {
|
|
|
|
$this->registerCoreProvider(Preview\Movie::class, '/video\/.*/', ["movieBinary" => $movieBinary]);
|
2015-03-12 10:48:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 14:41:08 +02:00
|
|
|
|
2023-11-13 21:35:22 +01:00
|
|
|
private function registerCoreProvidersOffice(): void {
|
|
|
|
$officeProviders = [
|
|
|
|
['mimetype' => '/application\/msword/', 'class' => Preview\MSOfficeDoc::class],
|
|
|
|
['mimetype' => '/application\/vnd.ms-.*/', 'class' => Preview\MSOffice2003::class],
|
|
|
|
['mimetype' => '/application\/vnd.openxmlformats-officedocument.*/', 'class' => Preview\MSOffice2007::class],
|
|
|
|
['mimetype' => '/application\/vnd.oasis.opendocument.*/', 'class' => Preview\OpenDocument::class],
|
|
|
|
['mimetype' => '/application\/vnd.sun.xml.*/', 'class' => Preview\StarOffice::class],
|
|
|
|
['mimetype' => '/image\/emf/', 'class' => Preview\EMF::class],
|
|
|
|
];
|
|
|
|
|
|
|
|
$findBinary = true;
|
|
|
|
$officeBinary = false;
|
|
|
|
|
|
|
|
foreach ($officeProviders as $provider) {
|
|
|
|
$class = $provider['class'];
|
|
|
|
if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($findBinary) {
|
|
|
|
// Office requires openoffice or libreoffice
|
|
|
|
$officeBinary = $this->config->getSystemValue('preview_libreoffice_path', false);
|
|
|
|
if ($officeBinary === false) {
|
|
|
|
$officeBinary = $this->binaryFinder->findBinaryPath('libreoffice');
|
|
|
|
}
|
|
|
|
if ($officeBinary === false) {
|
|
|
|
$officeBinary = $this->binaryFinder->findBinaryPath('openoffice');
|
|
|
|
}
|
|
|
|
$findBinary = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($officeBinary) {
|
|
|
|
$this->registerCoreProvider($class, $provider['mimetype'], ['officeBinary' => $officeBinary]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 14:41:08 +02:00
|
|
|
private function registerBootstrapProviders(): void {
|
|
|
|
$context = $this->bootstrapCoordinator->getRegistrationContext();
|
|
|
|
|
|
|
|
if ($context === null) {
|
|
|
|
// Just ignore for now
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$providers = $context->getPreviewProviders();
|
|
|
|
foreach ($providers as $provider) {
|
|
|
|
$key = $provider->getMimeTypeRegex() . '-' . $provider->getService();
|
|
|
|
if (array_key_exists($key, $this->loadedBootstrapProviders)) {
|
|
|
|
// Do not load the provider more than once
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->loadedBootstrapProviders[$key] = null;
|
|
|
|
|
|
|
|
$this->registerProvider($provider->getMimeTypeRegex(), function () use ($provider) {
|
|
|
|
try {
|
2022-08-18 10:47:49 +02:00
|
|
|
return $this->container->get($provider->getService());
|
2020-10-04 14:41:08 +02:00
|
|
|
} catch (QueryException $e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-09-04 23:45:11 +02:00
|
|
|
}
|