diff options
Diffstat (limited to 'lib/private')
-rwxr-xr-x | lib/private/preview.php | 30 | ||||
-rw-r--r-- | lib/private/preview/provider.php | 10 | ||||
-rw-r--r-- | lib/private/preview/txt.php | 10 | ||||
-rwxr-xr-x | lib/private/previewmanager.php | 18 |
4 files changed, 64 insertions, 4 deletions
diff --git a/lib/private/preview.php b/lib/private/preview.php index 6172519c7d1..aeb9806904a 100755 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -13,6 +13,7 @@ */ namespace OC; +use OC\Files\Filesystem; use OC\Preview\Provider; require_once 'preview/image.php'; @@ -732,6 +733,35 @@ class Preview { } /** + * Check if a preview can be generated for a file + * + * @param \OC\Files\FileInfo $file + * @return bool + */ + public static function isAvailable($file) { + if (!\OC_Config::getValue('enable_previews', true)) { + return false; + } + + //check if there are preview backends + if (empty(self::$providers)) { + self::initProviders(); + } + + //remove last element because it has the mimetype * + $providers = array_slice(self::$providers, 0, -1); + foreach ($providers as $supportedMimeType => $provider) { + /** + * @var \OC\Preview\Provider $provider + */ + if (preg_match($supportedMimeType, $file->getMimetype())) { + return $provider->isAvailable($file); + } + } + return false; + } + + /** * @param string $mimeType * @return bool */ diff --git a/lib/private/preview/provider.php b/lib/private/preview/provider.php index f769823f6e6..f544c2c4b13 100644 --- a/lib/private/preview/provider.php +++ b/lib/private/preview/provider.php @@ -11,6 +11,16 @@ abstract class Provider { abstract public function getMimeType(); /** + * Check if a preview can be generated for $path + * + * @param string $path + * @return bool + */ + public function isAvailable($path) { + return true; + } + + /** * get thumbnail for file at path $path * @param string $path Path of file * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image diff --git a/lib/private/preview/txt.php b/lib/private/preview/txt.php index 063543c6279..b81436baa06 100644 --- a/lib/private/preview/txt.php +++ b/lib/private/preview/txt.php @@ -14,6 +14,16 @@ class TXT extends Provider { } /** + * Check if a preview can be generated for $path + * + * @param \OC\Files\FileInfo $file + * @return bool + */ + public function isAvailable($file) { + return $file->getSize() > 5; + } + + /** * @param string $path * @param int $maxX * @param int $maxY diff --git a/lib/private/previewmanager.php b/lib/private/previewmanager.php index 23dbee13c7d..85bf609743d 100755 --- a/lib/private/previewmanager.php +++ b/lib/private/previewmanager.php @@ -14,25 +14,35 @@ use OCP\IPreview; class PreviewManager implements IPreview { /** * return a preview of a file + * * @param string $file The path to the file where you want a thumbnail from * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image * @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly * @return \OCP\Image */ - function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false) - { + function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false) { $preview = new \OC\Preview('', '/', $file, $maxX, $maxY, $scaleUp); return $preview->getPreview(); } /** * returns true if the passed mime type is supported + * * @param string $mimeType * @return boolean */ - function isMimeSupported($mimeType = '*') - { + function isMimeSupported($mimeType = '*') { return \OC\Preview::isMimeSupported($mimeType); } + + /** + * Check if a preview can be generated for a file + * + * @param \OC\Files\FileInfo $file + * @return bool + */ + function isAvailable($file) { + return \OC\Preview::isAvailable($file); + } } |