@link http://www.phyks.me
@licence BEERWARE (See README.md file)
@version 2.0.0
@description The adblock plugin for leed allows to block embedded flash contents and / or images in feeds. You can set it fine-grained for each feed. You can also disable images only for mobile devices.
*/
function adblock_isMobileDevice() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
function adblock_trim_list($input) {
$output = array();
foreach($input as $key=>$value) {
$output[$key] = trim($value, "\t\n\r\0\x0B,");
}
return $output;
}
function adblock_plugin_treat_events(&$events) {
//Set params
$adblock_constants = file_get_contents("plugins/adblock/adblock_constants.php");
$adblock_constants = explode("\n", $adblock_constants);
$adblock_params = array();
foreach($adblock_constants as $adblock_constant) {
if(trim($adblock_constant) != "") {
$adblock_constant = explode("=", $adblock_constant);
$adblock_params[trim($adblock_constant[0])] = trim($adblock_constant[1]);
}
}
if(isset($adblock_params["flash_enabled"]) && $adblock_params["flash_enabled"] == "1") {
$filter_flash = true;
if(isset($adblock_params["flash_block"]) && $adblock_params["flash_block"] == "1") {
$block_flash = true;
}
else {
$block_flash = false;
}
}
else {
$filter_flash = false;
}
$flash_except_list = explode(',', trim($adblock_params["flash_list"], "\t\n\r\0\x0B,"));
$flash_except_list = adblock_trim_list($flash_except_list);
if(isset($adblock_params["img_enabled"]) && $adblock_params["img_enabled"] == "1") {
$filter_img = true;
if(isset($adblock_params["img_block"]) && $adblock_params["img_block"] == "1") {
$block_img = true;
}
else {
$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
$filter_img = false;
}
}
else {
$filter_img = false;
}
$img_except_list = explode(',', trim($adblock_params["img_list"], "\t\n\r\0\x0B,"));
$img_except_list = adblock_trim_list($flash_except_list);
foreach($events as $event) {
$filtered_content = $event->getContent();
// Flash handling
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
$event->setContent($filered_content); // TODO
}
}
// Images handling
if($filter_img) {
if(($block_img && !in_array("", $img_except_list)) || (!$block_img && in_array("", $img_except_list))) {
//Replace images
$img_list_in_event = preg_match_all("#