save current work state

This commit is contained in:
Georg Ehrke 2013-04-25 12:51:44 +02:00
parent f02aca3f6e
commit 8c1925425b
7 changed files with 197 additions and 3 deletions

View File

@ -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);
}
}

71
lib/preview/images.php Normal file
View File

@ -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');

42
lib/preview/movies.php Normal file
View File

@ -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');
}

1
lib/preview/mp3.php Normal file
View File

@ -0,0 +1 @@
///audio\/mpeg/

0
lib/preview/pdf.php Normal file
View File

20
lib/preview/provider.php Normal file
View File

@ -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);
}

34
lib/preview/unknown.php Normal file
View File

@ -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');