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.
This commit is contained in:
parent
1368dbe9a8
commit
2915037304
@ -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.
|
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.
|
**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.
|
||||||
|
|
||||||
|
@ -16,13 +16,16 @@ function adblock_trim_list($input) {
|
|||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
foreach($input as $key=>$value) {
|
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;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adblock_plugin_treat_events(&$events) {
|
function adblock_plugin_treat_events(&$events) {
|
||||||
//Set params
|
//Set params
|
||||||
|
$configurationManager = new Configuration();
|
||||||
|
$partial = $configurationManager->get('articleView') == "partial";
|
||||||
|
|
||||||
$adblock_constants = file_get_contents("plugins/adblock/adblock_constants.php");
|
$adblock_constants = file_get_contents("plugins/adblock/adblock_constants.php");
|
||||||
$adblock_constants = explode("\n", $adblock_constants);
|
$adblock_constants = explode("\n", $adblock_constants);
|
||||||
|
|
||||||
@ -58,7 +61,7 @@ function adblock_plugin_treat_events(&$events) {
|
|||||||
$block_img = false;
|
$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;
|
$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;
|
$elegant_degradation = (isset($adblock_params["elegant_degradation"]) && $adblock_params["elegant_degradation"] == "1") ? true : false;
|
||||||
|
|
||||||
foreach($events as $event) {
|
foreach($events as $event) {
|
||||||
$filtered_content = $event->getContent();
|
$filtered_content = ($partial) ? $event->getDescription : $event->getContent();
|
||||||
|
|
||||||
// Flash handling
|
// Flash handling
|
||||||
if($filter_flash) {
|
if($filter_flash) {
|
||||||
@ -94,20 +97,30 @@ function adblock_plugin_treat_events(&$events) {
|
|||||||
|
|
||||||
// Images handling
|
// Images handling
|
||||||
if($filter_img) {
|
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
|
//Replace images
|
||||||
$img_list_in_event = preg_match_all("#<img.{0,}src=[\"'](.{1,})[\"'].{0,}/>#U", $filtered_content);
|
preg_match_all("#<img.{0,}src=[\"'](.{1,})[\"'].{0,}/?(img)?>#U", $filtered_content, $img_list_in_event, PREG_SET_ORDER);
|
||||||
|
|
||||||
foreach($img_list_in_event as $img) {
|
foreach($img_list_in_event as $img) {
|
||||||
if($elegant_degradation) {
|
if(!$elegant_degradation) {
|
||||||
$filtered_content = str_replace($img[0], "", $filtered_content);
|
$replacement_content = '
|
||||||
|
<span class="blocked_image">X</span>
|
||||||
|
';
|
||||||
|
$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
|
||||||
|
$replacement_content = '
|
||||||
|
<span class="blocked_image" style="width:'.(int) $content_size[0].'px; height:'.(int) $content_size[1].'px;"></span>
|
||||||
|
';
|
||||||
|
$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;
|
$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 '
|
echo '
|
||||||
<section id="adblockSettingsBloc">
|
<section id="adblockSettingsBloc">
|
||||||
@ -199,7 +212,7 @@ function adblock_plugin_setting_bloc(&$myUser) {
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
<p>
|
<p>
|
||||||
Elegant degradation (replace content with same-size content) ?<br/>
|
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="1" id="adblock_elegant_degradation_yes" '.(($elegant_degradation) ? 'checked="checked"' : '').' '.((!$getimagesize_available) ? 'disabled' : '').'/><label for="adblock_elegant_degradation_yes">Yes</label>'.((!$getimagesize_available) ? ' <em>(Not available because the getimagesize seems to not be available on your system or allow_url_fopen is set to Off in php.ini)</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>
|
<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>
|
||||||
<p id="adblock_settings_submit">
|
<p id="adblock_settings_submit">
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
flash_enabled = 0
|
flash_enabled = 0
|
||||||
flash_block = 0
|
flash_block = 0
|
||||||
flash_list =
|
flash_list =
|
||||||
img_enabled = 0
|
img_enabled = 1
|
||||||
img_block = 0
|
img_block = 1
|
||||||
img_only_mobiles = 0
|
img_only_mobiles = 0
|
||||||
img_list =
|
img_list =
|
||||||
elegant_degradation =
|
elegant_degradation = 0
|
||||||
|
@ -9,3 +9,13 @@
|
|||||||
#adblock_settings_submit {
|
#adblock_settings_submit {
|
||||||
text-align: center;
|
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;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$gd_available = function_exists("getimagesize") ? 1 : 0;
|
$getimagesize_available = function_exists("getimagesize") && ((ini_get("allow_url_fopen") == "1") ? true : false);
|
||||||
|
$getimagesize_available = ($getimagesize_available) ? 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."))
|
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 = ".$getimagesize_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.");
|
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.");
|
||||||
|
Loading…
Reference in New Issue
Block a user