Пример #1
0
function _limitationsIsCapped($type, $id, $cap, $sessionCap, $block, $showCappedNoCookie)
{
    if (_areCookiesDisabled(($cap > 0 || $sessionCap > 0 || $block > 0) && !$showCappedNoCookie)) {
        return true;
    }
    $conf = $GLOBALS['_MAX']['CONF'];
    $cookieName = $conf['var']['cap' . $type];
    if (isset($_COOKIE[$cookieName][$id])) {
        $totalImpressions = $_COOKIE[$cookieName][$id];
    }
    $cookieName = $conf['var']['sessionCap' . $type];
    if (isset($_COOKIE[$cookieName][$id])) {
        $sessionImpressions = $_COOKIE[$cookieName][$id];
    }
    $cookieName = $conf['var']['block' . $type];
    if (isset($_COOKIE[$cookieName][$id])) {
        $lastSeen = $_COOKIE[$cookieName][$id];
    }
    if ($cap > 0 && isset($totalImpressions) && $totalImpressions >= $cap || $sessionCap > 0 && isset($sessionImpressions) && $sessionImpressions >= $sessionCap) {
        if ($block > 0 && MAX_commonGetTimeNow() > $lastSeen + $block) {
            return false;
        } else {
            return true;
        }
    } else {
        if ($block > 0 && ($cap == 0 && $sessionCap == 0) && MAX_commonGetTimeNow() <= $lastSeen + $block) {
            return true;
        } else {
            return false;
        }
    }
}
Пример #2
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;
        }
    }
}