aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/lib/helper.php4
-rw-r--r--core/ajax/preview.php3
-rwxr-xr-xlib/private/preview.php30
-rw-r--r--lib/private/preview/provider.php10
-rw-r--r--lib/private/preview/txt.php10
-rwxr-xr-xlib/private/previewmanager.php18
-rw-r--r--lib/public/ipreview.php7
7 files changed, 75 insertions, 7 deletions
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index be0992b1985..50b4e8338a8 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -31,7 +31,7 @@ class Helper
/**
* Determine icon for a given file
*
- * @param \OC\Files\FileInfo $file file info
+ * @param \OCP\Files\FileInfo $file file info
* @return string icon URL
*/
public static function determineIcon($file) {
@@ -111,7 +111,7 @@ class Helper
$entry['mtime'] = $i['mtime'] * 1000;
// only pick out the needed attributes
$entry['icon'] = \OCA\Files\Helper::determineIcon($i);
- if (\OC::$server->getPreviewManager()->isMimeSupported($i['mimetype'])) {
+ if (\OC::$server->getPreviewManager()->isAvailable($i)) {
$entry['isPreviewAvailable'] = true;
}
$entry['name'] = $i->getName();
diff --git a/core/ajax/preview.php b/core/ajax/preview.php
index edbd41d2db4..d2811f39dd6 100644
--- a/core/ajax/preview.php
+++ b/core/ajax/preview.php
@@ -30,7 +30,8 @@ if ($maxX === 0 || $maxY === 0) {
try {
$preview = new \OC\Preview(\OC_User::getUser(), 'files');
- if (!$always and !$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) {
+ $info = \OC\Files\Filesystem::getFileInfo($file);
+ if (!$always and !$preview->isAvailable($info)) {
\OC_Response::setStatus(404);
} else {
$preview->setFile($file);
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);
+ }
}
diff --git a/lib/public/ipreview.php b/lib/public/ipreview.php
index f74472ad368..cc756ef80d3 100644
--- a/lib/public/ipreview.php
+++ b/lib/public/ipreview.php
@@ -57,4 +57,11 @@ interface IPreview
*/
function isMimeSupported($mimeType = '*');
+ /**
+ * Check if a preview can be generated for a file
+ *
+ * @param \OCP\Files\FileInfo $file
+ * @return bool
+ */
+ function isAvailable($file);
}