Skip to content
Snippets Groups Projects
Commit 0344c7f1 authored by Phil Höfer's avatar Phil Höfer
Browse files

Merge branch '1324-implement-conditional-url-blocking' into 'development'

Resolve "Implement Conditional URL Blocking"

Closes #1324

See merge request !2226
parents a7d4cbb6 0b9cfcb6
No related branches found
No related tags found
2 merge requests!2227Development,!2226Resolve "Implement Conditional URL Blocking"
...@@ -89,17 +89,23 @@ class MetaGer ...@@ -89,17 +89,23 @@ class MetaGer
public function __construct($hash = "") public function __construct($hash = "")
{ {
# Timer starten # start timer
$this->starttime = microtime(true); $this->starttime = microtime(true);
# Versuchen Blacklists einzulesen # Read blocklists
if (file_exists(config_path() . "/blacklistDomains.txt") && file_exists(config_path() . "/blacklistUrl.txt")) { if (file_exists(config_path() . "/blacklistDomains.txt") && file_exists(config_path() . "/blacklistUrl.txt")) {
$tmp = file_get_contents(config_path() . "/blacklistDomains.txt"); $tmp = file_get_contents(config_path() . "/blacklistDomains.txt");
$this->domainsBlacklisted = explode("\n", $tmp); $this->domainsBlacklisted = explode("\n", $tmp);
$tmp = file_get_contents(config_path() . "/blacklistUrl.txt"); $tmp = file_get_contents(config_path() . "/blacklistUrl.txt");
$this->urlsBlacklisted = explode("\n", $tmp); $lines = explode("\n", $tmp);
$filtered_lines = array_filter($lines, function($line) {
return strpos(trim($line), '#') !== 0;
});
# Re-index the array (array_filter preserves keys by default)
$filtered_lines = array_values($filtered_lines);
$this->urlsBlacklisted = $filtered_lines;
} }
# Versuchen Blacklists einzulesen # Read blocklists
if (file_exists(config_path() . "/adBlacklistDomains.txt")) { if (file_exists(config_path() . "/adBlacklistDomains.txt")) {
$tmp = file_get_contents(config_path() . "/adBlacklistDomains.txt"); $tmp = file_get_contents(config_path() . "/adBlacklistDomains.txt");
$this->adDomainsBlacklisted = explode("\n", $tmp); $this->adDomainsBlacklisted = explode("\n", $tmp);
......
...@@ -294,7 +294,10 @@ class Result ...@@ -294,7 +294,10 @@ class Result
{ {
if ( if (
($this->strippedHost !== "" && (in_array($this->strippedHost, $metager->getDomainBlacklist()) || ($this->strippedHost !== "" && (in_array($this->strippedHost, $metager->getDomainBlacklist()) ||
in_array($this->strippedLink, $metager->getUrlBlacklist()))) in_array($this->strippedLink, $metager->getUrlBlacklist()) ||
in_array($this->strippedLink . "|" . strtolower(app(SearchSettings::class)->q), $metager->getUrlBlacklist())
)
)
) { ) {
return true; return true;
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment