diff --git a/app/MetaGer.php b/app/MetaGer.php index c915b55c2c49ba4e2c41a283655f5cf25d7c2057..757b647afacc28f2cac646fdec41230b8839e5ab 100644 --- a/app/MetaGer.php +++ b/app/MetaGer.php @@ -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)) { diff --git a/resources/views/metager3resultsrss20.blade.php b/resources/views/metager3resultsrss20.blade.php index f8fb9ac93226ddc4019c46706291643d55bb802c..8bdf721326a27440ef536e56b53c3362d1cdf1e9 100644 --- a/resources/views/metager3resultsrss20.blade.php +++ b/resources/views/metager3resultsrss20.blade.php @@ -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> diff --git a/resources/views/metager3rich.blade.php b/resources/views/metager3rich.blade.php index 9676713ab28ccebc00ed1ec188cc0ee0799c29b7..b2008cb9d8c9d3481008724d3f1ae8e05b0d84a2 100644 --- a/resources/views/metager3rich.blade.php +++ b/resources/views/metager3rich.blade.php @@ -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])