startTime = microtime(true); $publicKey = config("metager.metager.adgoal.public_key"); $privateKey = config("metager.metager.adgoal.private_key"); if ($publicKey === false) { return true; } $results = $metager->getResults(); $linkList = ""; foreach ($results as $result) { if (!$result->new) { continue; } $link = $result->originalLink; if (strpos($link, "http") !== 0) { $link = "http://" . $link; } $linkList .= $link . ","; } if (empty($linkList)) { return; } $linkList = rtrim($linkList, ","); # Hashwert $this->hash = md5($linkList . $privateKey); $link = "https://xf.gdprvalidate.de/v4/check"; # Which country to use # Will be de for metager.de and en for metager.org $country = "de"; if (LaravelLocalization::getCurrentLocale() === "en") { $country = "us"; } $preferredLanguage = Request::getPreferredLanguage(); if (!empty($preferredLanguage)) { if (str_contains($preferredLanguage, "_")) { $preferredLanguage = substr($preferredLanguage, stripos($preferredLanguage, "_") + 1); } elseif (str_contains($preferredLanguage, "-")) { $preferredLanguage = substr($preferredLanguage, stripos($preferredLanguage, "-") + 1); } $preferredLanguage = strtolower($preferredLanguage); if (in_array($preferredLanguage, self::COUNTRIES)) { $country = $preferredLanguage; } } $postfields = [ "key" => $publicKey, "panel" => "ZMkW9eSKJS", "member" => "338b9Bnm", "signature" => $this->hash, "links" => $linkList, "country" => $country, ]; // Submit fetch job to worker $mission = [ "resulthash" => $this->hash, "url" => $link, "useragent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0", "username" => null, "password" => null, "headers" => [ "Content-Type" => "application/x-www-form-urlencoded" ], "cacheDuration" => 60, "name" => "Adgoal", "curlopts" => [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => \http_build_query($postfields) ] ]; $mission = json_encode($mission); Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission); } public function fetchAffiliates($wait = false) { if ($this->affiliates !== null) { return; } $answer = null; $startTime = microtime(true); if ($wait) { while (microtime(true) - $startTime < 5) { $answer = Cache::get($this->hash); if ($answer === null) { usleep(50 * 1000); } else { break; } } } else { $answer = Cache::get($this->hash); } $answer = json_decode($answer, true); // If the fetcher had an Error if ($answer === "no-result") { $this->affiliates = []; return; } if (empty($answer) && !is_array($answer)) { return; } $this->affiliates = $answer; } /** * Converts all Affiliate Links. * * @param \App\Models\Result[] $results */ public function parseAffiliates(&$results) { if ($this->finished || $this->affiliates === null) { return; } foreach ($this->affiliates as $partnershop) { $targetUrl = $partnershop["url"]; $tld = $partnershop["tld"]; // Sometimes TLD is null if (empty($tld)) { continue; } $targetHost = parse_url($targetUrl, PHP_URL_HOST); /* Adgoal sometimes returns affiliate Links for every URL That's why we check if the corresponding TLD matches the orginial URL */ if ($targetHost !== false && stripos($targetHost, $tld) === false) { continue; } $preference = config("metager.metager.affiliate_preference", "adgoal"); foreach ($results as $result) { if ($result->originalLink === $targetUrl && (config("metager.metager.affiliate_preference", "adgoal") === "adgoal" || !$result->partnershop)) { # Ein Advertiser gefunden # Check ob er auf der Blacklist steht if (Redis::hexists(\App\Http\Controllers\AdgoalController::REDIS_BLACKLIST_KEY, $targetHost)) { continue; } if ($result->image !== "" && !$result->partnershop) { $result->logo = $partnershop["logo"]; } else { $result->image = $partnershop["logo"]; } # Den Link hinzufügen: # Redirect the user over our tracker # see \App\Http\Controllers\AdgoalController # for more information $result->link = \App\Http\Controllers\AdgoalController::generateRedirectUrl($partnershop["click_url"], $targetUrl); $result->partnershop = true; $result->changed = true; } } } $requestTime = microtime(true) - $this->startTime; \App\PrometheusExporter::Duration($requestTime, "adgoal"); $this->finished = true; } }