[Pkg-owncloud-commits] [owncloud] 128/258: Add a configuration switch for enabled preview mimetypes
David Prévot
taffit at moszumanska.debian.org
Sat Oct 11 17:22:28 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit bb69eebde4e03b2672c99827d4ad5339ba432a85
Author: Lukas Reschke <lukas at owncloud.com>
Date: Tue Sep 23 10:42:45 2014 +0200
Add a configuration switch for enabled preview mimetypes
Backport of https://github.com/owncloud/core/pull/11211 to stable7
---
config/config.sample.php | 21 ++++++++++++++++++
lib/private/preview.php | 37 +++++++++++++++++++++++++------
lib/private/preview/svg.php | 5 +++++
lib/private/preview/unknown.php | 49 -----------------------------------------
tests/data/testcal.ics | 13 -----------
tests/data/testcontact.vcf | 6 -----
tests/lib/preview.php | 4 ----
7 files changed, 56 insertions(+), 79 deletions(-)
diff --git a/config/config.sample.php b/config/config.sample.php
index d093cff..0a933b1 100755
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -270,6 +270,27 @@ $CONFIG = array(
'preview_libreoffice_path' => '/usr/bin/libreoffice',
/* cl parameters for libreoffice / openoffice */
'preview_office_cl_parameters' => '',
+/**
+ * Only register providers that have been explicitly enabled
+ *
+ * The following providers are enabled by default:
+ * - OC\Preview\Image
+ * - OC\Preview\MP3
+ * - OC\Preview\TXT
+ * - OC\Preview\MarkDown
+ *
+ * The following providers are disabled by default due to performance or privacy concerns:
+ * - OC\Preview\Office
+ * - OC\Preview\SVG
+ * - OC\Preview\Movies
+ * - OC\Preview\PDF
+ */
+'enabledPreviewProviders' => array(
+ 'OC\Preview\Image',
+ 'OC\Preview\MP3',
+ 'OC\Preview\TXT',
+ 'OC\Preview\MarkDown'
+),
/* whether avatars should be enabled */
'enable_avatars' => true,
diff --git a/lib/private/preview.php b/lib/private/preview.php
index 9006a2e..40b3eb8 100755
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -21,7 +21,6 @@ require_once 'preview/mp3.php';
require_once 'preview/pdf.php';
require_once 'preview/svg.php';
require_once 'preview/txt.php';
-require_once 'preview/unknown.php';
require_once 'preview/office.php';
class Preview {
@@ -59,6 +58,7 @@ class Preview {
//preview providers
static private $providers = array();
static private $registeredProviders = array();
+ static private $enabledProviders = array();
/**
* @var \OCP\Files\FileInfo
@@ -665,7 +665,33 @@ class Preview {
* @return void
*/
public static function registerProvider($class, $options = array()) {
- self::$registeredProviders[] = array('class' => $class, 'options' => $options);
+ /**
+ * Only register providers that have been explicitly enabled
+ *
+ * The following providers are enabled by default:
+ * - OC\Preview\Image
+ * - OC\Preview\MP3
+ * - OC\Preview\TXT
+ * - OC\Preview\MarkDown
+ *
+ * The following providers are disabled by default due to performance or privacy concerns:
+ * - OC\Preview\Office
+ * - OC\Preview\SVG
+ * - OC\Preview\Movies
+ * - OC\Preview\PDF
+ */
+ if(empty(self::$enabledProviders)) {
+ self::$enabledProviders = \OC_Config::getValue('enabledPreviewProviders', array(
+ 'OC\Preview\Image',
+ 'OC\Preview\MP3',
+ 'OC\Preview\TXT',
+ 'OC\Preview\MarkDown',
+ ));
+ }
+
+ if(in_array($class, self::$enabledProviders)) {
+ self::$registeredProviders[] = array('class' => $class, 'options' => $options);
+ }
}
/**
@@ -674,8 +700,7 @@ class Preview {
*/
private static function initProviders() {
if (!\OC_Config::getValue('enable_previews', true)) {
- $provider = new Preview\Unknown(array());
- self::$providers = array($provider->getMimeType() => $provider);
+ self::$providers = array();
return;
}
@@ -747,9 +772,7 @@ class Preview {
self::initProviders();
}
- //remove last element because it has the mimetype *
- $providers = array_slice(self::$providers, 0, -1);
- foreach ($providers as $supportedMimeType => $provider) {
+ foreach (self::$providers as $supportedMimeType => $provider) {
if (preg_match($supportedMimeType, $mimeType)) {
return true;
}
diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php
index 82ef3cd..0b5dbc9 100644
--- a/lib/private/preview/svg.php
+++ b/lib/private/preview/svg.php
@@ -31,6 +31,11 @@ if (extension_loaded('imagick')) {
$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) {
diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php
deleted file mode 100644
index 2d3b5c5..0000000
--- a/lib/private/preview/unknown.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Frank Karlitschek frank at owncloud.org
- * Copyright (c) 2013 Georg Ehrke georg at ownCloud.com
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-namespace OC\Preview;
-
-class Unknown extends Provider {
-
- public function getMimeType() {
- return '/.*/';
- }
-
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- $mimetype = $fileview->getMimeType($path);
-
- $path = \OC_Helper::mimetypeIcon($mimetype);
- $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
-
- $svgPath = substr_replace($path, 'svg', -3);
-
- if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
-
- // http://www.php.net/manual/de/imagick.setresolution.php#85284
- $svg = new \Imagick();
- $svg->readImage($svgPath);
- $res = $svg->getImageResolution();
- $x_ratio = $res['x'] / $svg->getImageWidth();
- $y_ratio = $res['y'] / $svg->getImageHeight();
- $svg->removeImage();
- $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
- $svg->setBackgroundColor(new \ImagickPixel('transparent'));
- $svg->readImage($svgPath);
- $svg->setImageFormat('png32');
-
- $image = new \OC_Image();
- $image->loadFromData($svg);
- } else {
- $image = new \OC_Image($path);
- }
-
- return $image;
- }
-}
-
-\OC\Preview::registerProvider('OC\Preview\Unknown');
diff --git a/tests/data/testcal.ics b/tests/data/testcal.ics
deleted file mode 100644
index e05f01b..0000000
--- a/tests/data/testcal.ics
+++ /dev/null
@@ -1,13 +0,0 @@
-BEGIN:VCALENDAR
-PRODID:-//some random cal software//EN
-VERSION:2.0
-BEGIN:VEVENT
-CREATED:20130102T120000Z
-LAST-MODIFIED:20130102T120000Z
-DTSTAMP:20130102T120000Z
-UID:f106ecdf-c716-43ef-9d94-4e6f19f2fcfb
-SUMMARY:a test cal file
-DTSTART;VALUE=DATE:20130101
-DTEND;VALUE=DATE:20130102
-END:VEVENT
-END:VCALENDAR
\ No newline at end of file
diff --git a/tests/data/testcontact.vcf b/tests/data/testcontact.vcf
deleted file mode 100644
index 2af963d..0000000
--- a/tests/data/testcontact.vcf
+++ /dev/null
@@ -1,6 +0,0 @@
-BEGIN:VCARD
-VERSION:3.0
-PRODID:-//some random contact software//EN
-N:def;abc;;;
-FN:abc def
-END:VCARD
\ No newline at end of file
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index 4ef61fb..2febe52 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -97,13 +97,9 @@ class Preview extends \PHPUnit_Framework_TestCase {
public function txtBlacklist() {
$txt = 'random text file';
- $ics = file_get_contents(__DIR__ . '/../data/testcal.ics');
- $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf');
return array(
array('txt', $txt, false),
- array('ics', $ics, true),
- array('vcf', $vcf, true),
);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list