1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace OC\Preview;
- use OCA\Theming\ThemingDefaults;
- use OCP\App\IAppManager;
- use OCP\Files\IMimeTypeDetector;
- use OCP\IConfig;
- use OCP\IURLGenerator;
- use OCP\Preview\IMimeIconProvider;
- class MimeIconProvider implements IMimeIconProvider {
- public function __construct(
- protected IMimeTypeDetector $mimetypeDetector,
- protected IConfig $config,
- protected IURLGenerator $urlGenerator,
- protected IAppManager $appManager,
- protected ThemingDefaults $themingDefaults,
- ) {
- }
- public function getMimeIconUrl(string $mime): null|string {
- if (!$mime) {
- return null;
- }
-
- $aliases = $this->mimetypeDetector->getAllAliases();
-
- $aliases = array_filter($aliases, static function (string $key) {
- return !($key === '' || $key[0] === '_');
- }, ARRAY_FILTER_USE_KEY);
-
- 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 {
-
-
- $theme = $this->config->getSystemValue('theme', '');
- if (!empty($theme)) {
- $path = "/themes/$theme/core/img/filetypes/$fileName.svg";
- if (file_exists(\OC::$SERVERROOT . $path)) {
- return $this->urlGenerator->getAbsoluteURL($path);
- }
- }
-
-
-
-
-
-
- $path = "/core/img/filetypes/$fileName.svg";
- if (file_exists(\OC::$SERVERROOT . $path)) {
- return $this->urlGenerator->getAbsoluteURL($path);
- }
- return null;
- }
- }
|