From 29150373045f59e645a8e97fafddcf63efbf7b0b Mon Sep 17 00:00:00 2001 From: Phyks Date: Mon, 5 Aug 2013 13:27:40 +0200 Subject: [PATCH] Basic image filtering (+ elegant degradation) works Flash content filtering may not work and image filtering may need improvements. No ability to load the image at this time, will be coming in future commits. --- README.md | 2 +- adblock/adblock.plugin.disabled.php | 39 +++++++++++++++++++---------- adblock/adblock_constants.php | 6 ++--- adblock/css/adblock_plugin_css.css | 10 ++++++++ adblock/install.php | 5 ++-- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7dcba93..4d21efa 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This is a plugin for Leed written by Phyks (phyks@phyks.me) to allow a leed user 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. -**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 GD library. +**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. diff --git a/adblock/adblock.plugin.disabled.php b/adblock/adblock.plugin.disabled.php index c31f301..88de155 100755 --- a/adblock/adblock.plugin.disabled.php +++ b/adblock/adblock.plugin.disabled.php @@ -16,13 +16,16 @@ function adblock_trim_list($input) { $output = array(); foreach($input as $key=>$value) { - $output[$key] = trim($value, "\t\n\r\0\x0B,"); + $output[$key] = trim($value, "\t\n\r\0\x0B,\""); } return $output; } function adblock_plugin_treat_events(&$events) { //Set params + $configurationManager = new Configuration(); + $partial = $configurationManager->get('articleView') == "partial"; + $adblock_constants = file_get_contents("plugins/adblock/adblock_constants.php"); $adblock_constants = explode("\n", $adblock_constants); @@ -58,7 +61,7 @@ function adblock_plugin_treat_events(&$events) { $block_img = false; } - if(isset($adblock_params["img_block"]) && $adblock_params["img_block"] == "1" && !adblock_isMobileDevice()) { //If filter only on mobile devices and not a mobile device + if(isset($adblock_params["img_only_mobiles"]) && $adblock_params["img_only_mobiles"] == "1" && !adblock_isMobileDevice()) { //If filter only on mobile devices and not a mobile device $filter_img = false; } } @@ -71,7 +74,7 @@ function adblock_plugin_treat_events(&$events) { $elegant_degradation = (isset($adblock_params["elegant_degradation"]) && $adblock_params["elegant_degradation"] == "1") ? true : false; foreach($events as $event) { - $filtered_content = $event->getContent(); + $filtered_content = ($partial) ? $event->getDescription : $event->getContent(); // Flash handling if($filter_flash) { @@ -84,7 +87,7 @@ function adblock_plugin_treat_events(&$events) { $filtered_content = str_replace($object[0], "", $filtered_content); } else { - + } } @@ -94,20 +97,30 @@ function adblock_plugin_treat_events(&$events) { // Images handling if($filter_img) { - if(($block_img && !in_array("", $img_except_list)) || (!$block_img && in_array("", $img_except_list))) { + if(($block_img && !in_array($event->getFeed(), $img_except_list)) || (!$block_img && in_array($event->getFeed(), $img_except_list))) { //Replace images - $img_list_in_event = preg_match_all("##U", $filtered_content); - + preg_match_all("##U", $filtered_content, $img_list_in_event, PREG_SET_ORDER); + foreach($img_list_in_event as $img) { - if($elegant_degradation) { - $filtered_content = str_replace($img[0], "", $filtered_content); + if(!$elegant_degradation) { + $replacement_content = ' + 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 + $replacement_content = ' + + '; + $filtered_content = str_replace($img[0], $replacement_content, $filtered_content); } } - $event->setContent($filtered_content); + if($partial) + $event->setDescription($filtered_content); + else + $event->setContent($filtered_content); } } } @@ -147,7 +160,7 @@ function adblock_plugin_setting_bloc(&$myUser) { $elegant_degradation = (isset($adblock_params["elegant_degradation"]) && $adblock_params["elegant_degradation"] == "1") ? true : false; - $gd_available = function_exists("getimagesize"); + $getimagesize_available = function_exists("getimagesize") && ((ini_get("allow_url_fopen") == "1") ? true : false); echo '
@@ -199,7 +212,7 @@ function adblock_plugin_setting_bloc(&$myUser) {

Elegant degradation (replace content with same-size content) ?
- '.((!$gd_available) ? ' (Not available because GD seems to not be installed on your system)' : '').'
+ '.((!$getimagesize_available) ? ' (Not available because the getimagesize seems to not be available on your system or allow_url_fopen is set to Off in php.ini)' : '').'

diff --git a/adblock/adblock_constants.php b/adblock/adblock_constants.php index 64ef612..5e77d8c 100755 --- a/adblock/adblock_constants.php +++ b/adblock/adblock_constants.php @@ -1,8 +1,8 @@ flash_enabled = 0 flash_block = 0 flash_list = -img_enabled = 0 -img_block = 0 +img_enabled = 1 +img_block = 1 img_only_mobiles = 0 img_list = -elegant_degradation = +elegant_degradation = 0 diff --git a/adblock/css/adblock_plugin_css.css b/adblock/css/adblock_plugin_css.css index 6ecca10..d0a21dd 100644 --- a/adblock/css/adblock_plugin_css.css +++ b/adblock/css/adblock_plugin_css.css @@ -9,3 +9,13 @@ #adblock_settings_submit { text-align: center; } + +.blocked_image { + display: inline-block; + background-color: white; + color: rgb(241, 101, 41); + font-weight: bold; + text-align: center; + font-size: 2em; + padding: 0.2em; +} diff --git a/adblock/install.php b/adblock/install.php index a87132c..7bbab11 100644 --- a/adblock/install.php +++ b/adblock/install.php @@ -1,5 +1,6 @@