Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(htmlpurifer): use it to clean text inputs which are raw displayed
- Loading branch information
Showing
6 changed files
with
107 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace YesWiki\Core\Service; | ||
|
||
use HTMLPurifier; | ||
use HTMLPurifier_Config; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use YesWiki\Security\Controller\SecurityController; | ||
use YesWiki\Wiki; | ||
|
||
class HtmlPurifierService | ||
{ | ||
public const HTMLPURIFIER_PATH = "vendor/ezyang/htmlpurifier/"; | ||
|
||
protected $wiki; | ||
private $purifier; | ||
|
||
public function __construct(Wiki $wiki) | ||
{ | ||
$this->wiki = $wiki; | ||
$this->purifier = null; | ||
} | ||
|
||
/** | ||
* load a HTMLpurifier if needed | ||
* configure it | ||
* then use it to clean HTML | ||
*/ | ||
public function cleanHTML(string $dirty_html): string | ||
{ | ||
if (is_null($this->purifier)) { | ||
$this->load(); | ||
} | ||
|
||
return $this->purifier->purify($dirty_html); | ||
} | ||
|
||
private function load() | ||
{ | ||
$config = HTMLPurifier_Config::createDefault(); | ||
$this->purifier = new HTMLPurifier($config); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
{% extends "@bazar/layouts/field.twig" %} | ||
|
||
{% block value %}{{ value|raw }}{% endblock %} |