Created
October 6, 2013 03:43
-
-
Save clouddueling/6849208 to your computer and use it in GitHub Desktop.
allow vimeo and youtube iframes in HTMLPurifier
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
/** | |
* Sanitize string input | |
* @param string $dirty_html | |
* @return string | |
*/ | |
public static function purify( $dirty_html ) | |
{ | |
$config = HTMLPurifier_Config::createDefault(); | |
$config->set('HTML.SafeIframe', true); | |
$config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%'); //allow YouTube and Vimeo | |
$purifier = new HTMLPurifier($config); | |
$clean_html = $purifier->purify($dirty_html); | |
return $clean_html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment