Added options to handle elegant degradation (_ie_ replacing filtered content by same size content)

This commit is contained in:
Phyks 2013-08-05 11:49:28 +02:00
parent b4cdd31c2a
commit 1368dbe9a8
4 changed files with 30 additions and 5 deletions

View File

@ -10,7 +10,7 @@ This behavior can be fully customized in a per feed way (with either a blacklist
**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.
**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.
**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.
## Constants (_adblock_constants.php_ file)

View File

@ -68,6 +68,7 @@ function adblock_plugin_treat_events(&$events) {
$img_except_list = explode(',', trim($adblock_params["img_list"], "\t\n\r\0\x0B,"));
$img_except_list = adblock_trim_list($flash_except_list);
$elegant_degradation = (isset($adblock_params["elegant_degradation"]) && $adblock_params["elegant_degradation"] == "1") ? true : false;
foreach($events as $event) {
$filtered_content = $event->getContent();
@ -79,7 +80,12 @@ function adblock_plugin_treat_events(&$events) {
$object_list_in_event = preg_match_all("#<object.{0,}>.{0,}</object>#U", $filtered_content);
foreach($object_list_in_event as $object) {
$filtered_content = str_replace($object[0], "", $filtered_content);
if($elegant_degradation) {
$filtered_content = str_replace($object[0], "", $filtered_content);
}
else {
}
}
$event->setContent($filtered_content);
@ -93,7 +99,12 @@ function adblock_plugin_treat_events(&$events) {
$img_list_in_event = preg_match_all("#<img.{0,}src=[\"'](.{1,})[\"'].{0,}/>#U", $filtered_content);
foreach($img_list_in_event as $img) {
$filtered_content = str_replace($img[0], "", $filtered_content);
if($elegant_degradation) {
$filtered_content = str_replace($img[0], "", $filtered_content);
}
else {
}
}
$event->setContent($filtered_content);
@ -134,6 +145,10 @@ function adblock_plugin_setting_bloc(&$myUser) {
else
$img_list = "";
$elegant_degradation = (isset($adblock_params["elegant_degradation"]) && $adblock_params["elegant_degradation"] == "1") ? true : false;
$gd_available = function_exists("getimagesize");
echo '
<section id="adblockSettingsBloc">
<form action="action.php?action=adblock_update" method="POST">
@ -182,6 +197,11 @@ function adblock_plugin_setting_bloc(&$myUser) {
<textarea name="img_adblock_list" rows="7">'.$img_list.'</textarea>
</div>
</fieldset>
<p>
Elegant degradation (replace content with same-size content) ?<br/>
<input type="radio" name="adblock_elegant_degradation" value="1" id="adblock_elegant_degradation_yes" '.(($elegant_degradation) ? 'checked="checked"' : '').' '.((!$gd_available) ? 'disabled' : '').'/><label for="adblock_elegant_degradation_yes">Yes</label>'.((!$gd_available) ? ' <em>(Not available because GD seems to not be installed on your system)</em>' : '').'<br/>
<input type="radio" name="adblock_elegant_degradation" value="0" id="adblock_elegant_degradation_no" '.((!$elegant_degradation) ? 'checked="checked"' : '').'/><label for="adblock_elegant_degradation_no">No</label>
</p>
<p id="adblock_settings_submit">
<input type="submit" class="button" value="Save"/>
</p>
@ -202,7 +222,9 @@ function adblock_plugin_setting_update($_) {
$img_list = str_replace("\r\n", ",", trim($_["img_adblock_list"]));
$img_list = str_replace("\n", ",", trim($img_list));
if(file_put_contents("plugins/adblock/adblock_constants.php", "flash_enabled = ".$flash_enabled."\nflash_block = ".$flash_block."\nflash_list = ".$flash_list."\nimg_enabled = ".$img_enabled."\nimg_block = ".$img_block."\nimg_only_mobiles = ".$img_only_mobiles."\nimg_list = ".$img_list))
$elegant_degradation = (int) $_["adblock_elegant_degradation"];
if(file_put_contents("plugins/adblock/adblock_constants.php", "flash_enabled = ".$flash_enabled."\nflash_block = ".$flash_block."\nflash_list = ".$flash_list."\nimg_enabled = ".$img_enabled."\nimg_block = ".$img_block."\nimg_only_mobiles = ".$img_only_mobiles."\nimg_list = ".$img_list."\nelegant_degradation = ".$elegant_degradation))
header('location: settings.php');
else
exit("Unable to write parameters to plugins/adblock/adblock_constants.php. Check permissions on the folders.");

View File

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

View File

@ -1,3 +1,5 @@
<?php
if(!file_put_contents("plugins/adblock/adblock_constants.php", "flash_enabled = 0\nflash_block = 0\nflash_list = \"\"\nimg_enabled = 0\nimg_block = 0\nimg_only_mobiles = 0\nimg_list = \"\""))
$gd_available = function_exists("getimagesize") ? 1 : 0;
if(!file_put_contents("plugins/adblock/adblock_constants.php", "flash_enabled = 0\nflash_block = 0\nflash_list = \"\"\nimg_enabled = 0\nimg_block = 0\nimg_only_mobiles = 0\nimg_list = \"\"\nelegant_degradation = ".$gd_available."))
exit("An error occured while initalizing the file to store parameters (plugins/adblock/adblock_constants.php). Check the write permissions of the web server on the parent folders.");