Skip to content

Commit

Permalink
Merge branch 'develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Hotel authored Nov 21, 2024
2 parents fee835c + 0986853 commit f76e70d
Show file tree
Hide file tree
Showing 225 changed files with 2,293 additions and 299 deletions.
10 changes: 5 additions & 5 deletions .github/.metadata.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"templateVersion": "0.1",
"templateVersion": "0.2",
"product": {
"name": "Magento 2 Page Builder",
"description": "Page Builder introduces an intuitive, drag-and-drop interface for creating digital content, powered by content types like images, videos, banners, etc. with instant preview capabilities that enable non-technical users to take control of their content."
},
"contacts": {
"team": {
"name": "Amigos",
"DL": "Grp-amigos",
"slackChannel": "team-amigos"
"name": "Bluetooth",
"DL": "Grp-RQ-BLUETOOTH",
"slackChannel": ""
}
},
"ticketTracker": {
"functionalJiraQueue": {
"projectKey": "PB",
"projectKey": "AC",
"component": ""
},
"securityJiraQueue": {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/AwsS3PageBuilder/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Aws S3 Page Builder module",
"require": {
"magento/framework": "*",
"php": "~8.1.0||~8.2.0||~8.3.0"
"php": "~8.2.0||~8.3.0"
},
"suggest": {
"magento/module-page-builder": "*",
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogPageBuilderAnalytics/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"magento/module-page-builder-analytics": "*",
"magento/module-catalog": "*",
"magento/framework": "*",
"php": "~8.1.0||~8.2.0||~8.3.0"
"php": "~8.2.0||~8.3.0"
},
"type": "magento2-module",
"license": [
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CmsPageBuilderAnalytics/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"magento/module-page-builder-analytics": "*",
"magento/module-cms": "*",
"magento/framework": "*",
"php": "~8.1.0||~8.2.0||~8.3.0"
"php": "~8.2.0||~8.3.0"
},
"type": "magento2-module",
"license": [
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/PageBuilder/Block/GoogleMapsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
class GoogleMapsApi extends \Magento\Framework\View\Element\Template
{
const GOOGLE_MAPS_API_KEY_PATH = 'cms/pagebuilder/google_maps_api_key';
const GOOGLE_MAPS_LIBRARY_URL = 'https://maps.googleapis.com/maps/api/js?v=3&key=%s';
const GOOGLE_MAPS_STYLE_PATH = 'cms/pagebuilder/google_maps_style';
public const GOOGLE_MAPS_API_KEY_PATH = 'cms/pagebuilder/google_maps_api_key';
public const GOOGLE_MAPS_LIBRARY_URL = 'https://maps.googleapis.com/maps/api/js?v=3.56&key=%s';
public const GOOGLE_MAPS_STYLE_PATH = 'cms/pagebuilder/google_maps_style';

/**
* Retrieve the Google Maps API key
Expand Down
52 changes: 32 additions & 20 deletions app/code/Magento/PageBuilder/Controller/Adminhtml/Template/Save.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\PageBuilder\Controller\Adminhtml\Template;

use function preg_replace;
use function str_replace;
use function strpos;
use function strtolower;
use function substr;
use function uniqid;
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Api\ImageContent;
use Magento\Framework\Api\ImageContentFactory;
use Magento\Framework\Api\ImageContentValidator;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem;
use Magento\Framework\Image\AdapterFactory;
use Magento\MediaStorage\Helper\File\Storage\Database;
use Magento\PageBuilder\Api\Data\TemplateInterface;
use Magento\PageBuilder\Api\TemplateRepositoryInterface;
use Magento\PageBuilder\Model\TemplateFactory;
use Psr\Log\LoggerInterface;
use Magento\Framework\Image\AdapterFactory;

/**
* Save a template within template manager
Expand All @@ -33,7 +43,7 @@
*/
class Save extends Action implements HttpPostActionInterface
{
const ADMIN_RESOURCE = 'Magento_PageBuilder::template_save';
public const ADMIN_RESOURCE = 'Magento_PageBuilder::template_save';

/**
* @var LoggerInterface
Expand Down Expand Up @@ -151,7 +161,7 @@ public function execute()
$filePath = $this->storePreviewImage($request);
// Store the preview image within the new entity
$template->setPreviewImage($filePath);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->critical($e);

return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData(
Expand All @@ -176,7 +186,7 @@ public function execute()
'status' => 'error',
'message' => $e->getMessage()
];
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->critical($e);

$result = [
Expand Down Expand Up @@ -215,26 +225,28 @@ private function validate(RequestInterface $request)
* Handle storing the preview image
*
* @param RequestInterface $request
* @return string
* @return null|string
* @throws Exception
* @throws FileSystemException
* @throws InputException
* @throws LocalizedException
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Magento\Framework\Exception\InputException
*/
private function storePreviewImage(RequestInterface $request) : ?string
private function storePreviewImage(RequestInterface $request): ?string
{
$fileName = preg_replace("/[^A-Za-z0-9]/", '', str_replace(
' ',
'-',
strtolower($request->getParam(TemplateInterface::KEY_NAME))
)) . uniqid() . '.jpg';
' ',
'-',
strtolower($request->getParam(TemplateInterface::KEY_NAME))
)) . uniqid() . '.jpg';

// Prepare the image data
$imgData = str_replace(' ', '+', $request->getParam('previewImage'));
$imgData = substr($imgData, strpos($imgData, ",") + 1);
// phpcs:ignore
$imgData = substr($imgData, strpos($imgData, ',') + 1);
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$decodedImage = base64_decode($imgData);

$imageProperties = getimagesizefromstring($decodedImage);

if (!$imageProperties) {
throw new LocalizedException(__('Unable to get properties from image.'));
}
Expand All @@ -246,16 +258,16 @@ private function storePreviewImage(RequestInterface $request) : ?string
$imageContent->setType($imageProperties['mime']);

if ($this->imageContentValidator->isValid($imageContent)) {
$mediaDirWrite = $this->filesystem
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
$mediaDirWrite = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$directory = $mediaDirWrite->getAbsolutePath('.template-manager');
$mediaDirWrite->create($directory);
$fileAbsolutePath = $directory . $fileName;

$fileAbsolutePath = $directory . DIRECTORY_SEPARATOR . $fileName;
// Write the file to the directory
$mediaDirWrite->getDriver()->filePutContents($fileAbsolutePath, $decodedImage);
// Generate a thumbnail, called -thumb next to the image for usage in the grid
$thumbPath = str_replace('.jpg', '-thumb.jpg', $fileName);
$thumbAbsolutePath = $directory . $thumbPath;
$thumbAbsolutePath = $directory . DIRECTORY_SEPARATOR . $thumbPath;
$imageFactory = $this->imageAdapterFactory->create();
$imageFactory->open($fileAbsolutePath);
$imageFactory->resize(350);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/PageBuilder/Model/Filter/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function generateDecodedHtmlPlaceholderMappingInDocument(DOMDocument $do
$htmlContentTypeNode->setAttribute('data-decoded', 'true');

// if nothing exists inside the node, continue
if (!strlen(trim($htmlContentTypeNode->nodeValue))) {
if (!strlen(trim($htmlContentTypeNode->nodeValue ?? ''))) {
continue;
}

Expand Down
36 changes: 31 additions & 5 deletions app/code/Magento/PageBuilder/Model/Stage/HtmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,43 @@ public function filterHtml(string $content): string
);
foreach ($htmlContentTypes as $htmlContentType) {
/* @var \DOMElement $htmlContentType */
$innerHTML = '';
$children = $htmlContentType->childNodes;
foreach ($children as $child) {
$innerHTML .= $child->ownerDocument->saveXML($child);
}
$htmlContentType->setAttribute(
"class",
$htmlContentType->getAttribute("class") . " placeholder-html-code"
);

$innerHTML = $this->getChildrenInnerHtml($htmlContentType);

$htmlContentType->nodeValue = htmlentities($innerHTML);
}
return substr(trim($dom->saveHTML()), 5, -6);
}

/**
* Get inner HTML of element's children
*
* @param \DOMElement $element
* @return string
*/
private function getChildrenInnerHtml(\DOMElement $element): string
{
$innerHTML = '';
$childrenIterator = $element->childNodes->getIterator();
while ($childrenIterator->valid()) {
$child = $childrenIterator->current();
try {
$ownerDocument = $child->ownerDocument;
} catch (\Error $error) {
$ownerDocument = null;
$this->loggerInterface->critical($error->getMessage());
}
if ($ownerDocument === null) {
$childrenIterator->next();
continue;
}
$innerHTML .= $ownerDocument->saveXML($child);
$childrenIterator->next();
}
return $innerHTML;
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/PageBuilder/Model/Stage/Renderer/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function render(array $params): array
];

$contentTypes = $this->config->getContentTypes();
$backendBlockClassName = isset($contentTypes[$params['role']]['backend_block'])
$backendBlockClassName = isset($params['role']) && isset($contentTypes[$params['role']]['backend_block'])
? $contentTypes[$params['role']]['backend_block'] : false;
$backendBlockTemplate = isset($contentTypes[$params['role']]['backend_template'])
$backendBlockTemplate = isset($params['role']) && isset($contentTypes[$params['role']]['backend_template'])
? $contentTypes[$params['role']]['backend_template'] : false;

if ($backendBlockTemplate) {
Expand Down
53 changes: 36 additions & 17 deletions app/code/Magento/PageBuilder/Model/TemplateRepository.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\PageBuilder\Model;

use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Filesystem;
use Magento\Framework\Image\Factory;
use Magento\PageBuilder\Api\Data\TemplateInterface;
use Magento\PageBuilder\Api\Data\TemplateSearchResultsInterfaceFactory;
use Magento\PageBuilder\Api\TemplateRepositoryInterface;
Expand Down Expand Up @@ -71,6 +73,7 @@ class TemplateRepository implements TemplateRepositoryInterface
* @param CollectionProcessorInterface $collectionProcessor
* @param Filesystem $filesystem
* @param Database $mediaStorage
* @param Factory $imageFactory
*/
public function __construct(
ResourceTemplate $resource,
Expand All @@ -79,7 +82,8 @@ public function __construct(
TemplateSearchResultsInterfaceFactory $searchResultsFactory,
CollectionProcessorInterface $collectionProcessor,
Filesystem $filesystem,
Database $mediaStorage
Database $mediaStorage,
private readonly Factory $imageFactory
) {
$this->resource = $resource;
$this->templateFactory = $templateFactory;
Expand Down Expand Up @@ -142,25 +146,14 @@ public function getList(SearchCriteriaInterface $criteria)
*/
public function delete(TemplateInterface $template) : bool
{
$mediaDir = $this->filesystem
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);

try {
$templateModel = $this->templateFactory->create();
$this->resource->load($templateModel, $template->getTemplateId());
$this->resource->delete($templateModel);
$previewImage = $template->getPreviewImage();
$previewThumbImage = $templateModel->getPreviewThumbnailImage();

// Remove the preview image from the media directory
if ($mediaDir->isExist($previewImage)) {
$mediaDir->delete($previewImage);
}
if ($mediaDir->isExist($previewThumbImage)) {
$mediaDir->delete($previewThumbImage);
}
$this->mediaStorage->deleteFile($previewImage);
$this->mediaStorage->deleteFile($previewThumbImage);
$this->deletePreviewImage($previewImage);
$this->deletePreviewImage($previewThumbImage);
} catch (\Exception $exception) {
throw new CouldNotDeleteException(
__('Could not delete the Template: %1', $exception->getMessage())
Expand All @@ -170,6 +163,32 @@ public function delete(TemplateInterface $template) : bool
return true;
}

/**
* Checks if preview image is valid and tries to delete it
*
* @param string $imageName
* @return void
* @throws FileSystemException
*/
private function deletePreviewImage(string $imageName): void
{
$isValid = true;
$mediaDir = $this->filesystem
->getDirectoryWrite(DirectoryList::MEDIA);

try {
$this->imageFactory->create($mediaDir->getAbsolutePath().$imageName);
} catch (\Exception) {
$isValid = false;
}

if ($mediaDir->isExist($imageName) && $isValid) {
$mediaDir->delete($imageName);
}

$this->mediaStorage->deleteFile($imageName);
}

/**
* @inheritdoc
*/
Expand Down
Loading

0 comments on commit f76e70d

Please sign in to comment.