aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-02-21 15:57:10 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-02-21 15:57:10 +0100
commit99679d06884120c57f43b44e55e03595f1f87bed (patch)
treea3f2a1aa1afdaeca1386d0c6e8a75344fd2241fb /inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php
parent655214ab30ee84884dc408488b85586f36263fcb (diff)
parentd3b47e94705e17b3ba3529cbb1dc6efe69c5d2b7 (diff)
downloadwallabag-99679d06884120c57f43b44e55e03595f1f87bed.tar.gz
wallabag-99679d06884120c57f43b44e55e03595f1f87bed.tar.zst
wallabag-99679d06884120c57f43b44e55e03595f1f87bed.zip
Merge pull request #481 from wallabag/dev1.5.2
1.5.2
Diffstat (limited to 'inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php')
-rw-r--r--inc/3rdparty/htmlpurifier/HTMLPurifier/Filter/YouTube.php65
1 files changed, 65 insertions, 0 deletions
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 @@
1<?php
2
3class HTMLPurifier_Filter_YouTube extends HTMLPurifier_Filter
4{
5
6 /**
7 * @type string
8 */
9 public $name = 'YouTube';
10
11 /**
12 * @param string $html
13 * @param HTMLPurifier_Config $config
14 * @param HTMLPurifier_Context $context
15 * @return string
16 */
17 public function preFilter($html, $config, $context)
18 {
19 $pre_regex = '#<object[^>]+>.+?' .
20 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s';
21 $pre_replace = '<span class="youtube-embed">\1</span>';
22 return preg_replace($pre_regex, $pre_replace, $html);
23 }
24
25 /**
26 * @param string $html
27 * @param HTMLPurifier_Config $config
28 * @param HTMLPurifier_Context $context
29 * @return string
30 */
31 public function postFilter($html, $config, $context)
32 {
33 $post_regex = '#<span class="youtube-embed">((?:v|cp)/[A-Za-z0-9\-_=]+)</span>#';
34 return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html);
35 }
36
37 /**
38 * @param $url
39 * @return string
40 */
41 protected function armorUrl($url)
42 {
43 return str_replace('--', '-&#45;', $url);
44 }
45
46 /**
47 * @param array $matches
48 * @return string
49 */
50 protected function postFilterCallback($matches)
51 {
52 $url = $this->armorUrl($matches[1]);
53 return '<object width="425" height="350" type="application/x-shockwave-flash" ' .
54 'data="http://www.youtube.com/' . $url . '">' .
55 '<param name="movie" value="http://www.youtube.com/' . $url . '"></param>' .
56 '<!--[if IE]>' .
57 '<embed src="http://www.youtube.com/' . $url . '"' .
58 'type="application/x-shockwave-flash"' .
59 'wmode="transparent" width="425" height="350" />' .
60 '<![endif]-->' .
61 '</object>';
62 }
63}
64
65// vim: et sw=4 sts=4