Skip to content

Commit 3b1ad4e

Browse files
committed
Merge branch '1.0.0-beta-release' of github.com:magento/magento2-page-builder into 1.0.0-beta-release
2 parents e111af6 + b59da88 commit 3b1ad4e

File tree

88 files changed

+1907
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1907
-230
lines changed

app/code/Magento/PageBuilder/Controller/ContentType/Preview.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
namespace Magento\PageBuilder\Controller\ContentType;
1010

1111
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Framework\App\Action\HttpPostActionInterface;
1213

1314
/**
1415
* Preview controller to render blocks preview on Stage
16+
*
17+
* This isn't placed within the adminhtml folder as it has to extend from the front-end controllers app action to
18+
* ensure the content is rendered in the storefront scope.
19+
*
1520
* @api
1621
*/
17-
class Preview extends \Magento\Framework\App\Action\Action
22+
class Preview extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface
1823
{
1924
/**
2025
* @var \Magento\PageBuilder\Model\Stage\RendererPool
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\PageBuilder\Model\Config\ContentType\AdditionalData\Provider\Uploader;
10+
11+
use Magento\PageBuilder\Model\Config\ContentType\AdditionalData\ProviderInterface;
12+
use Magento\Framework\File\Size;
13+
14+
/**
15+
* Provides maximum file size for uploader
16+
*
17+
* Will provide the lower of the following two values:
18+
* - upload_max_filesize from php.ini config
19+
* - staticFileSize argument passed to constructor
20+
*/
21+
class MaxFileSize implements ProviderInterface
22+
{
23+
/**
24+
* @var Size
25+
*/
26+
private $fileSize;
27+
28+
/**
29+
* @var int
30+
*/
31+
private $staticFileSize;
32+
33+
/**
34+
* @param Size $fileSize
35+
* @param int $staticFileSize
36+
*/
37+
public function __construct(
38+
Size $fileSize,
39+
$staticFileSize = null
40+
) {
41+
$this->fileSize = $fileSize;
42+
$this->staticFileSize = $staticFileSize;
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function getData(string $itemName) : array
49+
{
50+
// dynamically set max file size based on the lower of php ini config and static value (if present)
51+
$maxFileSize = min(array_filter([
52+
$this->staticFileSize ?? 0,
53+
$this->fileSize->getMaxFileSize()
54+
]));
55+
56+
return [
57+
$itemName => $maxFileSize
58+
];
59+
}
60+
}

app/code/Magento/PageBuilder/Model/Stage/ScriptFilter.php app/code/Magento/PageBuilder/Model/Stage/HtmlFilter.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
use Psr\Log\LoggerInterface;
1212

1313
/**
14-
* Filters script tags from stage output
14+
* Filters HTML from stage output
1515
*
1616
* @api
1717
*/
18-
class ScriptFilter
18+
class HtmlFilter
1919
{
2020
/**
2121
* @var LoggerInterface
2222
*/
2323
private $loggerInterface;
2424

2525
/**
26-
* ScriptFilter constructor.
26+
* HtmlFilter constructor.
2727
* @param LoggerInterface $loggerInterface
2828
*/
2929
public function __construct(
@@ -33,12 +33,12 @@ public function __construct(
3333
}
3434

3535
/**
36-
* Remove script tag from html
36+
* Filter HTML text to remove script tags and encode HTML content types
3737
*
3838
* @param string $content
3939
* @return string
4040
*/
41-
public function removeScriptTags(string $content): string
41+
public function filterHtml(string $content): string
4242
{
4343
$dom = new \DOMDocument();
4444
try {
@@ -49,9 +49,25 @@ public function removeScriptTags(string $content): string
4949
$this->loggerInterface->critical($e->getMessage());
5050
}
5151
libxml_use_internal_errors($previous);
52+
// Remove all <script /> tags from output
5253
foreach (iterator_to_array($dom->getElementsByTagName('script')) as $item) {
5354
$item->parentNode->removeChild($item);
5455
}
56+
$xpath = new \DOMXPath($dom);
57+
$htmlContentTypes = $xpath->query('//*[@data-role="html" and not(contains(@class, "placeholder-html-code"))]');
58+
foreach ($htmlContentTypes as $htmlContentType) {
59+
/* @var \DOMElement $htmlContentType */
60+
$innerHTML= '';
61+
$children = $htmlContentType->childNodes;
62+
foreach ($children as $child) {
63+
$innerHTML .= $child->ownerDocument->saveXML($child);
64+
}
65+
$htmlContentType->setAttribute(
66+
"class",
67+
$htmlContentType->getAttribute("class") . " placeholder-html-code"
68+
);
69+
$htmlContentType->nodeValue = htmlentities($innerHTML);
70+
}
5571
return $dom->saveHTML();
5672
}
5773
}

app/code/Magento/PageBuilder/Model/Stage/Renderer/CmsStaticBlock.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@ class CmsStaticBlock implements \Magento\PageBuilder\Model\Stage\RendererInterfa
3333
private $loggerInterface;
3434

3535
/**
36-
* @var \Magento\PageBuilder\Model\Stage\ScriptFilter
36+
* @var \Magento\PageBuilder\Model\Stage\HtmlFilter
3737
*/
38-
private $scriptFilter;
38+
private $htmlFilter;
3939

4040
/**
4141
* CmsStaticBlock constructor.
4242
*
4343
* @param \Magento\Cms\Model\ResourceModel\Block\CollectionFactory $blockCollectionFactory
4444
* @param WidgetDirective $widgetDirectiveRenderer
4545
* @param LoggerInterface $loggerInterface
46-
* @param \Magento\PageBuilder\Model\Stage\ScriptFilter $scriptFilter
46+
* @param \Magento\PageBuilder\Model\Stage\HtmlFilter $htmlFilter
4747
*/
4848
public function __construct(
4949
\Magento\Cms\Model\ResourceModel\Block\CollectionFactory $blockCollectionFactory,
5050
WidgetDirective $widgetDirectiveRenderer,
5151
LoggerInterface $loggerInterface,
52-
\Magento\PageBuilder\Model\Stage\ScriptFilter $scriptFilter
52+
\Magento\PageBuilder\Model\Stage\HtmlFilter $htmlFilter
5353
) {
5454
$this->blockCollectionFactory = $blockCollectionFactory;
5555
$this->widgetDirectiveRenderer = $widgetDirectiveRenderer;
5656
$this->loggerInterface = $loggerInterface;
57-
$this->scriptFilter = $scriptFilter;
57+
$this->htmlFilter = $htmlFilter;
5858
}
5959

6060
/**
@@ -96,7 +96,7 @@ public function render(array $params): array
9696

9797
if ($block->isActive()) {
9898
$directiveResult = $this->widgetDirectiveRenderer->render($params);
99-
$result['content'] = $this->scriptFilter->removeScriptTags($directiveResult['content']);
99+
$result['content'] = $this->htmlFilter->filterHtml($directiveResult['content']);
100100
} else {
101101
$result['error'] = __('Block disabled');
102102
}

app/code/Magento/PageBuilder/Model/WidgetInitializerConfig.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getConfig(): array
3535
{
3636
$resultConfig = [];
3737
foreach ($this->config as $contentTypeName => $config) {
38-
$selector = sprintf('div[data-role="%s"]', $contentTypeName);
38+
$selector = sprintf('[data-role="%s"]', $contentTypeName);
3939
foreach ($config as $item) {
4040
if (!isset($item['component'])) {
4141
continue;

0 commit comments

Comments
 (0)