]> source.dussan.org Git - nextcloud-server.git/commitdiff
OC\Preview - proper handling of a cached previews's filename
authorGeorg Ehrke <developer@georgehrke.com>
Fri, 12 Jul 2013 09:50:24 +0000 (11:50 +0200)
committerGeorg Ehrke <developer@georgehrke.com>
Fri, 12 Jul 2013 09:50:24 +0000 (11:50 +0200)
lib/preview.php

index 5576981225b52d25acf17f2831ab84fc9f717baf..08c0b7e20d070103a54d33fe3a46860ffb6a0a13 100755 (executable)
@@ -283,6 +283,10 @@ class Preview {
                $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;
@@ -293,18 +297,19 @@ class Preview {
                        return $previewpath . $maxX . '-' . $maxY . '.png';
                }
 
-               $wantedaspectratio = $maxX / $maxY;
+               $wantedaspectratio = (float) ($maxX / $maxY);
 
                //array for usable cached thumbnails
                $possiblethumbnails = array();
 
                $allthumbnails = $this->userview->getDirectoryContent($previewpath);
                foreach($allthumbnails as $thumbnail) {
-                       $size = explode('-', $thumbnail['name']);
-                       $x = $size[0];
-                       $y = $size[1];
+                       $name = rtrim($thumbnail['name'], '.png');
+                       $size = explode('-', $name);
+                       $x = (int) $size[0];
+                       $y = (int) $size[1];
 
-                       $aspectratio = $x / $y;
+                       $aspectratio = (float) ($x / $y);
                        if($aspectratio !== $wantedaspectratio) {
                                continue;
                        }