2013-06-05 12:50:20 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
namespace OC\Preview;
|
|
|
|
|
|
|
|
//we need imagick to convert
|
2013-06-11 13:00:44 +04:00
|
|
|
class Office extends Provider {
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
private $cmd;
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
public function getMimeType() {
|
|
|
|
return null;
|
|
|
|
}
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
|
|
|
|
$this->initCmd();
|
|
|
|
if(is_null($this->cmd)) {
|
|
|
|
return false;
|
2013-06-05 12:50:20 +04:00
|
|
|
}
|
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
$abspath = $fileview->toTmpFile($path);
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
$tmpdir = get_temp_dir();
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
$exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath);
|
|
|
|
$export = 'export HOME=/' . $tmpdir;
|
2013-06-05 14:44:31 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
shell_exec($export . "\n" . $exec);
|
2013-06-05 14:44:31 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
//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;
|
|
|
|
}
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
$image = new \OC_Image($pdf);
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
unlink($abspath);
|
|
|
|
unlink($abspath . '.pdf');
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
return $image->valid() ? $image : false;
|
|
|
|
}
|
2013-06-05 14:44:31 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
private function initCmd() {
|
|
|
|
$cmd = '';
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) {
|
|
|
|
$cmd = \OC_Config::getValue('preview_libreoffice_path', null);
|
2013-06-05 12:50:20 +04:00
|
|
|
}
|
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
if($cmd === '' && shell_exec('libreoffice --headless --version')) {
|
|
|
|
$cmd = 'libreoffice';
|
|
|
|
}
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
if($cmd === '' && shell_exec('openoffice --headless --version')) {
|
|
|
|
$cmd = 'openoffice';
|
|
|
|
}
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-06-11 13:00:44 +04:00
|
|
|
if($cmd === '') {
|
|
|
|
$cmd = null;
|
2013-06-05 12:50:20 +04:00
|
|
|
}
|
2013-06-11 13:00:44 +04:00
|
|
|
|
|
|
|
$this->cmd = $cmd;
|
2013-06-05 12:50:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//.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');
|