3 * Name: Leistungsschutzrecht
4 * Description: Only useful in germany: Remove data from snippets from members of the VG Media
6 * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
8 use Friendica\Core\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Util\Network;
12 function leistungsschutzrecht_install() {
13 Addon::registerHook('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
14 Addon::registerHook('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
15 Addon::registerHook('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
19 function leistungsschutzrecht_uninstall() {
20 Addon::unregisterHook('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
21 Addon::unregisterHook('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
22 Addon::unregisterHook('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
25 function leistungsschutzrecht_getsiteinfo($a, &$siteinfo) {
26 if (!isset($siteinfo["url"])) {
30 if (!leistungsschutzrecht_is_member_site($siteinfo["url"])) {
34 //$siteinfo["title"] = $siteinfo["url"];
36 if (!empty($siteinfo["text"])) {
37 $siteinfo["text"] = leistungsschutzrecht_cuttext($siteinfo["text"]);
40 unset($siteinfo["image"]);
41 unset($siteinfo["images"]);
42 unset($siteinfo["keywords"]);
45 function leistungsschutzrecht_cuttext($text) {
46 $text = str_replace(["\r", "\n"], [" ", " "], $text);
50 $text = str_replace(" ", " ", $text);
51 } while ($oldtext != $text);
53 $words = explode(" ", $text);
59 foreach ($words as $word) {
65 if (++$count >= $limit) {
66 if (sizeof($words) > $limit)
75 function leistungsschutzrecht_fetchsites()
77 // This list works - but question is how current it is
78 $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt";
79 $sitelist = Network::fetchUrl($url);
80 $siteurls = explode(',', $sitelist);
82 $whitelist = ['tagesschau.de', 'heute.de', 'wdr.de'];
85 foreach ($siteurls as $site) {
86 if (!in_array($site, $whitelist)) {
87 $sites[$site] = $site;
91 // I would prefer parsing the list from the original site, but I haven't found a list.
92 // The following stays here to possibly reenable it in the future without having to reinvent the wheel completely.
96 $url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
98 $site = Network::fetchUrl($url);
100 $doc = new DOMDocument();
101 @$doc->loadHTML($site);
103 $xpath = new DomXPath($doc);
104 $list = $xpath->query("//td/a");
105 foreach ($list as $node) {
107 if ($node->attributes->length)
108 foreach ($node->attributes as $attribute)
109 $attr[$attribute->name] = $attribute->value;
111 if (isset($attr["href"])) {
112 $urldata = parse_url($attr["href"]);
114 if (isset($urldata["host"]) && !isset($urldata["path"])) {
115 $cleanedurlpart = explode("%", $urldata["host"]);
117 $hostname = explode(".", $cleanedurlpart[0]);
118 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
119 $sites[$site] = $site;
125 if (sizeof($sites)) {
126 Config::set('leistungsschutzrecht','sites',$sites);
130 function leistungsschutzrecht_is_member_site($url) {
131 $sites = Config::get('leistungsschutzrecht','sites');
136 if (sizeof($sites) == 0)
139 $urldata = parse_url($url);
141 if (!isset($urldata["host"]))
144 $cleanedurlpart = explode("%", $urldata["host"]);
146 $hostname = explode(".", $cleanedurlpart[0]);
147 if (empty($hostname)) {
151 if (count($hostname) <= 2) {
155 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
157 return (isset($sites[$site]));
160 function leistungsschutzrecht_cron($a,$b) {
161 $last = Config::get('leistungsschutzrecht','last_poll');
164 $next = $last + 86400;
166 logger('poll intervall not reached');
170 leistungsschutzrecht_fetchsites();
171 Config::set('leistungsschutzrecht','last_poll', time());