From eeb31420fe2185b4caf2fbf564b5ac6177d348c3 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Nov 2013 18:52:58 +0100 Subject: [PATCH 1/5] we need to be able to set the mimetype manually --- lib/private/preview.php | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/private/preview.php b/lib/private/preview.php index 266f7795f1..7f219850bb 100755 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -9,7 +9,7 @@ * Thumbnails: * structure of filename: * /data/user/thumbnails/pathhash/x-y.png - * + * */ namespace OC; @@ -40,6 +40,7 @@ class Preview { private $maxX; private $maxY; private $scalingup; + private $mimetype; //preview images object /** @@ -59,11 +60,18 @@ class Preview { * @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 bool $scalingUp Disable/Enable upscaling of previews - * @return mixed (bool / string) + * @return mixed (bool / string) * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingUp=true) { + //init fileviews + if($user === ''){ + $user = \OC_User::getUser(); + } + $this->fileView = new \OC\Files\View('/' . $user . '/' . $root); + $this->userView = new \OC\Files\View('/' . $user); + //set config $this->configMaxX = \OC_Config::getValue('preview_max_x', null); $this->configMaxY = \OC_Config::getValue('preview_max_y', null); @@ -75,13 +83,6 @@ class Preview { $this->setMaxY($maxY); $this->setScalingUp($scalingUp); - //init fileviews - if($user === ''){ - $user = \OC_User::getUser(); - } - $this->fileView = new \OC\Files\View('/' . $user . '/' . $root); - $this->userView = new \OC\Files\View('/' . $user); - $this->preview = null; //check if there are preview backends @@ -166,9 +167,16 @@ class Preview { */ public function setFile($file) { $this->file = $file; + if ($file !== '') { + $this->mimetype = $this->fileView->getMimeType($this->file); + } return $this; } + public function setMimetype($mimetype) { + $this->mimetype = $mimetype; + } + /** * @brief set the the max width of the preview * @param int $maxX @@ -265,7 +273,7 @@ class Preview { $fileInfo = $this->fileView->getFileInfo($file); $fileId = $fileInfo['fileid']; - + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; $this->userView->deleteAll($previewPath); $this->userView->rmdir($previewPath); @@ -274,7 +282,7 @@ class Preview { /** * @brief check if thumbnail or bigger version of thumbnail of file is cached - * @return mixed (bool / string) + * @return mixed (bool / string) * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ @@ -386,11 +394,10 @@ class Preview { } if(is_null($this->preview)) { - $mimetype = $this->fileView->getMimeType($file); $preview = null; foreach(self::$providers as $supportedMimetype => $provider) { - if(!preg_match($supportedMimetype, $mimetype)) { + if(!preg_match($supportedMimetype, $this->mimetype)) { continue; } @@ -516,7 +523,7 @@ class Preview { $cropY = 0; $image->crop($cropX, $cropY, $x, $y); - + $this->preview = $image; return; } @@ -598,7 +605,7 @@ class Preview { public static function post_write($args) { self::post_delete($args); } - + public static function post_delete($args) { $path = $args['path']; if(substr($path, 0, 1) === '/') { From 863aedf784d582a458c8befd709795f2595e3ba6 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Nov 2013 18:59:12 +0100 Subject: [PATCH 2/5] detect mimetype from the original filename, without the delete timestamp --- apps/files_trashbin/ajax/preview.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/ajax/preview.php b/apps/files_trashbin/ajax/preview.php index a0846b051c..945466705c 100644 --- a/apps/files_trashbin/ajax/preview.php +++ b/apps/files_trashbin/ajax/preview.php @@ -29,8 +29,15 @@ if($maxX === 0 || $maxY === 0) { } try{ - $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files'); - $preview->setFile($file); + $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files', $file); + $view = new \OC\Files\View('/'.\OC_User::getUser(). '/files_trashbin/files'); + if ($view->is_dir($file)) { + $mimetype = 'httpd/unix-directory'; + } else { + $mimetype = \OC_Helper::getFileNameMimeType(pathinfo($file, PATHINFO_FILENAME)); + } + $preview->setMimetype($mimetype); + $preview->setMimetype($mimetype); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); From bef510821880df95eefc9b908997d5fdca8d1cbc Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Nov 2013 18:59:38 +0100 Subject: [PATCH 3/5] detect mimetype from the original filename, without the versioning timestamp --- apps/files_versions/ajax/preview.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/files_versions/ajax/preview.php b/apps/files_versions/ajax/preview.php index 62bcc03f52..31525028ef 100644 --- a/apps/files_versions/ajax/preview.php +++ b/apps/files_versions/ajax/preview.php @@ -37,8 +37,9 @@ if($maxX === 0 || $maxY === 0) { } try{ - $preview = new \OC\Preview($user, 'files_versions'); - $preview->setFile($file.'.v'.$version); + $preview = new \OC\Preview($user, 'files_versions', $file.'.v'.$version); + $mimetype = \OC_Helper::getFileNameMimeType($file); + $preview->setMimetype($mimetype); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); From bdfef554c44e7af190122a035535c900d5513d32 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Nov 2013 19:05:43 +0100 Subject: [PATCH 4/5] add PHPDoc for setMimetype() --- lib/private/preview.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/private/preview.php b/lib/private/preview.php index 7f219850bb..ff93f438f7 100755 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -173,6 +173,10 @@ class Preview { return $this; } + /** + * @brief set mimetype explicitely + * @param string $mimetype + */ public function setMimetype($mimetype) { $this->mimetype = $mimetype; } From b3724cd9c699522c8ec3c6754670b505d3481736 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Nov 2013 20:58:32 +0100 Subject: [PATCH 5/5] remove duplicate --- apps/files_trashbin/ajax/preview.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/files_trashbin/ajax/preview.php b/apps/files_trashbin/ajax/preview.php index 945466705c..ce432f4d14 100644 --- a/apps/files_trashbin/ajax/preview.php +++ b/apps/files_trashbin/ajax/preview.php @@ -37,7 +37,6 @@ try{ $mimetype = \OC_Helper::getFileNameMimeType(pathinfo($file, PATHINFO_FILENAME)); } $preview->setMimetype($mimetype); - $preview->setMimetype($mimetype); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp);