diff --git a/app/MetaGer.php b/app/MetaGer.php index 664cf6b77d0c7ffe2de8d5ae296ef0be0e4ccb83..19d34f507891fb3a16ec8b1a92032db6bb6c2b78 100644 --- a/app/MetaGer.php +++ b/app/MetaGer.php @@ -1034,40 +1034,52 @@ class MetaGer public function checkSpecialSearches(Request $request) { - if ($request->has('site')) { - $site = $request->input('site'); - } else { - $site = ""; - } - - $this->searchCheckSitesearch($site); - $this->searchCheckHostBlacklist(); - $this->searchCheckDomainBlacklist(); + $this->searchCheckSitesearch($request); + $this->searchCheckHostBlacklist($request); + $this->searchCheckDomainBlacklist($request); $this->searchCheckUrlBlacklist(); $this->searchCheckPhrase(); - $this->searchCheckStopwords(); + $this->searchCheckStopwords($request); $this->searchCheckNoSearch(); } - private function searchCheckSitesearch($site) + private function searchCheckSitesearch($request) { // matches '[... ]site:test.de[ ...]' while (preg_match("/(^|.+\s)site:(\S+)(?:\s(.+)|($))/si", $this->q, $match)) { $this->site = $match[2]; $this->q = $match[1] . $match[3]; } - if ($site !== "") { - $this->site = $site; + # Overwrite Setting if it's submitted via Parameter + if ($request->has('site')) { + $this->site = $request->input('site'); } } - private function searchCheckHostBlacklist() + private function searchCheckHostBlacklist($request) { // 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]; } + # Overwrite Setting if it's submitted via Parameter + if($request->has('blacklist')){ + $this->hostBlacklist = []; + $blacklistString = trim($request->input('blacklist')); + if(strpos($blacklistString, ",") !== FALSE){ + $blacklistArray = explode(',', $blacklistString); + foreach($blacklistArray as $blacklistElement){ + $blacklistElement = trim($blacklistElement); + if(strpos($blacklistElement, "*") !== 0){ + $this->hostBlacklist[] = $blacklistElement; + } + } + }else if(strpos($blacklistString, "*") !== 0){ + $this->hostBlacklist[] = $blacklistString; + } + } + // print the host blacklist as a user warning if (sizeof($this->hostBlacklist) > 0) { $hostString = ""; @@ -1079,13 +1091,29 @@ class MetaGer } } - private function searchCheckDomainBlacklist() + private function searchCheckDomainBlacklist($request) { // 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]; } + # Overwrite Setting if it's submitted via Parameter + if($request->has('blacklist')){ + $this->domainBlacklist = []; + $blacklistString = trim($request->input('blacklist')); + if(strpos($blacklistString, ",") !== FALSE){ + $blacklistArray = explode(',', $blacklistString); + foreach($blacklistArray as $blacklistElement){ + $blacklistElement = trim($blacklistElement); + if(strpos($blacklistElement, "*.") === 0){ + $this->domainBlacklist[] = substr($blacklistElement, strpos($blacklistElement, "*.")+2); + } + } + }else if(strpos($blacklistString, "*.") === 0){ + $this->domainBlacklist[] = substr($blacklistString, strpos($blacklistString, "*.")+2); + } + } // print the domain blacklist as a user warning if (sizeof($this->domainBlacklist) > 0) { $domainString = ""; @@ -1115,13 +1143,27 @@ class MetaGer } } - private function searchCheckStopwords() + private function searchCheckStopwords($request) { // matches '[... ]-test[ ...]' while (preg_match("/(^|.+\s)-(\S+)(?:\s(.+)|($))/si", $this->q, $match)) { $this->stopWords[] = $match[2]; $this->q = $match[1] . $match[3]; } + # Overwrite Setting if submitted via Parameter + if($request->has('stop')){ + $this->stopWords = []; + $stop = trim($request->input('stop')); + if(strpos($stop, ',') !== FALSE){ + $stopArray = explode(',', $stop); + foreach($stopArray as $stopElement){ + $stopElement = trim($stopElement); + $this->stopWords[] = $stopElement; + } + }else{ + $this->stopWords[] = $stop; + } + } // print the stopwords as a user warning if (sizeof($this->stopWords) > 0) { $stopwordsString = "";