Skip to content
Snippets Groups Projects
Commit 0d110f95 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 0c1c99d8 98942b95
No related branches found
No related tags found
2 merge requests!924Development,!920MetaGer-Key eingebaut
......@@ -40,6 +40,8 @@ class MetaGer
protected $ip;
protected $language;
protected $agent;
protected $apiKey = "";
protected $apiAuthorized = false;
# Konfigurationseinstellungen:
protected $sumaFile;
protected $mobile;
......@@ -148,6 +150,7 @@ class MetaGer
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('apiAuthorized', $this->apiAuthorized)
->with('metager', $this)
->with('browser', (new Agent())->browser());
break;
......@@ -155,6 +158,7 @@ class MetaGer
return view('metager3resultsrss20')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('apiAuthorized', $this->apiAuthorized)
->with('metager', $this)
->with('resultcount', sizeof($viewResults));
break;
......@@ -190,6 +194,9 @@ class MetaGer
// filter
// augment (boost&adgoal)
// authorize
if ($this->apiKey) {
$this->apiAuthorized = $this->authorize($this->apiKey);
}
// misc (WiP)
if ($this->fokus == "nachrichten") {
$this->results = array_filter($this->results, function ($v, $k) {
......@@ -451,6 +458,34 @@ class MetaGer
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
*/
......@@ -983,6 +1018,8 @@ class MetaGer
} else {
$this->quicktips = true;
}
$this->apiKey = $request->input('key', '');
$this->validated = false;
if (isset($this->password)) {
......
......@@ -8,6 +8,7 @@
<opensearch:totalResults>{{ $resultcount }}</opensearch:totalResults>
<opensearch:Query role="request" searchTerms="{{ htmlspecialchars($eingabe, ENT_QUOTES) }}"/>
@if($apiAuthorized)
@foreach($metager->getResults() as $result)
<item>
<title>{!! htmlspecialchars($result->titel, ENT_XML1, 'UTF-8'); !!}</title>
......@@ -18,5 +19,6 @@
</description>
</item>
@endforeach
@endif
</channel>
</rss>
......@@ -33,7 +33,7 @@
</details>
<main class="results-container">
@foreach($metager->getResults() as $result)
@if($result->number % 7 === 0)
@if($result->number % 7 === 0 && !$apiAuthorized)
@include('layouts.rich.ad', ['result' => $metager->popAd()])
@endif
@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