-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-7182 Move HtmlFilter classes into the module
- Loading branch information
1 parent
6785431
commit 9a4a03e
Showing
10 changed files
with
94 additions
and
17 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
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,43 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\WysiwygModule\HtmlFilter; | ||
|
||
use DOMDocument; | ||
use DOMXPath; | ||
|
||
class HtmlFilter implements HtmlFilterInterface | ||
{ | ||
public function __construct(private readonly HtmlRemoverInterface $htmlRemover) | ||
{ | ||
} | ||
|
||
public function filter(string $html): string | ||
{ | ||
$doc = new DOMDocument(); | ||
$doc->loadHTML("<div>$html</div>", LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); | ||
|
||
$xpath = new DOMXPath($doc); | ||
foreach ($xpath->query('//script') as $node) { | ||
$this->htmlRemover->remove($node); | ||
} | ||
|
||
return $this->getInnerHtml($doc); | ||
} | ||
|
||
private function getInnerHtml(DOMDocument $doc): string | ||
{ | ||
$html = ''; | ||
foreach ($doc->documentElement->childNodes as $node) { | ||
$html .= $doc->saveHTML($node); | ||
} | ||
|
||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\WysiwygModule\HtmlFilter; | ||
|
||
interface HtmlFilterInterface | ||
{ | ||
public function filter(string $html): string; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\WysiwygModule\HtmlFilter; | ||
|
||
use DOMNode; | ||
|
||
interface HtmlRemoverInterface | ||
{ | ||
public function remove(DOMNode $node): void; | ||
} |
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,12 @@ | ||
services: | ||
_defaults: | ||
public: false | ||
autowire: true | ||
|
||
OxidEsales\WysiwygModule\HtmlFilter\HtmlRemoverInterface: | ||
class: OxidEsales\WysiwygModule\HtmlFilter\HtmlTagRemover | ||
public: true | ||
|
||
OxidEsales\WysiwygModule\HtmlFilter\HtmlFilterInterface: | ||
class: OxidEsales\WysiwygModule\HtmlFilter\HtmlFilter | ||
public: true |
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