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"]))
29 if (!leistungsschutzrecht_is_member_site($siteinfo["url"]))
32 //$siteinfo["title"] = $siteinfo["url"];
33 $siteinfo["text"] = leistungsschutzrecht_cuttext($siteinfo["text"]);
34 unset($siteinfo["image"]);
35 unset($siteinfo["images"]);
36 unset($siteinfo["keywords"]);
39 function leistungsschutzrecht_cuttext($text) {
40 $text = str_replace(["\r", "\n"], [" ", " "], $text);
44 $text = str_replace(" ", " ", $text);
45 } while ($oldtext != $text);
47 $words = explode(" ", $text);
53 foreach ($words as $word) {
59 if (++$count >= $limit) {
60 if (sizeof($words) > $limit)
69 function leistungsschutzrecht_fetchsites()
71 // This list works - but question is how current it is
72 $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt";
73 $sitelist = Network::fetchUrl($url);
74 $siteurls = explode(',', $sitelist);
76 $whitelist = ['tagesschau.de', 'heute.de', 'wdr.de'];
79 foreach ($siteurls as $site) {
80 if (!in_array($site, $whitelist)) {
81 $sites[$site] = $site;
85 // I would prefer parsing the list from the original site, but I haven't found a list.
86 // The following stays here to possibly reenable it in the future without having to reinvent the wheel completely.
90 $url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
92 $site = Network::fetchUrl($url);
94 $doc = new DOMDocument();
95 @$doc->loadHTML($site);
97 $xpath = new DomXPath($doc);
98 $list = $xpath->query("//td/a");
99 foreach ($list as $node) {
101 if ($node->attributes->length)
102 foreach ($node->attributes as $attribute)
103 $attr[$attribute->name] = $attribute->value;
105 if (isset($attr["href"])) {
106 $urldata = parse_url($attr["href"]);
108 if (isset($urldata["host"]) && !isset($urldata["path"])) {
109 $cleanedurlpart = explode("%", $urldata["host"]);
111 $hostname = explode(".", $cleanedurlpart[0]);
112 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
113 $sites[$site] = $site;
119 if (sizeof($sites)) {
120 Config::set('leistungsschutzrecht','sites',$sites);
124 function leistungsschutzrecht_is_member_site($url) {
125 $sites = Config::get('leistungsschutzrecht','sites');
130 if (sizeof($sites) == 0)
133 $urldata = parse_url($url);
135 if (!isset($urldata["host"]))
138 $cleanedurlpart = explode("%", $urldata["host"]);
140 $hostname = explode(".", $cleanedurlpart[0]);
141 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
143 return (isset($sites[$site]));
146 function leistungsschutzrecht_cron($a,$b) {
147 $last = Config::get('leistungsschutzrecht','last_poll');
150 $next = $last + 86400;
152 logger('poll intervall not reached');
156 leistungsschutzrecht_fetchsites();
157 Config::set('leistungsschutzrecht','last_poll', time());