diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 33fa7a04e5..2749c4867e 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -8,71 +8,66 @@ namespace OC\Preview; //we need imagick to convert -if (extension_loaded('imagick')) { +class Office extends Provider { - class Office extends Provider { + private $cmd; - private $cmd; + public function getMimeType() { + return null; + } - public function getMimeType() { - return null; + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $this->initCmd(); + if(is_null($this->cmd)) { + return false; } - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $this->initCmd(); - if(is_null($this->cmd)) { - return false; - } + $abspath = $fileview->toTmpFile($path); - $abspath = $fileview->toTmpFile($path); + $tmpdir = get_temp_dir(); - $tmpdir = get_temp_dir(); + $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath); + $export = 'export HOME=/' . $tmpdir; - $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); - shell_exec($export . "\n" . $exec); - - //create imagick object from pdf - try{ - $pdf = new \imagick($abspath . '.pdf' . '[0]'); - $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - return false; - } - - $image = new \OC_Image($pdf); - - unlink($abspath); - unlink($abspath . '.pdf'); - - if (!$image->valid()) return false; - - return $image; + //create imagick object from pdf + try{ + $pdf = new \imagick($abspath . '.pdf' . '[0]'); + $pdf->setImageFormat('jpg'); + }catch(\Exception $e){ + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; } - private function initCmd() { - $cmd = ''; + $image = new \OC_Image($pdf); - if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { - $cmd = \OC_Config::getValue('preview_libreoffice_path', null); - } + unlink($abspath); + unlink($abspath . '.pdf'); - if($cmd === '' && shell_exec('libreoffice --headless --version')) { - $cmd = 'libreoffice'; - } + return $image->valid() ? $image : false; + } - if($cmd === '' && shell_exec('openoffice --headless --version')) { - $cmd = 'openoffice'; - } + private function initCmd() { + $cmd = ''; - if($cmd === '') { - $cmd = null; - } - - $this->cmd = $cmd; + if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + $cmd = \OC_Config::getValue('preview_libreoffice_path', null); } + + if($cmd === '' && shell_exec('libreoffice --headless --version')) { + $cmd = 'libreoffice'; + } + + if($cmd === '' && shell_exec('openoffice --headless --version')) { + $cmd = 'openoffice'; + } + + if($cmd === '') { + $cmd = null; + } + + $this->cmd = $cmd; } } diff --git a/lib/preview/office.php b/lib/preview/office.php index cc1addf399..20f545ef33 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -5,11 +5,14 @@ * later. * See the COPYING-README file. */ -//let's see if there is libreoffice or openoffice on this machine -if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { - require_once('libreoffice-cl.php'); -}else{ - //in case there isn't, use our fallback - require_once('msoffice.php'); - require_once('opendocument.php'); +//both, libreoffice backend and php fallback, need imagick +if (extension_loaded('imagick')) { + //let's see if there is libreoffice or openoffice on this machine + if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + require_once('libreoffice-cl.php'); + }else{ + //in case there isn't, use our fallback + require_once('msoffice.php'); + require_once('opendocument.php'); + } } \ No newline at end of file