diff options
author | Georg Ehrke <georg@ownCloud.com> | 2013-04-25 12:51:44 +0200 |
---|---|---|
committer | Georg Ehrke <georg@ownCloud.com> | 2013-04-25 12:51:44 +0200 |
commit | 8c1925425b26d9b2889632c724ec455ceeed4dd4 (patch) | |
tree | 5755e4c45caee37bc06360dd769ae8a7933f2551 /lib | |
parent | f02aca3f6ee295485d5bb9bc99b85b5573716f17 (diff) | |
download | nextcloud-server-8c1925425b26d9b2889632c724ec455ceeed4dd4.tar.gz nextcloud-server-8c1925425b26d9b2889632c724ec455ceeed4dd4.zip |
save current work state
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/preview.php | 32 | ||||
-rw-r--r-- | lib/preview/images.php | 71 | ||||
-rw-r--r-- | lib/preview/movies.php | 42 | ||||
-rw-r--r-- | lib/preview/mp3.php | 1 | ||||
-rw-r--r-- | lib/preview/pdf.php | 0 | ||||
-rw-r--r-- | lib/preview/provider.php | 20 | ||||
-rw-r--r-- | lib/preview/unknown.php | 34 |
7 files changed, 197 insertions, 3 deletions
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 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyrigjt (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. + */ +class OC_Preview_Image extends OC_Preview_Provider{ + + public function getMimeType(){ + 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 + $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 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyrigjt (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. + */ +if(!is_null(shell_exec('ffmpeg'))){ + + class OC_Preview_Movie extends OC_Preview_Provider{ + + public function getMimeType(){ + return '/video\/.*/'; + } + + 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); + } + + } + + 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 --- /dev/null +++ b/lib/preview/pdf.php 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 @@ +<?php +/** + * provides search functionalty + */ +abstract class OC_Preview_Provider{ + private $options; + + public function __construct($options) { + $this->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 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyrigjt (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. + */ +class OC_Preview_Unknown extends OC_Preview_Provider{ + + public function getMimeType(){ + return '/.*/'; + } + + 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); + } + +} + +OC_Preview::registerProvider('OC_Preview_Unknown');
\ No newline at end of file |