summaryrefslogtreecommitdiffstats
path: root/lib/private/preview.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-09-19 13:35:21 +0200
committerLukas Reschke <lukas@owncloud.com>2014-09-22 16:09:08 +0200
commitca3447fcdea878ade24caed4ad300697fc132d08 (patch)
tree2749ec20587207a007ac35e76d5d1d48712b5606 /lib/private/preview.php
parent831d34f084e4c2f6b13303f58e12a9f96eb10a74 (diff)
downloadnextcloud-server-ca3447fcdea878ade24caed4ad300697fc132d08.tar.gz
nextcloud-server-ca3447fcdea878ade24caed4ad300697fc132d08.zip
Add a configuration switch for enabled preview mimetypes
Diffstat (limited to 'lib/private/preview.php')
-rwxr-xr-xlib/private/preview.php47
1 files changed, 35 insertions, 12 deletions
diff --git a/lib/private/preview.php b/lib/private/preview.php
index b04cc2b8564..9d44d00e686 100755
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -13,7 +13,6 @@
*/
namespace OC;
-use OC\Files\Filesystem;
use OC\Preview\Provider;
use OCP\Files\NotFoundException;
@@ -23,7 +22,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';
require_once 'preview/tiff.php';
@@ -62,6 +60,7 @@ class Preview {
//preview providers
static private $providers = array();
static private $registeredProviders = array();
+ static private $enabledProviders = array();
/**
* @var \OCP\Files\FileInfo
@@ -669,12 +668,39 @@ class Preview {
}
/**
- * register a new preview provider to be used
+ * Register a new preview provider to be used
+ * @param $class
* @param array $options
- * @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
+ * - OC\Preview\Tiff
+ */
+ if(empty(self::$enabledProviders)) {
+ self::$enabledProviders = \OC::$server->getConfig()->getSystemValue('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);
+ }
}
/**
@@ -682,9 +708,8 @@ class Preview {
* @return void
*/
private static function initProviders() {
- if (!\OC_Config::getValue('enable_previews', true)) {
- $provider = new Preview\Unknown(array());
- self::$providers = array($provider->getMimeType() => $provider);
+ if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
+ self::$providers = array();
return;
}
@@ -698,12 +723,12 @@ class Preview {
/** @var $object Provider */
$object = new $class($options);
-
self::$providers[$object->getMimeType()] = $object;
}
$keys = array_map('strlen', array_keys(self::$providers));
array_multisort($keys, SORT_DESC, self::$providers);
+
}
public static function post_write($args) {
@@ -758,9 +783,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) {
/**
* @var \OC\Preview\Provider $provider
*/
class="sd"> * @author Julius Härtl <jus@bitgrid.net> * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Vincent Petry <vincent@nextcloud.com> * * @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/> * */ // load needed apps $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging']; OC_App::loadApps($RUNTIME_APPTYPES); OC_Util::obEnd(); \OC::$server->getSession()->close(); // Backends $authBackend = new OCA\DAV\Connector\PublicAuth( \OC::$server->getRequest(), \OC::$server->getShareManager(), \OC::$server->getSession() ); $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( \OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), \OC::$server->getUserSession(), \OC::$server->getMountManager(), \OC::$server->getTagManager(), \OC::$server->getRequest(), \OC::$server->getPreviewManager(), \OC::$server->getEventDispatcher(), \OC::$server->getL10N('dav') ); $requestUri = \OC::$server->getRequest()->getRequestUri(); $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin(); $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */ $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class); if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { // this is what is thrown when trying to access a non-existing share throw new \Sabre\DAV\Exception\NotAuthenticated(); } $share = $authBackend->getShare(); $owner = $share->getShareOwner(); $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; $fileId = $share->getNodeId(); // FIXME: should not add storage wrappers outside of preSetup, need to find a better way $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { return new \OC\Files\Storage\Wrapper\PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE]); }); \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); }); \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); OC_Util::tearDownFS(); OC_Util::setupFS($owner); $ownerView = new \OC\Files\View('/'. $owner . '/files'); $path = $ownerView->getPath($fileId); $fileInfo = $ownerView->getFileInfo($path); $linkCheckPlugin->setFileInfo($fileInfo); // If not readble (files_drop) enable the filesdrop plugin if (!$isReadable) { $filesDropPlugin->enable(); } $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); $filesDropPlugin->setView($view); return $view; }); $server->addPlugin($linkCheckPlugin); $server->addPlugin($filesDropPlugin); // And off we go! $server->exec();