diff --git a/app/MetaGer.php b/app/MetaGer.php index ca9726b8eb5186461a3f4210dbc396e51ef2d3ae..dfe14975f907c4665d1f00ce23b0397b2b877593 100644 --- a/app/MetaGer.php +++ b/app/MetaGer.php @@ -95,10 +95,8 @@ class MetaGer foreach ($this->results as $result) { $viewResults[] = get_object_vars($result); } - # Wir müssen natürlich noch den Log für die durchgeführte Suche schreiben: $this->createLogs(); - if ($this->fokus === "bilder") { switch ($this->out) { case 'results': @@ -166,6 +164,10 @@ class MetaGer ->with('metager', $this) ->with('resultcount', sizeof($viewResults)); break; + case 'atom10': + return response()->view('metager3resultsatom10', ['results' => $viewResults,'eingabe' => $this->eingabe,'metager' => $this,'resultcount' => sizeof($viewResults)]) + ->header('Content-Type', 'application/xml'); + break; case 'result-count': # Wir geben die Ergebniszahl und die benötigte Zeit zurück: return sizeof($viewResults) . ";" . round((microtime(true) - $this->starttime), 2); @@ -235,6 +237,9 @@ class MetaGer #Adgoal Implementation $this->results = $this->parseAdgoal($this->results); + #Amazon Affiliate (MetaGers tag ist: metager04-21) + $this->results = $this->parseAmazon($this->results); + $counter = 0; $firstRank = 0; @@ -433,6 +438,34 @@ class MetaGer return $results; } + + public function parseAmazon($results) + { + $amazonTag = "metager04-21"; + + foreach ($results as $result) { + $link = $result->anzeigeLink; + if (strpos($link, "http") !== 0) { + $link = "http://" . $link; + } + $info = parse_url($link); + if(isset($info["host"])){ + $host = $info['host']; + $newurl = $link; + if(strpos($host, "amazon") !== FALSE){ + # This is Probably an Amazon Link. We'll add our tag as get parameter + if(isset($info["query"])){ + $newurl .= "&tag=metager04-21"; + }else{ + $newurl .= "?tag=metager04-21"; + } + } + $result->link = $newurl; + $result->partnershop = true; + } + } + return $results; + } public function authorize($key) { @@ -1013,7 +1046,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" && $this->out !== "rss20" && $this->out !== "rich") { + 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 = "html"; } # Wir schalten den Cache aus, wenn die Ergebniszahl überprüft werden soll diff --git a/resources/views/metager3resultsatom10.blade.php b/resources/views/metager3resultsatom10.blade.php new file mode 100644 index 0000000000000000000000000000000000000000..55468b929fd750fd03c2c7402ff6b4773e316e6c --- /dev/null +++ b/resources/views/metager3resultsatom10.blade.php @@ -0,0 +1,24 @@ +<?xmlversion = "1.0"encoding = "UTF-8"?> + <feed xmlns="http://www.w3.org/2005/Atom" + xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" + xmlns:mg="http://metager.de/opensearch/"> + <title>{!! htmlspecialchars($eingabe, ENT_XML1, 'UTF-8'); !!} - MetaGer</title> + <link href="{{ url()->full() }}"/> + <updated>{{ date('c') }}</updated> + <opensearch:totalResults>{{ $resultcount }}</opensearch:totalResults> + <opensearch:Query role="request" searchTerms="{{ htmlspecialchars($eingabe, ENT_QUOTES) }}"/> + <link rel="next" href="{{htmlspecialchars($metager->nextSearchLink() ,ENT_QUOTES)}}" type="application/atom+xml"/> + <id>urn:uuid:1d634a8c-2764-424f-b082-6c96494b7240</id> + @foreach($metager->getResults() as $result) + <entry> + <title>{!! htmlspecialchars($result->titel, ENT_XML1, 'UTF-8'); !!}</title> + <link href="{!! htmlspecialchars($result->link, ENT_XML1, 'UTF-8'); !!}" /> + <mg:anzeigeLink>{!! htmlspecialchars($result->anzeigeLink, ENT_XML1, 'UTF-8'); !!}</mg:anzeigeLink> + <content type="text"> + {!! htmlspecialchars($result->longDescr, ENT_XML1, 'UTF-8'); !!} + </content> + </entry> + @endforeach + </feed> + + <!-- Muster zu finden unter http://www.opensearch.org/Specifications/OpenSearch/1.1#Example_of_OpenSearch_response_elements_in_RSS_2.0 -->