Commit 7f43dde7 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow twitter badges/buttons through htmlpurifier, tinymce

parent af50e312
......@@ -38,7 +38,7 @@ $themeoptions = get_themes();
$yesno = array(true => get_string('yes'),
false => get_string('no'));
$allowedfilters = array('YouTube', 'GoogleVideo', 'TeacherTube', 'SciVee', 'Skype');
$allowedfilters = array('YouTube', 'GoogleVideo', 'TeacherTube', 'SciVee', 'Skype', 'Twitter'); //@todo read from the htmlpurifiercustom directory
$enabledfilters = get_config('filters');
if ($enabledfilters) {
$enabledfilters = unserialize($enabledfilters);
......@@ -209,6 +209,11 @@ $siteoptionform['elements']['filters'] = array(
'title' => 'http://skype.com',
'defaultvalue' => in_array('Skype', $enabledfilters),
),
'Twitter' => array(
'type' => 'checkbox',
'title' => 'http://twitter.com',
'defaultvalue' => in_array('Twitter', $enabledfilters),
),
),
);
......
<?php
class HTMLPurifier_Filter_Twitter extends HTMLPurifier_Filter
{
public $name = 'Twitter';
public function preFilter($html, $config, $context) {
$pre_regex = array(
'#<div id="twitter_div">\s*<h2 class="sidebar-title">([^<]*)</h2>\s*<ul id="twitter_update_list"></ul>\s*</div>\s*'.
'<script\b[^>]+?\bsrc="http://twitter.com/javascripts/blogger.js"[^>]*></script>\s*'.
'<script\b[^>]+?\bsrc="http://twitter.com/statuses/user_timeline/([a-zA-Z0-9_]+).json\?callback=twitterCallback2&(?:amp;)?count=(\d+)"[^>]*></script>#s',
'#<embed\b[^>]+\bsrc="http://twitter.com/flash/twitter_badge.swf"[^>]+?\bflashvars="([^"]+)"[^>]*>\s*</embed>#s',
'#<embed\b[^>]+\bsrc="http://static.twitter.com/flash/twitter_timeline_badge.swf"[^>]+?\bflashvars="([^"]+)"[^>]*>\s*</embed>#s',
);
$pre_replace = array(
'<span class="twitter-updates-js"><span class="title">\1</span><span class="username">\2</span><span class="count">\3</span></span>',
'<span class="twitter-badge-flash">\1</span>',
'<span class="twitter-timeline-badge-flash">\1</span>',
);
return preg_replace($pre_regex, $pre_replace, $html);
}
public function postFilter($html, $config, $context) {
$post_regex = array(
'#<span class="twitter-updates-js"><span class="title">([^<]+)</span><span class="username">([a-zA-Z0-9_]+)</span><span class="count">(\d+)</span></span>#',
'#<span class="twitter-badge-flash">([^"]+)</span>#',
'#<span class="twitter-timeline-badge-flash">([^"]+)</span>#',
);
$post_replace = array(
'<div id="twitter_div"><h2 class="sidebar-title">\1</h2><ul id="twitter_update_list"></ul></div>'.
'<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>'.
'<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/\2.json?callback=twitterCallback2&amp;count=\3"></script>',
'<object width="176" height="176" data="http://twitter.com/flash/twitter_badge.swf">'.
'<param name="flashvars" value="\1">'.
'<param name="name" value="twitter_badge">'.
'<!--[if IE]>'.
'<embed src="http://twitter.com/flash/twitter_badge.swf" '.
'flashvars="\1" quality="high" width="176" height="176" name="twitter_badge" '.
'align="middle" allowScriptAccess="always" wmode="transparent" type="application/x-shockwave-flash" '.
'pluginspage="http://www.macromedia.com/go/getflashplayer" />'.
'<![endif]-->'.
'</object>',
'<object width="200" height="400" data="http://static.twitter.com/flash/twitter_timeline_badge.swf">'.
'<param name="flashvars" value="\1">'.
'<param name="name" value="twitter_timeline_badge">'.
'<!--[if IE]>'.
'<embed src="http://static.twitter.com/flash/twitter_timeline_badge.swf" '.
'flashvars="\1" width="200" height="400" quality="high" name="twitter_timeline_badge" '.
'align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" '.
'pluginspage="http://www.adobe.com/go/getflashplayer" />'.
'<![endif]-->'.
'</object>',
);
return preg_replace($post_regex, $post_replace, $html);
}
}
......@@ -170,7 +170,7 @@ 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]",
extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language],+ul[id|type|compact]",
urlconverter_callback : "custom_urlconvert",
language: '{$language}',
content_css : {$content_css},
......
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