diff options
| -rw-r--r-- | htmlpure/Filter/SafeIframe.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/htmlpure/Filter/SafeIframe.php b/htmlpure/Filter/SafeIframe.php new file mode 100644 index 0000000..370c89c --- /dev/null +++ b/htmlpure/Filter/SafeIframe.php @@ -0,0 +1,20 @@ +<?php + +class HTMLPurifier_Filter_SafeIframe extends HTMLPurifier_Filter +{ + public $name = 'SafeIframe'; + + public function preFilter($html, $config, $context) { + return preg_replace("/iframe/", "img class=\"SafeIframe\" ", preg_replace("/<\/iframe>/", "", $html)); + } + + public function postFilter($html, $config, $context) { + $post_regex = '#<img class="SafeIframe" ([^>]+)>#'; + return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html); + } + + protected function postFilterCallback($matches) { + return '<iframe '.$matches[1].'></iframe>'; + } +} + |
