Commit 0037c788 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

htmlpurifier filter for embedded TeacherTube videos

parent 9a67bc9d
......@@ -38,7 +38,7 @@ $themeoptions = get_themes();
$yesno = array(true => get_string('yes'),
false => get_string('no'));
$allowedfilters = array('YouTube', 'GoogleVideo');
$allowedfilters = array('YouTube', 'GoogleVideo', 'TeacherTube');
$enabledfilters = get_config('filters');
if ($enabledfilters) {
$enabledfilters = unserialize($enabledfilters);
......@@ -183,6 +183,11 @@ $siteoptionform['elements']['filters'] = array(
'title' => 'http://video.google.com',
'defaultvalue' => in_array('GoogleVideo', $enabledfilters),
),
'TeacherTube' => array(
'type' => 'checkbox',
'title' => 'http://www.teachertube.com',
'defaultvalue' => in_array('TeacherTube', $enabledfilters),
),
),
);
......
<?php
class HTMLPurifier_Filter_TeacherTube extends HTMLPurifier_Filter
{
public $name = 'TeacherTube';
public function preFilter($html, $config, $context) {
$pre_regex = '#<embed src="http://www.teachertube.com/(player/search|skin-p)/mediaplayer.swf" [^>]+\bfile=http://www.teachertube.com/flvideo/(\d+).flv\b[^>]+></embed>#s';
$pre_replace = '<span class="teachertube-embed">\2</span>';
return preg_replace($pre_regex, $pre_replace, $html);
}
public function postFilter($html, $config, $context) {
$post_regex = '#<span class="teachertube-embed">(\d+)</span>#';
$post_replace = '<embed src="http://www.teachertube.com/skin-p/mediaplayer.swf" '.
'width="425" height="350" type="application/x-shockwave-flash" allowfullscreen="true" '.
'flashvars="height=350&width=425'.
'&file=http://www.teachertube.com/flvideo/\1.flv'.
'&image=http://www.teachertube.com/thumb/\1.jpg'.
'&location=http://www.teachertube.com/skin-p/mediaplayer.swf'.
'&logo=http://www.teachertube.com/images/greylogo.swf'.
'&frontcolor=0xffffff&backcolor=0x000000&lightcolor=0xFF0000&screencolor=0xffffff'.
'&autostart=false&volume=80&overstretch=fit">'.
'</embed>';
return preg_replace($post_regex, $post_replace, $html);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment