Esempio n. 1
0
function MAX_adSelect($what, $campaignid = '', $target = '', $source = '', $withtext = 0, $charset = '', $context = array(), $richmedia = true, $ct0 = '', $loc = '', $referer = '')
{
    $conf = $GLOBALS['_MAX']['CONF'];
    if (empty($GLOBALS['source'])) {
        $GLOBALS['source'] = $source;
    }
    if (empty($GLOBALS['loc'])) {
        $GLOBALS['loc'] = $loc;
    }
    $originalZoneId = null;
    if (strpos($what, 'zone:') === 0) {
        $originalZoneId = intval(substr($what, 5));
    } elseif (strpos($what, 'campaignid:') === 0) {
        $originalCampaignId = intval(substr($what, 11));
    } elseif (strpos($what, 'bannerid:') === 0) {
        $originalBannerId = intval(substr($what, 9));
    }
    $userid = MAX_cookieGetUniqueViewerID();
    MAX_cookieAdd($conf['var']['viewerId'], $userid, _getTimeYearFromNow());
    $outputbuffer = '';
    $found = false;
    $GLOBALS['_MAX']['followedChain'] = array();
    $GLOBALS['_MAX']['adChain'] = array();
    $GLOBALS['_MAX']['considered_ads'] = array();
    $first = true;
    global $g_append, $g_prepend;
    $g_append = '';
    $g_prepend = '';
    if (!empty($what)) {
        while ($first || $what != '' && $found == false) {
            $first = false;
            $ix = strpos($what, '|');
            if ($ix === false) {
                $remaining = '';
            } else {
                $remaining = substr($what, $ix + 1);
                $what = substr($what, 0, $ix);
            }
            if (strpos($what, 'zone:') === 0) {
                $zoneId = intval(substr($what, 5));
                $row = _adSelectZone($zoneId, $context, $source, $richmedia);
            } else {
                if (strpos($what, '/') > 0) {
                    if (strpos($what, '@') > 0) {
                        list($what, $append) = explode('@', $what);
                    } else {
                        $append = '';
                    }
                    $separate = explode('/', $what);
                    $expanded = '';
                    $collected = array();
                    reset($separate);
                    while (list(, $v) = each($separate)) {
                        $expanded .= ($expanded != '' ? ',+' : '') . $v;
                        $collected[] = $expanded . ($append != '' ? ',+' . $append : '');
                    }
                    $what = strtok(implode('|', array_reverse($collected)), '|');
                    $remaining = strtok('') . ($remaining != '' ? '|' . $remaining : '');
                }
                $row = _adSelectDirect($what, $campaignid, $context, $source, $richmedia, $remaining == '');
            }
            if (is_array($row) && empty($row['default'])) {
                MAX_Delivery_log_logAdRequest($row['bannerid'], $row['zoneid'], $row);
                if (($row['adserver'] == 'max' || $row['adserver'] == '3rdPartyServers:ox3rdPartyServers:max') && preg_match("#{$conf['webpath']['delivery']}.*zoneid=([0-9]+)#", $row['htmltemplate'], $matches) && !stristr($row['htmltemplate'], $conf['file']['popup'])) {
                    $GLOBALS['_MAX']['adChain'][] = $row;
                    $found = false;
                    $what = "zone:{$matches[1]}";
                } else {
                    $found = true;
                }
            } else {
                MAX_Delivery_log_logAdRequest(null, $originalZoneId, null);
                $what = $remaining;
            }
        }
    }
    if ($found) {
        $zoneId = empty($row['zoneid']) ? 0 : $row['zoneid'];
        if (!empty($GLOBALS['_MAX']['adChain'])) {
            foreach ($GLOBALS['_MAX']['adChain'] as $index => $ad) {
                if ($ad['ad_id'] != $row['ad_id'] && !empty($ad['append'])) {
                    $row['append'] .= $ad['append'];
                }
            }
        }
        $outputbuffer = MAX_adRender($row, $zoneId, $source, $target, $ct0, $withtext, $charset, true, true, $richmedia, $loc, $referer, $context);
        $output = array('html' => $outputbuffer, 'bannerid' => $row['bannerid'], 'contenttype' => $row['contenttype'], 'alt' => $row['alt'], 'width' => $row['width'], 'height' => $row['height'], 'url' => $row['url'], 'campaignid' => $row['campaignid'], 'clickUrl' => $row['clickUrl'], 'logUrl' => $row['logUrl'], 'aSearch' => $row['aSearch'], 'aReplace' => $row['aReplace'], 'bannerContent' => $row['bannerContent'], 'clickwindow' => $row['clickwindow'], 'aRow' => $row, 'context' => _adSelectBuildContext($row, $context));
        $row += array('block_ad' => 0, 'cap_ad' => 0, 'session_cap_ad' => 0, 'block_campaign' => 0, 'cap_campaign' => 0, 'session_cap_campaign' => 0, 'block_zone' => 0, 'cap_zone' => 0, 'session_cap_zone' => 0);
        if (MAX_Delivery_cookie_cappingOnRequest()) {
            if ($row['block_ad'] > 0 || $row['cap_ad'] > 0 || $row['session_cap_ad'] > 0) {
                MAX_Delivery_cookie_setCapping('Ad', $row['bannerid'], $row['block_ad'], $row['cap_ad'], $row['session_cap_ad']);
            }
            if ($row['block_campaign'] > 0 || $row['cap_campaign'] > 0 || $row['session_cap_campaign'] > 0) {
                MAX_Delivery_cookie_setCapping('Campaign', $row['campaign_id'], $row['block_campaign'], $row['cap_campaign'], $row['session_cap_campaign']);
            }
            if ($row['block_zone'] > 0 || $row['cap_zone'] > 0 || $row['session_cap_zone'] > 0) {
                MAX_Delivery_cookie_setCapping('Zone', $row['zoneid'], $row['block_zone'], $row['cap_zone'], $row['session_cap_zone']);
            }
            MAX_Delivery_log_setLastAction(0, array($row['bannerid']), array($zoneId), array($row['viewwindow']));
        }
    } else {
        if (!empty($row['default'])) {
            if (empty($target)) {
                $target = '_blank';
            }
            $outputbuffer = $g_prepend . '<a href=\'' . $row['default_banner_destination_url'] . '\' target=\'' . $target . '\'><img src=\'' . $row['default_banner_image_url'] . '\' border=\'0\' alt=\'\'></a>' . $g_append;
            $output = array('html' => $outputbuffer, 'bannerid' => '', 'default_banner_image_url' => $row['default_banner_image_url']);
        } else {
            if (!empty($conf['defaultBanner']['imageUrl'])) {
                if (empty($target)) {
                    $target = '_blank';
                }
                $outputbuffer = "{$g_prepend}<img src='{$conf['defaultBanner']['imageUrl']}' border='0' alt=''>{$g_append}";
                $output = array('html' => $outputbuffer, 'bannerid' => '', 'default_banner_image_url' => $conf['defaultBanner']['imageUrl']);
            } else {
                $outputbuffer = $g_prepend . $g_append;
                $output = array('html' => $outputbuffer, 'bannerid' => '');
            }
        }
    }
    OX_Delivery_Common_hook('postAdSelect', array(&$output));
    return $output;
}
 /**
  * This function should take a viewerID and set this in a cookie, and then send a header redirect
  * To self with the additional querystring parameter "ct=1" (cookieTest = 1) to indicate that a
  *
  */
 function test_MAX_cookieAddViewerIdAndRedirect()
 {
     $conf =& $GLOBALS['_MAX']['CONF'];
     // Disable the p3p policies because those are tested elsewhere and we need the redirect header to be [0]
     $conf['p3p']['policies'] = false;
     // Generate a clean viewerId
     unset($_COOKIE[$conf['var']['viewerId']]);
     $viewerId = MAX_cookieGetUniqueViewerID(true);
     // I know I've tested this elsewhere in the file, but sanity check that we have a valid viewerId
     $this->assertIsA($viewerId, 'string');
     $this->assertEqual(strlen($viewerId), 32);
     // Ensure that calling MAX_cookieSetViewerIdAndRedirect($viewerId) sets and flushes the viewerId cookie and redirects
     unset($GLOBALS['_HEADERS']);
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['SCRIPT_NAME'] = 'tests/index.php';
     $_SERVER['QUERY_STRING'] = 'test=1&toast=2';
     MAX_cookieSetViewerIdAndRedirect($viewerId);
     $this->assertEqual($_COOKIE[$conf['var']['viewerId']], $viewerId);
     // Ensure that the redirect header is set
     $this->assertIsA($GLOBALS['_HEADERS'][0], 'string');
     $this->assertTrue(preg_match('#^Location: http:\\/\\/.*' . $conf['var']['cookieTest'] . '=1.*$#', $GLOBALS['_HEADERS'][0]));
 }
