Пример #1
0
 private function process_publisher_tag($config, $banner_request)
 {
     $PublisherAdZoneFactory = \_factory\PublisherAdZone::get_instance();
     $PublisherWebsiteFactory = \_factory\PublisherWebsite::get_instance();
     $params = array();
     $params["AdStatus"] = 1;
     $params["PublisherAdZoneID"] = $banner_request["publisher_banner_id"];
     $PublisherAdZone = $PublisherAdZoneFactory->get_row_cached($config, $params);
     if ($PublisherAdZone == null) {
         return;
     }
     $params = array();
     $params["PublisherWebsiteID"] = $PublisherAdZone->PublisherWebsiteID;
     $PublisherWebsite = $PublisherWebsiteFactory->get_row_cached($config, $params);
     if ($PublisherWebsite == null) {
         return;
     }
     /*
      * Does this publisher's website belong to a Domain Admin
      * running a private exchange?
      * 
      * If it does, did the domain admin enable this website's inventory
      * to be available on the platform connection feature to other
      * domain admins running their own private exchanges?
      * 
      * Did he enable platform exchange on the website edit page
      * to enable this publisher's website inventory to be sent to DSPs?
      */
     $banner_request["PrivateExchangeOnly"] = $PublisherWebsite->VisibilityTypeID == 2 ? true : false;
     $banner_request["ImpressionType"] = $PublisherAdZone->ImpressionType;
     $banner_request = $this->build_request_array($config, $banner_request);
     $RtbSellV22Bid = new \rtbsellv22\RtbSellV22Bid();
     $RtbSellV22Bid->create_rtb_request_from_publisher_display_impression($config, $banner_request);
     /* 
      * We build the OpenRTB request destined for demand
      * that is local to this NginAd instance
      */
     $PmpDealPublisherWebsiteToInsertionOrderLineItemFactory = \_factory\PmpDealPublisherWebsiteToInsertionOrderLineItem::get_instance();
     $params = array();
     $params["PublisherWebsiteID"] = $PublisherWebsite->PublisherWebsiteID;
     $params["Enabled"] = 1;
     if ($banner_request["PrivateExchangeOnly"] === true) {
         /*
          * PublisherWebsiteLocal is set to 1 only if the domain admin
          * owns the publishers under their private exchange
          */
         $params["PublisherWebsiteLocal"] = $PublisherWebsite->VisibilityTypeID == 2 ? 1 : 0;
     }
     $PmpDealPublisherWebsiteToInsertionOrderLineItemList = $PmpDealPublisherWebsiteToInsertionOrderLineItemFactory->get_cached($config, $params);
     $RtbSellV22Bid->clone_local_rtb_request_with_pmp($config, $banner_request, $PmpDealPublisherWebsiteToInsertionOrderLineItemList);
     $bid_request_list[self::GENERIC_PARTNER] = $RtbSellV22Bid->build_rtb_bid_request_generic();
     $bid_request_list[self::LOOPBACK_PARTNER] = $RtbSellV22Bid->build_rtb_bid_request_loopback();
     $PingManager = new \pinger\PingManager($config, $bid_request_list, $PublisherAdZone->AdOwnerID, $PublisherAdZone->PublisherWebsiteID, $PublisherAdZone->FloorPrice, $banner_request["PublisherAdZoneID"], $banner_request["AdName"], $banner_request["WebDomain"], $banner_request["ImpressionType"]);
     /*
      * Send the RTB request to local demand
      */
     $PingManager->set_up_local_demand_ping_clients();
     /*
      * Only send the RTB request to DSPs if the source
      * website is not marked for a private exchange only
      */
     if ($banner_request["PrivateExchangeOnly"] === false) {
         $PingManager->set_up_remote_rtb_ping_clients();
     }
     $PingManager->ping_rtb_ping_clients();
     $AuctionPopo = $PingManager->process_rtb_ping_responses();
     $auction_was_won = $AuctionPopo->auction_was_won;
     $winning_ad_tag = $AuctionPopo->winning_ad_tag;
     /*
      * Auction stats should be published to the database
      * regardless of whether there was a winning bid or not.
      */
     $PingManager->process_rtb_ping_statistics($AuctionPopo);
     /*
      * The RTB auction may not have been won because
      * a floor price wasn't met or there simply may not 
      * have been a valid bid on the auction.
      * 
      * Try to set the tag to the publisher's passback tag 
      * if one exists and if not show the default ad
      */
     if ($auction_was_won === false) {
         if ($PublisherAdZone->PassbackAdTag != null && !empty($PublisherAdZone->PassbackAdTag)) {
             $winning_ad_tag = $PublisherAdZone->PassbackAdTag;
         } else {
             return;
         }
     } else {
         /*
          * Process the macro replacements in the winning Ad tag:
          *
          * NGINCLKTRK: The click tracking URL, TBD, generic click tracking not yet implemented.
          * Try implementing your own custom CTR rate tracking
          *
          * NGINWBIDPRC: The winning bid price expressed as CPM.
          * If this was a 2nd price auction, the value would be the second price expressed as CPM
          */
         $winning_ad_tag = str_replace("{NGINCLKTRK}", "", $winning_ad_tag);
         $winning_ad_tag = str_replace("{NGINWBIDPRC}", $AuctionPopo->winning_bid_price, $winning_ad_tag);
     }
     // now output the logs to the log file
     \rtbsellv22\RtbSellV22Logger::get_instance()->output_log();
     $tracker_url = "";
     if ($banner_request["ImpressionType"] == 'video' && \util\ParseHelper::isVastURL($winning_ad_tag) === true && $AuctionPopo->auction_was_won) {
         $encryption_key = $config['settings']['rtb']['encryption_key'];
         $params = array();
         $params["winning_price"] = $AuctionPopo->winning_bid_price;
         $params["auction_timestamp"] = time();
         $vast_auction_param = $this->encrypt_vast_auction_params($encryption_key, $params);
         $vast_publisher_param = $this->encrypt_vast_auction_params($encryption_key, $AuctionPopo->vast_publisher_imp_obj);
         $tracker_url = $this->get_vast_tracker_url($config, $vast_auction_param, $vast_publisher_param);
         $banner_request["tracker_url"] = $tracker_url;
     }
     if ($AuctionPopo->loopback_demand_partner_won === true) {
         $banner_request["demand_banner_id"] = $AuctionPopo->loopback_demand_partner_ad_campaign_banner_id;
         $banner_request["winning_partner_id"] = $AuctionPopo->winning_partner_id;
         $banner_request["winning_seat"] = $AuctionPopo->winning_seat;
         $this->process_demand_tag($config, $banner_request);
         /* 
          * If this is a local auction we don't need to worry about
          * firing off notice urls
          */
     } else {
         if ($banner_request["ImpressionType"] == 'video') {
             header("Content-type: text/xml");
             if (\util\ParseHelper::isVastURL($winning_ad_tag) === true) {
                 echo $this->get_vast_wrapper_xml($config, $winning_ad_tag, $tracker_url);
             } else {
                 echo $winning_ad_tag;
             }
         } else {
             // credit publisher account here
             header("Content-type: application/javascript");
             $output = "document.write(" . json_encode($winning_ad_tag) . ");";
             echo $output;
         }
         if (!empty($AuctionPopo->nurl)) {
             /*
              * If this is a remote RTB auction we do need to worry about
              * firing off notice urls
              *
              * If safe_mode is off we can fire off an asynchronous CURL
              * call which will not block. Otherwise we are stuck
              * with curl call with a timeout.
              * 
              * curl must also be on the path
              */
             // clear output buffer
             ob_end_flush();
             // check if curl is installed
             $has_curl_on_path = $config['settings']['shell']['has_curl_on_path'];
             if (!ini_get('safe_mode') && $has_curl_on_path) {
                 exec('bash -c "exec nohup setsid curl \'' . $AuctionPopo->nurl . '\' > /dev/null 2>&1 &"');
             } else {
                 \util\WorkflowHelper::get_ping_notice_url_curl_request($AuctionPopo->nurl);
             }
         }
     }
     exit;
 }
