Exemple #1
0
function _adSelectZone($zoneId, $context = array(), $source = '', $richMedia = true)
{
    if ($zoneId === 0) {
        return false;
    }
    global $g_append, $g_prepend;
    while (!in_array($zoneId, $GLOBALS['_MAX']['followedChain'])) {
        $GLOBALS['_MAX']['followedChain'][] = $zoneId;
        $appendedThisZone = false;
        $aZoneInfo = MAX_cacheGetZoneInfo($zoneId);
        if (empty($aZoneInfo)) {
            return false;
        }
        if ($zoneId != 0 && MAX_limitationsIsZoneForbidden($zoneId, $aZoneInfo)) {
            $zoneId = _getNextZone($zoneId, $aZoneInfo);
            continue;
        }
        $aZoneLinkedAdInfos = MAX_cacheGetZoneLinkedAdInfos($zoneId);
        if (is_array($aZoneInfo)) {
            if (isset($aZoneInfo['forceappend']) && $aZoneInfo['forceappend'] == 't') {
                $g_prepend .= $aZoneInfo['prepend'];
                $g_append = $aZoneInfo['append'] . $g_append;
                $appendedThisZone = true;
            }
            $aZoneLinkedAdInfos += $aZoneInfo;
            $aLinkedAd = _adSelectCommon($aZoneLinkedAdInfos, $context, $source, $richMedia);
            if (is_array($aLinkedAd)) {
                $aLinkedAd['zoneid'] = $zoneId;
                $aLinkedAd['bannerid'] = $aLinkedAd['ad_id'];
                $aLinkedAd['storagetype'] = $aLinkedAd['type'];
                $aLinkedAd['campaignid'] = $aLinkedAd['placement_id'];
                $aLinkedAd['zone_companion'] = $aZoneLinkedAdInfos['zone_companion'];
                $aLinkedAd['block_zone'] = @$aZoneInfo['block_zone'];
                $aLinkedAd['cap_zone'] = @$aZoneInfo['cap_zone'];
                $aLinkedAd['session_cap_zone'] = @$aZoneInfo['session_cap_zone'];
                $aLinkedAd['affiliate_id'] = @$aZoneInfo['publisher_id'];
                if (!$appendedThisZone) {
                    $aLinkedAd['append'] .= @$aZoneInfo['append'] . $g_append;
                    $aLinkedAd['prepend'] = $g_prepend . @$aZoneInfo['prepend'] . $aLinkedAd['prepend'];
                } else {
                    $aLinkedAd['append'] .= $g_append;
                    $aLinkedAd['prepend'] = $g_prepend . $aLinkedAd['prepend'];
                }
                return $aLinkedAd;
            }
            $zoneId = _getNextZone($zoneId, $aZoneInfo);
        }
    }
    if (!empty($aZoneInfo['default_banner_image_url'])) {
        return array('default' => true, 'default_banner_image_url' => $aZoneInfo['default_banner_image_url'], 'default_banner_destination_url' => $aZoneInfo['default_banner_destination_url']);
    }
    return false;
}
Exemple #2
0
| License: GPLv2 or later, see the LICENSE.txt file.                        |
+---------------------------------------------------------------------------+
*/
// Require the initialisation file
require_once '../../init-delivery.php';
// Required files
require_once MAX_PATH . '/lib/max/Delivery/adSelect.php';
require_once MAX_PATH . '/lib/max/Delivery/flash.php';
require_once MAX_PATH . '/lib/max/Delivery/cache.php';
MAX_commonSendContentTypeHeader('text/html');
//Register any script specific input variables
MAX_commonRegisterGlobalsArray(array('timeout'));
$timeout = !empty($timeout) ? $timeout : 0;
if ($zoneid > 0) {
    // Get the zone from cache
    $aZone = MAX_cacheGetZoneInfo($zoneid);
} else {
    // Direct selection, or problem with admin DB
    $aZone = array();
    $aZone['zoneid'] = $zoneid;
    $aZone['append'] = '';
    $aZone['prepend'] = '';
}
// Get the banner from cache
$aBanner = MAX_cacheGetAd($bannerid);
$prepend = !empty($aZone['prepend']) ? $aZone['prepend'] : '';
$html = MAX_adRender($aBanner, $zoneid, $source, $target, $ct0, $withtext);
$append = !empty($aZone['append']) ? $aZone['append'] : '';
$title = !empty($aBanner['alt']) ? $aBanner['alt'] : 'Advertisement';
echo "\n<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n<head>\n<title>{$title}</title>";
if ($timeout > 0) {
 /**
  * Method tests invalidateZoneCache method
  *
  */
 function test_invalidateZoneCache()
 {
     $cachedZoneInfoData = MAX_cacheGetZoneInfo($this->_aIds['zones'][0]);
     $cachedZoneLinkedAdsData = MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][0]);
     $cachedPublisherZonesData = OA_cacheGetPublisherZones($this->_aIds['affiliates'][0]);
     // Change zonename
     $doZone = OA_Dal::factoryDO('zones');
     $doZone->get($this->_aIds['zones']);
     $doZone->zonename = 'new name';
     $doZone->update();
     // Expect no changes in cache
     $this->assertEqual(MAX_cacheGetZoneInfo($this->_aIds['zones'][0]), $cachedZoneInfoData);
     $this->assertEqual(MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][0]), $cachedZoneLinkedAdsData);
     $this->assertEqual(OA_cacheGetPublisherZones($this->_aIds['affiliates'][0]), $cachedPublisherZonesData);
     $this->oDeliveryCacheManager->invalidateZoneCache($this->_aIds['zones'][0]);
     // Now expect changes in cache
     $this->assertNotEqual(MAX_cacheGetZoneInfo($this->_aIds['zones'][0]), $cachedZoneInfoData);
     $this->assertNotEqual(MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][0]), $cachedZoneLinkedAdsData);
     $this->assertNotEqual(OA_cacheGetPublisherZones($this->_aIds['affiliates'][0]), $cachedPublisherZonesData);
 }
 /**
  * Creates all possible delivert cache files
  *
  * @param array $aIds array of DB Ids returned by _createTestData
  * @see _createTestData
  */
 function _createTestCacheFiles($aIds)
 {
     // Create cache files not related to DB Objects
     MAX_cacheGetAccountTZs();
     MAX_cacheCheckIfMaintenanceShouldRun();
     MAX_cacheGetGoogleJavaScript();
     // Create cache files for banners and images
     foreach ($aIds['banners'] as $bannerId) {
         MAX_cacheGetAd($bannerId);
     }
     foreach ($aIds['images'] as $filename) {
         MAX_cacheGetCreative($filename);
     }
     // Create cache files for zones
     foreach ($aIds['zones'] as $zoneId) {
         MAX_cacheGetZoneLinkedAds($zoneId);
         MAX_cacheGetZoneInfo($zoneId);
     }
     // Create cache files for websites
     foreach ($aIds['affiliates'] as $affiliateid) {
         OA_cacheGetPublisherZones($affiliateid);
     }
     // Create cache files for trackers
     foreach ($aIds['trackers'] as $trackerid) {
         MAX_cacheGetTracker($trackerid);
         MAX_cacheGetTrackerVariables($trackerid);
     }
     // Create cache files for channels
     foreach ($aIds['channel'] as $channelid) {
         MAX_cacheGetChannelLimitations($channelid);
     }
     // cache files for direct-selection are not created
     // due to problems with invalidating MAX_cacheGetLinkedAds
 }
 /**
  * Method tests invalidateGetZoneInfoCache method
  */
 function test_invalidateGetZoneInfoCache()
 {
     $aIds = $this->_createTestData();
     $this->_createTestCacheFiles($aIds);
     $cachedData = MAX_cacheGetZoneInfo($aIds['zones'][0]);
     // Change zone
     $doZone = OA_Dal::factoryDO('zones');
     $doZone->get($aIds['zones'][0]);
     $doZone->zonename = 'new name';
     $doZone->update();
     // Expect no changes in cache
     $this->assertEqual(MAX_cacheGetZoneInfo($aIds['zones'][0]), $cachedData);
     $this->oDeliveryCacheCommon->invalidateGetZoneInfoCache($aIds['zones'][0]);
     // Now expect changes in cache
     $cachedData2 = MAX_cacheGetZoneInfo($aIds['zones'][0]);
     $this->assertNotEqual($cachedData2, $cachedData);
 }
