Skip to content

Commit

Permalink
let iframe for Facebook video
Browse files Browse the repository at this point in the history
  • Loading branch information
panakour committed Oct 4, 2019
1 parent 47b3b55 commit 84515bb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Clean/HtmlCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function setAllowedElements(array $allowedElements)
protected function purify(): void
{
$purifierConfig = HTMLPurifier_Config::createDefault();
$this->enableIframeForYoutubeAndVimeo($purifierConfig);
$this->enableIframeForYoutubeVimeoFacebook($purifierConfig);
$purifierConfig->set('HTML.AllowedElements', $this->allowedElements);
if (in_array('a', $this->allowedElements)) {
$this->allowedAttributes = array_merge($this->allowedAttributes, ['a.href', 'a.target', 'a.rel']);
Expand Down Expand Up @@ -127,13 +127,13 @@ public function cleanRelativeUrls()
}
}

protected function enableIframeForYoutubeAndVimeo($purifierConfig)
protected function enableIframeForYoutubeVimeoFacebook($purifierConfig)
{
if ($this->dom->getNodeList('iframe')->length) {
array_push($this->allowedElements, 'iframe');
array_push($this->allowedAttributes, 'iframe.src');
$purifierConfig->set('HTML.SafeIframe', true);
$purifierConfig->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%');
$purifierConfig->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/|www\.facebook\.com/plugins/video.php\?)%');
}
}

Expand Down

0 comments on commit 84515bb

Please sign in to comment.