connect preview lib to filesystem hooks
This commit is contained in:
parent
a03787bc42
commit
eebc15dce0
|
@ -474,6 +474,7 @@ class OC {
|
||||||
|
|
||||||
self::registerCacheHooks();
|
self::registerCacheHooks();
|
||||||
self::registerFilesystemHooks();
|
self::registerFilesystemHooks();
|
||||||
|
self::registerPreviewHooks();
|
||||||
self::registerShareHooks();
|
self::registerShareHooks();
|
||||||
|
|
||||||
//make sure temporary files are cleaned up
|
//make sure temporary files are cleaned up
|
||||||
|
@ -539,6 +540,14 @@ class OC {
|
||||||
OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
|
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
|
* register hooks for sharing
|
||||||
*/
|
*/
|
||||||
|
|
106
lib/preview.php
106
lib/preview.php
|
@ -55,7 +55,7 @@ class OC_Preview {
|
||||||
* false if thumbnail does not exist
|
* false if thumbnail does not exist
|
||||||
* path to thumbnail if thumbnail exists
|
* 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
|
//set config
|
||||||
$this->max_x = OC_Config::getValue('preview_max_x', null);
|
$this->max_x = OC_Config::getValue('preview_max_x', null);
|
||||||
$this->max_y = OC_Config::getValue('preview_max_y', 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->fileview = new \OC\Files\View('/' . $user . '/' . $root);
|
||||||
$this->userview = new \OC\Files\View('/' . $user);
|
$this->userview = new \OC\Files\View('/' . $user);
|
||||||
|
|
||||||
if(!is_null($this->max_x)){
|
if($force !== true){
|
||||||
if($this->maxX > $this->max_x){
|
if(!is_null($this->max_x)){
|
||||||
OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, OC_Log::DEBUG);
|
if($this->maxX > $this->max_x){
|
||||||
$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(!is_null($this->max_y)){
|
if($this->maxY > $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;
|
||||||
$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(){
|
public function deletePreview(){
|
||||||
$fileinfo = $this->fileview->getFileInfo($this->file);
|
$fileinfo = $this->fileview->getFileInfo($this->file);
|
||||||
$fileid = $fileinfo['fileid'];
|
$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
|
* @brief deletes all previews of a file
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function deleteAllPrevies(){
|
public function deleteAllPreviews(){
|
||||||
$fileinfo = $this->fileview->getFileInfo($this->file);
|
$fileinfo = $this->fileview->getFileInfo($this->file);
|
||||||
$fileid = $fileinfo['fileid'];
|
$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;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue