Images filtering now working + elegant degradation

(Tested with some feeds)

TODO : Flash filtering
This commit is contained in:
Phyks 2013-08-05 14:41:48 +02:00
parent 2915037304
commit 230d0941f3
3 changed files with 19 additions and 7 deletions

View File

@ -75,6 +75,7 @@ function adblock_plugin_treat_events(&$events) {
foreach($events as $event) { foreach($events as $event) {
$filtered_content = ($partial) ? $event->getDescription : $event->getContent(); $filtered_content = ($partial) ? $event->getDescription : $event->getContent();
$modified = false;
// Flash handling // Flash handling
if($filter_flash) { if($filter_flash) {
@ -104,26 +105,28 @@ function adblock_plugin_treat_events(&$events) {
foreach($img_list_in_event as $img) { foreach($img_list_in_event as $img) {
if(!$elegant_degradation) { if(!$elegant_degradation) {
$replacement_content = ' $replacement_content = '
<span class="blocked_image">X</span> <span class="blocked_image" onclick="return adblock_unblock_img(this, \''.$img[1].'\');">X</span>
'; ';
$filtered_content = str_replace($img[0], $replacement_content, $filtered_content); $filtered_content = str_replace($img[0], $replacement_content, $filtered_content);
} }
else { else {
$content_size = getimagesize($img[1]); //Index 0 is width, index 1 is height $content_size = getimagesize($img[1]); //Index 0 is width, index 1 is height
$replacement_content = ' $replacement_content = '
<span class="blocked_image" style="width:'.(int) $content_size[0].'px; height:'.(int) $content_size[1].'px;"></span> <span class="blocked_image" style="width:'.(int) $content_size[0].'px; height:'.(int) $content_size[1].'px; max-width: 100%;" onclick="return adblock_unblock_img(this, \''.$img[1].'\'):"></span>
'; ';
$filtered_content = str_replace($img[0], $replacement_content, $filtered_content); $filtered_content = str_replace($img[0], $replacement_content, $filtered_content);
} }
} }
$modified = true;
}
}
if($partial) if($partial)
$event->setDescription($filtered_content); $event->setDescription($filtered_content);
else else
$event->setContent($filtered_content); $event->setContent($filtered_content);
} }
}
}
} }
function adblock_plugin_setting_link(&$myUser) { function adblock_plugin_setting_link(&$myUser) {

View File

@ -5,4 +5,4 @@ img_enabled = 1
img_block = 1 img_block = 1
img_only_mobiles = 0 img_only_mobiles = 0
img_list = img_list =
elegant_degradation = 0 elegant_degradation = 1

View File

@ -4,3 +4,12 @@ function adblock_whitelist_blacklist(id, whitelist_blacklist) {
else else
document.getElementById(id).innerHTML = "Blacklist :"; document.getElementById(id).innerHTML = "Blacklist :";
} }
function adblock_unblock_img(span, url) {
if($(span).html() != "X")
return true;
$(span).html("<img src='"+url+"'/>");
$(span).removeClass("blocked_image");
return false;
}