Commit 90f8bdbe authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add htmlpurifier filter for Skype button; let script tags through from TinyMCE...

Add htmlpurifier filter for Skype button; let script tags through from TinyMCE & don't rewrite 'skype:' urls
parent a8cdf976
......@@ -38,7 +38,7 @@ $themeoptions = get_themes();
$yesno = array(true => get_string('yes'),
false => get_string('no'));
$allowedfilters = array('YouTube', 'GoogleVideo', 'TeacherTube', 'SciVee');
$allowedfilters = array('YouTube', 'GoogleVideo', 'TeacherTube', 'SciVee', 'Skype');
$enabledfilters = get_config('filters');
if ($enabledfilters) {
$enabledfilters = unserialize($enabledfilters);
......@@ -193,6 +193,11 @@ $siteoptionform['elements']['filters'] = array(
'title' => 'http://www.scivee.tv',
'defaultvalue' => in_array('SciVee', $enabledfilters),
),
'Skype' => array(
'type' => 'checkbox',
'title' => 'http://skype.com',
'defaultvalue' => in_array('Skype', $enabledfilters),
),
),
);
......
<?php
class HTMLPurifier_Filter_Skype extends HTMLPurifier_Filter
{
public $name = 'Skype';
public function preFilter($html, $config, $context) {
$pre_regex = '#<script\b[^>]+?\bsrc="http://download.skype.com/share/skypebuttons/js/skypeCheck.js"[^>]*>\s*</script>\s*<a\b[^>]+?\bhref="skype:([^?"<>]+)\?call"[^>]*>\s*(<img\b[^>]+?>)\s*</a>#s';
$pre_replace = '<span class="skype-button"><span class="skype-name">\1</span>\2</span>';
return preg_replace($pre_regex, $pre_replace, $html);
}
public function postFilter($html, $config, $context) {
$post_regex = '#<span class="skype-button"><span class="skype-name">([^"?<>]+)</span>(<img\b[^>]+>)</span>#';
$post_replace = '<script type="text/javascript" src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js"></script><a href="skype:\1?call">\2</a>';
return preg_replace($post_regex, $post_replace, $html);
}
}
......@@ -139,7 +139,6 @@ function &smarty($javascript = array(), $headers = array(), $pagestrings = array
theme_advanced_buttons3 : "fontselect,separator,fontsizeselect,separator,formatselect",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode]",
//width: '512',
EOF;
}
......@@ -154,7 +153,6 @@ EOF;
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode]",
fullscreen_new_window: true,
fullscreen_settings: {
theme: "advanced",
......@@ -172,11 +170,20 @@ tinyMCE.init({
button_tile_map: true,
{$tinymce_config}
{$execcommand}
extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language]",
urlconverter_callback : "custom_urlconvert",
language: '{$language}',
content_css : {$content_css},
//document_base_url: {$jswwwroot},
relative_urls: false
});
function custom_urlconvert (url, node, on_save) {
// Don't convert the url on the skype status buttons.
if (url.indexOf('skype:') == 0) {
return url;
}
return TinyMCE.prototype.convertURL(url, node, on_save);
}
</script>
EOF;
......
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