/www/delivery/ck.php
PHP | 3277 lines | 3224 code | 30 blank | 23 comment | 560 complexity | 5d81693d63e8c4f0ca566526653d46d1 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, AGPL-1.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- +---------------------------------------------------------------------------+
- | Revive Adserver |
- | http://www.revive-adserver.com |
- | |
- | Copyright: See the COPYRIGHT.txt file. |
- | License: GPLv2 or later, see the LICENSE.txt file. |
- +---------------------------------------------------------------------------+
- */
- /**
- * This is autogenerated file which contains all files from the "delivery_dev"
- * folder of Revive Adserver merged into a single output file. On systems
- * without a PHP opcode cache that is configured to not regularly check for
- * file updates, this autogenerated file can dramatically improve the
- * performance of Revive Adserver's delivery engine.
- *
- * !!!Warning!!!
- *
- * Do not edit this file. If you need to do any changes to any delivery file,
- * check out the source code from GitHub; make the necessary changes to the
- * file(s) in the "delivery_dev" folder; and regenerate the delivery files
- * using the script located in the "scripts/delivery" directory.
- */
- function parseDeliveryIniFile($configPath = null, $configFile = null, $sections = true)
- {
- if (!$configPath) {
- $configPath = MAX_PATH . '/var';
- }
- if ($configFile) {
- $configFile = '.' . $configFile;
- }
- $host = OX_getHostName();
- $configFileName = $configPath . '/' . $host . $configFile . '.conf.php';
- $conf = @parse_ini_file($configFileName, $sections);
- if (isset($conf['realConfig'])) {
- $realconf = @parse_ini_file(MAX_PATH . '/var/' . $conf['realConfig'] . '.conf.php', $sections);
- $conf = mergeConfigFiles($realconf, $conf);
- }
- if (!empty($conf)) {
- return $conf;
- } elseif ($configFile === '.plugin') {
- $pluginType = basename($configPath);
- $defaultConfig = MAX_PATH . '/plugins/' . $pluginType . '/default.plugin.conf.php';
- $conf = @parse_ini_file($defaultConfig, $sections);
- if ($conf !== false) {
- return $conf;
- }
- echo "Revive Adserver could not read the default configuration file for the {$pluginType} plugin";
- exit(1);
- }
- $configFileName = $configPath . '/default' . $configFile . '.conf.php';
- $conf = @parse_ini_file($configFileName, $sections);
- if (isset($conf['realConfig'])) {
- $conf = @parse_ini_file(MAX_PATH . '/var/' . $conf['realConfig'] . '.conf.php', $sections);
- }
- if (!empty($conf)) {
- return $conf;
- }
- if (file_exists(MAX_PATH . '/var/INSTALLED')) {
- echo "Revive Adserver has been installed, but no configuration file was found.\n";
- exit(1);
- }
- echo "Revive Adserver has not been installed yet -- please read the INSTALL.txt file.\n";
- exit(1);
- }
- if (!function_exists('mergeConfigFiles'))
- {
- function mergeConfigFiles($realConfig, $fakeConfig)
- {
- foreach ($fakeConfig as $key => $value) {
- if (is_array($value)) {
- if (!isset($realConfig[$key])) {
- $realConfig[$key] = array();
- }
- $realConfig[$key] = mergeConfigFiles($realConfig[$key], $value);
- } else {
- if (isset($realConfig[$key]) && is_array($realConfig[$key])) {
- $realConfig[$key][0] = $value;
- } else {
- if (isset($realConfig) && !is_array($realConfig)) {
- $temp = $realConfig;
- $realConfig = array();
- $realConfig[0] = $temp;
- }
- $realConfig[$key] = $value;
- }
- }
- }
- unset($realConfig['realConfig']);
- return $realConfig;
- }
- }
- function OX_getMinimumRequiredMemory($limit = null)
- {
- if ($limit == 'maintenance') {
- return 134217728; }
- return 134217728; }
- function OX_getMemoryLimitSizeInBytes() {
- $phpMemoryLimit = ini_get('memory_limit');
- if (empty($phpMemoryLimit) || $phpMemoryLimit == -1) {
- return -1;
- }
- $aSize = array(
- 'G' => 1073741824,
- 'M' => 1048576,
- 'K' => 1024
- );
- $phpMemoryLimitInBytes = $phpMemoryLimit;
- foreach($aSize as $type => $multiplier) {
- $pos = strpos($phpMemoryLimit, $type);
- if (!$pos) {
- $pos = strpos($phpMemoryLimit, strtolower($type));
- }
- if ($pos) {
- $phpMemoryLimitInBytes = substr($phpMemoryLimit, 0, $pos) * $multiplier;
- }
- }
- return $phpMemoryLimitInBytes;
- }
- function OX_checkMemoryCanBeSet()
- {
- $phpMemoryLimitInBytes = OX_getMemoryLimitSizeInBytes();
- if ($phpMemoryLimitInBytes == -1) {
- return true;
- }
- OX_increaseMemoryLimit($phpMemoryLimitInBytes + 1);
- $newPhpMemoryLimitInBytes = OX_getMemoryLimitSizeInBytes();
- $memoryCanBeSet = ($phpMemoryLimitInBytes != $newPhpMemoryLimitInBytes);
- @ini_set('memory_limit', $phpMemoryLimitInBytes);
- return $memoryCanBeSet;
- }
- function OX_increaseMemoryLimit($setMemory) {
- $phpMemoryLimitInBytes = OX_getMemoryLimitSizeInBytes();
- if ($phpMemoryLimitInBytes == -1) {
- return true;
- }
- if ($setMemory > $phpMemoryLimitInBytes) {
- if (@ini_set('memory_limit', $setMemory) === false) {
- return false;
- }
- }
- return true;
- }
- function setupConfigVariables()
- {
- $GLOBALS['_MAX']['MAX_DELIVERY_MULTIPLE_DELIMITER'] = '|';
- $GLOBALS['_MAX']['MAX_COOKIELESS_PREFIX'] = '__';
- $GLOBALS['_MAX']['thread_id'] = uniqid();
- $GLOBALS['_MAX']['SSL_REQUEST'] = false;
- if (
- (!empty($_SERVER['SERVER_PORT']) && !empty($GLOBALS['_MAX']['CONF']['openads']['sslPort']) && ($_SERVER['SERVER_PORT'] == $GLOBALS['_MAX']['CONF']['openads']['sslPort'])) ||
- (!empty($_SERVER['HTTPS']) && ((strtolower($_SERVER['HTTPS']) == 'on') || ($_SERVER['HTTPS'] == 1))) ||
- (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && (strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https')) ||
- (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && (strtolower($_SERVER['HTTP_X_FORWARDED_SSL']) == 'on')) ||
- (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && (strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) == 'on')) ||
- (!empty($_SERVER['FRONT-END-HTTPS']) && (strtolower($_SERVER['FRONT-END-HTTPS']) == 'on'))
- ) {
- $GLOBALS['_MAX']['SSL_REQUEST'] = true;
- }
- $GLOBALS['_MAX']['MAX_RAND'] = isset($GLOBALS['_MAX']['CONF']['priority']['randmax']) ?
- $GLOBALS['_MAX']['CONF']['priority']['randmax'] : 2147483647;
- list($micro_seconds, $seconds) = explode(" ", microtime());
- $GLOBALS['_MAX']['NOW_ms'] = round(1000 *((float)$micro_seconds + (float)$seconds));
- if (substr($_SERVER['SCRIPT_NAME'], -11) != 'install.php') {
- $GLOBALS['serverTimezone'] = date_default_timezone_get();
- OA_setTimeZoneUTC();
- }
- }
- function setupServerVariables()
- {
- if (empty($_SERVER['REQUEST_URI'])) {
- $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
- if (!empty($_SERVER['QUERY_STRING'])) {
- $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
- }
- }
- }
- function setupDeliveryConfigVariables()
- {
- if (!defined('MAX_PATH')) {
- define('MAX_PATH', dirname(__FILE__).'/../..');
- }
- if (!defined('OX_PATH')) {
- define('OX_PATH', MAX_PATH);
- }
- if (!defined('RV_PATH')) {
- define('RV_PATH', MAX_PATH);
- }
- if (!defined('LIB_PATH')) {
- define('LIB_PATH', MAX_PATH. DIRECTORY_SEPARATOR. 'lib'. DIRECTORY_SEPARATOR. 'OX');
- }
- if ( !(isset($GLOBALS['_MAX']['CONF']))) {
- $GLOBALS['_MAX']['CONF'] = parseDeliveryIniFile();
- }
- setupConfigVariables();
- }
- function OA_setTimeZone($timezone)
- {
- date_default_timezone_set($timezone);
- $GLOBALS['_DATE_TIMEZONE_DEFAULT'] = $timezone;
- }
- function OA_setTimeZoneUTC()
- {
- OA_setTimeZone('UTC');
- }
- function OA_setTimeZoneLocal()
- {
- $tz = !empty($GLOBALS['_MAX']['PREF']['timezone']) ? $GLOBALS['_MAX']['PREF']['timezone'] : 'GMT';
- OA_setTimeZone($tz);
- }
- function OX_getHostName()
- {
- if (!empty($_SERVER['HTTP_HOST'])) {
- $host = explode(':', $_SERVER['HTTP_HOST']);
- $host = $host[0];
- } else if (!empty($_SERVER['SERVER_NAME'])) {
- $host = explode(':', $_SERVER['SERVER_NAME']);
- $host = $host[0];
- }
- return $host;
- }
- function OX_getHostNameWithPort()
- {
- if (!empty($_SERVER['HTTP_HOST'])) {
- $host = $_SERVER['HTTP_HOST'];
- } else if (!empty($_SERVER['SERVER_NAME'])) {
- $host = $_SERVER['SERVER_NAME'];
- }
- return $host;
- }
- function setupIncludePath()
- {
- static $checkIfAlreadySet;
- if (isset($checkIfAlreadySet)) {
- return;
- }
- $checkIfAlreadySet = true;
- $oxPearPath = MAX_PATH . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pear';
- $oxZendPath = MAX_PATH . DIRECTORY_SEPARATOR . 'lib';
- set_include_path($oxPearPath . PATH_SEPARATOR . $oxZendPath . PATH_SEPARATOR . get_include_path());
- }
- OX_increaseMemoryLimit(OX_getMinimumRequiredMemory());
- if (!defined('E_DEPRECATED')) {
- define('E_DEPRECATED', 0);
- }
- setupServerVariables();
- setupDeliveryConfigVariables();
- $conf = $GLOBALS['_MAX']['CONF'];
- $GLOBALS['_OA']['invocationType'] = array_search(basename($_SERVER['SCRIPT_FILENAME']), $conf['file']);
- if (!empty($conf['debug']['production'])) {
- error_reporting(E_ALL & ~(E_NOTICE | E_WARNING | E_DEPRECATED | E_STRICT));
- } else {
- error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT));
- }
- $file = '/lib/max/Delivery/common.php';
- $GLOBALS['_MAX']['FILES'][$file] = true;
- $file = '/lib/max/Delivery/cookie.php';
- $GLOBALS['_MAX']['FILES'][$file] = true;
- $GLOBALS['_MAX']['COOKIE']['LIMITATIONS']['arrCappingCookieNames'] = array();
- if (!is_callable('MAX_cookieSet')) {
- if (!empty($conf['cookie']['plugin']) && is_readable(MAX_PATH . "/plugins/cookieStorage/{$conf['cookie']['plugin']}.delivery.php")) {
- include MAX_PATH . "/plugins/cookieStorage/{$conf['cookie']['plugin']}.delivery.php";
- } else {
- function MAX_cookieSet($name, $value, $expire, $path = '/', $domain = null) { return MAX_cookieClientCookieSet($name, $value, $expire, $path, $domain); }
- function MAX_cookieUnset($name) { return MAX_cookieClientCookieUnset($name); }
- function MAX_cookieFlush() { return MAX_cookieClientCookieFlush(); }
- function MAX_cookieLoad() { return true; }
- }
- }
- function MAX_cookieAdd($name, $value, $expire = 0)
- {
- if (!isset($GLOBALS['_MAX']['COOKIE']['CACHE'])) {
- $GLOBALS['_MAX']['COOKIE']['CACHE'] = array();
- }
- $GLOBALS['_MAX']['COOKIE']['CACHE'][$name] = array($value, $expire);
- }
- function MAX_cookieSetViewerIdAndRedirect($viewerId) {
- $aConf = $GLOBALS['_MAX']['CONF'];
- MAX_cookieAdd($aConf['var']['viewerId'], $viewerId, _getTimeYearFromNow());
- MAX_cookieFlush();
- if ($GLOBALS['_MAX']['SSL_REQUEST']) {
- $url = MAX_commonConstructSecureDeliveryUrl(basename($_SERVER['SCRIPT_NAME']));
- } else {
- $url = MAX_commonConstructDeliveryUrl(basename($_SERVER['SCRIPT_NAME']));
- }
- $url .= "?{$aConf['var']['cookieTest']}=1&" . $_SERVER['QUERY_STRING'];
- MAX_header("Location: {$url}");
- exit;
- }
- function _getTimeThirtyDaysFromNow()
- {
- return MAX_commonGetTimeNow() + 2592000; }
- function _getTimeYearFromNow()
- {
- return MAX_commonGetTimeNow() + 31536000; }
- function _getTimeYearAgo()
- {
- return MAX_commonGetTimeNow() - 31536000; }
- function MAX_cookieUnpackCapping()
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $cookieNames = $GLOBALS['_MAX']['COOKIE']['LIMITATIONS']['arrCappingCookieNames'];
- if (!is_array($cookieNames))
- return;
- foreach ($cookieNames as $cookieName) {
- if (!empty($_COOKIE[$cookieName])) {
- if (!is_array($_COOKIE[$cookieName])) {
- $output = array();
- $data = explode('_', $_COOKIE[$cookieName]);
- foreach ($data as $pair) {
- list($name, $value) = explode('.', $pair);
- $output[$name] = $value;
- }
- $_COOKIE[$cookieName] = $output;
- }
- }
- if (!empty($_COOKIE['_' . $cookieName]) && is_array($_COOKIE['_' . $cookieName])) {
- foreach ($_COOKIE['_' . $cookieName] as $adId => $cookie) {
- if (_isBlockCookie($cookieName)) {
- $_COOKIE[$cookieName][$adId] = $cookie;
- } else {
- if (isset($_COOKIE[$cookieName][$adId])) {
- $_COOKIE[$cookieName][$adId] += $cookie;
- } else {
- $_COOKIE[$cookieName][$adId] = $cookie;
- }
- }
- MAX_cookieUnset("_{$cookieName}[{$adId}]");
- }
- }
- }
- }
- function _isBlockCookie($cookieName)
- {
- return in_array($cookieName, array(
- $GLOBALS['_MAX']['CONF']['var']['blockAd'],
- $GLOBALS['_MAX']['CONF']['var']['blockCampaign'],
- $GLOBALS['_MAX']['CONF']['var']['blockZone'],
- $GLOBALS['_MAX']['CONF']['var']['lastView'],
- $GLOBALS['_MAX']['CONF']['var']['lastClick'],
- $GLOBALS['_MAX']['CONF']['var']['blockLoggingClick'],
- ));
- }
- function MAX_cookieGetUniqueViewerId($create = true)
- {
- static $uniqueViewerId = null;
- if(!is_null($uniqueViewerId)) {
- return $uniqueViewerId;
- }
- $conf = $GLOBALS['_MAX']['CONF'];
- if (isset($_COOKIE[$conf['var']['viewerId']])) {
- $uniqueViewerId = $_COOKIE[$conf['var']['viewerId']];
- } elseif ($create) {
- $uniqueViewerId = md5(uniqid('', true)); $GLOBALS['_MAX']['COOKIE']['newViewerId'] = true;
- }
- return $uniqueViewerId;
- }
- function MAX_cookieGetCookielessViewerID()
- {
- if (empty($_SERVER['REMOTE_ADDR']) || empty($_SERVER['HTTP_USER_AGENT'])) {
- return '';
- }
- $cookiePrefix = $GLOBALS['_MAX']['MAX_COOKIELESS_PREFIX'];
- return $cookiePrefix . substr(md5($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']), 0, 32-(strlen($cookiePrefix)));
- }
- function MAX_Delivery_cookie_cappingOnRequest()
- {
- if (isset($GLOBALS['_OA']['invocationType']) &&
- ($GLOBALS['_OA']['invocationType'] == 'xmlrpc' || $GLOBALS['_OA']['invocationType'] == 'view')
- ) {
- return true;
- }
- return !$GLOBALS['_MAX']['CONF']['logging']['adImpressions'];
- }
- function MAX_Delivery_cookie_setCapping($type, $id, $block = 0, $cap = 0, $sessionCap = 0)
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $setBlock = false;
- if ($cap > 0) {
- $expire = MAX_commonGetTimeNow() + $conf['cookie']['permCookieSeconds'];
- 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;
- $setBlock = true;
- } else {
- $value = 1;
- }
- MAX_cookieAdd("_{$conf['var']['cap' . $type]}[{$id}]", $value, $expire);
- }
- if ($sessionCap > 0) {
- 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;
- $setBlock = true;
- } else {
- $value = 1;
- }
- MAX_cookieAdd("_{$conf['var']['sessionCap' . $type]}[{$id}]", $value, 0);
- }
- if ($block > 0 || $setBlock) {
- MAX_cookieAdd("_{$conf['var']['block' . $type]}[{$id}]", MAX_commonGetTimeNow(), _getTimeThirtyDaysFromNow());
- }
- }
- function MAX_cookieClientCookieSet($name, $value, $expire, $path = '/', $domain = null)
- {
- if (isset($GLOBALS['_OA']['invocationType']) && $GLOBALS['_OA']['invocationType'] == 'xmlrpc') {
- if (!isset($GLOBALS['_OA']['COOKIE']['XMLRPC_CACHE'])) {
- $GLOBALS['_OA']['COOKIE']['XMLRPC_CACHE'] = array();
- }
- $GLOBALS['_OA']['COOKIE']['XMLRPC_CACHE'][$name] = array($value, $expire);
- } else {
- @setcookie($name, $value, $expire, $path, $domain);
- }
- }
- function MAX_cookieClientCookieUnset($name)
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $domain = (!empty($conf['cookie']['domain'])) ? $conf['cookie']['domain'] : null;
- MAX_cookieSet($name, false, _getTimeYearAgo(), '/', $domain);
- MAX_cookieSet(str_replace('_', '%5F', urlencode($name)), false, _getTimeYearAgo(), '/', $domain);
- }
- function MAX_cookieClientCookieFlush()
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- MAX_cookieSendP3PHeaders();
- if (!empty($GLOBALS['_MAX']['COOKIE']['CACHE'])) {
- reset($GLOBALS['_MAX']['COOKIE']['CACHE']);
- while (list($name,$v) = each ($GLOBALS['_MAX']['COOKIE']['CACHE'])) {
- list($value, $expire) = $v;
- if ($name == $conf['var']['viewerId']) {
- MAX_cookieClientCookieSet($name, $value, $expire, '/', (!empty($conf['cookie']['domain']) ? $conf['cookie']['domain'] : null));
- } else {
- MAX_cookieSet($name, $value, $expire, '/', (!empty($conf['cookie']['domain']) ? $conf['cookie']['domain'] : null));
- }
- }
- $GLOBALS['_MAX']['COOKIE']['CACHE'] = array();
- }
- $cookieNames = $GLOBALS['_MAX']['COOKIE']['LIMITATIONS']['arrCappingCookieNames'];
- if (!is_array($cookieNames))
- return;
- $maxCookieSize = !empty($conf['cookie']['maxCookieSize']) ? $conf['cookie']['maxCookieSize'] : 2048;
- foreach ($cookieNames as $cookieName) {
- if (empty($_COOKIE["_{$cookieName}"])) {
- continue;
- }
- switch ($cookieName) {
- case $conf['var']['blockAd'] :
- case $conf['var']['blockCampaign'] :
- case $conf['var']['blockZone'] : $expire = _getTimeThirtyDaysFromNow(); break;
- case $conf['var']['lastClick'] :
- case $conf['var']['lastView'] :
- case $conf['var']['capAd'] :
- case $conf['var']['capCampaign'] :
- case $conf['var']['capZone'] : $expire = _getTimeYearFromNow(); break;
- case $conf['var']['sessionCapCampaign'] :
- case $conf['var']['sessionCapAd'] :
- case $conf['var']['sessionCapZone'] : $expire = 0; break;
- }
- if (!empty($_COOKIE[$cookieName]) && is_array($_COOKIE[$cookieName])) {
- $data = array();
- foreach ($_COOKIE[$cookieName] as $adId => $value) {
- $data[] = "{$adId}.{$value}";
- }
- while (strlen(implode('_', $data)) > $maxCookieSize) {
- $data = array_slice($data, 1);
- }
- MAX_cookieSet($cookieName, implode('_', $data), $expire, '/', (!empty($conf['cookie']['domain']) ? $conf['cookie']['domain'] : null));
- }
- }
- }
- function MAX_cookieSendP3PHeaders() {
- if ($GLOBALS['_MAX']['CONF']['p3p']['policies']) {
- MAX_header("P3P: ". _generateP3PHeader());
- }
- }
- function _generateP3PHeader()
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $p3p_header = '';
- if ($conf['p3p']['policies']) {
- if ($conf['p3p']['policyLocation'] != '') {
- $p3p_header .= " policyref=\"".$conf['p3p']['policyLocation']."\"";
- }
- if ($conf['p3p']['policyLocation'] != '' && $conf['p3p']['compactPolicy'] != '') {
- $p3p_header .= ", ";
- }
- if ($conf['p3p']['compactPolicy'] != '') {
- $p3p_header .= " CP=\"".$conf['p3p']['compactPolicy']."\"";
- }
- }
- return $p3p_header;
- }
- $file = '/lib/max/Delivery/remotehost.php';
- $GLOBALS['_MAX']['FILES'][$file] = true;
- function MAX_remotehostSetInfo($run = false)
- {
- if (empty($GLOBALS['_OA']['invocationType']) || $run || ($GLOBALS['_OA']['invocationType'] != 'xmlrpc')) {
- MAX_remotehostProxyLookup();
- MAX_remotehostReverseLookup();
- MAX_remotehostSetGeoInfo();
- }
- }
- function MAX_remotehostProxyLookup()
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- if ($conf['logging']['proxyLookup']) {
- OX_Delivery_logMessage('checking remote host proxy', 7);
- $proxy = false;
- if (!empty($_SERVER['HTTP_VIA']) || !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $proxy = true;
- } elseif (!empty($_SERVER['REMOTE_HOST'])) {
- $aProxyHosts = array(
- 'proxy',
- 'cache',
- 'inktomi'
- );
- foreach ($aProxyHosts as $proxyName) {
- if (strpos($_SERVER['REMOTE_HOST'], $proxyName) !== false) {
- $proxy = true;
- break;
- }
- }
- }
- if ($proxy) {
- OX_Delivery_logMessage('proxy detected', 7);
- $aHeaders = array(
- 'HTTP_FORWARDED',
- 'HTTP_FORWARDED_FOR',
- 'HTTP_X_FORWARDED',
- 'HTTP_X_FORWARDED_FOR',
- 'HTTP_CLIENT_IP'
- );
- foreach ($aHeaders as $header) {
- if (!empty($_SERVER[$header])) {
- $ip = $_SERVER[$header];
- break;
- }
- }
- if (!empty($ip)) {
- foreach (explode(',', $ip) as $ip) {
- $ip = trim($ip);
- if (($ip != 'unknown') && (!MAX_remotehostPrivateAddress($ip))) {
- $_SERVER['REMOTE_ADDR'] = $ip;
- $_SERVER['REMOTE_HOST'] = '';
- $_SERVER['HTTP_VIA'] = '';
- OX_Delivery_logMessage('real address set to '.$ip, 7);
- break;
- }
- }
- }
- }
- }
- }
- function MAX_remotehostReverseLookup()
- {
- if (empty($_SERVER['REMOTE_HOST'])) {
- if ($GLOBALS['_MAX']['CONF']['logging']['reverseLookup']) {
- $_SERVER['REMOTE_HOST'] = @gethostbyaddr($_SERVER['REMOTE_ADDR']);
- } else {
- $_SERVER['REMOTE_HOST'] = $_SERVER['REMOTE_ADDR'];
- }
- }
- }
- function MAX_remotehostSetGeoInfo()
- {
- if (!function_exists('parseDeliveryIniFile')) {
- }
- $aConf = $GLOBALS['_MAX']['CONF'];
- $type = (!empty($aConf['geotargeting']['type'])) ? $aConf['geotargeting']['type'] : null;
- if (!is_null($type) && $type != 'none') {
- $aComponent = explode(':', $aConf['geotargeting']['type']);
- if (!empty($aComponent[1]) && (!empty($aConf['pluginGroupComponents'][$aComponent[1]]))) {
- $GLOBALS['_MAX']['CLIENT_GEO'] = OX_Delivery_Common_hook('getGeoInfo', array(), $type);
- }
- }
- }
- function MAX_remotehostPrivateAddress($ip)
- {
- $ip = ip2long($ip);
- if (!$ip) return false;
- return (MAX_remotehostMatchSubnet($ip, '10.0.0.0', 8) ||
- MAX_remotehostMatchSubnet($ip, '172.16.0.0', 12) ||
- MAX_remotehostMatchSubnet($ip, '192.168.0.0', 16) ||
- MAX_remotehostMatchSubnet($ip, '127.0.0.0', 8)
- );
- }
- function MAX_remotehostMatchSubnet($ip, $net, $mask)
- {
- $net = ip2long($net);
- if (!is_integer($ip)) {
- $ip = ip2long($ip);
- }
- if (!$ip || !$net) {
- return false;
- }
- if (is_integer($mask)) {
- if ($mask > 32 || $mask <= 0)
- return false;
- elseif ($mask == 32)
- $mask = ~0;
- else
- $mask = ~((1 << (32 - $mask)) - 1);
- } elseif (!($mask = ip2long($mask))) {
- return false;
- }
- return ($ip & $mask) == ($net & $mask) ? true : false;
- }
- $file = '/lib/max/Delivery/log.php';
- $GLOBALS['_MAX']['FILES'][$file] = true;
- $file = '/lib/max/Dal/Delivery.php';
- $GLOBALS['_MAX']['FILES'][$file] = true;
- $file = '/lib/OA/Dal/Delivery.php';
- $GLOBALS['_MAX']['FILES'][$file] = true;
- function OA_Dal_Delivery_getAccountTZs()
- {
- $aConf = $GLOBALS['_MAX']['CONF'];
- $query = "
- SELECT
- value
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['application_variable'])."
- WHERE
- name = 'admin_account_id'
- ";
- $res = OA_Dal_Delivery_query($query);
- if (is_resource($res) && OA_Dal_Delivery_numRows($res)) {
- $adminAccountId = (int)OA_Dal_Delivery_result($res, 0, 0);
- } else {
- $adminAccountId = false;
- }
- $query = "
- SELECT
- a.account_id AS account_id,
- apa.value AS timezone
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['accounts'])." AS a JOIN
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['account_preference_assoc'])." AS apa ON (apa.account_id = a.account_id) JOIN
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['preferences'])." AS p ON (p.preference_id = apa.preference_id)
- WHERE
- a.account_type IN ('ADMIN', 'MANAGER') AND
- p.preference_name = 'timezone'
- ";
- $res = OA_Dal_Delivery_query($query);
- $aResult = array(
- 'adminAccountId' => $adminAccountId,
- 'aAccounts' => array()
- );
- if (is_resource($res)) {
- while ($row = OA_Dal_Delivery_fetchAssoc($res)) {
- $accountId = (int)$row['account_id'];
- if ($accountId === $adminAccountId) {
- $aResult['default'] = $row['timezone'];
- } else {
- $aResult['aAccounts'][$accountId] = $row['timezone'];
- }
- }
- }
- if (empty($aResult['default'])) {
- $aResult['default'] = 'UTC';
- }
- return $aResult;
- }
- function OA_Dal_Delivery_getZoneInfo($zoneid) {
- $aConf = $GLOBALS['_MAX']['CONF'];
- $zoneid = (int)$zoneid;
- $query = "
- SELECT
- z.zoneid AS zone_id,
- z.zonename AS name,
- z.delivery AS type,
- z.description AS description,
- z.width AS width,
- z.height AS height,
- z.chain AS chain,
- z.prepend AS prepend,
- z.append AS append,
- z.appendtype AS appendtype,
- z.forceappend AS forceappend,
- z.inventory_forecast_type AS inventory_forecast_type,
- z.block AS block_zone,
- z.capping AS cap_zone,
- z.session_capping AS session_cap_zone,
- z.show_capped_no_cookie AS show_capped_no_cookie_zone,
- z.ext_adselection AS ext_adselection,
- z.affiliateid AS publisher_id,
- a.agencyid AS agency_id,
- a.account_id AS trafficker_account_id,
- m.account_id AS manager_account_id
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['zones'])." AS z,
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['affiliates'])." AS a,
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['agency'])." AS m
- WHERE
- z.zoneid = {$zoneid}
- AND
- z.affiliateid = a.affiliateid
- AND
- a.agencyid = m.agencyid";
- $rZoneInfo = OA_Dal_Delivery_query($query);
- if (!is_resource($rZoneInfo)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : false;
- }
- $aZoneInfo = OA_Dal_Delivery_fetchAssoc($rZoneInfo);
- if (empty($aZoneInfo)) {
- return false;
- }
- $query = "
- SELECT
- p.preference_id AS preference_id,
- p.preference_name AS preference_name
- FROM
- {$aConf['table']['prefix']}{$aConf['table']['preferences']} AS p
- WHERE
- p.preference_name = 'default_banner_image_url'
- OR
- p.preference_name = 'default_banner_destination_url'";
- $rPreferenceInfo = OA_Dal_Delivery_query($query);
- if (!is_resource($rPreferenceInfo)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : false;
- }
- if (OA_Dal_Delivery_numRows($rPreferenceInfo) != 2) {
- return $aZoneInfo;
- }
- $aPreferenceInfo = OA_Dal_Delivery_fetchAssoc($rPreferenceInfo);
- $variableName = $aPreferenceInfo['preference_name'] . '_id';
- $$variableName = $aPreferenceInfo['preference_id'];
- $aPreferenceInfo = OA_Dal_Delivery_fetchAssoc($rPreferenceInfo);
- $variableName = $aPreferenceInfo['preference_name'] . '_id';
- $$variableName = $aPreferenceInfo['preference_id'];
- $query = "
- SELECT
- 'default_banner_destination_url_trafficker' AS item,
- apa.value AS value
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['account_preference_assoc'])." AS apa
- WHERE
- apa.account_id = {$aZoneInfo['trafficker_account_id']}
- AND
- apa.preference_id = $default_banner_destination_url_id
- UNION
- SELECT
- 'default_banner_destination_url_manager' AS item,
- apa.value AS value
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['account_preference_assoc'])." AS apa
- WHERE
- apa.account_id = {$aZoneInfo['manager_account_id']}
- AND
- apa.preference_id = $default_banner_destination_url_id
- UNION
- SELECT
- 'default_banner_image_url_trafficker' AS item,
- apa.value AS value
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['account_preference_assoc'])." AS apa
- WHERE
- apa.account_id = {$aZoneInfo['trafficker_account_id']}
- AND
- apa.preference_id = $default_banner_image_url_id
- UNION
- SELECT
- 'default_banner_image_url_manager' AS item,
- apa.value AS value
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['account_preference_assoc'])." AS apa
- WHERE
- apa.account_id = {$aZoneInfo['manager_account_id']}
- AND
- apa.preference_id = $default_banner_image_url_id
- UNION
- SELECT
- 'default_banner_image_url_admin' AS item,
- apa.value AS value
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['account_preference_assoc'])." AS apa,
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['accounts'])." AS a
- WHERE
- apa.account_id = a.account_id
- AND
- a.account_type = 'ADMIN'
- AND
- apa.preference_id = $default_banner_image_url_id
- UNION
- SELECT
- 'default_banner_destination_url_admin' AS item,
- apa.value AS value
- FROM
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['account_preference_assoc'])." AS apa,
- ".OX_escapeIdentifier($aConf['table']['prefix'].$aConf['table']['accounts'])." AS a
- WHERE
- apa.account_id = a.account_id
- AND
- a.account_type = 'ADMIN'
- AND
- apa.preference_id = $default_banner_destination_url_id";
- $rDefaultBannerInfo = OA_Dal_Delivery_query($query);
- if (!is_resource($rDefaultBannerInfo)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : false;
- }
- if (OA_Dal_Delivery_numRows($rDefaultBannerInfo) == 0) {
- if ($aConf['defaultBanner']['imageUrl'] != '') {
- $aZoneInfo['default_banner_image_url'] = $aConf['defaultBanner']['imageUrl'];
- }
- return $aZoneInfo;
- }
- $aDefaultImageURLs = array();
- $aDefaultDestinationURLs = array();
- while ($aRow = OA_Dal_Delivery_fetchAssoc($rDefaultBannerInfo)) {
- if (stristr($aRow['item'], 'default_banner_image_url')) {
- $aDefaultImageURLs[$aRow['item']] = $aRow['value'];
- } else if (stristr($aRow['item'], 'default_banner_destination_url')) {
- $aDefaultDestinationURLs[$aRow['item']] = $aRow['value'];
- }
- }
- $aTypes = array(
- 0 => 'admin',
- 1 => 'manager',
- 2 => 'trafficker'
- );
- foreach ($aTypes as $type) {
- if (isset($aDefaultImageURLs['default_banner_image_url_' . $type])) {
- $aZoneInfo['default_banner_image_url'] = $aDefaultImageURLs['default_banner_image_url_' . $type];
- }
- if (isset($aDefaultDestinationURLs['default_banner_destination_url_' . $type])) {
- $aZoneInfo['default_banner_destination_url'] = $aDefaultDestinationURLs['default_banner_destination_url_' . $type];
- }
- }
- return $aZoneInfo;
- }
- function OA_Dal_Delivery_getPublisherZones($publisherid) {
- $conf = $GLOBALS['_MAX']['CONF'];
- $publisherid = (int)$publisherid;
- $rZones = OA_Dal_Delivery_query("
- SELECT
- z.zoneid AS zone_id,
- z.affiliateid AS publisher_id,
- z.zonename AS name,
- z.delivery AS type
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['zones'])." AS z
- WHERE
- z.affiliateid={$publisherid}
- ");
- if (!is_resource($rZones)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : false;
- }
- while ($aZone = OA_Dal_Delivery_fetchAssoc($rZones)) {
- $aZones[$aZone['zone_id']] = $aZone;
- }
- return ($aZones);
- }
- function OA_Dal_Delivery_getZoneLinkedAds($zoneid) {
- $conf = $GLOBALS['_MAX']['CONF'];
- $zoneid = (int)$zoneid;
- $aRows = OA_Dal_Delivery_getZoneInfo($zoneid);
- $aRows['xAds'] = array();
- $aRows['ads'] = array();
- $aRows['lAds'] = array();
- $aRows['eAds'] = array();
- $aRows['count_active'] = 0;
- $aRows['zone_companion'] = false;
- $aRows['count_active'] = 0;
- $totals = array(
- 'xAds' => 0,
- 'ads' => 0,
- 'lAds' => 0
- );
- $query = "
- SELECT
- d.bannerid AS ad_id,
- d.campaignid AS placement_id,
- d.status AS status,
- d.description AS name,
- d.storagetype AS type,
- d.contenttype AS contenttype,
- d.pluginversion AS pluginversion,
- d.filename AS filename,
- d.imageurl AS imageurl,
- d.htmltemplate AS htmltemplate,
- d.htmlcache AS htmlcache,
- d.width AS width,
- d.height AS height,
- d.weight AS weight,
- d.seq AS seq,
- d.target AS target,
- d.url AS url,
- d.alt AS alt,
- d.statustext AS statustext,
- d.bannertext AS bannertext,
- d.adserver AS adserver,
- d.block AS block_ad,
- d.capping AS cap_ad,
- d.session_capping AS session_cap_ad,
- d.compiledlimitation AS compiledlimitation,
- d.acl_plugins AS acl_plugins,
- d.prepend AS prepend,
- d.append AS append,
- d.bannertype AS bannertype,
- d.alt_filename AS alt_filename,
- d.alt_imageurl AS alt_imageurl,
- d.alt_contenttype AS alt_contenttype,
- d.parameters AS parameters,
- d.transparent AS transparent,
- d.ext_bannertype AS ext_bannertype,
- az.priority AS priority,
- az.priority_factor AS priority_factor,
- az.to_be_delivered AS to_be_delivered,
- c.campaignid AS campaign_id,
- c.priority AS campaign_priority,
- c.weight AS campaign_weight,
- c.companion AS campaign_companion,
- c.block AS block_campaign,
- c.capping AS cap_campaign,
- c.session_capping AS session_cap_campaign,
- c.show_capped_no_cookie AS show_capped_no_cookie,
- c.clientid AS client_id,
- c.expire_time AS expire_time,
- c.revenue_type AS revenue_type,
- c.ecpm_enabled AS ecpm_enabled,
- c.ecpm AS ecpm,
- c.clickwindow AS clickwindow,
- c.viewwindow AS viewwindow,
- m.advertiser_limitation AS advertiser_limitation,
- a.account_id AS account_id,
- z.affiliateid AS affiliate_id,
- a.agencyid as agency_id
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['banners'])." AS d JOIN
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['ad_zone_assoc'])." AS az ON (d.bannerid = az.ad_id) JOIN
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['zones'])." AS z ON (az.zone_id = z.zoneid) JOIN
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['campaigns'])." AS c ON (c.campaignid = d.campaignid) LEFT JOIN
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['clients'])." AS m ON (m.clientid = c.clientid) LEFT JOIN
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['agency'])." AS a ON (a.agencyid = m.agencyid)
- WHERE
- az.zone_id = {$zoneid}
- AND
- d.status <= 0
- AND
- c.status <= 0
- ";
- $rAds = OA_Dal_Delivery_query($query);
- if (!is_resource($rAds)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- }
- $aConversionLinkedCreatives = MAX_cacheGetTrackerLinkedCreatives();
- while ($aAd = OA_Dal_Delivery_fetchAssoc($rAds)) {
- $aAd['tracker_status'] = (!empty($aConversionLinkedCreatives[$aAd['ad_id']]['status'])) ? $aConversionLinkedCreatives[$aAd['ad_id']]['status'] : null;
- if ($aAd['campaign_priority'] == -1) {
- $aRows['xAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } elseif ($aAd['campaign_priority'] == 0) {
- $aRows['lAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } elseif ($aAd['campaign_priority'] == -2) {
- $aRows['eAds'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } else {
- $aRows['ads'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- }
- if ($aAd['campaign_companion'] == 1) {
- $aRows['zone_companion'][] = $aAd['placement_id'];
- }
- }
- if (is_array($aRows['xAds'])) {
- $totals['xAds'] = _setPriorityFromWeights($aRows['xAds']);
- }
- if (is_array($aRows['ads'])) {
- $totals['ads'] = _getTotalPrioritiesByCP($aRows['ads']);
- }
- if (is_array($aRows['eAds'])) {
- $totals['eAds'] = _getTotalPrioritiesByCP($aRows['eAds']);
- }
- if (is_array($aRows['lAds'])) {
- $totals['lAds'] = _setPriorityFromWeights($aRows['lAds']);
- }
- $aRows['priority'] = $totals;
- return $aRows;
- }
- function OA_Dal_Delivery_getZoneLinkedAdInfos($zoneid) {
- $conf = $GLOBALS['_MAX']['CONF'];
- $zoneid = (int)$zoneid;
- $aRows['xAds'] = array();
- $aRows['ads'] = array();
- $aRows['lAds'] = array();
- $aRows['eAds'] = array();
- $aRows['zone_companion'] = false;
- $aRows['count_active'] = 0;
- $query =
- "SELECT "
- ."d.bannerid AS ad_id, " ."d.campaignid AS placement_id, " ."d.status AS status, " ."d.width AS width, "
- ."d.ext_bannertype AS ext_bannertype, "
- ."d.height AS height, "
- ."d.storagetype AS type, " ."d.contenttype AS contenttype, " ."d.weight AS weight, " ."d.adserver AS adserver, " ."d.block AS block_ad, " ."d.capping AS cap_ad, " ."d.session_capping AS session_cap_ad, " ."d.compiledlimitation AS compiledlimitation, " ."d.acl_plugins AS acl_plugins, " ."d.alt_filename AS alt_filename, " ."az.priority AS priority, " ."az.priority_factor AS priority_factor, " ."az.to_be_delivered AS to_be_delivered, " ."c.campaignid AS campaign_id, " ."c.priority AS campaign_priority, " ."c.weight AS campaign_weight, " ."c.companion AS campaign_companion, " ."c.block AS block_campaign, " ."c.capping AS cap_campaign, " ."c.session_capping AS session_cap_campaign, " ."c.show_capped_no_cookie AS show_capped_no_cookie, "
- ."c.clientid AS client_id, " ."c.expire_time AS expire_time, "
- ."c.revenue_type AS revenue_type, "
- ."c.ecpm_enabled AS ecpm_enabled, "
- ."c.ecpm AS ecpm, "
- ."ct.status AS tracker_status, "
- .OX_Dal_Delivery_regex("d.htmlcache", "src\\s?=\\s?[\\'\"]http:")." AS html_ssl_unsafe, "
- .OX_Dal_Delivery_regex("d.imageurl", "^http:")." AS url_ssl_unsafe "
- ."FROM "
- .OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['banners'])." AS d JOIN "
- .OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['ad_zone_assoc'])." AS az ON (d.bannerid = az.ad_id) JOIN "
- .OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['campaigns'])." AS c ON (c.campaignid = d.campaignid) LEFT JOIN "
- .OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['campaigns_trackers'])." AS ct ON (ct.campaignid = c.campaignid) "
- ."WHERE "
- ."az.zone_id = {$zoneid} "
- ."AND "
- ."d.status <= 0 "
- ."AND "
- ."c.status <= 0 ";
- $rAds = OA_Dal_Delivery_query($query);
- if (!is_resource($rAds)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- }
- while ($aAd = OA_Dal_Delivery_fetchAssoc($rAds)) {
- if ($aAd['campaign_priority'] == -1) {
- $aRows['xAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } elseif ($aAd['campaign_priority'] == 0) {
- $aRows['lAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } elseif ($aAd['campaign_priority'] == -2) {
- $aRows['eAds'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } else {
- $aRows['ads'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- }
- if ($aAd['campaign_companion'] == 1) {
- $aRows['zone_companion'][] = $aAd['placement_id']; }
- }
- return $aRows;
- }
- function OA_Dal_Delivery_getLinkedAdInfos($search, $campaignid = '', $lastpart = true) {
- $conf = $GLOBALS['_MAX']['CONF'];
- $campaignid = (int)$campaignid;
- if ($campaignid > 0) {
- $precondition = " AND d.campaignid = '".$campaignid."' ";
- } else {
- $precondition = '';
- }
- $aRows['xAds'] = array();
- $aRows['ads'] = array();
- $aRows['lAds'] = array();
- $aRows['count_active'] = 0;
- $aRows['zone_companion'] = false;
- $aRows['count_active'] = 0;
- $totals = array(
- 'xAds' => 0,
- 'ads' => 0,
- 'lAds' => 0
- );
- $query = OA_Dal_Delivery_buildAdInfoQuery($search, $lastpart, $precondition);
- $rAds = OA_Dal_Delivery_query($query);
- if (!is_resource($rAds)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- }
- while ($aAd = OA_Dal_Delivery_fetchAssoc($rAds)) {
- if ($aAd['campaign_priority'] == -1) {
- $aAd['priority'] = $aAd['campaign_weight'] * $aAd['weight'];
- $aRows['xAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- $totals['xAds'] += $aAd['priority'];
- } elseif ($aAd['campaign_priority'] == 0) {
- $aAd['priority'] = $aAd['campaign_weight'] * $aAd['weight'];
- $aRows['lAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- $totals['lAds'] += $aAd['priority'];
- } elseif ($aAd['campaign_priority'] == -2) {
- $aRows['eAds'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } else {
- $aRows['ads'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- }
- }
- return $aRows;
- }
- function OA_Dal_Delivery_getLinkedAds($search, $campaignid = '', $lastpart = true) {
- $conf = $GLOBALS['_MAX']['CONF'];
- $campaignid = (int)$campaignid;
- if ($campaignid > 0) {
- $precondition = " AND d.campaignid = '".$campaignid."' ";
- } else {
- $precondition = '';
- }
- $aRows['xAds'] = array();
- $aRows['ads'] = array();
- $aRows['lAds'] = array();
- $aRows['count_active'] = 0;
- $aRows['zone_companion'] = false;
- $aRows['count_active'] = 0;
- $totals = array(
- 'xAds' => 0,
- 'ads' => 0,
- 'lAds' => 0
- );
- $query = OA_Dal_Delivery_buildQuery($search, $lastpart, $precondition);
- $rAds = OA_Dal_Delivery_query($query);
- if (!is_resource($rAds)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- }
- $aConversionLinkedCreatives = MAX_cacheGetTrackerLinkedCreatives();
- while ($aAd = OA_Dal_Delivery_fetchAssoc($rAds)) {
- $aAd['tracker_status'] = (!empty($aConversionLinkedCreatives[$aAd['ad_id']]['status'])) ? $aConversionLinkedCreatives[$aAd['ad_id']]['status'] : null;
- if ($aAd['campaign_priority'] == -1) {
- $aAd['priority'] = $aAd['campaign_weight'] * $aAd['weight'];
- $aRows['xAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- $totals['xAds'] += $aAd['priority'];
- } elseif ($aAd['campaign_priority'] == 0) {
- $aAd['priority'] = $aAd['campaign_weight'] * $aAd['weight'];
- $aRows['lAds'][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- $totals['lAds'] += $aAd['priority'];
- } elseif ($aAd['campaign_priority'] == -2) {
- $aRows['eAds'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- } else {
- $aRows['ads'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd;
- $aRows['count_active']++;
- }
- }
- if (isset($aRows['xAds']) && is_array($aRows['xAds'])) {
- $totals['xAds'] = _setPriorityFromWeights($aRows['xAds']);
- }
- if (isset($aRows['ads']) && is_array($aRows['ads'])) {
- if (isset($aRows['lAds']) && is_array($aRows['lAds']) && count($aRows['lAds']) > 0) {
- $totals['ads'] = _getTotalPrioritiesByCP($aRows['ads'], true);
- } else {
- $totals['ads'] = _getTotalPrioritiesByCP($aRows['ads'], false);
- }
- }
- if (is_array($aRows['eAds'])) {
- $totals['eAds'] = _getTotalPrioritiesByCP($aRows['eAds']);
- }
- if (isset($aRows['lAds']) && is_array($aRows['lAds'])) {
- $totals['lAds'] = _setPriorityFromWeights($aRows['lAds']);
- }
- $aRows['priority'] = $totals;
- return $aRows;
- }
- function OA_Dal_Delivery_getAd($ad_id) {
- $conf = $GLOBALS['_MAX']['CONF'];
- $ad_id = (int)$ad_id;
- $query = "
- SELECT
- d.bannerid AS ad_id,
- d.campaignid AS placement_id,
- d.status AS status,
- d.description AS name,
- d.storagetype AS type,
- d.contenttype AS contenttype,
- d.pluginversion AS pluginversion,
- d.filename AS filename,
- d.imageurl AS imageurl,
- d.htmltemplate AS htmltemplate,
- d.htmlcache AS htmlcache,
- d.width AS width,
- d.height AS height,
- d.weight AS weight,
- d.seq AS seq,
- d.target AS target,
- d.url AS url,
- d.alt AS alt,
- d.statustext AS statustext,
- d.bannertext AS bannertext,
- d.adserver AS adserver,
- d.block AS block_ad,
- d.capping AS cap_ad,
- d.session_capping AS session_cap_ad,
- d.compiledlimitation AS compiledlimitation,
- d.acl_plugins AS acl_plugins,
- d.prepend AS prepend,
- d.append AS append,
- d.bannertype AS bannertype,
- d.alt_filename AS alt_filename,
- d.alt_imageurl AS alt_imageurl,
- d.alt_contenttype AS alt_contenttype,
- d.parameters AS parameters,
- d.transparent AS transparent,
- d.ext_bannertype AS ext_bannertype,
- c.campaignid AS campaign_id,
- c.block AS block_campaign,
- c.capping AS cap_campaign,
- c.session_capping AS session_cap_campaign,
- c.show_capped_no_cookie AS show_capped_no_cookie,
- m.clientid AS client_id,
- c.clickwindow AS clickwindow,
- c.viewwindow AS viewwindow,
- m.advertiser_limitation AS advertiser_limitation,
- m.agencyid AS agency_id
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['banners'])." AS d,
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['campaigns'])." AS c,
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['clients'])." AS m
- WHERE
- d.bannerid={$ad_id}
- AND
- d.campaignid = c.campaignid
- AND
- m.clientid = c.clientid
- ";
- $rAd = OA_Dal_Delivery_query($query);
- if (!is_resource($rAd)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- } else {
- return (OA_Dal_Delivery_fetchAssoc($rAd));
- }
- }
- function OA_Dal_Delivery_getChannelLimitations($channelid) {
- $conf = $GLOBALS['_MAX']['CONF'];
- $channelid = (int)$channelid;
- $rLimitation = OA_Dal_Delivery_query("
- SELECT
- acl_plugins,compiledlimitation
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['channel'])."
- WHERE
- channelid={$channelid}");
- if (!is_resource($rLimitation)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- }
- $limitations = OA_Dal_Delivery_fetchAssoc($rLimitation);
- return $limitations;
- }
- function OA_Dal_Delivery_getCreative($filename)
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $rCreative = OA_Dal_Delivery_query("
- SELECT
- contents,
- t_stamp
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['images'])."
- WHERE
- filename = '".OX_escapeString($filename)."'
- ");
- if (!is_resource($rCreative)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- } else {
- $aResult = OA_Dal_Delivery_fetchAssoc($rCreative);
- $aResult['contents'] = OX_unescapeBlob($aResult['contents']);
- $aResult['t_stamp'] = strtotime($aResult['t_stamp'] . ' GMT');
- return ($aResult);
- }
- }
- function OA_Dal_Delivery_getTracker($trackerid)
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $trackerid = (int)$trackerid;
- $rTracker = OA_Dal_Delivery_query("
- SELECT
- t.clientid AS advertiser_id,
- t.trackerid AS tracker_id,
- t.trackername AS name,
- t.variablemethod AS variablemethod,
- t.description AS description,
- t.viewwindow AS viewwindow,
- t.clickwindow AS clickwindow,
- t.blockwindow AS blockwindow,
- t.appendcode AS appendcode
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['trackers'])." AS t
- WHERE
- t.trackerid={$trackerid}
- ");
- if (!is_resource($rTracker)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- } else {
- return (OA_Dal_Delivery_fetchAssoc($rTracker));
- }
- }
- function OA_Dal_Delivery_getTrackerLinkedCreatives($trackerid = null)
- {
- $aConf = $GLOBALS['_MAX']['CONF'];
- $trackerid = (int)$trackerid;
- $rCreatives = OA_Dal_Delivery_query("
- SELECT
- b.bannerid AS ad_id,
- b.campaignid AS placement_id,
- c.viewwindow AS view_window,
- c.clickwindow AS click_window,
- ct.status AS status,
- t.type AS tracker_type
- FROM
- {$aConf['table']['prefix']}{$aConf['table']['banners']} AS b,
- {$aConf['table']['prefix']}{$aConf['table']['campaigns_trackers']} AS ct,
- {$aConf['table']['prefix']}{$aConf['table']['campaigns']} AS c,
- {$aConf['table']['prefix']}{$aConf['table']['trackers']} AS t
- WHERE
- ct.trackerid=t.trackerid
- AND c.campaignid=b.campaignid
- AND b.campaignid = ct.campaignid
- " . ((!empty($trackerid)) ? ' AND t.trackerid='.$trackerid : '') . "
- ");
- if (!is_resource($rCreatives)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- } else {
- $output = array();
- while ($aRow = OA_Dal_Delivery_fetchAssoc($rCreatives)) {
- $output[$aRow['ad_id']] = $aRow;
- }
- return $output;
- }
- }
- function OA_Dal_Delivery_getTrackerVariables($trackerid)
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $trackerid = (int)$trackerid;
- $rVariables = OA_Dal_Delivery_query("
- SELECT
- v.variableid AS variable_id,
- v.trackerid AS tracker_id,
- v.name AS name,
- v.datatype AS type,
- purpose AS purpose,
- reject_if_empty AS reject_if_empty,
- is_unique AS is_unique,
- unique_window AS unique_window,
- v.variablecode AS variablecode
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['variables'])." AS v
- WHERE
- v.trackerid={$trackerid}
- ");
- if (!is_resource($rVariables)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- } else {
- $output = array();
- while ($aRow = OA_Dal_Delivery_fetchAssoc($rVariables)) {
- $output[$aRow['variable_id']] = $aRow;
- }
- return $output;
- }
- }
- function OA_Dal_Delivery_getMaintenanceInfo()
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $result = OA_Dal_Delivery_query("
- SELECT
- value AS maintenance_timestamp
- FROM
- ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['application_variable'])."
- WHERE name = 'maintenance_timestamp'
- ");
- if (!is_resource($result)) {
- return (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) ? OA_DELIVERY_CACHE_FUNCTION_ERROR : null;
- } else {
- $result = OA_Dal_Delivery_fetchAssoc($result);
- return $result['maintenance_timestamp'];
- }
- }
- function OA_Dal_Delivery_buildQuery($part, $lastpart, $precondition)
- {
- $conf = $GLOBALS['_MAX']['CONF'];
- $aColumns = array(
- 'd.bannerid AS ad_id',
- 'd.campaignid AS placement_id',
- 'd.status AS status',
- 'd.description AS name',
- 'd.storagetype AS type',
- 'd.contenttype AS contenttype',
- 'd.pluginversion AS pluginversion',
- 'd.filename AS filename',
- 'd.imageurl AS imageurl',
- 'd.htmltemplate AS htmltemplate',
- 'd.htmlcache AS htmlcache',
- 'd.width AS width',
- 'd.height AS height',
- 'd.weight AS weight',
- 'd.seq AS seq',
- 'd.target AS target',
- 'd.url AS url',
- 'd.alt AS alt',
- 'd.statustext AS statustext',
- 'd.bannertext AS bannertext',
- 'd.adserver AS adserver',
- 'd.block AS block_ad',
- 'd.capping AS cap_ad',
- 'd.session_capping AS session_cap_ad',
- 'd.compiledlimitation AS compiledlimitation',
- 'd.acl_plugins AS acl_plugins',
- 'd.prepend AS prepend',
- 'd.append AS append',
- 'd.bannertype AS bannertype',
- 'd.alt_filename AS alt_filename',
- 'd.alt_imageurl AS alt_imageurl',
- 'd.alt_contenttype AS alt_contenttype',
- 'd.parameters AS parameters',
- 'd.transparent AS transparent',
- 'd.ext_bannertype AS ext_bannertype',
- 'az.priority AS priority',
- 'az.priority_factor AS priority_factor',
- 'az.to_be_delivered AS to_be_delivered',
- 'm.campaignid AS campaign_id',
- 'm.priority AS campaign_priority',
- 'm.weight AS campaign_weight',
- 'm.companion AS campaign_companion',
- 'm.block AS block_campaign',
- 'm.capping AS cap_campaign',
- 'm.session_capping AS session_cap_campaign',
- 'm.show_capped_no_cookie AS show_capped_no_cookie',
- 'm.clickwindow AS clickwindow',
- 'm.viewwindow AS viewwindow',
- 'cl.clientid AS client_id',
- 'm.expire_time AS expire_time',
- 'm.revenue_type AS revenue_type',
- 'm.ecpm_enabled AS ecpm_enabled',
- 'm.ecpm AS ecpm',
- 'cl.advertiser_limitation AS advertiser_limitation',
- 'a.account_id AS account_id',
- 'a.agencyid AS agency_id'
- );
- $aTables = array(
- "".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['banners'])." AS d",
- "JOIN ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['campaigns'])." AS m ON (d.campaignid = m.campaignid) ",
- "JOIN ".OX_escapeIdentifier($conf['table']['prefix'].$conf['table']['clients'])." AS cl ON (m.clientid = cl.clienti…
Large files files are truncated, but you can click here to view the full file