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-07-30 14:29:12 +04:00
|
|
|
$absPath = $fileview->toTmpFile($path);
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-07-30 14:29:12 +04:00
|
|
|
$tmpDir = get_temp_dir();
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-07-30 14:29:12 +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{
|
2013-07-30 14:29:12 +04:00
|
|
|
$pdf = new \imagick($absPath . '.pdf' . '[0]');
|
2013-06-11 13:00:44 +04:00
|
|
|
$pdf->setImageFormat('jpg');
|
2013-07-30 15:43:15 +04:00
|
|
|
} catch (\Exception $e) {
|
2013-07-30 14:29:12 +04:00
|
|
|
unlink($absPath);
|
|
|
|
unlink($absPath . '.pdf');
|
2013-06-11 13:00:44 +04:00
|
|
|
\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-07-30 14:29:12 +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-07-30 14:29:12 +04:00
|
|
|
$whichLibreOffice = shell_exec('which libreoffice');
|
|
|
|
if($cmd === '' && !empty($whichLibreOffice)) {
|
2013-06-11 13:00:44 +04:00
|
|
|
$cmd = 'libreoffice';
|
|
|
|
}
|
2013-06-05 12:50:20 +04:00
|
|
|
|
2013-07-30 14:29:12 +04:00
|
|
|
$whichOpenOffice = shell_exec('which openoffice');
|
|
|
|
if($cmd === '' && !empty($whichOpenOffice)) {
|
2013-06-11 13:00:44 +04:00
|
|
|
$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/';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-29 16:46:20 +04:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc');
|
2013-06-05 12:50:20 +04:00
|
|
|
|
|
|
|
//.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-.*/';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-29 16:46:20 +04:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\MSOffice2003');
|
2013-06-05 12:50:20 +04:00
|
|
|
|
|
|
|
//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
|
|
|
|
class MSOffice2007 extends Office {
|
|
|
|
|
|
|
|
public function getMimeType() {
|
|
|
|
return '/application\/vnd.openxmlformats-officedocument.*/';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-29 16:46:20 +04:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\MSOffice2007');
|
2013-06-05 12:50:20 +04:00
|
|
|
|
|
|
|
//.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.*/';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-29 16:46:20 +04:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\OpenDocument');
|
2013-06-05 12:50:20 +04:00
|
|
|
|
|
|
|
//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
|
|
|
|
class StarOffice extends Office {
|
|
|
|
|
|
|
|
public function getMimeType() {
|
|
|
|
return '/application\/vnd.sun.xml.*/';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-29 16:46:20 +04:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\StarOffice');
|