summaryrefslogtreecommitdiffstats
path: root/lib/private/preview.php
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-04-02 17:59:39 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-04-02 18:00:21 +0200
commit436a78db448d4263f90de0490202b8d7a936d3a2 (patch)
tree3a0624a328347cae64551bbb779dc32d509fa2b4 /lib/private/preview.php
parentbca6cc6f741ae957a345ca21d689a5f23d964d9a (diff)
downloadnextcloud-server-436a78db448d4263f90de0490202b8d7a936d3a2.tar.gz
nextcloud-server-436a78db448d4263f90de0490202b8d7a936d3a2.zip
extract method isCachedBigger
Diffstat (limited to 'lib/private/preview.php')
-rwxr-xr-xlib/private/preview.php47
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/private/preview.php b/lib/private/preview.php
index 493ed90f770..7be392a50d9 100755
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -314,16 +314,12 @@ class Preview {
/**
* @brief check if thumbnail or bigger version of thumbnail of file is cached
- * @return mixed (bool / string)
- * false if thumbnail does not exist
- * path to thumbnail if thumbnail exists
+ * @return string|false path to thumbnail if it exists or false
*/
private function isCached() {
$file = $this->getFile();
$maxX = $this->getMaxX();
$maxY = $this->getMaxY();
- $scalingUp = $this->getScalingUp();
- $maxScaleFactor = $this->getMaxScaleFactor();
$fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo->getId();
@@ -333,16 +329,40 @@ class Preview {
}
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
- if (!$this->userView->is_dir($previewPath)) {
- return false;
- }
//does a preview with the wanted height and width already exist?
if ($this->userView->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) {
return $previewPath . $maxX . '-' . $maxY . '.png';
}
- $wantedAspectRatio = (float)($maxX / $maxY);
+ return $this->isCachedBigger();
+ }
+
+ /**
+ * @brief check if a bigger version of thumbnail of file is cached
+ * @return string|false path to bigger thumbnail if it exists or false
+ */
+ private function isCachedBigger() {
+
+ $file = $this->getFile();
+ $maxX = $this->getMaxX();
+ $maxY = $this->getMaxY();
+ $scalingUp = $this->getScalingUp();
+ $maxScaleFactor = $this->getMaxScaleFactor();
+
+ $fileInfo = $this->fileView->getFileInfo($file);
+ $fileId = $fileInfo['fileid'];
+
+ if (is_null($fileId)) {
+ return false;
+ }
+
+ $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
+ if (!$this->userView->is_dir($previewPath)) {
+ return false;
+ }
+
+ $wantedAspectRatio = (float) ($maxX / $maxY);
//array for usable cached thumbnails
$possibleThumbnails = array();
@@ -351,10 +371,10 @@ class Preview {
foreach ($allThumbnails as $thumbnail) {
$name = rtrim($thumbnail['name'], '.png');
$size = explode('-', $name);
- $x = (int)$size[0];
- $y = (int)$size[1];
+ $x = (int) $size[0];
+ $y = (int) $size[1];
- $aspectRatio = (float)($x / $y);
+ $aspectRatio = (float) ($x / $y);
$epsilon = 0.000001;
if (($aspectRatio - $wantedAspectRatio) >= $epsilon) {
continue;
@@ -382,10 +402,9 @@ class Preview {
return $path;
}
}
-
+
return false;
}
-
/**
* @brief return a preview of a file
* @return \OC_Image