diff --git a/lib/preview.php b/lib/preview.php index c70476332123c1d3f7aaa19cbe229bbd06917c93..de79b4240778974d90c88ca9b3041ee6316b5046 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 0000000000000000000000000000000000000000..6b6e8e3599ffb038b275996bbc5755767f8c4e96 --- /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 0000000000000000000000000000000000000000..afa27c0b14359f0d6b4825acd24a809e19cf6c4f --- /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 0000000000000000000000000000000000000000..645e6fa6232cd631c32a4ac677f2697f8688a053 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lib/preview/provider.php b/lib/preview/provider.php new file mode 100644 index 0000000000000000000000000000000000000000..c45edbba44d97d4e0d0611d4ff7bde421085c1fd --- /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 0000000000000000000000000000000000000000..1cd270db6870e59731157f0c4078b6328176e40a --- /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