Repository navigation
Expand file tree
/
Copy pathboot.php
More file actions
63 lines (51 loc) · 2.92 KB
/
Copy pathboot.php
File metadata and controls
63 lines (51 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
if (rex_addon::get('media_manager')->isAvailable()) {
rex_media_manager::addEffect(rex_effect_negotiator::class);
rex_media_manager::addEffect(rex_effect_srgb_preprocess::class);
}
if (rex::isBackend()) {
$page = rex_request('page', 'string', '');
if ($page === 'media_manager/media_negotiator/setup') {
rex_view::addJsFile(rex_url::addonAssets('media_negotiator', 'setup_compare.js'));
}
}
rex_extension::register('MEDIA_MANAGER_INIT', function (rex_extension_point $ep) {
$mediaManager = $ep->getSubject();
$type = $ep->getParam('type');
$effects = $mediaManager->effectsFromType($type);
// media_srcset requests its widths as "<type>__<width>". No type of that
// name exists in the table (media_srcset supplies the effects later via
// MEDIA_MANAGER_FILTERSET), so the loop below found no negotiator, the
// cache path got no format prefix, and whoever requested a width first
// decided the format for everyone: a WebP-only client cached WebP, and
// every AVIF client got WebP from then on (and vice versa). Fall back to
// the base type, split at the first "__" like media_srcset does.
if ([] === $effects && is_string($type) && false !== ($pos = strpos($type, '__'))) {
$effects = $mediaManager->effectsFromType(substr($type, 0, $pos));
}
foreach ($effects as $effect) {
if ($effect['effect'] === 'negotiator') {
// change cache path for negotiator
$possibleFormat = FriendsOfRedaxo\MediaNegotiator\Helper::getRequestOutputFormat();
// Include effective conversion config in cache key so changed quality/settings
// produce fresh derivatives instead of serving stale cached files.
$cacheKey = $possibleFormat;
if ($possibleFormat === 'webp') {
$cacheKey .= '-q' . FriendsOfRedaxo\MediaNegotiator\Helper::getWebpQuality();
} elseif ($possibleFormat === 'avif') {
$cacheKey .= '-q' . FriendsOfRedaxo\MediaNegotiator\Helper::getAvifQuality();
$cacheKey .= '-acp' . FriendsOfRedaxo\MediaNegotiator\Helper::getAvifConverterPreference();
$cacheKey .= '-ace' . FriendsOfRedaxo\MediaNegotiator\Helper::getEffectiveAvifConverter();
}
$cacheKey .= '-im' . ((bool) rex_config::get('media_negotiator', 'force_imagick', false) ? '1' : '0');
$cacheKey .= '-davif' . ((bool) rex_config::get('media_negotiator', 'disable_avif', false) ? '1' : '0');
$cacheKey .= '-pref' . FriendsOfRedaxo\MediaNegotiator\Helper::getPreferredFormat();
// Nur bei aktiver Option anhängen, damit bestehende Cache-Dateien gültig bleiben
if (FriendsOfRedaxo\MediaNegotiator\Helper::pngLossless()) {
$cacheKey .= '-png1';
}
$mediaManager->setCachePath($mediaManager->getCachePath() . $cacheKey . '-');
return;
}
}
});