Skip to content

Commit

Permalink
remove unsecured functions
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Dec 26, 2020
1 parent f15ae35 commit 6b30d85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Service/Export/Renderer/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Magento\Framework\View\FileSystem as ViewFileSystem;
use Magento\Framework\View\Page\Config;
use Magento\Framework\View\Page\Config\RendererInterface;
use Opengento\Gdpr\Model\View\Page\Config\RendererFactory;
use Opengento\Gdpr\Service\Export\Renderer\HtmlRenderer\View\RendererFactory;
use Opengento\Gdpr\Service\Export\Renderer\HtmlRenderer\LayoutInitiatorInterface;
use function extract;
use function ob_end_clean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,53 @@
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Model\View\Page\Config;
namespace Opengento\Gdpr\Service\Export\Renderer\HtmlRenderer\View;

use Magento\Framework\View\Asset\AssetInterface;
use Magento\Framework\View\Asset\File;
use Magento\Framework\View\Asset\GroupedCollection;
use Magento\Framework\View\Asset\PropertyGroup;
use Magento\Framework\View\Page\Config\Renderer as ViewRenderer;
use function file_get_contents;
use function sprintf;
use const PHP_EOL;

class Renderer extends ViewRenderer
{
protected function renderAssetHtml(PropertyGroup $group): string
{
$contentType = $group->getProperty(GroupedCollection::PROPERTY_CONTENT_TYPE);
$assets = $this->processMerge($group->getAll(), $group);
$attributes = $this->getGroupAttributes($group);
$result = '';

/** @var $asset AssetInterface */
foreach ($assets as $asset) {
$result .= $this->inlineHtml(
$group->getProperty(GroupedCollection::PROPERTY_CONTENT_TYPE),
$asset->getUrl(),
$this->addDefaultAttributes($this->getAssetContentType($asset), $attributes)
);
if ($asset instanceof File) {
$result .= $this->inlineHtml(
$contentType,
$asset,
$this->addDefaultAttributes($this->getAssetContentType($asset), $attributes)
);
} else {
$result .= sprintf($this->getAssetTemplate($contentType, $attributes), $asset->getUrl()) . PHP_EOL;
}
}

return $result;
}

private function inlineHtml(string $contentType, string $src, ?string $attributes): string
private function inlineHtml(string $contentType, File $asset, ?string $attributes): string
{
switch ($contentType) {
case 'js':
$result = '<script ' . $attributes . '>' . file_get_contents($src) . '</script>';
$result = '<script' . $attributes . '>' . PHP_EOL . $asset->getContent() . '</script>';
break;

case 'css':
$result = '<style ' . $attributes . '>' . file_get_contents($src) . '</style>';
$result = '<style' . $attributes . '>' . PHP_EOL . $asset->getContent() . '</style>';
break;
default:
$result = sprintf($this->getAssetTemplate($contentType, $attributes), $src);
$result = sprintf($this->getAssetTemplate($contentType, $attributes), $asset->getUrl());
break;
}

Expand Down

0 comments on commit 6b30d85

Please sign in to comment.