|
7 | 7 |
|
8 | 8 | namespace Magento\PageBuilder\Plugin\Filter;
|
9 | 9 |
|
10 |
| -use Magento\Store\Model\Store; |
11 |
| - |
12 | 10 | /**
|
13 | 11 | * Plugin to the template filter to process any background images added by Page Builder
|
14 | 12 | */
|
@@ -38,19 +36,27 @@ class TemplatePlugin
|
38 | 36 | */
|
39 | 37 | private $mathRandom;
|
40 | 38 |
|
| 39 | + /** |
| 40 | + * @var \Magento\Framework\Serialize\Serializer\Json |
| 41 | + */ |
| 42 | + private $json; |
| 43 | + |
41 | 44 | /**
|
42 | 45 | * @param \Psr\Log\LoggerInterface $logger
|
43 | 46 | * @param \Magento\Framework\View\ConfigInterface $viewConfig
|
44 | 47 | * @param \Magento\Framework\Math\Random $mathRandom
|
| 48 | + * @param \Magento\Framework\Serialize\Serializer\Json $json |
45 | 49 | */
|
46 | 50 | public function __construct(
|
47 | 51 | \Psr\Log\LoggerInterface $logger,
|
48 | 52 | \Magento\Framework\View\ConfigInterface $viewConfig,
|
49 |
| - \Magento\Framework\Math\Random $mathRandom |
| 53 | + \Magento\Framework\Math\Random $mathRandom, |
| 54 | + \Magento\Framework\Serialize\Serializer\Json $json |
50 | 55 | ) {
|
51 | 56 | $this->logger = $logger;
|
52 | 57 | $this->viewConfig = $viewConfig;
|
53 | 58 | $this->mathRandom = $mathRandom;
|
| 59 | + $this->json = $json; |
54 | 60 | }
|
55 | 61 |
|
56 | 62 | /**
|
@@ -107,32 +113,6 @@ public function afterFilter(\Magento\Framework\Filter\Template $subject, string
|
107 | 113 | return $result;
|
108 | 114 | }
|
109 | 115 |
|
110 |
| - /** |
111 |
| - * Determine if custom variable directive's return value needs to be escaped and do so if true |
112 |
| - * |
113 |
| - * @param \Magento\Framework\Filter\Template $subject |
114 |
| - * @param \Closure $proceed |
115 |
| - * @param string[] $construction |
116 |
| - * @return string |
117 |
| - */ |
118 |
| - public function aroundCustomvarDirective( |
119 |
| - \Magento\Framework\Filter\Template $subject, |
120 |
| - \Closure $proceed, |
121 |
| - $construction |
122 |
| - ) { |
123 |
| - // Determine the need to escape the return value of observed method. |
124 |
| - // Admin context requires store ID of 0; in that context return value should be escaped |
125 |
| - $shouldEscape = $subject->getStoreId() !== null && (int) $subject->getStoreId() === Store::DEFAULT_STORE_ID; |
126 |
| - |
127 |
| - if (!$shouldEscape) { |
128 |
| - return $proceed($construction); |
129 |
| - } |
130 |
| - |
131 |
| - $result = $proceed($construction); |
132 |
| - |
133 |
| - return htmlspecialchars($result); |
134 |
| - } |
135 |
| - |
136 | 116 | /**
|
137 | 117 | * Create a DOM document from a given string
|
138 | 118 | *
|
@@ -161,7 +141,7 @@ private function createDomDocument(string $html) : \DOMDocument
|
161 | 141 | $domDocument = new \DOMDocument('1.0', 'UTF-8');
|
162 | 142 | set_error_handler(
|
163 | 143 | function ($errorNumber, $errorString) {
|
164 |
| - throw new \Exception($errorString, $errorNumber); |
| 144 | + throw new \DOMException($errorString, $errorNumber); |
165 | 145 | }
|
166 | 146 | );
|
167 | 147 | $string = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
|
@@ -225,6 +205,7 @@ private function generateDecodedHtmlPlaceholderMappingInDocument(\DOMDocument $d
|
225 | 205 | $preDecodedOuterHtml = $document->saveHTML($htmlContentTypeNode);
|
226 | 206 |
|
227 | 207 | // clear empty <div> wrapper around outerHTML to replace with $clonedHtmlContentTypeNode
|
| 208 | + // phpcs:ignore Magento2.Functions.DiscouragedFunction |
228 | 209 | $decodedInnerHtml = preg_replace('#^<[^>]*>|</[^>]*>$#', '', html_entity_decode($preDecodedOuterHtml));
|
229 | 210 |
|
230 | 211 | // Use $clonedHtmlContentTypeNode's placeholder to inject decoded inner html
|
@@ -258,7 +239,8 @@ private function generateBackgroundImageStyles(\DOMDocument $document) : void
|
258 | 239 | $backgroundImages = $node->attributes->getNamedItem('data-background-images');
|
259 | 240 | if ($backgroundImages->nodeValue !== '') {
|
260 | 241 | $elementClass = uniqid('background-image-');
|
261 |
| - $images = json_decode(stripslashes($backgroundImages->nodeValue), true); |
| 242 | + // phpcs:ignore Magento2.Functions.DiscouragedFunction |
| 243 | + $images = $this->json->unserialize(stripslashes($backgroundImages->nodeValue)); |
262 | 244 | if (count($images) > 0) {
|
263 | 245 | $style = $xpath->document->createElement(
|
264 | 246 | 'style',
|
|
0 commit comments