Commit 73d5db45 authored by Karl Hasselbring's avatar Karl Hasselbring
Browse files

urls mit bestimmten wörtern auszuschließen ins jetzt über -url:<Wort> möglich

parent 218093ec
......@@ -24,6 +24,7 @@ class MetaGer
protected $site;
protected $hostBlacklist = [];
protected $domainBlacklist = [];
private $urlBlacklist = [];
protected $stopWords = [];
protected $phrases = [];
protected $engines = [];
......@@ -1023,12 +1024,13 @@ class MetaGer
$this->searchCheckSitesearch($site);
$this->searchCheckHostBlacklist();
$this->searchCheckDomainBlacklist();
$this->searchCheckUrlBlacklist();
$this->searchCheckPhrase();
$this->searchCheckStopwords();
$this->searchCheckNoSearch();
}
public function searchCheckSitesearch($site)
private function searchCheckSitesearch($site)
{
// matches '[... ]site:test.de[ ...]'
while (preg_match("/(^|.+\s)site:(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
......@@ -1040,13 +1042,14 @@ class MetaGer
}
}
public function searchCheckHostBlacklist()
private function searchCheckHostBlacklist()
{
// matches '[... ]-site:test.de[ ...]'
while (preg_match("/(^|.+\s)-site:([^\s\*]\S*)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->hostBlacklist[] = $match[2];
$this->q = $match[1] . $match[3];
}
// print the host blacklist as a user warning
if (sizeof($this->hostBlacklist) > 0) {
$hostString = "";
foreach ($this->hostBlacklist as $host) {
......@@ -1057,13 +1060,14 @@ class MetaGer
}
}
public function searchCheckDomainBlacklist()
private function searchCheckDomainBlacklist()
{
// matches '[... ]-site:*.test.de[ ...]'
while (preg_match("/(^|.+\s)-site:\*\.(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->domainBlacklist[] = $match[2];
$this->q = $match[1] . $match[3];
}
// print the domain blacklist as a user warning
if (sizeof($this->domainBlacklist) > 0) {
$domainString = "";
foreach ($this->domainBlacklist as $domain) {
......@@ -1074,13 +1078,32 @@ class MetaGer
}
}
public function searchCheckStopwords()
private function searchCheckUrlBlacklist()
{
// matches '[... ]-site:*.test.de[ ...]'
while (preg_match("/(^|.+\s)-url:(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->urlBlacklist[] = $match[2];
$this->q = $match[1] . $match[3];
}
// print the url blacklist as a user warning
if (sizeof($this->urlBlacklist) > 0) {
$urlString = "";
foreach ($this->urlBlacklist as $url) {
$urlString .= $url . ", ";
}
$urlString = rtrim($urlString, ", ");
$this->warnings[] = trans('metaGer.formdata.urlBlacklist', ['url' => $urlString]);
}
}
private function searchCheckStopwords()
{
// matches '[... ]-test[ ...]'
while (preg_match("/(^|.+\s)-(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->stopWords[] = $match[2];
$this->q = $match[1] . $match[3];
}
// print the stopwords as a user warning
if (sizeof($this->stopWords) > 0) {
$stopwordsString = "";
foreach ($this->stopWords as $stopword) {
......@@ -1091,7 +1114,7 @@ class MetaGer
}
}
public function searchCheckPhrase()
private function searchCheckPhrase()
{
$p = "";
$tmp = $this->q;
......@@ -1109,7 +1132,7 @@ class MetaGer
}
}
public function searchCheckNoSearch()
private function searchCheckNoSearch()
{
if ($this->q === "") {
$this->warnings[] = trans('metaGer.formdata.noSearch');
......@@ -1447,6 +1470,11 @@ class MetaGer
return $this->domainBlacklist;
}
public function getUserUrlBlacklist()
{
return $this->urlBlacklist;
}
public function getDomainBlacklist()
{
return $this->domainsBlacklisted;
......
......@@ -216,12 +216,17 @@ class Result
# Überprüft ob das Ergebnis aus irgendwelchen Gründen unerwünscht ist.
public function isValid(\App\MetaGer $metager)
{
# Perönliche URL und Domain Blacklist
if (in_array($this->strippedHost, $metager->getUserHostBlacklist())
|| in_array($this->strippedDomain, $metager->getUserDomainBlacklist())) {
# Perönliche Host und Domain Blacklist
if (in_array(strtolower($this->strippedHost), $metager->getUserHostBlacklist())
|| in_array(strtolower($this->strippedDomain), $metager->getUserDomainBlacklist())) {
return false;
}
# Persönliche URL Blacklist
foreach ($metager->getUserUrlBlacklist() as $word) {
if (strpos(strtolower($this->link), $word)) return false;
}
# Allgemeine URL und Domain Blacklist
if ($this->strippedHost !== "" && (in_array($this->strippedHost, $metager->getDomainBlacklist()) || in_array($this->strippedLink, $metager->getUrlBlacklist()))) {
return false;
......
......@@ -11,8 +11,8 @@ return [
'formdata.noSearch' => 'Achtung: Sie haben keinen Suchbegriff eingegeben. Sie können ihre Suchbegriffe oben eingeben und es erneut versuchen.',
'formdata.dartEurope' => 'Hinweis: Sie haben Dart-Europe aktiviert. Die Suche kann deshalb länger dauern und die maximale Suchzeit wurde auf 10 Sekunden hochgesetzt.',
'formdata.hostBlacklist' => 'Ergebnisse von folgenden Hosts werden nicht angezeigt: ":host"',
'formdata.domainBlacklist' => 'Ergebnisse von folgenden Domains werden nicht angezeigt: ":domain"',
'formdata.urlBlacklist' => 'Ergebnisse mit URLs die folgendes nicht beinhalten werden nicht angezeigt: ":url"',
'formdata.stopwords' => 'Sie machen eine Ausschlusssuche. Ergebnisse mit folgenden Wörtern werden nicht angezeigt: ":stopwords"',
'formdata.phrase' => 'Sie führen eine Phrasensuche durch: :phrase',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment