From 5b44714f4cbd75138519789f55fd8b6f4b5d4241 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Tue, 13 Nov 2012 15:11:02 +0100 Subject: first version of the new previewer lib. It currently only created previews/thumbnails for images. It get´s more interesting when we add PDFs, movies, mp3, text files and more... 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 00000000000..8b1a42925a6 --- /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 00000000000..a7487c485f1 --- /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)); + } + +} -- cgit v1.2.3 From e484811e24f6332df49eb35c7e2adffca81d2005 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Tue, 13 Nov 2012 16:14:16 +0100 Subject: 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 8b1a42925a6..3fa494a2e03 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)) { -- cgit v1.2.3 From eb27c0b2a84da44f8e42f7e4aca0102c969eb195 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 14 Jan 2013 15:51:47 +0100 Subject: 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 3fa494a2e03..d49e9d3bde3 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) { -- cgit v1.2.3 From 9ef449842a369c2517f5c34932b502b754393ce0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 25 Apr 2013 11:18:45 +0200 Subject: save current work state of Preview Lib --- lib/preview.php | 378 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 229 insertions(+), 149 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index d49e9d3bde3..c7047633212 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; + } + } + } - // the thumbnail cache folder - const THUMBNAILS_FOLDER = 'thumbnails'; + /** + * @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(); - - // 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); + 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; } + /** + * @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(); + } + } -} - - - -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); - } - - -} - + /** + * @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_PreviewUnknown { - public static function getThumbnail($maxX,$maxY) { + /** + * @brief create instances of all the registered preview providers + * @return void + */ + private static function initProviders(){ + if(count(self::$providers)>0) { + return; + } + + foreach(self::$registeredProviders as $provider) { + $class=$provider['class']; + $options=$provider['options']; - // 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; + $object = new $class($options); + + self::$providers[$object->getMimeType()] = $object; } - - // 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); - } - -} - + + $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 -- cgit v1.2.3 From f02aca3f6ee295485d5bb9bc99b85b5573716f17 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 25 Apr 2013 11:42:40 +0200 Subject: 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 be19b66bf72..be5766cea9d 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() -- cgit v1.2.3 From 8c1925425b26d9b2889632c724ec455ceeed4dd4 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 25 Apr 2013 12:51:44 +0200 Subject: 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 c7047633212..de79b424077 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 00000000000..6b6e8e3599f --- /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 00000000000..afa27c0b143 --- /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 00000000000..645e6fa6232 --- /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 00000000000..e69de29bb2d diff --git a/lib/preview/provider.php b/lib/preview/provider.php new file mode 100644 index 00000000000..c45edbba44d --- /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 00000000000..1cd270db687 --- /dev/null +++ b/lib/preview/unknown.php @@ -0,0 +1,34 @@ + Date: Thu, 9 May 2013 23:59:16 +0200 Subject: implement OC_Preview --- lib/preview.php | 517 +++++++++++++++++++++++++++++++++++------------ 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, 446 insertions(+), 182 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index de79b424077..c062a068872 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)){ - return false; + //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; @@ -106,33 +280,56 @@ 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 + * @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 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'); - } + public function getPreview(){ + $file = $this->file; + $maxX = $this->maxX; + $maxY = $this->maxY; + $scalingup = $this->scalingup; - /** - * @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); + $fileinfo = $this->fileview->getFileInfo($file); + $fileid = $fileinfo['fileid']; + + $cached = self::isCached(); + + if($cached){ + $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; + } + $this->preview = $preview; + } + $this->resizeAndCrop(); + return $this->preview; } /** @@ -141,72 +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 void + */ + public function showPreview(){ + OCP\Response::enableCaching(3600 * 24); // 24 hour + $preview = $this->getPreview(); + if($preview){ + $preview->show(); + } + } + + /** + * @brief resize, crop and fix orientation * @return image */ - public static function getPreview($file, $maxX, $maxY, $scalingup){ - self::init(); + 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; - $cached = self::isCached($file, $maxX, $maxY); - if($cached){ - $image = new \OC_Image($cached); - if($image->width() != $maxX && $image->height != $maxY){ - $image->preciseResize($maxX, $maxY); + 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; } - return $image; } + $newXsize = $realx * $factor; + $newYsize = $realy * $factor; + + // resize + $image->preciseResize($newXsize, $newYsize); - $mimetype = self::$fileview->getMimeType($file); + if($newXsize === $x && $newYsize === $y){ + $this->preview = $image; + return; + } - $preview; + 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; + } - foreach(self::$providers as $supportedmimetype => $provider){ - if(!preg_match($supportedmimetype, $mimetype)){ - continue; + if($newXsize < $x || $newYsize < $y){ + if($newXsize > $x){ + $cropX = floor(($newXsize - $x) * 0.5); + $image->crop($cropX, 0, $x, $newYsize); } - $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup); - - if(!$preview){ - continue; + if($newYsize > $y){ + $cropY = floor(($newYsize - $y) * 0.5); + $image->crop(0, $cropY, $newXsize, $y); } - if(!($preview instanceof \OC_Image)){ - $preview = @new \OC_Image($preview); - } + $newXsize = (int) $image->width(); + $newYsize = (int) $image->height(); - //cache thumbnail - $preview->save(self::$filesview->getAbsolutePath(self::THUMBNAILS_FOLDER . PATH_SEPARATOR . $fileid . PATH_SEPARATOR . $x . '-' . $y . '.png')); + //create transparent background layer + $transparentlayer = imagecreatetruecolor($x, $y); + $black = imagecolorallocate($transparentlayer, 0, 0, 0); + $image = $image->resource(); + imagecolortransparent($transparentlayer, $black); - break; - } - - return $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 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::$fileview)){ - self::initViews(); + $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){ - self::init(); + OC_Util::checkLoggedIn(); - $file = (string) urldecode($_GET['file']); - $maxX = (int) $_GET['x']; - $maxY = (int) $_GET['y']; - $scalingup = (bool) $_GET['scalingup']; + $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; - $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($maxX === 0 || $maxY === 0){ - OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::DEBUG); + 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; } + } + + /** + * @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 = ''; + + $user = null; + $path = null; - 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(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(!self::$fileview->filesize($path)){ - OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); + $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; } - 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 6b6e8e3599f..6766cdb2148 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 afa27c0b143..c994240424c 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 645e6fa6232..2481e743783 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 c45edbba44d..e9264030144 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 1cd270db687..5089a56d671 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); -- cgit v1.2.3 From 837c6ed597f1c549cac5b0b439b257d81ea02b1d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 09:43:25 +0200 Subject: 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 d86ad643914..695f8569538 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; -- cgit v1.2.3 From 8dba46912d19bf976b24e0c097368f2e56ccb97b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 11:28:49 +0200 Subject: 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 c062a068872..44b551006f1 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); + + //$black = imagecolorallocate(0,0,0); + //imagecolortransparent($transparentlayer, $black); - $image = new \OC_Image($transparentlayer); + $image = new \OC_Image($backgroundlayer); $this->preview = $image; return; -- cgit v1.2.3 From f29b8cf68531844c23c45a210e280769a8cece73 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 11:30:44 +0200 Subject: 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 44b551006f1..3b6e0ae131e 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; -- cgit v1.2.3 From 04a4234b9eba85dc1a2f690c12e6a59381a74a54 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 11:32:42 +0200 Subject: 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 2481e743783..f5fac0b8366 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; } } -- cgit v1.2.3 From 8b39a085121fae7823046f209eecc3484cf5c936 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 12:00:32 +0200 Subject: 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 6766cdb2148..589c7d829d5 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: 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 1f0ceb3ace3..868755a1205 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 -- cgit v1.2.3 From dd06387a9c65dfaf8d95e6545586f7a042bfd44e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 17 May 2013 19:08:16 +0200 Subject: 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 3b6e0ae131e..d6c72603524 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 589c7d829d5..a0df337d58e 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 868755a1205..8144956c998 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 5194e165818..6fb4b051f41 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 f1b7f3eee73..bf1d8b2b3b5 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 e9264030144..2f2a0e68486 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 746b0ebb47a..290c18a72d7 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 -- cgit v1.2.3 From 13c6ef1ba9c3f857150679d164852d8724ab946f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 21 May 2013 12:23:31 +0200 Subject: 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 d6c72603524..572c85057be 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 00000000000..12b93f696ea --- /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 -- cgit v1.2.3 From 00985068ca249f4087f9f5b634e628afb8e8f7b1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 22 May 2013 15:12:25 +0200 Subject: 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 be5766cea9d..c45ffee26fd 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 572c85057be..39a87ed5396 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; + } + + $path = \OC\Files\Filesystem::normalizePath($path, false); + if(substr($path, 0, 1) == '/'){ + $path = substr($path, 1); } - if($user !== null && $path !== null){ - $preview = new OC_Preview($userid, $path, $file, $maxX, $maxY, $scalingup); + 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 290c18a72d7..5bbdcf847f1 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'); -- cgit v1.2.3 From 1bed3253abfc627a6dd698fc62a617285c1d7c84 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 25 May 2013 11:05:37 +0200 Subject: 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 72834009201..db6eaf852af 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, ); -- cgit v1.2.3 From f78e00209692d28253b91a432eb02d432c96a695 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 27 May 2013 10:45:21 +0200 Subject: 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 a0df337d58e..52aad67ca8b 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; } } -- cgit v1.2.3 From 62411965f9ccfbe66584e91bc325d156e08196d2 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 27 May 2013 11:09:55 +0200 Subject: 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 12b93f696ea..8f4697dce04 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 -- cgit v1.2.3 From 005d8e98706fc98d8dc5aa4927bb3ab0e6b00ac2 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 10:21:02 +0200 Subject: 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 52aad67ca8b..a8f203528c5 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; } } -- cgit v1.2.3 From 707f52f1dbb063595541331f94b3796f0f96ce9a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 10:23:40 +0200 Subject: check if the imagick extension is loaded --- lib/preview/svg.php | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 8f4697dce04..415b7751c2b 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'); + 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; + //new image object + $image = new \OC_Image($svg); + //check if image object is valid + if (!$image->valid()) return false; - return $image; + return $image; + } } -} -OC_Preview::registerProvider('OC_Preview_SVG'); \ No newline at end of file + OC_Preview::registerProvider('OC_Preview_SVG'); + +} \ No newline at end of file -- cgit v1.2.3 From 5ae1333c76fd1331e21fff0fc7343888c473c8d4 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:29:01 +0200 Subject: 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 00000000000..2b5d8edb893 --- /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 -- cgit v1.2.3 From 7555332d58c6e684cfbde72d5676e8e1902ae4f3 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:31:48 +0200 Subject: 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 2b5d8edb893..1e88aec69fd 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; -- cgit v1.2.3 From 4d52dfb0a0517a7fd52d20572085aba2ec0e4ad0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:48:02 +0200 Subject: 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 8144956c998..1e517b38182 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 -- cgit v1.2.3 From 738cc48a85f48f8dca2b42d5667d6662810a688b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:49:18 +0200 Subject: 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 6fb4b051f41..18f5cfde375 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; } -- cgit v1.2.3 From 55b00fe819079d78224989eee91d5886233738ab Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 11:59:20 +0200 Subject: make pdf backend work with encryption --- lib/preview/pdf.php | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index bf1d8b2b3b5..de5263f91d8 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); - public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) { - //create imagick object from pdf - $pdf = new imagick($fileview->getLocalFile($path) . '[0]'); - $pdf->setImageFormat('jpg'); + //create imagick object from pdf + $pdf = new imagick($tmppath . '[0]'); + $pdf->setImageFormat('jpg'); - //new image object - $image = new \OC_Image($pdf); - //check if image object is valid - if (!$image->valid()) return false; + unlink($tmppath); - return $image; + //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'); \ No newline at end of file + OC_Preview::registerProvider('OC_Preview_PDF'); +} -- cgit v1.2.3 From 08a022aaa48a6bae95ff75204a763a7c16a8253e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 12:09:46 +0200 Subject: 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 1e517b38182..d2aaf730d67 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); -- cgit v1.2.3 From a03787bc422563d129359d34673eb361b0173f51 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 28 May 2013 16:04:39 +0200 Subject: 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 39a87ed5396..6fc166b9c70 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; -- cgit v1.2.3 From eebc15dce0da88dff91dc5249938341cd50b8a85 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 12:01:43 +0200 Subject: 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 724bd250a5c..ae384225bed 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 6fc166b9c70..7c4db971dfb 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 -- cgit v1.2.3 From fa6b96090abc341da4f9320af02ee75b29a204e6 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 12:33:24 +0200 Subject: 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 c45ffee26fd..4b3ad53da01 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 ae384225bed..525b259f673 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 7c4db971dfb..31812035c49 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 a8f203528c5..c62fc5397e5 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 d2aaf730d67..14ac97b552d 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 18f5cfde375..d62c7230788 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 de5263f91d8..4dd4538545c 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 2f2a0e68486..1e8d537adc8 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 415b7751c2b..70be263189d 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 1e88aec69fd..4004ecd3fce 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 5bbdcf847f1..6a8d2fbb75c 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'); -- cgit v1.2.3 From 268246fac833837d7b9e7a6a2a4559cfadc0a7ab Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 12:48:21 +0200 Subject: namespace fix --- lib/preview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 31812035c49..855d5a9da04 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; } -- cgit v1.2.3 From 7408ab660af2c681ca6abfb15d6230382f35dd7c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 13:03:33 +0200 Subject: 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 855d5a9da04..1150681e64f 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 c62fc5397e5..933d65ec59e 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 14ac97b552d..aa97c3f43fc 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 d62c7230788..cfe78f32727 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 4dd4538545c..66570b05aa4 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 1e8d537adc8..58e7ad7f453 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 70be263189d..746315d6e6a 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 4004ecd3fce..5961761aaa4 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 6a8d2fbb75c..2977cd68923 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'] : ''; -- cgit v1.2.3 From 6b90416891e9e0943a7b19f29017bf7d8140eb0a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 13:09:38 +0200 Subject: 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 5961761aaa4..def6806860b 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 -- cgit v1.2.3 From 1e252b67635aeed7fa8180a0868abd6442a3c42c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 29 May 2013 13:11:43 +0200 Subject: 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 933d65ec59e..080e424e5bd 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 aa97c3f43fc..18e9d4f778c 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 cfe78f32727..303626e022e 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: 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 303626e022e..3c6be5c9226 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: 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 1150681e64f..be3abc2cd47 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; -- cgit v1.2.3 From a014662c52f5295a7e86cd43b7dd62b89e3f1085 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 30 May 2013 11:06:52 +0200 Subject: improve imagick error handling --- lib/preview/pdf.php | 9 +++++++-- lib/preview/svg.php | 23 ++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 85878a122a8..f1d0a33dc63 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 8bceeaf60d1..76d81589bac 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); - - $content = stream_get_contents($fileview->fopen($path, 'r')); - if(substr($content, 0, 5) !== '' . $content; + try{ + $svg = new \Imagick(); + $svg->setResolution($maxX, $maxY); + + $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 -- cgit v1.2.3 From b944b1c5d29393e1b6f0bc51cf50db6eba356e64 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 30 May 2013 11:12:12 +0200 Subject: 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 4eb0e820406..f18da66c3b8 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 -- cgit v1.2.3 From f7c80a391d192a15d594c3eaf7909a3d78df1a29 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 30 May 2013 15:29:38 +0200 Subject: 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 3c6be5c9226..660e9fc3ce4 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); -- cgit v1.2.3 From a11a40d9a96685d41e5acae096752f16785b16b5 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 31 May 2013 12:23:51 +0200 Subject: 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 be3abc2cd47..a73f4cb1ac0 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 00000000000..c99ca313c72 --- /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 -- cgit v1.2.3 From 34decf357697a81c23e844ef606c04a20a08c597 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 3 Jun 2013 11:24:31 +0200 Subject: 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 a73f4cb1ac0..4705efe2107 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 00000000000..e69de29bb2d diff --git a/lib/preview/office.php b/lib/preview/office.php new file mode 100644 index 00000000000..c66f5584f07 --- /dev/null +++ b/lib/preview/office.php @@ -0,0 +1,13 @@ + Date: Wed, 5 Jun 2013 10:50:20 +0200 Subject: 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 e69de29bb2d..1408e69e8cf 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 c66f5584f07..cc1addf3996 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 -- cgit v1.2.3 From 749c33f39d9452e2c1fdca718e3abcdb7c4a9dd0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 10:53:16 +0200 Subject: 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 18e9d4f778c..8cd50263e2a 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); -- cgit v1.2.3 From f437673f1a03ba5b2eeb3e79d24bf6ad3265aa0b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 10:55:57 +0200 Subject: 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 4705efe2107..f9f1288cb98 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 -- cgit v1.2.3 From bab8b20cbdc65888d92477f9a5810ea4b114ada1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:06:36 +0200 Subject: 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 1408e69e8cf..49c574c9521 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 -- cgit v1.2.3 From 8c5fceba296ae76a0f22f3ed0324dec46ef16019 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:13:13 +0200 Subject: 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 49c574c9521..1b8e482fb23 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{ -- cgit v1.2.3 From 78e8712366e2a198973f9a887c771894bef9a905 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:17:29 +0200 Subject: 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 db6eaf852af..2f437771f2b 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'; ); -- cgit v1.2.3 From 5c1d4fc186b692508f718c06218621bddcfd8f22 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 11:18:57 +0200 Subject: 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 2f437771f2b..2812d848133 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', ); -- cgit v1.2.3 From 21cc4f6960618c41e81ca7e785a6d9e21c21ecf9 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 12:44:31 +0200 Subject: 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 1b8e482fb23..5121a4c5a08 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; -- cgit v1.2.3 From f80aba48935e7325effaa65f899922927157028a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Jun 2013 12:58:39 +0200 Subject: 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 5121a4c5a08..33fa7a04e5d 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); -- cgit v1.2.3 From 25e8ac1c2f51e7f3f35eaec013aa1b3f8356f17b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 10 Jun 2013 11:01:12 +0200 Subject: implement previews for single shared files --- lib/preview.php | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index f9f1288cb98..904689bc4e1 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); -- cgit v1.2.3 From 0e4f5001d5143f55a9d051b501fe32de900917c5 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 10:45:50 +0200 Subject: 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 904689bc4e1..ed33e7b09dc 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); -- cgit v1.2.3 From 2ff97917e9e72b674de07ca05dc04dd3bea14f07 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 10:56:16 +0200 Subject: 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 080e424e5bd..e4041538e92 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 8cd50263e2a..cb959a962a7 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 660e9fc3ce4..60dfb5ff461 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 f1d0a33dc63..3eabd201156 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 76d81589bac..bafaf71b15a 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 f18da66c3b8..c7b8fabc6b0 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; } } -- cgit v1.2.3 From 28cf63d37d6a2b90ae32a2b5b7193a5f5c69830d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 11:00:44 +0200 Subject: check if imagick is loaded in office.php, not in libreoffice-cl.php --- lib/preview/libreoffice-cl.php | 87 ++++++++++++++++++++---------------------- lib/preview/office.php | 17 +++++---- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 33fa7a04e5d..2749c4867e9 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; + } - //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); - $image = new \OC_Image($pdf); + unlink($abspath); + unlink($abspath . '.pdf'); - unlink($abspath); - unlink($abspath . '.pdf'); + return $image->valid() ? $image : false; + } - if (!$image->valid()) return false; + private function initCmd() { + $cmd = ''; - return $image; + if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + $cmd = \OC_Config::getValue('preview_libreoffice_path', null); } - 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 === '' && shell_exec('libreoffice --headless --version')) { + $cmd = 'libreoffice'; + } - if($cmd === '') { - $cmd = null; - } + if($cmd === '' && shell_exec('openoffice --headless --version')) { + $cmd = 'openoffice'; + } - $this->cmd = $cmd; + if($cmd === '') { + $cmd = null; } + + $this->cmd = $cmd; } } diff --git a/lib/preview/office.php b/lib/preview/office.php index cc1addf3996..20f545ef337 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 -- cgit v1.2.3 From 67816da0bfe16ecb58d3a3bdb70c1fb9a79cff75 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 13:15:24 +0200 Subject: save current work state of office fallback --- lib/preview/msoffice.php | 95 ++++++++++++++++++++++++++++++++------------ lib/preview/opendocument.php | 12 ++++++ 2 files changed, 81 insertions(+), 26 deletions(-) diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index c99ca313c72..4fedb735c95 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; + + return $image->valid() ? $image : false; } + } -class DOC extends MSOffice2003 { +\OC\Preview::registerProvider('OC\Preview\DOCX'); + +class MSOfficeExcel extends Provider { public function getMimeType() { - return '/application\/msword/'; + 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'); -\OC\Preview::registerProvider('OC\Preview\DOC'); + $abspath = $fileview->toTmpFile($path); + $tmppath = \OC_Helper::tmpFile(); -class DOCX extends MSOffice2007 { + $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; + $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/dompdf'; - public function getMimeType() { - return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/'; + \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; } } -\OC\Preview::registerProvider('OC\Preview\DOCX'); - -class XLS extends MSOffice2003 { +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 e69de29bb2d..786a038ff82 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: 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 4fedb735c95..c2e39d00d94 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; } -- cgit v1.2.3 From 1f52ad0363e2cff05e2058d31317b580c27e2c31 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 12 Jun 2013 13:20:59 +0200 Subject: 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 c2e39d00d94..65886169e9a 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; } -- cgit v1.2.3 From f89a23b463884e1a9b89c84fdcb1c34afba62645 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 12 Jun 2013 16:18:16 +0200 Subject: 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 6b161424917..6e1dc06c1bc 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; } } -- cgit v1.2.3 From 25981a079a185080ad3ca2d2a23dd827efbd9d05 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 13 Jun 2013 09:52:39 +0200 Subject: 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 ed33e7b09dc..3564fe3df44 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 6e1dc06c1bc..4e1ca7de741 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 -- cgit v1.2.3 From 6082a0649cefd356370d4ca8034041c1af3875ff Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 17 Jun 2013 12:27:26 +0200 Subject: stream first mb of movie to create preview --- lib/preview/movies.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/preview/movies.php b/lib/preview/movies.php index cb959a962a7..8531050d112 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -17,17 +17,19 @@ 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(); + $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 -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); + $cmd = 'ffmpeg -an -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); + shell_exec($cmd); - $image = new \OC_Image($tmppath); unlink($abspath); -- cgit v1.2.3 From bea4376fd48e714b121e1abb54f9bd786e89c877 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 18 Jun 2013 11:04:08 +0200 Subject: 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 20f545ef337..b6783bc5798 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 786a038ff82..00000000000 --- a/lib/preview/opendocument.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Tue, 18 Jun 2013 13:53:02 +0200 Subject: 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 65886169e9a..262582f0216 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 -- cgit v1.2.3 From 1fcbf8dd7ac69bfce888cc61084a72919503fd05 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 19 Jun 2013 10:21:55 +0200 Subject: 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 60dfb5ff461..835ff529000 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; } } -- cgit v1.2.3 From fb67b458412241cb91c01bdb339d1a4317aeacab Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 19 Jun 2013 13:40:57 +0200 Subject: 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 262582f0216..ccf1d674c7a 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 { -- cgit v1.2.3 From efe4bfc693ce98fc45e6a003f9bedd0d9da1d1af Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 19 Jun 2013 13:43:11 +0200 Subject: update 3rdparty submodule --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 3ef9f738a91..0a8f54ed446 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 3ef9f738a9107879dddc7d97842cf4d2198fae4c +Subproject commit 0a8f54ed446d9c0d56f8abff3bdb18fcaa6f561b -- cgit v1.2.3 From 1a8e4399b0084a2769bbf43f0ba417c547ac931c Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Tue, 25 Jun 2013 15:08:51 +0200 Subject: 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 108dcd741c6..be29186cbb7 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; } -- cgit v1.2.3 From dc65482d50ae274b0db12cadce25f6fff0c86671 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Tue, 25 Jun 2013 17:57:38 +0200 Subject: 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 8f8095e46fa..2cbcb741d84 100644 Binary files a/core/img/filetypes/application-pdf.png and b/core/img/filetypes/application-pdf.png differ diff --git a/core/img/filetypes/application-pdf.svg b/core/img/filetypes/application-pdf.svg new file mode 100644 index 00000000000..3f9ad528afb --- /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 315c4f4fa62..e5bb322c573 100644 Binary files a/core/img/filetypes/application-rss+xml.png and b/core/img/filetypes/application-rss+xml.png differ diff --git a/core/img/filetypes/application-rss+xml.svg b/core/img/filetypes/application-rss+xml.svg new file mode 100644 index 00000000000..7b4f1127a94 --- /dev/null +++ b/core/img/filetypes/application-rss+xml.svg @@ -0,0 +1,914 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/core/img/filetypes/application.png b/core/img/filetypes/application.png index 1dee9e36609..3518d3116d2 100644 Binary files a/core/img/filetypes/application.png and b/core/img/filetypes/application.png differ diff --git a/core/img/filetypes/application.svg b/core/img/filetypes/application.svg new file mode 100644 index 00000000000..31951cc043c --- /dev/null +++ b/core/img/filetypes/application.svg @@ -0,0 +1,320 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/audio.png b/core/img/filetypes/audio.png index a8b3ede3df9..cd9821ec047 100644 Binary files a/core/img/filetypes/audio.png and b/core/img/filetypes/audio.png differ diff --git a/core/img/filetypes/audio.svg b/core/img/filetypes/audio.svg new file mode 100644 index 00000000000..f742383d632 --- /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 0c76bd12977..753d151f538 100644 Binary files a/core/img/filetypes/code.png and b/core/img/filetypes/code.png differ diff --git a/core/img/filetypes/code.svg b/core/img/filetypes/code.svg new file mode 100644 index 00000000000..1dee047b11f --- /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 8b8b1ca0000..c20f13c2e13 100644 Binary files a/core/img/filetypes/file.png and b/core/img/filetypes/file.png differ diff --git a/core/img/filetypes/file.svg b/core/img/filetypes/file.svg new file mode 100644 index 00000000000..f0c0f1daf7e --- /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 9f5db634a4f..bcde641da3c 100644 Binary files a/core/img/filetypes/flash.png and b/core/img/filetypes/flash.png differ diff --git a/core/img/filetypes/flash.svg b/core/img/filetypes/flash.svg new file mode 100644 index 00000000000..60cab4ad380 --- /dev/null +++ b/core/img/filetypes/flash.svg @@ -0,0 +1,310 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/folder.png b/core/img/filetypes/folder.png index 784e8fa4823..b7be63d5836 100644 Binary files a/core/img/filetypes/folder.png and b/core/img/filetypes/folder.png differ diff --git a/core/img/filetypes/folder.svg b/core/img/filetypes/folder.svg new file mode 100644 index 00000000000..dd80b695bb1 --- /dev/null +++ b/core/img/filetypes/folder.svg @@ -0,0 +1,329 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/font.png b/core/img/filetypes/font.png index 81e41de7d3a..df44a7fc47d 100644 Binary files a/core/img/filetypes/font.png and b/core/img/filetypes/font.png differ diff --git a/core/img/filetypes/font.svg b/core/img/filetypes/font.svg new file mode 100644 index 00000000000..404f622ea7b --- /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 a1291c2dfad..e3dd52489d3 100644 Binary files a/core/img/filetypes/image-svg+xml.png and b/core/img/filetypes/image-svg+xml.png differ diff --git a/core/img/filetypes/image-svg+xml.svg b/core/img/filetypes/image-svg+xml.svg new file mode 100644 index 00000000000..f9b378887f3 --- /dev/null +++ b/core/img/filetypes/image-svg+xml.svg @@ -0,0 +1,666 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/image.png b/core/img/filetypes/image.png index 4a158fef7e0..83d20fdb776 100644 Binary files a/core/img/filetypes/image.png and b/core/img/filetypes/image.png differ diff --git a/core/img/filetypes/image.svg b/core/img/filetypes/image.svg new file mode 100644 index 00000000000..440b6af7ac0 --- /dev/null +++ b/core/img/filetypes/image.svg @@ -0,0 +1,321 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text-html.png b/core/img/filetypes/text-html.png index 55d1072eafd..de11613f25f 100644 Binary files a/core/img/filetypes/text-html.png and b/core/img/filetypes/text-html.png differ diff --git a/core/img/filetypes/text-html.svg b/core/img/filetypes/text-html.svg new file mode 100644 index 00000000000..bf29fbcbbf2 --- /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 813f712f726..2b96638d16c 100644 Binary files a/core/img/filetypes/text.png and b/core/img/filetypes/text.png differ diff --git a/core/img/filetypes/text.svg b/core/img/filetypes/text.svg new file mode 100644 index 00000000000..93e6be14cb6 --- /dev/null +++ b/core/img/filetypes/text.svg @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + -- cgit v1.2.3 From c7fdf00e8497af9804b0cfd4fa081940bf53bc96 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 21 Jun 2013 14:24:52 +0200 Subject: 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 00000000000..2599da400c8 --- /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 -- cgit v1.2.3 From a98391b976ba7dd544af6a0d16b324efb2fc7a3c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 10:57:37 +0200 Subject: 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 3564fe3df44..87e2e78d1d8 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(); -- cgit v1.2.3 From 9b7efef39d3f7eae45741f0adf0bc0d52945d842 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 14:28:40 +0200 Subject: 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 e4041538e92..987aa9aef0a 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)); -- cgit v1.2.3 From 39c387eed4e5da7bddb6f7cd48a8f8b607f3b8dd Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 18:04:18 +0200 Subject: 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 1e94275dcba..6dabd7d6970 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 a315c640d1a..e8cc81774dd 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 ccf19cf052c..5f9888f9f28 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 ae9ea187445..048d172f1c9 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 -- cgit v1.2.3 From 806f3bddecbd8182f1da90ec91e2a03a1a6e2c3b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 26 Jun 2013 18:19:10 +0200 Subject: 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 be29186cbb7..222cc9c83ef 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 e8cc81774dd..0a8962a5312 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)); } /** -- cgit v1.2.3 From d332b1d4a2e9382aaa8e8a11b6200efaadb18768 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 2 Jul 2013 11:13:22 +0200 Subject: 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 e19a35bbc5b..11bf028d93a 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 a79d34c9b23..224167b99c1 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('.'); -- cgit v1.2.3 From 6e864e6599602609b5808ae4d043b273a9fe5071 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 2 Jul 2013 16:30:58 +0200 Subject: 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 b576253f4f0..c4a15c5fa61 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -6,9 +6,9 @@
t('New'));?>
    -
  • t('Text file'));?>

  • -
  • t('Folder'));?>

  • t('From link'));?>

  • -- cgit v1.2.3 From 04292ff16c56d85216ddbd6f644e8055413c0170 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 8 Jul 2013 10:53:53 +0200 Subject: implement use of preview icons in thrashbin app --- apps/files_trashbin/lib/trash.php | 4 ++++ apps/files_trashbin/templates/part.list.php | 2 +- core/routes.php | 2 ++ lib/preview.php | 35 +++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 7b8d3cb4252..e82a597c61e 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -850,4 +850,8 @@ class Trashbin { //Listen to delete user signal \OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Trashbin\Hooks", "deleteUser_hook"); } + + public static function preview_icon($path) { + return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => $path)); + } } diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 92a38bd2635..d53e38549d1 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -27,7 +27,7 @@ style="background-image:url()" - style="background-image:url()" + style="background-image:url()" > diff --git a/core/routes.php b/core/routes.php index 4b3ad53da01..41e82f8a73d 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_trashbin_preview', '/core/trashbinpreview.png') + ->action('OC\Preview', 'trashbinPreviewRouter'); $this->create('core_ajax_public_preview', '/core/publicpreview.png') ->action('OC\Preview', 'publicPreviewRouter'); OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; diff --git a/lib/preview.php b/lib/preview.php index 87e2e78d1d8..f12107c9f57 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -519,10 +519,6 @@ class Preview { $file = ''; $maxX = 0; $maxY = 0; - /* - * use: ?scalingup=0 / ?scalingup = 1 - * 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']); @@ -610,6 +606,37 @@ class Preview { } } + public static function trashbinPreviewRouter() { + if(!\OC_App::isEnabled('files_trashbin')){ + exit; + } + \OC_Util::checkLoggedIn(); + + $file = ''; + $maxX = 0; + $maxY = 0; + $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) { + try{ + $preview = new Preview(\OC_User::getUser(), 'files_trashbin/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; + } + } + public static function post_write($args) { self::post_delete($args); } -- cgit v1.2.3 From d699135c5e9cc56b7c3bcbb2263ffa5946b0b8b6 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 8 Jul 2013 15:14:25 +0200 Subject: fix for previews in trashbin app --- apps/files_trashbin/templates/part.list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index d53e38549d1..3f260867582 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -27,7 +27,7 @@ style="background-image:url()" - style="background-image:url()" + style="background-image:url()" > -- cgit v1.2.3 From 8eefaba719160eb92dcb6747b5e70b7e04736cea Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 9 Jul 2013 11:40:09 +0200 Subject: some style adjustments --- apps/files/css/files.css | 4 ++-- apps/files/templates/index.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 222cc9c83ef..d7843ab3535 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -19,9 +19,9 @@ background:#f8f8f8; border:1px solid #ddd; border-radius:10px; border-top-left-radius:0; box-shadow:0 2px 7px rgba(170,170,170,.4); } -#new>ul>li { height:20px; margin:.3em; padding-left:2em; padding-bottom:0.1em; +#new>ul>li { height:36px; margin:.3em; padding-left:3em; padding-bottom:0.1em; background-repeat:no-repeat; cursor:pointer; } -#new>ul>li>p { cursor:pointer; } +#new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;} #new>ul>li>form>input { padding:0.3em; margin:-0.3em; } #trash { height:17px; margin: 0 1em; z-index:1010; float: right; } diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index c4a15c5fa61..89e270fd146 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -6,11 +6,11 @@
    t('New'));?>
      -
    • t('Text file'));?>

    • -
    • t('Folder'));?>

    • -
    • t('From link'));?>

    -- cgit v1.2.3 From cf449d42e87b21dff0de35c394031c5fa28b56aa Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 10 Jul 2013 11:25:28 +0200 Subject: properly encode path --- apps/files/js/files.js | 2 +- apps/files_trashbin/lib/trash.php | 2 +- lib/helper.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 224167b99c1..06d193bf8f3 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -960,7 +960,7 @@ function getMimeIcon(mime, ready){ getMimeIcon.cache={}; function getPreviewIcon(path, ready){ - ready(OC.Router.generate('core_ajax_preview', {file:path, x:44, y:44})); + ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:44, y:44})); } function getUniqueName(name){ diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index e82a597c61e..fb99fca5b3f 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -852,6 +852,6 @@ class Trashbin { } public static function preview_icon($path) { - return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => $path)); + return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) )); } } diff --git a/lib/helper.php b/lib/helper.php index 0a8962a5312..326f2567f99 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' => 44, 'y' => 44, 'file' => $path)); + return self::linkToRoute( 'core_ajax_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) )); } /** -- cgit v1.2.3 From 832779804d36d27c47325d1dcce09e566c8cee60 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 10 Jul 2013 12:18:17 +0200 Subject: add two new icons - for copyright see filetypes/readme-2.txt --- core/img/web.png | Bin 0 -> 4472 bytes core/img/web.svg | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 core/img/web.png create mode 100644 core/img/web.svg diff --git a/core/img/web.png b/core/img/web.png new file mode 100644 index 00000000000..bdc2f4a84a5 Binary files /dev/null and b/core/img/web.png differ diff --git a/core/img/web.svg b/core/img/web.svg new file mode 100644 index 00000000000..bc6c6bde650 --- /dev/null +++ b/core/img/web.svg @@ -0,0 +1,183 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 45d16916718ea103b371da9c7bef0385717d8cef Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 10 Jul 2013 13:38:42 +0200 Subject: fix orientation before caching preview --- lib/preview.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index f12107c9f57..6173fc8aa6b 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -332,7 +332,7 @@ class Preview { $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup, $this->fileview); - if(!$preview) { + if(!($preview instanceof \OC_Image)) { continue; } @@ -346,6 +346,8 @@ class Preview { if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/') === false) { $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/'); } + + $preview->fixOrientation(); $this->userview->file_put_contents($cachepath, $preview->data()); break; @@ -382,8 +384,6 @@ class Preview { * @return image */ public function resizeAndCrop() { - $this->preview->fixOrientation(); - $image = $this->preview; $x = $this->maxX; $y = $this->maxY; -- cgit v1.2.3 From 7091d7a6d2c495901383d89aaa0030366bf61d02 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 10 Jul 2013 17:57:04 +0200 Subject: clean up oc\preview --- lib/preview.php | 301 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 181 insertions(+), 120 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 6173fc8aa6b..8ecad159157 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -23,7 +23,7 @@ require_once('preview/unknown.php'); require_once('preview/office.php'); class Preview { - //the thumbnail folder + //the thumbnail folder const THUMBNAILS_FOLDER = 'thumbnails'; //config @@ -50,7 +50,7 @@ class Preview { /** * @brief check if thumbnail or bigger version of thumbnail of file is cached - * @param $user userid + * @param $user userid - if no user is given, OC_User::getUser will be used * @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 @@ -59,73 +59,35 @@ 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='', $root='/', $file='', $maxX=1, $maxY=1, $scalingup=true) { //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); //save parameters - $this->file = $file; - $this->maxX = $maxX; - $this->maxY = $maxY; - $this->scalingup = $scalingup; + $this->setFile($file); + $this->setMaxX($maxX); + $this->setMaxY($maxY); + $this->setScalingUp($scalingup); //init fileviews + if($user === ''){ + $user = OC_User::getUser(); + } $this->fileview = new \OC\Files\View('/' . $user . '/' . $root); $this->userview = new \OC\Files\View('/' . $user); + + $this->preview = null; - 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; - } - } - - $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(); - } - - //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 there are preview backends + if(empty(self::$providers)) { + self::initProviders(); + } - //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'); - } + if(empty(self::$providers)) { + \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); + throw new \Exception('No preview providers'); } } @@ -165,7 +127,7 @@ class Preview { * @brief returns the name of the thumbnailfolder * @return string */ - public function getThumbnailsfolder() { + public function getThumbnailsFolder() { return self::THUMBNAILS_FOLDER; } @@ -193,16 +155,97 @@ class Preview { return $this->max_y; } + /** + * @brief set the path of the file you want a thumbnail from + * @return $this + */ + public function setFile($file) { + $this->file = $file; + return $this; + } + + /** + * @brief set the the max width of the preview + * @return $this + */ + public function setMaxX($maxX=1) { + if($maxX === 0) { + throw new \Exception('Cannot set width of 0!'); + } + $configMaxX = $this->getConfigMaxX(); + if(!is_null($configMaxX)) { + if($maxX > $configMaxX) { + \OC_Log::write('core', 'maxX reduced from ' . $maxX . ' to ' . $configMaxX, \OC_Log::DEBUG); + $maxX = $configMaxX; + } + } + $this->maxX = $maxX; + return $this; + } + + /** + * @brief set the the max height of the preview + * @return $this + */ + public function setMaxY($maxY=1) { + if($maxY === 0) { + throw new \Exception('Cannot set height of 0!'); + } + $configMaxY = $this->getConfigMaxY(); + if(!is_null($configMaxY)) { + if($maxY > $configMaxY) { + \OC_Log::write('core', 'maxX reduced from ' . $maxY . ' to ' . $configMaxY, \OC_Log::DEBUG); + $maxY = $configMaxY; + } + } + $this->maxY = $maxY; + return $this; + } + + /** + * @brief set whether or not scalingup is enabled + * @return $this + */ + public function setScalingup($scalingup) { + if($this->getMaxScaleFactor() === 1) { + $scalingup = false; + } + $this->scalingup = $scalingup; + return $this; + } + + /** + * @brief check if all parameters are valid + * @return integer + */ + public function isFileValid() { + $file = $this->getFile(); + if($file === '') { + \OC_Log::write('core', 'No filename passed', \OC_Log::ERROR); + return false; + } + + if(!$this->fileview->file_exists($file)) { + \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::ERROR); + return false; + } + + return true; + } + /** * @brief deletes previews of a file with specific x and y * @return bool */ public function deletePreview() { - $fileinfo = $this->fileview->getFileInfo($this->file); + $file = $this->getFile(); + + $fileinfo = $this->fileview->getFileInfo($file); $fileid = $fileinfo['fileid']; - $this->userview->unlink(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $this->maxX . '-' . $this->maxY . '.png'); - return; + $previepath = $this->getThumbnailsFolder() . '/' . $fileid . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; + $this->userview->unlink($previepath); + return $this->userview->file_exists($previepath); } /** @@ -210,12 +253,15 @@ class Preview { * @return bool */ public function deleteAllPreviews() { - $fileinfo = $this->fileview->getFileInfo($this->file); - $fileid = $fileinfo['fileid']; + $file = $this->getFile(); - $this->userview->deleteAll(self::THUMBNAILS_FOLDER . '/' . $fileid . '/'); - $this->userview->rmdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/'); - return; + $fileinfo = $this->fileview->getFileInfo($file); + $fileid = $fileinfo['fileid']; + + $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; + $this->userview->deleteAll($previewpath); + $this->userview->rmdir($previewpath); + return $this->userview->is_dir($previepath); } /** @@ -225,21 +271,23 @@ class Preview { * path to thumbnail if thumbnail exists */ private function isCached() { - $file = $this->file; - $maxX = $this->maxX; - $maxY = $this->maxY; - $scalingup = $this->scalingup; + $file = $this->getFile(); + $maxX = $this->getMaxX(); + $maxY = $this->getMaxY(); + $scalingup = $this->getScalingup(); + $maxscalefactor = $this->getMaxScaleFactor(); $fileinfo = $this->fileview->getFileInfo($file); $fileid = $fileinfo['fileid']; - if(!$this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid)) { + $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; + if(!$this->userview->is_dir($previewpath)) { return false; } //does a preview with the wanted height and width already exist? - if($this->userview->file_exists(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')) { - return self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png'; + if($this->userview->file_exists($previewpath . $maxX . '-' . $maxY . '.png')) { + return $previewpath . $maxX . '-' . $maxY . '.png'; } $wantedaspectratio = $maxX / $maxY; @@ -247,7 +295,7 @@ class Preview { //array for usable cached thumbnails $possiblethumbnails = array(); - $allthumbnails = $this->userview->getDirectoryContent(self::THUMBNAILS_FOLDER . '/' . $fileid); + $allthumbnails = $this->userview->getDirectoryContent($previewpath); foreach($allthumbnails as $thumbnail) { $size = explode('-', $thumbnail['name']); $x = $size[0]; @@ -261,7 +309,7 @@ class Preview { if($x < $maxX || $y < $maxY) { if($scalingup) { $scalefactor = $maxX / $x; - if($scalefactor > $this->max_scale_factor) { + if($scalefactor > $maxscalefactor) { continue; } }else{ @@ -307,22 +355,28 @@ class Preview { * @return image */ public function getPreview() { - $file = $this->file; - $maxX = $this->maxX; - $maxY = $this->maxY; - $scalingup = $this->scalingup; + if(!is_null($this->preview) && $this->preview->valid()){ + return $this->preview; + } + + $this->preview = null; + $file = $this->getFile(); + $maxX = $this->getMaxX(); + $maxY = $this->getMaxY(); + $scalingup = $this->getScalingup(); $fileinfo = $this->fileview->getFileInfo($file); $fileid = $fileinfo['fileid']; - $cached = self::isCached(); + $cached = $this->isCached(); if($cached) { $image = new \OC_Image($this->userview->file_get_contents($cached, 'r')); - $this->preview = $image; - }else{ - $mimetype = $this->fileview->getMimeType($file); + $this->preview = $image->valid() ? $image : null; + } + if(is_null($this->preview)) { + $mimetype = $this->fileview->getMimeType($file); $preview = null; foreach(self::$providers as $supportedmimetype => $provider) { @@ -336,35 +390,35 @@ class Preview { continue; } - //are there any cached thumbnails yet - if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/') === false) { - $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/'); + $this->preview = $preview; + $this->resizeAndCrop(); + + $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; + $cachepath = $previewpath . $maxX . '-' . $maxY . '.png'; + + if($this->userview->is_dir($this->getThumbnailsFolder() . '/') === false) { + $this->userview->mkdir($this->getThumbnailsFolder() . '/'); } - //cache thumbnail - $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 . '/'); + if($this->userview->is_dir($previewpath) === false) { + $this->userview->mkdir($previewpath); } - $preview->fixOrientation(); $this->userview->file_put_contents($cachepath, $preview->data()); break; } + } - if(is_null($preview) || $preview === false) { - $preview = new \OC_Image(); - } - - $this->preview = $preview; + if(is_null($this->preview)) { + $this->preview = new \OC_Image(); } - $this->resizeAndCrop(); + return $this->preview; } /** - * @brief return a preview of a file + * @brief show preview * @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 @@ -372,67 +426,74 @@ class Preview { * @return void */ public function showPreview() { - \OCP\Response::enableCaching(3600 * 24); // 24 hour - $preview = $this->getPreview(); - if($preview) { - $preview->show(); + \OCP\Response::enableCaching(3600 * 24); // 24 hours + if(is_null($this->preview)) { + $this->getPreview(); } + $this->preview->show(); } /** * @brief resize, crop and fix orientation * @return image */ - public function resizeAndCrop() { + private function resizeAndCrop() { $image = $this->preview; - $x = $this->maxX; - $y = $this->maxY; - $scalingup = $this->scalingup; + $x = $this->getMaxX(); + $y = $this->getMaxY(); + $scalingup = $this->getScalingup(); + $maxscalefactor = $this->getMaxScaleFactor(); 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', '$this->preview is not an instance of OC_Image', \OC_Log::DEBUG); return; } + $image->fixOrientation(); + $realx = (int) $image->width(); $realy = (int) $image->height(); if($x === $realx && $y === $realy) { - return $image; + $this->preview = $image; + return true; } $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($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; + + if(!is_null($maxscalefactor)) { + if($factor > $maxscalefactor) { + \OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $maxscalefactor, \OC_Log::DEBUG); + $factor = $maxscalefactor; } } - $newXsize = $realx * $factor; - $newYsize = $realy * $factor; - // resize + $newXsize = (int) ($realx * $factor); + $newYsize = (int) ($realy * $factor); + $image->preciseResize($newXsize, $newYsize); - if($newXsize === $x && $newYsize === $y) { + if($newXsize == $x && $newYsize === $y) { $this->preview = $image; return; } if($newXsize >= $x && $newYsize >= $y) { $cropX = floor(abs($x - $newXsize) * 0.5); + //don't crop previews on the Y axis, this sucks if it's a document. //$cropY = floor(abs($y - $newYsize) * 0.5); $cropY = 0; -- cgit v1.2.3 From f14b0fa6e0dfad28f2f6573ec517019ac12342cf Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 10 Jul 2013 18:01:04 +0200 Subject: update some comments in preview lib --- lib/preview.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 8ecad159157..0a8ab438367 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -348,10 +348,6 @@ 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 function getPreview() { @@ -419,10 +415,6 @@ class Preview { /** * @brief show preview - * @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 void */ public function showPreview() { @@ -431,6 +423,7 @@ class Preview { $this->getPreview(); } $this->preview->show(); + return; } /** @@ -486,7 +479,7 @@ class Preview { $image->preciseResize($newXsize, $newYsize); - if($newXsize == $x && $newYsize === $y) { + if($newXsize === $x && $newYsize === $y) { $this->preview = $image; return; } -- cgit v1.2.3 From 5c31b843fc62b2be43d85ca680eeffa3e6f292dd Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 10 Jul 2013 18:04:13 +0200 Subject: fix typo --- lib/preview.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 0a8ab438367..f018fa38850 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -243,9 +243,9 @@ class Preview { $fileinfo = $this->fileview->getFileInfo($file); $fileid = $fileinfo['fileid']; - $previepath = $this->getThumbnailsFolder() . '/' . $fileid . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; - $this->userview->unlink($previepath); - return $this->userview->file_exists($previepath); + $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; + $this->userview->unlink($previewpath); + return $this->userview->file_exists($previewpath); } /** @@ -261,7 +261,7 @@ class Preview { $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; $this->userview->deleteAll($previewpath); $this->userview->rmdir($previewpath); - return $this->userview->is_dir($previepath); + return $this->userview->is_dir($previewpath); } /** -- cgit v1.2.3 From 7f71ae60b0fefe697aa9da2cda40853736df0580 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 10:10:07 +0200 Subject: improve validation of oc\preview and implement preview of error icon if something went wrong --- lib/preview.php | 255 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 159 insertions(+), 96 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index f018fa38850..94e0cd96e7c 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -426,6 +426,14 @@ class Preview { return; } + /** + * @brief show preview + * @return void + */ + public function show() { + return $this->showPreview(); + } + /** * @brief resize, crop and fix orientation * @return image @@ -567,30 +575,40 @@ 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() { \OC_Util::checkLoggedIn(); - $file = ''; - $maxX = 0; - $maxY = 0; - $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) { - try{ - $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); - exit; - } - }else{ - \OC_Response::setStatus(404); + $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; + $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; + $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; + $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; + + if($file === '') { + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); + self::showErrorPreview(); + exit; + } + + if($maxX === 0 || $maxY === 0) { + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); + self::showErrorPreview(); + exit; + } + + try{ + $preview = new Preview(\OC_User::getUser(), 'files'); + $preview->setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingup); + + $preview->show(); + }catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + self::showErrorPreview(); exit; } } @@ -599,94 +617,132 @@ 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) { - $file = ''; - $maxX = 0; - $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($userid); - - $pathid = $linkItem['file_source']; - $path = \OC\Files\Filesystem::getPath($pathid); - $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']; - } + public static function publicPreviewRouter() { + if(!\OC_App::isEnabled('files_sharing')){ + exit; + } - $path = \OC\Files\Filesystem::normalizePath($path, false); - if(substr($path, 0, 1) == '/') { - $path = substr($path, 1); - } + $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; + $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; + $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; + $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; + $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; + + if($token === ''){ + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG); + self::showErrorPreview(); + exit; } - if($userid !== null && $path !== null && $sharedfile !== null) { - try{ - $preview = new Preview($userid, 'files/' . $path, $sharedfile, $maxX, $maxY, $scalingup); - $preview->showPreview(); - }catch(\Exception $e) { - \OC_Response::setStatus(404); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + $linkedItem = \OCP\Share::getShareByToken($token); + if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) { + \OC_Response::setStatus(404); + \OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG); + self::showErrorPreview(); + exit; + } + + if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) { + \OC_Response::setStatus(500); + \OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")'); + self::showErrorPreview(); + exit; + } + + $userid = $linkedItem['uid_owner']; + \OC_Util::setupFS($userid); + + $pathid = $linkedItem['file_source']; + $path = \OC\Files\Filesystem::getPath($pathid); + $pathinfo = \OC\Files\Filesystem::getFileInfo($path); + $sharedfile = null; + + if($linkedItem['item_type'] === 'folder') { + $isvalid = \OC\File\Filesystem::isValidPath($file); + if(!$isvalid) { + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN); + self::showErrorPreview(); exit; } - }else{ - \OC_Response::setStatus(404); + $sharedfile = \OC\Files\Filesystem::normalizePath($file); + } + + if($linkedItem['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); + } + + if($maxX === 0 || $maxY === 0) { + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); + self::showErrorPreview(); + exit; + } + + $root = 'files/' . $path; + + try{ + $preview = new Preview($userid, $path); + $preview->setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingup); + + $preview->show(); + }catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + self::showErrorPreview(); exit; } } public static function trashbinPreviewRouter() { + \OC_Util::checkLoggedIn(); + if(!\OC_App::isEnabled('files_trashbin')){ exit; } - \OC_Util::checkLoggedIn(); - $file = ''; - $maxX = 0; - $maxY = 0; - $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) { - try{ - $preview = new Preview(\OC_User::getUser(), 'files_trashbin/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); + $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; + $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; + $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; + $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; + + if($file === '') { + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); + self::showErrorPreview(); + exit; + } + + if($maxX === 0 || $maxY === 0) { + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); + self::showErrorPreview(); + exit; + } + + try{ + $preview = new Preview(\OC_User::getUser(), 'files_trashbin/files'); + $preview->setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingup); + + $preview->showPreview(); + }catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + self::showErrorPreview(); exit; } } @@ -703,4 +759,11 @@ class Preview { $preview = new Preview(\OC_User::getUser(), 'files/', $path, 0, 0, false, true); $preview->deleteAllPreviews(); } + + private static function showErrorPreview() { + $path = \OC::$SERVERROOT . '/core/img/actions/delete.png'; + $preview = new \OC_Image($path); + $preview->preciseResize(44, 44); + $preview->show(); + } } \ No newline at end of file -- cgit v1.2.3 From 4bbbba1dc8288462881d9bfdf979b3f207572d2e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 11:43:53 +0200 Subject: fix typo --- lib/preview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 94e0cd96e7c..5b2ee2cddd4 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -659,7 +659,7 @@ class Preview { $sharedfile = null; if($linkedItem['item_type'] === 'folder') { - $isvalid = \OC\File\Filesystem::isValidPath($file); + $isvalid = \OC\Files\Filesystem::isValidPath($file); if(!$isvalid) { \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN); -- cgit v1.2.3 From 06eca985ce493bba65293003bd52aed10566c6d6 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 11:57:19 +0200 Subject: use $root instead of $path --- lib/preview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 5b2ee2cddd4..62bcf4873b5 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -690,7 +690,7 @@ class Preview { $root = 'files/' . $path; try{ - $preview = new Preview($userid, $path); + $preview = new Preview($userid, $root); $preview->setFile($file); $preview->setMaxX($maxX); $preview->setMaxY($maxY); -- cgit v1.2.3 From 53830f2f751151d2d326b253471e63d9b1cf8eb1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 11:58:52 +0200 Subject: implement use of previews in sharing app --- apps/files/index.php | 1 + apps/files/templates/part.list.php | 9 ++++++++- apps/files_sharing/public.php | 3 +++ lib/helper.php | 4 ++++ lib/public/template.php | 10 ++++++++++ lib/template.php | 4 ++++ 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/files/index.php b/apps/files/index.php index 2338cf439e4..156febd87f4 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -95,6 +95,7 @@ $list->assign('files', $files); $list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir='); $list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/'))); $list->assign('disableSharing', false); +$list->assign('isPublic', false); $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); $breadcrumbNav->assign('breadcrumb', $breadcrumb); $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir='); diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 38d1314392b..9e62c991975 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -30,7 +30,14 @@ $totalsize = 0; ?> style="background-image:url()" - style="background-image:url()" + + + style="background-image:url()" + + style="background-image:url()" + > diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 9462844a82b..0c4150f74d2 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -191,6 +191,9 @@ if (isset($path)) { $list->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path='); $list->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path='); + $list->assign('isPublic', true); + $list->assign('sharingtoken', $token); + $list->assign('sharingroot', ($path)); $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); $breadcrumbNav->assign('breadcrumb', $breadcrumb); $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path='); diff --git a/lib/helper.php b/lib/helper.php index 856dba625b3..6153f318723 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -234,6 +234,10 @@ class OC_Helper { return self::linkToRoute( 'core_ajax_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) )); } + public static function publicPreview_icon( $path, $token ) { + return self::linkToRoute( 'core_ajax_public_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path), 't' => $token)); + } + /** * @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 5f9888f9f28..69997ad42b6 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -64,6 +64,16 @@ function preview_icon( $path ) { return(\preview_icon( $path )); } +/** + * @brief make publicpreview_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 publicPreview_icon ( $path, $token ) { + return(\publicPreview_icon( $path, $token )); +} + /** * @brief make OC_Helper::humanFileSize available as a simple function * Makes 2048 to 2 kB. diff --git a/lib/template.php b/lib/template.php index 048d172f1c9..842c3325357 100644 --- a/lib/template.php +++ b/lib/template.php @@ -74,6 +74,10 @@ function preview_icon( $path ) { return OC_Helper::previewIcon( $path ); } +function publicPreview_icon ( $path, $token ) { + return OC_Helper::publicPreview_icon( $path, $token ); +} + /** * @brief make OC_Helper::mimetypeIcon available as a simple function * @param string $mimetype mimetype -- cgit v1.2.3 From ec75e1904d9d4c77d1a6c1c656e7deeae07a8804 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 12:28:41 +0200 Subject: make jenkins happy --- lib/preview/unknown.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index 4e1ca7de741..a31b365722e 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -22,7 +22,11 @@ class Unknown extends Provider { $iconsroot = \OC::$SERVERROOT . '/core/img/filetypes/'; - $icons = array($mimetype, $type, 'text'); + if(isset($type)){ + $icons = array($mimetype, $type, 'text'); + }else{ + $icons = array($mimetype, 'text'); + } foreach($icons as $icon) { $icon = str_replace('/', '-', $icon); -- cgit v1.2.3 From 89554bd917f9cbc7d16cc31b754a47d9f942b0b1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 13:39:10 +0200 Subject: it's setValue not getValue, damn type --- tests/lib/preview.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 2599da400c8..c4894f848f6 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -74,8 +74,8 @@ class Preview extends \PHPUnit_Framework_TestCase { $maxX = 250; $maxY = 250; - \OC_Config::getValue('preview_max_x', $maxX); - \OC_Config::getValue('preview_max_y', $maxY); + \OC_Config::setValue('preview_max_x', $maxX); + \OC_Config::setValue('preview_max_y', $maxY); $rootView = new \OC\Files\View(''); $rootView->mkdir('/'.$user); @@ -87,7 +87,10 @@ class Preview extends \PHPUnit_Framework_TestCase { $preview = new \OC\Preview($user, 'files/', 'test.txt', 1000, 1000); $image = $preview->getPreview(); - + + var_dump($image->width()); + var_dump($image->height()); + $this->assertEquals($image->width(), $maxX); $this->assertEquals($image->height(), $maxY); } -- cgit v1.2.3 From 7f3dbb6936cded830cbbf135f887a84ebd50b77c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 13:41:09 +0200 Subject: remove debug code ... --- tests/lib/preview.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/lib/preview.php b/tests/lib/preview.php index c4894f848f6..bebdc12b500 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -87,10 +87,7 @@ class Preview extends \PHPUnit_Framework_TestCase { $preview = new \OC\Preview($user, 'files/', 'test.txt', 1000, 1000); $image = $preview->getPreview(); - - var_dump($image->width()); - var_dump($image->height()); - + $this->assertEquals($image->width(), $maxX); $this->assertEquals($image->height(), $maxY); } -- cgit v1.2.3 From 7b2aa5d830efeea7e68a71ddc33bc6e9add1409d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 19:03:21 +0200 Subject: OC\Preview - use camelCase --- lib/preview.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 62bcf4873b5..327a45d8d13 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -27,9 +27,9 @@ class Preview { const THUMBNAILS_FOLDER = 'thumbnails'; //config - private $max_scale_factor; - private $max_x; - private $max_y; + private $maxScaleFactor; + private $configMaxX; + private $configMaxY; //fileview object private $fileview = null; @@ -61,9 +61,9 @@ class Preview { */ public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingup=true) { //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->configMaxX = \OC_Config::getValue('preview_max_x', null); + $this->configMaxY = \OC_Config::getValue('preview_max_y', null); + $this->maxScaleFactor = \OC_Config::getValue('preview_max_scale_factor', 10); //save parameters $this->setFile($file); @@ -136,7 +136,7 @@ class Preview { * @return integer */ public function getMaxScaleFactor() { - return $this->max_scale_factor; + return $this->maxScaleFactor; } /** @@ -144,7 +144,7 @@ class Preview { * @return integer */ public function getConfigMaxX() { - return $this->max_x; + return $this->configMaxX; } /** @@ -152,7 +152,7 @@ class Preview { * @return integer */ public function getConfigMaxY() { - return $this->max_y; + return $this->configMaxY; } /** -- cgit v1.2.3 From 1e8a646f51428d19f565fa702cbb935ca8267adb Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 19:21:37 +0200 Subject: OC\Preview - improve documentation --- lib/preview.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 327a45d8d13..fba1d893e08 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -50,11 +50,12 @@ class Preview { /** * @brief check if thumbnail or bigger version of thumbnail of file is cached - * @param $user userid - if no user is given, OC_User::getUser will be used - * @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 + * @param string $user userid - if no user is given, OC_User::getUser will be used + * @param string $root path of root + * @param string $file The path to the file where you want a thumbnail from + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image + * @param bool $scalingup Disable/Enable upscaling of previews * @return mixed (bool / string) * false if thumbnail does not exist * path to thumbnail if thumbnail exists @@ -157,6 +158,7 @@ class Preview { /** * @brief set the path of the file you want a thumbnail from + * @param string $file * @return $this */ public function setFile($file) { @@ -166,6 +168,7 @@ class Preview { /** * @brief set the the max width of the preview + * @param int $maxX * @return $this */ public function setMaxX($maxX=1) { @@ -185,6 +188,7 @@ class Preview { /** * @brief set the the max height of the preview + * @param int $maxY * @return $this */ public function setMaxY($maxY=1) { @@ -204,6 +208,7 @@ class Preview { /** * @brief set whether or not scalingup is enabled + * @param bool $scalingup * @return $this */ public function setScalingup($scalingup) { @@ -216,7 +221,7 @@ class Preview { /** * @brief check if all parameters are valid - * @return integer + * @return bool */ public function isFileValid() { $file = $this->getFile(); @@ -543,6 +548,7 @@ class Preview { /** * @brief register a new preview provider to be used * @param string $provider class name of a Preview_Provider + * @param array $options * @return void */ public static function registerProvider($class, $options=array()) { -- cgit v1.2.3 From c6849bed9da49b488497eb44c81059630bade2e0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 20:02:59 +0200 Subject: OC\Preview - remove unneeded comment --- lib/preview/provider.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/preview/provider.php b/lib/preview/provider.php index 44e1d11ba06..e4a730bafc8 100644 --- a/lib/preview/provider.php +++ b/lib/preview/provider.php @@ -1,7 +1,4 @@ Date: Thu, 11 Jul 2013 20:15:30 +0200 Subject: OC\Preview - fix logic of two return values --- lib/preview.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index fba1d893e08..cc287595f40 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -250,7 +250,7 @@ class Preview { $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; $this->userview->unlink($previewpath); - return $this->userview->file_exists($previewpath); + return !$this->userview->file_exists($previewpath); } /** @@ -266,7 +266,7 @@ class Preview { $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; $this->userview->deleteAll($previewpath); $this->userview->rmdir($previewpath); - return $this->userview->is_dir($previewpath); + return !$this->userview->is_dir($previewpath); } /** -- cgit v1.2.3 From 14a35267c15115a1e7d2901ddd9b8c5c7e1b9a31 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 11 Jul 2013 20:35:55 +0200 Subject: OC\Preview - outsource static methods --- core/routes.php | 7 ++++--- lib/preview.php | 29 +++++++++++++++++++---------- lib/preview/images.php | 2 +- lib/preview/libreoffice-cl.php | 10 +++++----- lib/preview/movies.php | 2 +- lib/preview/mp3.php | 2 +- lib/preview/msoffice.php | 12 ++++++------ lib/preview/pdf.php | 2 +- lib/preview/svg.php | 2 +- lib/preview/txt.php | 6 +++--- lib/preview/unknown.php | 2 +- 11 files changed, 43 insertions(+), 33 deletions(-) diff --git a/core/routes.php b/core/routes.php index 41e82f8a73d..c0e658b26dc 100644 --- a/core/routes.php +++ b/core/routes.php @@ -42,12 +42,13 @@ $this->create('js_config', '/core/js/config.js') // Routing $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); +OC::$CLASSPATH['OC\PreviewManager'] = 'lib/preview.php'; $this->create('core_ajax_preview', '/core/preview.png') - ->action('OC\Preview', 'previewRouter'); + ->action('OC\PreviewManager', 'previewRouter'); $this->create('core_ajax_trashbin_preview', '/core/trashbinpreview.png') - ->action('OC\Preview', 'trashbinPreviewRouter'); + ->action('OC\PreviewManager', 'trashbinPreviewRouter'); $this->create('core_ajax_public_preview', '/core/publicpreview.png') - ->action('OC\Preview', 'publicPreviewRouter'); + ->action('OC\PreviewManager', '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 cc287595f40..73e01a9e552 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -44,10 +44,6 @@ class Preview { //preview images object private $preview; - //preview providers - static private $providers = array(); - static private $registeredProviders = array(); - /** * @brief check if thumbnail or bigger version of thumbnail of file is cached * @param string $user userid - if no user is given, OC_User::getUser will be used @@ -82,11 +78,13 @@ class Preview { $this->preview = null; //check if there are preview backends - if(empty(self::$providers)) { - self::initProviders(); + $providers = PreviewManager::getProviders(); + if(empty($providers)) { + PreviewManager::initProviders(); } - if(empty(self::$providers)) { + $providers = PreviewManager::getProviders(); + if(empty($providers)) { \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); throw new \Exception('No preview providers'); } @@ -380,7 +378,8 @@ class Preview { $mimetype = $this->fileview->getMimeType($file); $preview = null; - foreach(self::$providers as $supportedmimetype => $provider) { + $providers = PreviewManager::getProviders(); + foreach($providers as $supportedmimetype => $provider) { if(!preg_match($supportedmimetype, $mimetype)) { continue; } @@ -544,6 +543,16 @@ class Preview { return; } } +} + +class PreviewManager { + //preview providers + static private $providers = array(); + static private $registeredProviders = array(); + + public static function getProviders() { + return self::$providers; + } /** * @brief register a new preview provider to be used @@ -559,7 +568,7 @@ class Preview { * @brief create instances of all the registered preview providers * @return void */ - private static function initProviders() { + public static function initProviders() { if(count(self::$providers)>0) { return; } @@ -766,7 +775,7 @@ class Preview { $preview->deleteAllPreviews(); } - private static function showErrorPreview() { + public static function showErrorPreview() { $path = \OC::$SERVERROOT . '/core/img/actions/delete.png'; $preview = new \OC_Image($path); $preview->preciseResize(44, 44); diff --git a/lib/preview/images.php b/lib/preview/images.php index 987aa9aef0a..84ab9f1ae43 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -30,4 +30,4 @@ class Image extends Provider { } } -\OC\Preview::registerProvider('OC\Preview\Image'); \ No newline at end of file +\OC\PreviewManager::registerProvider('OC\Preview\Image'); \ No newline at end of file diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 2749c4867e9..ffe8de505f7 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -80,7 +80,7 @@ class MSOfficeDoc extends Office { } -\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc'); +\OC\PreviewManager::registerProvider('OC\Preview\MSOfficeDoc'); //.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m) class MSOffice2003 extends Office { @@ -91,7 +91,7 @@ class MSOffice2003 extends Office { } -\OC\Preview::registerProvider('OC\Preview\MSOffice2003'); +\OC\PreviewManager::registerProvider('OC\Preview\MSOffice2003'); //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx class MSOffice2007 extends Office { @@ -102,7 +102,7 @@ class MSOffice2007 extends Office { } -\OC\Preview::registerProvider('OC\Preview\MSOffice2007'); +\OC\PreviewManager::registerProvider('OC\Preview\MSOffice2007'); //.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt class OpenDocument extends Office { @@ -113,7 +113,7 @@ class OpenDocument extends Office { } -\OC\Preview::registerProvider('OC\Preview\OpenDocument'); +\OC\PreviewManager::registerProvider('OC\Preview\OpenDocument'); //.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm class StarOffice extends Office { @@ -124,4 +124,4 @@ class StarOffice extends Office { } -\OC\Preview::registerProvider('OC\Preview\StarOffice'); \ No newline at end of file +\OC\PreviewManager::registerProvider('OC\Preview\StarOffice'); \ No newline at end of file diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 8531050d112..f4452e02fc2 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -39,5 +39,5 @@ if(!is_null(shell_exec('ffmpeg -version'))) { } } - \OC\Preview::registerProvider('OC\Preview\Movie'); + \OC\PreviewManager::registerProvider('OC\Preview\Movie'); } \ No newline at end of file diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 835ff529000..baa24ad129e 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -43,4 +43,4 @@ class MP3 extends Provider { } -\OC\Preview::registerProvider('OC\Preview\MP3'); \ No newline at end of file +\OC\PreviewManager::registerProvider('OC\Preview\MP3'); \ No newline at end of file diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index ccf1d674c7a..9f6ea7f74cf 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -20,7 +20,7 @@ class DOC extends Provider { } -\OC\Preview::registerProvider('OC\Preview\DOC'); +\OC\PreviewManager::registerProvider('OC\Preview\DOC'); */ class DOCX extends Provider { @@ -50,7 +50,7 @@ class DOCX extends Provider { } -\OC\Preview::registerProvider('OC\Preview\DOCX'); +\OC\PreviewManager::registerProvider('OC\Preview\DOCX'); class MSOfficeExcel extends Provider { @@ -95,7 +95,7 @@ class XLS extends MSOfficeExcel { } -\OC\Preview::registerProvider('OC\Preview\XLS'); +\OC\PreviewManager::registerProvider('OC\Preview\XLS'); class XLSX extends MSOfficeExcel { @@ -105,7 +105,7 @@ class XLSX extends MSOfficeExcel { } -\OC\Preview::registerProvider('OC\Preview\XLSX'); +\OC\PreviewManager::registerProvider('OC\Preview\XLSX'); /* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ... class MSOfficePowerPoint extends Provider { @@ -128,7 +128,7 @@ class PPT extends MSOfficePowerPoint { } -\OC\Preview::registerProvider('OC\Preview\PPT'); +\OC\PreviewManager::registerProvider('OC\Preview\PPT'); class PPTX extends MSOfficePowerPoint { @@ -138,5 +138,5 @@ class PPTX extends MSOfficePowerPoint { } -\OC\Preview::registerProvider('OC\Preview\PPTX'); +\OC\PreviewManager::registerProvider('OC\Preview\PPTX'); */ \ No newline at end of file diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 3eabd201156..0d289e9db94 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -36,5 +36,5 @@ if (extension_loaded('imagick')) { } } - \OC\Preview::registerProvider('OC\Preview\PDF'); + \OC\PreviewManager::registerProvider('OC\Preview\PDF'); } diff --git a/lib/preview/svg.php b/lib/preview/svg.php index bafaf71b15a..5507686af97 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -39,6 +39,6 @@ if (extension_loaded('imagick')) { } } - \OC\Preview::registerProvider('OC\Preview\SVG'); + \OC\PreviewManager::registerProvider('OC\Preview\SVG'); } \ No newline at end of file diff --git a/lib/preview/txt.php b/lib/preview/txt.php index c7b8fabc6b0..acbf34c5e42 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -46,7 +46,7 @@ class TXT extends Provider { } } -\OC\Preview::registerProvider('OC\Preview\TXT'); +\OC\PreviewManager::registerProvider('OC\Preview\TXT'); class PHP extends TXT { @@ -56,7 +56,7 @@ class PHP extends TXT { } -\OC\Preview::registerProvider('OC\Preview\PHP'); +\OC\PreviewManager::registerProvider('OC\Preview\PHP'); class JavaScript extends TXT { @@ -66,4 +66,4 @@ class JavaScript extends TXT { } -\OC\Preview::registerProvider('OC\Preview\JavaScript'); \ No newline at end of file +\OC\PreviewManager::registerProvider('OC\Preview\JavaScript'); \ No newline at end of file diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index a31b365722e..f9f6fe957b2 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -40,4 +40,4 @@ class Unknown extends Provider { } } -\OC\Preview::registerProvider('OC\Preview\Unknown'); \ No newline at end of file +\OC\PreviewManager::registerProvider('OC\Preview\Unknown'); \ No newline at end of file -- cgit v1.2.3 From 10cc0511af5e1c5a37314ff2fabe0e27f9482e27 Mon Sep 17 00:00:00 2001 From: kondou Date: Fri, 12 Jul 2013 01:36:10 +0200 Subject: Optimize images with optipng and scour --- core/img/filetypes/application-pdf.png | Bin 1759 -> 1746 bytes core/img/filetypes/application-pdf.svg | 323 ++-------- core/img/filetypes/application-rss+xml.svg | 950 ++--------------------------- core/img/filetypes/application.png | Bin 1235 -> 1018 bytes core/img/filetypes/application.svg | 373 ++--------- core/img/filetypes/audio.png | Bin 858 -> 816 bytes core/img/filetypes/audio.svg | 317 ++-------- core/img/filetypes/code.svg | 419 ++----------- core/img/filetypes/file.svg | 229 ++----- core/img/filetypes/flash.svg | 366 ++--------- core/img/filetypes/folder.svg | 385 ++---------- core/img/filetypes/font.png | Bin 1793 -> 1697 bytes core/img/filetypes/font.svg | 371 ++--------- core/img/filetypes/image-svg+xml.svg | 716 ++-------------------- core/img/filetypes/image.png | Bin 978 -> 976 bytes core/img/filetypes/image.svg | 376 ++---------- core/img/filetypes/text-html.png | Bin 741 -> 654 bytes core/img/filetypes/text-html.svg | 323 ++-------- core/img/filetypes/text.png | Bin 757 -> 693 bytes core/img/filetypes/text.svg | 265 ++------ 20 files changed, 634 insertions(+), 4779 deletions(-) diff --git a/core/img/filetypes/application-pdf.png b/core/img/filetypes/application-pdf.png index 2cbcb741d84..a9ab6d279b6 100644 Binary files a/core/img/filetypes/application-pdf.png and b/core/img/filetypes/application-pdf.png differ diff --git a/core/img/filetypes/application-pdf.svg b/core/img/filetypes/application-pdf.svg index 3f9ad528afb..47c2caabdad 100644 --- a/core/img/filetypes/application-pdf.svg +++ b/core/img/filetypes/application-pdf.svg @@ -1,277 +1,52 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/application-rss+xml.svg b/core/img/filetypes/application-rss+xml.svg index 7b4f1127a94..4fd98545a7d 100644 --- a/core/img/filetypes/application-rss+xml.svg +++ b/core/img/filetypes/application-rss+xml.svg @@ -1,914 +1,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/application.png b/core/img/filetypes/application.png index 3518d3116d2..9152cc1b744 100644 Binary files a/core/img/filetypes/application.png and b/core/img/filetypes/application.png differ diff --git a/core/img/filetypes/application.svg b/core/img/filetypes/application.svg index 31951cc043c..870a4ac2467 100644 --- a/core/img/filetypes/application.svg +++ b/core/img/filetypes/application.svg @@ -1,320 +1,59 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/audio.png b/core/img/filetypes/audio.png index cd9821ec047..3f56a7e2a9a 100644 Binary files a/core/img/filetypes/audio.png and b/core/img/filetypes/audio.png differ diff --git a/core/img/filetypes/audio.svg b/core/img/filetypes/audio.svg index f742383d632..d5eda38e8aa 100644 --- a/core/img/filetypes/audio.svg +++ b/core/img/filetypes/audio.svg @@ -1,274 +1,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/code.svg b/core/img/filetypes/code.svg index 1dee047b11f..61a5c19f511 100644 --- a/core/img/filetypes/code.svg +++ b/core/img/filetypes/code.svg @@ -1,359 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/file.svg b/core/img/filetypes/file.svg index f0c0f1daf7e..3d91c341143 100644 --- a/core/img/filetypes/file.svg +++ b/core/img/filetypes/file.svg @@ -1,197 +1,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/flash.svg b/core/img/filetypes/flash.svg index 60cab4ad380..cb823703d9b 100644 --- a/core/img/filetypes/flash.svg +++ b/core/img/filetypes/flash.svg @@ -1,310 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/folder.svg b/core/img/filetypes/folder.svg index dd80b695bb1..92d4cc22718 100644 --- a/core/img/filetypes/folder.svg +++ b/core/img/filetypes/folder.svg @@ -1,329 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/font.png b/core/img/filetypes/font.png index df44a7fc47d..9404c3ca6ac 100644 Binary files a/core/img/filetypes/font.png and b/core/img/filetypes/font.png differ diff --git a/core/img/filetypes/font.svg b/core/img/filetypes/font.svg index 404f622ea7b..8fca5ff9eff 100644 --- a/core/img/filetypes/font.svg +++ b/core/img/filetypes/font.svg @@ -1,338 +1,37 @@ - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/image-svg+xml.svg b/core/img/filetypes/image-svg+xml.svg index f9b378887f3..06df5f54da6 100644 --- a/core/img/filetypes/image-svg+xml.svg +++ b/core/img/filetypes/image-svg+xml.svg @@ -1,666 +1,56 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/image.png b/core/img/filetypes/image.png index 83d20fdb776..087f5dcdbdf 100644 Binary files a/core/img/filetypes/image.png and b/core/img/filetypes/image.png differ diff --git a/core/img/filetypes/image.svg b/core/img/filetypes/image.svg index 440b6af7ac0..50991f7359d 100644 --- a/core/img/filetypes/image.svg +++ b/core/img/filetypes/image.svg @@ -1,321 +1,61 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + diff --git a/core/img/filetypes/text-html.png b/core/img/filetypes/text-html.png index de11613f25f..dd17b750103 100644 Binary files a/core/img/filetypes/text-html.png and b/core/img/filetypes/text-html.png differ diff --git a/core/img/filetypes/text-html.svg b/core/img/filetypes/text-html.svg index bf29fbcbbf2..c41964738d0 100644 --- a/core/img/filetypes/text-html.svg +++ b/core/img/filetypes/text-html.svg @@ -1,280 +1,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text.png b/core/img/filetypes/text.png index 2b96638d16c..6b069c82c11 100644 Binary files a/core/img/filetypes/text.png and b/core/img/filetypes/text.png differ diff --git a/core/img/filetypes/text.svg b/core/img/filetypes/text.svg index 93e6be14cb6..69a1bcd98c3 100644 --- a/core/img/filetypes/text.svg +++ b/core/img/filetypes/text.svg @@ -1,228 +1,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 33ac4d93d63b98761cf9c09467dcad7bc5d34bf0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 12 Jul 2013 10:03:25 +0200 Subject: OC\Preview - use !== and === instead of != and == --- lib/preview.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 73e01a9e552..5576981225b 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -305,7 +305,7 @@ class Preview { $y = $size[1]; $aspectratio = $x / $y; - if($aspectratio != $wantedaspectratio) { + if($aspectratio !== $wantedaspectratio) { continue; } @@ -691,7 +691,7 @@ class PreviewManager { } $path = \OC\Files\Filesystem::normalizePath($path, false); - if(substr($path, 0, 1) == '/') { + if(substr($path, 0, 1) === '/') { $path = substr($path, 1); } @@ -768,7 +768,7 @@ class PreviewManager { 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); -- cgit v1.2.3 From 21abebf96a45323b81ddf057d3851d25085b59ad Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 12 Jul 2013 11:50:24 +0200 Subject: OC\Preview - proper handling of a cached previews's filename --- lib/preview.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/preview.php b/lib/preview.php index 5576981225b..08c0b7e20d0 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -283,6 +283,10 @@ class Preview { $fileinfo = $this->fileview->getFileInfo($file); $fileid = $fileinfo['fileid']; + if(is_null($fileid)) { + return false; + } + $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; if(!$this->userview->is_dir($previewpath)) { return false; @@ -293,18 +297,19 @@ class Preview { return $previewpath . $maxX . '-' . $maxY . '.png'; } - $wantedaspectratio = $maxX / $maxY; + $wantedaspectratio = (float) ($maxX / $maxY); //array for usable cached thumbnails $possiblethumbnails = array(); $allthumbnails = $this->userview->getDirectoryContent($previewpath); foreach($allthumbnails as $thumbnail) { - $size = explode('-', $thumbnail['name']); - $x = $size[0]; - $y = $size[1]; + $name = rtrim($thumbnail['name'], '.png'); + $size = explode('-', $name); + $x = (int) $size[0]; + $y = (int) $size[1]; - $aspectratio = $x / $y; + $aspectratio = (float) ($x / $y); if($aspectratio !== $wantedaspectratio) { continue; } -- cgit v1.2.3 From c834d93e8778bbbe008c992e6fab5250296ec216 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 12 Jul 2013 14:16:06 +0200 Subject: OC\Preview - update git submodule --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 21762672395..31ed0ab78e4 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 217626723957161191572ea50172a3943c30696d +Subproject commit 31ed0ab78e48d7515740b05f64c07a2b0648421f -- cgit v1.2.3 From 1303fe0f9fe7c67764fb48cbb84fcb30e4a32b33 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 14 Jul 2013 00:00:10 +0200 Subject: OC\Preview - set scale factor down to 2 and upscale cached preview - this got lost in a git stash ... --- lib/preview.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 08c0b7e20d0..03aaaceb9ca 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -60,7 +60,7 @@ class Preview { //set config $this->configMaxX = \OC_Config::getValue('preview_max_x', null); $this->configMaxY = \OC_Config::getValue('preview_max_y', null); - $this->maxScaleFactor = \OC_Config::getValue('preview_max_scale_factor', 10); + $this->maxScaleFactor = \OC_Config::getValue('preview_max_scale_factor', 2); //save parameters $this->setFile($file); @@ -377,6 +377,7 @@ class Preview { if($cached) { $image = new \OC_Image($this->userview->file_get_contents($cached, 'r')); $this->preview = $image->valid() ? $image : null; + $this->resizeAndCrop(); } if(is_null($this->preview)) { -- cgit v1.2.3 From 65affdc9b32629ab4692f77ffd4dff77e026b1dc Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 29 Jul 2013 14:40:26 +0200 Subject: make previews in files app smaller --- lib/helper.php | 4 ++-- lib/preview.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index 6153f318723..0853c792750 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -231,11 +231,11 @@ 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' => 44, 'y' => 44, 'file' => urlencode($path) )); + return self::linkToRoute( 'core_ajax_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) )); } public static function publicPreview_icon( $path, $token ) { - return self::linkToRoute( 'core_ajax_public_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path), 't' => $token)); + return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path), 't' => $token)); } /** diff --git a/lib/preview.php b/lib/preview.php index 03aaaceb9ca..c570a17e4a7 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -784,7 +784,7 @@ class PreviewManager { public static function showErrorPreview() { $path = \OC::$SERVERROOT . '/core/img/actions/delete.png'; $preview = new \OC_Image($path); - $preview->preciseResize(44, 44); + $preview->preciseResize(36, 36); $preview->show(); } } \ No newline at end of file -- cgit v1.2.3 From e01bc7de987ddb7d33feb75ad598bdf97c348105 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 29 Jul 2013 14:46:20 +0200 Subject: Revert "OC\Preview - outsource static methods" This reverts commit 14a35267c15115a1e7d2901ddd9b8c5c7e1b9a31. --- core/routes.php | 7 +++---- lib/preview.php | 37 ++++++++++++++----------------------- lib/preview/images.php | 2 +- lib/preview/libreoffice-cl.php | 10 +++++----- lib/preview/movies.php | 2 +- lib/preview/mp3.php | 2 +- lib/preview/msoffice.php | 12 ++++++------ lib/preview/pdf.php | 2 +- lib/preview/svg.php | 2 +- lib/preview/txt.php | 6 +++--- lib/preview/unknown.php | 2 +- 11 files changed, 37 insertions(+), 47 deletions(-) diff --git a/core/routes.php b/core/routes.php index c0e658b26dc..41e82f8a73d 100644 --- a/core/routes.php +++ b/core/routes.php @@ -42,13 +42,12 @@ $this->create('js_config', '/core/js/config.js') // Routing $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); -OC::$CLASSPATH['OC\PreviewManager'] = 'lib/preview.php'; $this->create('core_ajax_preview', '/core/preview.png') - ->action('OC\PreviewManager', 'previewRouter'); + ->action('OC\Preview', 'previewRouter'); $this->create('core_ajax_trashbin_preview', '/core/trashbinpreview.png') - ->action('OC\PreviewManager', 'trashbinPreviewRouter'); + ->action('OC\Preview', 'trashbinPreviewRouter'); $this->create('core_ajax_public_preview', '/core/publicpreview.png') - ->action('OC\PreviewManager', '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/preview.php b/lib/preview.php index c570a17e4a7..113b200c29b 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -44,6 +44,10 @@ class Preview { //preview images object private $preview; + //preview providers + static private $providers = array(); + static private $registeredProviders = array(); + /** * @brief check if thumbnail or bigger version of thumbnail of file is cached * @param string $user userid - if no user is given, OC_User::getUser will be used @@ -78,13 +82,11 @@ class Preview { $this->preview = null; //check if there are preview backends - $providers = PreviewManager::getProviders(); - if(empty($providers)) { - PreviewManager::initProviders(); + if(empty(self::$providers)) { + self::initProviders(); } - $providers = PreviewManager::getProviders(); - if(empty($providers)) { + if(empty(self::$providers)) { \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); throw new \Exception('No preview providers'); } @@ -384,8 +386,7 @@ class Preview { $mimetype = $this->fileview->getMimeType($file); $preview = null; - $providers = PreviewManager::getProviders(); - foreach($providers as $supportedmimetype => $provider) { + foreach(self::$providers as $supportedmimetype => $provider) { if(!preg_match($supportedmimetype, $mimetype)) { continue; } @@ -549,16 +550,6 @@ class Preview { return; } } -} - -class PreviewManager { - //preview providers - static private $providers = array(); - static private $registeredProviders = array(); - - public static function getProviders() { - return self::$providers; - } /** * @brief register a new preview provider to be used @@ -574,7 +565,7 @@ class PreviewManager { * @brief create instances of all the registered preview providers * @return void */ - public static function initProviders() { + private static function initProviders() { if(count(self::$providers)>0) { return; } @@ -600,8 +591,8 @@ class PreviewManager { \OC_Util::checkLoggedIn(); $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; + $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; + $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; if($file === '') { @@ -644,8 +635,8 @@ class PreviewManager { } $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; + $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; + $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; @@ -781,7 +772,7 @@ class PreviewManager { $preview->deleteAllPreviews(); } - public static function showErrorPreview() { + private static function showErrorPreview() { $path = \OC::$SERVERROOT . '/core/img/actions/delete.png'; $preview = new \OC_Image($path); $preview->preciseResize(36, 36); diff --git a/lib/preview/images.php b/lib/preview/images.php index 84ab9f1ae43..987aa9aef0a 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -30,4 +30,4 @@ class Image extends Provider { } } -\OC\PreviewManager::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/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index ffe8de505f7..2749c4867e9 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -80,7 +80,7 @@ class MSOfficeDoc extends Office { } -\OC\PreviewManager::registerProvider('OC\Preview\MSOfficeDoc'); +\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 { @@ -91,7 +91,7 @@ class MSOffice2003 extends Office { } -\OC\PreviewManager::registerProvider('OC\Preview\MSOffice2003'); +\OC\Preview::registerProvider('OC\Preview\MSOffice2003'); //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx class MSOffice2007 extends Office { @@ -102,7 +102,7 @@ class MSOffice2007 extends Office { } -\OC\PreviewManager::registerProvider('OC\Preview\MSOffice2007'); +\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 { @@ -113,7 +113,7 @@ class OpenDocument extends Office { } -\OC\PreviewManager::registerProvider('OC\Preview\OpenDocument'); +\OC\Preview::registerProvider('OC\Preview\OpenDocument'); //.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm class StarOffice extends Office { @@ -124,4 +124,4 @@ class StarOffice extends Office { } -\OC\PreviewManager::registerProvider('OC\Preview\StarOffice'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\StarOffice'); \ No newline at end of file diff --git a/lib/preview/movies.php b/lib/preview/movies.php index f4452e02fc2..8531050d112 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -39,5 +39,5 @@ if(!is_null(shell_exec('ffmpeg -version'))) { } } - \OC\PreviewManager::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 baa24ad129e..835ff529000 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -43,4 +43,4 @@ class MP3 extends Provider { } -\OC\PreviewManager::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/msoffice.php b/lib/preview/msoffice.php index 9f6ea7f74cf..ccf1d674c7a 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -20,7 +20,7 @@ class DOC extends Provider { } -\OC\PreviewManager::registerProvider('OC\Preview\DOC'); +\OC\Preview::registerProvider('OC\Preview\DOC'); */ class DOCX extends Provider { @@ -50,7 +50,7 @@ class DOCX extends Provider { } -\OC\PreviewManager::registerProvider('OC\Preview\DOCX'); +\OC\Preview::registerProvider('OC\Preview\DOCX'); class MSOfficeExcel extends Provider { @@ -95,7 +95,7 @@ class XLS extends MSOfficeExcel { } -\OC\PreviewManager::registerProvider('OC\Preview\XLS'); +\OC\Preview::registerProvider('OC\Preview\XLS'); class XLSX extends MSOfficeExcel { @@ -105,7 +105,7 @@ class XLSX extends MSOfficeExcel { } -\OC\PreviewManager::registerProvider('OC\Preview\XLSX'); +\OC\Preview::registerProvider('OC\Preview\XLSX'); /* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ... class MSOfficePowerPoint extends Provider { @@ -128,7 +128,7 @@ class PPT extends MSOfficePowerPoint { } -\OC\PreviewManager::registerProvider('OC\Preview\PPT'); +\OC\Preview::registerProvider('OC\Preview\PPT'); class PPTX extends MSOfficePowerPoint { @@ -138,5 +138,5 @@ class PPTX extends MSOfficePowerPoint { } -\OC\PreviewManager::registerProvider('OC\Preview\PPTX'); +\OC\Preview::registerProvider('OC\Preview\PPTX'); */ \ No newline at end of file diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 0d289e9db94..3eabd201156 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -36,5 +36,5 @@ if (extension_loaded('imagick')) { } } - \OC\PreviewManager::registerProvider('OC\Preview\PDF'); + \OC\Preview::registerProvider('OC\Preview\PDF'); } diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 5507686af97..bafaf71b15a 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -39,6 +39,6 @@ if (extension_loaded('imagick')) { } } - \OC\PreviewManager::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 acbf34c5e42..c7b8fabc6b0 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -46,7 +46,7 @@ class TXT extends Provider { } } -\OC\PreviewManager::registerProvider('OC\Preview\TXT'); +\OC\Preview::registerProvider('OC\Preview\TXT'); class PHP extends TXT { @@ -56,7 +56,7 @@ class PHP extends TXT { } -\OC\PreviewManager::registerProvider('OC\Preview\PHP'); +\OC\Preview::registerProvider('OC\Preview\PHP'); class JavaScript extends TXT { @@ -66,4 +66,4 @@ class JavaScript extends TXT { } -\OC\PreviewManager::registerProvider('OC\Preview\JavaScript'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\JavaScript'); \ No newline at end of file diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index f9f6fe957b2..a31b365722e 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -40,4 +40,4 @@ class Unknown extends Provider { } } -\OC\PreviewManager::registerProvider('OC\Preview\Unknown'); \ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\Unknown'); \ No newline at end of file -- cgit v1.2.3 From 1e4ec2ac276b15232824da056b6253696d324d42 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 29 Jul 2013 15:47:17 +0200 Subject: add class='preview-icon' to rows in file app that make use of previews --- apps/files/templates/part.list.php | 12 ++++++++++-- lib/preview.php | 18 +++++++++++++++++- lib/public/preview.php | 38 +++++++++++--------------------------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 9e62c991975..b87000a8993 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -34,9 +34,17 @@ $totalsize = 0; ?> - style="background-image:url()" + + style="background-image:url()" class="preview-icon" + + style="background-image:url()" + - style="background-image:url()" + + style="background-image:url()" class="preview-icon" + + style="background-image:url()" + > diff --git a/lib/preview.php b/lib/preview.php index 113b200c29b..245ad64014e 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -771,7 +771,23 @@ class Preview { $preview = new Preview(\OC_User::getUser(), 'files/', $path, 0, 0, false, true); $preview->deleteAllPreviews(); } - + + public static function isMimeSupported($mimetype) { + //check if there are preview backends + if(empty(self::$providers)) { + self::initProviders(); + } + + //remove last element because it has the mimetype * + $providers = array_slice(self::$providers, 0, -1); + foreach($providers as $supportedmimetype => $provider) { + if(preg_match($supportedmimetype, $mimetype)) { + return true; + } + } + return false; + } + private static function showErrorPreview() { $path = \OC::$SERVERROOT . '/core/img/actions/delete.png'; $preview = new \OC_Image($path); diff --git a/lib/public/preview.php b/lib/public/preview.php index a7487c485f1..e488eade4da 100644 --- a/lib/public/preview.php +++ b/lib/public/preview.php @@ -1,33 +1,11 @@ . -* -*/ - -/** - * Public interface of ownCloud for apps to use. - * Preview Class. - * + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ - -// 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; /** @@ -47,4 +25,10 @@ class Preview { return(\OC_Preview::show($file,$maxX,$maxY,$scaleup)); } + + + public static function isMimeSupported($mimetype='*') { + return \OC\Preview::isMimeSupported($mimetype); + } + } -- cgit v1.2.3 From 2ea8ee613986216a420fad2795b5e7fa89519d5e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 29 Jul 2013 16:27:40 +0200 Subject: add class='preview-icon' in trashbin app as well --- apps/files_trashbin/lib/trash.php | 2 +- apps/files_trashbin/templates/part.list.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 4174ef0d185..71e76770aa9 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -858,6 +858,6 @@ class Trashbin { } public static function preview_icon($path) { - return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) )); + return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) )); } } diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 44e2fc7293b..71b9a238823 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -25,7 +25,11 @@ style="background-image:url()" - style="background-image:url()" + + style="background-image:url()" class="preview-icon" + + style="background-image:url()" + > -- cgit v1.2.3 From b4a523927823ab8bc80c5f1fc0d5bd5ef61f8eb8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 29 Jul 2013 16:30:04 +0200 Subject: fix syntax in 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 cacca78e970..7629414ef16 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -185,7 +185,7 @@ $CONFIG = array( //links to custom clients '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 +'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 */ -- cgit v1.2.3 From ac6a3133eca86b853da838ae310534b76e9fb662 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 30 Jul 2013 12:29:12 +0200 Subject: style fixes --- apps/files/js/files.js | 2 +- apps/files/templates/part.list.php | 2 +- apps/files_sharing/public.php | 2 +- core/ajax/preview.php | 42 +++++ core/ajax/publicpreview.php | 92 +++++++++++ core/ajax/trashbinpreview.php | 46 ++++++ core/routes.php | 6 +- lib/helper.php | 2 +- lib/preview.php | 308 ++++++++----------------------------- lib/preview/images.php | 7 +- lib/preview/libreoffice-cl.php | 24 +-- lib/preview/movies.php | 22 +-- lib/preview/mp3.php | 22 +-- lib/preview/msoffice.php | 24 +-- lib/preview/office.php | 7 +- lib/preview/pdf.php | 8 +- lib/preview/txt.php | 15 +- lib/preview/unknown.php | 8 +- lib/template.php | 3 + lib/template/functions.php | 16 ++ 20 files changed, 349 insertions(+), 309 deletions(-) create mode 100644 core/ajax/preview.php create mode 100644 core/ajax/publicpreview.php create mode 100644 core/ajax/trashbinpreview.php diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 53c6de09dd0..8b66ed6747b 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -825,7 +825,7 @@ function getMimeIcon(mime, ready){ getMimeIcon.cache={}; function getPreviewIcon(path, ready){ - ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:44, y:44})); + ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:36, y:36})); } function getUniqueName(name){ diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index a957a94f332..ab1b91167db 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -3,7 +3,7 @@ $totaldirs = 0; $totalsize = 0; ?> 6 $totalsize += $file['size']; if ($file['type'] === 'dir') { $totaldirs++; diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 284b7a30208..650fa6a7c27 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -196,7 +196,7 @@ if (isset($path)) { OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path='); $list->assign('isPublic', true); $list->assign('sharingtoken', $token); - $list->assign('sharingroot', ($path)); + $list->assign('sharingroot', $basePath); $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); $breadcrumbNav->assign('breadcrumb', $breadcrumb); $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path='); diff --git a/core/ajax/preview.php b/core/ajax/preview.php new file mode 100644 index 00000000000..a9d127ffcc4 --- /dev/null +++ b/core/ajax/preview.php @@ -0,0 +1,42 @@ +setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->show(); +}catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + \OC\Preview::showErrorPreview(); + exit; +} \ No newline at end of file diff --git a/core/ajax/publicpreview.php b/core/ajax/publicpreview.php new file mode 100644 index 00000000000..aace24caa21 --- /dev/null +++ b/core/ajax/publicpreview.php @@ -0,0 +1,92 @@ +setFile($sharedFile); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->show(); +}catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + \OC\Preview::showErrorPreview(); + exit; +} \ No newline at end of file diff --git a/core/ajax/trashbinpreview.php b/core/ajax/trashbinpreview.php new file mode 100644 index 00000000000..d018a57d37b --- /dev/null +++ b/core/ajax/trashbinpreview.php @@ -0,0 +1,46 @@ +setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->showPreview(); +}catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + \OC\Preview::showErrorPreview(); + exit; +} \ No newline at end of file diff --git a/core/routes.php b/core/routes.php index 41e82f8a73d..75cc4d511c0 100644 --- a/core/routes.php +++ b/core/routes.php @@ -43,11 +43,11 @@ $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'); + ->actionInclude('core/ajax/preview.php'); $this->create('core_ajax_trashbin_preview', '/core/trashbinpreview.png') - ->action('OC\Preview', 'trashbinPreviewRouter'); + ->actionInclude('core/ajax/trashbinpreview.php'); $this->create('core_ajax_public_preview', '/core/publicpreview.png') - ->action('OC\Preview', 'publicPreviewRouter'); + ->actionInclude('core/ajax/publicpreview.php'); OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; $this->create('core_lostpassword_index', '/lostpassword/') ->get() diff --git a/lib/helper.php b/lib/helper.php index 460e5679b02..b74e4c4512e 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -233,7 +233,7 @@ class OC_Helper { return self::linkToRoute( 'core_ajax_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) )); } - public static function publicPreview_icon( $path, $token ) { + public static function publicPreviewIcon( $path, $token ) { return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path), 't' => $token)); } diff --git a/lib/preview.php b/lib/preview.php index 245ad64014e..9f4d20b4650 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -55,12 +55,12 @@ class Preview { * @param string $file The path to the file where you want a thumbnail from * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image - * @param bool $scalingup Disable/Enable upscaling of previews + * @param bool $scalingUp Disable/Enable upscaling of previews * @return mixed (bool / string) * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ - public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingup=true) { + public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingUp=true) { //set config $this->configMaxX = \OC_Config::getValue('preview_max_x', null); $this->configMaxY = \OC_Config::getValue('preview_max_y', null); @@ -70,11 +70,11 @@ class Preview { $this->setFile($file); $this->setMaxX($maxX); $this->setMaxY($maxY); - $this->setScalingUp($scalingup); + $this->setScalingUp($scalingUp); //init fileviews if($user === ''){ - $user = OC_User::getUser(); + $user = \OC_User::getUser(); } $this->fileview = new \OC\Files\View('/' . $user . '/' . $root); $this->userview = new \OC\Files\View('/' . $user); @@ -120,7 +120,7 @@ class Preview { * @brief returns whether or not scalingup is enabled * @return bool */ - public function getScalingup() { + public function getScalingUp() { return $this->scalingup; } @@ -172,8 +172,8 @@ class Preview { * @return $this */ public function setMaxX($maxX=1) { - if($maxX === 0) { - throw new \Exception('Cannot set width of 0!'); + if($maxX <= 0) { + throw new \Exception('Cannot set width of 0 or smaller!'); } $configMaxX = $this->getConfigMaxX(); if(!is_null($configMaxX)) { @@ -192,8 +192,8 @@ class Preview { * @return $this */ public function setMaxY($maxY=1) { - if($maxY === 0) { - throw new \Exception('Cannot set height of 0!'); + if($maxY <= 0) { + throw new \Exception('Cannot set height of 0 or smaller!'); } $configMaxY = $this->getConfigMaxY(); if(!is_null($configMaxY)) { @@ -208,14 +208,14 @@ class Preview { /** * @brief set whether or not scalingup is enabled - * @param bool $scalingup + * @param bool $scalingUp * @return $this */ - public function setScalingup($scalingup) { + public function setScalingup($scalingUp) { if($this->getMaxScaleFactor() === 1) { - $scalingup = false; + $scalingUp = false; } - $this->scalingup = $scalingup; + $this->scalingup = $scalingUp; return $this; } @@ -245,12 +245,12 @@ class Preview { public function deletePreview() { $file = $this->getFile(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; - $this->userview->unlink($previewpath); - return !$this->userview->file_exists($previewpath); + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; + $this->userview->unlink($previewPath); + return !$this->userview->file_exists($previewPath); } /** @@ -260,13 +260,13 @@ class Preview { public function deleteAllPreviews() { $file = $this->getFile(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; - $this->userview->deleteAll($previewpath); - $this->userview->rmdir($previewpath); - return !$this->userview->is_dir($previewpath); + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + $this->userview->deleteAll($previewPath); + $this->userview->rmdir($previewPath); + return !$this->userview->is_dir($previewPath); } /** @@ -279,45 +279,45 @@ class Preview { $file = $this->getFile(); $maxX = $this->getMaxX(); $maxY = $this->getMaxY(); - $scalingup = $this->getScalingup(); + $scalingUp = $this->getScalingUp(); $maxscalefactor = $this->getMaxScaleFactor(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; - if(is_null($fileid)) { + if(is_null($fileId)) { return false; } - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; - if(!$this->userview->is_dir($previewpath)) { + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + if(!$this->userview->is_dir($previewPath)) { return false; } //does a preview with the wanted height and width already exist? - if($this->userview->file_exists($previewpath . $maxX . '-' . $maxY . '.png')) { - return $previewpath . $maxX . '-' . $maxY . '.png'; + if($this->userview->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) { + return $previewPath . $maxX . '-' . $maxY . '.png'; } - $wantedaspectratio = (float) ($maxX / $maxY); + $wantedAspectRatio = (float) ($maxX / $maxY); //array for usable cached thumbnails - $possiblethumbnails = array(); + $possibleThumbnails = array(); - $allthumbnails = $this->userview->getDirectoryContent($previewpath); - foreach($allthumbnails as $thumbnail) { + $allThumbnails = $this->userview->getDirectoryContent($previewPath); + foreach($allThumbnails as $thumbnail) { $name = rtrim($thumbnail['name'], '.png'); $size = explode('-', $name); $x = (int) $size[0]; $y = (int) $size[1]; - $aspectratio = (float) ($x / $y); - if($aspectratio !== $wantedaspectratio) { + $aspectRatio = (float) ($x / $y); + if($aspectRatio !== $wantedAspectRatio) { continue; } if($x < $maxX || $y < $maxY) { - if($scalingup) { + if($scalingUp) { $scalefactor = $maxX / $x; if($scalefactor > $maxscalefactor) { continue; @@ -326,28 +326,28 @@ class Preview { continue; } } - $possiblethumbnails[$x] = $thumbnail['path']; + $possibleThumbnails[$x] = $thumbnail['path']; } - if(count($possiblethumbnails) === 0) { + if(count($possibleThumbnails) === 0) { return false; } - if(count($possiblethumbnails) === 1) { - return current($possiblethumbnails); + if(count($possibleThumbnails) === 1) { + return current($possibleThumbnails); } - ksort($possiblethumbnails); + ksort($possibleThumbnails); - if(key(reset($possiblethumbnails)) > $maxX) { - return current(reset($possiblethumbnails)); + if(key(reset($possibleThumbnails)) > $maxX) { + return current(reset($possibleThumbnails)); } - if(key(end($possiblethumbnails)) < $maxX) { - return current(end($possiblethumbnails)); + if(key(end($possibleThumbnails)) < $maxX) { + return current(end($possibleThumbnails)); } - foreach($possiblethumbnails as $width => $path) { + foreach($possibleThumbnails as $width => $path) { if($width < $maxX) { continue; }else{ @@ -358,7 +358,7 @@ class Preview { /** * @brief return a preview of a file - * @return image + * @return \OC_Image */ public function getPreview() { if(!is_null($this->preview) && $this->preview->valid()){ @@ -369,10 +369,10 @@ class Preview { $file = $this->getFile(); $maxX = $this->getMaxX(); $maxY = $this->getMaxY(); - $scalingup = $this->getScalingup(); + $scalingUp = $this->getScalingUp(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; $cached = $this->isCached(); @@ -386,12 +386,12 @@ class Preview { $mimetype = $this->fileview->getMimeType($file); $preview = null; - 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); + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileview); if(!($preview instanceof \OC_Image)) { continue; @@ -400,18 +400,18 @@ class Preview { $this->preview = $preview; $this->resizeAndCrop(); - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; - $cachepath = $previewpath . $maxX . '-' . $maxY . '.png'; + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + $cachePath = $previewPath . $maxX . '-' . $maxY . '.png'; if($this->userview->is_dir($this->getThumbnailsFolder() . '/') === false) { $this->userview->mkdir($this->getThumbnailsFolder() . '/'); } - if($this->userview->is_dir($previewpath) === false) { - $this->userview->mkdir($previewpath); + if($this->userview->is_dir($previewPath) === false) { + $this->userview->mkdir($previewPath); } - $this->userview->file_put_contents($cachepath, $preview->data()); + $this->userview->file_put_contents($cachePath, $preview->data()); break; } @@ -447,13 +447,13 @@ class Preview { /** * @brief resize, crop and fix orientation - * @return image + * @return void */ private function resizeAndCrop() { $image = $this->preview; $x = $this->getMaxX(); $y = $this->getMaxY(); - $scalingup = $this->getScalingup(); + $scalingUp = $this->getScalingUp(); $maxscalefactor = $this->getMaxScaleFactor(); if(!($image instanceof \OC_Image)) { @@ -480,7 +480,7 @@ class Preview { $factor = $factorY; } - if($scalingup === false) { + if($scalingUp === false) { if($factor > 1) { $factor = 1; } @@ -583,182 +583,6 @@ class Preview { 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() { - \OC_Util::checkLoggedIn(); - - $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; - $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; - - if($file === '') { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - try{ - $preview = new Preview(\OC_User::getUser(), 'files'); - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingup); - - $preview->show(); - }catch(\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - self::showErrorPreview(); - exit; - } - } - - /** - * @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() { - if(!\OC_App::isEnabled('files_sharing')){ - exit; - } - - $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; - $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; - $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; - - if($token === ''){ - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - $linkedItem = \OCP\Share::getShareByToken($token); - if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) { - \OC_Response::setStatus(404); - \OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) { - \OC_Response::setStatus(500); - \OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")'); - self::showErrorPreview(); - exit; - } - - $userid = $linkedItem['uid_owner']; - \OC_Util::setupFS($userid); - - $pathid = $linkedItem['file_source']; - $path = \OC\Files\Filesystem::getPath($pathid); - $pathinfo = \OC\Files\Filesystem::getFileInfo($path); - $sharedfile = null; - - if($linkedItem['item_type'] === 'folder') { - $isvalid = \OC\Files\Filesystem::isValidPath($file); - if(!$isvalid) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN); - self::showErrorPreview(); - exit; - } - $sharedfile = \OC\Files\Filesystem::normalizePath($file); - } - - if($linkedItem['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); - } - - if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - $root = 'files/' . $path; - - try{ - $preview = new Preview($userid, $root); - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingup); - - $preview->show(); - }catch(\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - self::showErrorPreview(); - exit; - } - } - - public static function trashbinPreviewRouter() { - \OC_Util::checkLoggedIn(); - - if(!\OC_App::isEnabled('files_trashbin')){ - exit; - } - - $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; - $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; - - if($file === '') { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - try{ - $preview = new Preview(\OC_User::getUser(), 'files_trashbin/files'); - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingup); - - $preview->showPreview(); - }catch(\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - self::showErrorPreview(); - exit; - } - } - public static function post_write($args) { self::post_delete($args); } @@ -780,8 +604,8 @@ class Preview { //remove last element because it has the mimetype * $providers = array_slice(self::$providers, 0, -1); - foreach($providers as $supportedmimetype => $provider) { - if(preg_match($supportedmimetype, $mimetype)) { + foreach($providers as $supportedMimetype => $provider) { + if(preg_match($supportedMimetype, $mimetype)) { return true; } } diff --git a/lib/preview/images.php b/lib/preview/images.php index 987aa9aef0a..9aec967282d 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -16,10 +16,13 @@ class Image extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { //get fileinfo - $fileinfo = $fileview->getFileInfo($path); + $fileInfo = $fileview->getFileInfo($path); + if(!$fileInfo) { + return false; + } //check if file is encrypted - if($fileinfo['encrypted'] === true) { + if($fileInfo['encrypted'] === true) { $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r'))); }else{ $image = new \OC_Image(); diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 2749c4867e9..0f4ec3d0348 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -22,28 +22,30 @@ class Office extends Provider { 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); //create imagick object from pdf try{ - $pdf = new \imagick($abspath . '.pdf' . '[0]'); + $pdf = new \imagick($absPath . '.pdf' . '[0]'); $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ + }catch (\Exception $e) { + unlink($absPath); + unlink($absPath . '.pdf'); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } $image = new \OC_Image($pdf); - unlink($abspath); - unlink($abspath . '.pdf'); + unlink($absPath); + unlink($absPath . '.pdf'); return $image->valid() ? $image : false; } @@ -55,11 +57,13 @@ class Office extends Provider { $cmd = \OC_Config::getValue('preview_libreoffice_path', null); } - if($cmd === '' && shell_exec('libreoffice --headless --version')) { + $whichLibreOffice = shell_exec('which libreoffice'); + if($cmd === '' && !empty($whichLibreOffice)) { $cmd = 'libreoffice'; } - if($cmd === '' && shell_exec('openoffice --headless --version')) { + $whichOpenOffice = shell_exec('which openoffice'); + if($cmd === '' && !empty($whichOpenOffice)) { $cmd = 'openoffice'; } diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 8531050d112..e2a1b8edddc 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -8,7 +8,11 @@ */ namespace OC\Preview; -if(!is_null(shell_exec('ffmpeg -version'))) { +$isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); +$whichFFMPEG = shell_exec('which ffmpeg'); +$isFFMPEGAvailable = !empty($whichFFMPEG); + +if($isShellExecEnabled && $isFFMPEGAvailable) { class Movie extends Provider { @@ -17,23 +21,23 @@ if(!is_null(shell_exec('ffmpeg -version'))) { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $abspath = \OC_Helper::tmpFile(); - $tmppath = \OC_Helper::tmpFile(); + $absPath = \OC_Helper::tmpFile(); + $tmpPath = \OC_Helper::tmpFile(); $handle = $fileview->fopen($path, 'rb'); $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576 - file_put_contents($abspath, $firstmb); + 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); + //$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); + $image = new \OC_Image($tmpPath); - unlink($abspath); - unlink($tmppath); + unlink($absPath); + unlink($tmpPath); return $image->valid() ? $image : false; } diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 835ff529000..1eed566315c 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -18,19 +18,21 @@ class MP3 extends Provider { $getID3 = new \getID3(); - $tmppath = $fileview->toTmpFile($path); - - $tags = $getID3->analyze($tmppath); - \getid3_lib::CopyTagsToComments($tags); - $picture = @$tags['id3v2']['APIC'][0]['data']; - - unlink($tmppath); + $tmpPath = $fileview->toTmpFile($path); + + $tags = $getID3->analyze($tmpPath); + \getid3_lib::CopyTagsToComments($tags); + if(isset($tags['id3v2']['APIC'][0]['data'])) { + $picture = @$tags['id3v2']['APIC'][0]['data']; + unlink($tmpPath); + $image = new \OC_Image($picture); + return $image->valid() ? $image : $this->getNoCoverThumbnail(); + } - $image = new \OC_Image($picture); - return $image->valid() ? $image : $this->getNoCoverThumbnail($maxX, $maxY); + return $this->getNoCoverThumbnail(); } - public function getNoCoverThumbnail($maxX, $maxY) { + private function getNoCoverThumbnail() { $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png'; if(!file_exists($icon)) { diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index ccf1d674c7a..e69ab0ab8cb 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -32,16 +32,16 @@ class DOCX extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { require_once('phpdocx/classes/TransformDoc.inc'); - $tmpdoc = $fileview->toTmpFile($path); + $tmpDoc = $fileview->toTmpFile($path); $transformdoc = new \TransformDoc(); - $transformdoc->setStrFile($tmpdoc); - $transformdoc->generatePDF($tmpdoc); + $transformdoc->setStrFile($tmpDoc); + $transformdoc->generatePDF($tmpDoc); - $pdf = new \imagick($tmpdoc . '[0]'); + $pdf = new \imagick($tmpDoc . '[0]'); $pdf->setImageFormat('jpg'); - unlink($tmpdoc); + unlink($tmpDoc); $image = new \OC_Image($pdf); @@ -62,23 +62,23 @@ class MSOfficeExcel extends Provider { require_once('PHPExcel/Classes/PHPExcel.php'); require_once('PHPExcel/Classes/PHPExcel/IOFactory.php'); - $abspath = $fileview->toTmpFile($path); - $tmppath = \OC_Helper::tmpFile(); + $absPath = $fileview->toTmpFile($path); + $tmpPath = \OC_Helper::tmpFile(); $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf'; \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath); - $phpexcel = new \PHPExcel($abspath); + $phpexcel = new \PHPExcel($absPath); $excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF'); - $excel->save($tmppath); + $excel->save($tmpPath); - $pdf = new \imagick($tmppath . '[0]'); + $pdf = new \imagick($tmpPath . '[0]'); $pdf->setImageFormat('jpg'); - unlink($abspath); - unlink($tmppath); + unlink($absPath); + unlink($tmpPath); $image = new \OC_Image($pdf); diff --git a/lib/preview/office.php b/lib/preview/office.php index b6783bc5798..b93e1e57c8b 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -7,8 +7,13 @@ */ //both, libreoffice backend and php fallback, need imagick if (extension_loaded('imagick')) { + $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); + $whichLibreOffice = shell_exec('which libreoffice'); + $isLibreOfficeAvailable = !empty($whichLibreOffice); + $whichOpenOffice = shell_exec('which libreoffice'); + $isOpenOfficeAvailable = !empty($whichOpenOffice); //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))) { + if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) { require_once('libreoffice-cl.php'); }else{ //in case there isn't, use our fallback diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 3eabd201156..723dc1d80d2 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -16,18 +16,18 @@ if (extension_loaded('imagick')) { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $tmppath = $fileview->toTmpFile($path); + $tmpPath = $fileview->toTmpFile($path); //create imagick object from pdf try{ - $pdf = new \imagick($tmppath . '[0]'); + $pdf = new \imagick($tmpPath . '[0]'); $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ + }catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } - unlink($tmppath); + unlink($tmpPath); //new image object $image = new \OC_Image($pdf); diff --git a/lib/preview/txt.php b/lib/preview/txt.php index c7b8fabc6b0..89927fd580a 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -18,24 +18,23 @@ class TXT extends Provider { $content = stream_get_contents($content); $lines = preg_split("/\r\n|\n|\r/", $content); - $numoflines = count($lines); - $fontsize = 5; //5px - $linesize = ceil($fontsize * 1.25); + $fontSize = 5; //5px + $lineSize = ceil($fontSize * 1.25); $image = imagecreate($maxX, $maxY); - $imagecolor = imagecolorallocate($image, 255, 255, 255); - $textcolor = imagecolorallocate($image, 0, 0, 0); + 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; + $y = (int) ($index * $lineSize) - $fontSize; - imagestring($image, 1, $x, $y, $line, $textcolor); + 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 a31b365722e..ba13ca35d66 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -20,7 +20,7 @@ class Unknown extends Provider { list($type, $subtype) = explode('/', $mimetype); } - $iconsroot = \OC::$SERVERROOT . '/core/img/filetypes/'; + $iconsRoot = \OC::$SERVERROOT . '/core/img/filetypes/'; if(isset($type)){ $icons = array($mimetype, $type, 'text'); @@ -30,10 +30,10 @@ class Unknown extends Provider { foreach($icons as $icon) { $icon = str_replace('/', '-', $icon); - $iconpath = $iconsroot . $icon . '.png'; + $iconPath = $iconsRoot . $icon . '.png'; - if(file_exists($iconpath)) { - return new \OC_Image($iconpath); + if(file_exists($iconPath)) { + return new \OC_Image($iconPath); } } return false; diff --git a/lib/template.php b/lib/template.php index caa1e667c61..9b2c1211e61 100644 --- a/lib/template.php +++ b/lib/template.php @@ -23,6 +23,9 @@ require_once __DIR__.'/template/functions.php'; +/** + * This class provides the templates for ownCloud. + */ class OC_Template extends \OC\Template\Base { private $renderas; // Create a full page? private $path; // The path to the template diff --git a/lib/template/functions.php b/lib/template/functions.php index a864614c9a1..842f28c90e0 100644 --- a/lib/template/functions.php +++ b/lib/template/functions.php @@ -47,6 +47,22 @@ 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 ); +} + +function publicPreview_icon ( $path, $token ) { + return OC_Helper::publicPreviewIcon( $path, $token ); +} + /** * @brief make OC_Helper::mimetypeIcon available as a simple function * @param string $mimetype mimetype -- cgit v1.2.3 From d84d8f71082ba17a9f37f86600a71d20e2481772 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 30 Jul 2013 12:35:39 +0200 Subject: fix merge conflicts --- lib/template/functions.php | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/lib/template/functions.php b/lib/template/functions.php index 842f28c90e0..a892e310362 100644 --- a/lib/template/functions.php +++ b/lib/template/functions.php @@ -47,22 +47,6 @@ 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 ); -} - -function publicPreview_icon ( $path, $token ) { - return OC_Helper::publicPreviewIcon( $path, $token ); -} - /** * @brief make OC_Helper::mimetypeIcon available as a simple function * @param string $mimetype mimetype @@ -87,7 +71,7 @@ function preview_icon( $path ) { } function publicPreview_icon ( $path, $token ) { - return OC_Helper::publicPreview_icon( $path, $token ); + return OC_Helper::publicPreviewIcon( $path, $token ); } /** -- cgit v1.2.3 From 640253fa31928ff52ba41e53cf50192c4b0002e9 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 30 Jul 2013 13:43:15 +0200 Subject: fix code style of try catch blocks --- core/ajax/publicpreview.php | 2 +- lib/preview/libreoffice-cl.php | 2 +- lib/preview/pdf.php | 2 +- lib/preview/svg.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/ajax/publicpreview.php b/core/ajax/publicpreview.php index aace24caa21..955fbc2626a 100644 --- a/core/ajax/publicpreview.php +++ b/core/ajax/publicpreview.php @@ -84,7 +84,7 @@ try{ $preview->setScalingUp($scalingUp); $preview->show(); -}catch(\Exception $e) { +} catch (\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); \OC\Preview::showErrorPreview(); diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 0f4ec3d0348..2f1d08499ef 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -35,7 +35,7 @@ class Office extends Provider { try{ $pdf = new \imagick($absPath . '.pdf' . '[0]'); $pdf->setImageFormat('jpg'); - }catch (\Exception $e) { + } catch (\Exception $e) { unlink($absPath); unlink($absPath . '.pdf'); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 723dc1d80d2..cc974b68818 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -22,7 +22,7 @@ if (extension_loaded('imagick')) { try{ $pdf = new \imagick($tmpPath . '[0]'); $pdf->setImageFormat('jpg'); - }catch (\Exception $e) { + } catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } diff --git a/lib/preview/svg.php b/lib/preview/svg.php index bafaf71b15a..e939e526b1b 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -27,7 +27,7 @@ if (extension_loaded('imagick')) { $svg->readImageBlob($content); $svg->setImageFormat('jpg'); - }catch(\Exception $e){ + } catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } -- cgit v1.2.3 From 554b1990e23c76aea182e9b8c2687f8f8b939fb9 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 5 Aug 2013 14:23:30 +0200 Subject: suppress is_file error msg --- lib/image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/image.php b/lib/image.php index c1b187608a6..4bc38e20e56 100644 --- a/lib/image.php +++ b/lib/image.php @@ -392,7 +392,7 @@ class OC_Image { */ public function loadFromFile($imagepath=false) { // exif_imagetype throws "read error!" if file is less than 12 byte - if(!is_file($imagepath) || !file_exists($imagepath) || filesize($imagepath) < 12 || !is_readable($imagepath)) { + if(!@is_file($imagepath) || !file_exists($imagepath) || filesize($imagepath) < 12 || !is_readable($imagepath)) { // Debug output disabled because this method is tried before loadFromBase64? OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagepath, OC_Log::DEBUG); return false; -- cgit v1.2.3 From 91bd4dd67b7d58f09a4dadff8060f63c6d6b691e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 7 Aug 2013 11:48:08 +0200 Subject: implement previews of single shared files --- apps/files_sharing/js/public.js | 2 +- apps/files_sharing/templates/public.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 294223aa094..fbbe9b7f3cb 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -16,7 +16,7 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { var mimetype = $('#mimetype').val(); // Show file preview if previewer is available, images are already handled by the template - if (mimetype.substr(0, mimetype.indexOf('/')) != 'image') { + if (mimetype.substr(0, mimetype.indexOf('/')) != 'image' && $('.publicpreview').length() !== 0) { // Trigger default action if not download TODO var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ); if (typeof action === 'undefined') { diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 746a715f3cc..c164b3ea2b7 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -79,6 +79,10 @@
+ +
+ +
  • -- cgit v1.2.3 From dcc92445a0bc3d9d47768ac0f640780f2b09a5fd Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 7 Aug 2013 11:51:08 +0200 Subject: allow permissions.user to be null as suggested by @butonic --- db_structure.xml | 2 +- lib/util.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db_structure.xml b/db_structure.xml index ef5de653033..4c192ba028e 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -383,7 +383,7 @@ user text - true + false 64 diff --git a/lib/util.php b/lib/util.php index b7dc2207e6c..dc13d31fd2b 100755 --- a/lib/util.php +++ b/lib/util.php @@ -78,7 +78,7 @@ class OC_Util { public static function getVersion() { // hint: We only can count up. Reset minor/patchlevel when // updating major/minor version number. - return array(5, 80, 05); + return array(5, 80, 06); } /** -- cgit v1.2.3 From 41ba155a143d318377302e2672726d7ea588c3c4 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 7 Aug 2013 11:57:10 +0200 Subject: fix js error --- apps/files_sharing/js/public.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index fbbe9b7f3cb..8cac8bf1997 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -16,7 +16,7 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { var mimetype = $('#mimetype').val(); // Show file preview if previewer is available, images are already handled by the template - if (mimetype.substr(0, mimetype.indexOf('/')) != 'image' && $('.publicpreview').length() !== 0) { + if (mimetype.substr(0, mimetype.indexOf('/')) != 'image' && $('.publicpreview').length === 0) { // Trigger default action if not download TODO var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ); if (typeof action === 'undefined') { -- cgit v1.2.3 From 1c9d52774e165da3d916399510727de6b7c487fa Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 9 Aug 2013 09:31:53 +0200 Subject: update indexes of oc_permissions --- db_structure.xml | 2 -- lib/util.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/db_structure.xml b/db_structure.xml index 4c192ba028e..1fcba9e2247 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -397,8 +397,6 @@ id_user_index - true - true fileid ascending diff --git a/lib/util.php b/lib/util.php index dc13d31fd2b..a7a83cf1a23 100755 --- a/lib/util.php +++ b/lib/util.php @@ -78,7 +78,7 @@ class OC_Util { public static function getVersion() { // hint: We only can count up. Reset minor/patchlevel when // updating major/minor version number. - return array(5, 80, 06); + return array(5, 80, 07); } /** -- cgit v1.2.3 From 3cbbe395eba76be37c16dcb00ac93760e965975e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 11:38:52 +0200 Subject: don't use hardcoded size for preview --- apps/files/js/files.js | 4 +++- apps/files/templates/index.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8b66ed6747b..180c23cbfa4 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -825,7 +825,9 @@ function getMimeIcon(mime, ready){ getMimeIcon.cache={}; function getPreviewIcon(path, ready){ - ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:36, y:36})); + var x = $('#filestable').data('preview-x'); + var y = $('#filestable').data('preview-y'); + ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y})); } function getUniqueName(name){ diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index e4348904671..311ada70dfd 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -59,7 +59,7 @@
    t('Nothing in here. Upload something!'))?>
    - +
    ').attr({ "class": "filename", - "style": 'background-image:url('+iconurl+'); background-size: 16px;' + "style": 'background-image:url('+iconurl+'); background-size: 32px;' }); td.append(''); var link_elem = $('').attr({ -- cgit v1.2.3 From b16a018da99259278ba2f93f1e0c2d2e2bce6fb0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 26 Aug 2013 16:33:51 +0200 Subject: use random string as id for checkbox --- apps/files/js/filelist.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 7a48453488a..cbeca1764ea 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -17,7 +17,8 @@ var FileList={ "class": "filename", "style": 'background-image:url('+iconurl+'); background-size: 32px;' }); - td.append(''); + var rand = Math.random().toString(16).slice(2); + td.append(''); var link_elem = $('').attr({ "class": "name", "href": linktarget -- cgit v1.2.3 From 70b6e2161ec654f7049027bf6dc5072c1eda4d5e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 29 Aug 2013 10:08:53 +0200 Subject: invert logic of disable_previews --- config/config.sample.php | 2 +- lib/preview.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 76de97818d5..6dd45163677 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -191,7 +191,7 @@ $CONFIG = array( 'customclient_ios' => '', //https://itunes.apple.com/us/app/owncloud/id543672169?mt=8 // PREVIEW -'disable_previews' => false, +'enable_previews' => true, /* 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 */ diff --git a/lib/preview.php b/lib/preview.php index a8a8580e229..164ad10ba5f 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -569,9 +569,9 @@ class Preview { * @return void */ private static function initProviders() { - if(\OC_Config::getValue('disable_previews', false)) { + if(!\OC_Config::getValue('enable_previews', true)) { $provider = new Preview\Unknown(); - self::$providers = array($provider); + self::$providers = array($provider->getMimeType() => $provider); return; } @@ -606,7 +606,7 @@ class Preview { } public static function isMimeSupported($mimetype) { - if(\OC_Config::getValue('disable_previews', false)) { + if(!\OC_Config::getValue('enable_previews', true)) { return false; } -- cgit v1.2.3 From 728fc7f123eeedb79f01dd1f38d469857a8e15cf Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 29 Aug 2013 16:13:16 +0200 Subject: fix parameter missing warning --- lib/preview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 164ad10ba5f..b40ba191fba 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -570,7 +570,7 @@ class Preview { */ private static function initProviders() { if(!\OC_Config::getValue('enable_previews', true)) { - $provider = new Preview\Unknown(); + $provider = new Preview\Unknown(array()); self::$providers = array($provider->getMimeType() => $provider); return; } -- cgit v1.2.3 From 40cee5639e89ad052ba5234a28e5f197f2fd70ba Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 30 Aug 2013 18:07:49 +0200 Subject: use gerMimeTypeDetector detectPath instead of getMimeType --- apps/files/ajax/newfile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index d224e79d01b..76c03c87a51 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -79,7 +79,7 @@ if($source) { $success = false; if (!$content) { $templateManager = OC_Helper::getFileTemplateManager(); - $mimeType = OC_Helper::getMimeType($target); + $mimeType = OC_Helper::getMimetypeDetector()->detectPath($target); $content = $templateManager->getTemplate($mimeType); } -- cgit v1.2.3 From 668c4c2652ef4619a132d609461423aafaef424e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 30 Aug 2013 22:05:44 +0200 Subject: fix issue with filetable background --- apps/files/css/files.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index aadf29687b8..498e34d70d4 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -75,7 +75,7 @@ color:#888; text-shadow:#fff 0 1px 0; } #filestable { position: relative; top:37px; width:100%; } -#filestable tbody tr { background-color:#fff; height:2.5em; } +tbody tr { background-color:#fff; height:2.5em; } tbody tr:hover, tbody tr:active { background-color: rgb(240,240,240); } -- cgit v1.2.3
    -- cgit v1.2.3 From e704c8e4dc41e69b4d4d8e8f3d1c1108920bb29a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 11:51:54 +0200 Subject: use web.svg instead of web.png --- apps/files/templates/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 311ada70dfd..89604c4fa0b 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -10,7 +10,7 @@ data-type='file'>

    t('Text file'));?>

  • t('Folder'));?>

  • -
  • t('From link'));?>

  • -- cgit v1.2.3 From f9b281576726774c2109f8f909aceeb7320b4cae Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 12:21:27 +0200 Subject: remove \OC\Preview::showErrorPreview --- core/ajax/preview.php | 3 --- core/ajax/publicpreview.php | 6 ------ core/ajax/trashbinpreview.php | 3 --- lib/preview.php | 7 ------- 4 files changed, 19 deletions(-) diff --git a/core/ajax/preview.php b/core/ajax/preview.php index a9d127ffcc4..486155831d7 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -15,14 +15,12 @@ $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : if($file === '') { \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); - \OC\Preview::showErrorPreview(); exit; } if($maxX === 0 || $maxY === 0) { \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - \OC\Preview::showErrorPreview(); exit; } @@ -37,6 +35,5 @@ try{ }catch(\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - \OC\Preview::showErrorPreview(); exit; } \ No newline at end of file diff --git a/core/ajax/publicpreview.php b/core/ajax/publicpreview.php index 955fbc2626a..83194d5349c 100644 --- a/core/ajax/publicpreview.php +++ b/core/ajax/publicpreview.php @@ -18,7 +18,6 @@ $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; if($token === ''){ \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG); - \OC\Preview::showErrorPreview(); exit; } @@ -26,14 +25,12 @@ $linkedItem = \OCP\Share::getShareByToken($token); if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) { \OC_Response::setStatus(404); \OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG); - \OC\Preview::showErrorPreview(); exit; } if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) { \OC_Response::setStatus(500); \OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN); - \OC\Preview::showErrorPreview(); exit; } @@ -50,7 +47,6 @@ if($linkedItem['item_type'] === 'folder') { if(!$isvalid) { \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN); - \OC\Preview::showErrorPreview(); exit; } $sharedFile = \OC\Files\Filesystem::normalizePath($file); @@ -70,7 +66,6 @@ if(substr($path, 0, 1) === '/') { if($maxX === 0 || $maxY === 0) { \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - \OC\Preview::showErrorPreview(); exit; } @@ -87,6 +82,5 @@ try{ } catch (\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - \OC\Preview::showErrorPreview(); exit; } \ No newline at end of file diff --git a/core/ajax/trashbinpreview.php b/core/ajax/trashbinpreview.php index d018a57d37b..a916dcf229f 100644 --- a/core/ajax/trashbinpreview.php +++ b/core/ajax/trashbinpreview.php @@ -19,14 +19,12 @@ $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : if($file === '') { \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); - \OC\Preview::showErrorPreview(); exit; } if($maxX === 0 || $maxY === 0) { \OC_Response::setStatus(400); //400 Bad Request \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - \OC\Preview::showErrorPreview(); exit; } @@ -41,6 +39,5 @@ try{ }catch(\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - \OC\Preview::showErrorPreview(); exit; } \ No newline at end of file diff --git a/lib/preview.php b/lib/preview.php index 9f4d20b4650..92cc87c5897 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -611,11 +611,4 @@ class Preview { } return false; } - - private static function showErrorPreview() { - $path = \OC::$SERVERROOT . '/core/img/actions/delete.png'; - $preview = new \OC_Image($path); - $preview->preciseResize(36, 36); - $preview->show(); - } } \ No newline at end of file -- cgit v1.2.3 From 20855add94701432da093e2ae74477a76ddc7f48 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 12:33:41 +0200 Subject: add more file type icons, replace old ones --- core/img/filetypes/application-epub+zip.png | Bin 0 -> 1371 bytes core/img/filetypes/application-epub+zip.svg | 761 ++++++++++++++++++++++++++++ core/img/filetypes/calendar.png | Bin 0 -> 1333 bytes core/img/filetypes/calendar.svg | 94 ++++ core/img/filetypes/database.png | Bin 390 -> 1372 bytes core/img/filetypes/database.svg | 54 ++ core/img/filetypes/folder-drag-accept.png | Bin 0 -> 757 bytes core/img/filetypes/folder-drag-accept.svg | 335 ++++++++++++ core/img/filetypes/link.png | Bin 923 -> 850 bytes core/img/filetypes/link.svg | 12 + core/img/filetypes/text-calendar.png | Bin 675 -> 0 bytes core/img/filetypes/text-vcard.png | Bin 533 -> 782 bytes core/img/filetypes/text-vcard.svg | 60 +++ core/img/filetypes/video.png | Bin 653 -> 1809 bytes core/img/filetypes/video.svg | 71 +++ 15 files changed, 1387 insertions(+) create mode 100644 core/img/filetypes/application-epub+zip.png create mode 100644 core/img/filetypes/application-epub+zip.svg create mode 100644 core/img/filetypes/calendar.png create mode 100644 core/img/filetypes/calendar.svg create mode 100644 core/img/filetypes/database.svg create mode 100644 core/img/filetypes/folder-drag-accept.png create mode 100644 core/img/filetypes/folder-drag-accept.svg create mode 100644 core/img/filetypes/link.svg delete mode 100644 core/img/filetypes/text-calendar.png create mode 100644 core/img/filetypes/text-vcard.svg create mode 100644 core/img/filetypes/video.svg diff --git a/core/img/filetypes/application-epub+zip.png b/core/img/filetypes/application-epub+zip.png new file mode 100644 index 00000000000..b3e3b28b4d5 Binary files /dev/null and b/core/img/filetypes/application-epub+zip.png differ diff --git a/core/img/filetypes/application-epub+zip.svg b/core/img/filetypes/application-epub+zip.svg new file mode 100644 index 00000000000..041f9f15e68 --- /dev/null +++ b/core/img/filetypes/application-epub+zip.svg @@ -0,0 +1,761 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/calendar.png b/core/img/filetypes/calendar.png new file mode 100644 index 00000000000..d85b1db651c Binary files /dev/null and b/core/img/filetypes/calendar.png differ diff --git a/core/img/filetypes/calendar.svg b/core/img/filetypes/calendar.svg new file mode 100644 index 00000000000..0016749b936 --- /dev/null +++ b/core/img/filetypes/calendar.svg @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/database.png b/core/img/filetypes/database.png index 3d09261a26e..24788b2a37f 100644 Binary files a/core/img/filetypes/database.png and b/core/img/filetypes/database.png differ diff --git a/core/img/filetypes/database.svg b/core/img/filetypes/database.svg new file mode 100644 index 00000000000..6dfac54e68b --- /dev/null +++ b/core/img/filetypes/database.svg @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/core/img/filetypes/folder-drag-accept.png b/core/img/filetypes/folder-drag-accept.png new file mode 100644 index 00000000000..19c2d2eebd4 Binary files /dev/null and b/core/img/filetypes/folder-drag-accept.png differ diff --git a/core/img/filetypes/folder-drag-accept.svg b/core/img/filetypes/folder-drag-accept.svg new file mode 100644 index 00000000000..a7885c80be7 --- /dev/null +++ b/core/img/filetypes/folder-drag-accept.svg @@ -0,0 +1,335 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/link.png b/core/img/filetypes/link.png index 68f21d30116..0e021d89f82 100644 Binary files a/core/img/filetypes/link.png and b/core/img/filetypes/link.png differ diff --git a/core/img/filetypes/link.svg b/core/img/filetypes/link.svg new file mode 100644 index 00000000000..b25013414ba --- /dev/null +++ b/core/img/filetypes/link.svg @@ -0,0 +1,12 @@ + + + + + image/svg+xml + + + + + + + diff --git a/core/img/filetypes/text-calendar.png b/core/img/filetypes/text-calendar.png deleted file mode 100644 index 658913852d6..00000000000 Binary files a/core/img/filetypes/text-calendar.png and /dev/null differ diff --git a/core/img/filetypes/text-vcard.png b/core/img/filetypes/text-vcard.png index c02f315d207..2e52d1ecb3a 100644 Binary files a/core/img/filetypes/text-vcard.png and b/core/img/filetypes/text-vcard.png differ diff --git a/core/img/filetypes/text-vcard.svg b/core/img/filetypes/text-vcard.svg new file mode 100644 index 00000000000..27054be57e6 --- /dev/null +++ b/core/img/filetypes/text-vcard.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/video.png b/core/img/filetypes/video.png index b0ce7bb198a..13bf229fc45 100644 Binary files a/core/img/filetypes/video.png and b/core/img/filetypes/video.png differ diff --git a/core/img/filetypes/video.svg b/core/img/filetypes/video.svg new file mode 100644 index 00000000000..b499d1cd252 --- /dev/null +++ b/core/img/filetypes/video.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 5abf6ddea4b3e1246a1c66e876e420841322865f Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 12:36:31 +0200 Subject: replace same but differently named package graphics with one proper one --- core/img/filetypes/application-x-7z-compressed.png | Bin 650 -> 0 bytes .../application-x-bzip-compressed-tar.png | Bin 650 -> 0 bytes core/img/filetypes/application-x-bzip.png | Bin 650 -> 0 bytes .../img/filetypes/application-x-compressed-tar.png | Bin 650 -> 0 bytes core/img/filetypes/application-x-deb.png | Bin 650 -> 0 bytes .../img/filetypes/application-x-debian-package.png | Bin 539 -> 0 bytes core/img/filetypes/application-x-gzip.png | Bin 650 -> 0 bytes .../application-x-lzma-compressed-tar.png | Bin 650 -> 0 bytes core/img/filetypes/application-x-rar.png | Bin 650 -> 0 bytes core/img/filetypes/application-x-rpm.png | Bin 650 -> 0 bytes core/img/filetypes/application-x-tar.png | Bin 650 -> 0 bytes core/img/filetypes/application-x-tarz.png | Bin 650 -> 0 bytes core/img/filetypes/application-zip.png | Bin 650 -> 0 bytes core/img/filetypes/package-x-generic.png | Bin 0 -> 794 bytes core/img/filetypes/package-x-generic.svg | 62 +++++++++++++++++++++ core/img/filetypes/x-.png | Bin 555 -> 0 bytes 16 files changed, 62 insertions(+) delete mode 100644 core/img/filetypes/application-x-7z-compressed.png delete mode 100644 core/img/filetypes/application-x-bzip-compressed-tar.png delete mode 100644 core/img/filetypes/application-x-bzip.png delete mode 100644 core/img/filetypes/application-x-compressed-tar.png delete mode 100644 core/img/filetypes/application-x-deb.png delete mode 100644 core/img/filetypes/application-x-debian-package.png delete mode 100644 core/img/filetypes/application-x-gzip.png delete mode 100644 core/img/filetypes/application-x-lzma-compressed-tar.png delete mode 100644 core/img/filetypes/application-x-rar.png delete mode 100644 core/img/filetypes/application-x-rpm.png delete mode 100644 core/img/filetypes/application-x-tar.png delete mode 100644 core/img/filetypes/application-x-tarz.png delete mode 100644 core/img/filetypes/application-zip.png create mode 100644 core/img/filetypes/package-x-generic.png create mode 100644 core/img/filetypes/package-x-generic.svg delete mode 100644 core/img/filetypes/x-.png diff --git a/core/img/filetypes/application-x-7z-compressed.png b/core/img/filetypes/application-x-7z-compressed.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-7z-compressed.png and /dev/null differ diff --git a/core/img/filetypes/application-x-bzip-compressed-tar.png b/core/img/filetypes/application-x-bzip-compressed-tar.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-bzip-compressed-tar.png and /dev/null differ diff --git a/core/img/filetypes/application-x-bzip.png b/core/img/filetypes/application-x-bzip.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-bzip.png and /dev/null differ diff --git a/core/img/filetypes/application-x-compressed-tar.png b/core/img/filetypes/application-x-compressed-tar.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-compressed-tar.png and /dev/null differ diff --git a/core/img/filetypes/application-x-deb.png b/core/img/filetypes/application-x-deb.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-deb.png and /dev/null differ diff --git a/core/img/filetypes/application-x-debian-package.png b/core/img/filetypes/application-x-debian-package.png deleted file mode 100644 index 1d6db5f933a..00000000000 Binary files a/core/img/filetypes/application-x-debian-package.png and /dev/null differ diff --git a/core/img/filetypes/application-x-gzip.png b/core/img/filetypes/application-x-gzip.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-gzip.png and /dev/null differ diff --git a/core/img/filetypes/application-x-lzma-compressed-tar.png b/core/img/filetypes/application-x-lzma-compressed-tar.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-lzma-compressed-tar.png and /dev/null differ diff --git a/core/img/filetypes/application-x-rar.png b/core/img/filetypes/application-x-rar.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-rar.png and /dev/null differ diff --git a/core/img/filetypes/application-x-rpm.png b/core/img/filetypes/application-x-rpm.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-rpm.png and /dev/null differ diff --git a/core/img/filetypes/application-x-tar.png b/core/img/filetypes/application-x-tar.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-tar.png and /dev/null differ diff --git a/core/img/filetypes/application-x-tarz.png b/core/img/filetypes/application-x-tarz.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-x-tarz.png and /dev/null differ diff --git a/core/img/filetypes/application-zip.png b/core/img/filetypes/application-zip.png deleted file mode 100644 index 2cd08aebf95..00000000000 Binary files a/core/img/filetypes/application-zip.png and /dev/null differ diff --git a/core/img/filetypes/package-x-generic.png b/core/img/filetypes/package-x-generic.png new file mode 100644 index 00000000000..e08cc5480ce Binary files /dev/null and b/core/img/filetypes/package-x-generic.png differ diff --git a/core/img/filetypes/package-x-generic.svg b/core/img/filetypes/package-x-generic.svg new file mode 100644 index 00000000000..13ab5b7550e --- /dev/null +++ b/core/img/filetypes/package-x-generic.svg @@ -0,0 +1,62 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/x-.png b/core/img/filetypes/x-.png deleted file mode 100644 index 8443c23eb94..00000000000 Binary files a/core/img/filetypes/x-.png and /dev/null differ -- cgit v1.2.3 From fc23649fa1afa5123bc6421378c9bc756db0ba7d Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 12:43:42 +0200 Subject: replace different icons for documents, spreadsheets and presentations with proper ones --- core/img/filetypes/application-msexcel.png | Bin 663 -> 0 bytes core/img/filetypes/application-mspowerpoint.png | Bin 588 -> 0 bytes core/img/filetypes/application-msword.png | Bin 651 -> 0 bytes .../application-vnd.oasis.opendocument.formula.png | Bin 479 -> 0 bytes ...application-vnd.oasis.opendocument.graphics.png | Bin 475 -> 0 bytes ...ication-vnd.oasis.opendocument.presentation.png | Bin 333 -> 0 bytes ...lication-vnd.oasis.opendocument.spreadsheet.png | Bin 344 -> 0 bytes .../application-vnd.oasis.opendocument.text.png | Bin 347 -> 0 bytes core/img/filetypes/ms-excel.png | Bin 663 -> 0 bytes core/img/filetypes/ms-powerpoint.png | Bin 588 -> 0 bytes core/img/filetypes/presentation.png | Bin 519 -> 0 bytes core/img/filetypes/spreadsheet.png | Bin 566 -> 0 bytes core/img/filetypes/x-office-document.png | Bin 0 -> 930 bytes core/img/filetypes/x-office-document.svg | 60 ++++++++++++ core/img/filetypes/x-office-presentation.png | Bin 0 -> 1102 bytes core/img/filetypes/x-office-presentation.svg | 109 +++++++++++++++++++++ core/img/filetypes/x-office-spreadsheet.png | Bin 0 -> 789 bytes core/img/filetypes/x-office-spreadsheet.svg | 64 ++++++++++++ 18 files changed, 233 insertions(+) delete mode 100644 core/img/filetypes/application-msexcel.png delete mode 100644 core/img/filetypes/application-mspowerpoint.png delete mode 100644 core/img/filetypes/application-msword.png delete mode 100644 core/img/filetypes/application-vnd.oasis.opendocument.formula.png delete mode 100644 core/img/filetypes/application-vnd.oasis.opendocument.graphics.png delete mode 100644 core/img/filetypes/application-vnd.oasis.opendocument.presentation.png delete mode 100644 core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png delete mode 100644 core/img/filetypes/application-vnd.oasis.opendocument.text.png delete mode 100644 core/img/filetypes/ms-excel.png delete mode 100644 core/img/filetypes/ms-powerpoint.png delete mode 100644 core/img/filetypes/presentation.png delete mode 100644 core/img/filetypes/spreadsheet.png create mode 100644 core/img/filetypes/x-office-document.png create mode 100644 core/img/filetypes/x-office-document.svg create mode 100644 core/img/filetypes/x-office-presentation.png create mode 100644 core/img/filetypes/x-office-presentation.svg create mode 100644 core/img/filetypes/x-office-spreadsheet.png create mode 100644 core/img/filetypes/x-office-spreadsheet.svg diff --git a/core/img/filetypes/application-msexcel.png b/core/img/filetypes/application-msexcel.png deleted file mode 100644 index b977d7e52e2..00000000000 Binary files a/core/img/filetypes/application-msexcel.png and /dev/null differ diff --git a/core/img/filetypes/application-mspowerpoint.png b/core/img/filetypes/application-mspowerpoint.png deleted file mode 100644 index c4eff0387d5..00000000000 Binary files a/core/img/filetypes/application-mspowerpoint.png and /dev/null differ diff --git a/core/img/filetypes/application-msword.png b/core/img/filetypes/application-msword.png deleted file mode 100644 index ae8ecbf4767..00000000000 Binary files a/core/img/filetypes/application-msword.png and /dev/null differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.formula.png b/core/img/filetypes/application-vnd.oasis.opendocument.formula.png deleted file mode 100644 index e0cf49542d4..00000000000 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.formula.png and /dev/null differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.graphics.png b/core/img/filetypes/application-vnd.oasis.opendocument.graphics.png deleted file mode 100644 index b326a0543a5..00000000000 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.graphics.png and /dev/null differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.presentation.png b/core/img/filetypes/application-vnd.oasis.opendocument.presentation.png deleted file mode 100644 index 7c6fd246840..00000000000 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.presentation.png and /dev/null differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png b/core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png deleted file mode 100644 index 8b0e85b0670..00000000000 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png and /dev/null differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.text.png b/core/img/filetypes/application-vnd.oasis.opendocument.text.png deleted file mode 100644 index 48452eb3e86..00000000000 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.text.png and /dev/null differ diff --git a/core/img/filetypes/ms-excel.png b/core/img/filetypes/ms-excel.png deleted file mode 100644 index b977d7e52e2..00000000000 Binary files a/core/img/filetypes/ms-excel.png and /dev/null differ diff --git a/core/img/filetypes/ms-powerpoint.png b/core/img/filetypes/ms-powerpoint.png deleted file mode 100644 index c4eff0387d5..00000000000 Binary files a/core/img/filetypes/ms-powerpoint.png and /dev/null differ diff --git a/core/img/filetypes/presentation.png b/core/img/filetypes/presentation.png deleted file mode 100644 index b4aaad9a45c..00000000000 Binary files a/core/img/filetypes/presentation.png and /dev/null differ diff --git a/core/img/filetypes/spreadsheet.png b/core/img/filetypes/spreadsheet.png deleted file mode 100644 index abcd93689a0..00000000000 Binary files a/core/img/filetypes/spreadsheet.png and /dev/null differ diff --git a/core/img/filetypes/x-office-document.png b/core/img/filetypes/x-office-document.png new file mode 100644 index 00000000000..fcd28e9a292 Binary files /dev/null and b/core/img/filetypes/x-office-document.png differ diff --git a/core/img/filetypes/x-office-document.svg b/core/img/filetypes/x-office-document.svg new file mode 100644 index 00000000000..fc51a3a1b70 --- /dev/null +++ b/core/img/filetypes/x-office-document.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/x-office-presentation.png b/core/img/filetypes/x-office-presentation.png new file mode 100644 index 00000000000..7ee552ba7c8 Binary files /dev/null and b/core/img/filetypes/x-office-presentation.png differ diff --git a/core/img/filetypes/x-office-presentation.svg b/core/img/filetypes/x-office-presentation.svg new file mode 100644 index 00000000000..821798d50fd --- /dev/null +++ b/core/img/filetypes/x-office-presentation.svg @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/x-office-spreadsheet.png b/core/img/filetypes/x-office-spreadsheet.png new file mode 100644 index 00000000000..dfdc74a8bf6 Binary files /dev/null and b/core/img/filetypes/x-office-spreadsheet.png differ diff --git a/core/img/filetypes/x-office-spreadsheet.svg b/core/img/filetypes/x-office-spreadsheet.svg new file mode 100644 index 00000000000..af40bb252a2 --- /dev/null +++ b/core/img/filetypes/x-office-spreadsheet.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 14003b6d96396517875e39f46cd004ac867315bc Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 13:00:13 +0200 Subject: replace different icons for code with proper ones --- core/img/filetypes/application-sgf.png | Bin 702 -> 0 bytes core/img/filetypes/code-script.png | Bin 859 -> 0 bytes core/img/filetypes/code.png | Bin 908 -> 0 bytes core/img/filetypes/code.svg | 66 ----------------------- core/img/filetypes/model.png | Bin 452 -> 0 bytes core/img/filetypes/readme-2.txt | 28 ---------- core/img/filetypes/readme.txt | 22 -------- core/img/filetypes/ruby.png | Bin 626 -> 0 bytes core/img/filetypes/text-code.png | Bin 0 -> 908 bytes core/img/filetypes/text-code.svg | 66 +++++++++++++++++++++++ core/img/filetypes/text-css.png | Bin 524 -> 0 bytes core/img/filetypes/text-x-c++.png | Bin 621 -> 0 bytes core/img/filetypes/text-x-c.png | Bin 587 -> 1345 bytes core/img/filetypes/text-x-c.svg | 75 ++++++++++++++++++++++++++ core/img/filetypes/text-x-csharp.png | Bin 700 -> 0 bytes core/img/filetypes/text-x-h.png | Bin 603 -> 1242 bytes core/img/filetypes/text-x-h.svg | 79 ++++++++++++++++++++++++++++ core/img/filetypes/text-x-javascript.png | Bin 0 -> 1340 bytes core/img/filetypes/text-x-javascript.svg | 76 +++++++++++++++++++++++++++ core/img/filetypes/text-x-php.png | Bin 538 -> 0 bytes core/img/filetypes/text-x-python.png | Bin 0 -> 1469 bytes core/img/filetypes/text-x-python.svg | 87 +++++++++++++++++++++++++++++++ 22 files changed, 383 insertions(+), 116 deletions(-) delete mode 100644 core/img/filetypes/application-sgf.png delete mode 100644 core/img/filetypes/code-script.png delete mode 100644 core/img/filetypes/code.png delete mode 100644 core/img/filetypes/code.svg delete mode 100644 core/img/filetypes/model.png delete mode 100644 core/img/filetypes/readme-2.txt delete mode 100644 core/img/filetypes/readme.txt delete mode 100644 core/img/filetypes/ruby.png create mode 100644 core/img/filetypes/text-code.png create mode 100644 core/img/filetypes/text-code.svg delete mode 100644 core/img/filetypes/text-css.png delete mode 100644 core/img/filetypes/text-x-c++.png create mode 100644 core/img/filetypes/text-x-c.svg delete mode 100644 core/img/filetypes/text-x-csharp.png create mode 100644 core/img/filetypes/text-x-h.svg create mode 100644 core/img/filetypes/text-x-javascript.png create mode 100644 core/img/filetypes/text-x-javascript.svg delete mode 100644 core/img/filetypes/text-x-php.png create mode 100644 core/img/filetypes/text-x-python.png create mode 100644 core/img/filetypes/text-x-python.svg diff --git a/core/img/filetypes/application-sgf.png b/core/img/filetypes/application-sgf.png deleted file mode 100644 index 48996c54394..00000000000 Binary files a/core/img/filetypes/application-sgf.png and /dev/null differ diff --git a/core/img/filetypes/code-script.png b/core/img/filetypes/code-script.png deleted file mode 100644 index 63fe6ceff5b..00000000000 Binary files a/core/img/filetypes/code-script.png and /dev/null differ diff --git a/core/img/filetypes/code.png b/core/img/filetypes/code.png deleted file mode 100644 index 753d151f538..00000000000 Binary files a/core/img/filetypes/code.png and /dev/null differ diff --git a/core/img/filetypes/code.svg b/core/img/filetypes/code.svg deleted file mode 100644 index 61a5c19f511..00000000000 --- a/core/img/filetypes/code.svg +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/core/img/filetypes/model.png b/core/img/filetypes/model.png deleted file mode 100644 index 7851cf34c94..00000000000 Binary files a/core/img/filetypes/model.png and /dev/null differ diff --git a/core/img/filetypes/readme-2.txt b/core/img/filetypes/readme-2.txt deleted file mode 100644 index 5a606f9a0bb..00000000000 --- a/core/img/filetypes/readme-2.txt +++ /dev/null @@ -1,28 +0,0 @@ -15.02.2012 - -Following new icons have been added: -core/img/filetypes/application-vnd.oasis.opendocument.formula.png -core/img/filetypes/application-vnd.oasis.opendocument.graphics.png -core/img/filetypes/application-vnd.oasis.opendocument.presentation.png -core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png -core/img/filetypes/application-vnd.oasis.opendocument.text.png - Download: http://odftoolkit.org/ODF-Icons#ODF_Icons - License: Apache 2.0 - -core/img/filetypes/application-x-7z-compressed.png -core/img/filetypes/application-x-bzip-compressed-tar.png -core/img/filetypes/application-x-bzip.png -core/img/filetypes/application-x-compressed-tar.png -core/img/filetypes/application-x-deb.png -core/img/filetypes/application-x-debian-package.png -core/img/filetypes/application-x-gzip.png -core/img/filetypes/application-x-lzma-compressed-tar.png -core/img/filetypes/application-x-rar.png -core/img/filetypes/application-x-rpm.png -core/img/filetypes/application-x-tar.png -core/img/filetypes/application-x-tarz.png -core/img/filetypes/application-zip.png - Author: Gomez Hyuuga - License: Creative Commons Attribution-Share Alike 3.0 Unported License - Download: http://kde-look.org/content/show.php/?content=101767 - diff --git a/core/img/filetypes/readme.txt b/core/img/filetypes/readme.txt deleted file mode 100644 index 400a64d7857..00000000000 --- a/core/img/filetypes/readme.txt +++ /dev/null @@ -1,22 +0,0 @@ -Silk icon set 1.3 - -_________________________________________ -Mark James -http://www.famfamfam.com/lab/icons/silk/ -_________________________________________ - -This work is licensed under a -Creative Commons Attribution 2.5 License. -[ http://creativecommons.org/licenses/by/2.5/ ] - -This means you may use it for any purpose, -and make any changes you like. -All I ask is that you include a link back -to this page in your credits. - -Are you using this icon set? Send me an email -(including a link or picture if available) to -mjames@gmail.com - -Any other questions about this icon set please -contact mjames@gmail.com \ No newline at end of file diff --git a/core/img/filetypes/ruby.png b/core/img/filetypes/ruby.png deleted file mode 100644 index f59b7c4365f..00000000000 Binary files a/core/img/filetypes/ruby.png and /dev/null differ diff --git a/core/img/filetypes/text-code.png b/core/img/filetypes/text-code.png new file mode 100644 index 00000000000..753d151f538 Binary files /dev/null and b/core/img/filetypes/text-code.png differ diff --git a/core/img/filetypes/text-code.svg b/core/img/filetypes/text-code.svg new file mode 100644 index 00000000000..61a5c19f511 --- /dev/null +++ b/core/img/filetypes/text-code.svg @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text-css.png b/core/img/filetypes/text-css.png deleted file mode 100644 index 23f3101811f..00000000000 Binary files a/core/img/filetypes/text-css.png and /dev/null differ diff --git a/core/img/filetypes/text-x-c++.png b/core/img/filetypes/text-x-c++.png deleted file mode 100644 index a87cf847cb7..00000000000 Binary files a/core/img/filetypes/text-x-c++.png and /dev/null differ diff --git a/core/img/filetypes/text-x-c.png b/core/img/filetypes/text-x-c.png index 34a05cccf06..b9edd1e866e 100644 Binary files a/core/img/filetypes/text-x-c.png and b/core/img/filetypes/text-x-c.png differ diff --git a/core/img/filetypes/text-x-c.svg b/core/img/filetypes/text-x-c.svg new file mode 100644 index 00000000000..35a6a0cdfe2 --- /dev/null +++ b/core/img/filetypes/text-x-c.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text-x-csharp.png b/core/img/filetypes/text-x-csharp.png deleted file mode 100644 index ffb8fc932f3..00000000000 Binary files a/core/img/filetypes/text-x-csharp.png and /dev/null differ diff --git a/core/img/filetypes/text-x-h.png b/core/img/filetypes/text-x-h.png index e902abb0767..37a8805b506 100644 Binary files a/core/img/filetypes/text-x-h.png and b/core/img/filetypes/text-x-h.png differ diff --git a/core/img/filetypes/text-x-h.svg b/core/img/filetypes/text-x-h.svg new file mode 100644 index 00000000000..38ed04690fc --- /dev/null +++ b/core/img/filetypes/text-x-h.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text-x-javascript.png b/core/img/filetypes/text-x-javascript.png new file mode 100644 index 00000000000..24d09ce9781 Binary files /dev/null and b/core/img/filetypes/text-x-javascript.png differ diff --git a/core/img/filetypes/text-x-javascript.svg b/core/img/filetypes/text-x-javascript.svg new file mode 100644 index 00000000000..0cc52ce6ba7 --- /dev/null +++ b/core/img/filetypes/text-x-javascript.svg @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/text-x-php.png b/core/img/filetypes/text-x-php.png deleted file mode 100644 index 7868a25945c..00000000000 Binary files a/core/img/filetypes/text-x-php.png and /dev/null differ diff --git a/core/img/filetypes/text-x-python.png b/core/img/filetypes/text-x-python.png new file mode 100644 index 00000000000..57148f4b90d Binary files /dev/null and b/core/img/filetypes/text-x-python.png differ diff --git a/core/img/filetypes/text-x-python.svg b/core/img/filetypes/text-x-python.svg new file mode 100644 index 00000000000..00755e6d0c2 --- /dev/null +++ b/core/img/filetypes/text-x-python.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 4f525c864df7eb6caf1bc945c3c9e48b20bcce5e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 13:25:07 +0200 Subject: lazy load preview icons --- apps/files/js/filelist.js | 2 +- apps/files/js/files.js | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 288648693be..138329940b4 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -186,7 +186,7 @@ var FileList={ tr.attr('data-id', id); } var path = $('#dir').val()+'/'+name; - getPreviewIcon(path, function(previewpath){ + lazyLoadPreview(path, mime, 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 180c23cbfa4..7b01a5202da 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -366,8 +366,8 @@ $(document).ready(function() { var tr=$('tr').filterAttr('data-file',name); tr.attr('data-mime',result.data.mime); tr.attr('data-id', result.data.id); - var path = $('#dir').val()+'/'+name; - getPreviewIcon(path, function(previewpath){ + var path = $('#dir').val() + '/' + name; + lazyLoadPreview(path, result.data.mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } else { @@ -432,7 +432,7 @@ $(document).ready(function() { tr.data('mime',mime).data('id',id); tr.attr('data-id', id); var path = $('#dir').val()+'/'+localName; - getPreviewIcon(path, function(previewpath){ + lazyLoadPreview(path, mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); }); @@ -639,7 +639,7 @@ var createDragShadow = function(event){ newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { var path = $('#dir').val()+'/'+elem.name; - getPreviewIcon(path, function(previewpath){ + lazyLoadPreview(path, elem.mime, function(previewpath){ newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } @@ -824,10 +824,18 @@ function getMimeIcon(mime, ready){ } getMimeIcon.cache={}; -function getPreviewIcon(path, ready){ +function lazyLoadPreview(path, mime, ready) { + getMimeIcon(mime,ready); var x = $('#filestable').data('preview-x'); var y = $('#filestable').data('preview-y'); - ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y})); + var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y}); + $.ajax({ + url: previewURL, + type: 'GET', + success: function() { + ready(previewURL); + } + }); } function getUniqueName(name){ -- cgit v1.2.3 From 79a5e2a4cced4787635632f3857fe1d88cf64c71 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 13:45:20 +0200 Subject: adjustments of video and web icon --- core/img/filetypes/link.png | Bin 850 -> 0 bytes core/img/filetypes/link.svg | 12 --- core/img/filetypes/video.png | Bin 1809 -> 1362 bytes core/img/filetypes/video.svg | 110 ++++++++++++++------------ core/img/filetypes/web.png | Bin 0 -> 2284 bytes core/img/filetypes/web.svg | 47 +++++++++++ core/img/web.png | Bin 4472 -> 0 bytes core/img/web.svg | 183 ------------------------------------------- 8 files changed, 109 insertions(+), 243 deletions(-) delete mode 100644 core/img/filetypes/link.png delete mode 100644 core/img/filetypes/link.svg create mode 100644 core/img/filetypes/web.png create mode 100644 core/img/filetypes/web.svg delete mode 100644 core/img/web.png delete mode 100644 core/img/web.svg diff --git a/core/img/filetypes/link.png b/core/img/filetypes/link.png deleted file mode 100644 index 0e021d89f82..00000000000 Binary files a/core/img/filetypes/link.png and /dev/null differ diff --git a/core/img/filetypes/link.svg b/core/img/filetypes/link.svg deleted file mode 100644 index b25013414ba..00000000000 --- a/core/img/filetypes/link.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - image/svg+xml - - - - - - - diff --git a/core/img/filetypes/video.png b/core/img/filetypes/video.png index 13bf229fc45..045754df26f 100644 Binary files a/core/img/filetypes/video.png and b/core/img/filetypes/video.png differ diff --git a/core/img/filetypes/video.svg b/core/img/filetypes/video.svg index b499d1cd252..67691369ac9 100644 --- a/core/img/filetypes/video.svg +++ b/core/img/filetypes/video.svg @@ -1,51 +1,46 @@ - - - - - - - - - - - - - + + + + - - - - - + + + + + + + - - - + + + + - - - - - - - - - - - - - - + + - + + + - + + + + + + + + + + + + @@ -56,16 +51,35 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/web.png b/core/img/filetypes/web.png new file mode 100644 index 00000000000..0868ca52747 Binary files /dev/null and b/core/img/filetypes/web.png differ diff --git a/core/img/filetypes/web.svg b/core/img/filetypes/web.svg new file mode 100644 index 00000000000..6ea49d59fb4 --- /dev/null +++ b/core/img/filetypes/web.svg @@ -0,0 +1,47 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/web.png b/core/img/web.png deleted file mode 100644 index bdc2f4a84a5..00000000000 Binary files a/core/img/web.png and /dev/null differ diff --git a/core/img/web.svg b/core/img/web.svg deleted file mode 100644 index bc6c6bde650..00000000000 --- a/core/img/web.svg +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3 From 320bf0e8c1fda9560d2ec6046153eeef59c7da1e Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 16:19:02 +0200 Subject: fix breaking error due to ... a wrong icon link. Seriously? --- apps/files/templates/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 89604c4fa0b..8598ead2404 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -10,7 +10,7 @@ data-type='file'>

    t('Text file'));?>

  • t('Folder'));?>

  • -
  • t('From link'));?>

  • -- cgit v1.2.3 From a255cc60075e9dab831754ff09cb522c37ea421f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 18:48:30 +0200 Subject: fix adding preview-icon to clss attribute --- apps/files/templates/part.list.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index ab1b91167db..e3420ca14cb 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -25,7 +25,11 @@ $totalsize = 0; ?> data-mime="" data-size='' data-permissions=''> + +
    style="background-image:url()" @@ -34,13 +38,13 @@ $totalsize = 0; ?> $relativePath = substr($relativePath, strlen($_['sharingroot'])); ?> - style="background-image:url()" class="preview-icon" + style="background-image:url()" style="background-image:url()" - style="background-image:url()" class="preview-icon" + style="background-image:url()" style="background-image:url()" -- cgit v1.2.3 From cba0f696226d344e5caf25631eefb92213c8b6c2 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 20:41:20 +0200 Subject: increase row height to 50px, properly position everything, checkboxes, actions etc --- apps/files/css/files.css | 143 +++++++++++++++++++++++++++++-------- apps/files/js/filelist.js | 2 +- apps/files/templates/index.php | 25 ++++--- apps/files/templates/part.list.php | 5 +- core/css/styles.css | 2 +- 5 files changed, 132 insertions(+), 45 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index c66484db536..de7be0a6a22 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -64,7 +64,7 @@ #filestable { position: relative; top:37px; width:100%; } tbody tr { background-color: #fff; - height: 44px; + height: 50px; } tbody tr:hover, tbody tr:active { background-color: rgb(240,240,240); @@ -79,8 +79,9 @@ tr:hover span.extension { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Op table tr.mouseOver td { background-color:#eee; } table th { height:2em; padding:0 .5em; color:#999; } table th .name { - float: left; - margin-left: 17px; + position: absolute; + left: 55px; + top: 15px; } table th, table td { border-bottom:1px solid #ddd; text-align:left; font-weight:normal; } table td { @@ -89,17 +90,33 @@ table td { 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#headerName { + position: relative; + width: 100em; /* not really sure why this works better than 100% … table styling */ + padding: 0; +} +#headerName-container { + position: relative; + height: 50px; +} +table th#headerSize, table td.filesize { + min-width: 3em; + padding: 0 1em; + text-align: right; +} table th#headerDate, table td.date { + -moz-box-sizing: border-box; + box-sizing: border-box; position: relative; min-width: 11em; - padding:0 .1em 0 1em; - text-align:left; + display: block; + height: 51px; } /* Multiselect bar */ -#filestable.multiselect { top:63px; } +#filestable.multiselect { + top: 88px; +} table.multiselect thead { position:fixed; top:82px; z-index:1; -moz-box-sizing: border-box; box-sizing: border-box; left: 0; padding-left: 64px; width:100%; } table.multiselect thead th { background-color: rgba(210,210,210,.7); @@ -107,27 +124,41 @@ table.multiselect thead th { font-weight: bold; border-bottom: 0; } -table.multiselect #headerName { width: 100%; } +table.multiselect #headerName { + position: relative; + width: 100%; +} table td.selection, table th.selection, table td.fileaction { width:2em; text-align:center; } table td.filename a.name { + position:relative; /* Firefox needs to explicitly have this default set … */ + -moz-box-sizing: border-box; box-sizing: border-box; display: block; - height: 44px; + height: 50px; vertical-align: middle; - margin-left: 50px; + padding: 0; } 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 .3em; } table td.filename .nametext, .uploadtext, .modified { float:left; padding:.3em 0; } -.modified { + +#modified { position: absolute; - top: 10px; + top: 15px; +} +.modified { + position: relative; + top: 11px; + left: 5px; } + /* TODO fix usability bug (accidental file/folder selection) */ table td.filename .nametext { position: absolute; - top: 10px; + top: 16px; + left: 55px; + padding: 0; overflow: hidden; text-overflow: ellipsis; max-width: 800px; @@ -135,28 +166,58 @@ table td.filename .nametext { table td.filename .uploadtext { font-weight:normal; margin-left:.5em; } table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; } + /* File checkboxes */ -#fileList tr td.filename>input[type="checkbox"]:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter:alpha(opacity=0); opacity:0; float:left; margin:.7em 0 0 1em; /* bigger clickable area doesn’t work in FF width:2.8em; height:2.4em;*/ -webkit-transition:opacity 200ms; -moz-transition:opacity 200ms; -o-transition:opacity 200ms; transition:opacity 200ms; } -#fileList tr td.filename>input[type="checkbox"]:hover:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)"; filter:alpha(opacity=80); opacity:.8; } -/* Always show checkbox when selected */ -#fileList tr td.filename>input[type="checkbox"]:checked:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; } -#fileList tr.selected td.filename>input[type="checkbox"]:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; } +#fileList tr td.filename>input[type="checkbox"]:first-child { + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; + filter: alpha(opacity=0); + opacity: 0; + float: left; + margin: 32px 0 0 32px; /* bigger clickable area doesn’t work in FF width:2.8em; height:2.4em;*/ +} +/* Show checkbox when hovering, checked, or selected */ +#fileList tr:hover td.filename>input[type="checkbox"]:first-child, +#fileList tr td.filename>input[type="checkbox"]:checked:first-child, +#fileList tr.selected td.filename>input[type="checkbox"]:first-child { + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; + filter: alpha(opacity=100); + opacity: 1; +} +/* Use label to have bigger clickable size for checkbox */ +#fileList tr td.filename>input[type="checkbox"] + label, +#select_all + label { + height: 50px; + position: absolute; + width: 50px; + z-index: 100; +} +#fileList tr td.filename>input[type="checkbox"] + label { + left: 0; +} +#select_all + label { + top: 0; +} +#select_all { + position: absolute; + top: 18px; + left: 18px; +} + #fileList tr td.filename { position:relative; width:100%; -webkit-transition:background-image 500ms; -moz-transition:background-image 500ms; -o-transition:background-image 500ms; transition:background-image 500ms; } -#select_all { float:left; margin:.3em 0.6em 0 .5em; } + #uploadsize-message,#delete-confirm { display:none; } /* File actions */ .fileactions { position: absolute; - top: 13px; + top: 16px; 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 */ background-color: rgba(240,240,240,0.898); box-shadow: -5px 0 7px rgba(240,240,240,0.898); @@ -166,19 +227,39 @@ 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: 16px 8px !important; -} + #fileList img.move2trash { display:inline; margin:-.5em 0; padding:1em .5em 1em .5em !important; float:right; } -a.action.delete { float:right; } +#fileList a.action.delete { + position: absolute; + right: 0; + top: 0; + margin: 0; + padding: 15px 14px 19px !important; +} a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; } -.selectedActions { display:none; float:right; } -.selectedActions a { display:inline; margin:-.5em 0; padding:.5em !important; } -.selectedActions a img { position:relative; top:.3em; } + +/* Actions for selected files */ +.selectedActions { + display: none; + position: absolute; + top: -1px; + right: 0; + padding: 15px 8px; +} +.selectedActions a { + display: inline; + padding: 17px 5px; +} +.selectedActions a img { + position:relative; + top:.3em; +} + #fileList a.action { + display: inline; + margin: -.5em 0; + padding: 18px 8px !important; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); opacity: 0; diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 138329940b4..3a6b118ec9c 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -17,7 +17,7 @@ var FileList={ "class": "filename", "style": 'background-image:url('+iconurl+')' }); - td.append(''); + td.append(''); var link_elem = $('').attr({ "class": "name", "href": linktarget diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 8598ead2404..714ff497f9d 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -63,17 +63,20 @@
    - - t( 'Name' )); ?> - - - - Download" /> - t('Download'))?> - - - +
    + + + t( 'Name' )); ?> + + + + Download" /> + t('Download'))?> + + + +
    t('Size')); ?> diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index ab1b91167db..93d1aaf9dca 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -47,7 +47,10 @@ $totalsize = 0; ?> > - + + + + diff --git a/core/css/styles.css b/core/css/styles.css index 0dd66fb5b7c..db7f01cfebd 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -142,7 +142,7 @@ a.disabled, a.disabled:hover, a.disabled:focus { .searchbox input[type="search"] { font-size:1.2em; padding:.2em .5em .2em 1.5em; background:#fff url('../img/actions/search.svg') no-repeat .5em center; border:0; -moz-border-radius:1em; -webkit-border-radius:1em; border-radius:1em; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; filter:alpha(opacity=70);opacity:.7; -webkit-transition:opacity 300ms; -moz-transition:opacity 300ms; -o-transition:opacity 300ms; transition:opacity 300ms; margin-top:10px; float:right; } input[type="submit"].enabled { background:#66f866; border:1px solid #5e5; -moz-box-shadow:0 1px 1px #f8f8f8, 0 1px 1px #cfc inset; -webkit-box-shadow:0 1px 1px #f8f8f8, 0 1px 1px #cfc inset; box-shadow:0 1px 1px #f8f8f8, 0 1px 1px #cfc inset; } -#select_all{ margin-top:.4em !important;} + /* CONTENT ------------------------------------------------------------------ */ #controls { -- cgit v1.2.3 From e5761d90ef223a04205ad93eea7706439ef0b60e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 20:49:47 +0200 Subject: fix deleting old previews after file changed --- lib/preview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 92cc87c5897..293accb188a 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -592,7 +592,7 @@ class Preview { if(substr($path, 0, 1) === '/') { $path = substr($path, 1); } - $preview = new Preview(\OC_User::getUser(), 'files/', $path, 0, 0, false, true); + $preview = new Preview(\OC_User::getUser(), 'files/', $path); $preview->deleteAllPreviews(); } -- cgit v1.2.3 From 623f9ec817490c93e8abf0825bab372acf08c29e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 21:20:03 +0200 Subject: don't generate previews of empty txt files --- lib/preview/txt.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/preview/txt.php b/lib/preview/txt.php index 89927fd580a..c06f445e827 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -17,6 +17,10 @@ class TXT extends Provider { $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); + if(trim($content) === '') { + return false; + } + $lines = preg_split("/\r\n|\n|\r/", $content); $fontSize = 5; //5px -- cgit v1.2.3 From b2f666c98f462da43168ae93a39c8dc886ba847e Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 14 Aug 2013 21:26:06 +0200 Subject: fix file summary position --- apps/files/css/files.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index de7be0a6a22..4f2f10da4dd 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -281,9 +281,8 @@ a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; } .summary { opacity: .5; } - .summary .info { - margin-left: 3em; + margin-left: 55px; } #scanning-message{ top:40%; left:40%; position:absolute; display:none; } -- cgit v1.2.3 From 2fd5178a0049abc474da551dbdb2ac71fc49dec1 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Thu, 15 Aug 2013 12:50:26 +0200 Subject: adjust New file dialog for new styles --- apps/files/css/files.css | 7 +++++-- apps/files/js/file-upload.js | 2 +- core/img/filetypes/web.png | Bin 2284 -> 2254 bytes core/img/filetypes/web.svg | 24 +++++++++++------------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 4f2f10da4dd..20eb5fd083f 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -22,7 +22,10 @@ #new>ul>li { height:36px; margin:.3em; padding-left:3em; padding-bottom:0.1em; background-repeat:no-repeat; cursor:pointer; } #new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;} -#new>ul>li>form>input { padding:0.3em; margin:-0.3em; } +#new>ul>li>form>input { + padding: 5px; + margin: 2px 0; +} #trash { margin: 0 1em; z-index:1010; float: right; } @@ -189,7 +192,7 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; } height: 50px; position: absolute; width: 50px; - z-index: 100; + z-index: 5; } #fileList tr td.filename>input[type="checkbox"] + label { left: 0; diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 942a07dfccc..02e940aa3c4 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -221,7 +221,7 @@ $(document).ready(function() { $(this).data('text',text); $(this).children('p').remove(); var form=$('
    '); - var input=$(''); + var input=$(''); form.append(input); $(this).append(form); input.focus(); diff --git a/core/img/filetypes/web.png b/core/img/filetypes/web.png index 0868ca52747..c3802312645 100644 Binary files a/core/img/filetypes/web.png and b/core/img/filetypes/web.png differ diff --git a/core/img/filetypes/web.svg b/core/img/filetypes/web.svg index 6ea49d59fb4..67775a2233b 100644 --- a/core/img/filetypes/web.svg +++ b/core/img/filetypes/web.svg @@ -14,34 +14,32 @@ - + - + - + - + - - - - - - - - - + + + + + + + -- cgit v1.2.3 From 7fe9320ffe60d9f8346f424a235bbc51c99f9484 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 15 Aug 2013 13:20:31 +0200 Subject: improve unknown backend --- lib/helper.php | 33 ++++++++++++++++++++++++++++++++- lib/preview/unknown.php | 22 +++------------------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index b74e4c4512e..6552bcce703 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -188,7 +188,38 @@ class OC_Helper { * Returns the path to the image of this file type. */ public static function mimetypeIcon($mimetype) { - $alias = array('application/xml' => 'code/xml'); + $alias = array( + 'application/xml' => 'code/xml', + 'application/msword' => 'x-office/document', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'x-office/document', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'x-office/document', + 'application/vnd.ms-word.document.macroEnabled.12' => 'x-office/document', + 'application/vnd.ms-word.template.macroEnabled.12' => 'x-office/document', + 'application/vnd.oasis.opendocument.text' => 'x-office/document', + 'application/vnd.oasis.opendocument.text-template' => 'x-office/document', + 'application/vnd.oasis.opendocument.text-web' => 'x-office/document', + 'application/vnd.oasis.opendocument.text-master' => 'x-office/document', + 'application/vnd.ms-powerpoint' => 'x-office/presentation', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation', + 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation', + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation', + 'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation', + 'application/vnd.ms-excel' => 'x-office/spreadsheet', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.sheet.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.template.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.addin.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet', + 'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet', + ); + if (isset($alias[$mimetype])) { $mimetype = $alias[$mimetype]; } diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index ba13ca35d66..9e6cd68d401 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -16,27 +16,11 @@ class Unknown extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $mimetype = $fileview->getMimeType($path); - if(substr_count($mimetype, '/')) { - list($type, $subtype) = explode('/', $mimetype); - } - $iconsRoot = \OC::$SERVERROOT . '/core/img/filetypes/'; + $path = \OC_Helper::mimetypeIcon($mimetype); + $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT)); - if(isset($type)){ - $icons = array($mimetype, $type, 'text'); - }else{ - $icons = array($mimetype, 'text'); - } - foreach($icons as $icon) { - $icon = str_replace('/', '-', $icon); - - $iconPath = $iconsRoot . $icon . '.png'; - - if(file_exists($iconPath)) { - return new \OC_Image($iconPath); - } - } - return false; + return new \OC_Image($path); } } -- cgit v1.2.3 From 825d8610d0abbf1063df3019533253908142ae43 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 15 Aug 2013 13:21:35 +0200 Subject: fix svg and cache transparency issue --- lib/image.php | 3 +++ lib/preview.php | 2 ++ lib/preview/svg.php | 8 +++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/image.php b/lib/image.php index 4bc38e20e56..53ffb24d18c 100644 --- a/lib/image.php +++ b/lib/image.php @@ -496,6 +496,9 @@ class OC_Image { return false; } $this->resource = @imagecreatefromstring($str); + imagealphablending($this->resource, false); + imagesavealpha($this->resource, true); + if(!$this->resource) { OC_Log::write('core', 'OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG); return false; diff --git a/lib/preview.php b/lib/preview.php index 293accb188a..e7dd327d021 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -391,6 +391,8 @@ class Preview { continue; } + \OC_Log::write('core', 'Generating preview for "' . $file . '" with "' . get_class($provider) . '"', \OC_Log::DEBUG); + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileview); if(!($preview instanceof \OC_Image)) { diff --git a/lib/preview/svg.php b/lib/preview/svg.php index e939e526b1b..b49e51720fa 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -18,7 +18,7 @@ if (extension_loaded('imagick')) { public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { try{ $svg = new \Imagick(); - $svg->setResolution($maxX, $maxY); + $svg->setBackgroundColor(new \ImagickPixel('transparent')); $content = stream_get_contents($fileview->fopen($path, 'r')); if(substr($content, 0, 5) !== 'readImageBlob($content); - $svg->setImageFormat('jpg'); + $svg->setImageFormat('png32'); } catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } + //new image object - $image = new \OC_Image($svg); + $image = new \OC_Image(); + $image->loadFromData($svg); //check if image object is valid return $image->valid() ? $image : false; } -- cgit v1.2.3 From 7a11911aead74e07ba2917be27e343ff93ca931f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 15 Aug 2013 13:25:45 +0200 Subject: add comment to make @jancborchardt happy --- lib/preview/txt.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/preview/txt.php b/lib/preview/txt.php index c06f445e827..a487330691e 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -17,6 +17,7 @@ class TXT extends Provider { $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); + //don't create previews of empty text files if(trim($content) === '') { return false; } -- cgit v1.2.3 From 4574c5cf5cbb9efc4f787b264842573540f88439 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 15 Aug 2013 16:13:01 +0200 Subject: check if ->resource is a resource --- lib/image.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/image.php b/lib/image.php index 53ffb24d18c..840b744ad72 100644 --- a/lib/image.php +++ b/lib/image.php @@ -496,8 +496,10 @@ class OC_Image { return false; } $this->resource = @imagecreatefromstring($str); - imagealphablending($this->resource, false); - imagesavealpha($this->resource, true); + if(is_resource($this->resource)) { + imagealphablending($this->resource, false); + imagesavealpha($this->resource, true); + } if(!$this->resource) { OC_Log::write('core', 'OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG); -- cgit v1.2.3 From 61370a765581851664bbe1924e2d0e2e86083326 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Thu, 15 Aug 2013 18:58:23 +0200 Subject: add folder icons for shared, public and external --- core/img/filetypes/folder-external.png | Bin 0 -> 1012 bytes core/img/filetypes/folder-external.svg | 68 +++++++++++++++++++++++++++++++++ core/img/filetypes/folder-public.png | Bin 0 -> 1397 bytes core/img/filetypes/folder-public.svg | 68 +++++++++++++++++++++++++++++++++ core/img/filetypes/folder-shared.png | Bin 0 -> 1229 bytes core/img/filetypes/folder-shared.svg | 68 +++++++++++++++++++++++++++++++++ 6 files changed, 204 insertions(+) create mode 100644 core/img/filetypes/folder-external.png create mode 100644 core/img/filetypes/folder-external.svg create mode 100644 core/img/filetypes/folder-public.png create mode 100644 core/img/filetypes/folder-public.svg create mode 100644 core/img/filetypes/folder-shared.png create mode 100644 core/img/filetypes/folder-shared.svg diff --git a/core/img/filetypes/folder-external.png b/core/img/filetypes/folder-external.png new file mode 100644 index 00000000000..997f07b2bac Binary files /dev/null and b/core/img/filetypes/folder-external.png differ diff --git a/core/img/filetypes/folder-external.svg b/core/img/filetypes/folder-external.svg new file mode 100644 index 00000000000..89ec9a8ecaa --- /dev/null +++ b/core/img/filetypes/folder-external.svg @@ -0,0 +1,68 @@ + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/folder-public.png b/core/img/filetypes/folder-public.png new file mode 100644 index 00000000000..c716607e26e Binary files /dev/null and b/core/img/filetypes/folder-public.png differ diff --git a/core/img/filetypes/folder-public.svg b/core/img/filetypes/folder-public.svg new file mode 100644 index 00000000000..a949833f95a --- /dev/null +++ b/core/img/filetypes/folder-public.svg @@ -0,0 +1,68 @@ + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/img/filetypes/folder-shared.png b/core/img/filetypes/folder-shared.png new file mode 100644 index 00000000000..e547a242062 Binary files /dev/null and b/core/img/filetypes/folder-shared.png differ diff --git a/core/img/filetypes/folder-shared.svg b/core/img/filetypes/folder-shared.svg new file mode 100644 index 00000000000..56aa9634d27 --- /dev/null +++ b/core/img/filetypes/folder-shared.svg @@ -0,0 +1,68 @@ + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From e7c06935702dc794f7178cdc47ce947404752ec0 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Thu, 15 Aug 2013 19:40:39 +0200 Subject: checkstyle double quotes in HTML --- apps/files/templates/part.list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index bd1fe341f8d..1ed8e0cf91b 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -23,8 +23,8 @@ $totalsize = 0; ?> data-file="" data-type="" data-mime="" - data-size='' - data-permissions=''> + data-size="" + data-permissions="">
    -- cgit v1.2.3 From 164502477d8eac293ea002d39378be846bcc733c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 16 Aug 2013 17:24:45 +0200 Subject: use jQuery.get instead of jQuery.ajax --- apps/files/js/files.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 3178ff65af8..fd18cf21ee8 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -821,12 +821,8 @@ function lazyLoadPreview(path, mime, ready) { var x = $('#filestable').data('preview-x'); var y = $('#filestable').data('preview-y'); var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y}); - $.ajax({ - url: previewURL, - type: 'GET', - success: function() { - ready(previewURL); - } + $.get(previewURL, function() { + ready(previewURL); }); } -- cgit v1.2.3 From 7e4dcd268f6cb6618600718a51c4d882e9027829 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Sat, 17 Aug 2013 10:46:03 +0200 Subject: vertically center rename input box --- apps/files/css/files.css | 10 ++++++++-- apps/files/js/filelist.js | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 20eb5fd083f..be42a0056d8 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -142,7 +142,13 @@ table td.filename a.name { padding: 0; } 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 input.filename { + width: 80%; + font-size: 14px; + margin-top: 8px; + margin-left: 2px; + 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 .3em; } table td.filename .nametext, .uploadtext, .modified { float:left; padding:.3em 0; } @@ -176,7 +182,7 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; } filter: alpha(opacity=0); opacity: 0; float: left; - margin: 32px 0 0 32px; /* bigger clickable area doesn’t work in FF width:2.8em; height:2.4em;*/ + margin: 32px 0 4px 32px; /* bigger clickable area doesn’t work in FF width:2.8em; height:2.4em;*/ } /* Show checkbox when hovering, checked, or selected */ #fileList tr:hover td.filename>input[type="checkbox"]:first-child, diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 536becad49a..10a297ddadb 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -199,7 +199,7 @@ var FileList={ tr=$('tr').filterAttr('data-file',name); tr.data('renaming',true); td=tr.children('td.filename'); - input=$('').val(name); + input=$('').val(name); form=$('
    '); form.append(input); td.children('a.name').hide(); -- cgit v1.2.3 From 48f0c54261bfa2d2f20864b0d41db8f1df6f1777 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 19 Aug 2013 12:16:55 +0200 Subject: style fixes for preview lib --- apps/files/templates/part.list.php | 3 +- config/config.sample.php | 2 + core/ajax/preview.php | 9 +-- lib/preview.php | 76 ++++++++++---------- lib/preview/image.php | 36 ++++++++++ lib/preview/images.php | 36 ---------- lib/preview/libreoffice-cl.php | 131 ---------------------------------- lib/preview/msoffice.php | 142 ------------------------------------- lib/preview/office-cl.php | 134 ++++++++++++++++++++++++++++++++++ lib/preview/office-fallback.php | 142 +++++++++++++++++++++++++++++++++++++ lib/preview/office.php | 4 +- 11 files changed, 361 insertions(+), 354 deletions(-) create mode 100644 lib/preview/image.php delete mode 100644 lib/preview/images.php delete mode 100644 lib/preview/libreoffice-cl.php delete mode 100644 lib/preview/msoffice.php create mode 100644 lib/preview/office-cl.php create mode 100644 lib/preview/office-fallback.php diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 1ed8e0cf91b..899fb04e252 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -3,7 +3,8 @@ $totaldirs = 0; $totalsize = 0; ?> 6 + //strlen('files/') => 6 + $relativePath = substr($file['path'], 6); $totalsize += $file['size']; if ($file['type'] === 'dir') { $totaldirs++; diff --git a/config/config.sample.php b/config/config.sample.php index 86bc20b714e..5c40078c7d7 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -199,6 +199,8 @@ $CONFIG = array( 'preview_max_scale_factor' => 10, /* custom path for libreoffice / openoffice binary */ 'preview_libreoffice_path' => '/usr/bin/libreoffice', +/* cl parameters for libreoffice / openoffice */ +'preview_office_cl_parameters' => '', // date format to be used while writing to the owncloud logfile 'logdateformat' => 'F d, Y H:i:s', ); diff --git a/core/ajax/preview.php b/core/ajax/preview.php index 486155831d7..af0f0493f4c 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -13,13 +13,15 @@ $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; if($file === '') { - \OC_Response::setStatus(400); //400 Bad Request + //400 Bad Request + \OC_Response::setStatus(400); \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); exit; } if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request + //400 Bad Request + \OC_Response::setStatus(400); \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); exit; } @@ -34,6 +36,5 @@ try{ $preview->show(); }catch(\Exception $e) { \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - exit; + \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); } \ No newline at end of file diff --git a/lib/preview.php b/lib/preview.php index e7dd327d021..9fed7f1b58f 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -13,14 +13,14 @@ */ namespace OC; -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/txt.php'); -require_once('preview/unknown.php'); -require_once('preview/office.php'); +require_once 'preview/image.php'; +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'; +require_once 'preview/office.php'; class Preview { //the thumbnail folder @@ -32,8 +32,8 @@ class Preview { private $configMaxY; //fileview object - private $fileview = null; - private $userview = null; + private $fileView = null; + private $userView = null; //vars private $file; @@ -76,8 +76,8 @@ class Preview { if($user === ''){ $user = \OC_User::getUser(); } - $this->fileview = new \OC\Files\View('/' . $user . '/' . $root); - $this->userview = new \OC\Files\View('/' . $user); + $this->fileView = new \OC\Files\View('/' . $user . '/' . $root); + $this->userView = new \OC\Files\View('/' . $user); $this->preview = null; @@ -226,12 +226,12 @@ class Preview { public function isFileValid() { $file = $this->getFile(); if($file === '') { - \OC_Log::write('core', 'No filename passed', \OC_Log::ERROR); + \OC_Log::write('core', 'No filename passed', \OC_Log::DEBUG); return false; } - if(!$this->fileview->file_exists($file)) { - \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::ERROR); + if(!$this->fileView->file_exists($file)) { + \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::DEBUG); return false; } @@ -245,12 +245,12 @@ class Preview { public function deletePreview() { $file = $this->getFile(); - $fileInfo = $this->fileview->getFileInfo($file); + $fileInfo = $this->fileView->getFileInfo($file); $fileId = $fileInfo['fileid']; $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; - $this->userview->unlink($previewPath); - return !$this->userview->file_exists($previewPath); + $this->userView->unlink($previewPath); + return !$this->userView->file_exists($previewPath); } /** @@ -260,13 +260,13 @@ class Preview { public function deleteAllPreviews() { $file = $this->getFile(); - $fileInfo = $this->fileview->getFileInfo($file); + $fileInfo = $this->fileView->getFileInfo($file); $fileId = $fileInfo['fileid']; $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; - $this->userview->deleteAll($previewPath); - $this->userview->rmdir($previewPath); - return !$this->userview->is_dir($previewPath); + $this->userView->deleteAll($previewPath); + $this->userView->rmdir($previewPath); + return !$this->userView->is_dir($previewPath); } /** @@ -280,9 +280,9 @@ class Preview { $maxX = $this->getMaxX(); $maxY = $this->getMaxY(); $scalingUp = $this->getScalingUp(); - $maxscalefactor = $this->getMaxScaleFactor(); + $maxScaleFactor = $this->getMaxScaleFactor(); - $fileInfo = $this->fileview->getFileInfo($file); + $fileInfo = $this->fileView->getFileInfo($file); $fileId = $fileInfo['fileid']; if(is_null($fileId)) { @@ -290,12 +290,12 @@ class Preview { } $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; - if(!$this->userview->is_dir($previewPath)) { + if(!$this->userView->is_dir($previewPath)) { return false; } //does a preview with the wanted height and width already exist? - if($this->userview->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) { + if($this->userView->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) { return $previewPath . $maxX . '-' . $maxY . '.png'; } @@ -304,7 +304,7 @@ class Preview { //array for usable cached thumbnails $possibleThumbnails = array(); - $allThumbnails = $this->userview->getDirectoryContent($previewPath); + $allThumbnails = $this->userView->getDirectoryContent($previewPath); foreach($allThumbnails as $thumbnail) { $name = rtrim($thumbnail['name'], '.png'); $size = explode('-', $name); @@ -319,7 +319,7 @@ class Preview { if($x < $maxX || $y < $maxY) { if($scalingUp) { $scalefactor = $maxX / $x; - if($scalefactor > $maxscalefactor) { + if($scalefactor > $maxScaleFactor) { continue; } }else{ @@ -371,19 +371,19 @@ class Preview { $maxY = $this->getMaxY(); $scalingUp = $this->getScalingUp(); - $fileInfo = $this->fileview->getFileInfo($file); + $fileInfo = $this->fileView->getFileInfo($file); $fileId = $fileInfo['fileid']; $cached = $this->isCached(); if($cached) { - $image = new \OC_Image($this->userview->file_get_contents($cached, 'r')); + $image = new \OC_Image($this->userView->file_get_contents($cached, 'r')); $this->preview = $image->valid() ? $image : null; $this->resizeAndCrop(); } if(is_null($this->preview)) { - $mimetype = $this->fileview->getMimeType($file); + $mimetype = $this->fileView->getMimeType($file); $preview = null; foreach(self::$providers as $supportedMimetype => $provider) { @@ -393,7 +393,7 @@ class Preview { \OC_Log::write('core', 'Generating preview for "' . $file . '" with "' . get_class($provider) . '"', \OC_Log::DEBUG); - $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileview); + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileView); if(!($preview instanceof \OC_Image)) { continue; @@ -405,15 +405,15 @@ class Preview { $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; $cachePath = $previewPath . $maxX . '-' . $maxY . '.png'; - if($this->userview->is_dir($this->getThumbnailsFolder() . '/') === false) { - $this->userview->mkdir($this->getThumbnailsFolder() . '/'); + if($this->userView->is_dir($this->getThumbnailsFolder() . '/') === false) { + $this->userView->mkdir($this->getThumbnailsFolder() . '/'); } - if($this->userview->is_dir($previewPath) === false) { - $this->userview->mkdir($previewPath); + if($this->userView->is_dir($previewPath) === false) { + $this->userView->mkdir($previewPath); } - $this->userview->file_put_contents($cachePath, $preview->data()); + $this->userView->file_put_contents($cachePath, $preview->data()); break; } @@ -470,7 +470,7 @@ class Preview { if($x === $realx && $y === $realy) { $this->preview = $image; - return true; + return; } $factorX = $x / $realx; diff --git a/lib/preview/image.php b/lib/preview/image.php new file mode 100644 index 00000000000..9aec967282d --- /dev/null +++ b/lib/preview/image.php @@ -0,0 +1,36 @@ +getFileInfo($path); + if(!$fileInfo) { + return false; + } + + //check if file is encrypted + if($fileInfo['encrypted'] === true) { + $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r'))); + }else{ + $image = new \OC_Image(); + $image->loadFromFile($fileview->getLocalFile($path)); + } + + return $image->valid() ? $image : false; + } +} + +\OC\Preview::registerProvider('OC\Preview\Image'); \ No newline at end of file diff --git a/lib/preview/images.php b/lib/preview/images.php deleted file mode 100644 index 9aec967282d..00000000000 --- a/lib/preview/images.php +++ /dev/null @@ -1,36 +0,0 @@ -getFileInfo($path); - if(!$fileInfo) { - return false; - } - - //check if file is encrypted - if($fileInfo['encrypted'] === true) { - $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r'))); - }else{ - $image = new \OC_Image(); - $image->loadFromFile($fileview->getLocalFile($path)); - } - - return $image->valid() ? $image : false; - } -} - -\OC\Preview::registerProvider('OC\Preview\Image'); \ No newline at end of file diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php deleted file mode 100644 index 2f1d08499ef..00000000000 --- a/lib/preview/libreoffice-cl.php +++ /dev/null @@ -1,131 +0,0 @@ -initCmd(); - if(is_null($this->cmd)) { - return false; - } - - $absPath = $fileview->toTmpFile($path); - - $tmpDir = get_temp_dir(); - - $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); - - //create imagick object from pdf - try{ - $pdf = new \imagick($absPath . '.pdf' . '[0]'); - $pdf->setImageFormat('jpg'); - } catch (\Exception $e) { - unlink($absPath); - unlink($absPath . '.pdf'); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - return false; - } - - $image = new \OC_Image($pdf); - - unlink($absPath); - unlink($absPath . '.pdf'); - - return $image->valid() ? $image : false; - } - - private function initCmd() { - $cmd = ''; - - if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { - $cmd = \OC_Config::getValue('preview_libreoffice_path', null); - } - - $whichLibreOffice = shell_exec('which libreoffice'); - if($cmd === '' && !empty($whichLibreOffice)) { - $cmd = 'libreoffice'; - } - - $whichOpenOffice = shell_exec('which openoffice'); - if($cmd === '' && !empty($whichOpenOffice)) { - $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/msoffice.php b/lib/preview/msoffice.php deleted file mode 100644 index e69ab0ab8cb..00000000000 --- a/lib/preview/msoffice.php +++ /dev/null @@ -1,142 +0,0 @@ -toTmpFile($path); - - $transformdoc = new \TransformDoc(); - $transformdoc->setStrFile($tmpDoc); - $transformdoc->generatePDF($tmpDoc); - - $pdf = new \imagick($tmpDoc . '[0]'); - $pdf->setImageFormat('jpg'); - - unlink($tmpDoc); - - $image = new \OC_Image($pdf); - - return $image->valid() ? $image : false; - } - -} - -\OC\Preview::registerProvider('OC\Preview\DOCX'); - -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'); - - $absPath = $fileview->toTmpFile($path); - $tmpPath = \OC_Helper::tmpFile(); - - $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; - $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/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); - - $image = new \OC_Image($pdf); - - return $image->valid() ? $image : false; - } - -} - -class XLS extends MSOfficeExcel { - - public function getMimeType() { - return '/application\/vnd.ms-excel/'; - } - -} - -\OC\Preview::registerProvider('OC\Preview\XLS'); - -class XLSX extends MSOfficeExcel { - - public function getMimeType() { - return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/'; - } - -} - -\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() { - return null; - } - - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - return false; - } - -} - -class PPT extends MSOfficePowerPoint { - - public function getMimeType() { - return '/application\/vnd.ms-powerpoint/'; - } - -} - -\OC\Preview::registerProvider('OC\Preview\PPT'); - -class PPTX extends MSOfficePowerPoint { - - public function getMimeType() { - return '/application\/vnd.openxmlformats-officedocument.presentationml.presentation/'; - } - -} - -\OC\Preview::registerProvider('OC\Preview\PPTX'); -*/ \ No newline at end of file diff --git a/lib/preview/office-cl.php b/lib/preview/office-cl.php new file mode 100644 index 00000000000..112909d6523 --- /dev/null +++ b/lib/preview/office-cl.php @@ -0,0 +1,134 @@ +initCmd(); + if(is_null($this->cmd)) { + return false; + } + + $absPath = $fileview->toTmpFile($path); + + $tmpDir = get_temp_dir(); + + $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir '; + $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters); + + $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); + $export = 'export HOME=/' . $tmpDir; + + shell_exec($export . "\n" . $exec); + + //create imagick object from pdf + try{ + $pdf = new \imagick($absPath . '.pdf' . '[0]'); + $pdf->setImageFormat('jpg'); + } catch (\Exception $e) { + unlink($absPath); + unlink($absPath . '.pdf'); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; + } + + $image = new \OC_Image($pdf); + + unlink($absPath); + unlink($absPath . '.pdf'); + + return $image->valid() ? $image : false; + } + + private function initCmd() { + $cmd = ''; + + if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + $cmd = \OC_Config::getValue('preview_libreoffice_path', null); + } + + $whichLibreOffice = shell_exec('which libreoffice'); + if($cmd === '' && !empty($whichLibreOffice)) { + $cmd = 'libreoffice'; + } + + $whichOpenOffice = shell_exec('which openoffice'); + if($cmd === '' && !empty($whichOpenOffice)) { + $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-fallback.php b/lib/preview/office-fallback.php new file mode 100644 index 00000000000..e69ab0ab8cb --- /dev/null +++ b/lib/preview/office-fallback.php @@ -0,0 +1,142 @@ +toTmpFile($path); + + $transformdoc = new \TransformDoc(); + $transformdoc->setStrFile($tmpDoc); + $transformdoc->generatePDF($tmpDoc); + + $pdf = new \imagick($tmpDoc . '[0]'); + $pdf->setImageFormat('jpg'); + + unlink($tmpDoc); + + $image = new \OC_Image($pdf); + + return $image->valid() ? $image : false; + } + +} + +\OC\Preview::registerProvider('OC\Preview\DOCX'); + +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'); + + $absPath = $fileview->toTmpFile($path); + $tmpPath = \OC_Helper::tmpFile(); + + $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; + $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/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); + + $image = new \OC_Image($pdf); + + return $image->valid() ? $image : false; + } + +} + +class XLS extends MSOfficeExcel { + + public function getMimeType() { + return '/application\/vnd.ms-excel/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\XLS'); + +class XLSX extends MSOfficeExcel { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/'; + } + +} + +\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() { + return null; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + return false; + } + +} + +class PPT extends MSOfficePowerPoint { + + public function getMimeType() { + return '/application\/vnd.ms-powerpoint/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PPT'); + +class PPTX extends MSOfficePowerPoint { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.presentationml.presentation/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PPTX'); +*/ \ No newline at end of file diff --git a/lib/preview/office.php b/lib/preview/office.php index b93e1e57c8b..5287bbd6ac1 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -14,9 +14,9 @@ if (extension_loaded('imagick')) { $isOpenOfficeAvailable = !empty($whichOpenOffice); //let's see if there is libreoffice or openoffice on this machine if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) { - require_once('libreoffice-cl.php'); + require_once('office-cl.php'); }else{ //in case there isn't, use our fallback - require_once('msoffice.php'); + require_once('office-fallback.php'); } } \ No newline at end of file -- cgit v1.2.3 From d9e8ebabdcd99bade4201d6be82e1841d30c5d65 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 19 Aug 2013 13:24:07 +0200 Subject: outsource sharing and deleted files previews to apps --- apps/files_sharing/ajax/publicpreview.php | 85 ++++++++++++++++++++++++++++++ apps/files_sharing/appinfo/routes.php | 5 ++ apps/files_trashbin/ajax/preview.php | 42 +++++++++++++++ apps/files_trashbin/appinfo/routes.php | 5 ++ core/ajax/publicpreview.php | 86 ------------------------------- core/ajax/trashbinpreview.php | 43 ---------------- core/routes.php | 4 -- 7 files changed, 137 insertions(+), 133 deletions(-) create mode 100644 apps/files_sharing/ajax/publicpreview.php create mode 100644 apps/files_sharing/appinfo/routes.php create mode 100644 apps/files_trashbin/ajax/preview.php create mode 100644 apps/files_trashbin/appinfo/routes.php delete mode 100644 core/ajax/publicpreview.php delete mode 100644 core/ajax/trashbinpreview.php diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php new file mode 100644 index 00000000000..41a1c178a48 --- /dev/null +++ b/apps/files_sharing/ajax/publicpreview.php @@ -0,0 +1,85 @@ +setFile($sharedFile); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->show(); +} catch (\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); +} \ No newline at end of file diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php new file mode 100644 index 00000000000..02815b5eb42 --- /dev/null +++ b/apps/files_sharing/appinfo/routes.php @@ -0,0 +1,5 @@ +create('core_ajax_public_preview', '/publicpreview.png')->action( +function() { + require_once __DIR__ . '/../ajax/publicpreview.php'; +}); \ No newline at end of file diff --git a/apps/files_trashbin/ajax/preview.php b/apps/files_trashbin/ajax/preview.php new file mode 100644 index 00000000000..a0846b051c7 --- /dev/null +++ b/apps/files_trashbin/ajax/preview.php @@ -0,0 +1,42 @@ +setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->showPreview(); +}catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); +} \ No newline at end of file diff --git a/apps/files_trashbin/appinfo/routes.php b/apps/files_trashbin/appinfo/routes.php new file mode 100644 index 00000000000..b1c3f02741e --- /dev/null +++ b/apps/files_trashbin/appinfo/routes.php @@ -0,0 +1,5 @@ +create('core_ajax_trashbin_preview', '/preview.png')->action( +function() { + require_once __DIR__ . '/../ajax/preview.php'; +}); \ No newline at end of file diff --git a/core/ajax/publicpreview.php b/core/ajax/publicpreview.php deleted file mode 100644 index 83194d5349c..00000000000 --- a/core/ajax/publicpreview.php +++ /dev/null @@ -1,86 +0,0 @@ -setFile($sharedFile); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingUp); - - $preview->show(); -} catch (\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - exit; -} \ No newline at end of file diff --git a/core/ajax/trashbinpreview.php b/core/ajax/trashbinpreview.php deleted file mode 100644 index a916dcf229f..00000000000 --- a/core/ajax/trashbinpreview.php +++ /dev/null @@ -1,43 +0,0 @@ -setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingUp); - - $preview->showPreview(); -}catch(\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - exit; -} \ No newline at end of file diff --git a/core/routes.php b/core/routes.php index ce35be1d583..f0f8ce571e2 100644 --- a/core/routes.php +++ b/core/routes.php @@ -44,10 +44,6 @@ $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); $this->create('core_ajax_preview', '/core/preview.png') ->actionInclude('core/ajax/preview.php'); -$this->create('core_ajax_trashbin_preview', '/core/trashbinpreview.png') - ->actionInclude('core/ajax/trashbinpreview.php'); -$this->create('core_ajax_public_preview', '/core/publicpreview.png') - ->actionInclude('core/ajax/publicpreview.php'); OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; $this->create('core_lostpassword_index', '/lostpassword/') ->get() -- cgit v1.2.3 From 224b80f906c1b7cd6338854e58f228eff4ea871c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 21 Aug 2013 15:55:59 +0200 Subject: move isMimeSupported out of template files --- apps/files/index.php | 1 + apps/files/templates/part.list.php | 6 +++--- apps/files_sharing/public.php | 1 + apps/files_trashbin/index.php | 1 + apps/files_trashbin/templates/part.list.php | 8 ++++++-- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index c05c2a9384d..3007f56e024 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -74,6 +74,7 @@ foreach ($content as $i) { } } $i['directory'] = $dir; + $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($i['mimetype']); $files[] = $i; } diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 899fb04e252..c91dda4c77e 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -26,7 +26,7 @@ $totalsize = 0; ?> data-mime="" data-size="" data-permissions=""> - +
    - + style="background-image:url()" style="background-image:url()" - + style="background-image:url()" style="background-image:url()" diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index f050fecd7b5..ec6b4e815f8 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -172,6 +172,7 @@ if (isset($path)) { } else { $i['extension'] = ''; } + $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($i['mimetype']); } $i['directory'] = $getPath; $i['permissions'] = OCP\PERMISSION_READ; diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index 2dbaefe7a78..6ae238eb8eb 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -64,6 +64,7 @@ foreach ($result as $r) { $i['directory'] = ''; } $i['permissions'] = OCP\PERMISSION_READ; + $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($r['mime']); $files[] = $i; } diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 6c6d2162846..f7cc6b01bbb 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -21,12 +21,16 @@ data-timestamp='' data-dirlisting=0 > + + style="background-image:url()" - - style="background-image:url()" class="preview-icon" + + style="background-image:url()" style="background-image:url()" -- cgit v1.2.3 From 1dab0767502013b5e86e8e24e3b12a2a8939f7a8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 23 Aug 2013 23:05:44 +0200 Subject: make it possible to disable previews --- config/config.sample.php | 1 + lib/preview.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/config/config.sample.php b/config/config.sample.php index 5c40078c7d7..76de97818d5 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -191,6 +191,7 @@ $CONFIG = array( 'customclient_ios' => '', //https://itunes.apple.com/us/app/owncloud/id543672169?mt=8 // PREVIEW +'disable_previews' => false, /* 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 */ diff --git a/lib/preview.php b/lib/preview.php index 9fed7f1b58f..0497ec95bc5 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -568,6 +568,12 @@ class Preview { * @return void */ private static function initProviders() { + if(\OC_Config::getValue('disable_previews', false)) { + $provider = new Preview\Unknown(); + self::$providers = array($provider); + return; + } + if(count(self::$providers)>0) { return; } @@ -599,6 +605,10 @@ class Preview { } public static function isMimeSupported($mimetype) { + if(\OC_Config::getValue('disable_previews', false)) { + return false; + } + //check if there are preview backends if(empty(self::$providers)) { self::initProviders(); -- cgit v1.2.3 From 13e34649bfb1a7d15833c209d629e3540d3366ef Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 23 Aug 2013 23:19:21 +0200 Subject: move path generation for previews to dedicated function --- apps/files/js/filelist.js | 2 +- apps/files/js/files.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 41245c00ba6..e3e985af38b 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -185,7 +185,7 @@ var FileList={ if (id != null) { tr.attr('data-id', id); } - var path = $('#dir').val()+'/'+name; + var path = getPathForPreview(name); lazyLoadPreview(path, mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index f88ecd961b1..79fa01aa0aa 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -382,7 +382,7 @@ $(document).ready(function() { tr.attr('data-size',result.data.size); tr.attr('data-id', result.data.id); tr.find('.filesize').text(humanFileSize(result.data.size)); - var path = $('#dir').val() + '/' + name; + var path = getPathForPreview(name); lazyLoadPreview(path, result.data.mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); @@ -654,7 +654,7 @@ var createDragShadow = function(event){ if (elem.type === 'dir') { newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { - var path = $('#dir').val()+'/'+elem.name; + var path = getPathForPreview(elem.name); lazyLoadPreview(path, elem.mime, function(previewpath){ newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); @@ -832,6 +832,11 @@ function getMimeIcon(mime, ready){ } getMimeIcon.cache={}; +function getPathForPreview(name) { + var path = $('#dir').val() + '/' + name; + return path; +} + function lazyLoadPreview(path, mime, ready) { getMimeIcon(mime,ready); var x = $('#filestable').data('preview-x'); -- cgit v1.2.3 From 58c727a4955b9ab60fa3c31fe902b673e883d181 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 23 Aug 2013 23:27:36 +0200 Subject: fix return value of method --- lib/preview.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/preview.php b/lib/preview.php index 0497ec95bc5..a8a8580e229 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -444,7 +444,8 @@ class Preview { * @return void */ public function show() { - return $this->showPreview(); + $this->showPreview(); + return; } /** -- cgit v1.2.3 From 46cbd7cd3b37e073ebb497f34d54ab67e4761969 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 26 Aug 2013 12:16:51 +0200 Subject: fix preview issue when uploading a file with parentheses --- apps/files/js/files.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 79fa01aa0aa..a890da843bb 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -843,7 +843,9 @@ function lazyLoadPreview(path, mime, ready) { var y = $('#filestable').data('preview-y'); var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y}); $.get(previewURL, function() { - ready(previewURL); + previewURL = previewURL.replace('(','%28'); + previewURL = previewURL.replace(')','%29'); + ready(previewURL + '&reload=true'); }); } -- cgit v1.2.3 From d538a566acac35eab811b2bfa16596fb8534db0f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 26 Aug 2013 14:36:18 +0200 Subject: fix background size in filelist.js --- apps/files/js/filelist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index e3e985af38b..7a48453488a 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -15,7 +15,7 @@ var FileList={ // filename td td = $('