Ejemplo n.º 1
0
 private function build_banner_request($config, $banner_request)
 {
     $banner_request_id = intval($banner_request["publisher_banner_id"]);
     $PublisherAdZoneFactory = \_factory\PublisherAdZone::get_instance();
     $params = array();
     $params["PublisherAdZoneID"] = $banner_request_id;
     $params["AdStatus"] = 1;
     $PublisherAdZone = $PublisherAdZoneFactory->get_row_cached($params);
     $PublisherWebsite = null;
     if ($PublisherAdZone == null) {
         return null;
     }
     $PublisherWebsiteFactory = \_factory\PublisherWebsite::get_instance();
     $params = array();
     $params["PublisherWebsiteID"] = $PublisherAdZone->PublisherWebsiteID;
     $PublisherWebsite = $PublisherWebsiteFactory->get_row_cached($params);
     if ($PublisherWebsite == null) {
         return null;
     }
     /*
      * Produce the RTB request to our demand partners
      */
     $banner_request["PublisherAdZoneID"] = $PublisherAdZone->PublisherAdZoneID;
     $banner_request["AdName"] = $PublisherAdZone->AdName;
     $banner_request["WebDomain"] = $PublisherWebsite->WebDomain;
     if (!isset($banner_request["org_tld"]) || $banner_request["org_tld"] == null) {
         $banner_request["org_tld"] = $PublisherWebsite->WebDomain;
     }
     $banner_request["height"] = $PublisherAdZone->Height;
     $banner_request["width"] = $PublisherAdZone->Width;
     $banner_request["bidfloor"] = sprintf("%1.4f", $PublisherAdZone->FloorPrice);
     $banner_request["iab_category"] = $PublisherWebsite->IABCategory;
     $banner_request["iab_sub_category"] = $PublisherWebsite->IABSubCategory;
     $banner_request["website_id"] = $PublisherAdZone->PublisherWebsiteID;
     $banner_request["publisher_info_website"] = "example.com";
     // will be populated from the initial publisher signup.
     $banner_request["publisher_id"] = 1;
     // will be populated from the initial publisher signup.
     $banner_request["publisher_name"] = "Demo Publisher";
     // will be populated from the initial publisher signup.
     $banner_request["publisher_iab_category"] = null;
     $ip_address = isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER["REMOTE_ADDR"];
     $banner_request["ip_address"] = $ip_address;
     $banner_request["user_id"] = md5($banner_request["ip_address"]);
     $user_agent = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : "";
     $banner_request["user_agent"] = $user_agent;
     $banner_request["language"] = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : null;
     /*
      * Device Type
      *
      * 1	 Mobile/Tablet
      * 2	 Personal	Computer
      */
     $detect = new \mobileutil\MobileDetect(null, $banner_request["user_agent"]);
     if ($detect->isMobile()) {
         $banner_request["devicetype"] = 1;
         if ($detect->is('iOS')) {
             $banner_request["mobile_os"] = "iOS";
             $banner_request["mobile_make"] = "Apple";
             if ($detect->isTablet()) {
                 $banner_request["mobile_model"] = "iPad";
             } else {
                 $banner_request["mobile_model"] = "iPhone";
             }
         } elseif ($detect->is('AndroidOS') || $detect->is('Chrome')) {
             $banner_request["mobile_os"] = "Android";
         }
     } else {
         $banner_request["devicetype"] = 2;
     }
     return $banner_request;
 }
Ejemplo n.º 2
0
 private function add_mobile_request_params($config, &$banner_request)
 {
     /*
      * Device Type
      *
      * 1	 Mobile/Tablet
      * 2	 Personal	Computer
      */
     $detect = new \mobileutil\MobileDetect(null, $banner_request["user_agent"]);
     if ($detect->isMobile()) {
         $banner_request["devicetype"] = DEVICE_MOBILE;
         if ($detect->is('iOS')) {
             $banner_request["mobile_os"] = "iOS";
             $banner_request["mobile_make"] = "Apple";
             if ($detect->isTablet()) {
                 $banner_request["mobile_model"] = "iPad";
             } else {
                 $banner_request["mobile_model"] = "iPhone";
             }
         } elseif ($detect->is('AndroidOS') || $detect->is('Chrome')) {
             $banner_request["mobile_os"] = "Android";
         }
     } else {
         $banner_request["devicetype"] = DEVICE_DESKTOP;
     }
 }
