Commit 6095ec77 authored by Dominik Hebeler's avatar Dominik Hebeler

filter settings will now work

parent aefb4fa7
......@@ -26,7 +26,6 @@ class Kernel extends HttpKernel
*/
protected $middlewareGroups = [
'web' => [
#\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
......
......@@ -485,7 +485,6 @@ class MetaGer
|| \Cookie::get($this->getFokus() . "_engine_" . $suma) === "off") { # Check if the user has disabled this engine
continue;
}
# Check if this engine can use eventually defined query-filter
$valid = true;
foreach ($this->queryFilter as $queryFilter => $filter) {
......@@ -498,8 +497,7 @@ class MetaGer
if ($valid) {
foreach ($this->parameterFilter as $filterName => $filter) {
# We need to check if the searchengine supports the parameter value, too
$value = $request->input($filter->{"get-parameter"}, "");
if (empty($filter->sumas->$suma) || empty($filter->sumas->{$suma}->values->{$value})) {
if (empty($filter->sumas->$suma) || empty($filter->sumas->{$suma}->values->{$filter->value})) {
$valid = false;
break;
}
......@@ -526,12 +524,17 @@ class MetaGer
}
}
# Implements Yahoo Ads if Yahoo is not enabled as a searchengine
if (!$this->apiAuthorized && empty($this->enabledSearchengines["yahoo"]) && $this->fokus != "bilder" && !empty($this->sumaFile->sumas->{"yahoo-ads"})) {
$this->enabledSearchengines["yahoo-ads"] = $this->sumaFile->sumas->{"yahoo-ads"};
}
# Special case if search engines are disabled
# Since bing is normally only active if a filter is set but it should be active, too if yahoo is disabled
if ($this->getFokus() === "web" && empty($this->enabledSearchengines["yahoo"]) && \Cookie::get("web_engine_bing") !== "off") {
$this->enabledSearchengines["bing"] = $this->sumaFile->sumas->{"bing"};
}
if (sizeof($this->enabledSearchengines) === 0) {
$filter = "";
foreach ($this->queryFilter as $queryFilter => $filterPhrase) {
......@@ -630,27 +633,55 @@ class MetaGer
$availableFilter = [];
foreach ($parameterFilter as $filterName => $filter) {
$values = $filter->values;
# Check if any of the enabled search engines provide this filter
foreach ($this->enabledSearchengines as $engineName => $engine) {
if (!empty($filter->sumas->$engineName)) {
$availableFilter[$filterName] = $filter;
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
unset($availableFilter[$filterName]->values);
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = (object) ["" => $values->{""}];
}
foreach ($filter->sumas->{$engineName}->values as $key => $value) {
$availableFilter[$filterName]->values->$key = $values->$key;
}
}
}
# We will also add the filter from the opt-in search engines (the searchengines that are only used when a filter of it is too)
foreach ($this->sumaFile->foki->{$this->fokus}->sumas as $suma) {
if ($this->sumaFile->sumas->{$suma}->{"filter-opt-in"}) {
if ($this->sumaFile->sumas->{$suma}->{"filter-opt-in"} && \Cookie::get($this->getFokus() . "_engine_" . $suma) !== "off") {
if (!empty($filter->sumas->{$suma})) {
# If the searchengine is disabled this filter shouldn't be available
if ((!empty($this->sumaFile->sumas->{$suma}->disabled) && $this->sumaFile->sumas->{$suma}->disabled === true)
|| (!empty($this->sumaFile->sumas->{$suma}->{"auto-disabled"}) && $this->sumaFile->sumas->{$suma}->{"auto-disabled"} === true)) {
continue;
}
$availableFilter[$filterName] = $filter;
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
unset($availableFilter[$filterName]->values);
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = (object) ["" => $values->{""}];
}
foreach ($filter->sumas->{$suma}->values as $key => $value) {
$availableFilter[$filterName]->values->$key = $values->$key;
}
}
}
}
}
# Set the current values for the filters
foreach ($availableFilter as $filterName => $filter) {
if (\Request::filled($filter->{"get-parameter"})) {
$filter->value = \Request::input($filter->{"get-parameter"});
} else if (\Cookie::get($this->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null) {
$filter->value = \Cookie::get($this->getFokus() . "_setting_" . $filter->{"get-parameter"});
}
}
return $availableFilter;
}
......@@ -1019,10 +1050,17 @@ class MetaGer
} else {
$usedParameters[$filter->{"get-parameter"}] = true;
}
if ($request->filled($filter->{"get-parameter"})) {
$this->parameterFilter[$filterName] = $filter;
if (($request->filled($filter->{"get-parameter"}) && $request->input($filter->{"get-parameter"}) !== "off") ||
\Cookie::get($this->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null) { # If the filter is set via Cookie
$this->parameterFilter[$filterName] = $filter;
$this->parameterFilter[$filterName]->value = $request->input($filter->{"get-parameter"}, '');
if (empty($this->parameterFilter[$filterName]->value)) {
$this->parameterFilter[$filterName]->value = \Cookie::get($this->getFokus() . "_setting_" . $filter->{"get-parameter"});
}
}
}
$this->searchCheckHostBlacklist($request);
$this->searchCheckDomainBlacklist($request);
$this->searchCheckUrlBlacklist();
......
......@@ -7,7 +7,6 @@ use App\MetaGer;
use Cache;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Redis;
use Request;
abstract class Searchengine
{
......@@ -76,7 +75,8 @@ abstract class Searchengine
# Parse enabled Parameter-Filter
foreach ($metager->getParameterFilter() as $filterName => $filter) {
$inputParameter = Request::input($filter->{"get-parameter"}, "");
$inputParameter = $filter->value;
if (empty($inputParameter) || empty($filter->sumas->{$name}->values->{$inputParameter})) {
continue;
}
......
......@@ -26,9 +26,13 @@
@foreach($metager->getAvailableParameterFilter() as $filterName => $filter)
<div class="option-selector">
<label for="{{$filterName}}">@lang($filter->name)</label>
<select name="{{$filter->{'get-parameter'} }}" form="searchForm" onchange="this.form.submit()">
<select name="{{$filter->{'get-parameter'} }}" class="custom-select custom-select-sm" form="searchForm" onchange="this.form.submit()">
@foreach($filter->values as $value => $text)
<option value="{{$value}}" @if(Request::input($filter->{'get-parameter'}, '') === $value)selected="selected" @endif>{{trans($text)}}</option>
@if($value === "" && Cookie::get($metager->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null)
<option value="off" @if(empty($filter->value) || $filter->value === "off")selected @endif>{{trans($text)}}</option>
@else
<option value="{{$value}}" @if(!empty($filter->value) && $filter->value === $value)selected @endif>{{trans($text)}}</option>
@endif
@endforeach
</select>
</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