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>
9 function leistungsschutzrecht_install() {
10 register_hook('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
11 register_hook('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
12 register_hook('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
16 function leistungsschutzrecht_uninstall() {
17 unregister_hook('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
18 unregister_hook('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
19 unregister_hook('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo');
22 function leistungsschutzrecht_getsiteinfo($a, &$siteinfo) {
23 if (!isset($siteinfo["url"]))
26 if (!leistungsschutzrecht_is_member_site($siteinfo["url"]))
29 //$siteinfo["title"] = $siteinfo["url"];
30 $siteinfo["text"] = leistungsschutzrecht_cuttext($siteinfo["text"]);
31 unset($siteinfo["image"]);
32 unset($siteinfo["images"]);
33 unset($siteinfo["keywords"]);
36 function leistungsschutzrecht_cuttext($text) {
37 $text = str_replace(array("\r", "\n"), array(" ", " "), $text);
41 $text = str_replace(" ", " ", $text);
42 } while ($oldtext != $text);
44 $words = explode(" ", $text);
50 foreach ($words as $word) {
56 if (++$count >= $limit) {
57 if (sizeof($words) > $limit)
66 function leistungsschutzrecht_fetchsites() {
67 require_once("include/network.php");
69 // This list works - but question is how current it is
70 $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt";
71 $sitelist = fetch_url($url);
72 $siteurls = explode(',', $sitelist);
74 $whitelist = array('tagesschau.de', 'heute.de', 'wdr.de');
77 foreach ($siteurls AS $site) {
78 if (!in_array($site, $whitelist)) {
79 $sites[$site] = $site;
83 // I would prefer parsing the list from the original site, but I haven't found a list.
84 // The following stays here to possibly reenable it in the future without having to reinvent the wheel completely.
88 $url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
90 $site = fetch_url($url);
92 $doc = new DOMDocument();
93 @$doc->loadHTML($site);
95 $xpath = new DomXPath($doc);
96 $list = $xpath->query("//td/a");
97 foreach ($list as $node) {
99 if ($node->attributes->length)
100 foreach ($node->attributes as $attribute)
101 $attr[$attribute->name] = $attribute->value;
103 if (isset($attr["href"])) {
104 $urldata = parse_url($attr["href"]);
106 if (isset($urldata["host"]) && !isset($urldata["path"])) {
107 $cleanedurlpart = explode("%", $urldata["host"]);
109 $hostname = explode(".", $cleanedurlpart[0]);
110 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
111 $sites[$site] = $site;
117 if (sizeof($sites)) {
118 set_config('leistungsschutzrecht','sites',$sites);
122 function leistungsschutzrecht_is_member_site($url) {
123 $sites = get_config('leistungsschutzrecht','sites');
128 if (sizeof($sites) == 0)
131 $urldata = parse_url($url);
133 if (!isset($urldata["host"]))
136 $cleanedurlpart = explode("%", $urldata["host"]);
138 $hostname = explode(".", $cleanedurlpart[0]);
139 $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1];
141 return (isset($sites[$site]));
144 function leistungsschutzrecht_cron($a,$b) {
145 $last = get_config('leistungsschutzrecht','last_poll');
148 $next = $last + 86400;
150 logger('poll intervall not reached');
154 leistungsschutzrecht_fetchsites();
155 set_config('leistungsschutzrecht','last_poll', time());