From d4949327efa15b492cab1bef3fe074290a328a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 21 Feb 2014 15:43:14 +0100 Subject: [add] HTML Purifier added to clean code --- .../htmlpurifier/HTMLPurifier/Filter/YouTube.php | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php (limited to 'inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php') diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php new file mode 100644 index 00000000..9200802a --- /dev/null +++ b/inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php @@ -0,0 +1,65 @@ +]+>.+?' . + 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s'; + $pre_replace = '\1'; + return preg_replace($pre_regex, $pre_replace, $html); + } + + /** + * @param string $html + * @param HTMLPurifier_Config $config + * @param HTMLPurifier_Context $context + * @return string + */ + public function postFilter($html, $config, $context) + { + $post_regex = '#((?:v|cp)/[A-Za-z0-9\-_=]+)#'; + return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html); + } + + /** + * @param $url + * @return string + */ + protected function armorUrl($url) + { + return str_replace('--', '--', $url); + } + + /** + * @param array $matches + * @return string + */ + protected function postFilterCallback($matches) + { + $url = $this->armorUrl($matches[1]); + return '' . + '' . + '' . + ''; + } +} + +// vim: et sw=4 sts=4 -- cgit v1.2.3