From 8a08a8366668bcc0d38a6cfa3dc9f623d6bb1385 Mon Sep 17 00:00:00 2001
From: Dominik Pfennig <dominik@suma-ev.de>
Date: Fri, 8 Sep 2017 13:20:22 +0200
Subject: [PATCH] =?UTF-8?q?Amazon=20Affiliate=20Links=20mit=20neuem=20Tag?=
 =?UTF-8?q?=20wieder=20eingef=C3=BCgt.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/MetaGer.php | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/app/MetaGer.php b/app/MetaGer.php
index 664cf6b77..1e776909d 100644
--- a/app/MetaGer.php
+++ b/app/MetaGer.php
@@ -237,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;
 
@@ -435,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($url);
+            if(isset($info["host"])){
+                $host = $info['host'];
+                if(strpos($host, "amazon") !== FALSE){
+                    # This is Probably an Amazon Link. We'll add our tag as get parameter
+                    if(isset($info["query"])){
+                        $info["query"] .= "&tag=metager04-21";
+                    }else{
+                        $info["query"] = "tag=metager04-21";
+                    }
+                }
+                $newurl = http_build_url($info);
+                $result->link = $newurl;
+                $result->partnershop = true;
+            }
+        }
+        return $results;
+    }
 
     public function authorize($key)
     {
-- 
GitLab