영카트 5.2.9.7 버전 변경
This commit is contained in:
66
plugin/htmlpurifier/extend.video.php
Normal file
66
plugin/htmlpurifier/extend.video.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
||||
|
||||
//https://stackoverflow.com/questions/4739284/htmlpurifier-iframe-vimeo-and-youtube-video
|
||||
/**
|
||||
* Based on: http://sachachua.com/blog/2011/08/drupal-html-purifier-embedding-iframes-youtube/
|
||||
* Iframe filter that does some primitive whitelisting in a somewhat recognizable and tweakable way
|
||||
*/
|
||||
|
||||
if( !class_exists('HTMLPurifier_Filter_Iframevideo') ){
|
||||
class HTMLPurifier_Filter_iframevideo extends HTMLPurifier_Filter
|
||||
{
|
||||
public $name = 'Iframevideo';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $html
|
||||
* @param HTMLPurifier_Config $config
|
||||
* @param HTMLPurifier_Context $context
|
||||
* @return string
|
||||
*/
|
||||
public function preFilter($html, $config, $context)
|
||||
{
|
||||
$html = preg_replace('#<iframe#i', '<img class="Iframevideo"', $html);
|
||||
$html = preg_replace('#</iframe>#i', '</img>', $html);
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $html
|
||||
* @param HTMLPurifier_Config $config
|
||||
* @param HTMLPurifier_Context $context
|
||||
* @return string
|
||||
*/
|
||||
public function postFilter($html, $config, $context)
|
||||
{
|
||||
$post_regex = '#<img class="Iframevideo"([^>]+?)>#';
|
||||
return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $matches
|
||||
* @return string
|
||||
*/
|
||||
protected function postFilterCallback($matches)
|
||||
{
|
||||
// Domain Whitelist
|
||||
$youTubeMatch = preg_match('#src="https?://www.youtube(-nocookie)?.com/#i', $matches[1]);
|
||||
$vimeoMatch = preg_match('#src="http://player.vimeo.com/#i', $matches[1]);
|
||||
if ($youTubeMatch || $vimeoMatch) {
|
||||
$extra = ' frameborder="0"';
|
||||
if ($youTubeMatch) {
|
||||
$extra .= ' allowfullscreen';
|
||||
} elseif ($vimeoMatch) {
|
||||
$extra .= ' webkitAllowFullScreen mozallowfullscreen allowFullScreen';
|
||||
}
|
||||
return '<iframe ' . $matches[1] . $extra . '></iframe>';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user