From 9b5d91f927de19417db05f2b26be8ff32d0137d6 Mon Sep 17 00:00:00 2001 From: Phyks Date: Mon, 5 Aug 2013 22:42:10 +0200 Subject: [PATCH] First working version This version should work to block both images and flash contents. It supports elegant degradation etc. Please report any issue as I didn't test it with every feed available... --- README.md | 6 ++++- adblock/adblock.plugin.disabled.php | 39 +++++++++++++++++++---------- adblock/adblock_constants.php | 6 ++--- adblock/css/adblock_plugin_css.css | 16 +++++++++++- adblock/js/adblock_plugin_js.js | 9 +++++++ 5 files changed, 58 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4d21efa..607afb3 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,15 @@ This is a plugin for Leed written by Phyks (phyks@phyks.me) to allow a leed user * Mask all embedded flash contents in the feeds (and allow him to play this content in a click to play way) * Mask all the images in the feeds to load the pages faster +The filtered contents will be replaced by orange cross on grey background (images) or white cross on orange background (flash). + This behavior can be fully customized in a per feed way (with either a blacklist or a whitelist). You can also choose to disable images only on mobile browsers. +Please report (via the issue system on github or send me an email) any problems with this plugin and the feed experiencing problems. I can't test it with every available feed (and have fun with all the html errors that may appear in them) and will improve the plugin to fit the majority of feeds. + **Important note :** To install the plugin, just do as usual with leed plugins. The adblock folder goes in the plugins directory of your leed installation. **Don't rename** the adblock directory unless you know what you do (you will need to change some paths values in the script itself). For an elegant degradation, _ie_ replacement of the deleted content by neutral content of the same size, you will need the getimagesize available in PHP and the directive _allow_url_fopen_ set to _On_ in your php.ini config file (the plugin will verify this for you). -**Note :** This will replace all images (found by searching for <img> tags) and all embedded objects (found by searching for <object> tags). This will only mask them when you display the page (and not load them) on a server side. If you click on the replacement content, it will load the masked content. So, the content is always downloaded from the external server to your running leed instance, but is only downloaded on-demand from to your device. +**Note :** This will replace all images (found by searching for <img> tags) and all embedded objects (found by searching for iframes, as all flash content I found in my feeds are embedded _via_ iframes). This will only mask them when you display the page (and not load them) on a server side. If you click on the replacement content, it will load the masked content. So, the content is always downloaded from the external server to your running leed instance, but is only downloaded on-demand from to your device. ## Constants (_adblock_constants.php_ file) diff --git a/adblock/adblock.plugin.disabled.php b/adblock/adblock.plugin.disabled.php index 0f08e8a..8f7ce4a 100755 --- a/adblock/adblock.plugin.disabled.php +++ b/adblock/adblock.plugin.disabled.php @@ -81,18 +81,28 @@ function adblock_plugin_treat_events(&$events) { if($filter_flash) { if(($block_flash && !in_array($event->getFeed(), $flash_except_list)) || (!$block_flash && in_array($event->getFeed(), $flash_except_list))) { //Replace flash content - $object_list_in_event = preg_match_all("#.{0,}#U", $filtered_content); - + preg_match_all("##U", $filtered_content, $object_list_in_event, PREG_SET_ORDER); + foreach($object_list_in_event as $object) { - if($elegant_degradation) { - $filtered_content = str_replace($object[0], "", $filtered_content); + if(!$elegant_degradation) { + $replacement_content = ' + X + '; + $filtered_content = str_replace($object[0], $replacement_content, $filtered_content); } else { - + preg_match("#width=[\"']([0-9]{1,})[\"']#U", $object[0], $width); + preg_match("#height=[\"']([0-9]{1,})[\"']#U", $object[0], $height); + $font_size = min($width[1], $height[1]); + + $replacement_content = ' + X + '; + $filtered_content = str_replace($object[0], $replacement_content, $filtered_content); } } - $event->setContent($filtered_content); + $modified = true; } } @@ -105,14 +115,15 @@ function adblock_plugin_treat_events(&$events) { foreach($img_list_in_event as $img) { if(!$elegant_degradation) { $replacement_content = ' - X + X '; $filtered_content = str_replace($img[0], $replacement_content, $filtered_content); } else { $content_size = getimagesize($img[1]); //Index 0 is width, index 1 is height + $font_size = min($content_size[0], $content_size[1]); $replacement_content = ' - + X '; $filtered_content = str_replace($img[0], $replacement_content, $filtered_content); } @@ -121,11 +132,13 @@ function adblock_plugin_treat_events(&$events) { $modified = true; } } - - if($partial) - $event->setDescription($filtered_content); - else - $event->setContent($filtered_content); + + if($modified) { + if($partial) + $event->setDescription($filtered_content); + else + $event->setContent($filtered_content); + } } } diff --git a/adblock/adblock_constants.php b/adblock/adblock_constants.php index f9c8699..a868147 100755 --- a/adblock/adblock_constants.php +++ b/adblock/adblock_constants.php @@ -1,6 +1,6 @@ -flash_enabled = 0 -flash_block = 0 -flash_list = +flash_enabled = 1 +flash_block = 1 +flash_list = img_enabled = 1 img_block = 1 img_only_mobiles = 0 diff --git a/adblock/css/adblock_plugin_css.css b/adblock/css/adblock_plugin_css.css index d0a21dd..c05b93a 100644 --- a/adblock/css/adblock_plugin_css.css +++ b/adblock/css/adblock_plugin_css.css @@ -12,10 +12,24 @@ .blocked_image { display: inline-block; - background-color: white; + background-color: rgb(141, 141, 141); color: rgb(241, 101, 41); font-weight: bold; text-align: center; font-size: 2em; padding: 0.2em; + cursor: pointer; + max-width: 100%; +} + +.blocked_flash { + display: inline-block; + color: white; + background-color: rgb(241, 101, 41); + font-weight: bold; + text-align: center; + font-size: 2em; + padding: 0.2em; + cursor: pointer; + max-width: 100%; } diff --git a/adblock/js/adblock_plugin_js.js b/adblock/js/adblock_plugin_js.js index d6f289a..823d68d 100644 --- a/adblock/js/adblock_plugin_js.js +++ b/adblock/js/adblock_plugin_js.js @@ -13,3 +13,12 @@ function adblock_unblock_img(span, url) { $(span).removeClass("blocked_image"); return false; } + +function adblock_unblock_flash(span, new_content) { + if($(span).html() != "X") + return true; + + $(span).html(new_content); + $(span).removeClass("blocked_flash"); + return false; +}