From e7db24c34828412da0bae38081bb05f20e2d84c1 Mon Sep 17 00:00:00 2001 From: Davide Aprea <davide@suma-ev.de> Date: Thu, 5 Nov 2020 14:03:22 +0100 Subject: [PATCH] fixed api and atom10 format --- app/Http/Middleware/BrowserVerification.php | 11 ++++++++--- app/MetaGer.php | 11 +++++------ .../views/resultpages/metager3resultsatom10.blade.php | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/Http/Middleware/BrowserVerification.php b/app/Http/Middleware/BrowserVerification.php index 482fc2b71..53598aa33 100644 --- a/app/Http/Middleware/BrowserVerification.php +++ b/app/Http/Middleware/BrowserVerification.php @@ -18,6 +18,14 @@ class BrowserVerification */ public function handle($request, Closure $next) { + + if(($request->input("out", "") === "api" || $request->input("out", "") === "atom10") && app('App\Models\Key')->getStatus()) { + header('Content-type: application/xml; charset=utf-8'); + } else { + header('Content-type: text/html; charset=utf-8'); + } + header('X-Accel-Buffering: no'); + if (($request->filled("loadMore") && Cache::has($request->input("loadMore"))) || app('App\Models\Key')->getStatus()) { return $next($request); } @@ -55,9 +63,6 @@ class BrowserVerification } } - header('Content-type: text/html; charset=utf-8'); - header('X-Accel-Buffering: no'); - $key = md5($request->ip() . microtime(true)); echo(view('layouts.resultpage.verificationHeader')->with('key', $key)->render()); diff --git a/app/MetaGer.php b/app/MetaGer.php index 4374b4316..8d00cdb98 100644 --- a/app/MetaGer.php +++ b/app/MetaGer.php @@ -206,14 +206,13 @@ class MetaGer ->with('browser', (new Agent())->browser()) ->with('fokus', $this->fokus); break; - /* WIP + case 'api': - return response()->view('resultpages.metager3resultsatom10', ['results' => $viewResults, 'eingabe' => $this->eingabe, 'metager' => $this, 'resultcount' => sizeof($viewResults), 'key' => $this->apiKey, 'apiAuthorized' => $this->apiAuthorized])->header('Content-Type', 'application/xml'); + return view('resultpages.metager3resultsatom10',['eingabe' => $this->eingabe, 'resultcount' => sizeof($viewResults), 'key' => $this->apiKey, 'metager' => $this]); break; case 'atom10': - return response()->view('resultpages.metager3resultsatom10', ['results' => $viewResults, 'eingabe' => $this->eingabe, 'metager' => $this, 'resultcount' => sizeof($viewResults), 'key' => $this->apiKey, 'apiAuthorized' => true]) - ->header('Content-Type', 'application/xml'); - break;*/ + return view('resultpages.metager3resultsatom10',['eingabe' => $this->eingabe, 'resultcount' => sizeof($viewResults), 'key' => $this->apiKey, 'metager' => $this]); + break; case 'result-count': # Wir geben die Ergebniszahl und die benötigte Zeit zurück: return sizeof($viewResults) . ";" . round((microtime(true) - $this->starttime), 2); @@ -1204,7 +1203,7 @@ class MetaGer $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" /*WIP && $this->out !== "atom10" && $this->out !== "api"*/) { + if ($this->out !== "html" && $this->out !== "json" && $this->out !== "results" && $this->out !== "results-with-style" && $this->out !== "result-count" && $this->out !== "atom10" && $this->out !== "api") { $this->out = "html"; } # Wir schalten den Cache aus, wenn die Ergebniszahl überprüft werden soll diff --git a/resources/views/resultpages/metager3resultsatom10.blade.php b/resources/views/resultpages/metager3resultsatom10.blade.php index 25df6e410..a5cfcbbf6 100644 --- a/resources/views/resultpages/metager3resultsatom10.blade.php +++ b/resources/views/resultpages/metager3resultsatom10.blade.php @@ -3,7 +3,7 @@ xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:mg="http://metager.de/opensearch/" xmlns:ad="http://a9.com/-/opensearch/extensions/advertisement/1.0/"> - <title>{!! htmlspecialchars($eingabe, ENT_XML1, 'UTF-8'); !!} - MetaGer</title> + <title>{{ htmlspecialchars($eingabe, ENT_XML1, 'UTF-8') }} - MetaGer</title> <link href="{{ url()->full() }}"/> <updated>{{ date('c') }}</updated> <opensearch:totalResults>{{ $resultcount }}</opensearch:totalResults> @@ -11,7 +11,7 @@ <link rel="next" href="{{ htmlspecialchars($metager->nextSearchLink() ,ENT_QUOTES) }}" type="application/atom+xml"/> <id>urn:uuid:1d634a8c-2764-424f-b082-6c96494b7240</id> @include('layouts.atom10ad', ['ad' => $metager->popAd()]) - @if($apiAuthorized) + @if(app('App\Models\Key')->getStatus()) @foreach($metager->getResults() as $index => $result) @if(($index+1) % 5 === 0) @include('layouts.atom10ad', ['ad' => $metager->popAd()]) -- GitLab