Пример #2
0
 private function process_publisher_tag($config, $banner_request)
 {
     $PublisherAdZoneFactory = \_factory\PublisherAdZone::get_instance();
     $params = array();
     $params["AdStatus"] = 1;
     $params["PublisherAdZoneID"] = $banner_request["publisher_banner_id"];
     $PublisherAdZone = $PublisherAdZoneFactory->get_row_cached($config, $params);
     if ($PublisherAdZone == null) {
         return;
     }
     /*
      * Is this ad zone linked to one or more contract banners?
      * If so forward the request to the contract banner
      * display probability logic.
      */
     if ($PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_CONTRACT) {
         $LinkedBannerToAdZoneFactory = \_factory\LinkedBannerToAdZone::get_instance();
         $params = array();
         $params["PublisherAdZoneID"] = $banner_request["publisher_banner_id"];
         $LinkedBannerToAdZoneList = $LinkedBannerToAdZoneFactory->get_cached($config, $params);
         if ($LinkedBannerToAdZoneList != null && count($LinkedBannerToAdZoneList) > 0) {
             $this->process_contract_zone_tag($config, $banner_request, $LinkedBannerToAdZoneList);
         } else {
             return;
         }
     } else {
         $banner_request = $this->build_banner_request($config, $banner_request);
         $RtbSellV22Bid = new \rtbsellv22\RtbSellV22Bid();
         $RtbSellV22Bid->create_rtb_request_from_publisher_impression($config, $banner_request);
         $bid_request = $RtbSellV22Bid->build_rtb_bid_request();
         $PingManager = new \pinger\PingManager($config, $bid_request, $PublisherAdZone->AdOwnerID, $PublisherAdZone->PublisherWebsiteID, $PublisherAdZone->FloorPrice, $banner_request["PublisherAdZoneID"], $banner_request["AdName"], $banner_request["WebDomain"]);
         if ($PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_IN_HOUSE_REMNANT || $PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_ANY_REMNANT) {
             $PingManager->set_up_local_demand_ping_clients();
         }
         if ($PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_RTB_REMNANT || $PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_ANY_REMNANT) {
             $PingManager->set_up_remote_rtb_ping_clients();
         }
         $PingManager->ping_rtb_ping_clients();
         $auction_was_won = $PingManager->process_rtb_ping_responses();
         $winning_ad_tag = $PingManager->winning_ad_tag;
         /*
          * The RTB auction may not have been won because
          * a floor price wasn't met or there simply may not 
          * have been a valid bid on the auction.
          * 
          * Try to set the tag to the publisher's passback tag 
          * if one exists and if not show the default ad
          */
         if ($auction_was_won === false) {
             if ($PublisherAdZone->PassbackAdTag != null && !empty($PublisherAdZone->PassbackAdTag)) {
                 $winning_ad_tag = $PublisherAdZone->PassbackAdTag;
             } else {
                 return;
             }
         }
         $PingManager->process_rtb_ping_statistics();
         // now output the logs to the log file
         \rtbsellv22\RtbSellV22Logger::get_instance()->output_log();
         header("Content-type: application/javascript");
         $output = "document.write(" . json_encode($winning_ad_tag) . ");";
         echo $output;
     }
     exit;
 }
 private function process_publisher_tag($config, $banner_request)
 {
     $PublisherAdZoneFactory = \_factory\PublisherAdZone::get_instance();
     $params = array();
     $params["AdStatus"] = 1;
     $params["PublisherAdZoneID"] = $banner_request["publisher_banner_id"];
     $PublisherAdZone = $PublisherAdZoneFactory->get_row_cached($config, $params);
     if ($PublisherAdZone == null) {
         return;
     }
     $banner_request["ImpressionType"] = $PublisherAdZone->ImpressionType;
     /*
      * Is this ad zone linked to one or more contract banners?
      * If so forward the request to the contract banner
      * display probability logic.
      */
     if ($PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_CONTRACT) {
         $LinkedBannerToAdZoneFactory = \_factory\LinkedBannerToAdZone::get_instance();
         $params = array();
         $params["PublisherAdZoneID"] = $banner_request["publisher_banner_id"];
         $LinkedBannerToAdZoneList = $LinkedBannerToAdZoneFactory->get_cached($config, $params);
         if ($LinkedBannerToAdZoneList != null && count($LinkedBannerToAdZoneList) > 0) {
             $this->process_contract_zone_tag($config, $banner_request, $LinkedBannerToAdZoneList);
         } else {
             return;
         }
     } else {
         $banner_request = $this->build_request_array($config, $banner_request);
         $RtbSellV22Bid = new \rtbsellv22\RtbSellV22Bid();
         $RtbSellV22Bid->create_rtb_request_from_publisher_display_impression($config, $banner_request);
         $bid_request = $RtbSellV22Bid->build_rtb_bid_request();
         $PingManager = new \pinger\PingManager($config, $bid_request, $PublisherAdZone->AdOwnerID, $PublisherAdZone->PublisherWebsiteID, $PublisherAdZone->FloorPrice, $banner_request["PublisherAdZoneID"], $banner_request["AdName"], $banner_request["WebDomain"], $banner_request["ImpressionType"]);
         if ($PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_IN_HOUSE_REMNANT || $PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_ANY_REMNANT) {
             $PingManager->set_up_local_demand_ping_clients();
         }
         if ($PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_RTB_REMNANT || $PublisherAdZone->PublisherAdZoneTypeID == AD_TYPE_ANY_REMNANT) {
             $PingManager->set_up_remote_rtb_ping_clients();
         }
         $PingManager->ping_rtb_ping_clients();
         $AuctionPopo = $PingManager->process_rtb_ping_responses();
         $auction_was_won = $AuctionPopo->auction_was_won;
         $winning_ad_tag = $AuctionPopo->winning_ad_tag;
         /*
          * Auction stats should be published to the database
          * regardless of whether there was a winning bid or not.
          */
         $PingManager->process_rtb_ping_statistics($AuctionPopo);
         /*
          * The RTB auction may not have been won because
          * a floor price wasn't met or there simply may not 
          * have been a valid bid on the auction.
          * 
          * Try to set the tag to the publisher's passback tag 
          * if one exists and if not show the default ad
          */
         if ($auction_was_won === false) {
             if ($PublisherAdZone->PassbackAdTag != null && !empty($PublisherAdZone->PassbackAdTag)) {
                 $winning_ad_tag = $PublisherAdZone->PassbackAdTag;
             } else {
                 return;
             }
         } else {
             /*
              * Process the macro replacements in the winning Ad tag:
              *
              * NGINCLKTRK: The click tracking URL, TBD, generic click tracking not yet implemented.
              * Try implementing your own custom CTR rate tracking
              *
              * NGINWBIDPRC: The winning bid price expressed as CPM.
              * If this was a 2nd price auction, the value would be the second price expressed as CPM
              */
             $winning_ad_tag = str_replace("{NGINCLKTRK}", "", $winning_ad_tag);
             $winning_ad_tag = str_replace("{NGINWBIDPRC}", $AuctionPopo->winning_bid_price, $winning_ad_tag);
         }
         // now output the logs to the log file
         \rtbsellv22\RtbSellV22Logger::get_instance()->output_log();
         $tracker_url = "";
         if ($banner_request["ImpressionType"] == 'video' && \util\ParseHelper::isVastURL($winning_ad_tag) === true && $AuctionPopo->auction_was_won) {
             $encryption_key = $config['settings']['rtb']['encryption_key'];
             $params = array();
             $params["winning_price"] = $AuctionPopo->winning_bid_price;
             $params["auction_timestamp"] = time();
             $vast_auction_param = $this->encrypt_vast_auction_params($encryption_key, $params);
             $vast_publisher_param = $this->encrypt_vast_auction_params($encryption_key, $AuctionPopo->vast_publisher_imp_obj);
             $tracker_url = $this->get_vast_tracker_url($config, $vast_auction_param, $vast_publisher_param);
             $banner_request["tracker_url"] = $tracker_url;
         }
         if ($AuctionPopo->loopback_demand_partner_won === true) {
             $banner_request["demand_banner_id"] = $AuctionPopo->loopback_demand_partner_ad_campaign_banner_id;
             $banner_request["winning_partner_id"] = $AuctionPopo->winning_partner_id;
             $banner_request["winning_seat"] = $AuctionPopo->winning_seat;
             $this->process_demand_tag($config, $banner_request);
             /* 
              * If this is a local auction we don't need to worry about
              * firing off notice urls
              */
         } else {
             if ($banner_request["ImpressionType"] == 'video') {
                 header("Content-type: text/xml");
                 if (\util\ParseHelper::isVastURL($winning_ad_tag) === true) {
                     echo $this->get_vast_wrapper_xml($config, $winning_ad_tag, $tracker_url);
                 } else {
                     echo $winning_ad_tag;
                 }
             } else {
                 // credit publisher account here
                 header("Content-type: application/javascript");
                 $output = "document.write(" . json_encode($winning_ad_tag) . ");";
                 echo $output;
             }
             if (!empty($AuctionPopo->nurl)) {
                 /*
                  * If this is a remote RTB auction we do need to worry about
                  * firing off notice urls
                  *
                  * If safe_mode is off we can fire off an asynchronous CURL
                  * call which will not block. Otherwise we are stuck
                  * with curl call with a timeout.
                  * 
                  * curl must also be on the path
                  */
                 // clear output buffer
                 ob_end_flush();
                 // check if curl is installed
                 $has_curl_on_path = $config['settings']['shell']['has_curl_on_path'];
                 if (!ini_get('safe_mode') && $has_curl_on_path) {
                     exec('bash -c "exec nohup setsid curl \'' . $AuctionPopo->nurl . '\' > /dev/null 2>&1 &"');
                 } else {
                     \util\WorkflowHelper::get_ping_notice_url_curl_request($AuctionPopo->nurl);
                 }
             }
         }
     }
     exit;
 }