@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | */ |
42 | 42 | 'instanceid' => '', |
43 | 43 | |
44 | - /** |
|
45 | - * The salt used to hash all passwords, auto-generated by the Nextcloud |
|
46 | - * installer. (There are also per-user salts.) If you lose this salt you lose |
|
47 | - * all your passwords. This example is for documentation only, and you should |
|
48 | - * never use it. |
|
49 | - * |
|
50 | - * @deprecated This salt is deprecated and only used for legacy-compatibility, |
|
51 | - * developers should *NOT* use this value for anything nowadays. |
|
52 | - * |
|
53 | - * 'passwordsalt' => 'd3c944a9af095aa08f', |
|
54 | - */ |
|
44 | + /** |
|
45 | + * The salt used to hash all passwords, auto-generated by the Nextcloud |
|
46 | + * installer. (There are also per-user salts.) If you lose this salt you lose |
|
47 | + * all your passwords. This example is for documentation only, and you should |
|
48 | + * never use it. |
|
49 | + * |
|
50 | + * @deprecated This salt is deprecated and only used for legacy-compatibility, |
|
51 | + * developers should *NOT* use this value for anything nowadays. |
|
52 | + * |
|
53 | + * 'passwordsalt' => 'd3c944a9af095aa08f', |
|
54 | + */ |
|
55 | 55 | 'passwordsalt' => '', |
56 | 56 | |
57 | 57 | /** |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | * Using TLS certificates where commonName=<IP address> is deprecated |
70 | 70 | */ |
71 | 71 | 'trusted_domains' => |
72 | - [ |
|
72 | + [ |
|
73 | 73 | 'demo.example.org', |
74 | 74 | 'otherdomain.example.org', |
75 | 75 | '10.111.112.113', |
76 | 76 | '[2001:db8::1]' |
77 | - ], |
|
77 | + ], |
|
78 | 78 | |
79 | 79 | |
80 | 80 | /** |
@@ -767,10 +767,10 @@ discard block |
||
767 | 767 | * - www.edri.org |
768 | 768 | */ |
769 | 769 | 'connectivity_check_domains' => [ |
770 | - 'www.nextcloud.com', |
|
771 | - 'www.startpage.com', |
|
772 | - 'www.eff.org', |
|
773 | - 'www.edri.org' |
|
770 | + 'www.nextcloud.com', |
|
771 | + 'www.startpage.com', |
|
772 | + 'www.eff.org', |
|
773 | + 'www.edri.org' |
|
774 | 774 | ], |
775 | 775 | |
776 | 776 | /** |
@@ -886,9 +886,9 @@ discard block |
||
886 | 886 | * Defaults to an empty array. |
887 | 887 | */ |
888 | 888 | 'log.condition' => [ |
889 | - 'shared_secret' => '57b58edb6637fe3059b3595cf9c41b9', |
|
890 | - 'users' => ['sample-user'], |
|
891 | - 'apps' => ['files'], |
|
889 | + 'shared_secret' => '57b58edb6637fe3059b3595cf9c41b9', |
|
890 | + 'users' => ['sample-user'], |
|
891 | + 'apps' => ['files'], |
|
892 | 892 | ], |
893 | 893 | |
894 | 894 | /** |
@@ -942,18 +942,18 @@ discard block |
||
942 | 942 | * - iOS client app id: ``1125420102`` |
943 | 943 | */ |
944 | 944 | 'customclient_desktop' => |
945 | - 'https://nextcloud.com/install/#install-clients', |
|
945 | + 'https://nextcloud.com/install/#install-clients', |
|
946 | 946 | 'customclient_android' => |
947 | - 'https://play.google.com/store/apps/details?id=com.nextcloud.client', |
|
947 | + 'https://play.google.com/store/apps/details?id=com.nextcloud.client', |
|
948 | 948 | 'customclient_ios' => |
949 | - 'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', |
|
949 | + 'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', |
|
950 | 950 | 'customclient_ios_appid' => |
951 | - '1125420102', |
|
951 | + '1125420102', |
|
952 | 952 | /** |
953 | - * Apps |
|
954 | - * |
|
955 | - * Options for the Apps folder, Apps store, and App code checker. |
|
956 | - */ |
|
953 | + * Apps |
|
954 | + * |
|
955 | + * Options for the Apps folder, Apps store, and App code checker. |
|
956 | + */ |
|
957 | 957 | |
958 | 958 | /** |
959 | 959 | * When enabled, admins may install apps from the Nextcloud app store. |
@@ -979,11 +979,11 @@ discard block |
||
979 | 979 | * indicates if a Web server can write files to that folder. |
980 | 980 | */ |
981 | 981 | 'apps_paths' => [ |
982 | - [ |
|
983 | - 'path'=> '/var/www/nextcloud/apps', |
|
984 | - 'url' => '/apps', |
|
985 | - 'writable' => true, |
|
986 | - ], |
|
982 | + [ |
|
983 | + 'path'=> '/var/www/nextcloud/apps', |
|
984 | + 'url' => '/apps', |
|
985 | + 'writable' => true, |
|
986 | + ], |
|
987 | 987 | ], |
988 | 988 | |
989 | 989 | /** |
@@ -1048,8 +1048,8 @@ discard block |
||
1048 | 1048 | * Defaults to ``''`` (empty string) |
1049 | 1049 | */ |
1050 | 1050 | 'preview_office_cl_parameters' => |
1051 | - ' --headless --nologo --nofirststartwizard --invisible --norestore '. |
|
1052 | - '--convert-to png --outdir ', |
|
1051 | + ' --headless --nologo --nofirststartwizard --invisible --norestore '. |
|
1052 | + '--convert-to png --outdir ', |
|
1053 | 1053 | |
1054 | 1054 | /** |
1055 | 1055 | * Only register providers that have been explicitly enabled |
@@ -1086,16 +1086,16 @@ discard block |
||
1086 | 1086 | * - OC\Preview\Krita |
1087 | 1087 | */ |
1088 | 1088 | 'enabledPreviewProviders' => [ |
1089 | - 'OC\Preview\PNG', |
|
1090 | - 'OC\Preview\JPEG', |
|
1091 | - 'OC\Preview\GIF', |
|
1092 | - 'OC\Preview\BMP', |
|
1093 | - 'OC\Preview\XBitmap', |
|
1094 | - 'OC\Preview\MP3', |
|
1095 | - 'OC\Preview\TXT', |
|
1096 | - 'OC\Preview\MarkDown', |
|
1097 | - 'OC\Preview\OpenDocument', |
|
1098 | - 'OC\Preview\Krita', |
|
1089 | + 'OC\Preview\PNG', |
|
1090 | + 'OC\Preview\JPEG', |
|
1091 | + 'OC\Preview\GIF', |
|
1092 | + 'OC\Preview\BMP', |
|
1093 | + 'OC\Preview\XBitmap', |
|
1094 | + 'OC\Preview\MP3', |
|
1095 | + 'OC\Preview\TXT', |
|
1096 | + 'OC\Preview\MarkDown', |
|
1097 | + 'OC\Preview\OpenDocument', |
|
1098 | + 'OC\Preview\Krita', |
|
1099 | 1099 | ], |
1100 | 1100 | |
1101 | 1101 | /** |
@@ -1171,11 +1171,11 @@ discard block |
||
1171 | 1171 | |
1172 | 1172 | /** |
1173 | 1173 | * Extra SSL options to be used for configuration. |
1174 | - * |
|
1174 | + * |
|
1175 | 1175 | * Defaults to an empty array. |
1176 | 1176 | */ |
1177 | 1177 | 'openssl' => [ |
1178 | - 'config' => '/absolute/location/of/openssl.cnf', |
|
1178 | + 'config' => '/absolute/location/of/openssl.cnf', |
|
1179 | 1179 | ], |
1180 | 1180 | |
1181 | 1181 | /** |
@@ -1223,11 +1223,11 @@ discard block |
||
1223 | 1223 | * for more information. |
1224 | 1224 | */ |
1225 | 1225 | 'redis' => [ |
1226 | - 'host' => 'localhost', // can also be a unix domain socket: '/tmp/redis.sock' |
|
1227 | - 'port' => 6379, |
|
1228 | - 'timeout' => 0.0, |
|
1229 | - 'password' => '', // Optional, if not defined no password will be used. |
|
1230 | - 'dbindex' => 0, // Optional, if undefined SELECT will not run and will use Redis Server's default DB Index. |
|
1226 | + 'host' => 'localhost', // can also be a unix domain socket: '/tmp/redis.sock' |
|
1227 | + 'port' => 6379, |
|
1228 | + 'timeout' => 0.0, |
|
1229 | + 'password' => '', // Optional, if not defined no password will be used. |
|
1230 | + 'dbindex' => 0, // Optional, if undefined SELECT will not run and will use Redis Server's default DB Index. |
|
1231 | 1231 | ], |
1232 | 1232 | |
1233 | 1233 | /** |
@@ -1256,14 +1256,14 @@ discard block |
||
1256 | 1256 | * https://github.com/phpredis/phpredis/commit/c5994f2a42b8a348af92d3acb4edff1328ad8ce1 |
1257 | 1257 | */ |
1258 | 1258 | 'redis.cluster' => [ |
1259 | - 'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required |
|
1260 | - 'localhost:7000', |
|
1261 | - 'localhost:7001', |
|
1262 | - ], |
|
1263 | - 'timeout' => 0.0, |
|
1264 | - 'read_timeout' => 0.0, |
|
1265 | - 'failover_mode' => \RedisCluster::FAILOVER_ERROR, |
|
1266 | - 'password' => '', // Optional, if not defined no password will be used. |
|
1259 | + 'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required |
|
1260 | + 'localhost:7000', |
|
1261 | + 'localhost:7001', |
|
1262 | + ], |
|
1263 | + 'timeout' => 0.0, |
|
1264 | + 'read_timeout' => 0.0, |
|
1265 | + 'failover_mode' => \RedisCluster::FAILOVER_ERROR, |
|
1266 | + 'password' => '', // Optional, if not defined no password will be used. |
|
1267 | 1267 | ], |
1268 | 1268 | |
1269 | 1269 | |
@@ -1271,35 +1271,35 @@ discard block |
||
1271 | 1271 | * Server details for one or more memcached servers to use for memory caching. |
1272 | 1272 | */ |
1273 | 1273 | 'memcached_servers' => [ |
1274 | - // hostname, port and optional weight. Also see: |
|
1275 | - // https://www.php.net/manual/en/memcached.addservers.php |
|
1276 | - // https://www.php.net/manual/en/memcached.addserver.php |
|
1277 | - ['localhost', 11211], |
|
1278 | - //array('other.host.local', 11211), |
|
1274 | + // hostname, port and optional weight. Also see: |
|
1275 | + // https://www.php.net/manual/en/memcached.addservers.php |
|
1276 | + // https://www.php.net/manual/en/memcached.addserver.php |
|
1277 | + ['localhost', 11211], |
|
1278 | + //array('other.host.local', 11211), |
|
1279 | 1279 | ], |
1280 | 1280 | |
1281 | 1281 | /** |
1282 | 1282 | * Connection options for memcached |
1283 | 1283 | */ |
1284 | 1284 | 'memcached_options' => [ |
1285 | - // Set timeouts to 50ms |
|
1286 | - \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
1287 | - \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
1288 | - \Memcached::OPT_SEND_TIMEOUT => 50, |
|
1289 | - \Memcached::OPT_RECV_TIMEOUT => 50, |
|
1290 | - \Memcached::OPT_POLL_TIMEOUT => 50, |
|
1285 | + // Set timeouts to 50ms |
|
1286 | + \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
1287 | + \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
1288 | + \Memcached::OPT_SEND_TIMEOUT => 50, |
|
1289 | + \Memcached::OPT_RECV_TIMEOUT => 50, |
|
1290 | + \Memcached::OPT_POLL_TIMEOUT => 50, |
|
1291 | 1291 | |
1292 | - // Enable compression |
|
1293 | - \Memcached::OPT_COMPRESSION => true, |
|
1292 | + // Enable compression |
|
1293 | + \Memcached::OPT_COMPRESSION => true, |
|
1294 | 1294 | |
1295 | - // Turn on consistent hashing |
|
1296 | - \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
1295 | + // Turn on consistent hashing |
|
1296 | + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
1297 | 1297 | |
1298 | - // Enable Binary Protocol |
|
1299 | - \Memcached::OPT_BINARY_PROTOCOL => true, |
|
1298 | + // Enable Binary Protocol |
|
1299 | + \Memcached::OPT_BINARY_PROTOCOL => true, |
|
1300 | 1300 | |
1301 | - // Binary serializer vill be enabled if the igbinary PECL module is available |
|
1302 | - //\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_IGBINARY, |
|
1301 | + // Binary serializer vill be enabled if the igbinary PECL module is available |
|
1302 | + //\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_IGBINARY, |
|
1303 | 1303 | ], |
1304 | 1304 | |
1305 | 1305 | |
@@ -1345,61 +1345,61 @@ discard block |
||
1345 | 1345 | * One way to test is applying for a trystack account at http://trystack.org/ |
1346 | 1346 | */ |
1347 | 1347 | 'objectstore' => [ |
1348 | - 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
1349 | - 'arguments' => [ |
|
1350 | - // trystack will use your facebook id as the user name |
|
1351 | - 'username' => 'facebook100000123456789', |
|
1352 | - // in the trystack dashboard go to user -> settings -> API Password to |
|
1353 | - // generate a password |
|
1354 | - 'password' => 'Secr3tPaSSWoRdt7', |
|
1355 | - // must already exist in the objectstore, name can be different |
|
1356 | - 'container' => 'nextcloud', |
|
1357 | - // prefix to prepend to the fileid, default is 'oid:urn:' |
|
1358 | - 'objectPrefix' => 'oid:urn:', |
|
1359 | - // create the container if it does not exist. default is false |
|
1360 | - 'autocreate' => true, |
|
1361 | - // required, dev-/trystack defaults to 'RegionOne' |
|
1362 | - 'region' => 'RegionOne', |
|
1363 | - // The Identity / Keystone endpoint |
|
1364 | - 'url' => 'http://8.21.28.222:5000/v2.0', |
|
1365 | - // required on dev-/trystack |
|
1366 | - 'tenantName' => 'facebook100000123456789', |
|
1367 | - // dev-/trystack uses swift by default, the lib defaults to 'cloudFiles' |
|
1368 | - // if omitted |
|
1369 | - 'serviceName' => 'swift', |
|
1370 | - // The Interface / url Type, optional |
|
1371 | - 'urlType' => 'internal' |
|
1372 | - ], |
|
1348 | + 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
1349 | + 'arguments' => [ |
|
1350 | + // trystack will use your facebook id as the user name |
|
1351 | + 'username' => 'facebook100000123456789', |
|
1352 | + // in the trystack dashboard go to user -> settings -> API Password to |
|
1353 | + // generate a password |
|
1354 | + 'password' => 'Secr3tPaSSWoRdt7', |
|
1355 | + // must already exist in the objectstore, name can be different |
|
1356 | + 'container' => 'nextcloud', |
|
1357 | + // prefix to prepend to the fileid, default is 'oid:urn:' |
|
1358 | + 'objectPrefix' => 'oid:urn:', |
|
1359 | + // create the container if it does not exist. default is false |
|
1360 | + 'autocreate' => true, |
|
1361 | + // required, dev-/trystack defaults to 'RegionOne' |
|
1362 | + 'region' => 'RegionOne', |
|
1363 | + // The Identity / Keystone endpoint |
|
1364 | + 'url' => 'http://8.21.28.222:5000/v2.0', |
|
1365 | + // required on dev-/trystack |
|
1366 | + 'tenantName' => 'facebook100000123456789', |
|
1367 | + // dev-/trystack uses swift by default, the lib defaults to 'cloudFiles' |
|
1368 | + // if omitted |
|
1369 | + 'serviceName' => 'swift', |
|
1370 | + // The Interface / url Type, optional |
|
1371 | + 'urlType' => 'internal' |
|
1372 | + ], |
|
1373 | 1373 | ], |
1374 | 1374 | |
1375 | 1375 | /** |
1376 | 1376 | * To use swift V3 |
1377 | 1377 | */ |
1378 | 1378 | 'objectstore' => [ |
1379 | - 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
1380 | - 'arguments' => [ |
|
1381 | - 'autocreate' => true, |
|
1382 | - 'user' => [ |
|
1383 | - 'name' => 'swift', |
|
1384 | - 'password' => 'swift', |
|
1385 | - 'domain' => [ |
|
1386 | - 'name' => 'default', |
|
1387 | - ], |
|
1388 | - ], |
|
1389 | - 'scope' => [ |
|
1390 | - 'project' => [ |
|
1391 | - 'name' => 'service', |
|
1392 | - 'domain' => [ |
|
1393 | - 'name' => 'default', |
|
1394 | - ], |
|
1395 | - ], |
|
1396 | - ], |
|
1397 | - 'tenantName' => 'service', |
|
1398 | - 'serviceName' => 'swift', |
|
1399 | - 'region' => 'regionOne', |
|
1400 | - 'url' => 'http://yourswifthost:5000/v3', |
|
1401 | - 'bucket' => 'nextcloud', |
|
1402 | - ], |
|
1379 | + 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
1380 | + 'arguments' => [ |
|
1381 | + 'autocreate' => true, |
|
1382 | + 'user' => [ |
|
1383 | + 'name' => 'swift', |
|
1384 | + 'password' => 'swift', |
|
1385 | + 'domain' => [ |
|
1386 | + 'name' => 'default', |
|
1387 | + ], |
|
1388 | + ], |
|
1389 | + 'scope' => [ |
|
1390 | + 'project' => [ |
|
1391 | + 'name' => 'service', |
|
1392 | + 'domain' => [ |
|
1393 | + 'name' => 'default', |
|
1394 | + ], |
|
1395 | + ], |
|
1396 | + ], |
|
1397 | + 'tenantName' => 'service', |
|
1398 | + 'serviceName' => 'swift', |
|
1399 | + 'region' => 'regionOne', |
|
1400 | + 'url' => 'http://yourswifthost:5000/v3', |
|
1401 | + 'bucket' => 'nextcloud', |
|
1402 | + ], |
|
1403 | 1403 | ], |
1404 | 1404 | |
1405 | 1405 | /** |
@@ -1480,8 +1480,8 @@ discard block |
||
1480 | 1480 | * encryption in MySQL or specify a custom wait timeout on a cheap hoster. |
1481 | 1481 | */ |
1482 | 1482 | 'dbdriveroptions' => [ |
1483 | - PDO::MYSQL_ATTR_SSL_CA => '/file/path/to/ca_cert.pem', |
|
1484 | - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET wait_timeout = 28800' |
|
1483 | + PDO::MYSQL_ATTR_SSL_CA => '/file/path/to/ca_cert.pem', |
|
1484 | + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET wait_timeout = 28800' |
|
1485 | 1485 | ], |
1486 | 1486 | |
1487 | 1487 | /** |
@@ -1538,10 +1538,10 @@ discard block |
||
1538 | 1538 | * - pgsql (PostgreSQL) |
1539 | 1539 | */ |
1540 | 1540 | 'supportedDatabases' => [ |
1541 | - 'sqlite', |
|
1542 | - 'mysql', |
|
1543 | - 'pgsql', |
|
1544 | - 'oci', |
|
1541 | + 'sqlite', |
|
1542 | + 'mysql', |
|
1543 | + 'pgsql', |
|
1544 | + 'oci', |
|
1545 | 1545 | ], |
1546 | 1546 | |
1547 | 1547 | /** |
@@ -1882,8 +1882,8 @@ discard block |
||
1882 | 1882 | * WARNING: only use this if you know what you are doing |
1883 | 1883 | */ |
1884 | 1884 | 'csrf.optout' => [ |
1885 | - '/^WebDAVFS/', // OS X Finder |
|
1886 | - '/^Microsoft-WebDAV-MiniRedir/', // Windows webdav drive |
|
1885 | + '/^WebDAVFS/', // OS X Finder |
|
1886 | + '/^Microsoft-WebDAV-MiniRedir/', // Windows webdav drive |
|
1887 | 1887 | ], |
1888 | 1888 | |
1889 | 1889 | /** |
@@ -43,392 +43,392 @@ |
||
43 | 43 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
44 | 44 | |
45 | 45 | class PreviewManager implements IPreview { |
46 | - /** @var IConfig */ |
|
47 | - protected $config; |
|
48 | - |
|
49 | - /** @var IRootFolder */ |
|
50 | - protected $rootFolder; |
|
51 | - |
|
52 | - /** @var IAppData */ |
|
53 | - protected $appData; |
|
54 | - |
|
55 | - /** @var EventDispatcherInterface */ |
|
56 | - protected $eventDispatcher; |
|
57 | - |
|
58 | - /** @var Generator */ |
|
59 | - private $generator; |
|
60 | - |
|
61 | - /** @var GeneratorHelper */ |
|
62 | - private $helper; |
|
63 | - |
|
64 | - /** @var bool */ |
|
65 | - protected $providerListDirty = false; |
|
66 | - |
|
67 | - /** @var bool */ |
|
68 | - protected $registeredCoreProviders = false; |
|
69 | - |
|
70 | - /** @var array */ |
|
71 | - protected $providers = []; |
|
72 | - |
|
73 | - /** @var array mime type => support status */ |
|
74 | - protected $mimeTypeSupportMap = []; |
|
75 | - |
|
76 | - /** @var array */ |
|
77 | - protected $defaultProviders; |
|
78 | - |
|
79 | - /** @var string */ |
|
80 | - protected $userId; |
|
81 | - |
|
82 | - /** |
|
83 | - * PreviewManager constructor. |
|
84 | - * |
|
85 | - * @param IConfig $config |
|
86 | - * @param IRootFolder $rootFolder |
|
87 | - * @param IAppData $appData |
|
88 | - * @param EventDispatcherInterface $eventDispatcher |
|
89 | - * @param string $userId |
|
90 | - */ |
|
91 | - public function __construct(IConfig $config, |
|
92 | - IRootFolder $rootFolder, |
|
93 | - IAppData $appData, |
|
94 | - EventDispatcherInterface $eventDispatcher, |
|
95 | - GeneratorHelper $helper, |
|
96 | - $userId) { |
|
97 | - $this->config = $config; |
|
98 | - $this->rootFolder = $rootFolder; |
|
99 | - $this->appData = $appData; |
|
100 | - $this->eventDispatcher = $eventDispatcher; |
|
101 | - $this->helper = $helper; |
|
102 | - $this->userId = $userId; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * In order to improve lazy loading a closure can be registered which will be |
|
107 | - * called in case preview providers are actually requested |
|
108 | - * |
|
109 | - * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2 |
|
110 | - * |
|
111 | - * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
112 | - * @param \Closure $callable |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - public function registerProvider($mimeTypeRegex, \Closure $callable) { |
|
116 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
117 | - return; |
|
118 | - } |
|
119 | - |
|
120 | - if (!isset($this->providers[$mimeTypeRegex])) { |
|
121 | - $this->providers[$mimeTypeRegex] = []; |
|
122 | - } |
|
123 | - $this->providers[$mimeTypeRegex][] = $callable; |
|
124 | - $this->providerListDirty = true; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Get all providers |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - public function getProviders() { |
|
132 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
133 | - return []; |
|
134 | - } |
|
135 | - |
|
136 | - $this->registerCoreProviders(); |
|
137 | - if ($this->providerListDirty) { |
|
138 | - $keys = array_map('strlen', array_keys($this->providers)); |
|
139 | - array_multisort($keys, SORT_DESC, $this->providers); |
|
140 | - $this->providerListDirty = false; |
|
141 | - } |
|
142 | - |
|
143 | - return $this->providers; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Does the manager have any providers |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public function hasProviders() { |
|
151 | - $this->registerCoreProviders(); |
|
152 | - return !empty($this->providers); |
|
153 | - } |
|
154 | - |
|
155 | - private function getGenerator(): Generator { |
|
156 | - if ($this->generator === null) { |
|
157 | - $this->generator = new Generator( |
|
158 | - $this->config, |
|
159 | - $this, |
|
160 | - $this->appData, |
|
161 | - new GeneratorHelper( |
|
162 | - $this->rootFolder, |
|
163 | - $this->config |
|
164 | - ), |
|
165 | - $this->eventDispatcher |
|
166 | - ); |
|
167 | - } |
|
168 | - return $this->generator; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Returns a preview of a file |
|
173 | - * |
|
174 | - * The cache is searched first and if nothing usable was found then a preview is |
|
175 | - * generated by one of the providers |
|
176 | - * |
|
177 | - * @param File $file |
|
178 | - * @param int $width |
|
179 | - * @param int $height |
|
180 | - * @param bool $crop |
|
181 | - * @param string $mode |
|
182 | - * @param string $mimeType |
|
183 | - * @return ISimpleFile |
|
184 | - * @throws NotFoundException |
|
185 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
186 | - * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
187 | - */ |
|
188 | - public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { |
|
189 | - return $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Generates previews of a file |
|
194 | - * |
|
195 | - * @param File $file |
|
196 | - * @param array $specifications |
|
197 | - * @param string $mimeType |
|
198 | - * @return ISimpleFile the last preview that was generated |
|
199 | - * @throws NotFoundException |
|
200 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
201 | - * @since 19.0.0 |
|
202 | - */ |
|
203 | - public function generatePreviews(File $file, array $specifications, $mimeType = null) { |
|
204 | - return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * returns true if the passed mime type is supported |
|
209 | - * |
|
210 | - * @param string $mimeType |
|
211 | - * @return boolean |
|
212 | - */ |
|
213 | - public function isMimeSupported($mimeType = '*') { |
|
214 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
215 | - return false; |
|
216 | - } |
|
217 | - |
|
218 | - if (isset($this->mimeTypeSupportMap[$mimeType])) { |
|
219 | - return $this->mimeTypeSupportMap[$mimeType]; |
|
220 | - } |
|
221 | - |
|
222 | - $this->registerCoreProviders(); |
|
223 | - $providerMimeTypes = array_keys($this->providers); |
|
224 | - foreach ($providerMimeTypes as $supportedMimeType) { |
|
225 | - if (preg_match($supportedMimeType, $mimeType)) { |
|
226 | - $this->mimeTypeSupportMap[$mimeType] = true; |
|
227 | - return true; |
|
228 | - } |
|
229 | - } |
|
230 | - $this->mimeTypeSupportMap[$mimeType] = false; |
|
231 | - return false; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Check if a preview can be generated for a file |
|
236 | - * |
|
237 | - * @param \OCP\Files\FileInfo $file |
|
238 | - * @return bool |
|
239 | - */ |
|
240 | - public function isAvailable(\OCP\Files\FileInfo $file) { |
|
241 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
242 | - return false; |
|
243 | - } |
|
244 | - |
|
245 | - $this->registerCoreProviders(); |
|
246 | - if (!$this->isMimeSupported($file->getMimetype())) { |
|
247 | - return false; |
|
248 | - } |
|
249 | - |
|
250 | - $mount = $file->getMountPoint(); |
|
251 | - if ($mount and !$mount->getOption('previews', true)) { |
|
252 | - return false; |
|
253 | - } |
|
254 | - |
|
255 | - foreach ($this->providers as $supportedMimeType => $providers) { |
|
256 | - if (preg_match($supportedMimeType, $file->getMimetype())) { |
|
257 | - foreach ($providers as $providerClosure) { |
|
258 | - $provider = $this->helper->getProvider($providerClosure); |
|
259 | - if (!($provider instanceof IProviderV2)) { |
|
260 | - continue; |
|
261 | - } |
|
262 | - |
|
263 | - if ($provider->isAvailable($file)) { |
|
264 | - return true; |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - return false; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * List of enabled default providers |
|
274 | - * |
|
275 | - * The following providers are enabled by default: |
|
276 | - * - OC\Preview\PNG |
|
277 | - * - OC\Preview\JPEG |
|
278 | - * - OC\Preview\GIF |
|
279 | - * - OC\Preview\BMP |
|
280 | - * - OC\Preview\XBitmap |
|
281 | - * - OC\Preview\MarkDown |
|
282 | - * - OC\Preview\MP3 |
|
283 | - * - OC\Preview\TXT |
|
284 | - * |
|
285 | - * The following providers are disabled by default due to performance or privacy concerns: |
|
286 | - * - OC\Preview\Font |
|
287 | - * - OC\Preview\HEIC |
|
288 | - * - OC\Preview\Illustrator |
|
289 | - * - OC\Preview\Movie |
|
290 | - * - OC\Preview\MSOfficeDoc |
|
291 | - * - OC\Preview\MSOffice2003 |
|
292 | - * - OC\Preview\MSOffice2007 |
|
293 | - * - OC\Preview\OpenDocument |
|
294 | - * - OC\Preview\PDF |
|
295 | - * - OC\Preview\Photoshop |
|
296 | - * - OC\Preview\Postscript |
|
297 | - * - OC\Preview\StarOffice |
|
298 | - * - OC\Preview\SVG |
|
299 | - * - OC\Preview\TIFF |
|
300 | - * |
|
301 | - * @return array |
|
302 | - */ |
|
303 | - protected function getEnabledDefaultProvider() { |
|
304 | - if ($this->defaultProviders !== null) { |
|
305 | - return $this->defaultProviders; |
|
306 | - } |
|
307 | - |
|
308 | - $imageProviders = [ |
|
309 | - Preview\PNG::class, |
|
310 | - Preview\JPEG::class, |
|
311 | - Preview\GIF::class, |
|
312 | - Preview\BMP::class, |
|
313 | - Preview\XBitmap::class, |
|
314 | - Preview\Krita::class, |
|
315 | - Preview\WebP::class, |
|
316 | - ]; |
|
317 | - |
|
318 | - $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ |
|
319 | - Preview\MarkDown::class, |
|
320 | - Preview\MP3::class, |
|
321 | - Preview\TXT::class, |
|
322 | - Preview\OpenDocument::class, |
|
323 | - ], $imageProviders)); |
|
324 | - |
|
325 | - if (in_array(Preview\Image::class, $this->defaultProviders)) { |
|
326 | - $this->defaultProviders = array_merge($this->defaultProviders, $imageProviders); |
|
327 | - } |
|
328 | - $this->defaultProviders = array_unique($this->defaultProviders); |
|
329 | - return $this->defaultProviders; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Register the default providers (if enabled) |
|
334 | - * |
|
335 | - * @param string $class |
|
336 | - * @param string $mimeType |
|
337 | - */ |
|
338 | - protected function registerCoreProvider($class, $mimeType, $options = []) { |
|
339 | - if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
340 | - $this->registerProvider($mimeType, function () use ($class, $options) { |
|
341 | - return new $class($options); |
|
342 | - }); |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Register the default providers (if enabled) |
|
348 | - */ |
|
349 | - protected function registerCoreProviders() { |
|
350 | - if ($this->registeredCoreProviders) { |
|
351 | - return; |
|
352 | - } |
|
353 | - $this->registeredCoreProviders = true; |
|
354 | - |
|
355 | - $this->registerCoreProvider(Preview\TXT::class, '/text\/plain/'); |
|
356 | - $this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/'); |
|
357 | - $this->registerCoreProvider(Preview\PNG::class, '/image\/png/'); |
|
358 | - $this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/'); |
|
359 | - $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/'); |
|
360 | - $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); |
|
361 | - $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); |
|
362 | - $this->registerCoreProvider(Preview\WebP::class, '/image\/webp/'); |
|
363 | - $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); |
|
364 | - $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); |
|
365 | - $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
366 | - |
|
367 | - // SVG, Office and Bitmap require imagick |
|
368 | - if (extension_loaded('imagick')) { |
|
369 | - $checkImagick = new \Imagick(); |
|
370 | - |
|
371 | - $imagickProviders = [ |
|
372 | - 'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class], |
|
373 | - 'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class], |
|
374 | - 'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class], |
|
375 | - 'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class], |
|
376 | - 'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class], |
|
377 | - 'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class], |
|
378 | - 'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class], |
|
379 | - 'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class], |
|
380 | - 'TGA' => ['mimetype' => '/image\/t(ar)?ga/', 'class' => Preview\TGA::class], |
|
381 | - 'SGI' => ['mimetype' => '/image\/sgi/', 'class' => Preview\SGI::class], |
|
382 | - ]; |
|
383 | - |
|
384 | - foreach ($imagickProviders as $queryFormat => $provider) { |
|
385 | - $class = $provider['class']; |
|
386 | - if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
387 | - continue; |
|
388 | - } |
|
389 | - |
|
390 | - if (count($checkImagick->queryFormats($queryFormat)) === 1) { |
|
391 | - $this->registerCoreProvider($class, $provider['mimetype']); |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - if (count($checkImagick->queryFormats('PDF')) === 1) { |
|
396 | - if (\OC_Helper::is_function_enabled('shell_exec')) { |
|
397 | - $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null)); |
|
398 | - |
|
399 | - if (!$officeFound) { |
|
400 | - //let's see if there is libreoffice or openoffice on this machine |
|
401 | - $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
402 | - $officeFound = !empty($whichLibreOffice); |
|
403 | - if (!$officeFound) { |
|
404 | - $whichOpenOffice = shell_exec('command -v openoffice'); |
|
405 | - $officeFound = !empty($whichOpenOffice); |
|
406 | - } |
|
407 | - } |
|
408 | - |
|
409 | - if ($officeFound) { |
|
410 | - $this->registerCoreProvider(Preview\MSOfficeDoc::class, '/application\/msword/'); |
|
411 | - $this->registerCoreProvider(Preview\MSOffice2003::class, '/application\/vnd.ms-.*/'); |
|
412 | - $this->registerCoreProvider(Preview\MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/'); |
|
413 | - $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
414 | - $this->registerCoreProvider(Preview\StarOffice::class, '/application\/vnd.sun.xml.*/'); |
|
415 | - } |
|
416 | - } |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - // Video requires avconv or ffmpeg |
|
421 | - if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) { |
|
422 | - $avconvBinary = \OC_Helper::findBinaryPath('avconv'); |
|
423 | - $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); |
|
424 | - |
|
425 | - if ($avconvBinary || $ffmpegBinary) { |
|
426 | - // FIXME // a bit hacky but didn't want to use subclasses |
|
427 | - \OC\Preview\Movie::$avconvBinary = $avconvBinary; |
|
428 | - \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; |
|
429 | - |
|
430 | - $this->registerCoreProvider(Preview\Movie::class, '/video\/.*/'); |
|
431 | - } |
|
432 | - } |
|
433 | - } |
|
46 | + /** @var IConfig */ |
|
47 | + protected $config; |
|
48 | + |
|
49 | + /** @var IRootFolder */ |
|
50 | + protected $rootFolder; |
|
51 | + |
|
52 | + /** @var IAppData */ |
|
53 | + protected $appData; |
|
54 | + |
|
55 | + /** @var EventDispatcherInterface */ |
|
56 | + protected $eventDispatcher; |
|
57 | + |
|
58 | + /** @var Generator */ |
|
59 | + private $generator; |
|
60 | + |
|
61 | + /** @var GeneratorHelper */ |
|
62 | + private $helper; |
|
63 | + |
|
64 | + /** @var bool */ |
|
65 | + protected $providerListDirty = false; |
|
66 | + |
|
67 | + /** @var bool */ |
|
68 | + protected $registeredCoreProviders = false; |
|
69 | + |
|
70 | + /** @var array */ |
|
71 | + protected $providers = []; |
|
72 | + |
|
73 | + /** @var array mime type => support status */ |
|
74 | + protected $mimeTypeSupportMap = []; |
|
75 | + |
|
76 | + /** @var array */ |
|
77 | + protected $defaultProviders; |
|
78 | + |
|
79 | + /** @var string */ |
|
80 | + protected $userId; |
|
81 | + |
|
82 | + /** |
|
83 | + * PreviewManager constructor. |
|
84 | + * |
|
85 | + * @param IConfig $config |
|
86 | + * @param IRootFolder $rootFolder |
|
87 | + * @param IAppData $appData |
|
88 | + * @param EventDispatcherInterface $eventDispatcher |
|
89 | + * @param string $userId |
|
90 | + */ |
|
91 | + public function __construct(IConfig $config, |
|
92 | + IRootFolder $rootFolder, |
|
93 | + IAppData $appData, |
|
94 | + EventDispatcherInterface $eventDispatcher, |
|
95 | + GeneratorHelper $helper, |
|
96 | + $userId) { |
|
97 | + $this->config = $config; |
|
98 | + $this->rootFolder = $rootFolder; |
|
99 | + $this->appData = $appData; |
|
100 | + $this->eventDispatcher = $eventDispatcher; |
|
101 | + $this->helper = $helper; |
|
102 | + $this->userId = $userId; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * In order to improve lazy loading a closure can be registered which will be |
|
107 | + * called in case preview providers are actually requested |
|
108 | + * |
|
109 | + * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2 |
|
110 | + * |
|
111 | + * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
112 | + * @param \Closure $callable |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + public function registerProvider($mimeTypeRegex, \Closure $callable) { |
|
116 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
117 | + return; |
|
118 | + } |
|
119 | + |
|
120 | + if (!isset($this->providers[$mimeTypeRegex])) { |
|
121 | + $this->providers[$mimeTypeRegex] = []; |
|
122 | + } |
|
123 | + $this->providers[$mimeTypeRegex][] = $callable; |
|
124 | + $this->providerListDirty = true; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Get all providers |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + public function getProviders() { |
|
132 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
133 | + return []; |
|
134 | + } |
|
135 | + |
|
136 | + $this->registerCoreProviders(); |
|
137 | + if ($this->providerListDirty) { |
|
138 | + $keys = array_map('strlen', array_keys($this->providers)); |
|
139 | + array_multisort($keys, SORT_DESC, $this->providers); |
|
140 | + $this->providerListDirty = false; |
|
141 | + } |
|
142 | + |
|
143 | + return $this->providers; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Does the manager have any providers |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public function hasProviders() { |
|
151 | + $this->registerCoreProviders(); |
|
152 | + return !empty($this->providers); |
|
153 | + } |
|
154 | + |
|
155 | + private function getGenerator(): Generator { |
|
156 | + if ($this->generator === null) { |
|
157 | + $this->generator = new Generator( |
|
158 | + $this->config, |
|
159 | + $this, |
|
160 | + $this->appData, |
|
161 | + new GeneratorHelper( |
|
162 | + $this->rootFolder, |
|
163 | + $this->config |
|
164 | + ), |
|
165 | + $this->eventDispatcher |
|
166 | + ); |
|
167 | + } |
|
168 | + return $this->generator; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Returns a preview of a file |
|
173 | + * |
|
174 | + * The cache is searched first and if nothing usable was found then a preview is |
|
175 | + * generated by one of the providers |
|
176 | + * |
|
177 | + * @param File $file |
|
178 | + * @param int $width |
|
179 | + * @param int $height |
|
180 | + * @param bool $crop |
|
181 | + * @param string $mode |
|
182 | + * @param string $mimeType |
|
183 | + * @return ISimpleFile |
|
184 | + * @throws NotFoundException |
|
185 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
186 | + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
187 | + */ |
|
188 | + public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { |
|
189 | + return $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Generates previews of a file |
|
194 | + * |
|
195 | + * @param File $file |
|
196 | + * @param array $specifications |
|
197 | + * @param string $mimeType |
|
198 | + * @return ISimpleFile the last preview that was generated |
|
199 | + * @throws NotFoundException |
|
200 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
201 | + * @since 19.0.0 |
|
202 | + */ |
|
203 | + public function generatePreviews(File $file, array $specifications, $mimeType = null) { |
|
204 | + return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * returns true if the passed mime type is supported |
|
209 | + * |
|
210 | + * @param string $mimeType |
|
211 | + * @return boolean |
|
212 | + */ |
|
213 | + public function isMimeSupported($mimeType = '*') { |
|
214 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
215 | + return false; |
|
216 | + } |
|
217 | + |
|
218 | + if (isset($this->mimeTypeSupportMap[$mimeType])) { |
|
219 | + return $this->mimeTypeSupportMap[$mimeType]; |
|
220 | + } |
|
221 | + |
|
222 | + $this->registerCoreProviders(); |
|
223 | + $providerMimeTypes = array_keys($this->providers); |
|
224 | + foreach ($providerMimeTypes as $supportedMimeType) { |
|
225 | + if (preg_match($supportedMimeType, $mimeType)) { |
|
226 | + $this->mimeTypeSupportMap[$mimeType] = true; |
|
227 | + return true; |
|
228 | + } |
|
229 | + } |
|
230 | + $this->mimeTypeSupportMap[$mimeType] = false; |
|
231 | + return false; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Check if a preview can be generated for a file |
|
236 | + * |
|
237 | + * @param \OCP\Files\FileInfo $file |
|
238 | + * @return bool |
|
239 | + */ |
|
240 | + public function isAvailable(\OCP\Files\FileInfo $file) { |
|
241 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
242 | + return false; |
|
243 | + } |
|
244 | + |
|
245 | + $this->registerCoreProviders(); |
|
246 | + if (!$this->isMimeSupported($file->getMimetype())) { |
|
247 | + return false; |
|
248 | + } |
|
249 | + |
|
250 | + $mount = $file->getMountPoint(); |
|
251 | + if ($mount and !$mount->getOption('previews', true)) { |
|
252 | + return false; |
|
253 | + } |
|
254 | + |
|
255 | + foreach ($this->providers as $supportedMimeType => $providers) { |
|
256 | + if (preg_match($supportedMimeType, $file->getMimetype())) { |
|
257 | + foreach ($providers as $providerClosure) { |
|
258 | + $provider = $this->helper->getProvider($providerClosure); |
|
259 | + if (!($provider instanceof IProviderV2)) { |
|
260 | + continue; |
|
261 | + } |
|
262 | + |
|
263 | + if ($provider->isAvailable($file)) { |
|
264 | + return true; |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + return false; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * List of enabled default providers |
|
274 | + * |
|
275 | + * The following providers are enabled by default: |
|
276 | + * - OC\Preview\PNG |
|
277 | + * - OC\Preview\JPEG |
|
278 | + * - OC\Preview\GIF |
|
279 | + * - OC\Preview\BMP |
|
280 | + * - OC\Preview\XBitmap |
|
281 | + * - OC\Preview\MarkDown |
|
282 | + * - OC\Preview\MP3 |
|
283 | + * - OC\Preview\TXT |
|
284 | + * |
|
285 | + * The following providers are disabled by default due to performance or privacy concerns: |
|
286 | + * - OC\Preview\Font |
|
287 | + * - OC\Preview\HEIC |
|
288 | + * - OC\Preview\Illustrator |
|
289 | + * - OC\Preview\Movie |
|
290 | + * - OC\Preview\MSOfficeDoc |
|
291 | + * - OC\Preview\MSOffice2003 |
|
292 | + * - OC\Preview\MSOffice2007 |
|
293 | + * - OC\Preview\OpenDocument |
|
294 | + * - OC\Preview\PDF |
|
295 | + * - OC\Preview\Photoshop |
|
296 | + * - OC\Preview\Postscript |
|
297 | + * - OC\Preview\StarOffice |
|
298 | + * - OC\Preview\SVG |
|
299 | + * - OC\Preview\TIFF |
|
300 | + * |
|
301 | + * @return array |
|
302 | + */ |
|
303 | + protected function getEnabledDefaultProvider() { |
|
304 | + if ($this->defaultProviders !== null) { |
|
305 | + return $this->defaultProviders; |
|
306 | + } |
|
307 | + |
|
308 | + $imageProviders = [ |
|
309 | + Preview\PNG::class, |
|
310 | + Preview\JPEG::class, |
|
311 | + Preview\GIF::class, |
|
312 | + Preview\BMP::class, |
|
313 | + Preview\XBitmap::class, |
|
314 | + Preview\Krita::class, |
|
315 | + Preview\WebP::class, |
|
316 | + ]; |
|
317 | + |
|
318 | + $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ |
|
319 | + Preview\MarkDown::class, |
|
320 | + Preview\MP3::class, |
|
321 | + Preview\TXT::class, |
|
322 | + Preview\OpenDocument::class, |
|
323 | + ], $imageProviders)); |
|
324 | + |
|
325 | + if (in_array(Preview\Image::class, $this->defaultProviders)) { |
|
326 | + $this->defaultProviders = array_merge($this->defaultProviders, $imageProviders); |
|
327 | + } |
|
328 | + $this->defaultProviders = array_unique($this->defaultProviders); |
|
329 | + return $this->defaultProviders; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Register the default providers (if enabled) |
|
334 | + * |
|
335 | + * @param string $class |
|
336 | + * @param string $mimeType |
|
337 | + */ |
|
338 | + protected function registerCoreProvider($class, $mimeType, $options = []) { |
|
339 | + if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
340 | + $this->registerProvider($mimeType, function () use ($class, $options) { |
|
341 | + return new $class($options); |
|
342 | + }); |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Register the default providers (if enabled) |
|
348 | + */ |
|
349 | + protected function registerCoreProviders() { |
|
350 | + if ($this->registeredCoreProviders) { |
|
351 | + return; |
|
352 | + } |
|
353 | + $this->registeredCoreProviders = true; |
|
354 | + |
|
355 | + $this->registerCoreProvider(Preview\TXT::class, '/text\/plain/'); |
|
356 | + $this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/'); |
|
357 | + $this->registerCoreProvider(Preview\PNG::class, '/image\/png/'); |
|
358 | + $this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/'); |
|
359 | + $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/'); |
|
360 | + $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); |
|
361 | + $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); |
|
362 | + $this->registerCoreProvider(Preview\WebP::class, '/image\/webp/'); |
|
363 | + $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); |
|
364 | + $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); |
|
365 | + $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
366 | + |
|
367 | + // SVG, Office and Bitmap require imagick |
|
368 | + if (extension_loaded('imagick')) { |
|
369 | + $checkImagick = new \Imagick(); |
|
370 | + |
|
371 | + $imagickProviders = [ |
|
372 | + 'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class], |
|
373 | + 'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class], |
|
374 | + 'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class], |
|
375 | + 'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class], |
|
376 | + 'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class], |
|
377 | + 'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class], |
|
378 | + 'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class], |
|
379 | + 'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class], |
|
380 | + 'TGA' => ['mimetype' => '/image\/t(ar)?ga/', 'class' => Preview\TGA::class], |
|
381 | + 'SGI' => ['mimetype' => '/image\/sgi/', 'class' => Preview\SGI::class], |
|
382 | + ]; |
|
383 | + |
|
384 | + foreach ($imagickProviders as $queryFormat => $provider) { |
|
385 | + $class = $provider['class']; |
|
386 | + if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
387 | + continue; |
|
388 | + } |
|
389 | + |
|
390 | + if (count($checkImagick->queryFormats($queryFormat)) === 1) { |
|
391 | + $this->registerCoreProvider($class, $provider['mimetype']); |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + if (count($checkImagick->queryFormats('PDF')) === 1) { |
|
396 | + if (\OC_Helper::is_function_enabled('shell_exec')) { |
|
397 | + $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null)); |
|
398 | + |
|
399 | + if (!$officeFound) { |
|
400 | + //let's see if there is libreoffice or openoffice on this machine |
|
401 | + $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
402 | + $officeFound = !empty($whichLibreOffice); |
|
403 | + if (!$officeFound) { |
|
404 | + $whichOpenOffice = shell_exec('command -v openoffice'); |
|
405 | + $officeFound = !empty($whichOpenOffice); |
|
406 | + } |
|
407 | + } |
|
408 | + |
|
409 | + if ($officeFound) { |
|
410 | + $this->registerCoreProvider(Preview\MSOfficeDoc::class, '/application\/msword/'); |
|
411 | + $this->registerCoreProvider(Preview\MSOffice2003::class, '/application\/vnd.ms-.*/'); |
|
412 | + $this->registerCoreProvider(Preview\MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/'); |
|
413 | + $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
414 | + $this->registerCoreProvider(Preview\StarOffice::class, '/application\/vnd.sun.xml.*/'); |
|
415 | + } |
|
416 | + } |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + // Video requires avconv or ffmpeg |
|
421 | + if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) { |
|
422 | + $avconvBinary = \OC_Helper::findBinaryPath('avconv'); |
|
423 | + $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); |
|
424 | + |
|
425 | + if ($avconvBinary || $ffmpegBinary) { |
|
426 | + // FIXME // a bit hacky but didn't want to use subclasses |
|
427 | + \OC\Preview\Movie::$avconvBinary = $avconvBinary; |
|
428 | + \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; |
|
429 | + |
|
430 | + $this->registerCoreProvider(Preview\Movie::class, '/video\/.*/'); |
|
431 | + } |
|
432 | + } |
|
433 | + } |
|
434 | 434 | } |