function Plugin_deliveryCacheStore_apRedis_apRedis_Delivery_cacheStore($filename, $cache_contents)
{
    $expiryTime = $GLOBALS['OA_Delivery_Cache']['expiry'];
    try {
        $redis = AP_Redis_Cache::singleton();
        if (isset($cache_contents['cache_expire'])) {
            $expiryTime = $cache_contents['cache_expire'];
        } elseif (isset($cache_contents['cache_time'])) {
            $expiryTime = $cache_contents['cache_time'] - MAX_commonGetTimeNow() + $GLOBALS['OA_Delivery_Cache']['expiry'];
        }
        $result = $redis->setex($filename, $expiryTime + 86400, $redis->serialize($cache_contents));
        $redis->del('_lock_' . $filename);
        return $result;
    } catch (Exception $e) {
        return false;
    }
}
Exemplo n.º 2
0
function MAX_cacheCheckIfMaintenanceShouldRun($cached = true)
{
    $interval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] * 60;
    $delay = intval($GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] / 12 * 60);
    $now = MAX_commonGetTimeNow();
    $today = strtotime(date('Y-m-d'), $now);
    $nextRunTime = $today + (floor(($now - $today) / $interval) + 1) * $interval + $delay;
    if ($nextRunTime - $now > $interval) {
        $nextRunTime -= $interval;
    }
    $cName = OA_Delivery_Cache_getName(__FUNCTION__);
    if (!$cached || ($lastRunTime = OA_Delivery_Cache_fetch($cName)) === false) {
        MAX_Dal_Delivery_Include();
        $lastRunTime = OA_Dal_Delivery_getMaintenanceInfo();
        if ($lastRunTime >= $nextRunTime - $delay) {
            $nextRunTime += $interval;
        }
        OA_Delivery_Cache_store($cName, $lastRunTime, false, $nextRunTime);
    }
    return $lastRunTime < $nextRunTime - $interval;
}
Exemplo n.º 3
0
function _adSelectCheckCriteria($aAd, $aContext, $source, $richMedia)
{
    $conf = $GLOBALS['_MAX']['CONF'];
    if (!empty($aAd['expire_time'])) {
        $expire = strtotime($aAd['expire_time']);
        $now = MAX_commonGetTimeNow();
        if ($expire > 0 && $now > $expire) {
            OX_Delivery_logMessage('Campaign has expired for bannerid ' . $aAd['ad_id'], 7);
            return false;
        }
    }
    if (isset($aContext['banner']['exclude'][$aAd['ad_id']])) {
        OX_Delivery_logMessage('List of excluded banners list contains bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (isset($aContext['campaign']['exclude'][$aAd['placement_id']])) {
        OX_Delivery_logMessage('List of excluded campaigns contains bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (isset($aContext['client']['exclude'][$aAd['client_id']])) {
        OX_Delivery_logMessage('List of excluded clients contains bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (sizeof($aContext['banner']['include']) && !isset($aContext['banner']['include'][$aAd['ad_id']])) {
        OX_Delivery_logMessage('List of included banners does not contain bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (sizeof($aContext['campaign']['include']) && !isset($aContext['campaign']['include'][$aAd['placement_id']])) {
        OX_Delivery_logMessage('List of included campaigns does not contain bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($richMedia == false && $aAd['alt_filename'] == '' && !($aAd['contenttype'] == 'jpeg' || $aAd['contenttype'] == 'gif' || $aAd['contenttype'] == 'png') && !($aAd['type'] == 'url' && $aAd['contenttype'] == '')) {
        OX_Delivery_logMessage('No alt image specified for richmedia bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (MAX_limitationsIsAdForbidden($aAd)) {
        OX_Delivery_logMessage('MAX_limitationsIsAdForbidden = true for bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($GLOBALS['_MAX']['SSL_REQUEST'] && $aAd['type'] == 'html' && $aAd['html_ssl_unsafe']) {
        OX_Delivery_logMessage('"http:" on SSL found for html bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($GLOBALS['_MAX']['SSL_REQUEST'] && $aAd['type'] == 'url' && $aAd['url_ssl_unsafe']) {
        OX_Delivery_logMessage('"http:" on SSL found in imagurl for url bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($conf['delivery']['acls'] && !MAX_limitationsCheckAcl($aAd, $source)) {
        OX_Delivery_logMessage('MAX_limitationsCheckAcl = false for bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    return true;
}
Exemplo n.º 4
0
/**
 * This function checks if the specified tracker connects back to a valid action
 *
 * @param integer $trackerid The ID of the tracker to look up in the database
 * @return mixed If action occurred: array indexed on [#s since action] => array('type' => <connection type>, 'id' => <creative ID>
 *               else false
 */
function MAX_trackerCheckForValidAction($trackerid)
{
    // Get all creatives that are linked to this tracker
    $aTrackerLinkedAds = MAX_cacheGetTrackerLinkedCreatives($trackerid);
    // This tracker is not linked to any creatives
    if (empty($aTrackerLinkedAds)) {
        return false;
    }
    // Note: Constants are not included n the delivery engine, the values below map to the values defined in constants.php
    $aPossibleActions = _getActionTypes();
    $now = MAX_commonGetTimeNow();
    $aConf = $GLOBALS['_MAX']['CONF'];
    $aMatchingActions = array();
    // Iterate over all creatives linked to this tracker...
    foreach ($aTrackerLinkedAds as $creativeId => $aLinkedInfo) {
        // Iterate over all possible actions (currently only "view" and "click")
        foreach ($aPossibleActions as $actionId => $action) {
            // If there is both a connection window set, and this creative has been actioned
            if (!empty($aLinkedInfo[$action . '_window']) && !empty($_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId])) {
                // Check for any custom data which a plugin may have stored in the cookie
                if (stristr($_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId], ' ')) {
                    list($value, $extra) = explode(' ', $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId], 2);
                    $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId] = $value;
                } else {
                    $extra = '';
                }
                list($lastAction, $zoneId) = explode('-', $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId]);
                // Decode the base32 timestamp
                $lastAction = MAX_commonUnCompressInt($lastAction);
                // Calculate how long ago this action occurred
                $lastSeenSecondsAgo = $now - $lastAction;
                // If the action occurred within the window (and sanity check that it's > 0), record this as a matching action
                if ($lastSeenSecondsAgo <= $aLinkedInfo[$action . '_window'] && $lastSeenSecondsAgo > 0) {
                    // Index the matching array against the # seconds ago that the action occurred
                    $aMatchingActions[$lastSeenSecondsAgo] = array('action_type' => $actionId, 'tracker_type' => $aLinkedInfo['tracker_type'], 'status' => $aLinkedInfo['status'], 'cid' => $creativeId, 'zid' => $zoneId, 'dt' => $lastAction, 'window' => $aLinkedInfo[$action . '_window'], 'extra' => $extra);
                }
            }
        }
    }
    // If no actions matched, return false
    if (empty($aMatchingActions)) {
        return false;
    }
    // Sort by ascending #seconds since action
    ksort($aMatchingActions);
    // Return the first matching action
    return array_shift($aMatchingActions);
}
Exemplo n.º 5
0
/**
 * This function check if the click logging for an add is blocked
 * when the block logging is active
 *
 * @param integer $adId              The add's id of the add that the function checks
 *                                   if is blocked for click logging
 * @param array $aBlockLoggingClick  And array with the timestamps of the last click logged
 *                                   for every add that has been clicked
 * @return boolean                   Returns true when the click block logging window for
 *                                   and add hasn't expired yet
 */
function MAX_Delivery_log_isClickBlocked($adId, $aBlockLoggingClick)
{
    if (isset($GLOBALS['conf']['logging']['blockAdClicksWindow']) && $GLOBALS['conf']['logging']['blockAdClicksWindow'] != 0) {
        if (isset($aBlockLoggingClick[$adId])) {
            $endBlock = MAX_commonUnCompressInt($aBlockLoggingClick[$adId]) + $GLOBALS['conf']['logging']['blockAdClicksWindow'];
            if ($endBlock >= MAX_commonGetTimeNow()) {
                ###START_STRIP_DELIVERY
                OA::debug('adID ' . $adId . ' click is still blocked by block logging window ');
                ###END_STRIP_DELIVERY
                return true;
            }
        }
    }
    return false;
}
Exemplo n.º 6
0
/**
 * Check if maintenance should run using cached information
 *
 * This function gets maintenance's last run info
 *
 * @param boolean $cached   Should a cache lookup be performed?
 * @return array            The array of tracker properties
 */
function MAX_cacheCheckIfMaintenanceShouldRun($cached = true)
{
    // Default delay is 5 minutes
    $interval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] * 60;
    $delay = intval($GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] / 12 * 60);
    $now = MAX_commonGetTimeNow();
    $today = strtotime(date('Y-m-d'), $now);
    $nextRunTime = $today + (floor(($now - $today) / $interval) + 1) * $interval + $delay;
    // Adding the delay could shift the time to the next operation interval,
    // make sure to fix it in case it happens
    if ($nextRunTime - $now > $interval) {
        $nextRunTime -= $interval;
    }
    $cName = OA_Delivery_Cache_getName(__FUNCTION__);
    if (!$cached || ($lastRunTime = OA_Delivery_Cache_fetch($cName)) === false) {
        MAX_Dal_Delivery_Include();
        $lastRunTime = OA_Dal_Delivery_getMaintenanceInfo();
        // Cache until the next operation interval if scheduled maintenance was run
        // during the delay
        if ($lastRunTime >= $nextRunTime - $delay) {
            $nextRunTime += $interval;
        }
        OA_Delivery_Cache_store($cName, $lastRunTime, false, $nextRunTime);
    }
    return $lastRunTime < $nextRunTime - $interval;
}
Exemplo n.º 7
0
/**
 * A "private" function to test to see if a capping limitation for an ad or zone item needs
 * to be enforced.
 *
 * @access private
 * @param string $type The capping limitation type - one of "Ad", "Campaign" or "Zone".
 * @param integer $id The ID of the ad, campaign or zone to check.
 * @param integer $cap The total number of times an ad or an ad from a zone is to be shown
 *                     to a viewer.
 * @param integer $sessionCap Optional total number of times an ad or an ad from a zone is
 *                            to be shown to a viewer in a session.
 * @param integer $block The time period to use for capping tests (seconds)
 * @param boolean $showCappedNoCookie true if we should show the ad even if there is no cookie.
 * @return boolean True if the ad or zone is capped, false otherwise.
 */
function _limitationsIsCapped($type, $id, $cap, $sessionCap, $block, $showCappedNoCookie)
{
    // Always return true (capped) if cookies have been disabled by the viewer
    // Return true if ( (capping has be set) && (do not show capped ads to users without cookies) )
    if (_areCookiesDisabled(($cap > 0 || $sessionCap > 0 || $block > 0) && !$showCappedNoCookie)) {
        return true;
    }
    // Get the capping cookie name from the configuration file
    $conf = $GLOBALS['_MAX']['CONF'];
    $cookieName = $conf['var']['cap' . $type];
    // How many times (total) has the item been by the viewer?
    if (isset($_COOKIE[$cookieName][$id])) {
        $totalImpressions = $_COOKIE[$cookieName][$id];
    }
    // Get the session capping cookie name from the configuration file
    $cookieName = $conf['var']['sessionCap' . $type];
    // How many times (session) has the item been by the viewer?
    if (isset($_COOKIE[$cookieName][$id])) {
        $sessionImpressions = $_COOKIE[$cookieName][$id];
    }
    // When was the ad last seen
    $cookieName = $conf['var']['block' . $type];
    if (isset($_COOKIE[$cookieName][$id])) {
        $lastSeen = $_COOKIE[$cookieName][$id];
    }
    // If the ad has been seen the requisite number of times...
    if ($cap > 0 && isset($totalImpressions) && $totalImpressions >= $cap || $sessionCap > 0 && isset($sessionImpressions) && $sessionImpressions >= $sessionCap) {
        if ($block > 0 && MAX_commonGetTimeNow() > $lastSeen + $block) {
            // This ad was last seen outside the block window, so it can now be seen again
            // The log mechanism will deal with resetting the frequency counter
            return false;
        } else {
            return true;
        }
    } else {
        if ($block > 0 && ($cap == 0 && $sessionCap == 0) && MAX_commonGetTimeNow() <= $lastSeen + $block) {
            return true;
        } else {
            return false;
        }
    }
}
Exemplo n.º 8
0
/**
 * A function to set any capping cookies (ie. block, cap or sessionCap) that are required
 * for an ad, a campaign or a zone.
 *
 * @param string $type The type of capping to set, one of "Ad", "Campaign" or "Zone".
 * @param integer $id The ID of the ad, campaign or zone that the capping cookies are for.
 * @param integer $block The number of seconds to block the ad, campaign or zone.
 * @param integer $cap The total number of times a viewer can see an ad, an ad from the
 *                     campaign, or an ad in a zone.
 * @param integer $sessionCap The number of times per session that a viewer can see an
 *                            ad, an ad from the campaign, or an ad in a zone.
 */
function MAX_Delivery_cookie_setCapping($type, $id, $block = 0, $cap = 0, $sessionCap = 0)
{
    $conf = $GLOBALS['_MAX']['CONF'];
    $setBlock = false;
    if ($cap > 0) {
        // This capping cookie requires a "permanent" expiration time
        $expire = MAX_commonGetTimeNow() + $conf['cookie']['permCookieSeconds'];
        // The unpack capping cookies function adds this value to the counter, so to reset it we add a negative number
        if (!isset($_COOKIE[$conf['var']['cap' . $type]][$id])) {
            $value = 1;
            $setBlock = true;
        } else {
            if ($_COOKIE[$conf['var']['cap' . $type]][$id] >= $cap) {
                $value = -$_COOKIE[$conf['var']['cap' . $type]][$id] + 1;
                // Also reset the last-seen when resetting the frequency counter
                $setBlock = true;
            } else {
                $value = 1;
            }
        }
        MAX_cookieAdd("_{$conf['var']['cap' . $type]}[{$id}]", $value, $expire);
    }
    if ($sessionCap > 0) {
        // The unpack capping cookies function deals with imcrementing the counter
        // The expiry is set to 0 to make a session cookie
        // The unpack capping cookies function adds this value to the counter, so to reset it we add a negative number
        if (!isset($_COOKIE[$conf['var']['sessionCap' . $type]][$id])) {
            $value = 1;
            $setBlock = true;
        } else {
            if ($_COOKIE[$conf['var']['sessionCap' . $type]][$id] >= $sessionCap) {
                $value = -$_COOKIE[$conf['var']['sessionCap' . $type]][$id] + 1;
                // Also reset the last-seen when resetting the frequency counter
                $setBlock = true;
            } else {
                $value = 1;
            }
        }
        MAX_cookieAdd("_{$conf['var']['sessionCap' . $type]}[{$id}]", $value, 0);
    }
    if ($block > 0 || $setBlock) {
        // This blocking cookie is limited to 30 days
        // Store a cookie using the current time so that the system knows when
        // the last time this viewer saw this ad, an ad in this campaign or an
        // ad in this zone
        MAX_cookieAdd("_{$conf['var']['block' . $type]}[{$id}]", MAX_commonGetTimeNow(), _getTimeThirtyDaysFromNow());
    }
}
 /**
  * Method tests invalidateSystemSettingsCache method
  */
 function test_invalidateSystemSettingsCache()
 {
     $interval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] * 60;
     $delay = intval($GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] / 12 * 60);
     // store orginal settings
     $currentClick = $GLOBALS['_MAX']['CONF']['file']['click'];
     // Set maintenace timestamp to 48h ago
     $doAppVar = OA_Dal::factoryDO('application_variable');
     $doAppVar->name = 'maintenance_timestamp';
     $doAppVar->value = MAX_commonGetTimeNow() - 2 * $interval;
     $doAppVar->insert();
     // Remember current cache
     $cachedJSData = MAX_cacheGetGoogleJavaScript();
     $cachedTZData = MAX_cacheGetAccountTZs();
     $cachedMaintenanceData = MAX_cacheCheckIfMaintenanceShouldRun();
     // Change JS settings, Time Zone, and time of Last Run of maintenace
     $GLOBALS['_MAX']['CONF']['file']['click'] = 'click.php';
     $doAppVar->name = 'maintenance_timestamp';
     $doAppVar->value = MAX_commonGetTimeNow() + $delay + 1;
     $doAppVar->update();
     // Add Admin user and set time zone in his preferences
     $doAccount = OA_Dal::factoryDO('accounts');
     $doAccount->account_type = 'ADMIN';
     $accountId = DataGenerator::generateOne($doAccount);
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->preference_name = 'timezone';
     $doPreferences->value = 'new value';
     $doPreferences->account_type = 'ADMIN';
     $preferencesId = DataGenerator::generateOne($doPreferences);
     $doAccountPreferenceAssoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccountPreferenceAssoc->account_id = $accountId;
     $doAccountPreferenceAssoc->preference_id = $preferencesId;
     $doAccountPreferenceAssoc->value = 'new value';
     DataGenerator::generateOne($doAccountPreferenceAssoc);
     // Expect no changes in cache files
     $this->assertEqual(MAX_cacheGetGoogleJavaScript(), $cachedJSData);
     $this->assertEqual(MAX_cacheGetAccountTZs(), $cachedTZData);
     $this->assertEqual(MAX_cacheCheckIfMaintenanceShouldRun(), $cachedMaintenanceData);
     $this->oDeliveryCacheManager->invalidateSystemSettingsCache();
     // Now expect changes in cache files
     $this->assertNotEqual(MAX_cacheGetGoogleJavaScript(), $cachedJSData);
     $this->assertNotEqual(MAX_cacheGetAccountTZs(), $cachedTZData);
     $this->assertNotEqual(MAX_cacheCheckIfMaintenanceShouldRun(), $cachedMaintenanceData);
     // restore orginal settings
     $GLOBALS['_MAX']['CONF']['file']['click'] = $currentClick;
 }
Exemplo n.º 10
0
 /**
  * A method to test the MAX_Delivery_log_isClickBlocked() function.
  *
  * Requirements:
  * Test 1: Test with a 0 seconds click block looging window (block logging no active)
  *         and ensure that false is returned.
  * Test 2: Test with a click block looging window bigger than 0 seconds and an add
  *         not clicked yet, and ensure that false is returned.
  * Test 3: Test with a click block looging window bigger than 0 seconds and an add
  *         clicked that still in the click block logging window, and ensure that
  *         true is returned.
  * Test 4: Test with a click block looging window bigger than 0 seconds and an add
  *         clicked the same time ago that the click block logging window's lenght,
  *         and ensure that true is returned.
  * Test 5: Test with a click block looging window bigger than 0 seconds and an add
  *         clicked with the click block logging window expired, and ensure that
  *         false is returned.
  */
 function test_MAX_Delivery_log_isClickBlocked()
 {
     $timeNow = MAX_commonGetTimeNow();
     $add1ClickTime = MAX_commonCompressInt($timeNow - 60);
     $add3ClickTime = MAX_commonCompressInt($timeNow - 30);
     $add9ClickTime = MAX_commonCompressInt($timeNow - 15);
     $aBlockLoggingClick = array(1 => $add1ClickTime, 3 => $add3ClickTime, 9 => $add9ClickTime);
     // Test 1
     $GLOBALS['conf']['logging']['blockAdClicksWindow'] = 0;
     $aReturn = MAX_Delivery_log_isClickBlocked(1, $aBlockLoggingClick);
     $this->assertTrue(!$aReturn);
     // Test 2
     $GLOBALS['conf']['logging']['blockAdClicksWindow'] = 30;
     $aReturn = MAX_Delivery_log_isClickBlocked(2, $aBlockLoggingClick);
     $this->assertTrue(!$aReturn);
     // Test 3
     $GLOBALS['conf']['logging']['blockAdClicksWindow'] = 30;
     $aReturn = MAX_Delivery_log_isClickBlocked(9, $aBlockLoggingClick);
     $this->assertTrue($aReturn);
     // Test 4
     $GLOBALS['conf']['logging']['blockAdClicksWindow'] = 30;
     $aReturn = MAX_Delivery_log_isClickBlocked(3, $aBlockLoggingClick);
     $this->assertTrue($aReturn);
     // Test 5
     $GLOBALS['conf']['logging']['blockAdClicksWindow'] = 30;
     $aReturn = MAX_Delivery_log_isClickBlocked(1, $aBlockLoggingClick);
     $this->assertTrue(!$aReturn);
 }
Exemplo n.º 11
0
/**
 * Enter description here...
 *
 * @param unknown_type $aAd
 * @param unknown_type $context
 * @param unknown_type $source
 * @param unknown_type $richMedia
 */
function _adSelectCheckCriteria($aAd, $aContext, $source, $richMedia)
{
    $conf = $GLOBALS['_MAX']['CONF'];
    // Enforce campaign expirations
    if (!empty($aAd['expire_time'])) {
        $expire = strtotime($aAd['expire_time']);
        $now = MAX_commonGetTimeNow();
        if ($expire > 0 && $now > $expire) {
            OX_Delivery_logMessage('Campaign has expired for bannerid ' . $aAd['ad_id'], 7);
            return false;
        }
    }
    // Excludelist banners
    if (isset($aContext['banner']['exclude'][$aAd['ad_id']])) {
        OX_Delivery_logMessage('List of excluded banners list contains bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (isset($aContext['campaign']['exclude'][$aAd['placement_id']])) {
        // Excludelist campaigns
        OX_Delivery_logMessage('List of excluded campaigns contains bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (isset($aContext['client']['exclude'][$aAd['client_id']])) {
        // Excludelist clients
        OX_Delivery_logMessage('List of excluded clients contains bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (sizeof($aContext['banner']['include']) && !isset($aContext['banner']['include'][$aAd['ad_id']])) {
        // Includelist banners
        OX_Delivery_logMessage('List of included banners does not contain bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (sizeof($aContext['campaign']['include']) && !isset($aContext['campaign']['include'][$aAd['placement_id']])) {
        // Includelist campaigns
        OX_Delivery_logMessage('List of included campaigns does not contain bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($richMedia == false && $aAd['alt_filename'] == '' && !($aAd['contenttype'] == 'jpeg' || $aAd['contenttype'] == 'gif' || $aAd['contenttype'] == 'png') && !($aAd['type'] == 'url' && $aAd['contenttype'] == '')) {
        OX_Delivery_logMessage('No alt image specified for richmedia bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if (MAX_limitationsIsAdForbidden($aAd)) {
        // Capping & blocking
        OX_Delivery_logMessage('MAX_limitationsIsAdForbidden = true for bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($GLOBALS['_MAX']['SSL_REQUEST'] && $aAd['type'] == 'html' && $aAd['html_ssl_unsafe']) {
        // HTML Banners that contain 'http:' on SSL
        OX_Delivery_logMessage('"http:" on SSL found for html bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($GLOBALS['_MAX']['SSL_REQUEST'] && $aAd['type'] == 'url' && $aAd['url_ssl_unsafe']) {
        // It only matters if the initial call is to non-SSL (it can/could contain http:)
        OX_Delivery_logMessage('"http:" on SSL found in imagurl for url bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    if ($conf['delivery']['acls'] && !MAX_limitationsCheckAcl($aAd, $source)) {
        // Delivery limitations
        OX_Delivery_logMessage('MAX_limitationsCheckAcl = false for bannerid ' . $aAd['ad_id'], 7);
        return false;
    }
    // If any of the above failed, this function will have already returned false
    // So to get this far means that the ad was valid
    return true;
}
Exemplo n.º 12
0
/**
 * This function check if the click logging for an add is blocked
 * when the block logging is active
 *
 * @param integer $adId              The add's id of the add that the function checks
 *                                   if is blocked for click logging
 * @param array $aBlockLoggingClick  And array with the timestamps of the last click logged
 *                                   for every add that has been clicked
 * @return boolean                   Returns true when the click block logging window for
 *                                   and add hasn't expired yet
 */
function MAX_Delivery_log_isClickBlocked($adId, $aBlockLoggingClick)
{
    if (isset($GLOBALS['conf']['logging']['blockAdClicksWindow']) && $GLOBALS['conf']['logging']['blockAdClicksWindow'] != 0) {
        if (isset($aBlockLoggingClick[$adId])) {
            $endBlock = MAX_commonUnCompressInt($aBlockLoggingClick[$adId]) + $GLOBALS['conf']['logging']['blockAdClicksWindow'];
            if ($endBlock >= MAX_commonGetTimeNow()) {
                OX_Delivery_logMessage('adID ' . $adId . ' click is still blocked by block logging window ', 7);
                return true;
            }
        }
    }
    return false;
}
 function _testIsThingCapped($thing)
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $now = MAX_commonGetTimeNow();
     switch ($thing) {
         case 'Ad':
             $functionName = '_limitationsIsAdCapped';
             $capCookieName = $conf['var']['capAd'];
             $sessionCapCookieName = $conf['var']['sessionCapAd'];
             $blockCookieName = $conf['var']['blockAd'];
             break;
         case 'Campaign':
             $functionName = '_limitationsIsCampaignCapped';
             $capCookieName = $conf['var']['capCampaign'];
             $sessionCapCookieName = $conf['var']['sessionCapCampaign'];
             $blockCookieName = $conf['var']['blockCampaign'];
             break;
         case 'Zone':
             $functionName = '_limitationsIsZoneCapped';
             $capCookieName = $conf['var']['capZone'];
             $sessionCapCookieName = $conf['var']['sessionCapZone'];
             $blockCookieName = $conf['var']['blockZone'];
     }
     // Test 1: No capping
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 0;
     $sessionCap = 0;
     $block = 0;
     $showCappedNoCookie = 0;
     unset($_COOKIE[$capCookieName][$id]);
     unset($_COOKIE[$sessionCapCookieName][$id]);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 2: Cap of 3, not seen yet
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 3;
     $sessionCap = 0;
     $block = 0;
     $showCappedNoCookie = 0;
     unset($_COOKIE[$capCookieName][$id]);
     unset($_COOKIE[$sessionCapCookieName][$id]);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 3: Cap of 3, seen two times
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 3;
     $sessionCap = 0;
     $block = 0;
     $showCappedNoCookie = 0;
     $_COOKIE[$capCookieName][$id] = 2;
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 4: Cap of 3, seen three times
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 3;
     $sessionCap = 0;
     $block = 0;
     $showCappedNoCookie = 0;
     $_COOKIE[$capCookieName][$id] = 3;
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertTrue($return);
     // Test 5: Cap of 3, seen four times
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 3;
     $sessionCap = 0;
     $block = 0;
     $showCappedNoCookie = 0;
     $_COOKIE[$capCookieName][$id] = 4;
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertTrue($return);
     // Test 6: Session cap of 3, not seen yet
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 0;
     $sessionCap = 3;
     $block = 0;
     $showCappedNoCookie = 0;
     unset($_COOKIE[$capCookieName][$id]);
     unset($_COOKIE[$sessionCapCookieName][$id]);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 7: Session cap of 3, seen two times
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 0;
     $sessionCap = 3;
     $block = 0;
     $showCappedNoCookie = 0;
     $_COOKIE[$sessionCapCookieName][$id] = 2;
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 8: Session cap of 3, seen three times
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 0;
     $sessionCap = 3;
     $block = 0;
     $showCappedNoCookie = 0;
     $_COOKIE[$sessionCapCookieName][$id] = 3;
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertTrue($return);
     // Test 9: Session cap of 3, seen four times
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $id = 123;
     $cap = 0;
     $sessionCap = 3;
     $block = 0;
     $showCappedNoCookie = 0;
     $_COOKIE[$sessionCapCookieName][$id] = 4;
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertTrue($return);
     // Test 10: First impression (cap = 2, block = 60s)
     $id = 123;
     $cap = 0;
     $sessionCap = 2;
     $block = 60;
     $showCappedNoCookie = 0;
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     unset($_COOKIE[$sessionCapCookieName][$id]);
     unset($_COOKIE[$blockCookieName][$id]);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 11: Second impression (cap = 2, block 60s)
     $id = 123;
     $cap = 0;
     $sessionCap = 2;
     $block = 60;
     $showCappedNoCookie = 0;
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $_COOKIE[$sessionCapCookieName][$id] = 1;
     $_COOKIE[$blockCookieName][$id] = $now - ($block - 1);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 12: Third impression within block (cap = 2, block 60s)
     $id = 123;
     $cap = 0;
     $sessionCap = 2;
     $block = 60;
     $showCappedNoCookie = 0;
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $_COOKIE[$sessionCapCookieName][$id] = 2;
     $_COOKIE[$blockCookieName][$id] = $now - ($block - 1);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertTrue($return);
     // Test 13: Third impression outside block (cap = 2, block = 60s)
     $id = 123;
     $cap = 0;
     $sessionCap = 2;
     $block = 60;
     $showCappedNoCookie = 0;
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = false;
     $_COOKIE[$sessionCapCookieName][$id] = 2;
     $_COOKIE[$blockCookieName][$id] = $now - ($block + 1);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertFalse($return);
     // Test 10: newViewerId cookie set
     $id = 123;
     $cap = 3;
     $sessionCap = 0;
     $block = 0;
     $showCappedNoCookie = 0;
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = true;
     unset($_COOKIE[$capCookieName][$id]);
     unset($_COOKIE[$sessionCapCookieName][$id]);
     $return = $functionName($id, $cap, $sessionCap, $block, $showCappedNoCookie);
     $this->assertTrue($return);
 }
<?php

/*
+---------------------------------------------------------------------------+
| Revive Adserver                                                           |
| http://www.revive-adserver.com                                            |
|                                                                           |
| Copyright: See the COPYRIGHT.txt file.                                    |
| License: GPLv2 or later, see the LICENSE.txt file.                        |
+---------------------------------------------------------------------------+
*/
/*
 * NOTE: If this list of event ever changes (IDs or names), the Video Reports must be updated as well
 */
$aVastEventStrToIdMap = array('start' => 1, 'midpoint' => 2, 'firstquartile' => 3, 'thirdquartile' => 4, 'complete' => 5, 'mute' => 6, 'replay' => 7, 'fullscreen' => 8, 'stop' => 9, 'unmute' => 10, 'resume' => 11, 'pause' => 12);
MAX_commonRegisterGlobalsArray(array('event', 'video_time_posn'));
// Prevent the logging beacon from being cached by browsers
MAX_commonSetNoCacheHeaders();
// if its a vast tracking event
if (!empty($bannerid) && isset($aVastEventStrToIdMap[$event])) {
    // Remove any special characters from the request variables
    MAX_commonRemoveSpecialChars($_REQUEST);
    $time = MAX_commonGetTimeNow();
    $oi = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'];
    $GLOBALS['_MAX']['deliveryData'] = array('interval_start' => gmdate('Y-m-d H:i:s', $time - $time % ($oi * 60)), 'creative_id' => (int) $bannerid, 'zone_id' => (int) $zoneid, 'vast_event_id' => $aVastEventStrToIdMap[$event]);
    OX_Delivery_Common_hook('logImpressionVast', array($bannerid, $zoneid, _viewersHostOkayToLog()));
}
MAX_cookieFlush();
MAX_commonDisplay1x1();
 /**
  * Method tests invalidateCheckIfMaintenanceShouldRunCache method
  */
 function test_invalidateCheckIfMaintenanceShouldRunCache()
 {
     $interval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] * 60;
     $delay = intval($GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] / 12 * 60);
     // Set value for maintenace_timestamp that maintenace should run now
     $doAppVar = OA_Dal::factoryDO('application_variable');
     $doAppVar->name = 'maintenance_timestamp';
     $doAppVar->value = MAX_commonGetTimeNow() - 2 * $interval;
     $doAppVar->insert();
     $cachedData = MAX_cacheCheckIfMaintenanceShouldRun();
     // Set value for maintenace_timestamp that maintenace shouldn't be run
     $doAppVar = OA_Dal::factoryDO('application_variable');
     $doAppVar->name = 'maintenance_timestamp';
     $doAppVar->value = MAX_commonGetTimeNow() + $delay + 1;
     $doAppVar->update();
     // Expect no changes in cache
     $this->assertEqual(MAX_cacheCheckIfMaintenanceShouldRun(), $cachedData);
     $this->oDeliveryCacheCommon->invalidateCheckIfMaintenanceShouldRunCache();
     // Now expect changes in cache
     $this->assertNotEqual(MAX_cacheCheckIfMaintenanceShouldRun(), $cachedData);
 }
Exemplo n.º 16
0
<?php

/*
+---------------------------------------------------------------------------+
| Revive Adserver                                                           |
| http://www.revive-adserver.com                                            |
|                                                                           |
| Copyright: See the COPYRIGHT.txt file.                                    |
| License: GPLv2 or later, see the LICENSE.txt file.                        |
+---------------------------------------------------------------------------+
*/
// Require the initialisation file
require_once '../../init-delivery.php';
$etag = md5("{$conf['webpath']['delivery']}*{$conf['webpath']['deliverySSL']}");
$product = $GLOBALS['_MAX']['CONF']['var']['product'];
if (!empty($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] == $etag) {
    header("HTTP/1.x 304 Not modified");
    exit;
}
header("Content-Type: text/javascript");
header("ETag: {$etag}");
// The browser is allowed to cache this
if (!empty($conf['delivery']['assetClientCacheExpire'])) {
    $expire = (int) $conf['delivery']['assetClientCacheExpire'];
    header("Expire: " . gmdate('D, d M Y H:i:s \\G\\M\\T', MAX_commonGetTimeNow() + $expire));
    header("Cache-Control: private, max-age={$expire}");
}
// Try to set the OAID cookie, so that the following request already has it
MAX_cookieGetUniqueViewerId();
require __DIR__ . '/' . $GLOBALS['_MAX']['CONF']['file']['asyncjsjs'];
require __DIR__ . '/' . $GLOBALS['_MAX']['CONF']['file']['flash'];