@@ -28,83 +28,83 @@ |
||
| 28 | 28 | use OCP\ILogger; |
| 29 | 29 | |
| 30 | 30 | abstract class Office extends Provider { |
| 31 | - private $cmd; |
|
| 31 | + private $cmd; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * {@inheritDoc} |
|
| 35 | - */ |
|
| 36 | - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
| 37 | - $this->initCmd(); |
|
| 38 | - if (is_null($this->cmd)) { |
|
| 39 | - return false; |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * {@inheritDoc} |
|
| 35 | + */ |
|
| 36 | + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
| 37 | + $this->initCmd(); |
|
| 38 | + if (is_null($this->cmd)) { |
|
| 39 | + return false; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $absPath = $fileview->toTmpFile($path); |
|
| 42 | + $absPath = $fileview->toTmpFile($path); |
|
| 43 | 43 | |
| 44 | - $tmpDir = \OC::$server->getTempManager()->getTempBaseDir(); |
|
| 44 | + $tmpDir = \OC::$server->getTempManager()->getTempBaseDir(); |
|
| 45 | 45 | |
| 46 | - $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to png --outdir '; |
|
| 47 | - $clParameters = \OC::$server->getConfig()->getSystemValue('preview_office_cl_parameters', $defaultParameters); |
|
| 46 | + $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to png --outdir '; |
|
| 47 | + $clParameters = \OC::$server->getConfig()->getSystemValue('preview_office_cl_parameters', $defaultParameters); |
|
| 48 | 48 | |
| 49 | - $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); |
|
| 49 | + $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); |
|
| 50 | 50 | |
| 51 | - shell_exec($exec); |
|
| 51 | + shell_exec($exec); |
|
| 52 | 52 | |
| 53 | - //create imagick object from png |
|
| 54 | - $pngPreview = null; |
|
| 55 | - try { |
|
| 56 | - list($dirname, , , $filename) = array_values(pathinfo($absPath)); |
|
| 57 | - $pngPreview = $dirname . '/' . $filename . '.png'; |
|
| 53 | + //create imagick object from png |
|
| 54 | + $pngPreview = null; |
|
| 55 | + try { |
|
| 56 | + list($dirname, , , $filename) = array_values(pathinfo($absPath)); |
|
| 57 | + $pngPreview = $dirname . '/' . $filename . '.png'; |
|
| 58 | 58 | |
| 59 | - $png = new \imagick($pngPreview . '[0]'); |
|
| 60 | - $png->setImageFormat('jpg'); |
|
| 61 | - } catch (\Exception $e) { |
|
| 62 | - unlink($absPath); |
|
| 63 | - unlink($pngPreview); |
|
| 64 | - \OC::$server->getLogger()->logException($e, [ |
|
| 65 | - 'level' => ILogger::ERROR, |
|
| 66 | - 'app' => 'core', |
|
| 67 | - ]); |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 59 | + $png = new \imagick($pngPreview . '[0]'); |
|
| 60 | + $png->setImageFormat('jpg'); |
|
| 61 | + } catch (\Exception $e) { |
|
| 62 | + unlink($absPath); |
|
| 63 | + unlink($pngPreview); |
|
| 64 | + \OC::$server->getLogger()->logException($e, [ |
|
| 65 | + 'level' => ILogger::ERROR, |
|
| 66 | + 'app' => 'core', |
|
| 67 | + ]); |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $image = new \OC_Image(); |
|
| 72 | - $image->loadFromData($png); |
|
| 71 | + $image = new \OC_Image(); |
|
| 72 | + $image->loadFromData($png); |
|
| 73 | 73 | |
| 74 | - unlink($absPath); |
|
| 75 | - unlink($pngPreview); |
|
| 74 | + unlink($absPath); |
|
| 75 | + unlink($pngPreview); |
|
| 76 | 76 | |
| 77 | - if ($image->valid()) { |
|
| 78 | - $image->scaleDownToFit($maxX, $maxY); |
|
| 77 | + if ($image->valid()) { |
|
| 78 | + $image->scaleDownToFit($maxX, $maxY); |
|
| 79 | 79 | |
| 80 | - return $image; |
|
| 81 | - } |
|
| 82 | - return false; |
|
| 80 | + return $image; |
|
| 81 | + } |
|
| 82 | + return false; |
|
| 83 | 83 | |
| 84 | - } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - private function initCmd() { |
|
| 87 | - $cmd = ''; |
|
| 86 | + private function initCmd() { |
|
| 87 | + $cmd = ''; |
|
| 88 | 88 | |
| 89 | - $libreOfficePath = \OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null); |
|
| 90 | - if (is_string($libreOfficePath)) { |
|
| 91 | - $cmd = $libreOfficePath; |
|
| 92 | - } |
|
| 89 | + $libreOfficePath = \OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null); |
|
| 90 | + if (is_string($libreOfficePath)) { |
|
| 91 | + $cmd = $libreOfficePath; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
| 95 | - if ($cmd === '' && !empty($whichLibreOffice)) { |
|
| 96 | - $cmd = 'libreoffice'; |
|
| 97 | - } |
|
| 94 | + $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
| 95 | + if ($cmd === '' && !empty($whichLibreOffice)) { |
|
| 96 | + $cmd = 'libreoffice'; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - $whichOpenOffice = shell_exec('command -v openoffice'); |
|
| 100 | - if ($cmd === '' && !empty($whichOpenOffice)) { |
|
| 101 | - $cmd = 'openoffice'; |
|
| 102 | - } |
|
| 99 | + $whichOpenOffice = shell_exec('command -v openoffice'); |
|
| 100 | + if ($cmd === '' && !empty($whichOpenOffice)) { |
|
| 101 | + $cmd = 'openoffice'; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - if ($cmd === '') { |
|
| 105 | - $cmd = null; |
|
| 106 | - } |
|
| 104 | + if ($cmd === '') { |
|
| 105 | + $cmd = null; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - $this->cmd = $cmd; |
|
| 109 | - } |
|
| 108 | + $this->cmd = $cmd; |
|
| 109 | + } |
|
| 110 | 110 | } |