2013-09-05 01:45:11 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Olivier Paroz <github@oparoz.com>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Sebastian Steinmetz <462714+steiny2k@users.noreply.github.com>
|
2015-03-26 13:44:34 +03: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 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-09-05 01:45:11 +04:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2013-09-05 01:45:11 +04:00
|
|
|
namespace OC;
|
|
|
|
|
2016-10-16 17:48:11 +03:00
|
|
|
use OC\Preview\Generator;
|
2016-10-17 22:53:23 +03:00
|
|
|
use OC\Preview\GeneratorHelper;
|
2016-10-16 17:48:11 +03:00
|
|
|
use OCP\Files\File;
|
|
|
|
use OCP\Files\IAppData;
|
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
|
|
|
use OCP\IConfig;
|
2013-09-05 01:45:11 +04:00
|
|
|
use OCP\IPreview;
|
2019-07-03 13:02:31 +03:00
|
|
|
use OCP\Preview\IProviderV2;
|
2016-11-10 16:04:59 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2013-09-05 01:45:11 +04:00
|
|
|
|
|
|
|
class PreviewManager implements IPreview {
|
2016-10-16 17:48:11 +03:00
|
|
|
/** @var IConfig */
|
2015-03-12 14:08:31 +03:00
|
|
|
protected $config;
|
|
|
|
|
2016-10-16 17:48:11 +03:00
|
|
|
/** @var IRootFolder */
|
|
|
|
protected $rootFolder;
|
|
|
|
|
|
|
|
/** @var IAppData */
|
|
|
|
protected $appData;
|
|
|
|
|
2016-11-10 16:04:59 +03:00
|
|
|
/** @var EventDispatcherInterface */
|
|
|
|
protected $eventDispatcher;
|
|
|
|
|
2016-10-16 17:48:11 +03:00
|
|
|
/** @var Generator */
|
|
|
|
private $generator;
|
2019-07-03 13:02:31 +03:00
|
|
|
|
|
|
|
/** @var GeneratorHelper */
|
|
|
|
private $helper;
|
2016-10-16 17:48:11 +03:00
|
|
|
|
2015-03-16 13:25:41 +03:00
|
|
|
/** @var bool */
|
2015-03-13 11:55:13 +03:00
|
|
|
protected $providerListDirty = false;
|
|
|
|
|
2015-03-16 13:25:41 +03:00
|
|
|
/** @var bool */
|
|
|
|
protected $registeredCoreProviders = false;
|
|
|
|
|
2015-03-11 18:43:00 +03:00
|
|
|
/** @var array */
|
|
|
|
protected $providers = [];
|
|
|
|
|
2015-03-13 11:39:16 +03:00
|
|
|
/** @var array mime type => support status */
|
|
|
|
protected $mimeTypeSupportMap = [];
|
|
|
|
|
2015-03-12 13:57:56 +03:00
|
|
|
/** @var array */
|
|
|
|
protected $defaultProviders;
|
|
|
|
|
2017-01-04 18:51:44 +03:00
|
|
|
/** @var string */
|
|
|
|
protected $userId;
|
|
|
|
|
2015-03-12 12:48:52 +03:00
|
|
|
/**
|
2016-11-10 16:04:59 +03:00
|
|
|
* PreviewManager constructor.
|
2015-03-12 14:08:31 +03:00
|
|
|
*
|
2016-11-10 16:04:59 +03:00
|
|
|
* @param IConfig $config
|
|
|
|
* @param IRootFolder $rootFolder
|
|
|
|
* @param IAppData $appData
|
|
|
|
* @param EventDispatcherInterface $eventDispatcher
|
2017-01-04 18:51:44 +03:00
|
|
|
* @param string $userId
|
2015-03-12 12:48:52 +03:00
|
|
|
*/
|
2016-10-16 17:48:11 +03:00
|
|
|
public function __construct(IConfig $config,
|
|
|
|
IRootFolder $rootFolder,
|
2016-11-10 16:04:59 +03:00
|
|
|
IAppData $appData,
|
2017-01-04 18:51:44 +03:00
|
|
|
EventDispatcherInterface $eventDispatcher,
|
2019-07-03 13:02:31 +03:00
|
|
|
GeneratorHelper $helper,
|
2017-01-04 18:51:44 +03:00
|
|
|
$userId) {
|
2015-03-12 14:08:31 +03:00
|
|
|
$this->config = $config;
|
2016-10-16 17:48:11 +03:00
|
|
|
$this->rootFolder = $rootFolder;
|
|
|
|
$this->appData = $appData;
|
2016-11-10 16:04:59 +03:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
2019-07-03 13:02:31 +03:00
|
|
|
$this->helper = $helper;
|
2017-01-04 18:51:44 +03:00
|
|
|
$this->userId = $userId;
|
2015-03-12 12:48:52 +03:00
|
|
|
}
|
|
|
|
|
2015-03-11 18:43:00 +03: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 16:25:25 +03:00
|
|
|
* $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2
|
2015-03-11 18:43:00 +03:00
|
|
|
*
|
|
|
|
* @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
|
|
|
|
* @param \Closure $callable
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function registerProvider($mimeTypeRegex, \Closure $callable) {
|
2015-03-12 14:08:31 +03:00
|
|
|
if (!$this->config->getSystemValue('enable_previews', true)) {
|
2015-03-12 12:48:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-11 18:43:00 +03:00
|
|
|
if (!isset($this->providers[$mimeTypeRegex])) {
|
|
|
|
$this->providers[$mimeTypeRegex] = [];
|
|
|
|
}
|
|
|
|
$this->providers[$mimeTypeRegex][] = $callable;
|
2015-03-13 11:55:13 +03:00
|
|
|
$this->providerListDirty = true;
|
2015-03-11 18:43:00 +03:00
|
|
|
}
|
|
|
|
|
2015-03-12 12:48:52 +03:00
|
|
|
/**
|
|
|
|
* Get all providers
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getProviders() {
|
2015-03-13 11:55:13 +03:00
|
|
|
if (!$this->config->getSystemValue('enable_previews', true)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:25:41 +03:00
|
|
|
$this->registerCoreProviders();
|
2015-03-13 11:55:13 +03: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 12:48:52 +03:00
|
|
|
|
|
|
|
return $this->providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the manager have any providers
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasProviders() {
|
2015-03-16 13:25:41 +03:00
|
|
|
$this->registerCoreProviders();
|
2015-03-12 12:48:52 +03:00
|
|
|
return !empty($this->providers);
|
|
|
|
}
|
|
|
|
|
2016-10-16 17:48:11 +03: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 21:42:35 +03:00
|
|
|
* @param string $mimeType
|
2016-10-16 17:48:11 +03:00
|
|
|
* @return ISimpleFile
|
|
|
|
* @throws NotFoundException
|
2017-05-02 00:35:47 +03: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 17:48:11 +03:00
|
|
|
*/
|
2016-10-16 21:42:35 +03:00
|
|
|
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
|
2016-10-16 17:48:11 +03:00
|
|
|
if ($this->generator === null) {
|
|
|
|
$this->generator = new Generator(
|
|
|
|
$this->config,
|
|
|
|
$this,
|
2016-10-17 22:53:23 +03:00
|
|
|
$this->appData,
|
|
|
|
new GeneratorHelper(
|
2018-10-08 15:35:35 +03:00
|
|
|
$this->rootFolder,
|
|
|
|
$this->config
|
2016-11-10 16:04:59 +03:00
|
|
|
),
|
|
|
|
$this->eventDispatcher
|
2016-10-16 17:48:11 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-16 21:42:35 +03:00
|
|
|
return $this->generator->getPreview($file, $width, $height, $crop, $mode, $mimeType);
|
2016-10-16 17:48:11 +03:00
|
|
|
}
|
|
|
|
|
2013-09-05 01:45:11 +04:00
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* returns true if the passed mime type is supported
|
2014-07-30 18:29:18 +04:00
|
|
|
*
|
2013-09-05 01:45:11 +04:00
|
|
|
* @param string $mimeType
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2015-03-12 13:57:56 +03:00
|
|
|
public function isMimeSupported($mimeType = '*') {
|
2015-03-12 14:08:31 +03:00
|
|
|
if (!$this->config->getSystemValue('enable_previews', true)) {
|
2015-03-11 18:43:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-13 11:39:16 +03:00
|
|
|
if (isset($this->mimeTypeSupportMap[$mimeType])) {
|
|
|
|
return $this->mimeTypeSupportMap[$mimeType];
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:25:41 +03:00
|
|
|
$this->registerCoreProviders();
|
2015-03-11 18:43:00 +03:00
|
|
|
$providerMimeTypes = array_keys($this->providers);
|
|
|
|
foreach ($providerMimeTypes as $supportedMimeType) {
|
|
|
|
if (preg_match($supportedMimeType, $mimeType)) {
|
2015-03-13 11:39:16 +03:00
|
|
|
$this->mimeTypeSupportMap[$mimeType] = true;
|
2015-03-11 18:43:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-03-13 11:39:16 +03:00
|
|
|
$this->mimeTypeSupportMap[$mimeType] = false;
|
2015-03-11 18:43:00 +03:00
|
|
|
return false;
|
2013-09-05 01:45:11 +04:00
|
|
|
}
|
2014-07-30 18:29:18 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a preview can be generated for a file
|
|
|
|
*
|
2015-03-11 18:43:00 +03:00
|
|
|
* @param \OCP\Files\FileInfo $file
|
2014-07-30 18:29:18 +04:00
|
|
|
* @return bool
|
|
|
|
*/
|
2015-03-12 13:57:56 +03:00
|
|
|
public function isAvailable(\OCP\Files\FileInfo $file) {
|
2015-03-12 14:08:31 +03:00
|
|
|
if (!$this->config->getSystemValue('enable_previews', true)) {
|
2015-03-11 18:43:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:25:41 +03:00
|
|
|
$this->registerCoreProviders();
|
2015-03-13 11:39:16 +03:00
|
|
|
if (!$this->isMimeSupported($file->getMimetype())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-11 18:43:00 +03:00
|
|
|
$mount = $file->getMountPoint();
|
|
|
|
if ($mount and !$mount->getOption('previews', true)){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->providers as $supportedMimeType => $providers) {
|
|
|
|
if (preg_match($supportedMimeType, $file->getMimetype())) {
|
2019-07-03 13:02:31 +03:00
|
|
|
foreach ($providers as $providerClosure) {
|
|
|
|
$provider = $this->helper->getProvider($providerClosure);
|
|
|
|
if (!($provider instanceof IProviderV2)) {
|
2015-03-12 12:48:52 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-03-12 13:59:45 +03:00
|
|
|
/** @var $provider IProvider */
|
2015-03-11 18:43:00 +03:00
|
|
|
if ($provider->isAvailable($file)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-30 18:29:18 +04:00
|
|
|
}
|
2015-03-12 12:48:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of enabled default providers
|
|
|
|
*
|
|
|
|
* The following providers are enabled by default:
|
2015-04-02 11:31:24 +03:00
|
|
|
* - OC\Preview\PNG
|
|
|
|
* - OC\Preview\JPEG
|
|
|
|
* - OC\Preview\GIF
|
|
|
|
* - OC\Preview\BMP
|
2018-08-03 16:33:58 +03:00
|
|
|
* - OC\Preview\HEIC
|
2015-04-02 11:31:24 +03:00
|
|
|
* - OC\Preview\XBitmap
|
2015-03-13 11:51:42 +03:00
|
|
|
* - OC\Preview\MarkDown
|
2015-03-12 12:48:52 +03:00
|
|
|
* - OC\Preview\MP3
|
|
|
|
* - OC\Preview\TXT
|
|
|
|
*
|
|
|
|
* The following providers are disabled by default due to performance or privacy concerns:
|
2015-03-13 11:51:42 +03:00
|
|
|
* - OC\Preview\Font
|
|
|
|
* - OC\Preview\Illustrator
|
|
|
|
* - OC\Preview\Movie
|
2015-03-12 12:48:52 +03:00
|
|
|
* - OC\Preview\MSOfficeDoc
|
|
|
|
* - OC\Preview\MSOffice2003
|
|
|
|
* - OC\Preview\MSOffice2007
|
|
|
|
* - OC\Preview\OpenDocument
|
2015-03-13 11:51:42 +03:00
|
|
|
* - OC\Preview\PDF
|
|
|
|
* - OC\Preview\Photoshop
|
|
|
|
* - OC\Preview\Postscript
|
2015-03-12 12:48:52 +03: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 11:31:24 +03:00
|
|
|
$imageProviders = [
|
2018-01-26 01:16:13 +03:00
|
|
|
Preview\PNG::class,
|
|
|
|
Preview\JPEG::class,
|
|
|
|
Preview\GIF::class,
|
|
|
|
Preview\BMP::class,
|
2018-08-03 16:33:58 +03:00
|
|
|
Preview\HEIC::class,
|
2020-04-05 12:01:40 +03:00
|
|
|
Preview\XBitmap::class,
|
|
|
|
Preview\Krita::class,
|
2015-04-02 11:31:24 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([
|
2018-01-26 01:16:13 +03:00
|
|
|
Preview\MarkDown::class,
|
|
|
|
Preview\MP3::class,
|
|
|
|
Preview\TXT::class,
|
2020-04-05 12:00:57 +03:00
|
|
|
Preview\OpenDocument::class,
|
2015-04-02 11:31:24 +03:00
|
|
|
], $imageProviders));
|
|
|
|
|
2018-01-26 01:16:13 +03:00
|
|
|
if (in_array(Preview\Image::class, $this->defaultProviders)) {
|
2015-04-02 11:31:24 +03:00
|
|
|
$this->defaultProviders = array_merge($this->defaultProviders, $imageProviders);
|
|
|
|
}
|
|
|
|
$this->defaultProviders = array_unique($this->defaultProviders);
|
2015-03-12 12:48:52 +03:00
|
|
|
return $this->defaultProviders;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the default providers (if enabled)
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @param string $mimeType
|
|
|
|
*/
|
2015-03-12 14:08:31 +03:00
|
|
|
protected function registerCoreProvider($class, $mimeType, $options = []) {
|
2015-03-12 12:48:52 +03:00
|
|
|
if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
|
2015-03-12 14:08:31 +03:00
|
|
|
$this->registerProvider($mimeType, function () use ($class, $options) {
|
|
|
|
return new $class($options);
|
2015-03-12 12:48:52 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the default providers (if enabled)
|
|
|
|
*/
|
|
|
|
protected function registerCoreProviders() {
|
2015-03-16 13:25:41 +03:00
|
|
|
if ($this->registeredCoreProviders) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->registeredCoreProviders = true;
|
|
|
|
|
2018-01-26 01:16:13 +03: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/');
|
2020-04-05 12:01:40 +03:00
|
|
|
$this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/');
|
2018-01-26 01:16:13 +03:00
|
|
|
$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/');
|
2020-04-05 12:00:57 +03:00
|
|
|
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
|
2015-03-12 12:48:52 +03:00
|
|
|
|
|
|
|
// SVG, Office and Bitmap require imagick
|
|
|
|
if (extension_loaded('imagick')) {
|
|
|
|
$checkImagick = new \Imagick();
|
|
|
|
|
|
|
|
$imagickProviders = [
|
2018-01-26 01:16:13 +03: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],
|
2018-08-03 16:33:58 +03:00
|
|
|
'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class],
|
2015-03-12 12:48:52 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($imagickProviders as $queryFormat => $provider) {
|
|
|
|
$class = $provider['class'];
|
|
|
|
if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($checkImagick->queryFormats($queryFormat)) === 1) {
|
|
|
|
$this->registerCoreProvider($class, $provider['mimetype']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($checkImagick->queryFormats('PDF')) === 1) {
|
2016-07-08 16:55:17 +03:00
|
|
|
if (\OC_Helper::is_function_enabled('shell_exec')) {
|
2015-03-12 14:08:31 +03:00
|
|
|
$officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null));
|
2015-03-12 12:48:52 +03:00
|
|
|
|
|
|
|
if (!$officeFound) {
|
|
|
|
//let's see if there is libreoffice or openoffice on this machine
|
|
|
|
$whichLibreOffice = shell_exec('command -v libreoffice');
|
|
|
|
$officeFound = !empty($whichLibreOffice);
|
|
|
|
if (!$officeFound) {
|
|
|
|
$whichOpenOffice = shell_exec('command -v openoffice');
|
|
|
|
$officeFound = !empty($whichOpenOffice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($officeFound) {
|
2018-01-26 01:16:13 +03:00
|
|
|
$this->registerCoreProvider(Preview\MSOfficeDoc::class, '/application\/msword/');
|
|
|
|
$this->registerCoreProvider(Preview\MSOffice2003::class, '/application\/vnd.ms-.*/');
|
|
|
|
$this->registerCoreProvider(Preview\MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/');
|
|
|
|
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
|
|
|
|
$this->registerCoreProvider(Preview\StarOffice::class, '/application\/vnd.sun.xml.*/');
|
2015-03-12 12:48:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:55:17 +03:00
|
|
|
// Video requires avconv or ffmpeg
|
2018-01-26 01:16:13 +03:00
|
|
|
if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) {
|
2015-03-12 12:48:52 +03:00
|
|
|
$avconvBinary = \OC_Helper::findBinaryPath('avconv');
|
2018-01-27 01:46:40 +03:00
|
|
|
$ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg');
|
2015-03-12 12:48:52 +03:00
|
|
|
|
|
|
|
if ($avconvBinary || $ffmpegBinary) {
|
|
|
|
// FIXME // a bit hacky but didn't want to use subclasses
|
|
|
|
\OC\Preview\Movie::$avconvBinary = $avconvBinary;
|
|
|
|
\OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary;
|
|
|
|
|
2018-01-26 01:16:13 +03:00
|
|
|
$this->registerCoreProvider(Preview\Movie::class, '/video\/.*/');
|
2015-03-12 12:48:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-05 01:45:11 +04:00
|
|
|
}
|