-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
1 parent
cfd6e7d
commit 7b0dcc4
Showing
14 changed files
with
50 additions
and
96 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
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,26 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Yireo\Webp2\Plugin; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Yireo\CspUtilities\Util\ReplaceInlineScripts; | ||
|
||
class AddCspInlineScripts | ||
{ | ||
private ReplaceInlineScripts $replaceInlineScripts; | ||
|
||
public function __construct( | ||
ReplaceInlineScripts $replaceInlineScripts | ||
) { | ||
$this->replaceInlineScripts = $replaceInlineScripts; | ||
} | ||
|
||
public function afterToHtml(Template $block, $html): string | ||
{ | ||
if (false === strstr((string)$block->getNameInLayout(), 'yireo_webp2.')) { | ||
return $html; | ||
} | ||
|
||
return $this->replaceInlineScripts->replace((string)$html); | ||
} | ||
} |
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 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 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Framework\View\Element\Template"> | ||
<plugin name="Yireo_Webp2::addCspInlineScripts" type="Yireo\Webp2\Plugin\AddCspInlineScripts"/> | ||
</type> | ||
</config> |
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 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 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 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 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 |
---|---|---|
|
@@ -33,5 +33,4 @@ | |
replaceImage(image); | ||
}); | ||
} | ||
}); | ||
</script> | ||
});</script> |
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,15 +1 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** @var $block \Magento\Framework\View\Element\Template */ | ||
/** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ | ||
$imageProvider = $block->getImageProvider(); | ||
$image = $imageProvider->getImage(); | ||
$imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); | ||
?> | ||
|
||
<h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1> | ||
|
||
<img class="alt-img" src="<?= /* @noEscape */ $imageUrl ?>" alt="test sample" style="display:insane; opacity:666;"> | ||
|
||
<h2>Layout handles</h2> | ||
<pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
<?php declare(strict_types=1); /** @var $block \Magento\Framework\View\Element\Template */ /** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ $imageProvider = $block->getImageProvider(); $image = $imageProvider->getImage(); $imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); ?> <h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1><img class="alt-img" src="<?= /* @noEscape */ $imageUrl ?>" alt="test sample" style="display:insane; opacity:666;"><h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
25 changes: 1 addition & 24 deletions
25
view/frontend/templates/test/multiple_existing_picturesets.phtml
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,24 +1 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** @var $block \Magento\Framework\View\Element\Template */ | ||
/** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ | ||
$imageProvider = $block->getImageProvider(); | ||
$images = $imageProvider->getImages(); | ||
|
||
$imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); | ||
?> | ||
|
||
<h1><?= /* @noEscape */ | ||
$block->getNameInLayout() ?></h1> | ||
|
||
<?php foreach ($images as $image): ?> | ||
<div> | ||
<picture> | ||
<img src="<?= /* @noEscape */ | ||
$imageUrl ?>" width="100" height="100"/> | ||
</picture> | ||
</div> | ||
<?php endforeach; ?> | ||
|
||
<h2>Layout handles</h2> | ||
<pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
<?php declare(strict_types=1); /** @var $block \Magento\Framework\View\Element\Template */ /** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ $imageProvider = $block->getImageProvider(); $images = $imageProvider->getImages(); $imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); ?> <h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1><?php foreach ($images as $image): ?> <div><picture><img src="<?= /* @noEscape */ $imageUrl ?>" width="100" height="100"/></picture></div><?php endforeach; ?> <h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
Check warning on line 1 in view/frontend/templates/test/multiple_existing_picturesets.phtml GitHub Actions / Static Code Analysis
Check warning on line 1 in view/frontend/templates/test/multiple_existing_picturesets.phtml GitHub Actions / Static Code Analysis
Check warning on line 1 in view/frontend/templates/test/multiple_existing_picturesets.phtml GitHub Actions / Static Code Analysis
|
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,19 +1 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** @var $block \Magento\Framework\View\Element\Template */ | ||
/** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ | ||
$imageProvider = $block->getImageProvider(); | ||
$images = $imageProvider->getImages(); | ||
?> | ||
|
||
<h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1> | ||
|
||
<?php foreach ($images as $image): ?> | ||
<?php $imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); ?> | ||
<div> | ||
<img src="<?= /* @noEscape */ $imageUrl ?>" width="100" height="100"/> | ||
</div> | ||
<?php endforeach; ?> | ||
|
||
<h2>Layout handles</h2> | ||
<pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
<?php declare(strict_types=1); /** @var $block \Magento\Framework\View\Element\Template */ /** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ $imageProvider = $block->getImageProvider(); $images = $imageProvider->getImages(); ?> <h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1><?php foreach ($images as $image): ?> <?php $imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); ?> <div><img src="<?= /* @noEscape */ $imageUrl ?>" width="100" height="100"/></div><?php endforeach; ?> <h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> |
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,18 +1 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** @var $block \Magento\Framework\View\Element\Template */ | ||
/** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ | ||
$imageProvider = $block->getImageProvider(); | ||
$image = $imageProvider->getImage(); | ||
?> | ||
|
||
<h1><?= /* @noEscape */$block->getNameInLayout() ?></h1> | ||
|
||
<?php for ($i = 0; $i < 3; $i++): ?> | ||
<div> | ||
<img src="<?= $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)) ?>" width="100" height="100"/> | ||
</div> | ||
<?php endfor; ?> | ||
|
||
<h2>Layout handles</h2> | ||
<pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
<?php declare(strict_types=1); /** @var $block \Magento\Framework\View\Element\Template */ /** @var $imageProvider \Yireo\Webp2\Test\Utils\ImageProvider */ $imageProvider = $block->getImageProvider(); $image = $imageProvider->getImage(); ?> <h1><?= /* @noEscape */$block->getNameInLayout() ?></h1><?php for ($i = 0; $i < 3; $i++): ?> <div><img src="<?= $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)) ?>" width="100" height="100"/></div><?php endfor; ?> <h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
Check warning on line 1 in view/frontend/templates/test/multiple_images_same.phtml GitHub Actions / Static Code Analysis
Check warning on line 1 in view/frontend/templates/test/multiple_images_same.phtml GitHub Actions / Static Code Analysis
|
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,9 +1 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** @var $block \Magento\Framework\View\Element\Template */ | ||
?> | ||
|
||
<img src="https://example.com/some/non/existing/image.png" alt="" width="10px"> | ||
|
||
<h2>Layout handles</h2> | ||
<pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> | ||
<?php declare(strict_types=1); /** @var $block \Magento\Framework\View\Element\Template */ ?> <img src="https://example.com/some/non/existing/image.png" alt="" width="10px"><h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre> |