Skip to content
Snippets Groups Projects
Commit e98a19ed authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch '504-mobile-styles-optimieren-inkl-quicktips' into 'development'

MetaGer-Key eingebaut

Closes #504

See merge request !920
parents 183146e2 c21f7b70
No related branches found
No related tags found
1 merge request!1365Resolve "Filter Options for MetaGer"
...@@ -40,6 +40,8 @@ class MetaGer ...@@ -40,6 +40,8 @@ class MetaGer
protected $ip; protected $ip;
protected $language; protected $language;
protected $agent; protected $agent;
protected $apiKey = "";
protected $apiAuthorized = false;
# Konfigurationseinstellungen: # Konfigurationseinstellungen:
protected $sumaFile; protected $sumaFile;
protected $mobile; protected $mobile;
...@@ -148,6 +150,7 @@ class MetaGer ...@@ -148,6 +150,7 @@ class MetaGer
->with('mobile', $this->mobile) ->with('mobile', $this->mobile)
->with('warnings', $this->warnings) ->with('warnings', $this->warnings)
->with('errors', $this->errors) ->with('errors', $this->errors)
->with('apiAuthorized', $this->apiAuthorized)
->with('metager', $this) ->with('metager', $this)
->with('browser', (new Agent())->browser()); ->with('browser', (new Agent())->browser());
break; break;
...@@ -155,6 +158,7 @@ class MetaGer ...@@ -155,6 +158,7 @@ class MetaGer
return view('metager3resultsrss20') return view('metager3resultsrss20')
->with('results', $viewResults) ->with('results', $viewResults)
->with('eingabe', $this->eingabe) ->with('eingabe', $this->eingabe)
->with('apiAuthorized', $this->apiAuthorized)
->with('metager', $this) ->with('metager', $this)
->with('resultcount', sizeof($viewResults)); ->with('resultcount', sizeof($viewResults));
break; break;
...@@ -190,6 +194,9 @@ class MetaGer ...@@ -190,6 +194,9 @@ class MetaGer
// filter // filter
// augment (boost&adgoal) // augment (boost&adgoal)
// authorize // authorize
if ($this->apiKey) {
$this->apiAuthorized = $this->authorize($this->apiKey);
}
// misc (WiP) // misc (WiP)
if ($this->fokus == "nachrichten") { if ($this->fokus == "nachrichten") {
$this->results = array_filter($this->results, function ($v, $k) { $this->results = array_filter($this->results, function ($v, $k) {
...@@ -451,6 +458,34 @@ class MetaGer ...@@ -451,6 +458,34 @@ class MetaGer
return $results; return $results;
} }
public function authorize($key)
{
$postdata = http_build_query(array(
'dummy' => rand(),
));
$opts = array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata,
),
);
$context = stream_context_create($opts);
try {
$link = "https://key.metager3.de/" . urlencode($key) . "/request-permission/api-access";
$result = json_decode(file_get_contents($link, false, $context));
if ($result->{'api-access'} == true) {
return true;
} else {
return false;
}
} catch (\ErrorException $e) {
return false;
}
}
/* /*
* Die Erstellung der Suchmaschinen bis die Ergebnisse da sind mit Unterfunktionen * Die Erstellung der Suchmaschinen bis die Ergebnisse da sind mit Unterfunktionen
*/ */
...@@ -983,6 +1018,8 @@ class MetaGer ...@@ -983,6 +1018,8 @@ class MetaGer
} else { } else {
$this->quicktips = true; $this->quicktips = true;
} }
$this->apiKey = $request->input('key', '');
$this->validated = false; $this->validated = false;
if (isset($this->password)) { if (isset($this->password)) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<opensearch:totalResults>{{ $resultcount }}</opensearch:totalResults> <opensearch:totalResults>{{ $resultcount }}</opensearch:totalResults>
<opensearch:Query role="request" searchTerms="{{ htmlspecialchars($eingabe, ENT_QUOTES) }}"/> <opensearch:Query role="request" searchTerms="{{ htmlspecialchars($eingabe, ENT_QUOTES) }}"/>
@if($apiAuthorized)
@foreach($metager->getResults() as $result) @foreach($metager->getResults() as $result)
<item> <item>
<title>{!! htmlspecialchars($result->titel, ENT_XML1, 'UTF-8'); !!}</title> <title>{!! htmlspecialchars($result->titel, ENT_XML1, 'UTF-8'); !!}</title>
...@@ -18,5 +19,6 @@ ...@@ -18,5 +19,6 @@
</description> </description>
</item> </item>
@endforeach @endforeach
@endif
</channel> </channel>
</rss> </rss>
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
</details> </details>
<main class="results-container"> <main class="results-container">
@foreach($metager->getResults() as $result) @foreach($metager->getResults() as $result)
@if($result->number % 7 === 0) @if($result->number % 7 === 0 && !$apiAuthorized)
@include('layouts.rich.ad', ['result' => $metager->popAd()]) @include('layouts.rich.ad', ['result' => $metager->popAd()])
@endif @endif
@include('layouts.rich.result', ['result' => $result]) @include('layouts.rich.result', ['result' => $result])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment