From ac6a3133eca86b853da838ae310534b76e9fb662 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 30 Jul 2013 12:29:12 +0200 Subject: style fixes --- core/ajax/preview.php | 42 ++++++++++++++++++++ core/ajax/publicpreview.php | 92 +++++++++++++++++++++++++++++++++++++++++++ core/ajax/trashbinpreview.php | 46 ++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 core/ajax/preview.php create mode 100644 core/ajax/publicpreview.php create mode 100644 core/ajax/trashbinpreview.php (limited to 'core/ajax') 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 -- 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(-) (limited to 'core/ajax') 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 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(-) (limited to 'core/ajax') 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 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 (limited to 'core/ajax') 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 (limited to 'core/ajax') 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 22e1f73d5e46f4c3d32e250ce9eb3c112875706e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 21 Aug 2013 13:15:31 +0200 Subject: Use Group methods for searching, fixes #4201 --- core/ajax/share.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'core/ajax') diff --git a/core/ajax/share.php b/core/ajax/share.php index d3c6a8456a6..648f0a71bd4 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -181,10 +181,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo // } // } // } + $groups = OC_Group::getGroups($_GET['search']); if ($sharePolicy == 'groups_only') { - $groups = OC_Group::getUserGroups(OC_User::getUser()); - } else { - $groups = OC_Group::getGroups(); + $usergroups = OC_Group::getUserGroups(OC_User::getUser()); + $groups = array_intersect($groups, $usergroups); } $count = 0; $users = array(); @@ -219,11 +219,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo foreach ($groups as $group) { if ($count < 15) { - if (stripos($group, $_GET['search']) !== false - && (!isset($_GET['itemShares']) + if (!isset($_GET['itemShares']) || !isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) - || !in_array($group, $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]))) { + || !in_array($group, $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])) { $shareWith[] = array( 'label' => $group.' ('.$l->t('group').')', 'value' => array( -- cgit v1.2.3