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\Config;
9 use Friendica\Core\Hook;
10 use Friendica\Core\Logger;
11 use Friendica\Util\Network;
13 function leistungsschutzrecht_install() {
14 Hook::register('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
15 Hook::register('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
16 Hook::register('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
20 function leistungsschutzrecht_uninstall() {
21 Hook::unregister('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
22 Hook::unregister('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
23 Hook::unregister('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
26 function leistungsschutzrecht_getsiteinfo($a, &$siteinfo) {
27 if (!isset($siteinfo["url"])) {
31 if (!leistungsschutzrecht_is_member_site($siteinfo["url"])) {
35 //$siteinfo["title"] = $siteinfo["url"];
37 if (!empty($siteinfo["text"])) {
38 $siteinfo["text"] = leistungsschutzrecht_cuttext($siteinfo["text"]);
41 unset($siteinfo["image"]);
42 unset($siteinfo["images"]);
43 unset($siteinfo["keywords"]);
46 function leistungsschutzrecht_cuttext($text) {
47 $text = str_replace(["\r", "\n"], [" ", " "], $text);
51 $text = str_replace(" ", " ", $text);
52 } while ($oldtext != $text);
54 $words = explode(" ", $text);
60 foreach ($words as $word) {
66 if (++$count >= $limit) {
67 if (sizeof($words) > $limit)
76 function leistungsschutzrecht_fetchsites()
78 // This list works - but question is how current it is
79 $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt";
80 $sitelist = Network::fetchUrl($url);
81 $siteurls = explode(',', $sitelist);
83 $whitelist = ['tagesschau.de', 'heute.de', 'wdr.de'];
86 foreach ($siteurls as $site) {
87 if (!in_array($site, $whitelist)) {
88 $sites[$site] = $site;
92 // I would prefer parsing the list from the original site, but I haven't found a list.
93 // The following stays here to possibly reenable it in the future without having to reinvent the wheel completely.
97 $url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
99 $site = Network::fetchUrl($url);
101 $doc = new DOMDocument();
102 @$doc->loadHTML($site);
104 $xpath = new DomXPath($doc);
105 $list = $xpath->query("//td/a");
106 foreach ($list as $node) {
108 if ($node->attributes->length)
109 foreach ($node->attributes as $attribute)
110 $attr[$attribute->name] = $attribute->value;
112 if (isset($attr["href"])) {
113 $urldata = parse_url($attr["href"]);
115 if (isset($urldata["host"]) && !isset($urldata["path"])) {
116 $cleanedurlpart = explode("%", $urldata["host"]);
118 $hostname = explode(".", $cleanedurlpart[0]);
119 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
120 $sites[$site] = $site;
126 if (sizeof($sites)) {
127 Config::set('leistungsschutzrecht','sites',$sites);
131 function leistungsschutzrecht_is_member_site($url) {
132 $sites = Config::get('leistungsschutzrecht','sites');
137 if (sizeof($sites) == 0)
140 $urldata = parse_url($url);
142 if (!isset($urldata["host"]))
145 $cleanedurlpart = explode("%", $urldata["host"]);
147 $hostname = explode(".", $cleanedurlpart[0]);
148 if (empty($hostname)) {
152 if (count($hostname) <= 2) {
156 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
158 return (isset($sites[$site]));
161 function leistungsschutzrecht_cron($a,$b) {
162 $last = Config::get('leistungsschutzrecht','last_poll');
165 $next = $last + 86400;
167 Logger::log('poll intervall not reached');
171 leistungsschutzrecht_fetchsites();
172 Config::set('leistungsschutzrecht','last_poll', time());