/**
 * This function selects an ad selected from a specific zone
 *
 * @param int     $zoneId       The ID of the zone to select an ad from
 * @param array   $context      The context of this ad selection
 *                              - used for companion positioning
 *                              - and excluding banner/campaigns from this ad-call
 * @param string  $source       The "source" parameter passed into the adcall
 * @param boolean $richMedia    Does this invocation method allow for serving 3rd party/html ads
 *
 * @return array|false          Returns an ad-array (see page DocBlock) or false if no ad found
 */
function _adSelectZone($zoneId, $context = array(), $source = '', $richMedia = true)
{
    // ZoneID zero is used for direct selected adRequests only
    if ($zoneId === 0) {
        return false;
    }
    global $g_append, $g_prepend;
    while (!in_array($zoneId, $GLOBALS['_MAX']['followedChain'])) {
        $GLOBALS['_MAX']['followedChain'][] = $zoneId;
        $appendedThisZone = false;
        // first get zone info
        $aZoneInfo = MAX_cacheGetZoneInfo($zoneId);
        if (empty($aZoneInfo)) {
            // the zone does not exist, sorry!
            return false;
        }
        //check zone level limitations
        if ($zoneId != 0 && MAX_limitationsIsZoneForbidden($zoneId, $aZoneInfo)) {
            $zoneId = _getNextZone($zoneId, $aZoneInfo);
            continue;
        }
        // Get all ads which are linked to the zone
        $aZoneLinkedAdInfos = MAX_cacheGetZoneLinkedAdInfos($zoneId);
        if (is_array($aZoneInfo)) {
            if (isset($aZoneInfo['forceappend']) && $aZoneInfo['forceappend'] == 't') {
                $g_prepend .= $aZoneInfo['prepend'];
                $g_append = $aZoneInfo['append'] . $g_append;
                $appendedThisZone = true;
            }
            // merge zone info and banner info
            $aZoneLinkedAdInfos += $aZoneInfo;
            $aLinkedAd = _adSelectCommon($aZoneLinkedAdInfos, $context, $source, $richMedia);
            if (is_array($aLinkedAd)) {
                $aLinkedAd['zoneid'] = $zoneId;
                $aLinkedAd['bannerid'] = $aLinkedAd['ad_id'];
                $aLinkedAd['storagetype'] = $aLinkedAd['type'];
                $aLinkedAd['campaignid'] = $aLinkedAd['placement_id'];
                $aLinkedAd['zone_companion'] = $aZoneLinkedAdInfos['zone_companion'];
                $aLinkedAd['block_zone'] = @$aZoneInfo['block_zone'];
                $aLinkedAd['cap_zone'] = @$aZoneInfo['cap_zone'];
                $aLinkedAd['session_cap_zone'] = @$aZoneInfo['session_cap_zone'];
                $aLinkedAd['affiliate_id'] = @$aZoneInfo['publisher_id'];
                if (!$appendedThisZone) {
                    $aLinkedAd['append'] .= @$aZoneInfo['append'] . $g_append;
                    $aLinkedAd['prepend'] = $g_prepend . @$aZoneInfo['prepend'] . $aLinkedAd['prepend'];
                } else {
                    $aLinkedAd['append'] .= $g_append;
                    $aLinkedAd['prepend'] = $g_prepend . $aLinkedAd['prepend'];
                }
                return $aLinkedAd;
            }
            $zoneId = _getNextZone($zoneId, $aZoneInfo);
        }
    }
    if (!empty($aZoneInfo['default_banner_image_url'])) {
        return array('default' => true, 'default_banner_image_url' => $aZoneInfo['default_banner_image_url'], 'default_banner_destination_url' => $aZoneInfo['default_banner_destination_url']);
    }
    return false;
}