accessUrlHelper->getCurrent(); $visualTheme = $accessUrl->getActiveColorTheme()?->getColorTheme()->getSlug(); if ('true' == $this->settingsManager->getSetting('profile.user_selected_theme')) { $visualTheme = $this->userHelper->getCurrent()?->getTheme(); } if ('true' == $this->settingsManager->getSetting('course.allow_course_theme')) { $course = $this->cidReqHelper->getCourseEntity(); if ($course) { $this->settingsCourseManager->setCourse($course); $visualTheme = $this->settingsCourseManager->getCourseSettingValue('course_theme'); if (1 === (int) $this->settingsCourseManager->getCourseSettingValue('allow_learning_path_theme')) { $visualTheme = $lp_theme_css; } } } if (empty($visualTheme)) { return self::DEFAULT_THEME; } return $visualTheme; } public function getThemeAssetUrl(string $path, bool $absoluteUrl = false): string { $themeName = $this->getVisualTheme(); try { if (!$this->filesystem->fileExists($themeName.DIRECTORY_SEPARATOR.$path)) { return ''; } } catch (FilesystemException) { return ''; } return $this->router->generate( 'theme_asset', ['name' => $themeName, 'path' => $path], $absoluteUrl ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH ); } public function getThemeAssetLinkTag(string $path, bool $absoluteUrl = false): string { $url = $this->getThemeAssetUrl($path, $absoluteUrl); if (empty($url)) { return ''; } return sprintf('', $url); } public function getAssetContents(string $path): string { $themeName = $this->getVisualTheme(); $fullPath = $themeName.DIRECTORY_SEPARATOR.$path; try { if ($this->filesystem->fileExists($fullPath)) { $stream = $this->filesystem->readStream($fullPath); return stream_get_contents($stream); } } catch (FilesystemException|UnableToReadFile) { return ''; } return ''; } public function getAssetBase64Encoded(string $path): string { $visualTheme = $this->getVisualTheme(); $fullPath = $visualTheme.DIRECTORY_SEPARATOR.$path; try { if ($this->filesystem->fileExists($fullPath)) { $detector = new ExtensionMimeTypeDetector(); $mimeType = (string) $detector->detectMimeTypeFromFile($fullPath); return 'data:'.$mimeType.';base64,'.base64_encode($this->getAssetContents($path)); } } catch (FilesystemException) { return ''; } return ''; } }