|
|
|
@ -10,6 +10,8 @@ use Chamilo\CoreBundle\Settings\SettingsManager; |
|
|
|
|
use Chamilo\CourseBundle\Settings\SettingsCourseManager; |
|
|
|
|
use League\Flysystem\FilesystemException; |
|
|
|
|
use League\Flysystem\FilesystemOperator; |
|
|
|
|
use League\Flysystem\UnableToReadFile; |
|
|
|
|
use League\MimeTypeDetection\ExtensionMimeTypeDetector; |
|
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire; |
|
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
|
|
@ -71,7 +73,7 @@ final class ThemeHelper |
|
|
|
|
return $visualTheme; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getThemeAssetUrl(string $path, bool $absolute = false): string |
|
|
|
|
public function getThemeAssetUrl(string $path, bool $absoluteUrl = false): string |
|
|
|
|
{ |
|
|
|
|
$themeName = $this->getVisualTheme(); |
|
|
|
|
|
|
|
|
@ -86,7 +88,7 @@ final class ThemeHelper |
|
|
|
|
return $this->router->generate( |
|
|
|
|
'theme_asset', |
|
|
|
|
['name' => $themeName, 'path' => $path], |
|
|
|
|
$absolute ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH |
|
|
|
|
$absoluteUrl ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -100,4 +102,41 @@ final class ThemeHelper |
|
|
|
|
|
|
|
|
|
return sprintf('<link rel="stylesheet" href="%s">', $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 ''; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|