summaryrefslogtreecommitdiffstats
path: root/lib/private/preview
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-04-20 15:02:44 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2016-04-20 15:02:44 +0200
commit702046d4aae6f22adc679df6e1a64c7a1504c80e (patch)
tree4ff1a427011a8909910aeedc9bf7d421e57b5f08 /lib/private/preview
parentafad27fafd996f0e2e7117d9f431f9eb63736569 (diff)
downloadnextcloud-server-702046d4aae6f22adc679df6e1a64c7a1504c80e.tar.gz
nextcloud-server-702046d4aae6f22adc679df6e1a64c7a1504c80e.zip
Move \OC\Preview to PSR-4
Diffstat (limited to 'lib/private/preview')
-rw-r--r--lib/private/preview/bitmap.php114
-rw-r--r--lib/private/preview/bmp.php31
-rw-r--r--lib/private/preview/font.php32
-rw-r--r--lib/private/preview/gif.php31
-rw-r--r--lib/private/preview/illustrator.php33
-rw-r--r--lib/private/preview/image.php68
-rw-r--r--lib/private/preview/jpeg.php31
-rw-r--r--lib/private/preview/markdown.php31
-rw-r--r--lib/private/preview/movie.php113
-rw-r--r--lib/private/preview/mp3.php81
-rw-r--r--lib/private/preview/msoffice2003.php31
-rw-r--r--lib/private/preview/msoffice2007.php31
-rw-r--r--lib/private/preview/msofficedoc.php31
-rw-r--r--lib/private/preview/office.php104
-rw-r--r--lib/private/preview/opendocument.php31
-rw-r--r--lib/private/preview/pdf.php33
-rw-r--r--lib/private/preview/photoshop.php33
-rw-r--r--lib/private/preview/png.php31
-rw-r--r--lib/private/preview/postscript.php33
-rw-r--r--lib/private/preview/provider.php67
-rw-r--r--lib/private/preview/staroffice.php31
-rw-r--r--lib/private/preview/svg.php70
-rw-r--r--lib/private/preview/tiff.php33
-rw-r--r--lib/private/preview/txt.php92
-rw-r--r--lib/private/preview/xbitmap.php31
25 files changed, 0 insertions, 1247 deletions
diff --git a/lib/private/preview/bitmap.php b/lib/private/preview/bitmap.php
deleted file mode 100644
index 34bc2f93fc7..00000000000
--- a/lib/private/preview/bitmap.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Olivier Paroz <github@oparoz.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-use Imagick;
-
-/**
- * Creates a PNG preview using ImageMagick via the PECL extension
- *
- * @package OC\Preview
- */
-abstract class Bitmap extends Provider {
-
- /**
- * {@inheritDoc}
- */
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
-
- $tmpPath = $fileview->toTmpFile($path);
- if (!$tmpPath) {
- return false;
- }
-
- // Creates \Imagick object from bitmap or vector file
- try {
- $bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
- } catch (\Exception $e) {
- \OCP\Util::writeLog('core', 'ImageMagick says: ' . $e->getmessage(), \OCP\Util::ERROR);
- return false;
- }
-
- unlink($tmpPath);
-
- //new bitmap image object
- $image = new \OC_Image();
- $image->loadFromData($bp);
- //check if image object is valid
- return $image->valid() ? $image : false;
- }
-
- /**
- * Returns a preview of maxX times maxY dimensions in PNG format
- *
- * * The default resolution is already 72dpi, no need to change it for a bitmap output
- * * It's possible to have proper colour conversion using profileimage().
- * ICC profiles are here: http://www.color.org/srgbprofiles.xalter
- * * It's possible to Gamma-correct an image via gammaImage()
- *
- * @param string $tmpPath the location of the file to convert
- * @param int $maxX
- * @param int $maxY
- *
- * @return \Imagick
- */
- private function getResizedPreview($tmpPath, $maxX, $maxY) {
- $bp = new Imagick();
-
- // Layer 0 contains either the bitmap or a flat representation of all vector layers
- $bp->readImage($tmpPath . '[0]');
-
- $bp = $this->resize($bp, $maxX, $maxY);
-
- $bp->setImageFormat('png');
-
- return $bp;
- }
-
- /**
- * Returns a resized \Imagick object
- *
- * If you want to know more on the various methods available to resize an
- * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im
- *
- * @param \Imagick $bp
- * @param int $maxX
- * @param int $maxY
- *
- * @return \Imagick
- */
- private function resize($bp, $maxX, $maxY) {
- list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry());
-
- // We only need to resize a preview which doesn't fit in the maximum dimensions
- if ($previewWidth > $maxX || $previewHeight > $maxY) {
- // TODO: LANCZOS is the default filter, CATROM could bring similar results faster
- $bp->resizeImage($maxX, $maxY, imagick::FILTER_LANCZOS, 1, true);
- }
-
- return $bp;
- }
-
-}
diff --git a/lib/private/preview/bmp.php b/lib/private/preview/bmp.php
deleted file mode 100644
index da13cd9e5b8..00000000000
--- a/lib/private/preview/bmp.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Olivier Paroz <github@oparoz.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-class BMP extends Image {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/image\/bmp/';
- }
-}
diff --git a/lib/private/preview/font.php b/lib/private/preview/font.php
deleted file mode 100644
index caac2923789..00000000000
--- a/lib/private/preview/font.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-/**
- * @author Olivier Paroz <github@oparoz.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-// .otf, .ttf and .pfb
-class Font extends Bitmap {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/(?:font-sfnt|x-font$)/';
- }
-} \ No newline at end of file
diff --git a/lib/private/preview/gif.php b/lib/private/preview/gif.php
deleted file mode 100644
index 0716a6f4406..00000000000
--- a/lib/private/preview/gif.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Olivier Paroz <github@oparoz.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-class GIF extends Image {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/image\/gif/';
- }
-}
diff --git a/lib/private/preview/illustrator.php b/lib/private/preview/illustrator.php
deleted file mode 100644
index ef8448d7b53..00000000000
--- a/lib/private/preview/illustrator.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-//.ai
-class Illustrator extends Bitmap {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/illustrator/';
- }
-}
diff --git a/lib/private/preview/image.php b/lib/private/preview/image.php
deleted file mode 100644
index 3ea99d6963a..00000000000
--- a/lib/private/preview/image.php
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-/**
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Olivier Paroz <github@oparoz.com>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Thomas Tanghus <thomas@tanghus.net>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-abstract class Image extends Provider {
-
- /**
- * {@inheritDoc}
- */
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- //get fileinfo
- $fileInfo = $fileview->getFileInfo($path);
- if (!$fileInfo) {
- return false;
- }
-
- $maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
- $size = $fileInfo->getSize();
-
- if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
- return false;
- }
-
- $image = new \OC_Image();
-
- $useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal();
- if ($useTempFile) {
- $fileName = $fileview->toTmpFile($path);
- } else {
- $fileName = $fileview->getLocalFile($path);
- }
- $image->loadFromFile($fileName);
- $image->fixOrientation();
- if ($useTempFile) {
- unlink($fileName);
- }
- if ($image->valid()) {
- $image->scaleDownToFit($maxX, $maxY);
-
- return $image;
- }
- return false;
- }
-
-}
diff --git a/lib/private/preview/jpeg.php b/lib/private/preview/jpeg.php
deleted file mode 100644
index 2ee5dd24419..00000000000
--- a/lib/private/preview/jpeg.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Olivier Paroz <github@oparoz.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-class JPEG extends Image {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/image\/jpeg/';
- }
-}
diff --git a/lib/private/preview/markdown.php b/lib/private/preview/markdown.php
deleted file mode 100644
index 394af6576c7..00000000000
--- a/lib/private/preview/markdown.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-class MarkDown extends TXT {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/text\/(x-)?markdown/';
- }
-
-}
diff --git a/lib/private/preview/movie.php b/lib/private/preview/movie.php
deleted file mode 100644
index 43a8d674fc9..00000000000
--- a/lib/private/preview/movie.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-/**
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Olivier Paroz <github@oparoz.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-class Movie extends Provider {
- public static $avconvBinary;
- public static $ffmpegBinary;
-
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/video\/.*/';
- }
-
- /**
- * {@inheritDoc}
- */
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- // TODO: use proc_open() and stream the source file ?
-
- $fileInfo = $fileview->getFileInfo($path);
- $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted());
-
- if ($useFileDirectly) {
- $absPath = $fileview->getLocalFile($path);
- } else {
- $absPath = \OC::$server->getTempManager()->getTemporaryFile();
-
- $handle = $fileview->fopen($path, 'rb');
-
- // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
- // in some cases 1MB was no enough to generate thumbnail
- $firstmb = stream_get_contents($handle, 5242880);
- file_put_contents($absPath, $firstmb);
- }
-
- $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5);
- if ($result === false) {
- $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1);
- if ($result === false) {
- $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0);
- }
- }
-
- if (!$useFileDirectly) {
- unlink($absPath);
- }
-
- return $result;
- }
-
- /**
- * @param int $maxX
- * @param int $maxY
- * @param string $absPath
- * @param int $second
- * @return bool|\OCP\IImage
- */
- private function generateThumbNail($maxX, $maxY, $absPath, $second) {
- $tmpPath = \OC::$server->getTempManager()->getTemporaryFile();
-
- if (self::$avconvBinary) {
- $cmd = self::$avconvBinary . ' -y -ss ' . escapeshellarg($second) .
- ' -i ' . escapeshellarg($absPath) .
- ' -an -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) .
- ' > /dev/null 2>&1';
- } else {
- $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) .
- ' -i ' . escapeshellarg($absPath) .
- ' -f mjpeg -vframes 1' .
- ' ' . escapeshellarg($tmpPath) .
- ' > /dev/null 2>&1';
- }
-
- exec($cmd, $output, $returnCode);
-
- if ($returnCode === 0) {
- $image = new \OC_Image();
- $image->loadFromFile($tmpPath);
- unlink($tmpPath);
- if ($image->valid()) {
- $image->scaleDownToFit($maxX, $maxY);
-
- return $image;
- }
- }
- unlink($tmpPath);
- return false;
- }
-}
diff --git a/lib/private/preview/mp3.php b/lib/private/preview/mp3.php
deleted file mode 100644
index c7b70457afe..00000000000
--- a/lib/private/preview/mp3.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-/**
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Olivier Paroz <github@oparoz.com>
- * @author Thomas Tanghus <thomas@tanghus.net>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-use ID3Parser\ID3Parser;
-
-class MP3 extends Provider {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/audio\/mpeg/';
- }
-
- /**
- * {@inheritDoc}
- */
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- $getID3 = new ID3Parser();
-
- $tmpPath = $fileview->toTmpFile($path);
- $tags = $getID3->analyze($tmpPath);
- unlink($tmpPath);
- $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
- if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
- $picture = $tags['id3v2']['PIC'][0]['data'];
- }
-
- if(!is_null($picture)) {
- $image = new \OC_Image();
- $image->loadFromData($picture);
-
- if ($image->valid()) {
- $image->scaleDownToFit($maxX, $maxY);
-
- return $image;
- }
- }
-
- return $this->getNoCoverThumbnail();
- }
-
- /**
- * Generates a default image when the file has no cover
- *
- * @return bool|\OCP\IImage false if the default image is missing or invalid
- */
- private function getNoCoverThumbnail() {
- $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png';
-
- if(!file_exists($icon)) {
- return false;
- }
-
- $image = new \OC_Image();
- $image->loadFromFile($icon);
- return $image->valid() ? $image : false;
- }
-
-}
diff --git a/lib/private/preview/msoffice2003.php b/lib/private/preview/msoffice2003.php
deleted file mode 100644
index 20dbe13543a..00000000000
--- a/lib/private/preview/msoffice2003.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-//.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
-class MSOffice2003 extends Office {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/vnd.ms-.*/';
- }
-}
diff --git a/lib/private/preview/msoffice2007.php b/lib/private/preview/msoffice2007.php
deleted file mode 100644
index ef6758843f1..00000000000
--- a/lib/private/preview/msoffice2007.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
-class MSOffice2007 extends Office {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/vnd.openxmlformats-officedocument.*/';
- }
-}
diff --git a/lib/private/preview/msofficedoc.php b/lib/private/preview/msofficedoc.php
deleted file mode 100644
index 05d839d508f..00000000000
--- a/lib/private/preview/msofficedoc.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-//.doc, .dot
-class MSOfficeDoc extends Office {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/msword/';
- }
-}
diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php
deleted file mode 100644
index 6496e091b1d..00000000000
--- a/lib/private/preview/office.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Olivier Paroz <github@oparoz.com>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-abstract class Office extends Provider {
- private $cmd;
-
- /**
- * {@inheritDoc}
- */
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- $this->initCmd();
- if (is_null($this->cmd)) {
- return false;
- }
-
- $absPath = $fileview->toTmpFile($path);
-
- $tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
-
- $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
- $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
-
- $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
-
- shell_exec($exec);
-
- //create imagick object from pdf
- $pdfPreview = null;
- try {
- list($dirname, , , $filename) = array_values(pathinfo($absPath));
- $pdfPreview = $dirname . '/' . $filename . '.pdf';
-
- $pdf = new \imagick($pdfPreview . '[0]');
- $pdf->setImageFormat('jpg');
- } catch (\Exception $e) {
- unlink($absPath);
- unlink($pdfPreview);
- \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
- return false;
- }
-
- $image = new \OC_Image();
- $image->loadFromData($pdf);
-
- unlink($absPath);
- unlink($pdfPreview);
-
- if ($image->valid()) {
- $image->scaleDownToFit($maxX, $maxY);
-
- return $image;
- }
- return false;
-
- }
-
- private function initCmd() {
- $cmd = '';
-
- $libreOfficePath = \OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null);
- if (is_string($libreOfficePath)) {
- $cmd = $libreOfficePath;
- }
-
- $whichLibreOffice = shell_exec('command -v libreoffice');
- if ($cmd === '' && !empty($whichLibreOffice)) {
- $cmd = 'libreoffice';
- }
-
- $whichOpenOffice = shell_exec('command -v openoffice');
- if ($cmd === '' && !empty($whichOpenOffice)) {
- $cmd = 'openoffice';
- }
-
- if ($cmd === '') {
- $cmd = null;
- }
-
- $this->cmd = $cmd;
- }
-}
diff --git a/lib/private/preview/opendocument.php b/lib/private/preview/opendocument.php
deleted file mode 100644
index 0da1e88cafa..00000000000
--- a/lib/private/preview/opendocument.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
-class OpenDocument extends Office {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/vnd.oasis.opendocument.*/';
- }
-}
diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php
deleted file mode 100644
index 6ddf33cdea2..00000000000
--- a/lib/private/preview/pdf.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-//.pdf
-class PDF extends Bitmap {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/pdf/';
- }
-}
diff --git a/lib/private/preview/photoshop.php b/lib/private/preview/photoshop.php
deleted file mode 100644
index df91247f072..00000000000
--- a/lib/private/preview/photoshop.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-//.psd
-class Photoshop extends Bitmap {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/x-photoshop/';
- }
-}
diff --git a/lib/private/preview/png.php b/lib/private/preview/png.php
deleted file mode 100644
index 5dd9ae484a5..00000000000
--- a/lib/private/preview/png.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Olivier Paroz <github@oparoz.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-class PNG extends Image {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/image\/png/';
- }
-}
diff --git a/lib/private/preview/postscript.php b/lib/private/preview/postscript.php
deleted file mode 100644
index edfd43968c2..00000000000
--- a/lib/private/preview/postscript.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-//.eps
-class Postscript extends Bitmap {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/postscript/';
- }
-}
diff --git a/lib/private/preview/provider.php b/lib/private/preview/provider.php
deleted file mode 100644
index 738d13d7fc8..00000000000
--- a/lib/private/preview/provider.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Olivier Paroz <github@oparoz.com>
- * @author Robin Appelman <icewind@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-use OCP\Preview\IProvider;
-
-abstract class Provider implements IProvider {
- private $options;
-
- /**
- * Constructor
- *
- * @param array $options
- */
- public function __construct(array $options = []) {
- $this->options = $options;
- }
-
- /**
- * @return string Regex with the mimetypes that are supported by this provider
- */
- abstract public function getMimeType();
-
- /**
- * Check if a preview can be generated for $path
- *
- * @param \OCP\Files\FileInfo $file
- * @return bool
- */
- public function isAvailable(\OCP\Files\FileInfo $file) {
- return true;
- }
-
- /**
- * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path
- *
- * @param string $path Path of file
- * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
- * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
- * @param bool $scalingup Disable/Enable upscaling of previews
- * @param \OC\Files\View $fileview fileview object of user folder
- * @return bool|\OCP\IImage false if no preview was generated
- */
- abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview);
-}
diff --git a/lib/private/preview/staroffice.php b/lib/private/preview/staroffice.php
deleted file mode 100644
index 6ea4efa5144..00000000000
--- a/lib/private/preview/staroffice.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
-class StarOffice extends Office {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/application\/vnd.sun.xml.*/';
- }
-}
diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php
deleted file mode 100644
index 6618c1fbf82..00000000000
--- a/lib/private/preview/svg.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Olivier Paroz <github@oparoz.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-class SVG extends Provider {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/image\/svg\+xml/';
- }
-
- /**
- * {@inheritDoc}
- */
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- try {
- $svg = new \Imagick();
- $svg->setBackgroundColor(new \ImagickPixel('transparent'));
-
- $content = stream_get_contents($fileview->fopen($path, 'r'));
- if (substr($content, 0, 5) !== '<?xml') {
- $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
- }
-
- // Do not parse SVG files with references
- if (stripos($content, 'xlink:href') !== false) {
- return false;
- }
-
- $svg->readImageBlob($content);
- $svg->setImageFormat('png32');
- } catch (\Exception $e) {
- \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
- return false;
- }
-
- //new image object
- $image = new \OC_Image();
- $image->loadFromData($svg);
- //check if image object is valid
- if ($image->valid()) {
- $image->scaleDownToFit($maxX, $maxY);
-
- return $image;
- }
- return false;
- }
-}
diff --git a/lib/private/preview/tiff.php b/lib/private/preview/tiff.php
deleted file mode 100644
index 006ced6aec0..00000000000
--- a/lib/private/preview/tiff.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-//.tiff
-class TIFF extends Bitmap {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/image\/tiff/';
- }
-}
diff --git a/lib/private/preview/txt.php b/lib/private/preview/txt.php
deleted file mode 100644
index a27517c9f39..00000000000
--- a/lib/private/preview/txt.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-/**
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Nmz <nemesiz@nmz.lt>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Preview;
-
-class TXT extends Provider {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/text\/plain/';
- }
-
- /**
- * {@inheritDoc}
- */
- public function isAvailable(\OCP\Files\FileInfo $file) {
- return $file->getSize() > 0;
- }
-
- /**
- * {@inheritDoc}
- */
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- $content = $fileview->fopen($path, 'r');
- $content = stream_get_contents($content,3000);
-
- //don't create previews of empty text files
- if(trim($content) === '') {
- return false;
- }
-
- $lines = preg_split("/\r\n|\n|\r/", $content);
-
- $fontSize = ($maxX) ? (int) ((5 / 32) * $maxX) : 5; //5px
- $lineSize = ceil($fontSize * 1.25);
-
- $image = imagecreate($maxX, $maxY);
- imagecolorallocate($image, 255, 255, 255);
- $textColor = imagecolorallocate($image, 0, 0, 0);
-
- $fontFile = __DIR__;
- $fontFile .= '/../../../core';
- $fontFile .= '/fonts/OpenSans-Regular.ttf';
-
- $canUseTTF = function_exists('imagettftext');
-
- foreach($lines as $index => $line) {
- $index = $index + 1;
-
- $x = (int) 1;
- $y = (int) ($index * $lineSize);
-
- if ($canUseTTF === true) {
- imagettftext($image, $fontSize, 0, $x, $y, $textColor, $fontFile, $line);
- } else {
- $y -= $fontSize;
- imagestring($image, 1, $x, $y, $line, $textColor);
- }
-
- if(($index * $lineSize) >= $maxY) {
- break;
- }
- }
-
- $image = new \OC_Image($image);
-
- return $image->valid() ? $image : false;
- }
-}
diff --git a/lib/private/preview/xbitmap.php b/lib/private/preview/xbitmap.php
deleted file mode 100644
index 604a51a6a83..00000000000
--- a/lib/private/preview/xbitmap.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @author Olivier Paroz <github@oparoz.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Preview;
-
-class XBitmap extends Image {
- /**
- * {@inheritDoc}
- */
- public function getMimeType() {
- return '/image\/x-xbitmap/';
- }
-}