-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
201 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 T-Systems International | ||
* | ||
* @author Bernd Rederlechner <[email protected]> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\NMCTheme; | ||
|
||
use OCP\IConfig; | ||
use OCP\Files\IMimeTypeDetector; | ||
use OCP\IURLGenerator; | ||
use OCP\Preview\IMimeIconProvider; | ||
|
||
class MimeIconProviderDecorator implements IMimeIconProvider { | ||
|
||
protected IConfig $config; | ||
protected IMimeIconProvider $decorated; | ||
protected IMimeTypeDetector $mimetypeDetector; | ||
protected IURLGenerator $urlGenerator; | ||
|
||
public function __construct(IConfig $config, IMimeIconProvider $decorated, IMimeTypeDetector $mimetypeDetector, IURLGenerator $urlGenerator) { | ||
$this->config = $config; | ||
$this->decorated = $decorated; | ||
$this->mimetypeDetector = $mimetypeDetector; | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
public function getMimeIconUrl(string $mime): null|string { | ||
if (!$mime) { | ||
return null; | ||
} | ||
|
||
// Fetch all the aliases | ||
$aliases = $this->mimetypeDetector->getAllAliases(); | ||
|
||
// Remove comments | ||
$aliases = array_filter($aliases, static function ($key) { | ||
return !($key === '' || $key[0] === '_'); | ||
}, ARRAY_FILTER_USE_KEY); | ||
|
||
// Map all the aliases recursively | ||
foreach ($aliases as $alias => $value) { | ||
if ($alias === $mime) { | ||
$mime = $value; | ||
} | ||
} | ||
|
||
$fileName = str_replace('/', '-', $mime); | ||
|
||
if ($url = $this->searchfileName($fileName)) { | ||
return $url; | ||
} | ||
|
||
$mimeType = explode('/', $mime)[0]; | ||
|
||
if ($url = $this->searchfileName($mimeType)) { | ||
return $url; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private function searchfileName(string $fileName): null|string { | ||
|
||
// always return nmctheme style icons | ||
$path = "/customapps/nmctheme/img/filetypes/$fileName.svg"; | ||
|
||
if (file_exists(\OC::$SERVERROOT . $path)) { | ||
return $this->urlGenerator->getAbsoluteURL($path); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters