2013-08-07 18:38:57 +04:00
|
|
|
<?php
|
2019-12-19 15:16:31 +03:00
|
|
|
|
2019-11-28 17:47:13 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-19 15:16:31 +03:00
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Andreas Fischer <bantu@owncloud.com>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-19 15:16:31 +03:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Hendrik Leppelsack <hendrik@leppelsack.de>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Jens-Christian Fischer <jens-christian.fischer@switch.ch>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Magnus Walbeck <mw@mwalbeck.org>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Tanghus <thomas@tanghus.net>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Xheni Myrtaj <myrtajxheni@gmail.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
2013-08-07 18:38:57 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
namespace OC\Files\Type;
|
|
|
|
|
2015-04-09 16:19:57 +03:00
|
|
|
use OCP\Files\IMimeTypeDetector;
|
2019-12-08 19:20:50 +03:00
|
|
|
use OCP\ILogger;
|
2015-07-14 09:43:14 +03:00
|
|
|
use OCP\IURLGenerator;
|
2015-04-09 16:19:57 +03:00
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
/**
|
|
|
|
* Class Detection
|
|
|
|
*
|
|
|
|
* Mimetype detection
|
|
|
|
*
|
|
|
|
* @package OC\Files\Type
|
|
|
|
*/
|
2015-04-09 16:19:57 +03:00
|
|
|
class Detection implements IMimeTypeDetector {
|
2019-12-09 00:16:25 +03:00
|
|
|
private const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';
|
|
|
|
private const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json';
|
2019-12-08 19:20:50 +03:00
|
|
|
|
2015-07-15 11:04:34 +03:00
|
|
|
protected $mimetypes = [];
|
|
|
|
protected $secureMimeTypes = [];
|
2013-08-07 18:38:57 +04:00
|
|
|
|
2015-04-09 16:19:57 +03:00
|
|
|
protected $mimetypeIcons = [];
|
|
|
|
/** @var string[] */
|
2015-07-14 09:43:14 +03:00
|
|
|
protected $mimeTypeAlias = [];
|
2015-04-09 16:19:57 +03:00
|
|
|
|
2015-07-14 09:43:14 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
2015-04-09 16:19:57 +03:00
|
|
|
|
2019-12-08 19:20:50 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
2015-07-20 13:28:36 +03:00
|
|
|
/** @var string */
|
2015-09-08 13:17:57 +03:00
|
|
|
private $customConfigDir;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $defaultConfigDir;
|
2015-07-20 13:28:36 +03:00
|
|
|
|
2015-07-14 09:43:14 +03:00
|
|
|
/**
|
|
|
|
* @param IURLGenerator $urlGenerator
|
2019-12-08 19:20:50 +03:00
|
|
|
* @param ILogger $logger
|
2015-09-08 13:17:57 +03:00
|
|
|
* @param string $customConfigDir
|
|
|
|
* @param string $defaultConfigDir
|
2015-07-14 09:43:14 +03:00
|
|
|
*/
|
2015-09-08 13:17:57 +03:00
|
|
|
public function __construct(IURLGenerator $urlGenerator,
|
2019-12-08 19:20:50 +03:00
|
|
|
ILogger $logger,
|
2019-11-28 17:47:13 +03:00
|
|
|
string $customConfigDir,
|
|
|
|
string $defaultConfigDir) {
|
2015-07-14 09:43:14 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2019-12-08 19:20:50 +03:00
|
|
|
$this->logger = $logger;
|
2015-09-08 13:17:57 +03:00
|
|
|
$this->customConfigDir = $customConfigDir;
|
|
|
|
$this->defaultConfigDir = $defaultConfigDir;
|
2015-07-14 09:43:14 +03:00
|
|
|
}
|
2015-04-09 16:19:57 +03:00
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
/**
|
2014-04-14 19:17:50 +04:00
|
|
|
* Add an extension -> mimetype mapping
|
|
|
|
*
|
|
|
|
* $mimetype is the assumed correct mime type
|
|
|
|
* The optional $secureMimeType is an alternative to send to send
|
|
|
|
* to avoid potential XSS.
|
2013-08-07 18:38:57 +04:00
|
|
|
*
|
|
|
|
* @param string $extension
|
|
|
|
* @param string $mimetype
|
2014-04-14 19:17:50 +04:00
|
|
|
* @param string|null $secureMimeType
|
2013-08-07 18:38:57 +04:00
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function registerType(string $extension,
|
|
|
|
string $mimetype,
|
|
|
|
?string $secureMimeType = null): void {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->mimetypes[$extension] = [$mimetype, $secureMimeType];
|
2014-04-14 19:17:50 +04:00
|
|
|
$this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype;
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-14 19:17:50 +04:00
|
|
|
* Add an array of extension -> mimetype mappings
|
|
|
|
*
|
|
|
|
* The mimetype value is in itself an array where the first index is
|
|
|
|
* the assumed correct mimetype and the second is either a secure alternative
|
|
|
|
* or null if the correct is considered secure.
|
2013-08-07 18:38:57 +04:00
|
|
|
*
|
|
|
|
* @param array $types
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function registerTypeArray(array $types): void {
|
2013-08-07 18:38:57 +04:00
|
|
|
$this->mimetypes = array_merge($this->mimetypes, $types);
|
2014-04-14 19:17:50 +04:00
|
|
|
|
|
|
|
// Update the alternative mimetypes to avoid having to look them up each time.
|
|
|
|
foreach ($this->mimetypes as $mimeType) {
|
2019-11-28 17:47:13 +03:00
|
|
|
$this->secureMimeTypes[$mimeType[0]] = $mimeType[1] ?? $mimeType[0];
|
2014-04-14 19:17:50 +04:00
|
|
|
}
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
|
|
|
|
2019-12-09 00:16:25 +03:00
|
|
|
private function loadCustomDefinitions(string $fileName, array $definitions): array {
|
|
|
|
if (file_exists($this->customConfigDir . '/' . $fileName)) {
|
|
|
|
$custom = json_decode(file_get_contents($this->customConfigDir . '/' . $fileName), true);
|
|
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
|
|
$definitions = array_merge($definitions, $custom);
|
|
|
|
} else {
|
|
|
|
$this->logger->warning('Failed to parse ' . $fileName . ': ' . json_last_error_msg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $definitions;
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:04:34 +03:00
|
|
|
/**
|
|
|
|
* Add the mimetype aliases if they are not yet present
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
private function loadAliases(): void {
|
2015-07-15 11:04:34 +03:00
|
|
|
if (!empty($this->mimeTypeAlias)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-08 13:17:57 +03:00
|
|
|
$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
|
2019-12-09 00:16:25 +03:00
|
|
|
$this->mimeTypeAlias = $this->loadCustomDefinitions(self::CUSTOM_MIMETYPEALIASES, $this->mimeTypeAlias);
|
2015-07-15 11:04:34 +03:00
|
|
|
}
|
|
|
|
|
2015-09-01 16:07:14 +03:00
|
|
|
/**
|
2016-02-05 12:38:43 +03:00
|
|
|
* @return string[]
|
2015-09-01 16:07:14 +03:00
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function getAllAliases(): array {
|
2015-09-01 16:07:14 +03:00
|
|
|
$this->loadAliases();
|
|
|
|
return $this->mimeTypeAlias;
|
|
|
|
}
|
|
|
|
|
2019-11-28 17:47:13 +03:00
|
|
|
public function getOnlyDefaultAliases(): array {
|
2019-05-27 22:54:58 +03:00
|
|
|
$this->loadMappings();
|
|
|
|
$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
|
|
|
|
return $this->mimeTypeAlias;
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:04:34 +03:00
|
|
|
/**
|
|
|
|
* Add mimetype mappings if they are not yet present
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
private function loadMappings(): void {
|
2015-07-15 11:04:34 +03:00
|
|
|
if (!empty($this->mimetypes)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-08 13:17:57 +03:00
|
|
|
$mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true);
|
2019-12-09 00:16:25 +03:00
|
|
|
$mimetypeMapping = $this->loadCustomDefinitions(self::CUSTOM_MIMETYPEMAPPING, $mimetypeMapping);
|
2015-07-15 11:04:34 +03:00
|
|
|
|
2015-09-08 13:17:57 +03:00
|
|
|
$this->registerTypeArray($mimetypeMapping);
|
2015-07-15 11:04:34 +03:00
|
|
|
}
|
|
|
|
|
2015-09-01 16:07:14 +03:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function getAllMappings(): array {
|
2015-09-01 16:07:14 +03:00
|
|
|
$this->loadMappings();
|
|
|
|
return $this->mimetypes;
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
/**
|
|
|
|
* detect mimetype only based on filename, content of file is not used
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function detectPath($path): string {
|
2015-07-15 11:04:34 +03:00
|
|
|
$this->loadMappings();
|
|
|
|
|
2016-09-19 16:41:44 +03:00
|
|
|
$fileName = basename($path);
|
2017-01-23 15:28:35 +03:00
|
|
|
|
|
|
|
// remove leading dot on hidden files with a file extension
|
2017-01-23 19:14:39 +03:00
|
|
|
$fileName = ltrim($fileName, '.');
|
2017-01-23 15:28:35 +03:00
|
|
|
|
2016-09-19 16:41:44 +03:00
|
|
|
// note: leading dot doesn't qualify as extension
|
|
|
|
if (strpos($fileName, '.') > 0) {
|
2017-10-25 18:57:21 +03:00
|
|
|
|
|
|
|
// remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part
|
2019-11-29 13:04:20 +03:00
|
|
|
$fileName = preg_replace('!((\.v\d+)|((\.ocTransferId\d+)?\.part))$!', '', $fileName);
|
2017-10-25 18:57:21 +03:00
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
//try to guess the type by the file extension
|
2019-12-12 11:58:22 +03:00
|
|
|
$extension = strrchr($fileName, '.');
|
|
|
|
if ($extension !== false) {
|
|
|
|
$extension = strtolower($extension);
|
|
|
|
$extension = substr($extension, 1); //remove leading .
|
|
|
|
return $this->mimetypes[$extension][0] ?? 'application/octet-stream';
|
|
|
|
}
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
2019-11-28 17:47:13 +03:00
|
|
|
|
|
|
|
return 'application/octet-stream';
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-28 17:24:57 +03:00
|
|
|
* detect mimetype only based on the content of file
|
2013-08-07 18:38:57 +04:00
|
|
|
* @param string $path
|
|
|
|
* @return string
|
2019-11-28 17:24:57 +03:00
|
|
|
* @since 18.0.0
|
2013-08-07 18:38:57 +04:00
|
|
|
*/
|
2019-11-28 17:24:57 +03:00
|
|
|
public function detectContent(string $path): string {
|
2015-07-15 11:04:34 +03:00
|
|
|
$this->loadMappings();
|
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
if (@is_dir($path)) {
|
|
|
|
// directories are easy
|
2019-11-28 17:47:13 +03:00
|
|
|
return 'httpd/unix-directory';
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
|
|
|
|
2019-11-28 17:24:57 +03:00
|
|
|
if (function_exists('finfo_open')
|
2019-11-28 17:47:13 +03:00
|
|
|
&& function_exists('finfo_file')
|
|
|
|
&& $finfo = finfo_open(FILEINFO_MIME)) {
|
2019-11-29 13:04:20 +03:00
|
|
|
$info = @finfo_file($finfo, $path);
|
2014-02-04 20:03:52 +04:00
|
|
|
finfo_close($finfo);
|
2013-08-07 18:38:57 +04:00
|
|
|
if ($info) {
|
2019-11-29 13:04:20 +03:00
|
|
|
$info = strtolower($info);
|
2016-09-02 14:29:30 +03:00
|
|
|
$mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
|
2019-12-10 12:56:47 +03:00
|
|
|
$mimeType = $this->getSecureMimeType($mimeType);
|
|
|
|
if ($mimeType !== 'application/octet-stream') {
|
|
|
|
return $mimeType;
|
|
|
|
}
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
|
|
|
}
|
2019-11-28 17:47:13 +03:00
|
|
|
|
|
|
|
if (strpos($path, '://') !== false && strpos($path, 'file://') === 0) {
|
|
|
|
// Is the file wrapped in a stream?
|
2019-11-29 13:04:20 +03:00
|
|
|
return 'application/octet-stream';
|
2019-11-28 17:47:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (function_exists('mime_content_type')) {
|
2013-08-07 18:38:57 +04:00
|
|
|
// use mime magic extension if available
|
|
|
|
$mimeType = mime_content_type($path);
|
2019-11-29 13:04:20 +03:00
|
|
|
if ($mimeType !== false) {
|
2019-12-10 12:56:47 +03:00
|
|
|
$mimeType = $this->getSecureMimeType($mimeType);
|
|
|
|
if ($mimeType !== 'application/octet-stream') {
|
|
|
|
return $mimeType;
|
|
|
|
}
|
2019-11-29 13:04:20 +03:00
|
|
|
}
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
2019-11-29 13:04:20 +03:00
|
|
|
|
|
|
|
if (\OC_Helper::canExecute('file')) {
|
2013-08-07 18:38:57 +04:00
|
|
|
// it looks like we have a 'file' command,
|
|
|
|
// lets see if it does have mime support
|
|
|
|
$path = escapeshellarg($path);
|
2019-11-29 13:04:20 +03:00
|
|
|
$fp = popen("test -f $path && file -b --mime-type $path", 'r');
|
|
|
|
$mimeType = fgets($fp);
|
2013-08-07 18:38:57 +04:00
|
|
|
pclose($fp);
|
|
|
|
|
2019-11-29 13:04:20 +03:00
|
|
|
if ($mimeType !== false) {
|
|
|
|
//trim the newline
|
|
|
|
$mimeType = trim($mimeType);
|
2019-12-10 12:56:47 +03:00
|
|
|
$mimeType = $this->getSecureMimeType($mimeType);
|
|
|
|
if ($mimeType !== 'application/octet-stream') {
|
|
|
|
return $mimeType;
|
|
|
|
}
|
2013-10-29 16:29:35 +04:00
|
|
|
}
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
2019-11-29 13:04:20 +03:00
|
|
|
return 'application/octet-stream';
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
|
|
|
|
2019-11-28 17:24:57 +03:00
|
|
|
/**
|
|
|
|
* detect mimetype based on both filename and content
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function detect($path): string {
|
2019-11-28 17:24:57 +03:00
|
|
|
$mimeType = $this->detectPath($path);
|
|
|
|
|
|
|
|
if ($mimeType !== 'application/octet-stream') {
|
|
|
|
return $mimeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->detectContent($path);
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:57 +04:00
|
|
|
/**
|
|
|
|
* detect mimetype based on the content of a string
|
|
|
|
*
|
|
|
|
* @param string $data
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function detectString($data): string {
|
|
|
|
if (function_exists('finfo_open') && function_exists('finfo_file')) {
|
2013-08-07 18:38:57 +04:00
|
|
|
$finfo = finfo_open(FILEINFO_MIME);
|
2016-09-02 14:29:30 +03:00
|
|
|
$info = finfo_buffer($finfo, $data);
|
|
|
|
return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
2019-11-28 17:47:13 +03:00
|
|
|
|
|
|
|
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
|
|
|
|
$fh = fopen($tmpFile, 'wb');
|
|
|
|
fwrite($fh, $data, 8024);
|
|
|
|
fclose($fh);
|
|
|
|
$mime = $this->detect($tmpFile);
|
|
|
|
unset($tmpFile);
|
|
|
|
return $mime;
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|
2014-04-14 19:17:50 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a secure mimetype that won't expose potential XSS.
|
|
|
|
*
|
|
|
|
* @param string $mimeType
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function getSecureMimeType($mimeType): string {
|
2015-07-15 11:04:34 +03:00
|
|
|
$this->loadMappings();
|
|
|
|
|
2019-11-28 17:47:13 +03:00
|
|
|
return $this->secureMimeTypes[$mimeType] ?? 'application/octet-stream';
|
2014-04-14 19:17:50 +04:00
|
|
|
}
|
2015-04-09 16:19:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get path to the icon of a file type
|
2016-02-05 12:38:43 +03:00
|
|
|
* @param string $mimetype the MIME type
|
2015-04-09 16:19:57 +03:00
|
|
|
* @return string the url
|
|
|
|
*/
|
2019-11-28 17:47:13 +03:00
|
|
|
public function mimeTypeIcon($mimetype): string {
|
2015-07-15 11:04:34 +03:00
|
|
|
$this->loadAliases();
|
2015-07-14 09:43:14 +03:00
|
|
|
|
2015-09-22 16:39:02 +03:00
|
|
|
while (isset($this->mimeTypeAlias[$mimetype])) {
|
2015-04-09 16:19:57 +03:00
|
|
|
$mimetype = $this->mimeTypeAlias[$mimetype];
|
|
|
|
}
|
|
|
|
if (isset($this->mimetypeIcons[$mimetype])) {
|
|
|
|
return $this->mimetypeIcons[$mimetype];
|
|
|
|
}
|
2015-07-14 09:43:14 +03:00
|
|
|
|
2015-04-09 16:19:57 +03:00
|
|
|
// Replace slash and backslash with a minus
|
2019-11-28 17:47:13 +03:00
|
|
|
$icon = str_replace(['/', '\\'], '-', $mimetype);
|
2015-04-09 16:19:57 +03:00
|
|
|
|
|
|
|
// Is it a dir?
|
|
|
|
if ($mimetype === 'dir') {
|
2016-06-23 14:20:03 +03:00
|
|
|
$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg');
|
2015-07-14 09:43:14 +03:00
|
|
|
return $this->mimetypeIcons[$mimetype];
|
2015-04-09 16:19:57 +03:00
|
|
|
}
|
|
|
|
if ($mimetype === 'dir-shared') {
|
2016-06-23 14:20:03 +03:00
|
|
|
$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg');
|
2015-07-14 09:43:14 +03:00
|
|
|
return $this->mimetypeIcons[$mimetype];
|
2015-04-09 16:19:57 +03:00
|
|
|
}
|
|
|
|
if ($mimetype === 'dir-external') {
|
2016-06-23 14:20:03 +03:00
|
|
|
$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg');
|
2015-07-14 09:43:14 +03:00
|
|
|
return $this->mimetypeIcons[$mimetype];
|
2015-04-09 16:19:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Icon exists?
|
2015-07-14 09:43:14 +03:00
|
|
|
try {
|
2016-06-23 14:20:03 +03:00
|
|
|
$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg');
|
2015-07-14 09:43:14 +03:00
|
|
|
return $this->mimetypeIcons[$mimetype];
|
|
|
|
} catch (\RuntimeException $e) {
|
|
|
|
// Specified image not found
|
2015-04-09 16:19:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try only the first part of the filetype
|
|
|
|
$mimePart = substr($icon, 0, strpos($icon, '-'));
|
2015-07-14 09:43:14 +03:00
|
|
|
try {
|
2016-06-23 14:20:03 +03:00
|
|
|
$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');
|
2015-07-14 09:43:14 +03:00
|
|
|
return $this->mimetypeIcons[$mimetype];
|
|
|
|
} catch (\RuntimeException $e) {
|
|
|
|
// Image for the first part of the mimetype not found
|
2015-04-09 16:19:57 +03:00
|
|
|
}
|
2015-07-14 09:43:14 +03:00
|
|
|
|
2016-06-23 14:20:03 +03:00
|
|
|
$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg');
|
2015-07-14 09:43:14 +03:00
|
|
|
return $this->mimetypeIcons[$mimetype];
|
2015-04-09 16:19:57 +03:00
|
|
|
}
|
2013-08-07 18:38:57 +04:00
|
|
|
}
|