check if imagick is loaded in office.php, not in libreoffice-cl.php

This commit is contained in:
Georg Ehrke 2013-06-11 11:00:44 +02:00
parent 2ff97917e9
commit 28cf63d37d
2 changed files with 54 additions and 56 deletions

View File

@ -8,71 +8,66 @@
namespace OC\Preview; namespace OC\Preview;
//we need imagick to convert //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() { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
return null; $this->initCmd();
if(is_null($this->cmd)) {
return false;
} }
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $abspath = $fileview->toTmpFile($path);
$this->initCmd();
if(is_null($this->cmd)) {
return false;
}
$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); shell_exec($export . "\n" . $exec);
$export = 'export HOME=/' . $tmpdir;
shell_exec($export . "\n" . $exec); //create imagick object from pdf
try{
//create imagick object from pdf $pdf = new \imagick($abspath . '.pdf' . '[0]');
try{ $pdf->setImageFormat('jpg');
$pdf = new \imagick($abspath . '.pdf' . '[0]'); }catch(\Exception $e){
$pdf->setImageFormat('jpg'); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
}catch(\Exception $e){ return false;
\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;
} }
private function initCmd() { $image = new \OC_Image($pdf);
$cmd = '';
if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { unlink($abspath);
$cmd = \OC_Config::getValue('preview_libreoffice_path', null); unlink($abspath . '.pdf');
}
if($cmd === '' && shell_exec('libreoffice --headless --version')) { return $image->valid() ? $image : false;
$cmd = 'libreoffice'; }
}
if($cmd === '' && shell_exec('openoffice --headless --version')) { private function initCmd() {
$cmd = 'openoffice'; $cmd = '';
}
if($cmd === '') { if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) {
$cmd = null; $cmd = \OC_Config::getValue('preview_libreoffice_path', null);
}
$this->cmd = $cmd;
} }
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;
} }
} }

View File

@ -5,11 +5,14 @@
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
//let's see if there is libreoffice or openoffice on this machine //both, libreoffice backend and php fallback, need imagick
if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { if (extension_loaded('imagick')) {
require_once('libreoffice-cl.php'); //let's see if there is libreoffice or openoffice on this machine
}else{ if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) {
//in case there isn't, use our fallback require_once('libreoffice-cl.php');
require_once('msoffice.php'); }else{
require_once('opendocument.php'); //in case there isn't, use our fallback
require_once('msoffice.php');
require_once('opendocument.php');
}
} }