Ejemplo n.º 3
0
 public static function execute(&$Logger, \buyrtbfidelity\parsers\openrtb\OpenRTBParser &$Parser, \model\openrtb\RtbBidRequest &$RtbBidRequest, \model\openrtb\RtbBidRequestDevice &$RtbBidRequestDevice, &$device)
 {
     $RtbBidRequestDevice->devicetype = DEVICE_DESKTOP;
     if (!isset($Parser->json_post["device"])) {
         return;
     }
     $default_device = $Parser->json_post["device"];
     // do not track bit
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "dnt");
     // User Agent. If URL encoded, decode
     if (isset($default_device["ua"])) {
         \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "ua");
         if (strpos($RtbBidRequestDevice->ua, '%20') !== false) {
             $RtbBidRequestDevice->ua = urldecode($RtbBidRequestDevice->ua);
         }
     }
     /*
      * NginAd requires the User's IP Address
      * for black listing purposes and for fill ratios
      * against the MD5 checksum.
      * 
      * The OpenRTB spec states it's optional
      */
     \util\ParseHelper::parse_with_exception($RtbBidRequestDevice, $default_device, $Parser->expeption_missing_min_bid_request_params . ": device_ip", "ip");
     // geo object
     if (isset($default_device["geo"])) {
         $geo = $default_device["geo"];
         $RtbBidRequestGeo = new \model\openrtb\RtbBidRequestGeo();
         \buyrtbfidelity\parsers\openrtb\parselets\common\ParseGeo::execute($Logger, $Parser, $RtbBidRequest, $RtbBidRequestGeo, $geo);
         $RtbBidRequestDevice->RtbBidRequestGeo = $RtbBidRequestGeo;
     }
     // device id SHA1
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "didsha1");
     // device id MD5
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "didmd5");
     // platform device id SHA1
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "dpidsha1");
     // platform device id MD5
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "dpidmd5");
     // mac address SHA1
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "macsha1");
     // mac address MD5
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "macmd5");
     // IPv6 address
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "ipv6");
     // mobile ISP carrier
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "carrier");
     // language code ( alpha-2/ISO 639-1 )
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "language");
     // Device OEM make
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "make");
     // Device OEM model
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "model");
     // OS name
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "os");
     // OS version
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "osv");
     // Bit Flag for Javascript Enabled
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "js");
     // Connection type id
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "connectiontype");
     // device type id
     if (!empty($default_device["devicetype"])) {
         $RtbBidRequestDevice->devicetype = intval($default_device["devicetype"]);
     } elseif (isset($RtbBidRequestDevice->model)) {
         if (\mobileutil\MobileDeviceType::isPhone($RtbBidRequestDevice->model) === true) {
             $RtbBidRequestDevice->devicetype = DEVICE_MOBILE;
         } elseif (\mobileutil\MobileDeviceType::isTablet($RtbBidRequestDevice->model) === true) {
             $RtbBidRequestDevice->devicetype = DEVICE_TABLET;
         }
     }
     if ($RtbBidRequestDevice->devicetype == DEVICE_DESKTOP && isset($RtbBidRequestDevice->ua) && $RtbBidRequestDevice->ua != null) {
         $detect = new \mobileutil\MobileDetect(null, $RtbBidRequestDevice->ua);
         if ($detect->isTablet()) {
             $RtbBidRequestDevice->devicetype = DEVICE_TABLET;
         } elseif ($detect->isMobile()) {
             $RtbBidRequestDevice->devicetype = DEVICE_MOBILE;
         }
     }
     // adobe flash version
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "flashver");
     // native ads unique id
     \util\ParseHelper::parse_item($RtbBidRequestDevice, $default_device, "ifa");
 }
Ejemplo n.º 4
0
 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;
 }