2013-06-05 08:50:20 +00: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;
|
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
// office preview is currently not supported on Windows
|
|
|
|
if (!\OC_Util::runningOnWindows()) {
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
//we need imagick to convert
|
|
|
|
class Office extends Provider {
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
private $cmd;
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
public function getMimeType() {
|
|
|
|
return null;
|
2013-06-05 08:50:20 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
|
|
|
|
$this->initCmd();
|
|
|
|
if(is_null($this->cmd)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$absPath = $fileview->toTmpFile($path);
|
|
|
|
|
|
|
|
$tmpDir = get_temp_dir();
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2014-09-03 14:08:40 +00:00
|
|
|
$defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId().'/') . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
|
2013-10-14 22:15:45 +00:00
|
|
|
$clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2014-09-03 14:08:40 +00:00
|
|
|
$exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
|
2013-08-19 10:16:55 +00:00
|
|
|
|
2014-07-23 05:46:38 +00:00
|
|
|
shell_exec($exec);
|
2013-06-05 10:44:31 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
//create imagick object from pdf
|
|
|
|
try{
|
|
|
|
$pdf = new \imagick($absPath . '.pdf' . '[0]');
|
|
|
|
$pdf->setImageFormat('jpg');
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
unlink($absPath);
|
|
|
|
unlink($absPath . '.pdf');
|
|
|
|
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-12 23:36:42 +00:00
|
|
|
$image = new \OC_Image();
|
|
|
|
$image->loadFromData($pdf);
|
2013-06-05 10:44:31 +00:00
|
|
|
|
2013-07-30 10:29:12 +00:00
|
|
|
unlink($absPath);
|
|
|
|
unlink($absPath . '.pdf');
|
2013-10-14 22:15:45 +00:00
|
|
|
|
|
|
|
return $image->valid() ? $image : false;
|
2013-06-11 09:00:44 +00:00
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
private function initCmd() {
|
|
|
|
$cmd = '';
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) {
|
|
|
|
$cmd = \OC_Config::getValue('preview_libreoffice_path', null);
|
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2014-02-21 12:45:57 +00:00
|
|
|
$whichLibreOffice = shell_exec('command -v libreoffice');
|
2013-10-14 22:15:45 +00:00
|
|
|
if($cmd === '' && !empty($whichLibreOffice)) {
|
|
|
|
$cmd = 'libreoffice';
|
|
|
|
}
|
2013-06-05 10:44:31 +00:00
|
|
|
|
2014-02-21 12:45:57 +00:00
|
|
|
$whichOpenOffice = shell_exec('command -v openoffice');
|
2013-10-14 22:15:45 +00:00
|
|
|
if($cmd === '' && !empty($whichOpenOffice)) {
|
|
|
|
$cmd = 'openoffice';
|
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
if($cmd === '') {
|
|
|
|
$cmd = null;
|
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
$this->cmd = $cmd;
|
2013-06-11 09:00:44 +00:00
|
|
|
}
|
2013-10-14 22:15:45 +00:00
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
//.doc, .dot
|
|
|
|
class MSOfficeDoc extends Office {
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
public function getMimeType() {
|
|
|
|
return '/application\/msword/';
|
2013-06-05 08:50:20 +00:00
|
|
|
}
|
2013-06-11 09:00:44 +00:00
|
|
|
|
2013-06-05 08:50:20 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc');
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
//.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
|
|
|
|
class MSOffice2003 extends Office {
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
public function getMimeType() {
|
|
|
|
return '/application\/vnd.ms-.*/';
|
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\MSOffice2003');
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
|
|
|
|
class MSOffice2007 extends Office {
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
public function getMimeType() {
|
|
|
|
return '/application\/vnd.openxmlformats-officedocument.*/';
|
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\MSOffice2007');
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
|
|
|
|
class OpenDocument extends Office {
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
public function getMimeType() {
|
|
|
|
return '/application\/vnd.oasis.opendocument.*/';
|
|
|
|
}
|
2013-08-19 10:16:55 +00:00
|
|
|
|
2013-06-05 08:50:20 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\OpenDocument');
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
|
|
|
|
class StarOffice extends Office {
|
2013-06-05 08:50:20 +00:00
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
public function getMimeType() {
|
|
|
|
return '/application\/vnd.sun.xml.*/';
|
|
|
|
}
|
2013-06-05 08:50:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-14 22:15:45 +00:00
|
|
|
\OC\Preview::registerProvider('OC\Preview\StarOffice');
|
2013-06-05 08:50:20 +00:00
|
|
|
}
|