2013-09-04 17:45:11 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2013-09-04 17:45:11 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-09-04 17:45:11 -04:00
|
|
|
*/
|
2013-11-03 07:38:25 -05:00
|
|
|
// use OCP namespace for all classes that are considered public.
|
2024-05-23 03:26:56 -04:00
|
|
|
// This means that they should be used by apps instead of the internal Nextcloud classes
|
2019-11-22 14:52:10 -05:00
|
|
|
|
2013-09-04 17:45:11 -04:00
|
|
|
namespace OCP;
|
|
|
|
|
|
2016-10-16 10:48:11 -04:00
|
|
|
use OCP\Files\File;
|
|
|
|
|
use OCP\Files\NotFoundException;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
2016-10-16 10:48:11 -04:00
|
|
|
|
2013-09-04 17:45:11 -04:00
|
|
|
/**
|
|
|
|
|
* This class provides functions to render and show thumbnails and previews of files
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 6.0.0
|
2013-09-04 17:45:11 -04:00
|
|
|
*/
|
2015-03-11 11:43:00 -04:00
|
|
|
interface IPreview {
|
2024-02-14 14:48:27 -05:00
|
|
|
/**
|
|
|
|
|
* @since 11.0.0
|
|
|
|
|
*/
|
2020-04-10 10:54:27 -04:00
|
|
|
public const MODE_FILL = 'fill';
|
2024-02-14 14:48:27 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 11.0.0
|
|
|
|
|
*/
|
2020-04-10 10:54:27 -04:00
|
|
|
public const MODE_COVER = 'cover';
|
2016-10-16 10:48:11 -04:00
|
|
|
|
2015-03-11 11:43:00 -04:00
|
|
|
/**
|
|
|
|
|
* In order to improve lazy loading a closure can be registered which will be
|
|
|
|
|
* called in case preview providers are actually requested
|
|
|
|
|
*
|
2015-03-12 07:20:39 -04:00
|
|
|
* $callable has to return an instance of \OCP\Preview\IProvider
|
2015-03-11 11:43:00 -04:00
|
|
|
*
|
|
|
|
|
* @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
|
|
|
|
|
* @param \Closure $callable
|
|
|
|
|
* @return void
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 8.1.0
|
2020-10-04 08:41:08 -04:00
|
|
|
* @see \OCP\AppFramework\Bootstrap\IRegistrationContext::registerPreviewProvider
|
|
|
|
|
*
|
|
|
|
|
* @deprecated 23.0.0 Register your provider via the IRegistrationContext when booting the app
|
2015-03-11 11:43:00 -04:00
|
|
|
*/
|
|
|
|
|
public function registerProvider($mimeTypeRegex, \Closure $callable);
|
2013-09-04 17:45:11 -04:00
|
|
|
|
2015-03-12 05:48:52 -04:00
|
|
|
/**
|
|
|
|
|
* Get all providers
|
|
|
|
|
* @return array
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 8.1.0
|
2015-03-12 05:48:52 -04:00
|
|
|
*/
|
|
|
|
|
public function getProviders();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Does the manager have any providers
|
|
|
|
|
* @return bool
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 8.1.0
|
2015-03-12 05:48:52 -04:00
|
|
|
*/
|
|
|
|
|
public function hasProviders();
|
|
|
|
|
|
2016-10-16 10:48:11 -04: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 14:42:35 -04:00
|
|
|
* @param string $mimeType To force a given mimetype for the file (files_versions needs this)
|
2025-04-22 10:40:02 -04:00
|
|
|
* @param bool $cacheResult Whether or not to cache the preview on the filesystem. Default to true. Can be useful to set to false to limit the amount of stored previews.
|
2016-10-16 10:48:11 -04:00
|
|
|
* @return ISimpleFile
|
|
|
|
|
* @throws NotFoundException
|
2017-05-01 17:35:47 -04: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
|
2025-04-22 10:40:02 -04:00
|
|
|
* @since 32.0.0 - getPreview($cacheResult) added the $cacheResult argument to the signature
|
2016-10-16 10:48:11 -04:00
|
|
|
*/
|
2025-04-22 10:40:02 -04:00
|
|
|
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null, bool $cacheResult = true);
|
2013-09-04 17:45:11 -04:00
|
|
|
|
|
|
|
|
/**
|
2013-10-31 14:00:53 -04:00
|
|
|
* Returns true if the passed mime type is supported
|
2013-09-04 17:45:11 -04:00
|
|
|
* @param string $mimeType
|
|
|
|
|
* @return boolean
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 6.0.0
|
2013-09-04 17:45:11 -04:00
|
|
|
*/
|
2015-03-12 06:57:56 -04:00
|
|
|
public function isMimeSupported($mimeType = '*');
|
2013-09-04 17:45:11 -04:00
|
|
|
|
2014-07-30 10:29:18 -04:00
|
|
|
/**
|
|
|
|
|
* Check if a preview can be generated for a file
|
|
|
|
|
*
|
|
|
|
|
* @param \OCP\Files\FileInfo $file
|
2025-05-30 07:19:34 -04:00
|
|
|
* @param string|null $mimeType To force a given mimetype for the file
|
2014-07-30 10:29:18 -04:00
|
|
|
* @return bool
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 8.0.0
|
2025-05-30 07:19:34 -04:00
|
|
|
* @since 32.0.0 - isAvailable($mimeType) added the $mimeType argument to the signature
|
2014-07-30 10:29:18 -04:00
|
|
|
*/
|
2025-05-30 07:19:34 -04:00
|
|
|
public function isAvailable(\OCP\Files\FileInfo $file, ?string $mimeType = null);
|
2020-02-15 19:45:47 -05: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);
|
2013-09-04 17:45:11 -04:00
|
|
|
}
|