2014-11-13 20:56:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Leistungsschutzrecht
|
|
|
|
* Description: Only useful in germany: Remove data from snippets from members of the VG Media
|
|
|
|
* Version: 0.1
|
|
|
|
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
|
|
|
|
*/
|
2020-03-04 21:07:04 +00:00
|
|
|
|
2018-12-26 07:28:16 +00:00
|
|
|
use Friendica\Core\Hook;
|
2018-10-29 23:40:18 +00:00
|
|
|
use Friendica\Core\Logger;
|
2020-01-19 20:26:41 +00:00
|
|
|
use Friendica\DI;
|
2017-11-06 23:55:24 +00:00
|
|
|
|
2014-11-13 20:56:23 +00:00
|
|
|
function leistungsschutzrecht_install() {
|
2018-12-26 07:28:16 +00:00
|
|
|
Hook::register('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
|
|
|
|
Hook::register('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
|
|
|
|
Hook::register('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
|
2014-11-13 20:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function leistungsschutzrecht_getsiteinfo($a, &$siteinfo) {
|
2018-12-17 21:09:09 +00:00
|
|
|
if (!isset($siteinfo["url"]) || empty($siteinfo['type'])) {
|
2014-11-13 20:56:23 +00:00
|
|
|
return;
|
2018-07-31 18:10:34 +00:00
|
|
|
}
|
2014-11-13 20:56:23 +00:00
|
|
|
|
2018-12-17 21:09:09 +00:00
|
|
|
// Avoid any third party pictures, to avoid copyright issues
|
2020-01-19 20:21:12 +00:00
|
|
|
if (!in_array($siteinfo['type'], ['photo', 'video']) && DI::config()->get('leistungsschutzrecht', 'suppress_photos', false)) {
|
2018-12-17 21:09:09 +00:00
|
|
|
unset($siteinfo["image"]);
|
|
|
|
unset($siteinfo["images"]);
|
|
|
|
}
|
|
|
|
|
2018-07-31 18:10:34 +00:00
|
|
|
if (!leistungsschutzrecht_is_member_site($siteinfo["url"])) {
|
2014-11-13 20:56:23 +00:00
|
|
|
return;
|
2018-07-31 18:10:34 +00:00
|
|
|
}
|
2014-11-13 20:56:23 +00:00
|
|
|
|
2018-07-31 18:10:34 +00:00
|
|
|
if (!empty($siteinfo["text"])) {
|
|
|
|
$siteinfo["text"] = leistungsschutzrecht_cuttext($siteinfo["text"]);
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:56:23 +00:00
|
|
|
unset($siteinfo["keywords"]);
|
|
|
|
}
|
|
|
|
|
2015-09-26 09:55:59 +00:00
|
|
|
function leistungsschutzrecht_cuttext($text) {
|
2018-01-15 13:15:33 +00:00
|
|
|
$text = str_replace(["\r", "\n"], [" ", " "], $text);
|
2015-09-26 09:55:59 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
$oldtext = $text;
|
|
|
|
$text = str_replace(" ", " ", $text);
|
|
|
|
} while ($oldtext != $text);
|
|
|
|
|
|
|
|
$words = explode(" ", $text);
|
|
|
|
|
|
|
|
$text = "";
|
|
|
|
$count = 0;
|
|
|
|
$limit = 7;
|
|
|
|
|
|
|
|
foreach ($words as $word) {
|
|
|
|
if ($text != "")
|
|
|
|
$text .= " ";
|
|
|
|
|
|
|
|
$text .= $word;
|
|
|
|
|
|
|
|
if (++$count >= $limit) {
|
|
|
|
if (sizeof($words) > $limit)
|
|
|
|
$text .= " ...";
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:52:02 +00:00
|
|
|
function leistungsschutzrecht_fetchsites()
|
|
|
|
{
|
2017-07-02 19:23:58 +00:00
|
|
|
// This list works - but question is how current it is
|
|
|
|
$url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt";
|
2021-08-25 19:54:54 +00:00
|
|
|
$sitelist = DI::httpClient()->fetch($url);
|
2017-07-02 19:23:58 +00:00
|
|
|
$siteurls = explode(',', $sitelist);
|
|
|
|
|
2018-01-15 13:15:33 +00:00
|
|
|
$whitelist = ['tagesschau.de', 'heute.de', 'wdr.de'];
|
2017-07-29 08:01:02 +00:00
|
|
|
|
2018-01-15 13:15:33 +00:00
|
|
|
$sites = [];
|
2018-01-27 13:52:02 +00:00
|
|
|
foreach ($siteurls as $site) {
|
2017-07-29 08:01:02 +00:00
|
|
|
if (!in_array($site, $whitelist)) {
|
|
|
|
$sites[$site] = $site;
|
|
|
|
}
|
2017-07-02 19:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// I would prefer parsing the list from the original site, but I haven't found a list.
|
|
|
|
// The following stays here to possibly reenable it in the future without having to reinvent the wheel completely.
|
|
|
|
/*
|
2014-11-13 20:56:23 +00:00
|
|
|
$sites = array();
|
|
|
|
|
|
|
|
$url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
|
|
|
|
|
2018-01-27 16:23:04 +00:00
|
|
|
$site = Network::fetchUrl($url);
|
2014-11-13 20:56:23 +00:00
|
|
|
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
@$doc->loadHTML($site);
|
|
|
|
|
|
|
|
$xpath = new DomXPath($doc);
|
|
|
|
$list = $xpath->query("//td/a");
|
|
|
|
foreach ($list as $node) {
|
|
|
|
$attr = array();
|
|
|
|
if ($node->attributes->length)
|
|
|
|
foreach ($node->attributes as $attribute)
|
|
|
|
$attr[$attribute->name] = $attribute->value;
|
|
|
|
|
|
|
|
if (isset($attr["href"])) {
|
|
|
|
$urldata = parse_url($attr["href"]);
|
|
|
|
|
2017-06-09 01:20:27 +00:00
|
|
|
if (isset($urldata["host"]) && !isset($urldata["path"])) {
|
2014-11-13 20:56:23 +00:00
|
|
|
$cleanedurlpart = explode("%", $urldata["host"]);
|
|
|
|
|
|
|
|
$hostname = explode(".", $cleanedurlpart[0]);
|
|
|
|
$site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
|
|
|
|
$sites[$site] = $site;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-02 19:23:58 +00:00
|
|
|
*/
|
2014-11-13 20:56:23 +00:00
|
|
|
|
|
|
|
if (sizeof($sites)) {
|
2020-01-19 20:21:52 +00:00
|
|
|
DI::config()->set('leistungsschutzrecht','sites',$sites);
|
2014-11-13 20:56:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function leistungsschutzrecht_is_member_site($url) {
|
2020-01-19 20:21:12 +00:00
|
|
|
$sites = DI::config()->get('leistungsschutzrecht','sites');
|
2014-11-13 20:56:23 +00:00
|
|
|
|
|
|
|
if ($sites == "")
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
if (sizeof($sites) == 0)
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
$urldata = parse_url($url);
|
|
|
|
|
|
|
|
if (!isset($urldata["host"]))
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
$cleanedurlpart = explode("%", $urldata["host"]);
|
|
|
|
|
|
|
|
$hostname = explode(".", $cleanedurlpart[0]);
|
2018-07-10 12:30:23 +00:00
|
|
|
if (empty($hostname)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-15 18:40:20 +00:00
|
|
|
if (count($hostname) <= 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:56:23 +00:00
|
|
|
$site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
|
|
|
|
|
|
|
|
return (isset($sites[$site]));
|
|
|
|
}
|
|
|
|
|
|
|
|
function leistungsschutzrecht_cron($a,$b) {
|
2020-01-19 20:21:12 +00:00
|
|
|
$last = DI::config()->get('leistungsschutzrecht','last_poll');
|
2014-11-13 20:56:23 +00:00
|
|
|
|
|
|
|
if($last) {
|
|
|
|
$next = $last + 86400;
|
|
|
|
if($next > time()) {
|
2021-10-21 06:04:27 +00:00
|
|
|
Logger::notice('poll intervall not reached');
|
2014-11-13 20:56:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
leistungsschutzrecht_fetchsites();
|
2020-01-19 20:21:52 +00:00
|
|
|
DI::config()->set('leistungsschutzrecht','last_poll', time());
|
2014-11-13 20:56:23 +00:00
|
|
|
}
|
|
|
|
?>
|