Cheetah
YouTube.php
Go to the documentation of this file.
1 <?php
2 
4 {
5 
9  public $name = 'YouTube';
10 
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 
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 
41  protected function armorUrl($url)
42  {
43  return str_replace('--', '-&#45;', $url);
44  }
45 
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="//www.youtube.com/' . $url . '">' .
55  '<param name="movie" value="//www.youtube.com/' . $url . '"></param>' .
56  '<!--[if IE]>' .
57  '<embed src="//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
$config
$config
Definition: Filter.ExtractStyleBlocks.txt:33
HTMLPurifier_Filter_YouTube
Definition: YouTube.php:4
HTMLPurifier_Filter_YouTube\armorUrl
armorUrl($url)
Definition: YouTube.php:41
HTMLPurifier_Filter_YouTube\preFilter
preFilter($html, $config, $context)
Definition: YouTube.php:17
php
HTMLPurifier_Filter_YouTube\postFilter
postFilter($html, $config, $context)
Definition: YouTube.php:31
$url
URI MungeSecretKey $url
Definition: URI.MungeSecretKey.txt:14
HTMLPurifier_Filter
Definition: HTMLPurifier.standalone.php:5134
HTMLPurifier_Filter_YouTube\postFilterCallback
postFilterCallback($matches)
Definition: YouTube.php:50
HTMLPurifier_Filter_YouTube\$name
$name
Definition: YouTube.php:9
$html
$html
Definition: Filter.ExtractStyleBlocks.txt:37