generated from FriendsOfREDAXO/rex_repo_template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
96 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
|
||
## [1.0.0] - 05.02.2023 | ||
|
||
### Changed | ||
- initial release |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
# rex_repo_template | ||
REDAXO AddOn english readme | ||
# media_negotiator | ||
|
||
please use in your classes a namespace as | ||
Addon für Redaxo welches dem Media Manager Addon einen Effekt für Content Negotiation hinzufügt. Siehe https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation | ||
|
||
``` | ||
namespace FriendsOfRedaxo\[AddOnNameWithoutSpacesAndAsCamelCase] | ||
``` | ||
|
||
in order to use non deprecated features please don't use PlugIns anymore | ||
Anleitung: | ||
Dem Media Profil den Effekt "Negotiate image format" hinzufügen. | ||
Danach wird automatisch eines der folgenden Formate ausgeliefert: avif, webp, jpg (in dieser Reihenfolge). |
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 |
---|---|---|
@@ -1 +1,42 @@ | ||
<?php // Boot code | ||
<?php | ||
|
||
function negotiateFormat($ep) | ||
{ | ||
|
||
// rex_media_manager object | ||
$subject = $ep->getSubject(); | ||
|
||
// check if the requested image has the 'negotiator' effect | ||
$set_effects = $subject->effectsFromType($subject->getMediaType()); | ||
$set_effects = array_column($set_effects, 'effect'); | ||
$type = $subject->getMediaType(); | ||
|
||
// if not, skip | ||
if (!in_array('negotiator', $set_effects)) { | ||
return $subject; | ||
} | ||
|
||
// if yes, set cache path | ||
if (in_array($type, ['avif'])) { | ||
$possible_types = rex_server('HTTP_ACCEPT', 'string', ''); | ||
$types = explode(',', $possible_types); | ||
|
||
|
||
if (in_array('image/avif', $types)) { | ||
$subject->setCachePath($subject->getCachePath() . 'avif-'); | ||
} elseif (in_array('image/webp', $types)) { | ||
$subject->setCachePath($subject->getCachePath() . 'webp-'); | ||
} else { | ||
$subject->setCachePath($subject->getCachePath() . 'jpg-'); | ||
} | ||
} | ||
|
||
return $subject; | ||
} | ||
|
||
|
||
rex_extension::register('MEDIA_MANAGER_BEFORE_SEND', "negotiateFormat"); | ||
|
||
if (rex_addon::get('media_manager')->isAvailable()) { | ||
rex_media_manager::addEffect(rex_effect_negotiator::class); | ||
} |
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,34 @@ | ||
<?php | ||
|
||
class rex_effect_negotiator extends rex_effect_abstract | ||
{ | ||
|
||
public function getName() | ||
{ | ||
return "Negotiate image format"; | ||
} | ||
|
||
public function execute() | ||
{ | ||
// get image mime types which are accepted by the requesting browser | ||
$possible_types = rex_server('HTTP_ACCEPT', 'string', ''); | ||
$types = explode(',', $possible_types); | ||
|
||
// instantiate image formatter class from media manager | ||
$re = new rex_effect_image_format(); | ||
// pass current image to formatter | ||
$re->media = $this->media; | ||
|
||
// set convert_to extension | ||
if (in_array('image/avif', $types)) { | ||
$re->params['convert_to'] = 'avif'; | ||
} elseif (in_array('image/webp', $types)) { | ||
$re->params['convert_to'] = 'webp'; | ||
} else { | ||
$re->params['convert_to'] = 'jpg'; | ||
} | ||
|
||
// change format | ||
$re->execute(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package: addon_key | ||
version: '0.0.0' | ||
author: 'Friends Of REDAXO' | ||
supportpage: https://github.com/FriendsOfREDAXO/addon_key | ||
package: media_negotiator | ||
version: 1.0.0 | ||
name: Media Negotiator | ||
author: Andreas Lenhardt | ||
|
||
requires: | ||
redaxo: '^5.13.0' | ||
redaxo: ^5.13.0 | ||
php: | ||
version: '>=7.3, <9' | ||
version: "^8.0" |