Commit 6d375506 authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '961-implement-more-time-filters' into 'development'

Resolve "Implement more Time Filters"

Closes #961

See merge request !1580
parents e1d39c68 a710c943
<?php
namespace App;
use Carbon;
class DynamicEngineParameters {
// Returns a string notating the Date Range of the last year
// The value is used as Parameter for the Bing search engine
// freshness Parameter
public static function FreshnessYearBing() {
$now = \Carbon::now()->format("Y-m-d");
$lastYear = \Carbon::now()->subYear()->format("Y-m-d");
return $lastYear . ".." . $now;
}
public static function FreshnessCustomBing(){
// Bings custom date filter uses YYYY-mm-dd..YYYY-mm-dd
// From and two dates are supplied by parameters ff and ft
// They already have been checked if they match above pattern in parseFormData function
$from = \Request::input("ff");
$to = \Request::input("ft");
return $from . ".." . $to;
}
}
\ No newline at end of file
......@@ -717,19 +717,23 @@ class MetaGer
$availableFilter = [];
foreach ($parameterFilter as $filterName => $filter) {
$values = $filter->values;
$values = clone $filter->values;
# Check if any of the enabled search engines provide this filter
foreach ($this->enabledSearchengines as $engineName => $engine) {
if (!empty($filter->sumas->$engineName)) {
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
unset($availableFilter[$filterName]->values);
foreach($availableFilter[$filterName]->values as $key => $value){
if($key !== "nofilter"){
unset($availableFilter[$filterName]->values->{$key});
}
}
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = (object) ["" => $values->{""}];
$availableFilter[$filterName]->values = new \stdClass();
}
foreach ($filter->sumas->{$engineName}->values as $key => $value) {
$availableFilter[$filterName]->values->$key = $values->$key;
$availableFilter[$filterName]->values->{$key} = $values->$key;
}
}
}
......@@ -745,13 +749,17 @@ class MetaGer
}
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
unset($availableFilter[$filterName]->values);
foreach($availableFilter[$filterName]->values as $key => $value){
if($key !== "nofilter"){
unset($availableFilter[$filterName]->values->{$key});
}
}
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = (object) ["" => $values->{""}];
$availableFilter[$filterName]->values = new \stdClass();
}
foreach ($filter->sumas->{$suma}->values as $key => $value) {
$availableFilter[$filterName]->values->$key = $values->$key;
$availableFilter[$filterName]->values->{$key} = $values->$key;
}
}
}
......@@ -1011,6 +1019,53 @@ class MetaGer
// Remove Inputs that are not used
$this->request = $request->replace($request->except(['verification_id', 'uid', 'verification_count']));
// Disable freshness filter if custom freshness filter isset
if($this->request->filled("ff") && $this->request->filled("f")){
$this->request = $this->request->replace($this->request->except(["f"]));
}
// Remove custom time filter if either of the dates isn't set or is not a date
if($this->request->input("fc") === "on"){
if(!$this->request->filled("ff") || !$this->request->filled("ft")){
$this->request = $this->request->replace($this->request->except(["fc", "ff", "ft"]));
}else{
$ff = $this->request->input("ff");
$ft = $this->request->input("ft");
if(!preg_match("/^\d{4}-\d{2}-\d{2}$/", $ff) || !preg_match("/^\d{4}-\d{2}-\d{2}$/", $ft)){
$this->request = $this->request->replace($this->request->except(["fc", "ff", "ft"]));
}else{
// Now Check if there is something wrong with the dates
$from = $this->request->input("ff");
$to = $this->request->input("ft");
$changed = false;
$from = Carbon::createFromFormat("Y-m-d H:i:s", $from . " 00:00:00");
$to = Carbon::createFromFormat("Y-m-d H:i:s", $to . " 00:00:00");
if($from > Carbon::now()){
$from = Carbon::now();
$changed = true;
}
if($to > Carbon::now()){
$to = Carbon::now();
$changed = true;
}
if($from > $to){
$tmp = $to;
$to = $from;
$from = $tmp;
$changed = true;
}
if($changed){
$oldParameters = $this->request->all();
$oldParameters["ff"] = $from->format("Y-m-d");
$oldParameters["ft"] = $to->format("Y-m-d");
$this->request = $this->request->replace($oldParameters);
}
}
}
}else if($this->request->filled("ff") || $this->request->filled("ft")){
$this->request = $this->request->replace($this->request->except(["fc", "ff", "ft"]));
}
$this->out = $request->input('out', "html");
# Standard output format html
if ($this->out !== "html" && $this->out !== "json" && $this->out !== "results" && $this->out !== "results-with-style" && $this->out !== "result-count" && $this->out !== "rss20" && $this->out !== "atom10" && $this->out !== "rich" && $this->out !== "api") {
......@@ -1078,7 +1133,6 @@ class MetaGer
# IPv4
return preg_replace("/(\d+)\.(\d+)\.\d+.\d+/s", "$1.$2.0.0", $ip);
}
die(var_dump($ip));
}
public function checkSpecialSearches(Request $request)
......@@ -1116,7 +1170,7 @@ class MetaGer
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] = $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"});
......
......@@ -81,6 +81,7 @@ abstract class Searchengine
$q = $query . " " . $q;
}
$tmpPara = false;
# Parse enabled Parameter-Filter
foreach ($metager->getParameterFilter() as $filterName => $filter) {
$inputParameter = $filter->value;
......@@ -88,8 +89,13 @@ abstract class Searchengine
if (empty($inputParameter) || empty($filter->sumas->{$name}->values->{$inputParameter})) {
continue;
}
$tmpPara = true;
$engineParameterKey = $filter->sumas->{$name}->{"get-parameter"};
$engineParameterValue = $filter->sumas->{$name}->values->{$inputParameter};
if(stripos($engineParameterValue, "dyn-") === 0){
$functionname = substr($engineParameterValue, stripos($engineParameterValue, "dyn-") + 4);
$engineParameterValue = \App\DynamicEngineParameters::$functionname();
}
$this->engine->{"get-parameter"}->{$engineParameterKey} = $engineParameterValue;
}
......
......@@ -81,6 +81,9 @@ return [
"filter.freshness.day" => "Letzte 24h",
"filter.freshness.week" => "Letzte Woche",
"filter.freshness.month" => "Letzter Monat",
"filter.freshness.year" => "Letztes Jahr",
"filter.freshness.custom" => "Benutzerdefiniert",
"filter.customdatetitle" => "Benutzerdefiniertes Datum auswählen",
"filter.market" => "Sprache",
"filter.market.ga" => "Deutsch (Österreich)",
......
......@@ -604,6 +604,21 @@ a {
padding: 3px;
border-radius: 5px;
}
label[for="custom-date"] {
cursor: pointer;
&:hover {
color: red;
}
}
#bing-from-to {
display: none;
}
#custom-date:checked + select {
display: none;
}
#custom-date:checked + select + #bing-from-to {
display: flex;
}
}
.option-selector:nth-child(1){
margin-left: 0;
......
<div id="bing-from-to">
<input type="date" form="searchForm" @if(Request::filled("ff")) value="{{ Request::input("ff", "") }}" @endif name="ff" onchange="if(document.querySelector('input[name=ff]').value != '' && document.querySelector('input[name=ft]').value != ''){this.form.submit();}">
<div>&nbsp;-&nbsp;</div>
<input type="date" form="searchForm" @if(Request::filled("ft")) value="{{ Request::input("ft", "") }}" @endif name="ft" onchange="if(document.querySelector('input[name=ff]').value != '' && document.querySelector('input[name=ft]').value != ''){this.form.submit();}">
</div>
\ No newline at end of file
......@@ -33,18 +33,37 @@
<div id="options-box">
<div id="options-items">
@foreach($metager->getAvailableParameterFilter() as $filterName => $filter)
@if(empty($filter->hidden) || $filter->hidden === false)
<div class="option-selector">
<label for="{{$filterName}}">@lang($filter->name)</label>
<select name="{{$filter->{'get-parameter'} }}" class="custom-select custom-select-sm" form="searchForm" onchange="this.form.submit()">
<div>
<label for="{{$filterName}}">
@lang($filter->name)
</label>
@if($filter->{'get-parameter'} === "f")
<label for="custom-date" title="@lang('metaGer.filter.customdatetitle')">
<i class="fas fa-cogs"></i>
</label>
</div>
<input id="custom-date" type="checkbox" form="searchForm" @if(Request::input('fc', "off") === "on")checked @endif name="fc" onchange="if(!this.checked){this.form.submit()}"/>
@else
</div>
@endif
<select name="{{$filter->{'get-parameter'} }}" class="custom-select custom-select-sm" form="searchForm" onchange="this.form.submit()">
@foreach($filter->values as $value => $text)
@if($value === "" && Cookie::get($metager->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null)
@if($value === "nofilter" && Cookie::get($metager->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null)
<option value="off" @if(empty($filter->value) || $filter->value === "off")selected @endif>{{trans($text)}}</option>
@elseif($value === "nofilter")
<option value="" @if(!empty($filter->value) && $filter->value === $value)selected @endif>{{trans($text)}}</option>
@else
<option value="{{$value}}" @if(!empty($filter->value) && $filter->value === $value)selected @endif>{{trans($text)}}</option>
@endif
@endforeach
</select>
@if(!empty($filter->htmlbelow))
@include($filter->htmlbelow)
@endif
</div>
@endif
@endforeach
</div>
......
......@@ -65,6 +65,7 @@
<input type="hidden" name="url" value="{{ $url }}">
<div id="filter-options">
@foreach($filter as $name => $filterInfo)
@if(empty($filterInfo->hidden) || $filterInfo->hidden === false)
<div class="form-group">
<label for="{{ $filterInfo->{"get-parameter"} }}">@lang($filterInfo->name)</label>
<select name="{{ $filterInfo->{"get-parameter"} }}" id="{{ $filterInfo->{"get-parameter"} }}" class="form-control">
......@@ -76,6 +77,7 @@
@endforeach
</select>
</div>
@endif
@endforeach
</div>
<button type="submit" class="btn btn-default">@lang('settings.save')</button>
......
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