Esempio n. 3
0
        $len = strpos($element, '=');
        if ($len !== false) {
            $name = substr($element, 0, $len);
            $value = substr($element, $len + 1);
            $aArr[$name] = urldecode($value);
        }
    }
}
// Prevent click from being cached by browsers
MAX_commonSetNoCacheHeaders();
// Convert specially encoded params into the $_REQUEST variable
MAX_querystringConvertParams();
// Remove any special characters
MAX_commonRemoveSpecialChars($_REQUEST);
// Get the variables
$viewerId = MAX_cookieGetUniqueViewerID();
if (!empty($GLOBALS['_MAX']['COOKIE']['newViewerId']) && empty($_GET[$conf['var']['cookieTest']])) {
    // No previous cookie was found, and we have not tried to force setting one...
    MAX_cookieSetViewerIdAndRedirect($viewerId);
}
$adId = isset($_REQUEST[$conf['var']['adId']]) ? explode($GLOBALS['_MAX']['MAX_DELIVERY_MULTIPLE_DELIMITER'], $_REQUEST[$conf['var']['adId']]) : array();
$zoneId = isset($_REQUEST[$conf['var']['zoneId']]) ? explode($GLOBALS['_MAX']['MAX_DELIVERY_MULTIPLE_DELIMITER'], $_REQUEST[$conf['var']['zoneId']]) : array();
$creativeId = isset($_REQUEST[$conf['var']['creativeId']]) ? explode($GLOBALS['_MAX']['MAX_DELIVERY_MULTIPLE_DELIMITER'], $_REQUEST[$conf['var']['creativeId']]) : array();
$lastClick = isset($_REQUEST[$conf['var']['lastClick']]) ? explode($GLOBALS['_MAX']['MAX_DELIVERY_MULTIPLE_DELIMITER'], $_REQUEST[$conf['var']['lastClick']]) : array();
$aBlockLoggingClick = isset($_REQUEST[$conf['var']['blockLoggingClick']]) ? $_REQUEST[$conf['var']['blockLoggingClick']] : array();
if (empty($adId) && !empty($zoneId)) {
    foreach ($zoneId as $index => $zone) {
        $adId[$index] = _getZoneAd($zone);
        $creativeId[$index] = 0;
    }
}
Esempio n. 4
0
function MAX_adSelect($what, $campaignid = '', $target = '', $source = '', $withtext = 0, $charset = '', $context = array(), $richmedia = true, $ct0 = '', $loc = '', $referer = '')
{
    $conf = $GLOBALS['_MAX']['CONF'];
    // For local mode and XML-RPC calls the some parameters are not set in the global scope
    // So we need to override the empty globals with the values passed into this function.
    if (empty($GLOBALS['source'])) {
        $GLOBALS['source'] = $source;
    }
    if (empty($GLOBALS['loc'])) {
        $GLOBALS['loc'] = $loc;
    }
    // Store the original zone, campaign or banner IDs for later use
    if (strpos($what, 'zone:') === 0) {
        $originalZoneId = intval(substr($what, 5));
    } elseif (strpos($what, 'campaignid:') === 0) {
        $originalCampaignId = intval(substr($what, 11));
    } elseif (strpos($what, 'bannerid:') === 0) {
        $originalBannerId = intval(substr($what, 9));
    }
    $userid = MAX_cookieGetUniqueViewerID();
    MAX_cookieSet($conf['var']['viewerId'], $userid, _getTimeYearFromNow());
    $outputbuffer = '';
    // Set flag
    $found = false;
    // Reset followed zone chain
    $GLOBALS['_MAX']['followedChain'] = array();
    $GLOBALS['_MAX']['adChain'] = array();
    $first = true;
    global $g_append, $g_prepend;
    $g_append = '';
    $g_prepend = '';
    if (!empty($what)) {
        while ($first || $what != '' && $found == false) {
            $first = false;
            // Get first part, store second part
            $ix = strpos($what, '|');
            if ($ix === false) {
                $remaining = '';
            } else {
                $remaining = substr($what, $ix + 1);
                $what = substr($what, 0, $ix);
            }
            if (strpos($what, 'zone:') === 0) {
                $zoneId = intval(substr($what, 5));
                $row = _adSelectZone($zoneId, $context, $source, $richmedia);
            } else {
                // Expand paths to regular statements
                if (strpos($what, '/') > 0) {
                    if (strpos($what, '@') > 0) {
                        list($what, $append) = explode('@', $what);
                    } else {
                        $append = '';
                    }
                    $separate = explode('/', $what);
                    $expanded = '';
                    $collected = array();
                    reset($separate);
                    while (list(, $v) = each($separate)) {
                        $expanded .= ($expanded != '' ? ',+' : '') . $v;
                        $collected[] = $expanded . ($append != '' ? ',+' . $append : '');
                    }
                    $what = strtok(implode('|', array_reverse($collected)), '|');
                    $remaining = strtok('') . ($remaining != '' ? '|' . $remaining : '');
                }
                $row = _adSelectDirect($what, $campaignid, $context, $source, $richmedia, $remaining == '');
            }
            if (is_array($row) && empty($row['default'])) {
                // Log the ad request
                MAX_Delivery_log_logAdRequest($row['bannerid'], $row['zoneid'], $row);
                if (($row['adserver'] == 'max' || $row['adserver'] == '3rdPartyServers:ox3rdPartyServers:max') && preg_match("#{$conf['webpath']['delivery']}.*zoneid=([0-9]+)#", $row['htmltemplate'], $matches) && !stristr($row['htmltemplate'], $conf['file']['popup'])) {
                    // The ad selected was an OpenX HTML ad on the same server... do internal redirecty stuff
                    $GLOBALS['_MAX']['adChain'][] = $row;
                    $found = false;
                    $what = "zone:{$matches[1]}";
                } else {
                    $found = true;
                }
            } else {
                $what = $remaining;
            }
        }
    }
    // Return the banner information
    if ($found) {
        $zoneId = empty($row['zoneid']) ? 0 : $row['zoneid'];
        // For internal redirected creatives, make sure that any appended code in the adChain is appended
        if (!empty($GLOBALS['_MAX']['adChain'])) {
            foreach ($GLOBALS['_MAX']['adChain'] as $index => $ad) {
                if ($ad['ad_id'] != $row['ad_id'] && !empty($ad['append'])) {
                    $row['append'] .= $ad['append'];
                }
            }
        }
        $outputbuffer = MAX_adRender($row, $zoneId, $source, $target, $ct0, $withtext, $charset, true, true, $richmedia, $loc, $referer, $context);
        $output = array('html' => $outputbuffer, 'bannerid' => $row['bannerid'], 'contenttype' => $row['contenttype'], 'alt' => $row['alt'], 'width' => $row['width'], 'height' => $row['height'], 'url' => $row['url'], 'campaignid' => $row['campaignid'], 'clickUrl' => $row['clickUrl'], 'logUrl' => $row['logUrl'], 'aSearch' => $row['aSearch'], 'aReplace' => $row['aReplace'], 'bannerContent' => $row['bannerContent'], 'clickwindow' => $row['clickwindow'], 'aRow' => $row, 'context' => _adSelectBuildContext($row, $context));
        // If ad-logging is disabled, the log beacon won't be sent, so set the capping at request
        if (MAX_Delivery_cookie_cappingOnRequest()) {
            if ($row['block_ad'] > 0 || $row['cap_ad'] > 0 || $row['session_cap_ad'] > 0) {
                MAX_Delivery_cookie_setCapping('Ad', $row['bannerid'], $row['block_ad'], $row['cap_ad'], $row['session_cap_ad']);
            }
            if ($row['block_campaign'] > 0 || $row['cap_campaign'] > 0 || $row['session_cap_campaign'] > 0) {
                MAX_Delivery_cookie_setCapping('Campaign', $row['campaign_id'], $row['block_campaign'], $row['cap_campaign'], $row['session_cap_campaign']);
            }
            if ($row['block_zone'] > 0 || $row['cap_zone'] > 0 || $row['session_cap_zone'] > 0) {
                MAX_Delivery_cookie_setCapping('Zone', $row['zoneid'], $row['block_zone'], $row['cap_zone'], $row['session_cap_zone']);
            }
            // Store the last view action event om the cookie as well (if required)
            MAX_Delivery_log_setLastAction(0, array($row['bannerid']), array($zoneId), array($row['viewwindow']));
        }
        return $output;
    } else {
        // No banner found
        if (!empty($row['default'])) {
            // Return the default banner
            if (empty($target)) {
                $target = '_blank';
                // Default
            }
            $outputbuffer = $g_prepend . '<a href=\'' . $row['default_banner_destination_url'] . '\' target=\'' . $target . '\'><img src=\'' . $row['default_banner_image_url'] . '\' border=\'0\' alt=\'\'></a>' . $g_append;
            return array('html' => $outputbuffer, 'bannerid' => '', 'default_banner_image_url' => $row['default_banner_image_url']);
        } else {
            // No default banner was returned, return no banner
            $outputbuffer = $g_prepend . $g_append;
            return array('html' => $outputbuffer, 'bannerid' => '');
        }
    }
}