Commit 9096a18c authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch 'development' into 'master'

Development

See merge request !1966
parents f6dc0021 6e01b0b5
......@@ -67,11 +67,16 @@ class SettingsController extends Controller
# Reading cookies for black list entries
$blacklist = [];
foreach ($cookies as $key => $value) {
if (stripos($key, 'blpage') !== false && stripos($key, $fokus) !== false) {
$blacklist[$key] = $value;
if (preg_match('/_blpage[0-9]+$/', $key) === 1 && stripos($key, $fokus) !== false) {
$blacklist[] = $value;
} elseif (preg_match('/_blpage$/', $key) === 1 && stripos($key, $fokus) !== false) {
$blacklist = array_merge($blacklist, explode(",", $value));
}
}
$blacklist = array_unique($blacklist);
sort($blacklist);
# Generating link with set cookies
$cookieLink = LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('loadSettings', $cookies));
......@@ -338,42 +343,55 @@ class SettingsController extends Controller
$fokus = $request->input('fokus', '');
$url = $request->input('url', '');
$regexProtocol = '#^([a-z]{0,5}://)?(www.)?#';
$blacklist = preg_filter($regexProtocol, '', $request->input('blacklist'));
$blacklist = $request->input('blacklist');
$blacklist = substr($blacklist, 0, 2048);
if (stripos($blacklist, '/') !== false) {
$blacklist = substr($blacklist, 0, stripos($blacklist, '/'));
}
#fixme: this doesn't match all valid URLs
$regexUrl = '#^(\*\.)?[a-z0-9-]+(\.[a-z0-9]+)?(\.[a-z0-9]{2,})$#';
if (preg_match($regexUrl, $blacklist) === 1) {
$path = \Request::path();
$cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5);
$cookies = Cookie::get();
$cookieCounter = 0;
$noduplicate = true;
ksort($cookies);
if (!empty($cookies)) {
foreach ($cookies as $key => $value) {
if (stripos($key, $fokus . '_blpage') === 0) {
if ($value === $blacklist) {
$noduplicate = false;
break;
}
if ((int)(substr($key, strlen($fokus . '_blpage'))) === $cookieCounter) {
$cookieCounter++;
}
}
}
// Split the blacklist by all sorts of newlines
$blacklist = preg_split('/\r\n|[\r\n]/', $blacklist);
$valid_blacklist_entries = [];
foreach ($blacklist as $blacklist_entry) {
$regexProtocol = '#^([a-z]{0,5}://)?(www.)?#';
$blacklist_entry = preg_filter($regexProtocol, '', $blacklist_entry);
# Allow Only Domains without path
if (stripos($blacklist_entry, '/') !== false) {
$blacklist_entry = substr($blacklist_entry, 0, stripos($blacklist_entry, '/'));
}
if ($noduplicate && !empty($blacklist) > 0 && strlen($blacklist) <= 255) {
$cookieName = $fokus . '_blpage' . $cookieCounter;
Cookie::queue($cookieName, $blacklist, 525600, $cookiePath, null, false, false);
#fixme: this doesn't match all valid URLs
$regexUrl = '#^(\*\.)?[a-z0-9-]+(\.[a-z0-9]+)?(\.[a-z0-9]{2,})$#';
if (preg_match($regexUrl, $blacklist_entry) === 1) {
$valid_blacklist_entries[] = $blacklist_entry;
}
}
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url])));
# Check if any setting is active
$cookies = Cookie::get();
# Remove all cookies from the old method where they got stored
# in multiple Cookies.
# The old cookies are in the request currently send so just delete the old cookie
foreach ($cookies as $key => $value) {
if (preg_match('/_blpage[0-9]+$/', $key) === 1 && stripos($key, $fokus) !== false) {
$path = \Request::path();
$cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5);
Cookie::queue($key, "", 0, $cookiePath, null, false, false);
}
}
$valid_blacklist_entries = array_unique($valid_blacklist_entries);
sort($valid_blacklist_entries);
$path = \Request::path();
$cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5);
$cookieName = $fokus . '_blpage';
Cookie::queue($cookieName, implode(",", $valid_blacklist_entries), 525600, $cookiePath, null, false, false);
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url])) . "#bl");
}
public function deleteBlacklist(Request $request)
......@@ -386,7 +404,7 @@ class SettingsController extends Controller
Cookie::queue($cookieKey, "", 0, $cookiePath, null, false, false);
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url])));
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url])) . "#bl");
}
public function clearBlacklist(Request $request)
......@@ -456,4 +474,8 @@ class SettingsController extends Controller
}
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), url('/')));
}
private function loadBlacklist(Request $request)
{
}
}
......@@ -1333,22 +1333,21 @@ class MetaGer
$this->hostBlacklist[] = $blacklistString;
}
}
foreach (Cookie::get() as $key => $value) {
if ((stripos($key, $this->fokus . '_blpage') === 0) && (stripos($value, '*.') === false)) {
$this->hostBlacklist[] = $value;
}
}
$this->hostBlacklist = array_unique($this->hostBlacklist);
// print the host blacklist as a user warning
if (sizeof($this->hostBlacklist) > 0) {
$hostString = "";
foreach ($this->hostBlacklist as $host) {
$hostString .= $host . ", ";
if (sizeof($this->hostBlacklist) <= 3) {
$hostString = "";
foreach ($this->hostBlacklist as $host) {
$hostString .= $host . ", ";
}
$hostString = rtrim($hostString, ", ");
$this->warnings[] = trans('metaGer.formdata.hostBlacklist', ['host' => $hostString]);
} else {
$this->warnings[] = trans('metaGer.formdata.hostBlacklistCount', ['count' => sizeof($this->hostBlacklist)]);
}
$hostString = rtrim($hostString, ", ");
$this->warnings[] = trans('metaGer.formdata.hostBlacklist', ['host' => $hostString]);
}
}
......@@ -1376,8 +1375,17 @@ class MetaGer
}
}
foreach (Cookie::get() as $key => $value) {
if (stripos($key, $this->fokus . '_blpage') === 0 && stripos($value, '*.') === 0) {
$this->domainBlacklist[] = str_replace("*.", "", $value);
$regexUrl = '#^(\*\.)?[a-z0-9-]+(\.[a-z0-9]+)?(\.[a-z0-9]{2,})$#';
if (preg_match('/_blpage[0-9]+$/', $key) === 1 && stripos($key, $this->fokus) !== false && preg_match($regexUrl, $value) === 1) {
$this->domainBlacklist[] = substr($value, 0, 255);
} elseif (preg_match('/_blpage$/', $key) === 1 && stripos($key, $this->fokus) !== false) {
$blacklistItems = explode(",", $value);
foreach ($blacklistItems as $blacklistItem) {
if (preg_match($regexUrl, $blacklistItem) === 1) {
$this->domainBlacklist[] = substr($blacklistItem, 0, 255);
}
}
}
}
......@@ -1385,12 +1393,16 @@ class MetaGer
// print the domain blacklist as a user warning
if (sizeof($this->domainBlacklist) > 0) {
$domainString = "";
foreach ($this->domainBlacklist as $domain) {
$domainString .= $domain . ", ";
if (sizeof($this->domainBlacklist) <= 3) {
$domainString = "";
foreach ($this->domainBlacklist as $domain) {
$domainString .= $domain . ", ";
}
$domainString = rtrim($domainString, ", ");
$this->warnings[] = trans('metaGer.formdata.domainBlacklist', ['domain' => $domainString]);
} else {
$this->warnings[] = trans('metaGer.formdata.domainBlacklistCount', ['count' => sizeof($this->domainBlacklist)]);
}
$domainString = rtrim($domainString, ", ");
$this->warnings[] = trans('metaGer.formdata.domainBlacklist', ['domain' => $domainString]);
}
}
......
......@@ -67,6 +67,7 @@ class Yandex extends Searchengine
* Yandex is currently not expected to have neutral results regarding this domains
* Thats why we filter those out here.
* Important: We do not filter out those domains completely as other search engines do have them in the index
* Returns true if the result is to be excluded.
*/
$filtered_domains = [
"rt.com",
......@@ -82,13 +83,12 @@ class Yandex extends Searchengine
}
// If the query does not contain kyrillic characters the result needs to not contain them, too
// If the query does not contain kyrillic characters then the result must not contain them or they will be filtered
if (
!preg_match('/[А-Яа-яЁё]/u', $this->query) === 1 &&
preg_match('/[А-Яа-яЁё]/u', $this->query) !== 1 &&
(preg_match('/[А-Яа-яЁё]/u', $title) === 1 ||
preg_match('/[А-Яа-яЁё]/u', $description) === 1)
) {
# Das Suchwort enthält kyrillische Zeichen, also dürfen es auch die Ergebnisse
return true;
}
......
......@@ -13,7 +13,9 @@ 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.hostBlacklistCount' => 'Ergebnisse von :count Hosts werden nicht angezeigt.',
'formdata.domainBlacklist' => 'Ergebnisse von folgenden Domains werden nicht angezeigt: ":domain"',
'formdata.domainBlacklistCount' => 'Ergebnisse von :count Domains werden nicht angezeigt.',
'formdata.urlBlacklist' => 'Ergebnisse mit URLs, die ":url" beinhalten, werden nicht angezeigt',
'formdata.stopwords' => 'Sie machen eine Ausschlusssuche. Ergebnisse mit folgenden Wörtern werden nicht angezeigt: ":stopwords"',
'formdata.phrase' => 'Sie führen eine Phrasensuche durch: :phrase',
......
......@@ -16,7 +16,7 @@ return [
'text.3' => 'An dieser Stelle können Sie Suchfilter dauerhaft setzen. Mit der Auswahl eines Suchfilters stehen nur noch Suchmaschinen zur Verfügung, welche diesen Filter unterstützen. Umgekehrt werden auch nur Suchfilter angezeigt, welche von der aktuellen Suchmaschinenauswahl unterstützt werden.',
'header.4' => 'Blacklist',
'text.4' => 'Hier können Sie Domains eintragen, welche aus Ihrer Suche ausgeschlossen werden sollen. Wenn Sie alle Subdomains einschließen wollen, starten Sie mit "*.".',
'text.4' => 'Hier können Sie Domains eintragen, welche aus Ihrer Suche ausgeschlossen werden sollen. Wenn Sie alle Subdomains einschließen wollen, starten Sie mit "*.". Eine Domain pro Zeile.',
'address' => 'Adresseingabe',
'save' => 'Speichern',
......
......@@ -13,7 +13,9 @@ return [
'formdata.noSearch' => 'Attention: you did not type in any search word/s. Please type search words and try again',
'formdata.dartEurope' => 'Hint: you have activated Dart-Europe. Therefore the response time might be longer and is set to 10 sec',
'formdata.hostBlacklist' => 'Results of the following domains will not be shown: \":host\"',
'formdata.hostBlacklistCount' => 'Results of :count hosts will not be shown.',
'formdata.domainBlacklist' => 'These domains get ignored: \":domain\"',
'formdata.domainBlacklistCount' => 'Results of :count domains will not be shown.',
'formdata.urlBlacklist' => 'Results containing \":url\" are not shown.',
'formdata.stopwords' => 'You have excluded results with the following words: \":stopwords\"',
'formdata.phrase' => 'You are doing a string search: :phrase',
......
......@@ -16,7 +16,7 @@ return [
"text.3" => "At this point you can set search filters permanently. With the selection of a search filter, only search engines are available that support this filter. Conversely, only search filters are displayed which are supported by the current search engine selection.",
'header.4' => 'Black list',
'text.4' => 'Here you can add domains to exclude when searching. If you want to exclude all subdomains start with "*.".',
'text.4' => 'Here you can add domains to exclude when searching. If you want to exclude all subdomains start with "*.". One domain per line.',
'address' => 'Address',
"save" => "Save",
......
......@@ -54,10 +54,13 @@
#create{
display:flex;
align-items:left;
flex-direction: column;
gap: 1rem;
margin-bottom:10px;
#blacklist{
flex-grow:1;
width:100%;
width: fit-content;
font-size: 1.2rem;
line-height: 1.2;
background-color:@input-bg;
color:@input-text;
}
......
......@@ -89,37 +89,18 @@
</form>
</div>
<div class="card" id="blacklist">
<h1>@lang('settings.header.4')</h1>
<div class="card" id="blacklist-container">
<h1 id="bl">@lang('settings.header.4')</h1>
<p>@lang('settings.text.4')</p>
<form id="newentry" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('newBlacklist', ["fokus" => $fokus, "url" => $url])) }}" method="post">
<input type="hidden" name="url" value="{{ $url }}">
<input type="hidden" name="fokus" value="{{ $fokus }}">
<label for="blacklist">@lang('settings.address')</label>
<label for="blacklist">@lang('settings.address') ({{ sizeof($blacklist) }}) </label>
<div id="create">
<input id="blacklist" name="blacklist" type="text" placeholder="example.com">
<button type="submit" class="btn btn-default">@lang('settings.add')</button>
<textarea name="blacklist" id="blacklist" cols="30" rows="{{ max(min(sizeof($blacklist)+1, 20), 4) }}" maxlength="2048" placeholder="example.com&#10;example2.com&#10;*.example3.com" spellcheck="false">{{ implode("\r\n", $blacklist) }}</textarea>
<button type="submit" class="btn btn-default">@lang('settings.save')</button>
</div>
</form>
@if(!empty($blacklist))
<form id="deleteentry" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('deleteBlacklist', ["fokus" => $fokus, "url" => $url])) }}" method="post">
<table>
@foreach($blacklist as $key => $value)
<tr>
<td>
{{ $value }}
</td>
<td>
<button type="submit" name="cookieKey" value="{{ $key }}"><img class="mg-icon allSettings-trashcan-icon" src="/img/trashcan.svg" alt="{{ trans('trashcan.alt') }}"></button>
</td>
</tr>
@endforeach
</table>
</form>
<form id="clearlist" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('clearBlacklist', ["fokus" => $fokus, "url" => $url])) }}" method="post">
<button class="btn btn-default" type="submit" name="clear" value="1">@lang('settings.clear')</button>
</form>
@endif
</div>
......
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