function send_bid_response() { $log_header = "\n----------------------------------------------------------------\n"; $log_header .= date('m-d-Y H:i:s') . " ------- NEW BID RESPONSE " . $this->rtb_provider . " -------\n"; $log_header .= "----------------------------------------------------------------\n"; \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = $log_header; header("Content-type: application/json"); $bid_response = $this->bid_responses; echo $bid_response; \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = $bid_response; \rtbbuyv22\RtbBuyV22Logger::get_instance()->min_log[] = $bid_response; }
public function parse_request($config, $is_local, $rtb_ssp_friendly_name, $raw_post = null) { $this->config = $config; $this->raw_post = $raw_post; // prepare the logger $logger = \rtbbuyv22\RtbBuyV22Logger::get_instance(); // prepare the response object $this->RtbBidRequest = new \model\openrtb\RtbBidRequest(); $this->RtbBidRequest->is_local_request = $is_local; $this->RtbBidRequest->ssp_exchange_name = $rtb_ssp_friendly_name; // Initialize Data try { \buyrtb\parsers\openrtb\parselets\common\Init::execute($logger, $this, $this->RtbBidRequest); } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } // Parse Currency try { \buyrtb\parsers\openrtb\parselets\common\ParseCurrency::execute($logger, $this, $this->RtbBidRequest); } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } // Parse Second Price \util\ParseHelper::parse_item($this->RtbBidRequest, $this->json_post, "at"); // Parse Max Timeout on RTB Bid Response \util\ParseHelper::parse_item($this->RtbBidRequest, $this->json_post, "tmax"); // Parse Allowed Buyer Seat IDs \util\ParseHelper::parse_item_list($this->RtbBidRequest, $this->json_post, "wseat"); // Parse All Available impressions for this publisher boolean \util\ParseHelper::parse_item($this->RtbBidRequest, $this->json_post, "allimps"); // Parse Blocked Advertiser Categories \util\ParseHelper::parse_item_list($this->RtbBidRequest, $this->json_post, "bcat"); // Parse Blocked TLDs for this RTB request, Publisher Black Listed \util\ParseHelper::parse_item_list($this->RtbBidRequest, $this->json_post, "badv"); // Parse Site if (isset($this->json_post["site"])) { $ad_campaign_site = $this->json_post["site"]; $RtbBidRequestSite = new \model\openrtb\RtbBidRequestSite(); try { \buyrtb\parsers\openrtb\parselets\common\ParseWebsite::execute($logger, $this, $this->RtbBidRequest, $RtbBidRequestSite, $ad_campaign_site); $this->RtbBidRequest->RtbBidRequestSite = $RtbBidRequestSite; } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } } // Parse App if (isset($this->json_post["app"])) { $rtb_app = $this->json_post["app"]; $RtbBidRequestApp = new \model\openrtb\RtbBidRequestApp(); try { \buyrtb\parsers\openrtb\parselets\common\ParseApp::execute($logger, $this, $this->RtbBidRequest, $RtbBidRequestApp, $rtb_app); $this->RtbBidRequest->RtbBidRequestApp = $RtbBidRequestApp; } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } } // Parse User if (isset($this->json_post["user"])) { $rtb_user = $this->json_post["user"]; $RtbBidRequestUser = new \model\openrtb\RtbBidRequestUser(); try { \buyrtb\parsers\openrtb\parselets\common\ParseUser::execute($logger, $this, $this->RtbBidRequest, $RtbBidRequestUser, $rtb_user); $this->RtbBidRequest->RtbBidRequestUser = $RtbBidRequestUser; } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } } // Parse Device $RtbBidRequestDevice = new \model\openrtb\RtbBidRequestDevice(); if (isset($this->json_post["device"])) { $device = $this->json_post["device"]; try { \buyrtb\parsers\openrtb\parselets\common\device\ParseDevice::execute($logger, $this, $this->RtbBidRequest, $RtbBidRequestDevice, $device); $logger->log[] = "Is Mobile: " . $RtbBidRequestDevice->devicetype != 2; } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } } $this->RtbBidRequest->RtbBidRequestDevice = $RtbBidRequestDevice; // Parse Regs if (isset($this->json_post["regs"])) { $ad_regs = $this->json_post["regs"]; $RtbBidRequestRegulations = new \model\openrtb\RtbBidRequestRegulations(); try { \buyrtb\parsers\openrtb\parselets\common\ParseRegs::execute($logger, $this, $this->RtbBidRequest, $RtbBidRequestRegulations, $ad_regs); $this->RtbBidRequest->RtbBidRequestRegulations = $RtbBidRequestRegulations; } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } } // process all ad impressions if (!isset($this->json_post["imp"][0])) { throw new Exception($this->expeption_missing_min_bid_request_params . ": at least 1 imp object"); } $ad_impression_list = $this->json_post["imp"]; foreach ($ad_impression_list as $ad_impression) { $RtbBidRequestImp = new \model\openrtb\RtbBidRequestImp(); // Parse Imp ID try { \util\ParseHelper::parse_with_exception($RtbBidRequestImp, $ad_impression, $this->expeption_missing_min_bid_request_params . ": imp_id", "id"); } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } // Parse Imp Display Manager \util\ParseHelper::parse_item($RtbBidRequestImp, $ad_impression, "displaymanager"); // Parse Imp Display Manager Version \util\ParseHelper::parse_item($RtbBidRequestImp, $ad_impression, "displaymanagerver"); // Parse Imp Is Interstitial \util\ParseHelper::parse_item($RtbBidRequestImp, $ad_impression, "instl"); // Parse SSP tag id DOM parent of RTB Auction Ad Zone in Publisher web page \util\ParseHelper::parse_item($RtbBidRequestImp, $ad_impression, "tagid"); // Parse Imp Floor Price \util\ParseHelper::parse_item($RtbBidRequestImp, $ad_impression, "bidfloor"); // Parse Imp Floor Currency \util\ParseHelper::parse_item($RtbBidRequestImp, $ad_impression, "bidfloorcur"); // Parse Imp https:// SSL flag \util\ParseHelper::parse_item($RtbBidRequestImp, $ad_impression, "secure"); // Parse Imp IFRAME Buster list \util\ParseHelper::parse_item_list($RtbBidRequestImp, $ad_impression, "secure"); // Parse Private Markplace (PMP) if (isset($ad_impression["pmp"])) { $pmp = $ad_impression["pmp"]; $RtbBidRequestPmp = new \model\openrtb\RtbBidRequestPmp(); try { \buyrtb\parsers\openrtb\parselets\common\imp\ParsePrivateMarketPlace::execute($logger, $this, $this->RtbBidRequest, $RtbBidRequestPmp, $pmp); $RtbBidRequestImp->RtbBidRequestPmp = $RtbBidRequestPmp; } catch (Exception $e) { throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } } if (isset($ad_impression["banner"])) { // this is a banner $ad_impression_banner = $ad_impression["banner"]; $RtbBidRequestImp->media_type = "banner"; $RtbBidRequestImp->RtbBidRequestBanner = new \model\openrtb\RtbBidRequestBanner(); $DisplayParser = new \buyrtb\parsers\openrtb\DisplayParser(); $DisplayParser->parse_request($logger, $this, $RtbBidRequestImp->RtbBidRequestBanner, $ad_impression_banner); } elseif (isset($ad_impression["video"])) { // this is a video $ad_impression_video = $ad_impression["video"]; $RtbBidRequestImp->media_type = "video"; $RtbBidRequestImp->RtbBidRequestVideo = new \model\openrtb\RtbBidRequestVideo(); $VideoParser = new \buyrtb\parsers\openrtb\VideoParser(); $VideoParser->parse_request($logger, $this, $RtbBidRequestImp->RtbBidRequestVideo, $ad_impression_video); } elseif (!empty($ad_impression["native"]["request"])) { // this is a native ad $ad_impression_native_raw = json_decode($ad_impression["native"]["request"], true); if (empty($ad_impression_native_raw["native"])) { throw new Exception($this->expeption_missing_min_bid_request_params . ": decoded native object is missing in the imp"); } $ad_impression_native = $ad_impression_native_raw["native"]; $RtbBidRequestImp->media_type = "native"; $RtbBidRequestImp->RtbBidRequestNative = new \model\openrtb\native\request\RtbBidRequestNative(); $NativeParser = new \buyrtb\parsers\openrtb\NativeParser(); $NativeParser->parse_request($logger, $this, $RtbBidRequestImp->RtbBidRequestNative, $ad_impression_native); } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": at least one banner or video object in the imp"); } $this->RtbBidRequest->RtbBidRequestImpList[] = $RtbBidRequestImp; } return $this->RtbBidRequest; }
public function process_business_rules_workflow($config, $rtb_seat_id, &$no_bid_reason, \model\openrtb\RtbBidRequest &$RtbBidRequest) { $logger = \rtbbuyv22\RtbBuyV22Logger::get_instance(); $OpenRTBWorkflow = new \buyrtb\workflows\OpenRTBWorkflow(); return $OpenRTBWorkflow->process_business_rules_workflow($logger, $config, $rtb_seat_id, $no_bid_reason, $RtbBidRequest); }
public function parse_incoming_request($raw_post = null) { /* * Get the incoming bid request data from the * HTTP REQUEST * * If the required fields are not there throw an exception * to the caller */ /* * mobile, rich media, ect.. * mobile web, phone, tablet, native iOS or native Android */ if ($raw_post === null) { $raw_post = file_get_contents('php://input'); } \rtbbuyv22\RtbBuyV22Logger::get_instance()->min_log[] = "POST: " . $raw_post; if ($raw_post) { $json_post = json_decode($raw_post, true); } else { $json_post = null; } $this->bid_request_mobile = 0; if ($json_post === null) { throw new Exception($this->expeption_missing_min_bid_request_params . ": JSON POST DATA"); } \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "POST: " . print_r($json_post, true); if (isset($json_post["id"])) { $this->bid_request_id = $json_post["id"]; } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": id"); } if (isset($json_post["imp"][0])) { $default_impression = $json_post["imp"][0]; if (isset($default_impression["id"])) { $this->bid_request_imp_id = $default_impression["id"]; } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": imp_id"); } if (isset($default_impression["banner"]["h"])) { $this->bid_request_imp_banner_h = $default_impression["banner"]["h"]; } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": imp_banner_h"); } if (isset($default_impression["banner"]["w"])) { $this->bid_request_imp_banner_w = $default_impression["banner"]["w"]; } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": imp_banner_w"); } /* * OpenRTB 2.1 * 0 Unknown 1 Above the fold 2 DEPRECATED - May or may not be immediately visible depending on screen size and resolution. 3 Below the fold 4 Header 5 Footer 6 Sidebar 7 Fullscreen */ /* * Proprietary DB values * uFoldPos No No User defined Fold position of the ad slot. • 0 – Not available/applicable • 1 – Completely Above the Fold • 2 – Completely Below the Fold • 3 – Partially Above the Fold sFoldPos No No System detected Fold position of the ad slot. • 0 – Not available/applicable • 1 – Completely Above the Fold • 2 – Completely Below the Fold • 3 – Partially Above the Fold */ /* * do conversion here */ if (isset($default_impression["banner"]["pos"])) { if ($default_impression["banner"]["pos"] == 1 || $default_impression["banner"]["pos"] == 4) { $this->bid_request_imp_banner_pos = 1; } elseif ($default_impression["banner"]["pos"] == 6) { $this->bid_request_imp_banner_pos = 3; } elseif ($default_impression["banner"]["pos"] == 3 || $default_impression["banner"]["pos"] == 5) { $this->bid_request_imp_banner_pos = 2; } } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": imp_banner_pos"); } if (isset($default_impression["pmp"])) { $this->bid_request_imp_pmp = 1; } } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": at least 1 imp object"); } if (isset($json_post["cur"][0])) { $this->bid_request_cur = strtoupper($json_post["cur"][0]); if ($this->bid_request_cur != "USD") { throw new Exception($this->expeption_missing_min_bid_request_params . ": cur: system only accepts USD currency at this time"); } } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": at least 1 cur object"); } if (isset($json_post["site"])) { $default_site = $json_post["site"]; if (isset($default_site["domain"])) { $this->bid_request_site_domain = $default_site["domain"]; } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": site_domain"); } if (isset($default_site["page"])) { $this->bid_request_site_page = $default_site["page"]; } if (strpos(strtolower($this->bid_request_site_domain), "https://") !== false || strpos(strtolower($this->bid_request_site_page), "https://") !== false) { $this->bid_request_secure = 1; } if (isset($default_site["publisher"])) { $default_site_publisher = $default_site["publisher"]; if (isset($default_site_publisher["cat"])) { $main_category = $default_site_publisher["cat"]; if ($main_category !== null) { /* * Could be a subcategory like IAB10-2 * In that case just get the main category and compare */ if (strpos($main_category, "-") !== false) { $main_category = substr($main_category, 0, strpos($main_category, "-")); } if (isset($this->vertical_map[strtoupper($main_category)])) { $this->bid_request_site_publisher_cat = $this->vertical_map[strtoupper($main_category)]; } } } } } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": at least 1 site object"); } $this->bid_request_mobile = 0; if (isset($json_post["device"])) { $default_device = $json_post["device"]; if (isset($default_device["ip"])) { $this->bid_request_device_ip = $default_device["ip"]; } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": device_ip"); } if (isset($default_device["language"])) { $this->bid_request_device_language = $default_device["language"]; } if (isset($default_device["model"])) { if (\mobileutil\MobileDeviceType::isPhone($default_device["model"]) === true) { $this->bid_request_mobile = 1; } elseif (\mobileutil\MobileDeviceType::isTablet($default_device["model"]) === true) { $this->bid_request_mobile = 2; } } elseif (isset($default_device["ua"])) { $this->bid_request_device_ua = $default_device["ua"]; if (strpos($this->bid_request_device_ua, '%20') !== false) { $this->bid_request_device_ua = urldecode($this->bid_request_device_ua); } $detect = new \mobileutil\MobileDetect(null, $this->bid_request_device_ua); if ($detect->isTablet() || $detect->isMobile() && !$this->phone_size()) { $this->bid_request_mobile = 2; } elseif ($detect->isMobile()) { $this->bid_request_mobile = 1; } } if (isset($default_device["geo"])) { $geo = $default_device["geo"]; $this->bid_request_geo = array(); if (isset($geo["country"])) { $this->bid_request_geo["country"] = $geo["country"]; } if (isset($geo["region"])) { $this->bid_request_geo["state"] = $geo["region"]; } if (isset($geo["city"])) { $this->bid_request_geo["city"] = $geo["city"]; } if (isset($this->bid_request_geo["country"])) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Geo Data Country: " . $this->bid_request_geo["country"]; } if (isset($this->bid_request_geo["state"])) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Geo Data State: " . $this->bid_request_geo["state"]; } if (isset($this->bid_request_geo["city"])) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Geo Data City: " . $this->bid_request_geo["city"]; } } } else { throw new Exception($this->expeption_missing_min_bid_request_params . ": at least 1 site object"); } if (isset($json_post["regs"])) { $default_regs = $json_post["regs"]; if (isset($default_regs["regs"])) { $this->bid_request_regs_coppa = $default_regs["regs"]; } } \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Is Mobile: " . $this->bid_request_mobile; }
public function process_business_rules_workflow($RtbBid) { $AdCampaignBanner_Match_List = array(); $AdCampaignFactory = \_factory\AdCampaign::get_instance(); $params = array(); $params["Active"] = 1; $AdCampaignList = $AdCampaignFactory->get_cached($RtbBid->config, $params); $current_time = time(); $AdCampaignBannerFactory = \_factory\AdCampaignBanner::get_instance(); $AdCampaignBannerDomainExclusionFactory = \_factory\AdCampaignBannerDomainExclusion::get_instance(); $AdCampaignBannerExclusiveInclusionFactory = \_factory\AdCampaignBannerDomainExclusiveInclusion::get_instance(); $AdCampaignBannerRestrictionsFactory = \_factory\AdCampaignBannerRestrictions::get_instance(); // geocity light $geo_info = null; $maxmind = null; /* * use maxmind incrementally. The geo-Country pay DB we have is only 1 meg * if we need city/state ok, but only load it if absolutely necessary */ if ($RtbBid->bid_request_device_ip !== null && $RtbBid->bid_request_geo === null) { $maxmind = new \geoip\maxmind(); $RtbBid->bid_request_geo["country"] = $maxmind->get_geo_code_country($RtbBid->bid_request_device_ip); } foreach ($AdCampaignList as $AdCampaign) { /* * Check campaign date */ $campaign_startdate = strtotime($AdCampaign->StartDate); $campaign_enddate = strtotime($AdCampaign->EndDate); if ($current_time < $campaign_startdate || $current_time > $campaign_enddate) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check campaign date :: EXPECTED: " . $AdCampaign->StartDate . "->" . $AdCampaign->EndDate . " GOT: " . date('m/d/Y', $current_time); } continue; } /* * Check max spend */ if ($AdCampaign->CurrentSpend >= $AdCampaign->MaxSpend) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Max Campaign Spend Exceeded"; } continue; } /* * Check max impressions */ if ($AdCampaign->ImpressionsCounter >= $AdCampaign->MaxImpressions) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Max Campaign Impressions Exceeded"; } continue; } $markup_rate = \util\Markup::getMarkupRate($AdCampaign, $RtbBid->config); $params = array(); $params["AdCampaignID"] = $AdCampaign->AdCampaignID; $params["Active"] = 1; $AdCampaignBannerList = $AdCampaignBannerFactory->get_cached($RtbBid->config, $params); foreach ($AdCampaignBannerList as $AdCampaignBanner) { /* * check the rules against the banner */ /* * Check banner date */ $banner_startdate = strtotime($AdCampaignBanner->StartDate); $banner_enddate = strtotime($AdCampaignBanner->EndDate); if ($current_time < $banner_startdate || $current_time > $banner_enddate) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner date :: EXPECTED: " . $AdCampaignBanner->StartDate . "->" . $AdCampaignBanner->EndDate . " GOT: " . date('m/d/Y', $current_time); } continue; } /* * Check is mobile web, phone, tablet, native iOS or native Android */ if ($RtbBid->bid_request_mobile != $AdCampaignBanner->IsMobile) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check is mobile web :: EXPECTED: " . $AdCampaignBanner->IsMobile . " GOT: " . $RtbBid->bid_request_mobile; } continue; } /* * Check banner height and width match */ if ($AdCampaignBanner->Height != $RtbBid->bid_request_imp_banner_h || $AdCampaignBanner->Width != $RtbBid->bid_request_imp_banner_w) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner height match :: EXPECTED: " . $AdCampaignBanner->Height . " GOT: " . $RtbBid->bid_request_imp_banner_h; \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner width match :: EXPECTED: " . $AdCampaignBanner->Width . " GOT: " . $RtbBid->bid_request_imp_banner_w; } continue; } /* * Check to see if this AdCampaginBanner is associated to a * contract zone. Contract bound banners are not eligible for * RTB bidding. */ if ($AdCampaignBanner->AdCampaignTypeID == AD_TYPE_CONTRACT) { continue; } elseif ($AdCampaignBanner->AdCampaignTypeID == AD_TYPE_IN_HOUSE_REMNANT && $RtbBid->is_local_request == false) { continue; } elseif ($AdCampaignBanner->AdCampaignTypeID == AD_TYPE_RTB_REMNANT && $RtbBid->is_local_request == true) { continue; } /* * Check banner domain exclusive inclusions * This will narrow the publisher pool down so we * only working with the publishers that the client wants * to advertise on. */ $params = array(); $params["AdCampaignBannerID"] = $AdCampaignBanner->AdCampaignBannerID; $AdCampaignBannerExclusiveInclusionList = $AdCampaignBannerExclusiveInclusionFactory->get_cached($RtbBid->config, $params); foreach ($AdCampaignBannerExclusiveInclusionList as $AdCampaignBannerExclusiveInclusion) { $domain_to_match = strtolower($AdCampaignBannerExclusiveInclusion->DomainName); if ($AdCampaignBannerExclusiveInclusion->InclusionType == "url") { if (strpos(strtolower($RtbBid->bid_request_site_page), $domain_to_match) === false && strpos(strtolower($RtbBid->bid_request_site_domain), $domain_to_match) === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page url, site exclusive inclusions do not match :: EXPECTED: " . $domain_to_match . " GOT: bid_request_site_page: " . $RtbBid->bid_request_site_page . ", bid_request_site_domain: " . $RtbBid->bid_request_site_domain; } // goto next in the larger enclosing foreach loop continue 2; } } elseif ($RtbBid->bid_request_refurl && $AdCampaignBannerExclusiveInclusion->InclusionType == "referrer") { if (strpos(strtolower($RtbBid->bid_request_refurl), $domain_to_match) === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page referrer url, site exclusive inclusions do not match :: EXPECTED: " . $domain_to_match . " GOT: " . $RtbBid->bid_request_refurl; } continue 2; } } } /* * Check banner domain exclusions match */ $params = array(); $params["AdCampaignBannerID"] = $AdCampaignBanner->AdCampaignBannerID; $AdCampaignBannerDomainExclusionList = $AdCampaignBannerDomainExclusionFactory->get_cached($RtbBid->config, $params); foreach ($AdCampaignBannerDomainExclusionList as $AdCampaignBannerDomainExclusion) { $domain_to_match = strtolower($AdCampaignBannerDomainExclusion->DomainName); if ($AdCampaignBannerDomainExclusion->ExclusionType == "url") { if (strpos(strtolower($RtbBid->bid_request_site_page), $domain_to_match) !== false || strpos(strtolower($RtbBid->bid_request_site_domain), $domain_to_match) !== false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page url, site exclusions match :: EXPECTED: " . $domain_to_match . " GOT: bid_request_site_page: " . $RtbBid->bid_request_site_page . ", bid_request_site_domain: " . $RtbBid->bid_request_site_domain; } // goto next in the larger enclosing foreach loop continue 2; } } elseif ($RtbBid->bid_request_refurl && $AdCampaignBannerDomainExclusion->ExclusionType == "referrer") { if (strpos(strtolower($RtbBid->bid_request_refurl), $domain_to_match) !== false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page referrer url, site exclusions match :: EXPECTED: " . $domain_to_match . " GOT: " . $RtbBid->bid_request_refurl; } continue 2; } } } /* * Check banner restrictions (optional fields) */ $params = array(); $params["AdCampaignBannerID"] = $AdCampaignBanner->AdCampaignBannerID; $AdCampaignBannerRestrictions = $AdCampaignBannerRestrictionsFactory->get_row_cached($RtbBid->config, $params); /* * Check banner restrictions */ if ($AdCampaignBannerRestrictions !== null) { /* * Check banner position on page */ /* * Banner position check not supported by OpenRTB 2.1 */ /* * Check banner system fold position (sFoldPos), I don't think we can trust the user fold position (uFoldPos) */ if ($AdCampaignBannerRestrictions->FoldPos !== null && $RtbBid->bid_request_sFoldPos !== null && $AdCampaignBannerRestrictions->FoldPos != $RtbBid->bid_request_sFoldPos) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner system fold position :: EXPECTED: " . $AdCampaignBannerRestrictions->FoldPos . " GOT: " . $RtbBid->bid_request_sFoldPos; } continue; } /* * Frequency capping not supported by OpenRTB 2.1 */ /* * Time Zone not supported by OpenRTB 2.1 */ /* * IFrame detection not supported by OpenRTB 2.1 */ /* * Multiple nested IFrames detection not supported by OpenRTB 2.1 */ /* * Client's screen resolution detection not supported by OpenRTB 2.1 */ /* * Check browser language */ if ($AdCampaignBannerRestrictions->HttpLanguage !== null && $RtbBid->bid_request_device_language !== null) { $has_http_language = false; $request_language_list = explode(";", strtolower($RtbBid->bid_request_device_language)); $http_language_list = explode(";", strtolower($AdCampaignBannerRestrictions->HttpLanguage)); foreach ($http_language_list as $http_language) { if (in_array(trim($http_language), $request_language_list)) { $has_http_language = true; break; } } if ($has_http_language === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check browser language :: EXPECTED: " . $AdCampaignBannerRestrictions->HttpLanguage . " GOT: " . $RtbBid->bid_request_device_language; } continue; } } /* * Check browser user-agent for string */ if ($AdCampaignBannerRestrictions->BrowserUserAgentGrep !== null && $RtbBid->bid_request_device_ua !== null) { if (strpos(strtolower($RtbBid->bid_request_device_ua), strtolower($AdCampaignBannerRestrictions->BrowserUserAgentGrep)) === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check browser user-agent for string :: EXPECTED: " . $AdCampaignBannerRestrictions->BrowserUserAgentGrep . " GOT: " . $RtbBid->bid_request_device_ua; } continue; } } /* * Check browser cookie for string detection not supported by OpenRTB 2.1 */ /* * Check banner for PMP Enable */ if ($AdCampaignBannerRestrictions->PmpEnable !== null && $RtbBid->bid_request_imp_pmp !== null && $RtbBid->bid_request_imp_pmp != $AdCampaignBannerRestrictions->PmpEnable) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner for PMP Enable :: EXPECTED: " . $AdCampaignBannerRestrictions->PmpEnable . " GOT: " . $RtbBid->bid_request_imp_pmp; } continue; } /* * Check banner for https:// secure */ if ($AdCampaignBannerRestrictions->Secure !== null && $RtbBid->bid_request_secure !== null && $RtbBid->bid_request_secure != $AdCampaignBannerRestrictions->Secure) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner for https:// secure :: EXPECTED: " . $AdCampaignBannerRestrictions->Secure . " GOT: " . $RtbBid->bid_request_secure; } continue; } /* * Check user for Coppa opt out status */ if ($AdCampaignBannerRestrictions->Optout !== null && $RtbBid->bid_request_regs_coppa !== null && $RtbBid->bid_request_regs_coppa != $AdCampaignBannerRestrictions->Optout) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check user for Coppa opt out status :: EXPECTED: " . $AdCampaignBannerRestrictions->Optout . " GOT: " . $RtbBid->bid_request_regs_coppa; } continue; } /* * Check banner for it being in the right vertical */ if ($AdCampaignBannerRestrictions->Vertical !== null && $RtbBid->bid_request_site_publisher_cat !== null) { $has_vertical = false; $vertical_list = explode(",", $AdCampaignBannerRestrictions->Vertical); foreach ($vertical_list as $vertical_id) { if ($RtbBid->bid_request_site_publisher_cat == $vertical_id) { $has_vertical = true; break; } } if ($has_vertical === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner for it being in the right vertical :: EXPECTED: " . $AdCampaignBannerRestrictions->Vertical . " GOT: " . $RtbBid->bid_request_site_publisher_cat; } continue; } } /* * Check banner geography */ if ($RtbBid->bid_request_geo !== null) { if ($AdCampaignBannerRestrictions->GeoCountry !== null && isset($RtbBid->bid_request_geo["country"])) { $has_country = false; $country = strtolower($RtbBid->bid_request_geo["country"]); $geo_country_list = explode(",", $AdCampaignBannerRestrictions->GeoCountry); foreach ($geo_country_list as $geo_country) { if (strtolower($geo_country) == $country) { $has_country = true; break; } } if ($has_country === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner geography : Country :: EXPECTED: " . strtolower($AdCampaignBannerRestrictions->GeoCountry) . " GOT: " . $country; } continue; } else { /* * STATE CHECK */ if ($geo_info === null && $AdCampaignBannerRestrictions->GeoState !== null && !isset($RtbBid->bid_request_geo["state"])) { if ($maxmind === null) { $maxmind = new \geoip\maxmind(); } $geo_info = $maxmind->get_geo_code($RtbBid->bid_request_device_ip); if ($geo_info !== null) { $RtbBid->bid_request_geo["state"] = $geo_info["state"]; $RtbBid->bid_request_geo["city"] = $geo_info["city"]; } } if ($AdCampaignBannerRestrictions->GeoState !== null && isset($RtbBid->bid_request_geo["state"])) { if (!isset($RtbBid->bid_request_geo["state"]) && $geo_info === null) { $geo_info = $maxmind->get_geo_code($this->bid_request_device_ip); $this->bid_request_geo["state"] = $geo_info["state"]; } $has_state = false; $state = strtolower($RtbBid->bid_request_geo["state"]); $geo_state_list = explode(",", $AdCampaignBannerRestrictions->GeoState); foreach ($geo_state_list as $geo_state) { if (strtolower($geo_state) == $state) { $has_state = true; break; } } if ($has_state === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner geography : State :: EXPECTED: " . strtolower($AdCampaignBannerRestrictions->GeoState) . " GOT: " . $state; } continue; } else { /* * CITY CHECK */ if ($geo_info === null && $AdCampaignBannerRestrictions->GeoCity !== null && !isset($RtbBid->bid_request_geo["city"])) { if ($maxmind === null) { $maxmind = new \geoip\maxmind(); } $geo_info = $maxmind->get_geo_code($RtbBid->bid_request_device_ip); $RtbBid->bid_request_geo["state"] = $geo_info["state"]; $RtbBid->bid_request_geo["city"] = $geo_info["city"]; } if ($AdCampaignBannerRestrictions->GeoCity !== null && isset($RtbBid->bid_request_geo["city"])) { $has_city = false; $city = strtolower($RtbBid->bid_request_geo["city"]); $geo_city_list = explode(",", $AdCampaignBannerRestrictions->GeoCity); foreach ($geo_city_list as $geo_city) { if (strtolower($geo_city) == $city) { $has_city = true; break; } } if ($has_city === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner geography : City :: EXPECTED: " . strtolower($AdCampaignBannerRestrictions->GeoCity) . " GOT: " . $city; } continue; } } } } } } } } /* * PASSED ALL THE BUSINESS RULES, ADD TO THE RESULTS */ $AdCampaignBannerFactory->incrementAdCampaignBannerBidsCounterCached($RtbBid->config, $RtbBid->rtb_seat_id, $AdCampaignBanner->AdCampaignBannerID); /* * Adjust the bid rate according to the markup */ $mark_down = floatval($AdCampaignBanner->BidAmount) * floatval($markup_rate); $adusted_amount = floatval($AdCampaignBanner->BidAmount) - floatval($mark_down); $AdCampaignBanner->BidAmount = sprintf("%1.4f", $adusted_amount); $AdCampaignBanner_Match_List[] = $AdCampaignBanner; } } return $AdCampaignBanner_Match_List; }