From 5b44714f4cbd75138519789f55fd8b6f4b5d4241 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Tue, 13 Nov 2012 15:11:02 +0100 Subject: [PATCH 0001/1989] =?UTF-8?q?first=20version=20of=20the=20new=20pr?= =?UTF-8?q?eviewer=20lib.=20It=20currently=20only=20created=20previews/thu?= =?UTF-8?q?mbnails=20for=20images.=20It=20get=C2=B4s=20more=20interesting?= =?UTF-8?q?=20when=20we=20add=20PDFs,=20movies,=20mp3,=20text=20files=20an?= =?UTF-8?q?d=20more...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/preview.php | 131 +++++++++++++++++++++++++++++++++++++++++ lib/public/preview.php | 50 ++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100755 lib/preview.php create mode 100644 lib/public/preview.php diff --git a/lib/preview.php b/lib/preview.php new file mode 100755 index 0000000000..8b1a42925a --- /dev/null +++ b/lib/preview.php @@ -0,0 +1,131 @@ +show(); + }else{ + header('Content-type: image/png'); + OC_PreviewUnknown::getThumbnail($maxX,$maxY); + } + } + + +} + + + +class OC_PreviewImage { + + // the thumbnail cache folder + const THUMBNAILS_FOLDER = 'thumbnails'; + + public static function getThumbnail($path,$maxX,$maxY,$scalingup) { + $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.self::THUMBNAILS_FOLDER); + + // is a preview already in the cache? + if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { + return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); + } + + // does the sourcefile exist? + if (!\OC_Filesystem::file_exists($path)) { + \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); + return false; + } + + // open the source image + $image = new \OC_Image(); + $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); + if (!$image->valid()) return false; + + // fix the orientation + $image->fixOrientation(); + + // calculate the right preview size + $Xsize=$image->width(); + $Ysize=$image->height(); + if (($Xsize/$Ysize)>($maxX/$maxY)) { + $factor=$maxX/$Xsize; + } else { + $factor=$maxY/$Ysize; + } + + // only scale up if requested + if($scalingup==false) { + if($factor>1) $factor=1; + } + $newXsize=$Xsize*$factor; + $newYsize=$Ysize*$factor; + + // resize + $ret = $image->preciseResize($newXsize, $newYsize); + if (!$ret) { + \OC_Log::write('Preview', 'Couldn\'t resize image', \OC_Log::ERROR); + unset($image); + return false; + } + + // store in cache + $l = $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); + $image->save($l); + + return $image; + } + + + +} + + +class OC_PreviewUnknown { + public static function getThumbnail($maxX,$maxY) { + + // check if GD is installed + if(!extension_loaded('gd') || !function_exists('gd_info')) { + OC_Log::write('preview', __METHOD__.'(): GD module not installed', OC_Log::ERROR); + return false; + } + + // create a white image + $image = imagecreatetruecolor($maxX, $maxY); + $color = imagecolorallocate($image, 255, 255, 255); + imagefill($image, 0, 0, $color); + + // output the image + imagepng($image); + imagedestroy($image); + } + +} + diff --git a/lib/public/preview.php b/lib/public/preview.php new file mode 100644 index 0000000000..a7487c485f --- /dev/null +++ b/lib/public/preview.php @@ -0,0 +1,50 @@ +. +* +*/ + +/** + * Public interface of ownCloud for apps to use. + * Preview Class. + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP; + +/** + * This class provides functions to render and show thumbnails and previews of files + */ +class Preview { + + /** + * @brief return a preview of a file + * @param $file The path to the file where you want a thumbnail from + * @param $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image + * @param $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image + * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly + * @return image + */ + public static function show($file,$maxX=100,$maxY=75,$scaleup=false) { + return(\OC_Preview::show($file,$maxX,$maxY,$scaleup)); + } + +} From e484811e24f6332df49eb35c7e2adffca81d2005 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Tue, 13 Nov 2012 16:14:16 +0100 Subject: [PATCH 0002/1989] add some documentation, remove a debug hack, move folder name definition to main class --- lib/preview.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 8b1a42925a..3fa494a2e0 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -19,21 +19,28 @@ TODO: class OC_Preview { - + + // the thumbnail cache folder + const THUMBNAILS_FOLDER = 'thumbnails'; /** * @brief return a preview of a file * @param $file The path to the file where you want a thumbnail from * @param $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image * @param $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image + * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly * @return image */ - static public function show($file,$maxX,$maxY) { + static public function show($file,$maxX,$maxY,$scalingup) { + // get the mimetype of the file $mimetype=explode('/',OC_FileSystem::getMimeType($file)); - if($mimetype[0]=='imaage'){ + + // it´s an image + if($mimetype[0]=='image'){ OCP\Response::enableCaching(3600 * 24); // 24 hour - $image=OC_PreviewImage::getThumbnail($file,$maxX,$maxY,false); + $image=OC_PreviewImage::getThumbnail($file,$maxX,$maxY,$scalingup); $image->show(); + // it´s something else. Let´s create a dummy preview }else{ header('Content-type: image/png'); OC_PreviewUnknown::getThumbnail($maxX,$maxY); @@ -47,11 +54,8 @@ class OC_Preview { class OC_PreviewImage { - // the thumbnail cache folder - const THUMBNAILS_FOLDER = 'thumbnails'; - public static function getThumbnail($path,$maxX,$maxY,$scalingup) { - $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.self::THUMBNAILS_FOLDER); + $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); // is a preview already in the cache? if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { From eb27c0b2a84da44f8e42f7e4aca0102c969eb195 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 14 Jan 2013 15:51:47 +0100 Subject: [PATCH 0003/1989] snapshor of the preview lib. movies are not yet working --- lib/preview.php | 94 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 26 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 3fa494a2e0..d49e9d3bde 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -9,6 +9,7 @@ /* TODO: - delete thumbnails if files change. + - make it work with external filesystem files. - movies support - pdf support - mp3/id3 support @@ -34,12 +35,17 @@ class OC_Preview { static public function show($file,$maxX,$maxY,$scalingup) { // get the mimetype of the file $mimetype=explode('/',OC_FileSystem::getMimeType($file)); - // it´s an image if($mimetype[0]=='image'){ OCP\Response::enableCaching(3600 * 24); // 24 hour $image=OC_PreviewImage::getThumbnail($file,$maxX,$maxY,$scalingup); $image->show(); + + // it´s a video + }elseif($mimetype[0]=='video'){ + OCP\Response::enableCaching(3600 * 24); // 24 hour + OC_PreviewMovie::getThumbnail($file,$maxX,$maxY,$scalingup); + // it´s something else. Let´s create a dummy preview }else{ header('Content-type: image/png'); @@ -55,56 +61,59 @@ class OC_Preview { class OC_PreviewImage { public static function getThumbnail($path,$maxX,$maxY,$scalingup) { - $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); - // is a preview already in the cache? + $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); + + // is a preview already in the cache? if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); } - - // does the sourcefile exist? + + // does the sourcefile exist? if (!\OC_Filesystem::file_exists($path)) { \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); return false; } - // open the source image + // open the source image $image = new \OC_Image(); $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); if (!$image->valid()) return false; - // fix the orientation + // fix the orientation $image->fixOrientation(); - - // calculate the right preview size - $Xsize=$image->width(); - $Ysize=$image->height(); - if (($Xsize/$Ysize)>($maxX/$maxY)) { - $factor=$maxX/$Xsize; - } else { - $factor=$maxY/$Ysize; - } - - // only scale up if requested - if($scalingup==false) { - if($factor>1) $factor=1; - } - $newXsize=$Xsize*$factor; - $newYsize=$Ysize*$factor; - // resize + // calculate the right preview size + $Xsize=$image->width(); + $Ysize=$image->height(); + if (($Xsize/$Ysize)>($maxX/$maxY)) { + $factor=$maxX/$Xsize; + } else { + $factor=$maxY/$Ysize; + } + + // only scale up if requested + if($scalingup==false) { + if($factor>1) $factor=1; + } + $newXsize=$Xsize*$factor; + $newYsize=$Ysize*$factor; + + // resize $ret = $image->preciseResize($newXsize, $newYsize); if (!$ret) { \OC_Log::write('Preview', 'Couldn\'t resize image', \OC_Log::ERROR); unset($image); return false; } - - // store in cache + + // store in cache $l = $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); $image->save($l); return $image; + + } @@ -112,6 +121,39 @@ class OC_PreviewImage { } +class OC_PreviewMovie { + + public static function isAvailable() { + $check=shell_exec('ffmpeg'); + if($check==NULL) return(false); else return(true); + } + + public static function getThumbnail($path,$maxX,$maxY,$scalingup) { + $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); + + // is a preview already in the cache? + if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { + return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); + } + + // does the sourcefile exist? + if (!\OC_Filesystem::file_exists($path)) { + \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); + return false; + } + + // call ffmpeg to do the screenshot + shell_exec('ffmpeg -y -i {'.escapeshellarg($path).'} -f mjpeg -vframes 1 -ss 1 -s {'.escapeshellarg($maxX).'}x{'.escapeshellarg($maxY).'} {.'.$thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup).'}'); + + // output the generated Preview + $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); + unset($thumbnails_view); + } + + +} + + class OC_PreviewUnknown { public static function getThumbnail($maxX,$maxY) { From 9ef449842a369c2517f5c34932b502b754393ce0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 25 Apr 2013 11:18:45 +0200 Subject: [PATCH 0004/1989] save current work state of Preview Lib --- lib/preview.php | 384 +++++++++++++++++++++++++++++------------------- 1 file changed, 232 insertions(+), 152 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index d49e9d3bde..c704763321 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -1,28 +1,139 @@ getFileInfo($file); + $fileid = self::$fileinfo['fileid']; + + //echo self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid; + if(!self::$fileview->is_dir(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid)){ + return false; + } + + //does a preview with the wanted height and width already exist? + if(self::$fileview->file_exists(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png')){ + return self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png'; + } + + $wantedaspectratio = $maxX / $maxY; + + //array for usable cached thumbnails + $possiblethumbnails = array(); + + $allthumbnails = self::$fileview->getDirectoryContent(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid); + foreach($allthumbnails as $thumbnail){ + $size = explode('-', $thumbnail['name']); + $x = $size[0]; + $y = $size[1]; + + $aspectratio = $x / $y; + if($aspectratio != $wantedaspectratio){ + continue; + } + + if($x < $maxX || $y < $maxY){ + if($scalingup){ + $scalefactor = $maxX / $x; + if($scalefactor > self::MAX_SCALE_FACTOR){ + continue; + } + }else{ + continue; + } + } + + $possiblethumbnails[$x] = $thumbnail['path']; + } + + if(count($possiblethumbnails) === 0){ + return false; + } + + if(count($possiblethumbnails) === 1){ + return current($possiblethumbnails); + } + + ksort($possiblethumbnails); + + if(key(reset($possiblethumbnails)) > $maxX){ + return current(reset($possiblethumbnails)); + } + + if(key(end($possiblethumbnails)) < $maxX){ + return current(end($possiblethumbnails)); + } + + foreach($possiblethumbnails as $width => $path){ + if($width < $maxX){ + continue; + }else{ + return $path; + } + } + } + + /** + * @brief delete a preview with a specfic height and width + * @param $file path to the file + * @param $x width of preview + * @param $y height of preview + * @return image + */ + public static function deletePreview($file, $x, $y){ + self::init(); + + $fileinfo = self::$fileview->getFileInfo($file); + $fileid = self::$fileinfo['fileid']; + + return self::$fileview->unlink(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png'); + } + + /** + * @brief deletes all previews of a file + * @param $file path of file + * @return bool + */ + public static function deleteAllPrevies($file){ + self::init(); + + $fileinfo = self::$fileview->getFileInfo($file); + $fileid = self::$fileinfo['fileid']; + + return self::$fielview->rmdir(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid); + } /** * @brief return a preview of a file @@ -32,146 +143,115 @@ class OC_Preview { * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly * @return image */ - static public function show($file,$maxX,$maxY,$scalingup) { - // get the mimetype of the file - $mimetype=explode('/',OC_FileSystem::getMimeType($file)); - // it´s an image - if($mimetype[0]=='image'){ - OCP\Response::enableCaching(3600 * 24); // 24 hour - $image=OC_PreviewImage::getThumbnail($file,$maxX,$maxY,$scalingup); - $image->show(); + public static function getPreview($file, $maxX, $maxY, $scalingup){ + self::init(); + + $cached = self::isCached($file, $maxX, $maxY); + if($cached){ + $image = new \OC_Image($cached); + if($image->width() != $maxX && $image->height != $maxY){ + $image->preciseResize($maxX, $maxY); + } + return $image; + } + + $mimetype = self::$fileview->getMimeType($file); + + $preview; + + foreach(self::$providers as $supportedmimetype => $provider){ + if(!preg_match($supportedmimetype, $mimetype)){ + continue; + } + + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup); + + if(!$preview){ + continue; + } + + if(!($preview instanceof \OC_Image)){ + $preview = @new \OC_Image($preview); + } + + //cache thumbnail + $preview->save(self::$filesview->getAbsolutePath(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png')); + + break; + } + + return $preview; + } - // it´s a video - }elseif($mimetype[0]=='video'){ - OCP\Response::enableCaching(3600 * 24); // 24 hour - OC_PreviewMovie::getThumbnail($file,$maxX,$maxY,$scalingup); - - // it´s something else. Let´s create a dummy preview - }else{ - header('Content-type: image/png'); - OC_PreviewUnknown::getThumbnail($maxX,$maxY); + /** + * @brief return a preview of a file + * @param $file The path to the file where you want a thumbnail from + * @param $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image + * @param $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image + * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly + * @return image + */ + public static function showPreview($file, $maxX, $maxY, $scalingup = true, $fontsize = 12){ + OCP\Response::enableCaching(3600 * 24); // 24 hour + $preview = self::getPreview($file, $maxX, $maxY, $scalingup, $fontsize); + $preview->show(); + } + + /** + * @brief check whether or not providers and views are initialized and initialize if not + * @return void + */ + private static function init(){ + if(empty(self::$providers)){ + self::initProviders(); + } + if(is_null(self::$thumbnailsview) || is_null(self::$userlandview)){ + self::initViews(); } } + /** + * @brief register a new preview provider to be used + * @param string $provider class name of a OC_Preview_Provider + * @return void + */ + public static function registerProvider($class, $options=array()){ + self::$registeredProviders[]=array('class'=>$class, 'options'=>$options); + } -} - - - -class OC_PreviewImage { - - public static function getThumbnail($path,$maxX,$maxY,$scalingup) { - - $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); - - // is a preview already in the cache? - if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { - return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); - } - - // does the sourcefile exist? - if (!\OC_Filesystem::file_exists($path)) { - \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); - return false; - } - - // open the source image - $image = new \OC_Image(); - $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); - if (!$image->valid()) return false; - - // fix the orientation - $image->fixOrientation(); - - // calculate the right preview size - $Xsize=$image->width(); - $Ysize=$image->height(); - if (($Xsize/$Ysize)>($maxX/$maxY)) { - $factor=$maxX/$Xsize; - } else { - $factor=$maxY/$Ysize; - } - - // only scale up if requested - if($scalingup==false) { - if($factor>1) $factor=1; - } - $newXsize=$Xsize*$factor; - $newYsize=$Ysize*$factor; - - // resize - $ret = $image->preciseResize($newXsize, $newYsize); - if (!$ret) { - \OC_Log::write('Preview', 'Couldn\'t resize image', \OC_Log::ERROR); - unset($image); - return false; - } - - // store in cache - $l = $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); - $image->save($l); - - return $image; - - - } - - - -} - - -class OC_PreviewMovie { - - public static function isAvailable() { - $check=shell_exec('ffmpeg'); - if($check==NULL) return(false); else return(true); - } - - public static function getThumbnail($path,$maxX,$maxY,$scalingup) { - $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); - - // is a preview already in the cache? - if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { - return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); - } - - // does the sourcefile exist? - if (!\OC_Filesystem::file_exists($path)) { - \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); - return false; - } - - // call ffmpeg to do the screenshot - shell_exec('ffmpeg -y -i {'.escapeshellarg($path).'} -f mjpeg -vframes 1 -ss 1 -s {'.escapeshellarg($maxX).'}x{'.escapeshellarg($maxY).'} {.'.$thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup).'}'); - - // output the generated Preview - $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); - unset($thumbnails_view); - } - - -} - - -class OC_PreviewUnknown { - public static function getThumbnail($maxX,$maxY) { - - // check if GD is installed - if(!extension_loaded('gd') || !function_exists('gd_info')) { - OC_Log::write('preview', __METHOD__.'(): GD module not installed', OC_Log::ERROR); - return false; + /** + * @brief create instances of all the registered preview providers + * @return void + */ + private static function initProviders(){ + if(count(self::$providers)>0) { + return; } - - // create a white image - $image = imagecreatetruecolor($maxX, $maxY); - $color = imagecolorallocate($image, 255, 255, 255); - imagefill($image, 0, 0, $color); - - // output the image - imagepng($image); - imagedestroy($image); - } - -} - + + foreach(self::$registeredProviders as $provider) { + $class=$provider['class']; + $options=$provider['options']; + + $object = new $class($options); + + self::$providers[$object->getMimeType()] = $object; + } + + $keys = array_map('strlen', array_keys(self::$providers)); + array_multisort($keys, SORT_DESC, self::$providers); + } + + /** + * @brief initialize a new \OC\Files\View object + * @return void + */ + private static function initViews(){ + if(is_null(self::$fileview)){ + self::$fileview = new OC\Files\View(); + } + } + + public static function previewRouter($params){ + var_dump($params); + } +} \ No newline at end of file From f02aca3f6ee295485d5bb9bc99b85b5573716f17 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 25 Apr 2013 11:42:40 +0200 Subject: [PATCH 0005/1989] add route for previews --- core/routes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/routes.php b/core/routes.php index be19b66bf7..be5766cea9 100644 --- a/core/routes.php +++ b/core/routes.php @@ -42,7 +42,8 @@ $this->create('js_config', '/core/js/config.js') // Routing $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); - +$this->create('core_ajax_preview', '/core/preview.png') + ->action('OC_Preview', 'previewRouter'); OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; $this->create('core_lostpassword_index', '/lostpassword/') ->get() From 8c1925425b26d9b2889632c724ec455ceeed4dd4 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 25 Apr 2013 12:51:44 +0200 Subject: [PATCH 0006/1989] save current work state --- lib/preview.php | 32 ++++++++++++++++-- lib/preview/images.php | 71 ++++++++++++++++++++++++++++++++++++++++ lib/preview/movies.php | 42 ++++++++++++++++++++++++ lib/preview/mp3.php | 1 + lib/preview/pdf.php | 0 lib/preview/provider.php | 20 +++++++++++ lib/preview/unknown.php | 34 +++++++++++++++++++ 7 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 lib/preview/images.php create mode 100644 lib/preview/movies.php create mode 100644 lib/preview/mp3.php create mode 100644 lib/preview/pdf.php create mode 100644 lib/preview/provider.php create mode 100644 lib/preview/unknown.php diff --git a/lib/preview.php b/lib/preview.php index c704763321..de79b42407 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -205,7 +205,7 @@ class OC_Preview { if(empty(self::$providers)){ self::initProviders(); } - if(is_null(self::$thumbnailsview) || is_null(self::$userlandview)){ + if(is_null(self::$fileview)){ self::initViews(); } } @@ -247,11 +247,37 @@ class OC_Preview { */ private static function initViews(){ if(is_null(self::$fileview)){ - self::$fileview = new OC\Files\View(); + //does this work with LDAP? + self::$fileview = new OC\Files\View(OC_User::getUser()); } } public static function previewRouter($params){ - var_dump($params); + self::init(); + + $file = (string) urldecode($_GET['file']); + $maxX = (int) $_GET['x']; + $maxY = (int) $_GET['y']; + $scalingup = (bool) $_GET['scalingup']; + + $path = 'files/' . $file; + + if($maxX === 0 || $maxY === 0){ + OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::DEBUG); + exit; + } + + var_dump(self::$fileview->file_exists($path)); + var_dump(self::$fileview->getDirectoryContent()); + var_dump(self::$fileview->getDirectoryContent('files/')); + var_dump($path); + var_dump(self::$fileview->filesize($path)); + var_dump(self::$fileview->getAbsolutePath('/')); + + if(!self::$fileview->filesize($path)){ + OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); + } + + self::showPreview($file, $maxX, $maxY, $scalingup); } } \ No newline at end of file diff --git a/lib/preview/images.php b/lib/preview/images.php new file mode 100644 index 0000000000..6b6e8e3599 --- /dev/null +++ b/lib/preview/images.php @@ -0,0 +1,71 @@ +file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { + return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); + } + + // does the sourcefile exist? + if (!\OC_Filesystem::file_exists($path)) { + \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); + return false; + } + + // open the source image + $image = new \OC_Image(); + $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); + if (!$image->valid()) return false; + + // fix the orientation + $image->fixOrientation(); + + // calculate the right preview size + $Xsize=$image->width(); + $Ysize=$image->height(); + if (($Xsize/$Ysize)>($maxX/$maxY)) { + $factor=$maxX/$Xsize; + } else { + $factor=$maxY/$Ysize; + } + + // only scale up if requested + if($scalingup==false) { + if($factor>1) $factor=1; + } + $newXsize=$Xsize*$factor; + $newYsize=$Ysize*$factor; + + // resize + $ret = $image->preciseResize($newXsize, $newYsize); + if (!$ret) { + \OC_Log::write('Preview', 'Couldn\'t resize image', \OC_Log::ERROR); + unset($image); + return false; + } + + // store in cache + $l = $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); + $image->save($l); + + return $image; + } + +} + +OC_Preview::registerProvider('OC_Preview_Image'); \ No newline at end of file diff --git a/lib/preview/movies.php b/lib/preview/movies.php new file mode 100644 index 0000000000..afa27c0b14 --- /dev/null +++ b/lib/preview/movies.php @@ -0,0 +1,42 @@ +file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { + return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); + } + + // does the sourcefile exist? + if (!\OC_Filesystem::file_exists($path)) { + \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); + return false; + } + + // call ffmpeg to do the screenshot + shell_exec('ffmpeg -y -i {'.escapeshellarg($path).'} -f mjpeg -vframes 1 -ss 1 -s {'.escapeshellarg($maxX).'}x{'.escapeshellarg($maxY).'} {.'.$thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup).'}'); + + // output the generated Preview + $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); + unset($thumbnails_view); + } + + } + + OC_Preview::registerProvider('OC_Preview_Movie'); +} \ No newline at end of file diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php new file mode 100644 index 0000000000..645e6fa623 --- /dev/null +++ b/lib/preview/mp3.php @@ -0,0 +1 @@ +///audio\/mpeg/ \ No newline at end of file diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/preview/provider.php b/lib/preview/provider.php new file mode 100644 index 0000000000..c45edbba44 --- /dev/null +++ b/lib/preview/provider.php @@ -0,0 +1,20 @@ +options=$options; + } + + abstract public function getMimeType(); + + /** + * search for $query + * @param string $query + * @return + */ + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup); +} diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php new file mode 100644 index 0000000000..1cd270db68 --- /dev/null +++ b/lib/preview/unknown.php @@ -0,0 +1,34 @@ + Date: Thu, 9 May 2013 23:59:16 +0200 Subject: [PATCH 0007/1989] implement OC_Preview --- lib/preview.php | 527 +++++++++++++++++++++++++++++---------- lib/preview/images.php | 53 +--- lib/preview/movies.php | 4 +- lib/preview/mp3.php | 21 +- lib/preview/pdf.php | 29 +++ lib/preview/provider.php | 2 +- lib/preview/unknown.php | 2 +- 7 files changed, 451 insertions(+), 187 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index de79b42407..c062a06887 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -5,21 +5,38 @@ * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. - */ -/* + * * Thumbnails: * structure of filename: * /data/user/thumbnails/pathhash/x-y.png * */ +require_once('preview/images.php'); +require_once('preview/movies.php'); +require_once('preview/mp3.php'); +require_once('preview/pdf.php'); +require_once('preview/unknown.php'); class OC_Preview { //the thumbnail folder const THUMBNAILS_FOLDER = 'thumbnails'; - const MAX_SCALE_FACTOR = 2; + + //config + private $max_scale_factor; + private $max_x; + private $max_y; //fileview object - static private $fileview = null; + private $fileview = null; + private $userview = null; + + //vars + private $file; + private $maxX; + private $maxY; + private $scalingup; + + private $preview; //preview providers static private $providers = array(); @@ -27,6 +44,8 @@ class OC_Preview { /** * @brief check if thumbnail or bigger version of thumbnail of file is cached + * @param $user userid + * @param $root path of root * @param $file The path to the file where you want a thumbnail from * @param $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image * @param $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image @@ -34,68 +53,223 @@ class OC_Preview { * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ - private static function isCached($file, $maxX, $maxY, $scalingup){ - $fileinfo = self::$fileview->getFileInfo($file); - $fileid = self::$fileinfo['fileid']; + public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = false){ + //set config + $this->max_x = OC_Config::getValue('preview_max_x', null); + $this->max_y = OC_Config::getValue('preview_max_y', null); + $this->max_scale_factor = OC_Config::getValue('preview_max_scale_factor', 10); - //echo self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid; - if(!self::$fileview->is_dir(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid)){ + //save parameters + $this->file = $file; + $this->maxX = $maxX; + $this->maxY = $maxY; + $this->scalingup = $scalingup; + + //init fileviews + $this->fileview = new \OC\Files\View('/' . $user . '/' . $root); + $this->userview = new \OC\Files\View('/' . $user); + + if(!is_null($this->max_x)){ + if($this->maxX > $this->max_x){ + OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, OC_Log::DEBUG); + $this->maxX = $this->max_x; + } + } + + if(!is_null($this->max_y)){ + if($this->maxY > $this->max_y){ + OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, OC_Log::DEBUG); + $this->maxY = $this->max_y; + } + } + + //init providers + if(empty(self::$providers)){ + self::initProviders(); + } + + //check if there are any providers at all + if(empty(self::$providers)){ + OC_Log::write('core', 'No preview providers exist', OC_Log::ERROR); + throw new Exception('No providers'); + } + + //validate parameters + if($file === ''){ + OC_Log::write('core', 'No filename passed', OC_Log::ERROR); + throw new Exception('File not found'); + } + + //check if file exists + if(!$this->fileview->file_exists($file)){ + OC_Log::write('core', 'File:"' . $file . '" not found', OC_Log::ERROR); + throw new Exception('File not found'); + } + + //check if given size makes sense + if($maxX === 0 || $maxY === 0){ + OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::ERROR); + throw new Exception('Height and/or width set to 0'); + } + } + + /** + * @brief returns the path of the file you want a thumbnail from + * @return string + */ + public function getFile(){ + return $this->file; + } + + /** + * @brief returns the max width of the preview + * @return integer + */ + public function getMaxX(){ + return $this->maxX; + } + + /** + * @brief returns the max height of the preview + * @return integer + */ + public function getMaxY(){ + return $this->maxY; + } + + /** + * @brief returns whether or not scalingup is enabled + * @return bool + */ + public function getScalingup(){ + return $this->scalingup; + } + + /** + * @brief returns the name of the thumbnailfolder + * @return string + */ + public function getThumbnailsfolder(){ + return self::THUMBNAILS_FOLDER; + } + + /** + * @brief returns the max scale factor + * @return integer + */ + public function getMaxScaleFactor(){ + return $this->max_scale_factor; + } + + /** + * @brief returns the max width set in ownCloud's config + * @return integer + */ + public function getConfigMaxX(){ + return $this->max_x; + } + + /** + * @brief returns the max height set in ownCloud's config + * @return integer + */ + public function getConfigMaxY(){ + return $this->max_y; + } + + /** + * @brief deletes previews of a file with specific x and y + * @return bool + */ + public function deletePreview(){ + $fileinfo = $this->fileview->getFileInfo($this->file); + $fileid = $fileinfo['fileid']; + + return $this->userview->unlink(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $this->maxX . '-' . $this->maxY . '.png'); + } + + /** + * @brief deletes all previews of a file + * @return bool + */ + public function deleteAllPrevies(){ + $fileinfo = $this->fileview->getFileInfo($this->file); + $fileid = $fileinfo['fileid']; + + return $this->userview->rmdir(self::THUMBNAILS_FOLDER . '/' . $fileid); + } + + /** + * @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 + */ + private function isCached(){ + $file = $this->file; + $maxX = $this->maxX; + $maxY = $this->maxY; + $scalingup = $this->scalingup; + + $fileinfo = $this->fileview->getFileInfo($file); + $fileid = $fileinfo['fileid']; + + if(!$this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid)){ return false; } - + //does a preview with the wanted height and width already exist? - if(self::$fileview->file_exists(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png')){ - return self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png'; + if($this->userview->file_exists(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')){ + return self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png'; } - + $wantedaspectratio = $maxX / $maxY; - + //array for usable cached thumbnails $possiblethumbnails = array(); - - $allthumbnails = self::$fileview->getDirectoryContent(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid); + + $allthumbnails = $this->userview->getDirectoryContent(self::THUMBNAILS_FOLDER . '/' . $fileid); foreach($allthumbnails as $thumbnail){ $size = explode('-', $thumbnail['name']); $x = $size[0]; $y = $size[1]; - + $aspectratio = $x / $y; if($aspectratio != $wantedaspectratio){ continue; } - + if($x < $maxX || $y < $maxY){ if($scalingup){ $scalefactor = $maxX / $x; - if($scalefactor > self::MAX_SCALE_FACTOR){ + if($scalefactor > $this->max_scale_factor){ continue; } }else{ continue; } } - $possiblethumbnails[$x] = $thumbnail['path']; } - + if(count($possiblethumbnails) === 0){ return false; } - + if(count($possiblethumbnails) === 1){ return current($possiblethumbnails); } - + ksort($possiblethumbnails); - + if(key(reset($possiblethumbnails)) > $maxX){ return current(reset($possiblethumbnails)); } - + if(key(end($possiblethumbnails)) < $maxX){ return current(end($possiblethumbnails)); } - + foreach($possiblethumbnails as $width => $path){ if($width < $maxX){ continue; @@ -105,36 +279,6 @@ class OC_Preview { } } - /** - * @brief delete a preview with a specfic height and width - * @param $file path to the file - * @param $x width of preview - * @param $y height of preview - * @return image - */ - public static function deletePreview($file, $x, $y){ - self::init(); - - $fileinfo = self::$fileview->getFileInfo($file); - $fileid = self::$fileinfo['fileid']; - - return self::$fileview->unlink(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png'); - } - - /** - * @brief deletes all previews of a file - * @param $file path of file - * @return bool - */ - public static function deleteAllPrevies($file){ - self::init(); - - $fileinfo = self::$fileview->getFileInfo($file); - $fileid = self::$fileinfo['fileid']; - - return self::$fielview->rmdir(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid); - } - /** * @brief return a preview of a file * @param $file The path to the file where you want a thumbnail from @@ -143,44 +287,49 @@ class OC_Preview { * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly * @return image */ - public static function getPreview($file, $maxX, $maxY, $scalingup){ - self::init(); - - $cached = self::isCached($file, $maxX, $maxY); + public function getPreview(){ + $file = $this->file; + $maxX = $this->maxX; + $maxY = $this->maxY; + $scalingup = $this->scalingup; + + $fileinfo = $this->fileview->getFileInfo($file); + $fileid = $fileinfo['fileid']; + + $cached = self::isCached(); + if($cached){ - $image = new \OC_Image($cached); - if($image->width() != $maxX && $image->height != $maxY){ - $image->preciseResize($maxX, $maxY); + $image = new \OC_Image($this->userview->getLocalFile($cached)); + $this->preview = $image; + }else{ + $mimetype = $this->fileview->getMimeType($file); + + $preview; + + foreach(self::$providers as $supportedmimetype => $provider){ + if(!preg_match($supportedmimetype, $mimetype)){ + continue; + } + + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup, $this->fileview); + + if(!$preview){ + continue; + } + + if(!($preview instanceof \OC_Image)){ + $preview = @new \OC_Image($preview); + } + + //cache thumbnail + $preview->save($this->userview->getLocalFile(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')); + + break; } - return $image; + $this->preview = $preview; } - - $mimetype = self::$fileview->getMimeType($file); - - $preview; - - foreach(self::$providers as $supportedmimetype => $provider){ - if(!preg_match($supportedmimetype, $mimetype)){ - continue; - } - - $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup); - - if(!$preview){ - continue; - } - - if(!($preview instanceof \OC_Image)){ - $preview = @new \OC_Image($preview); - } - - //cache thumbnail - $preview->save(self::$filesview->getAbsolutePath(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png')); - - break; - } - - return $preview; + $this->resizeAndCrop(); + return $this->preview; } /** @@ -189,24 +338,109 @@ class OC_Preview { * @param $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image * @param $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly - * @return image - */ - public static function showPreview($file, $maxX, $maxY, $scalingup = true, $fontsize = 12){ - OCP\Response::enableCaching(3600 * 24); // 24 hour - $preview = self::getPreview($file, $maxX, $maxY, $scalingup, $fontsize); - $preview->show(); - } - - /** - * @brief check whether or not providers and views are initialized and initialize if not * @return void */ - private static function init(){ - if(empty(self::$providers)){ - self::initProviders(); + public function showPreview(){ + OCP\Response::enableCaching(3600 * 24); // 24 hour + $preview = $this->getPreview(); + if($preview){ + $preview->show(); } - if(is_null(self::$fileview)){ - self::initViews(); + } + + /** + * @brief resize, crop and fix orientation + * @return image + */ + public function resizeAndCrop(){ + $image = $this->preview; + $x = $this->maxX; + $y = $this->maxY; + $scalingup = $this->scalingup; + + $image->fixOrientation(); + + if(!($image instanceof \OC_Image)){ + OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', OC_Log::DEBUG); + return; + } + + $realx = (int) $image->width(); + $realy = (int) $image->height(); + + if($x === $realx && $y === $realy){ + return $image; + } + + $factorX = $x / $realx; + $factorY = $y / $realy; + + if($factorX >= $factorY){ + $factor = $factorX; + }else{ + $factor = $factorY; + } + + // only scale up if requested + if($scalingup === false) { + if($factor>1) $factor=1; + } + if(!is_null($this->max_scale_factor)){ + if($factor > $this->max_scale_factor){ + OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $this->max_scale_factor, OC_Log::DEBUG); + $factor = $this->max_scale_factor; + } + } + $newXsize = $realx * $factor; + $newYsize = $realy * $factor; + + // resize + $image->preciseResize($newXsize, $newYsize); + + if($newXsize === $x && $newYsize === $y){ + $this->preview = $image; + return; + } + + if($newXsize >= $x && $newYsize >= $y){ + $cropX = floor(abs($x - $newXsize) * 0.5); + $cropY = floor(abs($y - $newYsize) * 0.5); + + $image->crop($cropX, $cropY, $x, $y); + + $this->preview = $image; + return; + } + + if($newXsize < $x || $newYsize < $y){ + if($newXsize > $x){ + $cropX = floor(($newXsize - $x) * 0.5); + $image->crop($cropX, 0, $x, $newYsize); + } + + if($newYsize > $y){ + $cropY = floor(($newYsize - $y) * 0.5); + $image->crop(0, $cropY, $newXsize, $y); + } + + $newXsize = (int) $image->width(); + $newYsize = (int) $image->height(); + + //create transparent background layer + $transparentlayer = imagecreatetruecolor($x, $y); + $black = imagecolorallocate($transparentlayer, 0, 0, 0); + $image = $image->resource(); + imagecolortransparent($transparentlayer, $black); + + $mergeX = floor(abs($x - $newXsize) * 0.5); + $mergeY = floor(abs($y - $newYsize) * 0.5); + + imagecopymerge($transparentlayer, $image, $mergeX, $mergeY, 0, 0, $newXsize, $newYsize, 100); + + $image = new \OC_Image($transparentlayer); + + $this->preview = $image; + return; } } @@ -236,48 +470,75 @@ class OC_Preview { self::$providers[$object->getMimeType()] = $object; } - + $keys = array_map('strlen', array_keys(self::$providers)); array_multisort($keys, SORT_DESC, self::$providers); } /** - * @brief initialize a new \OC\Files\View object + * @brief method that handles preview requests from users that are logged in * @return void */ - private static function initViews(){ - if(is_null(self::$fileview)){ - //does this work with LDAP? - self::$fileview = new OC\Files\View(OC_User::getUser()); + public static function previewRouter($params){ + OC_Util::checkLoggedIn(); + + $file = ''; + $maxX = 0; + $maxY = 0; + /* + * use: ?scalingup=0 / ?scalingup = 1 + * do not use ?scalingup=false / ?scalingup = true as these will always be true + */ + $scalingup = false; + + if(array_key_exists('file', $_GET)) $file = (string) urldecode($_GET['file']); + if(array_key_exists('x', $_GET)) $maxX = (int) $_GET['x']; + if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y']; + if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; + + if($file !== '' && $maxX !== 0 && $maxY !== 0){ + $preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); + $preview->showPreview(); + }else{ + OC_Response::setStatus(404); + exit; } } - public static function previewRouter($params){ - self::init(); + /** + * @brief method that handles preview requests from users that are not logged in / view shared folders that are public + * @return void + */ + public static function publicPreviewRouter($params){ + $file = ''; + $maxX = 0; + $maxY = 0; + $scalingup = false; + $token = ''; - $file = (string) urldecode($_GET['file']); - $maxX = (int) $_GET['x']; - $maxY = (int) $_GET['y']; - $scalingup = (bool) $_GET['scalingup']; + $user = null; + $path = null; - $path = 'files/' . $file; + if(array_key_exists('file', $_GET)) $file = (string) urldecode($_GET['file']); + if(array_key_exists('x', $_GET)) $maxX = (int) $_GET['x']; + if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y']; + if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; + if(array_key_exists('t', $_GET)) $token = (string) $_GET['t']; - if($maxX === 0 || $maxY === 0){ - OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::DEBUG); + $linkItem = OCP\Share::getShareByToken($token); + if (is_array($linkItem) && isset($linkItem['uid_owner']) && isset($linkItem['file_source'])) { + $userid = $linkItem['uid_owner']; + OC_Util::setupFS($fileOwner); + $path = $linkItem['file_source']; + } + + if($user !== null && $path !== null){ + $preview = new OC_Preview($userid, $path, $file, $maxX, $maxY, $scalingup); + $preview->showPreview(); + }else{ + OC_Response::setStatus(404); exit; } - var_dump(self::$fileview->file_exists($path)); - var_dump(self::$fileview->getDirectoryContent()); - var_dump(self::$fileview->getDirectoryContent('files/')); - var_dump($path); - var_dump(self::$fileview->filesize($path)); - var_dump(self::$fileview->getAbsolutePath('/')); - - if(!self::$fileview->filesize($path)){ - OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); - } - - self::showPreview($file, $maxX, $maxY, $scalingup); } } \ No newline at end of file diff --git a/lib/preview/images.php b/lib/preview/images.php index 6b6e8e3599..6766cdb214 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -12,60 +12,15 @@ class OC_Preview_Image extends OC_Preview_Provider{ return '/image\/.*/'; } - public static function getThumbnail($path,$maxX,$maxY,$scalingup) { - - $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); - - // is a preview already in the cache? - if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { - return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); - } - - // does the sourcefile exist? - if (!\OC_Filesystem::file_exists($path)) { - \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); - return false; - } - - // open the source image + public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { + //new image object $image = new \OC_Image(); - $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); + $image->loadFromFile($fileview->getLocalFile($path)); + //check if image object is valid if (!$image->valid()) return false; - // fix the orientation - $image->fixOrientation(); - - // calculate the right preview size - $Xsize=$image->width(); - $Ysize=$image->height(); - if (($Xsize/$Ysize)>($maxX/$maxY)) { - $factor=$maxX/$Xsize; - } else { - $factor=$maxY/$Ysize; - } - - // only scale up if requested - if($scalingup==false) { - if($factor>1) $factor=1; - } - $newXsize=$Xsize*$factor; - $newYsize=$Ysize*$factor; - - // resize - $ret = $image->preciseResize($newXsize, $newYsize); - if (!$ret) { - \OC_Log::write('Preview', 'Couldn\'t resize image', \OC_Log::ERROR); - unset($image); - return false; - } - - // store in cache - $l = $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); - $image->save($l); - return $image; } - } OC_Preview::registerProvider('OC_Preview_Image'); \ No newline at end of file diff --git a/lib/preview/movies.php b/lib/preview/movies.php index afa27c0b14..c994240424 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -6,7 +6,7 @@ * later. * See the COPYING-README file. */ -if(!is_null(shell_exec('ffmpeg'))){ +if(!is_null(shell_exec('ffmpeg -version'))){ class OC_Preview_Movie extends OC_Preview_Provider{ @@ -14,7 +14,7 @@ if(!is_null(shell_exec('ffmpeg'))){ return '/video\/.*/'; } - public static function getThumbnail($path,$maxX,$maxY,$scalingup) { + public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); // is a preview already in the cache? diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 645e6fa623..2481e74378 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -1 +1,20 @@ -///audio\/mpeg/ \ No newline at end of file +getLocalFile($path) . '[0]'); + $pdf->setImageFormat('png'); + + //new image object + $image = new \OC_Image(); + $image->loadFromFile($fileview->getLocalFile($path)); + //check if image object is valid + if (!$image->valid()) return false; + + return $image; + } +} + +OC_Preview::registerProvider('OC_Preview_PDF'); \ No newline at end of file diff --git a/lib/preview/provider.php b/lib/preview/provider.php index c45edbba44..e926403014 100644 --- a/lib/preview/provider.php +++ b/lib/preview/provider.php @@ -16,5 +16,5 @@ abstract class OC_Preview_Provider{ * @param string $query * @return */ - abstract public function getThumbnail($path, $maxX, $maxY, $scalingup); + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview); } diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 1cd270db68..5089a56d67 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -12,7 +12,7 @@ class OC_Preview_Unknown extends OC_Preview_Provider{ return '/.*/'; } - public static function getThumbnail($maxX,$maxY) { + public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { // check if GD is installed if(!extension_loaded('gd') || !function_exists('gd_info')) { OC_Log::write('preview', __METHOD__.'(): GD module not installed', OC_Log::ERROR); From 837c6ed597f1c549cac5b0b439b257d81ea02b1d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 09:43:25 +0200 Subject: [PATCH 0008/1989] implement pdf preview backend --- lib/preview/pdf.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index d86ad64391..695f856953 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -14,11 +14,10 @@ class OC_Preview_PDF extends OC_Preview_Provider{ public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { //create imagick object from pdf $pdf = new imagick($fileview->getLocalFile($path) . '[0]'); - $pdf->setImageFormat('png'); - + $pdf->setImageFormat('jpg'); + //new image object - $image = new \OC_Image(); - $image->loadFromFile($fileview->getLocalFile($path)); + $image = new \OC_Image($pdf); //check if image object is valid if (!$image->valid()) return false; From 8dba46912d19bf976b24e0c097368f2e56ccb97b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 11:28:49 +0200 Subject: [PATCH 0009/1989] Disable transparent backgrounds for now --- lib/preview.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index c062a06887..44b551006f 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -427,17 +427,21 @@ class OC_Preview { $newYsize = (int) $image->height(); //create transparent background layer - $transparentlayer = imagecreatetruecolor($x, $y); - $black = imagecolorallocate($transparentlayer, 0, 0, 0); + $backgroundlayer = imagecreatetruecolor($x, $y); + $white = imagecolorallocate($backgroundlayer, 255, 255, 255); + imagefill($backgroundlayer, 0, 0, $white); + $image = $image->resource(); - imagecolortransparent($transparentlayer, $black); $mergeX = floor(abs($x - $newXsize) * 0.5); $mergeY = floor(abs($y - $newYsize) * 0.5); - imagecopymerge($transparentlayer, $image, $mergeX, $mergeY, 0, 0, $newXsize, $newYsize, 100); + imagecopy($backgroundlayer, $image, $mergeX, $mergeY, 0, 0, $newXsize, $newYsize); - $image = new \OC_Image($transparentlayer); + //$black = imagecolorallocate(0,0,0); + //imagecolortransparent($transparentlayer, $black); + + $image = new \OC_Image($backgroundlayer); $this->preview = $image; return; From f29b8cf68531844c23c45a210e280769a8cece73 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 11:30:44 +0200 Subject: [PATCH 0010/1989] set default value of scalingup to true --- lib/preview.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 44b551006f..3b6e0ae131 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -53,7 +53,7 @@ class OC_Preview { * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ - public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = false){ + public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true){ //set config $this->max_x = OC_Config::getValue('preview_max_x', null); $this->max_y = OC_Config::getValue('preview_max_y', null); @@ -493,7 +493,7 @@ class OC_Preview { * use: ?scalingup=0 / ?scalingup = 1 * do not use ?scalingup=false / ?scalingup = true as these will always be true */ - $scalingup = false; + $scalingup = true; if(array_key_exists('file', $_GET)) $file = (string) urldecode($_GET['file']); if(array_key_exists('x', $_GET)) $maxX = (int) $_GET['x']; @@ -517,7 +517,7 @@ class OC_Preview { $file = ''; $maxX = 0; $maxY = 0; - $scalingup = false; + $scalingup = true; $token = ''; $user = null; From 04a4234b9eba85dc1a2f690c12e6a59381a74a54 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 11:32:42 +0200 Subject: [PATCH 0011/1989] implement mp3 preview backend --- lib/preview/mp3.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 2481e74378..f5fac0b836 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -5,14 +5,30 @@ * later. * See the COPYING-README file. */ +require_once('getid3/getid3.php'); + class OC_Preview_MP3 extends OC_Preview_Provider{ public function getMimeType(){ return '/audio\/mpeg/'; } - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $getID3 = new getID3(); + //Todo - add stream support + $tags = $getID3->analyze($fileview->getLocalFile($path)); + getid3_lib::CopyTagsToComments($tags); + $picture = @$tags['id3v2']['APIC'][0]['data']; + $image = new \OC_Image($picture); + if (!$image->valid()) return $this->getNoCoverThumbnail($maxX, $maxY); + + return $image; + } + + public function getNoCoverThumbnail($maxX, $maxY){ + $image = new \OC_Image(); + return $image; } } From 8b39a085121fae7823046f209eecc3484cf5c936 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 12:00:32 +0200 Subject: [PATCH 0012/1989] fix typo --- lib/preview/images.php | 2 +- lib/preview/movies.php | 2 +- lib/preview/mp3.php | 2 +- lib/preview/pdf.php | 2 +- lib/preview/unknown.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/preview/images.php b/lib/preview/images.php index 6766cdb214..589c7d829d 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -1,7 +1,7 @@ Date: Fri, 17 May 2013 15:06:37 +0200 Subject: [PATCH 0013/1989] implement movie previews --- lib/preview/movies.php | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 1f0ceb3ace..868755a120 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -7,7 +7,6 @@ * See the COPYING-README file. */ if(!is_null(shell_exec('ffmpeg -version'))){ - class OC_Preview_Movie extends OC_Preview_Provider{ public function getMimeType(){ @@ -15,28 +14,18 @@ if(!is_null(shell_exec('ffmpeg -version'))){ } public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { - $thumbnails_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/'.OC_Preview::THUMBNAILS_FOLDER); - - // is a preview already in the cache? - if ($thumbnails_view->file_exists($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)) { - return new \OC_Image($thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup)); - } - - // does the sourcefile exist? - if (!\OC_Filesystem::file_exists($path)) { - \OC_Log::write('Preview', 'File '.$path.' don\'t exists', \OC_Log::WARN); - return false; - } - - // call ffmpeg to do the screenshot - shell_exec('ffmpeg -y -i {'.escapeshellarg($path).'} -f mjpeg -vframes 1 -ss 1 -s {'.escapeshellarg($maxX).'}x{'.escapeshellarg($maxY).'} {.'.$thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup).'}'); - - // output the generated Preview - $thumbnails_view->getLocalFile($path.'-'.$maxX.'-'.$maxY.'-'.$scalingup); - unset($thumbnails_view); + $abspath = $fileview->getLocalfile($path); + + $tmppath = OC_Helper::tmpFile(); + + $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; + shell_exec($cmd); + + $image = new \OC_Image($tmppath); + if (!$image->valid()) return false; + + return $image; } - } - OC_Preview::registerProvider('OC_Preview_Movie'); } \ No newline at end of file From dd06387a9c65dfaf8d95e6545586f7a042bfd44e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 19:08:16 +0200 Subject: [PATCH 0014/1989] remove whitespace --- lib/preview.php | 79 ++++++++++++++++++++-------------------- lib/preview/images.php | 2 +- lib/preview/movies.php | 10 ++--- lib/preview/mp3.php | 2 +- lib/preview/pdf.php | 2 +- lib/preview/provider.php | 2 +- lib/preview/unknown.php | 21 +++-------- 7 files changed, 53 insertions(+), 65 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 3b6e0ae131..d6c7260352 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -20,7 +20,7 @@ require_once('preview/unknown.php'); class OC_Preview { //the thumbnail folder const THUMBNAILS_FOLDER = 'thumbnails'; - + //config private $max_scale_factor; private $max_x; @@ -35,7 +35,7 @@ class OC_Preview { private $maxX; private $maxY; private $scalingup; - + private $preview; //preview providers @@ -58,7 +58,7 @@ class OC_Preview { $this->max_x = OC_Config::getValue('preview_max_x', null); $this->max_y = OC_Config::getValue('preview_max_y', null); $this->max_scale_factor = OC_Config::getValue('preview_max_scale_factor', 10); - + //save parameters $this->file = $file; $this->maxX = $maxX; @@ -112,7 +112,7 @@ class OC_Preview { throw new Exception('Height and/or width set to 0'); } } - + /** * @brief returns the path of the file you want a thumbnail from * @return string @@ -120,7 +120,7 @@ class OC_Preview { public function getFile(){ return $this->file; } - + /** * @brief returns the max width of the preview * @return integer @@ -136,7 +136,7 @@ class OC_Preview { public function getMaxY(){ return $this->maxY; } - + /** * @brief returns whether or not scalingup is enabled * @return bool @@ -144,7 +144,7 @@ class OC_Preview { public function getScalingup(){ return $this->scalingup; } - + /** * @brief returns the name of the thumbnailfolder * @return string @@ -176,7 +176,7 @@ class OC_Preview { public function getConfigMaxY(){ return $this->max_y; } - + /** * @brief deletes previews of a file with specific x and y * @return bool @@ -303,27 +303,27 @@ class OC_Preview { $this->preview = $image; }else{ $mimetype = $this->fileview->getMimeType($file); - + $preview; - + foreach(self::$providers as $supportedmimetype => $provider){ if(!preg_match($supportedmimetype, $mimetype)){ continue; } - + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup, $this->fileview); if(!$preview){ continue; } - + if(!($preview instanceof \OC_Image)){ $preview = @new \OC_Image($preview); } - + //cache thumbnail $preview->save($this->userview->getLocalFile(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')); - + break; } $this->preview = $preview; @@ -396,12 +396,12 @@ class OC_Preview { // resize $image->preciseResize($newXsize, $newYsize); - + if($newXsize === $x && $newYsize === $y){ $this->preview = $image; return; } - + if($newXsize >= $x && $newYsize >= $y){ $cropX = floor(abs($x - $newXsize) * 0.5); $cropY = floor(abs($y - $newYsize) * 0.5); @@ -411,38 +411,38 @@ class OC_Preview { $this->preview = $image; return; } - + if($newXsize < $x || $newYsize < $y){ if($newXsize > $x){ $cropX = floor(($newXsize - $x) * 0.5); $image->crop($cropX, 0, $x, $newYsize); } - + if($newYsize > $y){ $cropY = floor(($newYsize - $y) * 0.5); $image->crop(0, $cropY, $newXsize, $y); } - + $newXsize = (int) $image->width(); $newYsize = (int) $image->height(); - + //create transparent background layer $backgroundlayer = imagecreatetruecolor($x, $y); $white = imagecolorallocate($backgroundlayer, 255, 255, 255); imagefill($backgroundlayer, 0, 0, $white); - + $image = $image->resource(); - + $mergeX = floor(abs($x - $newXsize) * 0.5); $mergeY = floor(abs($y - $newYsize) * 0.5); - + imagecopy($backgroundlayer, $image, $mergeX, $mergeY, 0, 0, $newXsize, $newYsize); - + //$black = imagecolorallocate(0,0,0); //imagecolortransparent($transparentlayer, $black); - + $image = new \OC_Image($backgroundlayer); - + $this->preview = $image; return; } @@ -465,27 +465,27 @@ class OC_Preview { if(count(self::$providers)>0) { return; } - + foreach(self::$registeredProviders as $provider) { $class=$provider['class']; $options=$provider['options']; - + $object = new $class($options); - + self::$providers[$object->getMimeType()] = $object; } - + $keys = array_map('strlen', array_keys(self::$providers)); array_multisort($keys, SORT_DESC, self::$providers); } - + /** * @brief method that handles preview requests from users that are logged in * @return void */ public static function previewRouter($params){ OC_Util::checkLoggedIn(); - + $file = ''; $maxX = 0; $maxY = 0; @@ -494,12 +494,12 @@ class OC_Preview { * do not use ?scalingup=false / ?scalingup = true as these will always be true */ $scalingup = true; - + if(array_key_exists('file', $_GET)) $file = (string) urldecode($_GET['file']); if(array_key_exists('x', $_GET)) $maxX = (int) $_GET['x']; if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y']; if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; - + if($file !== '' && $maxX !== 0 && $maxY !== 0){ $preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); $preview->showPreview(); @@ -508,7 +508,7 @@ class OC_Preview { exit; } } - + /** * @brief method that handles preview requests from users that are not logged in / view shared folders that are public * @return void @@ -519,23 +519,23 @@ class OC_Preview { $maxY = 0; $scalingup = true; $token = ''; - + $user = null; $path = null; - + if(array_key_exists('file', $_GET)) $file = (string) urldecode($_GET['file']); if(array_key_exists('x', $_GET)) $maxX = (int) $_GET['x']; if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y']; if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; if(array_key_exists('t', $_GET)) $token = (string) $_GET['t']; - + $linkItem = OCP\Share::getShareByToken($token); if (is_array($linkItem) && isset($linkItem['uid_owner']) && isset($linkItem['file_source'])) { $userid = $linkItem['uid_owner']; OC_Util::setupFS($fileOwner); $path = $linkItem['file_source']; } - + if($user !== null && $path !== null){ $preview = new OC_Preview($userid, $path, $file, $maxX, $maxY, $scalingup); $preview->showPreview(); @@ -543,6 +543,5 @@ class OC_Preview { OC_Response::setStatus(404); exit; } - } } \ No newline at end of file diff --git a/lib/preview/images.php b/lib/preview/images.php index 589c7d829d..a0df337d58 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -11,7 +11,7 @@ class OC_Preview_Image extends OC_Preview_Provider{ public function getMimeType(){ return '/image\/.*/'; } - + public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { //new image object $image = new \OC_Image(); diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 868755a120..8144956c99 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -12,18 +12,18 @@ if(!is_null(shell_exec('ffmpeg -version'))){ public function getMimeType(){ return '/video\/.*/'; } - + public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { $abspath = $fileview->getLocalfile($path); - + $tmppath = OC_Helper::tmpFile(); - + $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; shell_exec($cmd); - + $image = new \OC_Image($tmppath); if (!$image->valid()) return false; - + return $image; } } diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 5194e16581..6fb4b051f4 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -25,7 +25,7 @@ class OC_Preview_MP3 extends OC_Preview_Provider{ return $image; } - + public function getNoCoverThumbnail($maxX, $maxY){ $image = new \OC_Image(); return $image; diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index f1b7f3eee7..bf1d8b2b3b 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -15,7 +15,7 @@ class OC_Preview_PDF extends OC_Preview_Provider{ //create imagick object from pdf $pdf = new imagick($fileview->getLocalFile($path) . '[0]'); $pdf->setImageFormat('jpg'); - + //new image object $image = new \OC_Image($pdf); //check if image object is valid diff --git a/lib/preview/provider.php b/lib/preview/provider.php index e926403014..2f2a0e6848 100644 --- a/lib/preview/provider.php +++ b/lib/preview/provider.php @@ -8,7 +8,7 @@ abstract class OC_Preview_Provider{ public function __construct($options) { $this->options=$options; } - + abstract public function getMimeType(); /** diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 746b0ebb47..290c18a72d 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -12,23 +12,12 @@ class OC_Preview_Unknown extends OC_Preview_Provider{ return '/.*/'; } - public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { - // check if GD is installed - if(!extension_loaded('gd') || !function_exists('gd_info')) { - OC_Log::write('preview', __METHOD__.'(): GD module not installed', OC_Log::ERROR); - return false; - } - - // create a white image - $image = imagecreatetruecolor($maxX, $maxY); - $color = imagecolorallocate($image, 255, 255, 255); - imagefill($image, 0, 0, $color); - - // output the image - imagepng($image); - imagedestroy($image); - } + public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { + + $mimetype = $this->fileview->getMimeType($file); + return new \OC_Image(); + } } OC_Preview::registerProvider('OC_Preview_Unknown'); \ No newline at end of file From 13c6ef1ba9c3f857150679d164852d8724ab946f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 21 May 2013 12:23:31 +0200 Subject: [PATCH 0015/1989] add svg backend --- lib/preview.php | 1 + lib/preview/svg.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/preview/svg.php diff --git a/lib/preview.php b/lib/preview.php index d6c7260352..572c85057b 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -15,6 +15,7 @@ require_once('preview/images.php'); require_once('preview/movies.php'); require_once('preview/mp3.php'); require_once('preview/pdf.php'); +require_once('preview/svg.php'); require_once('preview/unknown.php'); class OC_Preview { diff --git a/lib/preview/svg.php b/lib/preview/svg.php new file mode 100644 index 0000000000..12b93f696e --- /dev/null +++ b/lib/preview/svg.php @@ -0,0 +1,28 @@ +readImageBlob($fileview->file_get_contents($path)); + $svg->setImageFormat('jpg'); + + //new image object + $image = new \OC_Image($svg); + //check if image object is valid + if (!$image->valid()) return false; + + return $image; + } +} + +OC_Preview::registerProvider('OC_Preview_SVG'); \ No newline at end of file From 00985068ca249f4087f9f5b634e628afb8e8f7b1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 22 May 2013 15:12:25 +0200 Subject: [PATCH 0016/1989] add previews for public files --- core/routes.php | 2 ++ lib/preview.php | 24 +++++++++++++++++++----- lib/preview/unknown.php | 10 ++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/core/routes.php b/core/routes.php index be5766cea9..c45ffee26f 100644 --- a/core/routes.php +++ b/core/routes.php @@ -44,6 +44,8 @@ $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); $this->create('core_ajax_preview', '/core/preview.png') ->action('OC_Preview', 'previewRouter'); +$this->create('core_ajax_public_preview', '/core/publicpreview.png') + ->action('OC_Preview', 'publicPreviewRouter'); OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; $this->create('core_lostpassword_index', '/lostpassword/') ->get() diff --git a/lib/preview.php b/lib/preview.php index 572c85057b..39a87ed539 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -529,16 +529,30 @@ class OC_Preview { if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y']; if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; if(array_key_exists('t', $_GET)) $token = (string) $_GET['t']; - + $linkItem = OCP\Share::getShareByToken($token); + if (is_array($linkItem) && isset($linkItem['uid_owner']) && isset($linkItem['file_source'])) { $userid = $linkItem['uid_owner']; - OC_Util::setupFS($fileOwner); - $path = $linkItem['file_source']; + OC_Util::setupFS($userid); + $pathid = $linkItem['file_source']; + $path = \OC\Files\Filesystem::getPath($pathid); + } + + //clean up file parameter + $file = \OC\Files\Filesystem::normalizePath($file); + if(!\OC\Files\Filesystem::isValidPath($file)){ + OC_Response::setStatus(403); + exit; } - if($user !== null && $path !== null){ - $preview = new OC_Preview($userid, $path, $file, $maxX, $maxY, $scalingup); + $path = \OC\Files\Filesystem::normalizePath($path, false); + if(substr($path, 0, 1) == '/'){ + $path = substr($path, 1); + } + + if($userid !== null && $path !== null){ + $preview = new OC_Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); $preview->showPreview(); }else{ OC_Response::setStatus(404); diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 290c18a72d..5bbdcf847f 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -13,11 +13,13 @@ class OC_Preview_Unknown extends OC_Preview_Provider{ } public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { - - - $mimetype = $this->fileview->getMimeType($file); + /*$mimetype = $fileview->getMimeType($path); + $info = $fileview->getFileInfo($path); + $name = array_key_exists('name', $info) ? $info['name'] : ''; + $size = array_key_exists('size', $info) ? $info['size'] : 0; + $isencrypted = array_key_exists('encrypted', $info) ? $info['encrypted'] : false;*/ // show little lock return new \OC_Image(); } } -OC_Preview::registerProvider('OC_Preview_Unknown'); \ No newline at end of file +OC_Preview::registerProvider('OC_Preview_Unknown'); From 1bed3253abfc627a6dd698fc62a617285c1d7c84 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 25 May 2013 11:05:37 +0200 Subject: [PATCH 0017/1989] add sample config for previews --- config/config.sample.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/config.sample.php b/config/config.sample.php index 7283400920..db6eaf852a 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -183,4 +183,12 @@ $CONFIG = array( 'customclient_desktop' => '', //http://owncloud.org/sync-clients/ 'customclient_android' => '', //https://play.google.com/store/apps/details?id=com.owncloud.android 'customclient_ios' => '' //https://itunes.apple.com/us/app/owncloud/id543672169?mt=8 + +// PREVIEW +/* the max width of a generated preview, if value is null, there is no limit */ +'preview_max_x' => null, +/* the max height of a generated preview, if value is null, there is no limit */ +'preview_max_y' => null, +/* the max factor to scale a preview, default is set to 10 */ +'preview_max_scale_factor' => 10, ); From f78e00209692d28253b91a432eb02d432c96a695 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 27 May 2013 10:45:21 +0200 Subject: [PATCH 0018/1989] make image preview backend work with encryption --- lib/preview/images.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/preview/images.php b/lib/preview/images.php index a0df337d58..52aad67ca8 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -14,11 +14,10 @@ class OC_Preview_Image extends OC_Preview_Provider{ public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { //new image object - $image = new \OC_Image(); - $image->loadFromFile($fileview->getLocalFile($path)); + $image = new \OC_Image($fileview->fopen($path, 'r')); //check if image object is valid if (!$image->valid()) return false; - + return $image; } } From 62411965f9ccfbe66584e91bc325d156e08196d2 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 27 May 2013 11:09:55 +0200 Subject: [PATCH 0019/1989] make svg preview backend work with encryption --- lib/preview/svg.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 12b93f696e..8f4697dce0 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -13,7 +13,8 @@ class OC_Preview_SVG extends OC_Preview_Provider{ public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { $svg = new Imagick(); - $svg->readImageBlob($fileview->file_get_contents($path)); + $svg->setResolution($maxX, $maxY); + $svg->readImageBlob('' . $fileview->file_get_contents($path)); $svg->setImageFormat('jpg'); //new image object From 005d8e98706fc98d8dc5aa4927bb3ab0e6b00ac2 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 10:21:02 +0200 Subject: [PATCH 0020/1989] update images.php --- lib/preview/images.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/preview/images.php b/lib/preview/images.php index 52aad67ca8..a8f203528c 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -13,11 +13,20 @@ class OC_Preview_Image extends OC_Preview_Provider{ } public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { - //new image object - $image = new \OC_Image($fileview->fopen($path, 'r')); + //get fileinfo + $fileinfo = $fileview->getFileInfo($path); + + //check if file is encrypted + if($fileinfo['encrypted'] === true){ + $image = new \OC_Image($fileview->fopen($path, 'r')); + }else{ + $image = new \OC_Image(); + $image->loadFromFile($fileview->getLocalFile($path)); + } + //check if image object is valid if (!$image->valid()) return false; - + return $image; } } From 707f52f1dbb063595541331f94b3796f0f96ce9a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 10:23:40 +0200 Subject: [PATCH 0021/1989] check if the imagick extension is loaded --- lib/preview/svg.php | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 8f4697dce0..415b7751c2 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -5,25 +5,29 @@ * later. * See the COPYING-README file. */ -class OC_Preview_SVG extends OC_Preview_Provider{ +if (extension_loaded('imagick')){ - public function getMimeType(){ - return '/image\/svg\+xml/'; + class OC_Preview_SVG extends OC_Preview_Provider{ + + public function getMimeType(){ + return '/image\/svg\+xml/'; + } + + public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { + $svg = new Imagick(); + $svg->setResolution($maxX, $maxY); + $svg->readImageBlob('' . $fileview->file_get_contents($path)); + $svg->setImageFormat('jpg'); + + //new image object + $image = new \OC_Image($svg); + //check if image object is valid + if (!$image->valid()) return false; + + return $image; + } } - public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { - $svg = new Imagick(); - $svg->setResolution($maxX, $maxY); - $svg->readImageBlob('' . $fileview->file_get_contents($path)); - $svg->setImageFormat('jpg'); + OC_Preview::registerProvider('OC_Preview_SVG'); - //new image object - $image = new \OC_Image($svg); - //check if image object is valid - if (!$image->valid()) return false; - - return $image; - } -} - -OC_Preview::registerProvider('OC_Preview_SVG'); \ No newline at end of file +} \ No newline at end of file From 5ae1333c76fd1331e21fff0fc7343888c473c8d4 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:29:01 +0200 Subject: [PATCH 0022/1989] add preview backend for text based files --- lib/preview/txt.php | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/preview/txt.php diff --git a/lib/preview/txt.php b/lib/preview/txt.php new file mode 100644 index 0000000000..2b5d8edb89 --- /dev/null +++ b/lib/preview/txt.php @@ -0,0 +1,49 @@ +fopen($path, 'r'); + $content = stream_get_contents($content); + + $lines = preg_split("/\r\n|\n|\r/", $content); + $numoflines = count($lines); + + $fontsize = 5; //5px + $linesize = ceil($fontsize * 1.25); + + $image = imagecreate($maxX, $maxY); + $imagecolor = imagecolorallocate($image, 255, 255, 255); + $textcolor = imagecolorallocate($image, 0, 0, 0); + + foreach($lines as $index => $line){ + $index = $index + 1; + + $x = (int) 1; + $y = (int) ($index * $linesize) - $fontsize; + + imagestring($image, 1, $x, $y, $line, $textcolor); + + if(($index * $linesize) >= $maxY){ + break; + } + } + + $image = new \OC_Image($image); + + if (!$image->valid()) return false; + + return $image; + } +} + +OC_Preview::registerProvider('OC_Preview_TXT'); \ No newline at end of file From 7555332d58c6e684cfbde72d5676e8e1902ae4f3 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:31:48 +0200 Subject: [PATCH 0023/1989] remove whitespace --- lib/preview/txt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview/txt.php b/lib/preview/txt.php index 2b5d8edb89..1e88aec69f 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -39,7 +39,7 @@ class OC_Preview_TXT extends OC_Preview_Provider{ } $image = new \OC_Image($image); - + if (!$image->valid()) return false; return $image; From 4d52dfb0a0517a7fd52d20572085aba2ec0e4ad0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:48:02 +0200 Subject: [PATCH 0024/1989] make movie backend work with encryption --- lib/preview/movies.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 8144956c99..1e517b3818 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -14,18 +14,25 @@ if(!is_null(shell_exec('ffmpeg -version'))){ } public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { - $abspath = $fileview->getLocalfile($path); + //get fileinfo + $fileinfo = $fileview->getFileInfo($path); + $abspath = $fileview->toTmpFile($path); $tmppath = OC_Helper::tmpFile(); $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; shell_exec($cmd); + unlink($abspath); + $image = new \OC_Image($tmppath); if (!$image->valid()) return false; + unlink($tmppath); + return $image; } } + OC_Preview::registerProvider('OC_Preview_Movie'); } \ No newline at end of file From 738cc48a85f48f8dca2b42d5667d6662810a688b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:49:18 +0200 Subject: [PATCH 0025/1989] make mp3 backend work with encryption --- lib/preview/mp3.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 6fb4b051f4..18f5cfde37 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -14,15 +14,20 @@ class OC_Preview_MP3 extends OC_Preview_Provider{ } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $getID3 = new getID3(); + $getID3 = new getID3(); + + $tmppath = $fileview->toTmpFile($path); + //Todo - add stream support - $tags = $getID3->analyze($fileview->getLocalFile($path)); + $tags = $getID3->analyze($tmppath); getid3_lib::CopyTagsToComments($tags); $picture = @$tags['id3v2']['APIC'][0]['data']; - + + unlink($tmppath); + $image = new \OC_Image($picture); if (!$image->valid()) return $this->getNoCoverThumbnail($maxX, $maxY); - + return $image; } From 55b00fe819079d78224989eee91d5886233738ab Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:59:20 +0200 Subject: [PATCH 0026/1989] make pdf backend work with encryption --- lib/preview/pdf.php | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index bf1d8b2b3b..de5263f91d 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -5,24 +5,31 @@ * later. * See the COPYING-README file. */ -class OC_Preview_PDF extends OC_Preview_Provider{ +if (extension_loaded('imagick')){ - public function getMimeType(){ - return '/application\/pdf/'; + class OC_Preview_PDF extends OC_Preview_Provider{ + + public function getMimeType(){ + return '/application\/pdf/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $tmppath = $fileview->toTmpFile($path); + + //create imagick object from pdf + $pdf = new imagick($tmppath . '[0]'); + $pdf->setImageFormat('jpg'); + + unlink($tmppath); + + //new image object + $image = new \OC_Image($pdf); + //check if image object is valid + if (!$image->valid()) return false; + + return $image; + } } - public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { - //create imagick object from pdf - $pdf = new imagick($fileview->getLocalFile($path) . '[0]'); - $pdf->setImageFormat('jpg'); - - //new image object - $image = new \OC_Image($pdf); - //check if image object is valid - if (!$image->valid()) return false; - - return $image; - } + OC_Preview::registerProvider('OC_Preview_PDF'); } - -OC_Preview::registerProvider('OC_Preview_PDF'); \ No newline at end of file From 08a022aaa48a6bae95ff75204a763a7c16a8253e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 12:09:46 +0200 Subject: [PATCH 0027/1989] don't give ffmpeg wanted size, cause it doesn't care about aspect ratio --- lib/preview/movies.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 1e517b3818..d2aaf730d6 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -20,7 +20,8 @@ if(!is_null(shell_exec('ffmpeg -version'))){ $abspath = $fileview->toTmpFile($path); $tmppath = OC_Helper::tmpFile(); - $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; + //$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; + $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . $tmppath; shell_exec($cmd); unlink($abspath); From a03787bc422563d129359d34673eb361b0173f51 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 16:04:39 +0200 Subject: [PATCH 0028/1989] make preview cache work with encryption and improve error handling --- lib/preview.php | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 39a87ed539..6fc166b9c7 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -16,6 +16,7 @@ require_once('preview/movies.php'); require_once('preview/mp3.php'); require_once('preview/pdf.php'); require_once('preview/svg.php'); +require_once('preview/txt.php'); require_once('preview/unknown.php'); class OC_Preview { @@ -300,7 +301,7 @@ class OC_Preview { $cached = self::isCached(); if($cached){ - $image = new \OC_Image($this->userview->getLocalFile($cached)); + $image = new \OC_Image($this->userview->file_get_contents($cached, 'r')); $this->preview = $image; }else{ $mimetype = $this->fileview->getMimeType($file); @@ -313,17 +314,22 @@ class OC_Preview { } $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup, $this->fileview); - + if(!$preview){ continue; } - if(!($preview instanceof \OC_Image)){ - $preview = @new \OC_Image($preview); + //are there any cached thumbnails yet + if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/') === false){ + $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/'); } //cache thumbnail - $preview->save($this->userview->getLocalFile(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')); + $cachepath = self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png'; + if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/') === false){ + $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/'); + } + $this->userview->file_put_contents($cachepath, $preview->data()); break; } @@ -354,13 +360,13 @@ class OC_Preview { * @return image */ public function resizeAndCrop(){ + $this->preview->fixOrientation(); + $image = $this->preview; $x = $this->maxX; $y = $this->maxY; $scalingup = $this->scalingup; - $image->fixOrientation(); - if(!($image instanceof \OC_Image)){ OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', OC_Log::DEBUG); return; @@ -502,8 +508,14 @@ class OC_Preview { if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; if($file !== '' && $maxX !== 0 && $maxY !== 0){ - $preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); - $preview->showPreview(); + try{ + $preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); + $preview->showPreview(); + }catch(Exception $e){ + OC_Response::setStatus(404); + OC_Log::write('core', $e->getmessage(), OC_Log::ERROR); + exit; + } }else{ OC_Response::setStatus(404); exit; @@ -552,8 +564,14 @@ class OC_Preview { } if($userid !== null && $path !== null){ - $preview = new OC_Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); - $preview->showPreview(); + try{ + $preview = new OC_Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); + $preview->showPreview(); + }catch(Exception $e){ + OC_Response::setStatus(404); + OC_Log::write('core', $e->getmessage(), OC_Log::ERROR); + exit; + } }else{ OC_Response::setStatus(404); exit; From eebc15dce0da88dff91dc5249938341cd50b8a85 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 12:01:43 +0200 Subject: [PATCH 0029/1989] connect preview lib to filesystem hooks --- lib/base.php | 9 ++++ lib/preview.php | 106 ++++++++++++++++++++++++++++-------------------- 2 files changed, 71 insertions(+), 44 deletions(-) diff --git a/lib/base.php b/lib/base.php index 724bd250a5..ae384225be 100644 --- a/lib/base.php +++ b/lib/base.php @@ -474,6 +474,7 @@ class OC { self::registerCacheHooks(); self::registerFilesystemHooks(); + self::registerPreviewHooks(); self::registerShareHooks(); //make sure temporary files are cleaned up @@ -539,6 +540,14 @@ class OC { OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted'); } + /** + * register hooks for previews + */ + public static function registerPreviewHooks() { + OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_Preview', 'post_write'); + OC_Hook::connect('OC_Filesystem', 'delete', 'OC_Preview', 'post_delete'); + } + /** * register hooks for sharing */ diff --git a/lib/preview.php b/lib/preview.php index 6fc166b9c7..7c4db971df 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -55,7 +55,7 @@ class OC_Preview { * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ - public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true){ + public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true, $force = false){ //set config $this->max_x = OC_Config::getValue('preview_max_x', null); $this->max_y = OC_Config::getValue('preview_max_y', null); @@ -71,47 +71,49 @@ class OC_Preview { $this->fileview = new \OC\Files\View('/' . $user . '/' . $root); $this->userview = new \OC\Files\View('/' . $user); - if(!is_null($this->max_x)){ - if($this->maxX > $this->max_x){ - OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, OC_Log::DEBUG); - $this->maxX = $this->max_x; + if($force !== true){ + if(!is_null($this->max_x)){ + if($this->maxX > $this->max_x){ + OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, OC_Log::DEBUG); + $this->maxX = $this->max_x; + } } - } - - if(!is_null($this->max_y)){ - if($this->maxY > $this->max_y){ - OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, OC_Log::DEBUG); - $this->maxY = $this->max_y; + + if(!is_null($this->max_y)){ + if($this->maxY > $this->max_y){ + OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, OC_Log::DEBUG); + $this->maxY = $this->max_y; + } + } + + //init providers + if(empty(self::$providers)){ + self::initProviders(); + } + + //check if there are any providers at all + if(empty(self::$providers)){ + OC_Log::write('core', 'No preview providers exist', OC_Log::ERROR); + throw new Exception('No providers'); + } + + //validate parameters + if($file === ''){ + OC_Log::write('core', 'No filename passed', OC_Log::ERROR); + throw new Exception('File not found'); + } + + //check if file exists + if(!$this->fileview->file_exists($file)){ + OC_Log::write('core', 'File:"' . $file . '" not found', OC_Log::ERROR); + throw new Exception('File not found'); + } + + //check if given size makes sense + if($maxX === 0 || $maxY === 0){ + OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::ERROR); + throw new Exception('Height and/or width set to 0'); } - } - - //init providers - if(empty(self::$providers)){ - self::initProviders(); - } - - //check if there are any providers at all - if(empty(self::$providers)){ - OC_Log::write('core', 'No preview providers exist', OC_Log::ERROR); - throw new Exception('No providers'); - } - - //validate parameters - if($file === ''){ - OC_Log::write('core', 'No filename passed', OC_Log::ERROR); - throw new Exception('File not found'); - } - - //check if file exists - if(!$this->fileview->file_exists($file)){ - OC_Log::write('core', 'File:"' . $file . '" not found', OC_Log::ERROR); - throw new Exception('File not found'); - } - - //check if given size makes sense - if($maxX === 0 || $maxY === 0){ - OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::ERROR); - throw new Exception('Height and/or width set to 0'); } } @@ -186,19 +188,22 @@ class OC_Preview { public function deletePreview(){ $fileinfo = $this->fileview->getFileInfo($this->file); $fileid = $fileinfo['fileid']; - - return $this->userview->unlink(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $this->maxX . '-' . $this->maxY . '.png'); + + $this->userview->unlink(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $this->maxX . '-' . $this->maxY . '.png'); + return; } /** * @brief deletes all previews of a file * @return bool */ - public function deleteAllPrevies(){ + public function deleteAllPreviews(){ $fileinfo = $this->fileview->getFileInfo($this->file); $fileid = $fileinfo['fileid']; - return $this->userview->rmdir(self::THUMBNAILS_FOLDER . '/' . $fileid); + $this->userview->deleteAll(self::THUMBNAILS_FOLDER . '/' . $fileid . '/'); + $this->userview->rmdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/'); + return; } /** @@ -577,4 +582,17 @@ class OC_Preview { exit; } } + + public static function post_write($args){ + self::post_delete($args); + } + + public static function post_delete($args){ + $path = $args['path']; + if(substr($path, 0, 1) == '/'){ + $path = substr($path, 1); + } + $preview = new OC_Preview(OC_User::getUser(), 'files/', $path, 0, 0, false, true); + $preview->deleteAllPreviews(); + } } \ No newline at end of file From fa6b96090abc341da4f9320af02ee75b29a204e6 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 12:33:24 +0200 Subject: [PATCH 0030/1989] move to OC namespace --- core/routes.php | 4 +-- lib/base.php | 4 +-- lib/preview.php | 64 +++++++++++++++++++++------------------- lib/preview/images.php | 6 ++-- lib/preview/movies.php | 8 +++-- lib/preview/mp3.php | 10 ++++--- lib/preview/pdf.php | 8 +++-- lib/preview/provider.php | 4 ++- lib/preview/svg.php | 16 +++++++--- lib/preview/txt.php | 6 ++-- lib/preview/unknown.php | 6 ++-- 11 files changed, 80 insertions(+), 56 deletions(-) diff --git a/core/routes.php b/core/routes.php index c45ffee26f..4b3ad53da0 100644 --- a/core/routes.php +++ b/core/routes.php @@ -43,9 +43,9 @@ $this->create('js_config', '/core/js/config.js') $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); $this->create('core_ajax_preview', '/core/preview.png') - ->action('OC_Preview', 'previewRouter'); + ->action('OC\Preview', 'previewRouter'); $this->create('core_ajax_public_preview', '/core/publicpreview.png') - ->action('OC_Preview', 'publicPreviewRouter'); + ->action('OC\Preview', 'publicPreviewRouter'); OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; $this->create('core_lostpassword_index', '/lostpassword/') ->get() diff --git a/lib/base.php b/lib/base.php index ae384225be..525b259f67 100644 --- a/lib/base.php +++ b/lib/base.php @@ -544,8 +544,8 @@ class OC { * register hooks for previews */ public static function registerPreviewHooks() { - OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_Preview', 'post_write'); - OC_Hook::connect('OC_Filesystem', 'delete', 'OC_Preview', 'post_delete'); + OC_Hook::connect('OC_Filesystem', 'post_write', 'OC\Preview', 'post_write'); + OC_Hook::connect('OC_Filesystem', 'delete', 'OC\Preview', 'post_delete'); } /** diff --git a/lib/preview.php b/lib/preview.php index 7c4db971df..31812035c4 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -11,6 +11,8 @@ * /data/user/thumbnails/pathhash/x-y.png * */ +namespace OC; + require_once('preview/images.php'); require_once('preview/movies.php'); require_once('preview/mp3.php'); @@ -19,7 +21,7 @@ require_once('preview/svg.php'); require_once('preview/txt.php'); require_once('preview/unknown.php'); -class OC_Preview { +class Preview { //the thumbnail folder const THUMBNAILS_FOLDER = 'thumbnails'; @@ -57,9 +59,9 @@ class OC_Preview { */ public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true, $force = false){ //set config - $this->max_x = OC_Config::getValue('preview_max_x', null); - $this->max_y = OC_Config::getValue('preview_max_y', null); - $this->max_scale_factor = OC_Config::getValue('preview_max_scale_factor', 10); + $this->max_x = \OC_Config::getValue('preview_max_x', null); + $this->max_y = \OC_Config::getValue('preview_max_y', null); + $this->max_scale_factor = \OC_Config::getValue('preview_max_scale_factor', 10); //save parameters $this->file = $file; @@ -74,14 +76,14 @@ class OC_Preview { if($force !== true){ if(!is_null($this->max_x)){ if($this->maxX > $this->max_x){ - OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, OC_Log::DEBUG); + \OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, \OC_Log::DEBUG); $this->maxX = $this->max_x; } } if(!is_null($this->max_y)){ if($this->maxY > $this->max_y){ - OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, OC_Log::DEBUG); + \OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, \OC_Log::DEBUG); $this->maxY = $this->max_y; } } @@ -93,26 +95,26 @@ class OC_Preview { //check if there are any providers at all if(empty(self::$providers)){ - OC_Log::write('core', 'No preview providers exist', OC_Log::ERROR); - throw new Exception('No providers'); + \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); + throw new \Exception('No providers'); } //validate parameters if($file === ''){ - OC_Log::write('core', 'No filename passed', OC_Log::ERROR); - throw new Exception('File not found'); + \OC_Log::write('core', 'No filename passed', \OC_Log::ERROR); + throw new \Exception('File not found'); } //check if file exists if(!$this->fileview->file_exists($file)){ - OC_Log::write('core', 'File:"' . $file . '" not found', OC_Log::ERROR); - throw new Exception('File not found'); + \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::ERROR); + throw new \Exception('File not found'); } //check if given size makes sense if($maxX === 0 || $maxY === 0){ - OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::ERROR); - throw new Exception('Height and/or width set to 0'); + \OC_Log::write('core', 'Can not create preview with 0px width or 0px height', \OC_Log::ERROR); + throw new \Exception('Height and/or width set to 0'); } } } @@ -353,7 +355,7 @@ class OC_Preview { * @return void */ public function showPreview(){ - OCP\Response::enableCaching(3600 * 24); // 24 hour + \OCP\Response::enableCaching(3600 * 24); // 24 hour $preview = $this->getPreview(); if($preview){ $preview->show(); @@ -373,7 +375,7 @@ class OC_Preview { $scalingup = $this->scalingup; if(!($image instanceof \OC_Image)){ - OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', OC_Log::DEBUG); + OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', \OC_Log::DEBUG); return; } @@ -399,7 +401,7 @@ class OC_Preview { } if(!is_null($this->max_scale_factor)){ if($factor > $this->max_scale_factor){ - OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $this->max_scale_factor, OC_Log::DEBUG); + \OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $this->max_scale_factor, \OC_Log::DEBUG); $factor = $this->max_scale_factor; } } @@ -462,7 +464,7 @@ class OC_Preview { /** * @brief register a new preview provider to be used - * @param string $provider class name of a OC_Preview_Provider + * @param string $provider class name of a Preview_Provider * @return void */ public static function registerProvider($class, $options=array()){ @@ -496,7 +498,7 @@ class OC_Preview { * @return void */ public static function previewRouter($params){ - OC_Util::checkLoggedIn(); + \OC_Util::checkLoggedIn(); $file = ''; $maxX = 0; @@ -514,15 +516,15 @@ class OC_Preview { if($file !== '' && $maxX !== 0 && $maxY !== 0){ try{ - $preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); + $preview = new Preview(\OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); $preview->showPreview(); }catch(Exception $e){ - OC_Response::setStatus(404); - OC_Log::write('core', $e->getmessage(), OC_Log::ERROR); + \OC_Response::setStatus(404); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); exit; } }else{ - OC_Response::setStatus(404); + \OC_Response::setStatus(404); exit; } } @@ -547,11 +549,11 @@ class OC_Preview { if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; if(array_key_exists('t', $_GET)) $token = (string) $_GET['t']; - $linkItem = OCP\Share::getShareByToken($token); + $linkItem = \OCP\Share::getShareByToken($token); if (is_array($linkItem) && isset($linkItem['uid_owner']) && isset($linkItem['file_source'])) { $userid = $linkItem['uid_owner']; - OC_Util::setupFS($userid); + \OC_Util::setupFS($userid); $pathid = $linkItem['file_source']; $path = \OC\Files\Filesystem::getPath($pathid); } @@ -559,7 +561,7 @@ class OC_Preview { //clean up file parameter $file = \OC\Files\Filesystem::normalizePath($file); if(!\OC\Files\Filesystem::isValidPath($file)){ - OC_Response::setStatus(403); + \OC_Response::setStatus(403); exit; } @@ -570,15 +572,15 @@ class OC_Preview { if($userid !== null && $path !== null){ try{ - $preview = new OC_Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); + $preview = new Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); $preview->showPreview(); }catch(Exception $e){ - OC_Response::setStatus(404); - OC_Log::write('core', $e->getmessage(), OC_Log::ERROR); + \OC_Response::setStatus(404); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); exit; } }else{ - OC_Response::setStatus(404); + \OC_Response::setStatus(404); exit; } } @@ -592,7 +594,7 @@ class OC_Preview { if(substr($path, 0, 1) == '/'){ $path = substr($path, 1); } - $preview = new OC_Preview(OC_User::getUser(), 'files/', $path, 0, 0, false, true); + $preview = new Preview(\OC_User::getUser(), 'files/', $path, 0, 0, false, true); $preview->deleteAllPreviews(); } } \ No newline at end of file diff --git a/lib/preview/images.php b/lib/preview/images.php index a8f203528c..c62fc5397e 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -6,7 +6,9 @@ * later. * See the COPYING-README file. */ -class OC_Preview_Image extends OC_Preview_Provider{ +namespace OC\Preview; + +class Image extends Provider{ public function getMimeType(){ return '/image\/.*/'; @@ -31,4 +33,4 @@ class OC_Preview_Image extends OC_Preview_Provider{ } } -OC_Preview::registerProvider('OC_Preview_Image'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\Image'); \ No newline at end of file diff --git a/lib/preview/movies.php b/lib/preview/movies.php index d2aaf730d6..14ac97b552 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -6,8 +6,10 @@ * later. * See the COPYING-README file. */ +namespace OC\Preview; + if(!is_null(shell_exec('ffmpeg -version'))){ - class OC_Preview_Movie extends OC_Preview_Provider{ + class Movie extends Provider{ public function getMimeType(){ return '/video\/.*/'; @@ -18,7 +20,7 @@ if(!is_null(shell_exec('ffmpeg -version'))){ $fileinfo = $fileview->getFileInfo($path); $abspath = $fileview->toTmpFile($path); - $tmppath = OC_Helper::tmpFile(); + $tmppath = \OC_Helper::tmpFile(); //$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . $tmppath; @@ -35,5 +37,5 @@ if(!is_null(shell_exec('ffmpeg -version'))){ } } - OC_Preview::registerProvider('OC_Preview_Movie'); + \OC\Preview::registerProvider('OC\Preview\Movie'); } \ No newline at end of file diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 18f5cfde37..d62c723078 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -5,22 +5,24 @@ * later. * See the COPYING-README file. */ +namespace OC\Preview; + require_once('getid3/getid3.php'); -class OC_Preview_MP3 extends OC_Preview_Provider{ +class MP3 extends Provider{ public function getMimeType(){ return '/audio\/mpeg/'; } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $getID3 = new getID3(); + $getID3 = new \getID3(); $tmppath = $fileview->toTmpFile($path); //Todo - add stream support $tags = $getID3->analyze($tmppath); - getid3_lib::CopyTagsToComments($tags); + \getid3_lib::CopyTagsToComments($tags); $picture = @$tags['id3v2']['APIC'][0]['data']; unlink($tmppath); @@ -38,4 +40,4 @@ class OC_Preview_MP3 extends OC_Preview_Provider{ } -OC_Preview::registerProvider('OC_Preview_MP3'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\MP3'); \ No newline at end of file diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index de5263f91d..4dd4538545 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -5,9 +5,11 @@ * later. * See the COPYING-README file. */ +namespace OC\Preview; + if (extension_loaded('imagick')){ - class OC_Preview_PDF extends OC_Preview_Provider{ + class PDF extends Provider{ public function getMimeType(){ return '/application\/pdf/'; @@ -17,7 +19,7 @@ if (extension_loaded('imagick')){ $tmppath = $fileview->toTmpFile($path); //create imagick object from pdf - $pdf = new imagick($tmppath . '[0]'); + $pdf = new \imagick($tmppath . '[0]'); $pdf->setImageFormat('jpg'); unlink($tmppath); @@ -31,5 +33,5 @@ if (extension_loaded('imagick')){ } } - OC_Preview::registerProvider('OC_Preview_PDF'); + \OC\Preview::registerProvider('OC\Preview\PDF'); } diff --git a/lib/preview/provider.php b/lib/preview/provider.php index 2f2a0e6848..1e8d537adc 100644 --- a/lib/preview/provider.php +++ b/lib/preview/provider.php @@ -2,7 +2,9 @@ /** * provides search functionalty */ -abstract class OC_Preview_Provider{ +namespace OC\Preview; + +abstract class Provider{ private $options; public function __construct($options) { diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 415b7751c2..70be263189 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -5,18 +5,26 @@ * later. * See the COPYING-README file. */ +namespace OC\Preview; + if (extension_loaded('imagick')){ - class OC_Preview_SVG extends OC_Preview_Provider{ + class SVG extends Provider{ public function getMimeType(){ return '/image\/svg\+xml/'; } public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { - $svg = new Imagick(); + $svg = new \Imagick(); $svg->setResolution($maxX, $maxY); - $svg->readImageBlob('' . $fileview->file_get_contents($path)); + + $content = stream_get_contents($fileview->fopen($path, 'r')); + if(substr($content, 0, 5) !== '' . $content; + } + + $svg->readImageBlob($content); $svg->setImageFormat('jpg'); //new image object @@ -28,6 +36,6 @@ if (extension_loaded('imagick')){ } } - OC_Preview::registerProvider('OC_Preview_SVG'); + \OC\Preview::registerProvider('OC\Preview\SVG'); } \ No newline at end of file diff --git a/lib/preview/txt.php b/lib/preview/txt.php index 1e88aec69f..4004ecd3fc 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -5,7 +5,9 @@ * later. * See the COPYING-README file. */ -class OC_Preview_TXT extends OC_Preview_Provider{ +namespace OC\Preview; + +class TXT extends Provider{ public function getMimeType(){ return '/text\/.*/'; @@ -46,4 +48,4 @@ class OC_Preview_TXT extends OC_Preview_Provider{ } } -OC_Preview::registerProvider('OC_Preview_TXT'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\TXT'); \ No newline at end of file diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 5bbdcf847f..6a8d2fbb75 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -6,7 +6,9 @@ * later. * See the COPYING-README file. */ -class OC_Preview_Unknown extends OC_Preview_Provider{ +namespace OC\Preview; + +class Unknown extends Provider{ public function getMimeType(){ return '/.*/'; @@ -22,4 +24,4 @@ class OC_Preview_Unknown extends OC_Preview_Provider{ } } -OC_Preview::registerProvider('OC_Preview_Unknown'); +\OC\Preview::registerProvider('OC\Preview\Unknown'); From 268246fac833837d7b9e7a6a2a4559cfadc0a7ab Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 12:48:21 +0200 Subject: [PATCH 0031/1989] namespace fix --- lib/preview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 31812035c4..855d5a9da0 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -375,7 +375,7 @@ class Preview { $scalingup = $this->scalingup; if(!($image instanceof \OC_Image)){ - OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', \OC_Log::DEBUG); + \OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', \OC_Log::DEBUG); return; } From 7408ab660af2c681ca6abfb15d6230382f35dd7c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 13:03:33 +0200 Subject: [PATCH 0032/1989] respect coding style guidelines --- lib/preview.php | 136 +++++++++++++++++++-------------------- lib/preview/images.php | 6 +- lib/preview/movies.php | 6 +- lib/preview/mp3.php | 4 +- lib/preview/pdf.php | 4 +- lib/preview/provider.php | 2 +- lib/preview/svg.php | 6 +- lib/preview/txt.php | 8 +-- lib/preview/unknown.php | 4 +- 9 files changed, 88 insertions(+), 88 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 855d5a9da0..1150681e64 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -57,7 +57,7 @@ class Preview { * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ - public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true, $force = false){ + public function __construct($user=null, $root='', $file='', $maxX=0, $maxY=0, $scalingup=true, $force=false) { //set config $this->max_x = \OC_Config::getValue('preview_max_x', null); $this->max_y = \OC_Config::getValue('preview_max_y', null); @@ -73,46 +73,46 @@ class Preview { $this->fileview = new \OC\Files\View('/' . $user . '/' . $root); $this->userview = new \OC\Files\View('/' . $user); - if($force !== true){ - if(!is_null($this->max_x)){ - if($this->maxX > $this->max_x){ + if($force !== true) { + if(!is_null($this->max_x)) { + if($this->maxX > $this->max_x) { \OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, \OC_Log::DEBUG); $this->maxX = $this->max_x; } } - if(!is_null($this->max_y)){ - if($this->maxY > $this->max_y){ + if(!is_null($this->max_y)) { + if($this->maxY > $this->max_y) { \OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, \OC_Log::DEBUG); $this->maxY = $this->max_y; } } //init providers - if(empty(self::$providers)){ + if(empty(self::$providers)) { self::initProviders(); } //check if there are any providers at all - if(empty(self::$providers)){ + if(empty(self::$providers)) { \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); throw new \Exception('No providers'); } //validate parameters - if($file === ''){ + if($file === '') { \OC_Log::write('core', 'No filename passed', \OC_Log::ERROR); throw new \Exception('File not found'); } //check if file exists - if(!$this->fileview->file_exists($file)){ + if(!$this->fileview->file_exists($file)) { \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::ERROR); throw new \Exception('File not found'); } //check if given size makes sense - if($maxX === 0 || $maxY === 0){ + if($maxX === 0 || $maxY === 0) { \OC_Log::write('core', 'Can not create preview with 0px width or 0px height', \OC_Log::ERROR); throw new \Exception('Height and/or width set to 0'); } @@ -123,7 +123,7 @@ class Preview { * @brief returns the path of the file you want a thumbnail from * @return string */ - public function getFile(){ + public function getFile() { return $this->file; } @@ -131,7 +131,7 @@ class Preview { * @brief returns the max width of the preview * @return integer */ - public function getMaxX(){ + public function getMaxX() { return $this->maxX; } @@ -139,7 +139,7 @@ class Preview { * @brief returns the max height of the preview * @return integer */ - public function getMaxY(){ + public function getMaxY() { return $this->maxY; } @@ -147,7 +147,7 @@ class Preview { * @brief returns whether or not scalingup is enabled * @return bool */ - public function getScalingup(){ + public function getScalingup() { return $this->scalingup; } @@ -155,7 +155,7 @@ class Preview { * @brief returns the name of the thumbnailfolder * @return string */ - public function getThumbnailsfolder(){ + public function getThumbnailsfolder() { return self::THUMBNAILS_FOLDER; } @@ -163,7 +163,7 @@ class Preview { * @brief returns the max scale factor * @return integer */ - public function getMaxScaleFactor(){ + public function getMaxScaleFactor() { return $this->max_scale_factor; } @@ -171,7 +171,7 @@ class Preview { * @brief returns the max width set in ownCloud's config * @return integer */ - public function getConfigMaxX(){ + public function getConfigMaxX() { return $this->max_x; } @@ -179,7 +179,7 @@ class Preview { * @brief returns the max height set in ownCloud's config * @return integer */ - public function getConfigMaxY(){ + public function getConfigMaxY() { return $this->max_y; } @@ -187,7 +187,7 @@ class Preview { * @brief deletes previews of a file with specific x and y * @return bool */ - public function deletePreview(){ + public function deletePreview() { $fileinfo = $this->fileview->getFileInfo($this->file); $fileid = $fileinfo['fileid']; @@ -199,7 +199,7 @@ class Preview { * @brief deletes all previews of a file * @return bool */ - public function deleteAllPreviews(){ + public function deleteAllPreviews() { $fileinfo = $this->fileview->getFileInfo($this->file); $fileid = $fileinfo['fileid']; @@ -214,7 +214,7 @@ class Preview { * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ - private function isCached(){ + private function isCached() { $file = $this->file; $maxX = $this->maxX; $maxY = $this->maxY; @@ -223,12 +223,12 @@ class Preview { $fileinfo = $this->fileview->getFileInfo($file); $fileid = $fileinfo['fileid']; - if(!$this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid)){ + if(!$this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid)) { return false; } //does a preview with the wanted height and width already exist? - if($this->userview->file_exists(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')){ + if($this->userview->file_exists(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')) { return self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png'; } @@ -238,20 +238,20 @@ class Preview { $possiblethumbnails = array(); $allthumbnails = $this->userview->getDirectoryContent(self::THUMBNAILS_FOLDER . '/' . $fileid); - foreach($allthumbnails as $thumbnail){ + foreach($allthumbnails as $thumbnail) { $size = explode('-', $thumbnail['name']); $x = $size[0]; $y = $size[1]; $aspectratio = $x / $y; - if($aspectratio != $wantedaspectratio){ + if($aspectratio != $wantedaspectratio) { continue; } - if($x < $maxX || $y < $maxY){ - if($scalingup){ + if($x < $maxX || $y < $maxY) { + if($scalingup) { $scalefactor = $maxX / $x; - if($scalefactor > $this->max_scale_factor){ + if($scalefactor > $this->max_scale_factor) { continue; } }else{ @@ -261,26 +261,26 @@ class Preview { $possiblethumbnails[$x] = $thumbnail['path']; } - if(count($possiblethumbnails) === 0){ + if(count($possiblethumbnails) === 0) { return false; } - if(count($possiblethumbnails) === 1){ + if(count($possiblethumbnails) === 1) { return current($possiblethumbnails); } ksort($possiblethumbnails); - if(key(reset($possiblethumbnails)) > $maxX){ + if(key(reset($possiblethumbnails)) > $maxX) { return current(reset($possiblethumbnails)); } - if(key(end($possiblethumbnails)) < $maxX){ + if(key(end($possiblethumbnails)) < $maxX) { return current(end($possiblethumbnails)); } - foreach($possiblethumbnails as $width => $path){ - if($width < $maxX){ + foreach($possiblethumbnails as $width => $path) { + if($width < $maxX) { continue; }else{ return $path; @@ -296,7 +296,7 @@ class Preview { * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly * @return image */ - public function getPreview(){ + public function getPreview() { $file = $this->file; $maxX = $this->maxX; $maxY = $this->maxY; @@ -307,7 +307,7 @@ class Preview { $cached = self::isCached(); - if($cached){ + if($cached) { $image = new \OC_Image($this->userview->file_get_contents($cached, 'r')); $this->preview = $image; }else{ @@ -315,25 +315,25 @@ class Preview { $preview; - foreach(self::$providers as $supportedmimetype => $provider){ - if(!preg_match($supportedmimetype, $mimetype)){ + foreach(self::$providers as $supportedmimetype => $provider) { + if(!preg_match($supportedmimetype, $mimetype)) { continue; } $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup, $this->fileview); - if(!$preview){ + if(!$preview) { continue; } //are there any cached thumbnails yet - if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/') === false){ + if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/') === false) { $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/'); } //cache thumbnail $cachepath = self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png'; - if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/') === false){ + if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/') === false) { $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/'); } $this->userview->file_put_contents($cachepath, $preview->data()); @@ -354,10 +354,10 @@ class Preview { * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly * @return void */ - public function showPreview(){ + public function showPreview() { \OCP\Response::enableCaching(3600 * 24); // 24 hour $preview = $this->getPreview(); - if($preview){ + if($preview) { $preview->show(); } } @@ -366,7 +366,7 @@ class Preview { * @brief resize, crop and fix orientation * @return image */ - public function resizeAndCrop(){ + public function resizeAndCrop() { $this->preview->fixOrientation(); $image = $this->preview; @@ -374,7 +374,7 @@ class Preview { $y = $this->maxY; $scalingup = $this->scalingup; - if(!($image instanceof \OC_Image)){ + if(!($image instanceof \OC_Image)) { \OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', \OC_Log::DEBUG); return; } @@ -382,14 +382,14 @@ class Preview { $realx = (int) $image->width(); $realy = (int) $image->height(); - if($x === $realx && $y === $realy){ + if($x === $realx && $y === $realy) { return $image; } $factorX = $x / $realx; $factorY = $y / $realy; - if($factorX >= $factorY){ + if($factorX >= $factorY) { $factor = $factorX; }else{ $factor = $factorY; @@ -399,8 +399,8 @@ class Preview { if($scalingup === false) { if($factor>1) $factor=1; } - if(!is_null($this->max_scale_factor)){ - if($factor > $this->max_scale_factor){ + if(!is_null($this->max_scale_factor)) { + if($factor > $this->max_scale_factor) { \OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $this->max_scale_factor, \OC_Log::DEBUG); $factor = $this->max_scale_factor; } @@ -411,12 +411,12 @@ class Preview { // resize $image->preciseResize($newXsize, $newYsize); - if($newXsize === $x && $newYsize === $y){ + if($newXsize === $x && $newYsize === $y) { $this->preview = $image; return; } - if($newXsize >= $x && $newYsize >= $y){ + if($newXsize >= $x && $newYsize >= $y) { $cropX = floor(abs($x - $newXsize) * 0.5); $cropY = floor(abs($y - $newYsize) * 0.5); @@ -426,13 +426,13 @@ class Preview { return; } - if($newXsize < $x || $newYsize < $y){ - if($newXsize > $x){ + if($newXsize < $x || $newYsize < $y) { + if($newXsize > $x) { $cropX = floor(($newXsize - $x) * 0.5); $image->crop($cropX, 0, $x, $newYsize); } - if($newYsize > $y){ + if($newYsize > $y) { $cropY = floor(($newYsize - $y) * 0.5); $image->crop(0, $cropY, $newXsize, $y); } @@ -467,7 +467,7 @@ class Preview { * @param string $provider class name of a Preview_Provider * @return void */ - public static function registerProvider($class, $options=array()){ + public static function registerProvider($class, $options=array()) { self::$registeredProviders[]=array('class'=>$class, 'options'=>$options); } @@ -475,7 +475,7 @@ class Preview { * @brief create instances of all the registered preview providers * @return void */ - private static function initProviders(){ + private static function initProviders() { if(count(self::$providers)>0) { return; } @@ -497,7 +497,7 @@ class Preview { * @brief method that handles preview requests from users that are logged in * @return void */ - public static function previewRouter($params){ + public static function previewRouter($params) { \OC_Util::checkLoggedIn(); $file = ''; @@ -514,11 +514,11 @@ class Preview { if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y']; if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; - if($file !== '' && $maxX !== 0 && $maxY !== 0){ + if($file !== '' && $maxX !== 0 && $maxY !== 0) { try{ $preview = new Preview(\OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); $preview->showPreview(); - }catch(Exception $e){ + }catch(Exception $e) { \OC_Response::setStatus(404); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); exit; @@ -533,7 +533,7 @@ class Preview { * @brief method that handles preview requests from users that are not logged in / view shared folders that are public * @return void */ - public static function publicPreviewRouter($params){ + public static function publicPreviewRouter($params) { $file = ''; $maxX = 0; $maxY = 0; @@ -560,21 +560,21 @@ class Preview { //clean up file parameter $file = \OC\Files\Filesystem::normalizePath($file); - if(!\OC\Files\Filesystem::isValidPath($file)){ + if(!\OC\Files\Filesystem::isValidPath($file)) { \OC_Response::setStatus(403); exit; } $path = \OC\Files\Filesystem::normalizePath($path, false); - if(substr($path, 0, 1) == '/'){ + if(substr($path, 0, 1) == '/') { $path = substr($path, 1); } - if($userid !== null && $path !== null){ + if($userid !== null && $path !== null) { try{ $preview = new Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); $preview->showPreview(); - }catch(Exception $e){ + }catch(Exception $e) { \OC_Response::setStatus(404); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); exit; @@ -585,13 +585,13 @@ class Preview { } } - public static function post_write($args){ + public static function post_write($args) { self::post_delete($args); } - public static function post_delete($args){ + public static function post_delete($args) { $path = $args['path']; - if(substr($path, 0, 1) == '/'){ + if(substr($path, 0, 1) == '/') { $path = substr($path, 1); } $preview = new Preview(\OC_User::getUser(), 'files/', $path, 0, 0, false, true); diff --git a/lib/preview/images.php b/lib/preview/images.php index c62fc5397e..933d65ec59 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -10,16 +10,16 @@ namespace OC\Preview; class Image extends Provider{ - public function getMimeType(){ + public function getMimeType() { return '/image\/.*/'; } - public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { //get fileinfo $fileinfo = $fileview->getFileInfo($path); //check if file is encrypted - if($fileinfo['encrypted'] === true){ + if($fileinfo['encrypted'] === true) { $image = new \OC_Image($fileview->fopen($path, 'r')); }else{ $image = new \OC_Image(); diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 14ac97b552..aa97c3f43f 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -8,14 +8,14 @@ */ namespace OC\Preview; -if(!is_null(shell_exec('ffmpeg -version'))){ +if(!is_null(shell_exec('ffmpeg -version'))) { class Movie extends Provider{ - public function getMimeType(){ + public function getMimeType() { return '/video\/.*/'; } - public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { //get fileinfo $fileinfo = $fileview->getFileInfo($path); diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index d62c723078..cfe78f3272 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -11,7 +11,7 @@ require_once('getid3/getid3.php'); class MP3 extends Provider{ - public function getMimeType(){ + public function getMimeType() { return '/audio\/mpeg/'; } @@ -33,7 +33,7 @@ class MP3 extends Provider{ return $image; } - public function getNoCoverThumbnail($maxX, $maxY){ + public function getNoCoverThumbnail($maxX, $maxY) { $image = new \OC_Image(); return $image; } diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 4dd4538545..66570b05aa 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -7,11 +7,11 @@ */ namespace OC\Preview; -if (extension_loaded('imagick')){ +if (extension_loaded('imagick')) { class PDF extends Provider{ - public function getMimeType(){ + public function getMimeType() { return '/application\/pdf/'; } diff --git a/lib/preview/provider.php b/lib/preview/provider.php index 1e8d537adc..58e7ad7f45 100644 --- a/lib/preview/provider.php +++ b/lib/preview/provider.php @@ -18,5 +18,5 @@ abstract class Provider{ * @param string $query * @return */ - abstract public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview); + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); } diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 70be263189..746315d6e6 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -7,11 +7,11 @@ */ namespace OC\Preview; -if (extension_loaded('imagick')){ +if (extension_loaded('imagick')) { class SVG extends Provider{ - public function getMimeType(){ + public function getMimeType() { return '/image\/svg\+xml/'; } @@ -20,7 +20,7 @@ if (extension_loaded('imagick')){ $svg->setResolution($maxX, $maxY); $content = stream_get_contents($fileview->fopen($path, 'r')); - if(substr($content, 0, 5) !== '' . $content; } diff --git a/lib/preview/txt.php b/lib/preview/txt.php index 4004ecd3fc..5961761aaa 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -9,11 +9,11 @@ namespace OC\Preview; class TXT extends Provider{ - public function getMimeType(){ + public function getMimeType() { return '/text\/.*/'; } - public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); @@ -27,7 +27,7 @@ class TXT extends Provider{ $imagecolor = imagecolorallocate($image, 255, 255, 255); $textcolor = imagecolorallocate($image, 0, 0, 0); - foreach($lines as $index => $line){ + foreach($lines as $index => $line) { $index = $index + 1; $x = (int) 1; @@ -35,7 +35,7 @@ class TXT extends Provider{ imagestring($image, 1, $x, $y, $line, $textcolor); - if(($index * $linesize) >= $maxY){ + if(($index * $linesize) >= $maxY) { break; } } diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 6a8d2fbb75..2977cd6892 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -10,11 +10,11 @@ namespace OC\Preview; class Unknown extends Provider{ - public function getMimeType(){ + public function getMimeType() { return '/.*/'; } - public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { /*$mimetype = $fileview->getMimeType($path); $info = $fileview->getFileInfo($path); $name = array_key_exists('name', $info) ? $info['name'] : ''; From 6b90416891e9e0943a7b19f29017bf7d8140eb0a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 13:09:38 +0200 Subject: [PATCH 0033/1989] add php preview backend --- lib/preview/txt.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/preview/txt.php b/lib/preview/txt.php index 5961761aaa..def6806860 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -48,4 +48,14 @@ class TXT extends Provider{ } } -\OC\Preview::registerProvider('OC\Preview\TXT'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\TXT'); + +class PHP extends TXT { + + public function getMimeType() { + return '/application\/x-php/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PHP'); \ No newline at end of file From 1e252b67635aeed7fa8180a0868abd6442a3c42c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 13:11:43 +0200 Subject: [PATCH 0034/1989] more style fixes --- lib/preview/images.php | 2 +- lib/preview/movies.php | 3 ++- lib/preview/mp3.php | 4 ++-- lib/preview/pdf.php | 2 +- lib/preview/provider.php | 2 +- lib/preview/svg.php | 2 +- lib/preview/txt.php | 2 +- lib/preview/unknown.php | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/preview/images.php b/lib/preview/images.php index 933d65ec59..080e424e5b 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -8,7 +8,7 @@ */ namespace OC\Preview; -class Image extends Provider{ +class Image extends Provider { public function getMimeType() { return '/image\/.*/'; diff --git a/lib/preview/movies.php b/lib/preview/movies.php index aa97c3f43f..18e9d4f778 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -9,7 +9,8 @@ namespace OC\Preview; if(!is_null(shell_exec('ffmpeg -version'))) { - class Movie extends Provider{ + + class Movie extends Provider { public function getMimeType() { return '/video\/.*/'; diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index cfe78f3272..303626e022 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -1,4 +1,4 @@ - Date: Wed, 29 May 2013 13:13:47 +0200 Subject: [PATCH 0035/1989] fix c&p fail --- lib/preview/mp3.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 303626e022..3c6be5c922 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -1,4 +1,4 @@ -Provider{ Date: Thu, 30 May 2013 10:44:23 +0200 Subject: [PATCH 0036/1989] validate size of file --- lib/preview.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 1150681e64..be3abc2cd4 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -87,7 +87,15 @@ class Preview { $this->maxY = $this->max_y; } } - + + $fileinfo = $this->fileview->getFileInfo($this->file); + if(array_key_exists('size', $fileinfo)){ + if((int) $fileinfo['size'] === 0){ + \OC_Log::write('core', 'You can\'t generate a preview of a 0 byte file (' . $this->file . ')', \OC_Log::ERROR); + throw new \Exception('0 byte file given'); + } + } + //init providers if(empty(self::$providers)) { self::initProviders(); @@ -518,7 +526,7 @@ class Preview { try{ $preview = new Preview(\OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup); $preview->showPreview(); - }catch(Exception $e) { + }catch(\Exception $e) { \OC_Response::setStatus(404); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); exit; @@ -574,7 +582,7 @@ class Preview { try{ $preview = new Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); $preview->showPreview(); - }catch(Exception $e) { + }catch(\Exception $e) { \OC_Response::setStatus(404); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); exit; From a014662c52f5295a7e86cd43b7dd62b89e3f1085 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 30 May 2013 11:06:52 +0200 Subject: [PATCH 0037/1989] improve imagick error handling --- lib/preview/pdf.php | 9 +++++++-- lib/preview/svg.php | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 85878a122a..f1d0a33dc6 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -19,8 +19,13 @@ if (extension_loaded('imagick')) { $tmppath = $fileview->toTmpFile($path); //create imagick object from pdf - $pdf = new \imagick($tmppath . '[0]'); - $pdf->setImageFormat('jpg'); + try{ + $pdf = new \imagick($tmppath . '[0]'); + $pdf->setImageFormat('jpg'); + }catch(\Exception $e){ + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; + } unlink($tmppath); diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 8bceeaf60d..76d81589ba 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -16,17 +16,22 @@ if (extension_loaded('imagick')) { } public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { - $svg = new \Imagick(); - $svg->setResolution($maxX, $maxY); + try{ + $svg = new \Imagick(); + $svg->setResolution($maxX, $maxY); - $content = stream_get_contents($fileview->fopen($path, 'r')); - if(substr($content, 0, 5) !== '' . $content; + $content = stream_get_contents($fileview->fopen($path, 'r')); + if(substr($content, 0, 5) !== '' . $content; + } + + $svg->readImageBlob($content); + $svg->setImageFormat('jpg'); + }catch(\Exception $e){ + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; } - $svg->readImageBlob($content); - $svg->setImageFormat('jpg'); - //new image object $image = new \OC_Image($svg); //check if image object is valid From b944b1c5d29393e1b6f0bc51cf50db6eba356e64 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 30 May 2013 11:12:12 +0200 Subject: [PATCH 0038/1989] add javascript preview backend --- lib/preview/txt.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/preview/txt.php b/lib/preview/txt.php index 4eb0e82040..f18da66c3b 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -58,4 +58,14 @@ class PHP extends TXT { } -\OC\Preview::registerProvider('OC\Preview\PHP'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\PHP'); + +class JavaScript extends TXT { + + public function getMimeType() { + return '/application\/javascript/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\JavaScript'); \ No newline at end of file From f7c80a391d192a15d594c3eaf7909a3d78df1a29 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 30 May 2013 15:29:38 +0200 Subject: [PATCH 0039/1989] load getID3 only if needed --- lib/preview/mp3.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 3c6be5c922..660e9fc3ce 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -7,8 +7,6 @@ */ namespace OC\Preview; -require_once('getid3/getid3.php'); - class MP3 extends Provider { public function getMimeType() { @@ -16,6 +14,8 @@ class MP3 extends Provider { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + require_once('getid3/getid3.php'); + $getID3 = new \getID3(); $tmppath = $fileview->toTmpFile($path); From a11a40d9a96685d41e5acae096752f16785b16b5 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 31 May 2013 12:23:51 +0200 Subject: [PATCH 0040/1989] add backend for microsoft office 2007 documents --- lib/preview.php | 2 + lib/preview/msoffice.php | 109 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 lib/preview/msoffice.php diff --git a/lib/preview.php b/lib/preview.php index be3abc2cd4..a73f4cb1ac 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -20,6 +20,8 @@ require_once('preview/pdf.php'); require_once('preview/svg.php'); require_once('preview/txt.php'); require_once('preview/unknown.php'); +require_once('preview/msoffice.php'); +//require_once('preview/opendocument.php'); class Preview { //the thumbnail folder diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php new file mode 100644 index 0000000000..c99ca313c7 --- /dev/null +++ b/lib/preview/msoffice.php @@ -0,0 +1,109 @@ +toTmpFile($path); + + $transformdoc = new \TransformDoc(); + $transformdoc->setStrFile($tmpdoc); + $transformdoc->generatePDF($tmpdoc); + + $pdf = new \imagick($tmpdoc . '[0]'); + $pdf->setImageFormat('jpg'); + + unlink($tmpdoc); + + //new image object + $image = new \OC_Image($pdf); + //check if image object is valid + if (!$image->valid()) return false; + + return $image; + } +} + +class DOC extends MSOffice2003 { + + public function getMimeType() { + return '/application\/msword/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\DOC'); + +class DOCX extends MSOffice2007 { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\DOCX'); + +class XLS extends MSOffice2003 { + + public function getMimeType() { + return '/application\/vnd.ms-excel/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\XLS'); + +class XLSX extends MSOffice2007 { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\XLSX'); + +class PPT extends MSOffice2003 { + + public function getMimeType() { + return '/application\/vnd.ms-powerpoint/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PPT'); + +class PPTX extends MSOffice2007 { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.presentationml.presentation/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PPTX'); \ No newline at end of file From 34decf357697a81c23e844ef606c04a20a08c597 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 3 Jun 2013 11:24:31 +0200 Subject: [PATCH 0041/1989] save current work state --- lib/preview.php | 2 +- lib/preview/libreoffice-cl.php | 0 lib/preview/office.php | 13 +++++++++++++ lib/preview/opendocument.php | 0 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/preview/libreoffice-cl.php create mode 100644 lib/preview/office.php create mode 100644 lib/preview/opendocument.php diff --git a/lib/preview.php b/lib/preview.php index a73f4cb1ac..4705efe210 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -20,7 +20,7 @@ require_once('preview/pdf.php'); require_once('preview/svg.php'); require_once('preview/txt.php'); require_once('preview/unknown.php'); -require_once('preview/msoffice.php'); +//require_once('preview/msoffice.php'); //require_once('preview/opendocument.php'); class Preview { diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/preview/office.php b/lib/preview/office.php new file mode 100644 index 0000000000..c66f5584f0 --- /dev/null +++ b/lib/preview/office.php @@ -0,0 +1,13 @@ + Date: Wed, 5 Jun 2013 10:50:20 +0200 Subject: [PATCH 0042/1989] save current work state of libreoffice preview backend --- lib/preview/libreoffice-cl.php | 129 +++++++++++++++++++++++++++++++++ lib/preview/office.php | 4 +- 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index e69de29bb2..1408e69e8c 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -0,0 +1,129 @@ +initCmd(); + if(is_null($this->cmd)) { + return false; + } + + $abspath = $fileview->toTmpFile($path); + + chdir(get_temp_dir()); + + $exec = 'libreoffice --headless -convert-to pdf ' . escapeshellarg($abspath); + exec($exec) + + //create imagick object from pdf + try{ + $pdf = new \imagick($abspath . '.pdf' . '[0]'); + $pdf->setImageFormat('jpg'); + }catch(\Exception $e){ + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; + } + + $image = new \OC_Image($pdf); + + unlink($abspath); + unlink($tmppath); + if (!$image->valid()) return false; + + return $image; + } + + private function initCmd() { + $cmd = ''; + + if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + $cmd = \OC_Config::getValue('preview_libreoffice_path', null); + } + + if($cmd === '' && shell_exec('libreoffice --headless --version')) { + $cmd = 'libreoffice'; + } + + if($cmd === '' && shell_exec('openoffice --headless --version')) { + $cmd = 'openoffice'; + } + + if($cmd === '') { + $cmd = null; + } + + $this->cmd = $cmd; + } + } +} + +//.doc, .dot +class MSOfficeDoc extends Office { + + public function getMimeType() { + return '/application\/msword/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc'); + +//.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m) +class MSOffice2003 extends Office { + + public function getMimeType() { + return '/application\/vnd.ms-.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\MSOffice2003'); + +//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx +class MSOffice2007 extends Office { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\MSOffice2007'); + +//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt +class OpenDocument extends Office { + + public function getMimeType() { + return '/application\/vnd.oasis.opendocument.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\OpenDocument'); + +//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm +class StarOffice extends Office { + + public function getMimeType() { + return '/application\/vnd.sun.xml.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\StarOffice'); \ No newline at end of file diff --git a/lib/preview/office.php b/lib/preview/office.php index c66f5584f0..cc1addf399 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -5,9 +5,11 @@ * later. * See the COPYING-README file. */ -if(shell_exec('libreoffice') || shell_exec('openoffice')) { +//let's see if there is libreoffice or openoffice on this machine +if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { require_once('libreoffice-cl.php'); }else{ + //in case there isn't, use our fallback require_once('msoffice.php'); require_once('opendocument.php'); } \ No newline at end of file From 749c33f39d9452e2c1fdca718e3abcdb7c4a9dd0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 10:53:16 +0200 Subject: [PATCH 0043/1989] escape tmppath shell arg --- lib/preview/movies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 18e9d4f778..8cd50263e2 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -24,7 +24,7 @@ if(!is_null(shell_exec('ffmpeg -version'))) { $tmppath = \OC_Helper::tmpFile(); //$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; - $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . $tmppath; + $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); shell_exec($cmd); unlink($abspath); From f437673f1a03ba5b2eeb3e79d24bf6ad3265aa0b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 10:55:57 +0200 Subject: [PATCH 0044/1989] update require_once block in preview.php --- lib/preview.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 4705efe210..f9f1288cb9 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -20,8 +20,7 @@ require_once('preview/pdf.php'); require_once('preview/svg.php'); require_once('preview/txt.php'); require_once('preview/unknown.php'); -//require_once('preview/msoffice.php'); -//require_once('preview/opendocument.php'); +require_once('preview/office.php'); class Preview { //the thumbnail folder From bab8b20cbdc65888d92477f9a5810ea4b114ada1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:06:36 +0200 Subject: [PATCH 0045/1989] use ->cmd instead of hardcoded libreoffice --- lib/preview/libreoffice-cl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 1408e69e8c..49c574c952 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -28,7 +28,7 @@ if (extension_loaded('imagick')) { chdir(get_temp_dir()); - $exec = 'libreoffice --headless -convert-to pdf ' . escapeshellarg($abspath); + $exec = $this->cmd . ' --headless -convert-to pdf ' . escapeshellarg($abspath); exec($exec) //create imagick object from pdf From 8c5fceba296ae76a0f22f3ed0324dec46ef16019 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:13:13 +0200 Subject: [PATCH 0046/1989] fix syntax error --- lib/preview/libreoffice-cl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 49c574c952..1b8e482fb2 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -29,7 +29,7 @@ if (extension_loaded('imagick')) { chdir(get_temp_dir()); $exec = $this->cmd . ' --headless -convert-to pdf ' . escapeshellarg($abspath); - exec($exec) + exec($exec); //create imagick object from pdf try{ From 78e8712366e2a198973f9a887c771894bef9a905 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:17:29 +0200 Subject: [PATCH 0047/1989] update config.sample.php --- config/config.sample.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/config.sample.php b/config/config.sample.php index db6eaf852a..2f437771f2 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -191,4 +191,6 @@ $CONFIG = array( 'preview_max_y' => null, /* the max factor to scale a preview, default is set to 10 */ 'preview_max_scale_factor' => 10, +/* custom path for libreoffice / openoffice binary */ +'preview_libreoffice_path' => '/usr/bin/libreoffice'; ); From 5c1d4fc186b692508f718c06218621bddcfd8f22 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:18:57 +0200 Subject: [PATCH 0048/1989] yet another update for config.sample.php --- config/config.sample.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.sample.php b/config/config.sample.php index 2f437771f2..2812d84813 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -192,5 +192,5 @@ $CONFIG = array( /* the max factor to scale a preview, default is set to 10 */ 'preview_max_scale_factor' => 10, /* custom path for libreoffice / openoffice binary */ -'preview_libreoffice_path' => '/usr/bin/libreoffice'; +'preview_libreoffice_path' => '/usr/bin/libreoffice', ); From 21cc4f6960618c41e81ca7e785a6d9e21c21ecf9 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 12:44:31 +0200 Subject: [PATCH 0049/1989] make libreoffice preview backend work :D --- lib/preview/libreoffice-cl.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 1b8e482fb2..5121a4c5a0 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -26,11 +26,13 @@ if (extension_loaded('imagick')) { $abspath = $fileview->toTmpFile($path); - chdir(get_temp_dir()); + $tmpdir = get_temp_dir(); + + $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath); + $export = 'export HOME=/tmp'; + + shell_exec($export . "\n" . $exec); - $exec = $this->cmd . ' --headless -convert-to pdf ' . escapeshellarg($abspath); - exec($exec); - //create imagick object from pdf try{ $pdf = new \imagick($abspath . '.pdf' . '[0]'); @@ -43,7 +45,8 @@ if (extension_loaded('imagick')) { $image = new \OC_Image($pdf); unlink($abspath); - unlink($tmppath); + unlink($abspath . '.pdf'); + if (!$image->valid()) return false; return $image; From f80aba48935e7325effaa65f899922927157028a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 12:58:39 +0200 Subject: [PATCH 0050/1989] use tmpdir var instead of hardcoded /tmp --- lib/preview/libreoffice-cl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 5121a4c5a0..33fa7a04e5 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -29,7 +29,7 @@ if (extension_loaded('imagick')) { $tmpdir = get_temp_dir(); $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath); - $export = 'export HOME=/tmp'; + $export = 'export HOME=/' . $tmpdir; shell_exec($export . "\n" . $exec); From 25e8ac1c2f51e7f3f35eaec013aa1b3f8356f17b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 10 Jun 2013 11:01:12 +0200 Subject: [PATCH 0051/1989] implement previews for single shared files --- lib/preview.php | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index f9f1288cb9..904689bc4e 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -557,31 +557,40 @@ class Preview { if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y']; if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup']; if(array_key_exists('t', $_GET)) $token = (string) $_GET['t']; - + $linkItem = \OCP\Share::getShareByToken($token); - + if (is_array($linkItem) && isset($linkItem['uid_owner']) && isset($linkItem['file_source'])) { $userid = $linkItem['uid_owner']; \OC_Util::setupFS($userid); + $pathid = $linkItem['file_source']; $path = \OC\Files\Filesystem::getPath($pathid); - } - - //clean up file parameter - $file = \OC\Files\Filesystem::normalizePath($file); - if(!\OC\Files\Filesystem::isValidPath($file)) { - \OC_Response::setStatus(403); - exit; + $pathinfo = \OC\Files\Filesystem::getFileInfo($path); + + $sharedfile = null; + if($linkItem['item_type'] === 'folder') { + //clean up file parameter + $sharedfile = \OC\Files\Filesystem::normalizePath($file); + if(!\OC\Files\Filesystem::isValidPath($file)) { + \OC_Response::setStatus(403); + exit; + } + } else if($linkItem['item_type'] === 'file') { + $parent = $pathinfo['parent']; + $path = \OC\Files\Filesystem::getPath($parent); + $sharedfile = $pathinfo['name']; + } + + $path = \OC\Files\Filesystem::normalizePath($path, false); + if(substr($path, 0, 1) == '/') { + $path = substr($path, 1); + } } - $path = \OC\Files\Filesystem::normalizePath($path, false); - if(substr($path, 0, 1) == '/') { - $path = substr($path, 1); - } - - if($userid !== null && $path !== null) { + if($userid !== null && $path !== null && $sharedfile !== null) { try{ - $preview = new Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup); + $preview = new Preview($userid, 'files/' . $path, $sharedfile, $maxX, $maxY, $scalingup); $preview->showPreview(); }catch(\Exception $e) { \OC_Response::setStatus(404); From 0e4f5001d5143f55a9d051b501fe32de900917c5 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 10:45:50 +0200 Subject: [PATCH 0052/1989] don't crop Y axis --- lib/preview.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 904689bc4e..ed33e7b09d 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -427,7 +427,8 @@ class Preview { if($newXsize >= $x && $newYsize >= $y) { $cropX = floor(abs($x - $newXsize) * 0.5); - $cropY = floor(abs($y - $newYsize) * 0.5); + //$cropY = floor(abs($y - $newYsize) * 0.5); + $cropY = 0; $image->crop($cropX, $cropY, $x, $y); From 2ff97917e9e72b674de07ca05dc04dd3bea14f07 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 10:56:16 +0200 Subject: [PATCH 0053/1989] code optimization --- lib/preview/images.php | 5 +---- lib/preview/movies.php | 5 ++--- lib/preview/mp3.php | 4 +--- lib/preview/pdf.php | 4 +--- lib/preview/svg.php | 4 +--- lib/preview/txt.php | 4 +--- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/preview/images.php b/lib/preview/images.php index 080e424e5b..e4041538e9 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -26,10 +26,7 @@ class Image extends Provider { $image->loadFromFile($fileview->getLocalFile($path)); } - //check if image object is valid - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 8cd50263e2..cb959a962a 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -27,14 +27,13 @@ if(!is_null(shell_exec('ffmpeg -version'))) { $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); shell_exec($cmd); - unlink($abspath); $image = new \OC_Image($tmppath); - if (!$image->valid()) return false; + unlink($abspath); unlink($tmppath); - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 660e9fc3ce..60dfb5ff46 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -28,9 +28,7 @@ class MP3 extends Provider { unlink($tmppath); $image = new \OC_Image($picture); - if (!$image->valid()) return $this->getNoCoverThumbnail($maxX, $maxY); - - return $image; + return $image->valid() ? $image : $this->getNoCoverThumbnail($maxX, $maxY); } public function getNoCoverThumbnail($maxX, $maxY) { diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index f1d0a33dc6..3eabd20115 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -32,9 +32,7 @@ if (extension_loaded('imagick')) { //new image object $image = new \OC_Image($pdf); //check if image object is valid - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 76d81589ba..bafaf71b15 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -35,9 +35,7 @@ if (extension_loaded('imagick')) { //new image object $image = new \OC_Image($svg); //check if image object is valid - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/txt.php b/lib/preview/txt.php index f18da66c3b..c7b8fabc6b 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -42,9 +42,7 @@ class TXT extends Provider { $image = new \OC_Image($image); - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } } From 28cf63d37d6a2b90ae32a2b5b7193a5f5c69830d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 11:00:44 +0200 Subject: [PATCH 0054/1989] check if imagick is loaded in office.php, not in libreoffice-cl.php --- lib/preview/libreoffice-cl.php | 93 ++++++++++++++++------------------ lib/preview/office.php | 17 ++++--- 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 33fa7a04e5..2749c4867e 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -8,71 +8,66 @@ namespace OC\Preview; //we need imagick to convert -if (extension_loaded('imagick')) { +class Office extends Provider { - class Office extends Provider { + private $cmd; - private $cmd; + public function getMimeType() { + return null; + } - public function getMimeType() { - return null; + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $this->initCmd(); + if(is_null($this->cmd)) { + return false; } - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $this->initCmd(); - if(is_null($this->cmd)) { - return false; - } + $abspath = $fileview->toTmpFile($path); - $abspath = $fileview->toTmpFile($path); + $tmpdir = get_temp_dir(); - $tmpdir = get_temp_dir(); + $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath); + $export = 'export HOME=/' . $tmpdir; - $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath); - $export = 'export HOME=/' . $tmpdir; + shell_exec($export . "\n" . $exec); - shell_exec($export . "\n" . $exec); - - //create imagick object from pdf - try{ - $pdf = new \imagick($abspath . '.pdf' . '[0]'); - $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - return false; - } - - $image = new \OC_Image($pdf); - - unlink($abspath); - unlink($abspath . '.pdf'); - - if (!$image->valid()) return false; - - return $image; + //create imagick object from pdf + try{ + $pdf = new \imagick($abspath . '.pdf' . '[0]'); + $pdf->setImageFormat('jpg'); + }catch(\Exception $e){ + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; } - private function initCmd() { - $cmd = ''; + $image = new \OC_Image($pdf); - if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { - $cmd = \OC_Config::getValue('preview_libreoffice_path', null); - } + unlink($abspath); + unlink($abspath . '.pdf'); - if($cmd === '' && shell_exec('libreoffice --headless --version')) { - $cmd = 'libreoffice'; - } + return $image->valid() ? $image : false; + } - if($cmd === '' && shell_exec('openoffice --headless --version')) { - $cmd = 'openoffice'; - } + private function initCmd() { + $cmd = ''; - if($cmd === '') { - $cmd = null; - } - - $this->cmd = $cmd; + if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + $cmd = \OC_Config::getValue('preview_libreoffice_path', null); } + + if($cmd === '' && shell_exec('libreoffice --headless --version')) { + $cmd = 'libreoffice'; + } + + if($cmd === '' && shell_exec('openoffice --headless --version')) { + $cmd = 'openoffice'; + } + + if($cmd === '') { + $cmd = null; + } + + $this->cmd = $cmd; } } diff --git a/lib/preview/office.php b/lib/preview/office.php index cc1addf399..20f545ef33 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -5,11 +5,14 @@ * later. * See the COPYING-README file. */ -//let's see if there is libreoffice or openoffice on this machine -if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { - require_once('libreoffice-cl.php'); -}else{ - //in case there isn't, use our fallback - require_once('msoffice.php'); - require_once('opendocument.php'); +//both, libreoffice backend and php fallback, need imagick +if (extension_loaded('imagick')) { + //let's see if there is libreoffice or openoffice on this machine + if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + require_once('libreoffice-cl.php'); + }else{ + //in case there isn't, use our fallback + require_once('msoffice.php'); + require_once('opendocument.php'); + } } \ No newline at end of file From 67816da0bfe16ecb58d3a3bdb70c1fb9a79cff75 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 13:15:24 +0200 Subject: [PATCH 0055/1989] save current work state of office fallback --- lib/preview/msoffice.php | 111 ++++++++++++++++++++++++----------- lib/preview/opendocument.php | 12 ++++ 2 files changed, 89 insertions(+), 34 deletions(-) diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index c99ca313c7..4fedb735c9 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -7,22 +7,24 @@ */ namespace OC\Preview; -class MSOffice2003 extends Provider { +class DOC extends Provider { - public function getMimeType(){ - return null; + public function getMimeType() { + return '/application\/msword/'; } - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview){ - return false; + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + } + } +\OC\Preview::registerProvider('OC\Preview\DOC'); -class MSOffice2007 extends Provider { +class DOCX extends Provider { - public function getMimeType(){ - return null; + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/'; } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { @@ -39,36 +41,50 @@ class MSOffice2007 extends Provider { unlink($tmpdoc); - //new image object $image = new \OC_Image($pdf); - //check if image object is valid - if (!$image->valid()) return false; - - return $image; - } -} - -class DOC extends MSOffice2003 { - - public function getMimeType() { - return '/application\/msword/'; - } - -} - -\OC\Preview::registerProvider('OC\Preview\DOC'); - -class DOCX extends MSOffice2007 { - - public function getMimeType() { - return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/'; + + return $image->valid() ? $image : false; } } \OC\Preview::registerProvider('OC\Preview\DOCX'); -class XLS extends MSOffice2003 { +class MSOfficeExcel extends Provider { + + public function getMimeType() { + return null; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + require_once('PHPExcel/Classes/PHPExcel.php'); + require_once('PHPExcel/Classes/PHPExcel/IOFactory.php'); + //require_once('mpdf/mpdf.php'); + + $abspath = $fileview->toTmpFile($path); + $tmppath = \OC_Helper::tmpFile(); + + $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; + $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/dompdf'; + + \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath); + + $phpexcel = new \PHPExcel($abspath); + $excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF'); + $excel->save($tmppath); + + $pdf = new \imagick($tmppath . '[0]'); + $pdf->setImageFormat('jpg'); + + unlink($abspath); + unlink($tmppath); + + return $image->valid() ? $image : false; + } + +} + +class XLS extends MSOfficeExcel { public function getMimeType() { return '/application\/vnd.ms-excel/'; @@ -78,7 +94,7 @@ class XLS extends MSOffice2003 { \OC\Preview::registerProvider('OC\Preview\XLS'); -class XLSX extends MSOffice2007 { +class XLSX extends MSOfficeExcel { public function getMimeType() { return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/'; @@ -88,7 +104,34 @@ class XLSX extends MSOffice2007 { \OC\Preview::registerProvider('OC\Preview\XLSX'); -class PPT extends MSOffice2003 { +class MSOfficePowerPoint extends Provider { + + public function getMimeType() { + return null; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + //require_once(''); + //require_once(''); + + $abspath = $fileview->toTmpFile($path); + $tmppath = \OC_Helper::tmpFile(); + + $excel = PHPPowerPoint_IOFactory::createWriter($abspath, 'PDF'); + $excel->save($tmppath); + + $pdf = new \imagick($tmppath . '[0]'); + $pdf->setImageFormat('jpg'); + + unlink($abspath); + unlink($tmppath); + + return $image->valid() ? $image : false; + } + +} + +class PPT extends MSOfficePowerPoint { public function getMimeType() { return '/application\/vnd.ms-powerpoint/'; @@ -98,7 +141,7 @@ class PPT extends MSOffice2003 { \OC\Preview::registerProvider('OC\Preview\PPT'); -class PPTX extends MSOffice2007 { +class PPTX extends MSOfficePowerPoint { public function getMimeType() { return '/application\/vnd.openxmlformats-officedocument.presentationml.presentation/'; diff --git a/lib/preview/opendocument.php b/lib/preview/opendocument.php index e69de29bb2..786a038ff8 100644 --- a/lib/preview/opendocument.php +++ b/lib/preview/opendocument.php @@ -0,0 +1,12 @@ + Date: Wed, 12 Jun 2013 11:40:01 +0200 Subject: [PATCH 0056/1989] finish implementation of Excel preview fallback --- lib/preview/msoffice.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index 4fedb735c9..c2e39d00d9 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -42,7 +42,7 @@ class DOCX extends Provider { unlink($tmpdoc); $image = new \OC_Image($pdf); - + return $image->valid() ? $image : false; } @@ -65,7 +65,7 @@ class MSOfficeExcel extends Provider { $tmppath = \OC_Helper::tmpFile(); $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; - $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/dompdf'; + $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf'; \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath); @@ -79,6 +79,8 @@ class MSOfficeExcel extends Provider { unlink($abspath); unlink($tmppath); + $image = new \OC_Image($pdf); + return $image->valid() ? $image : false; } From 1f52ad0363e2cff05e2058d31317b580c27e2c31 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 12 Jun 2013 13:20:59 +0200 Subject: [PATCH 0057/1989] work on powerpoint fallback --- lib/preview/msoffice.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index c2e39d00d9..65886169e9 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -59,7 +59,6 @@ class MSOfficeExcel extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { require_once('PHPExcel/Classes/PHPExcel.php'); require_once('PHPExcel/Classes/PHPExcel/IOFactory.php'); - //require_once('mpdf/mpdf.php'); $abspath = $fileview->toTmpFile($path); $tmppath = \OC_Helper::tmpFile(); @@ -113,14 +112,12 @@ class MSOfficePowerPoint extends Provider { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - //require_once(''); - //require_once(''); + return false; $abspath = $fileview->toTmpFile($path); $tmppath = \OC_Helper::tmpFile(); - $excel = PHPPowerPoint_IOFactory::createWriter($abspath, 'PDF'); - $excel->save($tmppath); + null; $pdf = new \imagick($tmppath . '[0]'); $pdf->setImageFormat('jpg'); @@ -128,6 +125,8 @@ class MSOfficePowerPoint extends Provider { unlink($abspath); unlink($tmppath); + $image = new \OC_Image($pdf); + return $image->valid() ? $image : false; } From f89a23b463884e1a9b89c84fdcb1c34afba62645 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 12 Jun 2013 16:18:16 +0200 Subject: [PATCH 0058/1989] implement unknown preview backend --- lib/preview/unknown.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 6b16142491..6e1dc06c1b 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -15,12 +15,24 @@ class Unknown extends Provider { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - /*$mimetype = $fileview->getMimeType($path); - $info = $fileview->getFileInfo($path); - $name = array_key_exists('name', $info) ? $info['name'] : ''; - $size = array_key_exists('size', $info) ? $info['size'] : 0; - $isencrypted = array_key_exists('encrypted', $info) ? $info['encrypted'] : false;*/ // show little lock - return new \OC_Image(); + $mimetype = $fileview->getMimeType($path); + if(substr_count($mimetype, '/')) { + list($type, $subtype) = explode('/', $mimetype); + } + + $iconsroot = \OC::$SERVERROOT . '/core/img/filetypes/'; + + $icons = array($mimetype, $type, 'text'); + foreach($icons as $icon) { + $icon = str_replace('/', '-', $icon); + + $iconpath = $iconsroot . $icon . '.png'; + + if(file_exists($iconpath)) { + return new \OC_Image($iconpath); + } + } + return false; } } From 25981a079a185080ad3ca2d2a23dd827efbd9d05 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 13 Jun 2013 09:52:39 +0200 Subject: [PATCH 0059/1989] some whitespace fixes --- lib/preview.php | 11 ++++++----- lib/preview/unknown.php | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index ed33e7b09d..3564fe3df4 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -41,6 +41,7 @@ class Preview { private $maxY; private $scalingup; + //preview images object private $preview; //preview providers @@ -81,7 +82,7 @@ class Preview { $this->maxX = $this->max_x; } } - + if(!is_null($this->max_y)) { if($this->maxY > $this->max_y) { \OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, \OC_Log::DEBUG); @@ -101,25 +102,25 @@ class Preview { if(empty(self::$providers)) { self::initProviders(); } - + //check if there are any providers at all if(empty(self::$providers)) { \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); throw new \Exception('No providers'); } - + //validate parameters if($file === '') { \OC_Log::write('core', 'No filename passed', \OC_Log::ERROR); throw new \Exception('File not found'); } - + //check if file exists if(!$this->fileview->file_exists($file)) { \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::ERROR); throw new \Exception('File not found'); } - + //check if given size makes sense if($maxX === 0 || $maxY === 0) { \OC_Log::write('core', 'Can not create preview with 0px width or 0px height', \OC_Log::ERROR); diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 6e1dc06c1b..4e1ca7de74 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -36,4 +36,4 @@ class Unknown extends Provider { } } -\OC\Preview::registerProvider('OC\Preview\Unknown'); +\OC\Preview::registerProvider('OC\Preview\Unknown'); \ No newline at end of file From 6082a0649cefd356370d4ca8034041c1af3875ff Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 17 Jun 2013 12:27:26 +0200 Subject: [PATCH 0060/1989] stream first mb of movie to create preview --- lib/preview/movies.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/preview/movies.php b/lib/preview/movies.php index cb959a962a..8531050d11 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -17,16 +17,18 @@ if(!is_null(shell_exec('ffmpeg -version'))) { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - //get fileinfo - $fileinfo = $fileview->getFileInfo($path); - - $abspath = $fileview->toTmpFile($path); + $abspath = \OC_Helper::tmpFile(); $tmppath = \OC_Helper::tmpFile(); - //$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; - $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); - shell_exec($cmd); + $handle = $fileview->fopen($path, 'rb'); + $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576 + file_put_contents($abspath, $firstmb); + + //$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; + $cmd = 'ffmpeg -an -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); + + shell_exec($cmd); $image = new \OC_Image($tmppath); From bea4376fd48e714b121e1abb54f9bd786e89c877 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 18 Jun 2013 11:04:08 +0200 Subject: [PATCH 0061/1989] remove opendocument.php --- lib/preview/office.php | 1 - lib/preview/opendocument.php | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100644 lib/preview/opendocument.php diff --git a/lib/preview/office.php b/lib/preview/office.php index 20f545ef33..b6783bc579 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -13,6 +13,5 @@ if (extension_loaded('imagick')) { }else{ //in case there isn't, use our fallback require_once('msoffice.php'); - require_once('opendocument.php'); } } \ No newline at end of file diff --git a/lib/preview/opendocument.php b/lib/preview/opendocument.php deleted file mode 100644 index 786a038ff8..0000000000 --- a/lib/preview/opendocument.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Tue, 18 Jun 2013 13:53:02 +0200 Subject: [PATCH 0062/1989] use ppt icon instead of preview --- lib/preview/msoffice.php | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index 65886169e9..262582f021 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -14,7 +14,7 @@ class DOC extends Provider { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - + require_once(); } } @@ -105,6 +105,7 @@ class XLSX extends MSOfficeExcel { \OC\Preview::registerProvider('OC\Preview\XLSX'); +/* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ... class MSOfficePowerPoint extends Provider { public function getMimeType() { @@ -113,21 +114,6 @@ class MSOfficePowerPoint extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { return false; - - $abspath = $fileview->toTmpFile($path); - $tmppath = \OC_Helper::tmpFile(); - - null; - - $pdf = new \imagick($tmppath . '[0]'); - $pdf->setImageFormat('jpg'); - - unlink($abspath); - unlink($tmppath); - - $image = new \OC_Image($pdf); - - return $image->valid() ? $image : false; } } @@ -150,4 +136,5 @@ class PPTX extends MSOfficePowerPoint { } -\OC\Preview::registerProvider('OC\Preview\PPTX'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\PPTX'); +*/ \ No newline at end of file From 1fcbf8dd7ac69bfce888cc61084a72919503fd05 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 19 Jun 2013 10:21:55 +0200 Subject: [PATCH 0063/1989] implemenet getNoCoverThumbnail --- lib/preview/mp3.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 60dfb5ff46..835ff52900 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -20,7 +20,6 @@ class MP3 extends Provider { $tmppath = $fileview->toTmpFile($path); - //Todo - add stream support $tags = $getID3->analyze($tmppath); \getid3_lib::CopyTagsToComments($tags); $picture = @$tags['id3v2']['APIC'][0]['data']; @@ -32,8 +31,14 @@ class MP3 extends Provider { } public function getNoCoverThumbnail($maxX, $maxY) { - $image = new \OC_Image(); - return $image; + $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png'; + + if(!file_exists($icon)) { + return false; + } + + $image = new \OC_Image($icon); + return $image->valid() ? $image : false; } } From fb67b458412241cb91c01bdb339d1a4317aeacab Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 19 Jun 2013 13:40:57 +0200 Subject: [PATCH 0064/1989] comment out old code --- lib/preview/msoffice.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index 262582f021..ccf1d674c7 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -7,6 +7,7 @@ */ namespace OC\Preview; +/* //There is no (good) php-only solution for converting 2003 word documents to pdfs / pngs ... class DOC extends Provider { public function getMimeType() { @@ -14,12 +15,13 @@ class DOC extends Provider { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - require_once(); + require_once(''); } } \OC\Preview::registerProvider('OC\Preview\DOC'); +*/ class DOCX extends Provider { From efe4bfc693ce98fc45e6a003f9bedd0d9da1d1af Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 19 Jun 2013 13:43:11 +0200 Subject: [PATCH 0065/1989] update 3rdparty submodule --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 3ef9f738a9..0a8f54ed44 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 3ef9f738a9107879dddc7d97842cf4d2198fae4c +Subproject commit 0a8f54ed446d9c0d56f8abff3bdb18fcaa6f561b From 1a8e4399b0084a2769bbf43f0ba417c547ac931c Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Tue, 25 Jun 2013 15:08:51 +0200 Subject: [PATCH 0066/1989] increase Files row height to tappable 44px, more breathing space --- apps/files/css/files.css | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 108dcd741c..be29186cbb 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -62,7 +62,10 @@ color:#888; text-shadow:#fff 0 1px 0; } #filestable { position: relative; top:37px; width:100%; } -tbody tr { background-color:#fff; height:2.5em; } +tbody tr { + background-color: #fff; + height: 44px; +} tbody tr:hover, tbody tr:active { background-color: rgb(240,240,240); } @@ -75,12 +78,25 @@ span.extension { text-transform:lowercase; -ms-filter:"progid:DXImageTransform.M tr:hover span.extension { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; color:#777; } table tr.mouseOver td { background-color:#eee; } table th { height:2em; padding:0 .5em; color:#999; } -table th .name { float:left; margin-left:.5em; } +table th .name { + float: left; + margin-left: 17px; +} table th, table td { border-bottom:1px solid #ddd; text-align:left; font-weight:normal; } -table td { border-bottom:1px solid #eee; font-style:normal; background-position:1em .5em; background-repeat:no-repeat; } +table td { + border-bottom: 1px solid #eee; + font-style: normal; + background-position: 8px center; + background-repeat: no-repeat; +} table th#headerName { width:100em; /* not really sure why this works better than 100% … table styling */ } table th#headerSize, table td.filesize { min-width:3em; padding:0 1em; text-align:right; } -table th#headerDate, table td.date { min-width:11em; padding:0 .1em 0 1em; text-align:left; } +table th#headerDate, table td.date { + position: relative; + min-width: 11em; + padding:0 .1em 0 1em; + text-align:left; +} /* Multiselect bar */ #filestable.multiselect { top:63px; } @@ -93,13 +109,29 @@ table.multiselect thead th { } table.multiselect #headerName { width: 100%; } table td.selection, table th.selection, table td.fileaction { width:2em; text-align:center; } -table td.filename a.name { display:block; height:1.5em; vertical-align:middle; margin-left:3em; } +table td.filename a.name { + box-sizing: border-box; + display: block; + height: 44px; + vertical-align: middle; + margin-left: 50px; +} table tr[data-type="dir"] td.filename a.name span.nametext {font-weight:bold; } table td.filename input.filename { width:100%; cursor:text; } table td.filename a, table td.login, table td.logout, table td.download, table td.upload, table td.create, table td.delete { padding:.2em .5em .5em 0; } table td.filename .nametext, .uploadtext, .modified { float:left; padding:.3em 0; } +.modified { + position: absolute; + top: 10px; +} /* TODO fix usability bug (accidental file/folder selection) */ -table td.filename .nametext { overflow:hidden; text-overflow:ellipsis; max-width:800px; } +table td.filename .nametext { + position: absolute; + top: 10px; + overflow: hidden; + text-overflow: ellipsis; + max-width: 800px; +} table td.filename .uploadtext { font-weight:normal; margin-left:.5em; } table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; } @@ -119,8 +151,10 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; } /* File actions */ .fileactions { - position:absolute; top:.6em; right:0; - font-size:.8em; + position: absolute; + top: 13px; + right: 0; + font-size: 11px; } #fileList .name { position:relative; /* Firefox needs to explicitly have this default set … */ } #fileList tr:hover .fileactions { /* background to distinguish when overlaying with file names */ @@ -132,7 +166,11 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; } box-shadow: -5px 0 7px rgba(230,230,230,.9); } #fileList .fileactions a.action img { position:relative; top:.2em; } -#fileList a.action { display:inline; margin:-.5em 0; padding:1em .5em 1em .5em !important; } +#fileList a.action { + display: inline; + margin: -.5em 0; + padding: 16px 8px !important; +} #fileList img.move2trash { display:inline; margin:-.5em 0; padding:1em .5em 1em .5em !important; float:right; } a.action.delete { float:right; } a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; } From dc65482d50ae274b0db12cadce25f6fff0c86671 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Tue, 25 Jun 2013 17:57:38 +0200 Subject: [PATCH 0067/1989] first round of replacing small filetype icons with proper ones, from Elementary --- core/img/filetypes/application-pdf.png | Bin 591 -> 1759 bytes core/img/filetypes/application-pdf.svg | 277 +++++++ core/img/filetypes/application-rss+xml.png | Bin 691 -> 1098 bytes core/img/filetypes/application-rss+xml.svg | 914 +++++++++++++++++++++ core/img/filetypes/application.png | Bin 464 -> 1235 bytes core/img/filetypes/application.svg | 320 ++++++++ core/img/filetypes/audio.png | Bin 385 -> 858 bytes core/img/filetypes/audio.svg | 274 ++++++ core/img/filetypes/code.png | Bin 603 -> 908 bytes core/img/filetypes/code.svg | 359 ++++++++ core/img/filetypes/file.png | Bin 294 -> 374 bytes core/img/filetypes/file.svg | 197 +++++ core/img/filetypes/flash.png | Bin 580 -> 954 bytes core/img/filetypes/flash.svg | 310 +++++++ core/img/filetypes/folder.png | Bin 537 -> 709 bytes core/img/filetypes/folder.svg | 329 ++++++++ core/img/filetypes/font.png | Bin 813 -> 1793 bytes core/img/filetypes/font.svg | 338 ++++++++ core/img/filetypes/image-svg+xml.png | Bin 481 -> 959 bytes core/img/filetypes/image-svg+xml.svg | 666 +++++++++++++++ core/img/filetypes/image.png | Bin 606 -> 978 bytes core/img/filetypes/image.svg | 321 ++++++++ core/img/filetypes/text-html.png | Bin 578 -> 741 bytes core/img/filetypes/text-html.svg | 280 +++++++ core/img/filetypes/text.png | Bin 342 -> 757 bytes core/img/filetypes/text.svg | 228 +++++ 26 files changed, 4813 insertions(+) create mode 100644 core/img/filetypes/application-pdf.svg create mode 100644 core/img/filetypes/application-rss+xml.svg create mode 100644 core/img/filetypes/application.svg create mode 100644 core/img/filetypes/audio.svg create mode 100644 core/img/filetypes/code.svg create mode 100644 core/img/filetypes/file.svg create mode 100644 core/img/filetypes/flash.svg create mode 100644 core/img/filetypes/folder.svg create mode 100644 core/img/filetypes/font.svg create mode 100644 core/img/filetypes/image-svg+xml.svg create mode 100644 core/img/filetypes/image.svg create mode 100644 core/img/filetypes/text-html.svg create mode 100644 core/img/filetypes/text.svg diff --git a/core/img/filetypes/application-pdf.png b/core/img/filetypes/application-pdf.png index 8f8095e46fa4965700afe1f9d065d8a37b101676..2cbcb741d84a8e1303608089a33e22180a0e4510 100644 GIT binary patch literal 1759 zcmV<51|a!~P)6y0bI$p6Bu6%zn&%#0xKS<6+L6nR(B9p8xxQ{?GrMF{;XqZ1#pm|33gATKwgs z#^mqmS+{FoZDmj7TmcKl7_b&hbCNa9p%uHRpo(EmQv#@;2)(;|HsMqT>8W{l9OP8^=S#UY1*NHHNRW*QsctO2@ zDyX7rFrugp=}>Eso(*(;;mgDwolK97@#pV+o6^iQao+&%Uwgl0$?35%EQB>OAGEO= z08v3j!bEFPtIZTBh`}cbxsN|g=O-S)ILE~kf8ebj{ebqwkpZT&!ct#rOitpO!BqrV zf}oWF2mnMuB`8c3v4&{JPP!la3{iVKS*^y|AHKrn-~NV5xj-p$%+xdD&Q8Kj3(Z<}bW;-~er!QOYM2qX;94_zY7l zh4Ne)!`MJ(Grdc5)B>Q^@X6Z!FM@LmKZF>w?{cmIqzbt(%3^d&rRVZ%0 zgT8OQNbZx5B3?iRBVaTb3#zRwSl4p@;+}50jj4Jg%v}O*nFvoj^DONH{jAx(o%Q$K z%laoi$Mn{_`1i{%W2YwP8E66S72~26Oei$B;a2LICtbk_muLVA@4d^FW5+qOe?Pzb z;?rCi8lwDxEeyQ$eHgr>sRL>0;w78|R(Sl`YL()~jbxb+>2f!00T3BeZ;NBP(wOcv zCB66#C!cwiH(xq{Nm2&B{sQLCElt`(UC-4xa||r%^;+1Lla5aEy|>`zuB`?@2^(LG zrQ{rKE@n-dFmdcSukYQ5iZHNmA9m~Ah{$|b5v+?^o?N`AR;z(3k#nrM{{b4AUzVj7 z0Mab4K&uiPD7%REIHrE~EGM7ai)5Znd%s5fq3sI{hy?py^z^gUSF5FoQACu2agKcD9C! zVvQw@la{oUw{4^0rM5U`iw}%eXMXX{)b!(hy}fZ1g-d2}$s0%%5})zcgNNAhjThMP z)Kgp=8zbrLB+Ie@#u(BxZP_vFv$MQ$_=t?oR$p5j)67k(R4Q#{Yd77VWshu0bGtC6 zqa`&jNvF?Te`&m(yX;U%d)z2?&|pX`25k?+~~jO{{au3n480DmkIy?002ovPDHLkV1k

~O9lw>B8WRlD)Gm}Jrz31u-X&&gn2lvjs=i{7nIaL6v2==uw+8Lcs(8j27 z;|c`rmSv@Lx!heopGP^^Ieb3f=R!%Lpp$}iMS-&P3EJ)s48wrJ_Ni0~k|c47D2nj= z{jS6bt|kFpFf|p5cM`_&0Zh|`rfEp0(}=}lT#(6RpzAsUfxv^LSYX>WlAaN$>)*J5 z0#sE+JRUD8iT9*fz{)_^7@6P&!sEjTcD+I9Z4YjT1`wH@fV{cEvneYGFU%maIEU2s55&K(LixD|{p-uiS@?KNj zk-Go8G$hH6g002ovPDHLkV1hVj1#|!a diff --git a/core/img/filetypes/application-pdf.svg b/core/img/filetypes/application-pdf.svg new file mode 100644 index 0000000000..3f9ad528af --- /dev/null +++ b/core/img/filetypes/application-pdf.svg @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/application-rss+xml.png b/core/img/filetypes/application-rss+xml.png index 315c4f4fa62cb720326ba3f54259666ba3999e42..e5bb322c5733e7d2961fd27e049e4249a0d2a5c1 100644 GIT binary patch literal 1098 zcmV-Q1hxB#P)a7G#|~(yYCzq z@9WOI*UT(}ap8kI_ua?4_y0Tpb3fjQnX#Fd+f?=c0sadB_3j7fp1*$%XG0(xEM=gw zcH28AcdQFw=+M|xQw>4D2}oM9Hd(t$!&0HNwzQ~W80U{1DRn6WsA6Ylu&WE;93l=} zT0)p^2n$42^V&?4_SWr~YHxs84ZH^*fjG=L5SP0lJpe3-noQgjyidmN1%N8%74bfe zI1^7CuuQlTfWmgu0>TXQDNHW_GfUFo4G{ye)OAVbWnTbEZDFlS)vj9tP*w1W3kcu@ zgT(sO{cEp~Oq?_o1%P->#_s8W8s=lnD<*=tgxXR7sfs>u!BURQ5!3YE$5=mez$~%f zVof4-X~be66mC@NXKA1_4H$S!RzxoVRYQG}21Ky9Y`aT>k1 zAZjUG52Md+!*Mg~v&b_yV#VUVQjpM^SDLS%Krj4^{&|}C!YuJG-yjt>cK6Sr0vPdq zuYx!SkdYgxjZ9M8J;?x|f6TJ>(QD|XbL$ZV03_)$z$>b89}Z~Yz|!|H*e{0)YNjfoeVpZT=EEKST864DR!H8GQT|wmdk+ z;1jQ6s3xxGex_dd2h`3A!;e~4_mk@l%$w2prO z1A{c4Ie^B3MyYTYjD^qQejNzrz`_gnv9SLEqMyE^e*0dU&mP2LSpE2I^snEk-MWYR zT@#(6QI~kwu9yR52duEp%%NBQX7Q~l+CO|r{f@m1J~V}{EYmvqDFC%y;}ua`DGlbe zawn`vLE*sY^ii%q^exid!SZ|401VvoFzS`)>?r{1V|zMsUzLWu^s@?76^mjtQlj&x zk)dI9WeJx(!D!<{m4x#cW&R-(B;K^tCj2s z?)N)2U4Hq{25xwiGYdbpQb1=l6TxbDZwj&S={?7%qx-u`rsG(Zp`-rh=e^=%((1yvsuf5d=&62Zj)Y zH&JviNS_F4_Hj|T(1j4$p-!}kixP9&dB4uv^MveG?dGf%sUCoc2!IFxD6wHRA2^dX zXRVk!-qSfk(jcaUKn#RP48(whfPlJUpApdrA!TQi_4D+fVoM;3I0gZ8{=Xv~Po;geVA+Em9@0Wq2 zr>OTZEGR05L=gf1T;ucCxq6Q6EgJiH@@-lVaAlQyw`jIF^c=&IVnj|95hHbE_cnt| zTzZQ?F4Ne@(bH(~&3nM%m)I@ID{@jJ2qZPjr)jhpe9hViOwH5k&|T#EmmL3(vHeUQ zq^!t^Al6JD;=mHq^Bg?J-8-zG2Od7gZbknG;K9czYjPqG*xjPo0k(c4%lPXTpw(qq z@aGMnxtFS(np+2kC} z7P02O874ZkJH$v#nCUVx$({yDN`IX@o2wyvTD#e`qN`_w5<}$3F+_ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/core/img/filetypes/application.png b/core/img/filetypes/application.png index 1dee9e366094e87db68c606d0522d72d4b939818..3518d3116d2a6d0fadd6b09b3b592a2cb322bdce 100644 GIT binary patch literal 1235 zcmV;^1T6cBP)zpC!G631~st$=$LjuDnvM`SqpI###sn8@8#)w6&qwSNGIL1Hskx^mf7_ukXz+^#B% zs;c;vCVy%5{{aAg{mYXlPksx6;AvG=4_4=Xf+-=y-(^|;_4x7Q(MABC=RJ+0=wY|p zmA>yIr9?`J=Xo2)Qhp}T7~@=Py>YCR@`uCW!?Uw9fIl|^P)a@UJWsxU{n{1tecydr z_dL%5u>iEzXsuC7Ik(>}kY=+fl~NDtHJ1PwV|=?<2tid<7-Nu9y0O+8fU2t27_hNb zRk`)`@t1l3s{mFLtOg4q+*G zL9f>%iX!qnUn_ns2CQXSMzh(Zsw&rrM@L8W`+Wcgg8?5td_V|+F@~L;9kMK2(tj%k z>L_j3W?6<(is^I;Kv|abdOiC6K3SFl(C_!rTJ!$>dxQ`S1_So@_X&c4cDw!GBse=e zLrRGd0x2a*DQ?}m#p&s(TQi@}IXpaMFc=U70Yy=8adCk$W~~pllAzAOYC{@h$n)Io z4e+^7R`p)poVI4b2H3>+@84%WpEDc|xw^VSYt3jhqSNUtC5q$N?UuW{yL7u<_V)J3 z^Lz=+wHUBZ8HOQ25b)x~3#61JNkUN+gkcE4cswS{GJM}hDaGBpcWJlVEEWrw>sk!h zASoqjnj(Z?GMPA8q?C-uW70GQKuU@4`)>a9^pt~xgC!ZaW?=Oo5khczc}bEaNGU1H z()EPz`%WsQlw&N8W2&m6)oLxBigkIdt(^sRq}HP-A`C;c)*KxjadL7(v)Od>&1RF6 zlM}k#E?R5CFm#(&-LEBqy$=W>$n%`z<71}NDZ9J7eERf>D2m)^7)2362ztF9w{PF3 z-EK1&43_k_3~VLADga{)uU@_4#*G_%{P^*6;1|s;aC2p|l@cDLJoc6D_XCQ0%;;BBn(0WbcEP)8e6`gpm!y1M!N^ZV(=IC*t) z{^;nqJv-tM$9J1L2QJ2DN!#51=1_l@G`2=6e0lehL%sic%`_4--LFM}IF!KzJCseW zq1I3__Z40|e?qyK1__gzP(qrBf-G7SQbQ`#Lw94WVe(o`qg+f4hy;Qju)q#I(9{`% zQmAGomzhQ!b|gq>KqL@IkO~$=Koi}a$u6d07kiS}NoYVMJjAeZpaB*;wwcDdEbK@K zNP;B7RzhQ|H9AlUO<`J>m1(5R)Pb-iLBb@7Jp)}LHdAb-VVgYxVoTzGoqu{~a>6uj zeqCRFI9pC#h09bGwy9;oHcp6(RB%jeY^F=Ll!S+9JkVe4nDG7tJMQiP0000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/audio.png b/core/img/filetypes/audio.png index a8b3ede3df956f8d505543b190bc8d1b5b4dce75..cd9821ec047ff066ac222f7434fd318f1968a6c6 100644 GIT binary patch literal 858 zcmV-g1Eu_lP)NI9*~1SCT_Gs%VjNDv0ZoG^URyES=V*=%*HvDbeh9Q z)6-KtJw1^GhEh7vfK7xk*1OF%Vtb_Px}Fs09BG^)&#sMb)+~*6VeDx!8uy>8ZGn)_~baRl~(% zfvTz;axnt-mducRgsSs|35u?Clbynh-6_%cfPW9< zc^(*;&*y{HlS*N~1!))yL7JvGIXOXDmPnEW^Z6WUnmVs2$_uef7^MMImZg+9I5@!B z*%`FfsO#Fv7z&&s5+&g0zTY;R4K|z2;O{X4V;&^DC<@GGGXQkq`J3i>z|kEuKNdxi zuU4xcLWmgv&KMIPg8oiI0nkdR-+7*YUoMv`hX4Q^9UV=TQeToJ$+XrVN`P~&+P0NK kh^j2hK87q7?|;$$0M}CEus3`j`~Uy|07*qoM6N<$f-drfxBvhE literal 385 zcmV-{0e=38P)klCE>?a@fNhGaV ftv%qM$TQzJ6;XjO8erVL00000NkvXXu0mjfw}q7O diff --git a/core/img/filetypes/audio.svg b/core/img/filetypes/audio.svg new file mode 100644 index 0000000000..f742383d63 --- /dev/null +++ b/core/img/filetypes/audio.svg @@ -0,0 +1,274 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/code.png b/core/img/filetypes/code.png index 0c76bd1297751b66230f74719504b2adb02b1615..753d151f538842c2636a94e0f9231fc4ef1c301f 100644 GIT binary patch literal 908 zcmV;719SX|P)calP19IDZ2()FQp&u6e`_n%%{zg$fG7#T{5*f}IRMSI>v=OdjnCu4>voZt znPW?hPD@=iTLOB~5Jdr)Y0pJEa=yN{%|#bpscy*t7w(Ved`-dieEc?x&*Netogt`u z`S@*?pkB$>*%X8OwmT1SwzsWdcjjEj0WLm#Y4L9j=)9Ynv78NbHd0sREeKcA68^C> zJ*~E+NNfG7Vyi(E1@O;bLv!$xOH(;t*NGbD#y*gGov;-O4DNOg!2ArKuCe%iyBhKB zYRoH8$jX|)*yXP|U;EK&7G8WJ^=i_RQ`r{6+qJ2ncu@d`VOWB@PHnIzgg4<0+rW7=;1;izPJMweME|Xz{et{60wL$2{xyZsozNH~rfs{rgt?xf;zwoCoU4ghY9O#pDX zJO3q>uWrcz2lZoFhfgA-hNZKCj*YfX9S68OdlSE+qkeHS`E&}8$3uUAe>PbWYY))p zJ%B(!y+nqVVoJ5L0d8Nv4S?V8Cz(vLzrK@7;U*JLqK5or;z_iIDvbF>+^s@ zb}6InA?}RFIn+^y$ED^4$XC0l2{1H7jjA&6+pnrBQc4c*sI%l9@2+1_#9X&@fQkxR z;F>R?rfIm{?vh1Tvp<*IssKU=Wn^R|F*-ULbX0w*enJSLNGWsIqA*hlAq1c=2XoNU iz>GABigJEWC+!!w&Od^wnO&v;0000^~*-1fljz_B$LUvK}k?BNXe#Y!m=zM!!V#}8bncK5m;8VP zw86G*RI63?Cd%b9bX|ueNlZ|wR6rj|r_)VIP@r2imh3?SN+^{|kY%~8B{maJ@F*OK z&VH9LwOeGt#DRjj0~v~8`>iO7!Ybi;zE$va`A^T#yW`y44;k^#O~K5*jD=qcUhPSc zvyy~q;5H_1WT1l~cqje9yfa+l!hu6xjdOJ8s;8E^+=QQ$tw p?%p!Hy#YapB=@+^9(46X{{RQg%9y;OKjr`c002ovPDHLkV1g7l326WT diff --git a/core/img/filetypes/code.svg b/core/img/filetypes/code.svg new file mode 100644 index 0000000000..1dee047b11 --- /dev/null +++ b/core/img/filetypes/code.svg @@ -0,0 +1,359 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/file.png b/core/img/filetypes/file.png index 8b8b1ca0000bc8fa8d0379926736029f8fabe364..c20f13c2e13af5bccf96b77dd66a6a0df0508c90 100644 GIT binary patch literal 374 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8!3Q zuY)k7lg8`{prB-lYeY$Kep*R+Vo@qXd3m{BW?pu2a$-TMUVc&f>~}U&Kt-QDT^vIq zTHj9H&D(4s(Dq)Z+eliWEkR@z&jFT~D>P5CyqVw|WW>-jq3h5tZ(${F>&}jI2ZR1h zzjpKc-ODG=B&=TdIyg{7mF0p(-}Qa(&wra4C;hZC&dj$s#H-UvT`A-CHOq3KHP0&9 zl6y27uEm8v;4O|7c5LGF}$;v{gPaVutPR)C#5QQ<|d}62BjvZR2H60wE-&H;pyTSqH(@-Vl>|&1p(LP>kg~E zYiz5X^`c$+%8#zC{u)yfe-5 zmgid={Z3k(ERKCKrE7DF;=x4^O+ pzO8rLO8p|Ip=x)jHOtWj`bJBmKdh_V<`47(gQu&X%Q~loCIFbEay|e6 diff --git a/core/img/filetypes/file.svg b/core/img/filetypes/file.svg new file mode 100644 index 0000000000..f0c0f1daf7 --- /dev/null +++ b/core/img/filetypes/file.svg @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/core/img/filetypes/flash.png b/core/img/filetypes/flash.png index 9f5db634a4fb42ad33c7a78f5488f03308d3317c..bcde641da3ca196a8212a5b6d91a62013f1430ab 100644 GIT binary patch literal 954 zcmV;r14aCaP)8=ZhVsRlE5JVI@Zd?wX?nDHR%jISl z78YJM3?tIyQc9MVmICVm007r@>2x}g0$7$d71}a;+Y*Hii>bv@N<|LQ7r^ZtqE-N) zTm7Bb0bR^UTd=dfPH}aW(%KrPWYo~BGOXL$NVhG%J2g4u$pwpp47*;x^eo#2uS*qfY+W6C@s) z#dX~S!`w}-8^VEF;Cmj$<@d>rXNWsCrfu?9+oQO0j!$N1_~MzTwSGDcbP<(5{g~mQ z7{enYIJQYgDss6=rY0xw+djYl_DjG&x{F9Du77lvsm$HP9TU?uF%{UBf$T`!RvW_* zS^%B;K882HynxwmkxWlw$75W+{434M%>y>avf0q_`r3h88%3_Yy-05A9)^xNRCX&2 zP2S5>pM4YXuhnXSwZQ?DqVfGY*WP-AiLp`A;~5Oc;zntknRm`otyXVeWd_~#ADG7TyifoGzXkqYh3VzF*APPBc^<7+i)zn=hXn{d1HB3}<%8<~`B(g(16Y!Kav9LZ#I-!JhChA6D-Iv8UfilU%gE+d!ANl7-FMJko@B=v9?3Fv}pny_sf z=E*mhpTB_ZBv7eTkk99(z%UF@k#stJCutT?*giObx$qWlViRogHB?nap-^ZUi83t$ z=kGt5(=*`f%P^*A!PYjsQHsT)>?D)PJRsm4)^;3x^8<|7M{rS<(>t*|l29kKk5Z}B zUcfJY! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/folder.png b/core/img/filetypes/folder.png index 784e8fa48234f4f64b6922a6758f254ee0ca08ec..b7be63d58369d5da485f12ead9ca6982c8e8e563 100644 GIT binary patch literal 709 zcmV;$0y_PPP)M_{T#OD zL*!f7*x1-vsEwk95U>jf7J?W|NZj3IbMMS~T9|!>kgRdc^k2sZ#MOqsjx?%!t$0I=ZhpQcF+A>0EnJ3t8GHUPLgnEA-0vMdKV zcTc!(*WK49003Gd^3lwW%{DWL$W)a&EQ+GIKl~n_==FLaqLco2s%W)Z6XW3Sc+g&Y ze0g#4>783Q+p5|qAkTArUj6c}^LyjPn^!NN7XWbe+Vw}v%g@?Ho;SMqARaC~X|JrT ztONK9NGknr8$F26=UQmx0GmZ%{|u;jO(d|qMAMIB2!N|X#p)q|g=1m?P|O7&Dqz!U z2oTjeu_Dg^Ygmwl0Aqo$j8%Z8A{G>-%>|$&P~j1P64#Lh=ggtjEFjMSVnJjZZ2?oP z6Du-p9$*e6QBaB_K%`WW2ugLx900_MNNEH}v8qTEEo&a&07wK>)g!>}PQOYdIByQt z=DXxXf>`y&D$v{9BN4DVSdV`V|1UBSGxj>&y&+(G^Jm4Z5N*B!0S*#Hck9OpK>a>P zCML6z{;2}TU=N*kL}KlCIy3|TK&n$B;xfqrz^pGO%aCFn2g3otV~Ug#Bgw&j;0VA; zY?h<0V*+5~fS|FqOBZqglRZHbC*oI%!!i#5J8K_azx}%U{)&6EO+g63l;ReEKCs`C r?N1Z{F5+MbW*-V**WG0Ta9Z&Pj@y0dwwZ6q00000NkvXXu0mjfO6e%^ literal 537 zcmV+!0_OdRP)x(K@^6+>g^d@v4;gkbWsEoXE%32*i1tcpTNXd5CcIl)ECgqz|2rE6EW}s7R?kl za1q`0GCkMruC6-2LANtwVlsgzsp4?{@7$`KBv!G66>Vie3h?3OmEEkjwdLG0PgLVi z`!N((f$A@n17Ldj#`};0I3@iHJ5M{#IZz|UIYRm4(!uV7eYIYIwQf&}_2J~}>pQ^n z6o8--^T(=hkBNQ_k{-_GWE;FMW7!p}f{NG3nHZ{D5<3d8&tLh%a4AqqnjMkr3m&fkMdECD3N5}Unig5wy40;>lo4j~k+e}v)` zR6)J8Mk*u=SpB`p6o)7j?S0T@9?bz#m@l>gc*zk__|*!FMcHwP!gwLJvS~9c0px8E zW + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/font.png b/core/img/filetypes/font.png index 81e41de7d3a9bcc50267b34d0005487d5c7cc7c0..df44a7fc47db6c6edce188fa5e00ead07456bf97 100644 GIT binary patch literal 1793 zcmV+c2mbhpP)kn#o@63d#~SKd+oK^#LT#!OYK22X zLr*dD$ihD}KYHN6f#6 zT>yCNt~>4(zWzFd`lNsB&FuB{1f&&6NstsM=i=ek{$mdx{luLkw~rlp0l2~zG@H#q z0DYe4Ax%>U;FXDqiPr&~$@3gx7!rVoMw-pu$-CFR#8L2ycT4{RvbV>j({tJU@zNhLykMF8XxI?P9+5%Q%XkxcAQ|vW0o}e{A3;Ewr_1 z3APT|TpG42?R|?|{C)tw?{85`IUxkv?RE~}Y3|%y6B83>r4VCTmcjEpoGu(4Ki8gY z?mPTgw{rk+N{&R!Z>+hbK>E-3U`QVC*1Ru(5MoCV1a;>evMggE#812XKVyr;wcBvc zL1~RAt=UL(xs>xpqtVCAo3z%*^Be#s_wL<$ zVsYa2>o?y8Y-V<_)BFi`kLlQz&RLQV~kHkJDGVW01!Yw)LtNF=E2NxLO9R&rPjLYoLj63FW<5L9^aFz07N&rBuR?`6Vr9eAPGBdQ+l;`0wYaWU1{?%2lssu2Vl&zyeZr>BypE>6s zgn$5jv?YacNf}#4khe>v1tHCBRxqY63qV9Wq?C2%9E>q3Gw&K7AAhS`^ZeSu_yd`# z`T{Uc=qNXjjs@~}Wm#@jN(m{2dP6yC=6H!f_Y|4AnFNp+pfnc)EY^WWqtORolMv#3 zb~{I9S^j$I0ArElg+-Yg+yD~@rn|Sa@Srf3m>G}~2Nlr_lkfX9d^VrE!t<2=uwCn8Nms`J%Eq|X-o z#8l4hvnAnO1Dq`xbJk&P#$e~b%pgG#fUnKwMS8|K%o@OB@_U7liG?+melU9S;LjHU z8jZ%s0rYi34`$X=Q&X=2hycirDFFK0({CJ`w#AQ*6=nOhahNfT6S*ye`8;>l7M_la?YV+yIZYR3qW@<;Evg! z%p7_0tSP=VUAiNuOZ)eCO!13D|C;%n1I{hXK}6nUudid{etWXC#p%Mnea01E{?5#s z-vq$ixwvTIZAe5OfUvVt2OtAbEF6%fxzK@ET@liqi0KY!4j=_!K2_-pk0xj4-v&wm jmb)IL^#8}{^#=GivXWu0)28I700000NkvXXu0mjfbU9WX literal 813 zcmV+|1JeA7P)%S8Yz4}?d^ZEOv#Sc!)mtIgHXaEQ+_ullV zJO1Y8v8UhuAAS7ozvIlitK{;}YszGvVI*jPQs)gu{RuZGF1qsJqxF>Ai*mOY zeUVJ^Xn04=g+vNN2-6q_7DHe6!8fa@! z^ZEB_2Vebf-umoI@{HTtK!PIfdyIp7Zk$|p=*|D=N%#IIE_w1_EaGe}ST5wWclgx% z|Fx4ZY{8likTKA?G12oM|4&}@o+);3yYs=L?ao)At-(S*$63Le zJ&q^>ZEbL?y!O>L=h9<7rvvdA2Do?L{p8zs_rGt?o&P=^cm5ltT|5S~l@laqmU8i; rSIv!oK>XjU`o@3v@@qdCD9z3Q7_5=EFk?|V00000NkvXXu0mjffa;^e diff --git a/core/img/filetypes/font.svg b/core/img/filetypes/font.svg new file mode 100644 index 0000000000..404f622ea7 --- /dev/null +++ b/core/img/filetypes/font.svg @@ -0,0 +1,338 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/image-svg+xml.png b/core/img/filetypes/image-svg+xml.png index a1291c2dfad75b289f88ab762a3a32ccb436c1ed..e3dd52489d3772962e22cdf47569b53616fe73eb 100644 GIT binary patch literal 959 zcmV;w13>(VP)z_|7@MbH1CXD&v&%^iqNC6zjp|aZmRb{Gb&4rJudU0!ZU@;&b3ZQ(98X^?H zWA8xK;(sR4OFtmbu7hREXXnht<1ls^P5+Io>_&Q$$hxv%*pp~*1m@GVjosx1A1$O!tmFaOWz|qKZPajp#bXMf;k|@K;T0$j~atHdzARr z_ld3V#cuD!YK-ALwUXxEw}?NHK>H8Yj1wB5QnK$etYym~pM|T#hz8iJo=5y_$qF+_ zJ_Gq_63=zR#3=gt{;D_&KLbmYBQi07i&EL={_ zi4n~^uyGr5{a5tH6~s#;K@KU*fR{!*_bxyNEBPuW(Gd!u?iSSCL%{6#7y_T%i4X54 zpT_d0kemyCj_ICv@n1iT*|NK;m}uUCL< zy_+D`9LhHoKqxh}Vy)hU?`Du+E{1Yh@IzF~nkI&6ac)8^jy>29H?Bn2f%&Xu{2N;T zIEUC4Xh8AJKAh8su)jME?w`>E*n|D0DosG!*q1bq4+2n_%%CftCRnwm6m0w&v6BZL z3Lw-qbiO?WKvQ;vvf;J@<<+Oz~z@wR`0ef1}Tm-j^vP}s1o%CXF$G_-YMUg(`O7a2elivAr~AVj4e zdk6lX0FL7jkH;egxcA9D5I{t%fq{X^p`oFUNVDIMKPe)Xs?L6kQcfiz0<>0wMJON0 hXjxKO%u^pm{{i;%Y;-~x&NBc2002ovPDHLkV1mQAx^@5n literal 481 zcmV<70UrK|P)SXcnW4?r|Fc?Kd3cm$;%kZi#G`Sa_VnwmC}YZ26Y zhXbnt^XAQKXm4+SUQ}H6r(?sz`|0x@O--EjU}EI72kk(5e$=!F(*t|%| zOO`#}*s$)|C0u^?YPrGY(Rf4Gt^S&sOU+enjCclWzS^+v`E5dh=Tv=F*rDQzDn?3c zT=(o=$L8ms2^j#wwxyStFa(R1K0Y&H$BX|!zZw%`2!=rX%m*7M?R@p$v*kt(Sq6Bw z+-#h< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/image.png b/core/img/filetypes/image.png index 4a158fef7e0da8fd19525f574f2c4966443866cf..83d20fdb7762d4b52b398c80e4ecc3fb6f2d5470 100644 GIT binary patch literal 978 zcmV;@11@dUJ z_uS{qnOPyFq@AX;75#q#fES=pD6}OJy1KfA7r;tHA;ez+wkLj-fDnSEr6o$GQgxDj zqP<^l%)PLEj%k_>Us+kHjyV*_<#JU5KVcT2l(O1d-wp*#(?keSv$IClY>pko4Q_88 z1gr%O!*C2XGs7_OcsveZx73Y@*f*fqS-0vP9UV+gPU7)+&~=?krGlnuXqrZ)QfcbC zt~*Gyq=1wX!!S@31w~O98yjP2Xoy@c$I;PI(;d6}R;cTSz?$r~P$g4gS< z0*sE1GBGhhAP``Gf1ka*y_#LyO;MD_1neQOFY@s4!13`h!^6V_gF$p%C!J0ckH_in z?+2huhgt6OBgc>FHs4d6}oDC!*0Pi;Ig$DOp`z zKw=y@8NH9A)i>j*R^LcJ>ZvnW!zvuh=8&y?VSXf|ZXNQA> zgQg|jt$^bgetv$E&1QLjf9LJ(jjyjSd_Es@b91Pw3V^DrOifKWS^&S_PcoULv$M0N z9@I<5nqw%Xq*yGX>$-#S$Hxb$RElsoOg^6{nM_vQvaPKxUSD5%d3m8wDExT{8r6aG z^K(qoWO{mq=bD-72)CKr9v`7z}c9a>C)^Ar}`HWHK2tnGAP#cNB}omhX^%J%(-x1AzcD zGc%-8DWsIFudh4CudlCL0=BGa4!GF?%+JrWySs~F7{3MdBLsSTdkKX?+}zy!2zWh= znh;n;Ls#OM)^b%<9R!4wl5{%VmRE5+9v6xbLiybX$xpcu zLJ@!fV!%H@$6wlf8OQ-oqLoMJe`#(1HETP8UxCcTx6i@D5&!@I07*qoM6N<$f_;y! A`2YX_ literal 606 zcmV-k0-^nhP)Q2rnAt>LM%-F zK|rtwgcU)}7x~z1Hrcs5bH*ZO$!>xO8K#?==bZPQ_ecnV>#P`H`QzGaRhd62G_&rC zTLU$c7_x*nFP_dW#Q+*);mMHE?j)HexK784D4x9l_tfpz2$@1y}9rkF+ zI+J5NMWeZyObc!d+rUc=>D+uOdAOg#%+Ej6h+wn5^xPmVVH*Eu446Y0A_@ zo$rlds-+sL10Db + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text-html.png b/core/img/filetypes/text-html.png index 55d1072eafda48abb0a5fcecb98b114d866077b9..de11613f25f41a5918b041f358a66cd38366eaaf 100644 GIT binary patch literal 741 zcmVba;AtS^`X`Q)aW-{s5~WK@i}19;H%=YPFh5sFb4L?{j~Dk1>X7wMwZ} z!t*?WAV?J6*#V^#gTa7eu}HmMCyJsJz{|@E7Z(>?UtcfhNWEUCSS&Ia3{Xn#=783E z89W}30cbXx#BrP|uC=Dy?Q(m2i>lnJOi{m&v4B?hm;gCY1K&@6I48y~YVI0Ra8jWR7EcUzIE;lzf zsU};*G#ZV}zFF5_U&S9EAK11{rBX@Q`0((6lrr^b%H>~QU6y4fzN!wI1yV|`uCCBp z^Zx!0fbaXMWB`|!msplX7>1d7_W}S2f*`Zty0V%z7l1?cWdTk;j!*8u*95R_oAdMY zTmcrd<*hNZ(J00000NkvXXu0mjf_EbrX literal 578 zcmV-I0=@l-P)dis)>+`f+#3Rv=dSV4I&~|Vk?LiBG~#L1X~NSQGbAyogj#ie_$n8 z*oYwUieR#5zw>=_v)By?+NE%sVPM|5yzfjE5$wfk_Go)9(A<0e{hvFiJ0eb2MFf%t zDJxl&RDw>Nl#~WweRba-&_F#fn|ifCG!S=00#QfIDe64k{5mZFusu=CnSq>Qvt$j5 zI$4b(K~|@Tvozn3#yaJ|Be;BKfh@+AwFR!7UF7D*61OfavvGQ!VN-Ga+zO*%#qEoS z8E0dX4NpRyRS|XCrXq{e4r(61{zg^7gBPDUwmjg}k(Q%NLkD6fm6*tZ=)6^ARRw9CNHr!!-b)EovamKwdDMpr>=!|-tf?S+boQE&JP}G_9P5@nR zSOjlBPI$jHA&U_KsTjQko(uJ_ROpKn!K^ckXTHmZd+_Mh7C&~BUYvvb=Xi2w6%i+L zP+hwJF0QUE^66)$h?CXHvdjEbu3a_69GS^`e5Gac*$0~K9VHcGVKhe>RE(rT+Ca5J zv_?D-3(OpKFrQAl`$E;pyKkaTN=V?@iK2u!kqwFy=F?aM-2b}R>c4;EZ`t2+*gqpJ QK>z>%07*qoM6N<$f@8}2CIA2c diff --git a/core/img/filetypes/text-html.svg b/core/img/filetypes/text-html.svg new file mode 100644 index 0000000000..bf29fbcbbf --- /dev/null +++ b/core/img/filetypes/text-html.svg @@ -0,0 +1,280 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text.png b/core/img/filetypes/text.png index 813f712f726c935f9adf8d2f2dd0d7683791ef11..2b96638d16c9af6b5f98350c4ec102d4975c1b64 100644 GIT binary patch literal 757 zcmVr^#nd|{2jDfVx`$1`XC^PkIDD5WqlpU;1cMx#5v z0GrL`_v7Q^Pt#^)7x}(_cYlBXz0qjYdbpI5#bS}O=Li5qQN(VytCfId6&^)lnAx<{ zfqgy;X(^>@CsB!jxnaFt5C9}=0364m-|y3Iw@ZoT2>D-+VUx9;AS|c(qyqq@vaT9mgSxB0SGSN=Y2YD5X+rbh}*!gTdh` zkW!`yOeT}Uja8uiNh!+-m>U3IUS0rbwOS~plJ@jG41fDgB+erKo`na zOv9s!aJgIp`8Ev05Zkti;~2+rk`~nOKR!MfkH;yWMJOFarxal=gGei2+cr|l%56BE zPETvYo12@mC3}%A+=B_23OqkQ1JG`_iQ^d8b=hvWxULI)DxmAb{Jpxm%H17D5jaJG zYz-VlAbS_og`@8Ror0pfK=q#u5CgH zf*`=MESk+G7Z(@wdcDMF5lU;|R0Xu3N;P2O>FEh5&U+99oS&c5Y&HqQkju-(g(B`YhYXo=00000NkvXXu0mjfEhtiT literal 342 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-%6;pyTSA|c6o&@eC9QG)Hj&ExYL zO&oVL^)+cM^qd@ApywS>pwx0H@RDN}hq;7mU-SKczYQ-hnrr=;iDAQMZQ+*g=YOM= z!QlMQEn7FbaD->uKAYgo_j9)W&$$zS*W9}m(ey0q$&7l-XEWO0Y(9M=SnhLbwy;d>@~SY$Ku*0xPvIOQeV1x7u_z-2-X>_74(yfh7C znXL|3GZ+d2`3re2hs?MK + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + From c7fdf00e8497af9804b0cfd4fa081940bf53bc96 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 21 Jun 2013 14:24:52 +0200 Subject: [PATCH 0068/1989] add unit tests for preview lib to make @DeepDiver1975 happy --- tests/lib/preview.php | 108 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/lib/preview.php diff --git a/tests/lib/preview.php b/tests/lib/preview.php new file mode 100644 index 0000000000..2599da400c --- /dev/null +++ b/tests/lib/preview.php @@ -0,0 +1,108 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test; + +class Preview extends \PHPUnit_Framework_TestCase { + + public function testIsPreviewDeleted() { + $user = $this->initFS(); + + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/'.$user); + $rootView->mkdir('/'.$user.'/files'); + + $samplefile = '/'.$user.'/files/test.txt'; + + $rootView->file_put_contents($samplefile, 'dummy file data'); + + $x = 50; + $y = 50; + + $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y); + $preview->getPreview(); + + $fileinfo = $rootView->getFileInfo($samplefile); + $fileid = $fileinfo['fileid']; + + $thumbcachefile = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $x . '-' . $y . '.png'; + + $this->assertEquals($rootView->file_exists($thumbcachefile), true); + + $preview->deletePreview(); + + $this->assertEquals($rootView->file_exists($thumbcachefile), false); + } + + public function testAreAllPreviewsDeleted() { + $user = $this->initFS(); + + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/'.$user); + $rootView->mkdir('/'.$user.'/files'); + + $samplefile = '/'.$user.'/files/test.txt'; + + $rootView->file_put_contents($samplefile, 'dummy file data'); + + $x = 50; + $y = 50; + + $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y); + $preview->getPreview(); + + $fileinfo = $rootView->getFileInfo($samplefile); + $fileid = $fileinfo['fileid']; + + $thumbcachefolder = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/'; + + $this->assertEquals($rootView->is_dir($thumbcachefolder), true); + + $preview->deleteAllPreviews(); + + $this->assertEquals($rootView->is_dir($thumbcachefolder), false); + } + + public function testIsMaxSizeWorking() { + $user = $this->initFS(); + + $maxX = 250; + $maxY = 250; + + \OC_Config::getValue('preview_max_x', $maxX); + \OC_Config::getValue('preview_max_y', $maxY); + + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/'.$user); + $rootView->mkdir('/'.$user.'/files'); + + $samplefile = '/'.$user.'/files/test.txt'; + + $rootView->file_put_contents($samplefile, 'dummy file data'); + + $preview = new \OC\Preview($user, 'files/', 'test.txt', 1000, 1000); + $image = $preview->getPreview(); + + $this->assertEquals($image->width(), $maxX); + $this->assertEquals($image->height(), $maxY); + } + + private function initFS() { + if(\OC\Files\Filesystem::getView()){ + $user = \OC_User::getUser(); + }else{ + $user=uniqid(); + \OC_User::setUserId($user); + \OC\Files\Filesystem::init($user, '/'.$user.'/files'); + } + + \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); + + return $user; + } +} \ No newline at end of file From a98391b976ba7dd544af6a0d16b324efb2fc7a3c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 10:57:37 +0200 Subject: [PATCH 0069/1989] some minor improvements to preview lib --- lib/preview.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 3564fe3df4..87e2e78d1d 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -323,7 +323,7 @@ class Preview { }else{ $mimetype = $this->fileview->getMimeType($file); - $preview; + $preview = null; foreach(self::$providers as $supportedmimetype => $provider) { if(!preg_match($supportedmimetype, $mimetype)) { @@ -350,6 +350,11 @@ class Preview { break; } + + if(is_null($preview) || $preview === false) { + $preview = new \OC_Image(); + } + $this->preview = $preview; } $this->resizeAndCrop(); From 9b7efef39d3f7eae45741f0adf0bc0d52945d842 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 14:28:40 +0200 Subject: [PATCH 0070/1989] improve Image Provider --- lib/preview/images.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview/images.php b/lib/preview/images.php index e4041538e9..987aa9aef0 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -20,7 +20,7 @@ class Image extends Provider { //check if file is encrypted if($fileinfo['encrypted'] === true) { - $image = new \OC_Image($fileview->fopen($path, 'r')); + $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r'))); }else{ $image = new \OC_Image(); $image->loadFromFile($fileview->getLocalFile($path)); From 39c387eed4e5da7bddb6f7cd48a8f8b607f3b8dd Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 18:04:18 +0200 Subject: [PATCH 0071/1989] implement server side use of previews --- apps/files/templates/part.list.php | 3 ++- lib/helper.php | 11 +++++++++++ lib/public/template.php | 9 +++++++++ lib/template.php | 12 ++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 1e94275dcb..6dabd7d697 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -1,6 +1,7 @@ style="background-image:url()" - style="background-image:url()" + style="background-image:url()" > diff --git a/lib/helper.php b/lib/helper.php index a315c640d1..e8cc81774d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -223,6 +223,17 @@ class OC_Helper { } } + /** + * @brief get path to preview of file + * @param string $path path + * @return string the url + * + * Returns the path to the preview of the file. + */ + public static function previewIcon($path) { + return self::linkToRoute( 'core_ajax_preview', array('x' => 32, 'y' => 32, 'file' => $path)); + } + /** * @brief Make a human file size * @param int $bytes file size in bytes diff --git a/lib/public/template.php b/lib/public/template.php index ccf19cf052..5f9888f9f2 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -54,6 +54,15 @@ function mimetype_icon( $mimetype ) { return(\mimetype_icon( $mimetype )); } +/** + * @brief make preview_icon available as a simple function + * Returns the path to the preview of the image. + * @param $path path of file + * @returns link to the preview + */ +function preview_icon( $path ) { + return(\preview_icon( $path )); +} /** * @brief make OC_Helper::humanFileSize available as a simple function diff --git a/lib/template.php b/lib/template.php index ae9ea18744..048d172f1c 100644 --- a/lib/template.php +++ b/lib/template.php @@ -62,6 +62,18 @@ function image_path( $app, $image ) { return OC_Helper::imagePath( $app, $image ); } +/** + * @brief make preview_icon available as a simple function + * Returns the path to the preview of the image. + * @param $path path of file + * @returns link to the preview + * + * For further information have a look at OC_Helper::previewIcon + */ +function preview_icon( $path ) { + return OC_Helper::previewIcon( $path ); +} + /** * @brief make OC_Helper::mimetypeIcon available as a simple function * @param string $mimetype mimetype From 806f3bddecbd8182f1da90ec91e2a03a1a6e2c3b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 18:19:10 +0200 Subject: [PATCH 0072/1989] increase size of preview to size of row --- apps/files/css/files.css | 2 +- lib/helper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index be29186cbb..222cc9c83e 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -118,7 +118,7 @@ table td.filename a.name { } table tr[data-type="dir"] td.filename a.name span.nametext {font-weight:bold; } table td.filename input.filename { width:100%; cursor:text; } -table td.filename a, table td.login, table td.logout, table td.download, table td.upload, table td.create, table td.delete { padding:.2em .5em .5em 0; } +table td.filename a, table td.login, table td.logout, table td.download, table td.upload, table td.create, table td.delete { padding:.2em .5em .5em .3em; } table td.filename .nametext, .uploadtext, .modified { float:left; padding:.3em 0; } .modified { position: absolute; diff --git a/lib/helper.php b/lib/helper.php index e8cc81774d..0a8962a531 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -231,7 +231,7 @@ class OC_Helper { * Returns the path to the preview of the file. */ public static function previewIcon($path) { - return self::linkToRoute( 'core_ajax_preview', array('x' => 32, 'y' => 32, 'file' => $path)); + return self::linkToRoute( 'core_ajax_preview', array('x' => 44, 'y' => 44, 'file' => $path)); } /** From 9a50a8f0cc680e9bb611bc92469c4b156c3a989b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 28 Jun 2013 17:23:40 +0200 Subject: [PATCH 0073/1989] Don't load the apps when we need to upgrade The loading can call functions that require new tables, like oc_jobs --- lib/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index fd4870974f..c95eac0d2f 100644 --- a/lib/base.php +++ b/lib/base.php @@ -472,7 +472,7 @@ class OC { // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; global $RUNTIME_APPTYPES; - if (!$RUNTIME_NOAPPS) { + if (!$RUNTIME_NOAPPS && !self::checkUpgrade(false)) { if ($RUNTIME_APPTYPES) { OC_App::loadApps($RUNTIME_APPTYPES); } else { From 57370353ad1b21156094adc3d1e735582bbd2bb0 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 28 Jun 2013 19:22:51 +0200 Subject: [PATCH 0074/1989] Check if the app is enabled and the app path is found before trying to load the script file --- lib/base.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/base.php b/lib/base.php index fd4870974f..af0a30ea17 100644 --- a/lib/base.php +++ b/lib/base.php @@ -661,12 +661,15 @@ class OC { $app = $param['app']; $file = $param['file']; $app_path = OC_App::getAppPath($app); - $file = $app_path . '/' . $file; - unset($app, $app_path); - if (file_exists($file)) { - require_once $file; - return true; + if (OC_App::isEnabled($app) && $app_path !== false) { + $file = $app_path . '/' . $file; + unset($app, $app_path); + if (file_exists($file)) { + require_once $file; + return true; + } } + header('HTTP/1.0 404 Not Found'); return false; } From d332b1d4a2e9382aaa8e8a11b6200efaadb18768 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 2 Jul 2013 11:13:22 +0200 Subject: [PATCH 0075/1989] implement preview loading after upload --- apps/files/js/filelist.js | 5 +++-- apps/files/js/files.js | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index e19a35bbc5..11bf028d93 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -172,8 +172,9 @@ var FileList={ if (id != null) { tr.attr('data-id', id); } - getMimeIcon(mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); + var path = $('#dir').val()+'/'+name; + getPreviewIcon(path, function(previewpath){ + tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); tr.find('td.filename').draggable(dragOptions); }, diff --git a/apps/files/js/files.js b/apps/files/js/files.js index a79d34c9b2..224167b99c 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -513,8 +513,9 @@ $(document).ready(function() { var tr=$('tr').filterAttr('data-file',name); tr.attr('data-mime',result.data.mime); tr.attr('data-id', result.data.id); - getMimeIcon(result.data.mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); + var path = $('#dir').val()+'/'+name; + getPreviewIcon(path, function(previewpath){ + tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } else { OC.dialogs.alert(result.data.message, t('core', 'Error')); @@ -577,8 +578,9 @@ $(document).ready(function() { var tr=$('tr').filterAttr('data-file',localName); tr.data('mime',mime).data('id',id); tr.attr('data-id', id); - getMimeIcon(mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); + var path = $('#dir').val()+'/'+localName; + getPreviewIcon(path, function(previewpath){ + tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); }); eventSource.listen('error',function(error){ @@ -769,8 +771,9 @@ var createDragShadow = function(event){ if (elem.type === 'dir') { newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { - getMimeIcon(elem.mime,function(path){ - newtr.find('td.filename').attr('style','background-image:url('+path+')'); + var path = $('#dir').val()+'/'+elem.name; + getPreviewIcon(path, function(previewpath){ + newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } }); @@ -956,6 +959,10 @@ function getMimeIcon(mime, ready){ } getMimeIcon.cache={}; +function getPreviewIcon(path, ready){ + ready(OC.Router.generate('core_ajax_preview', {file:path, x:44, y:44})); +} + function getUniqueName(name){ if($('tr').filterAttr('data-file',name).length>0){ var parts=name.split('.'); From 6e864e6599602609b5808ae4d043b273a9fe5071 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 2 Jul 2013 16:30:58 +0200 Subject: [PATCH 0076/1989] fix size of icons in 'new' dropdown menu - I hope @jancborchardt knows a better solution coz this won't work in most IE versions ... --- apps/files/templates/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index b576253f4f..c4a15c5fa6 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -6,9 +6,9 @@

t('New'));?>
+ +
+ +