function phpAds_fetchBannerDirect($remaining, $clientid = 0, $campaignid = 0, $context = 0, $source = '', $richmedia = true) { global $phpAds_config; /* //log ob_start(); print_r($GLOBALS); $log = ob_get_contents(); ob_end_clean(); $fh = @fopen('/var/www/html/origin.awarez.net/cache/mydebug.log','a'); @fwrite($fh, $log); @fclose($fh); */ // Get first part, store second part $what = strtok($remaining, '|'); $remaining = strtok(''); // Expand paths to regular statements if (strpos($what, '/') > 0) { if (strpos($what, '@') > 0) { list($what, $append) = explode('@', $what); } else { $append = ''; } $seperate = explode('/', $what); $expanded = ''; $collected = array(); while (list(, $v) = each($seperate)) { $expanded .= ($expanded != '' ? ',+' : '') . $v; $collected[] = $expanded . ($append != '' ? ',+' . $append : ''); } $what = strtok(implode('|', array_reverse($collected)), '|'); $remaining = strtok('') . ($remaining != '' ? '|' . $remaining : ''); } $cacheid = 'what=' . $what . '&clientid=' . $clientid . '&campaignid=' . $campaignid . '&remaining=' . ($remaining == '' ? 'true' : 'false'); // Get cache if (!defined('LIBVIEWCACHE_INCLUDED')) { include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php'; } $cache = phpAds_cacheFetch($cacheid); if (!$cache) { if (!defined('LIBVIEWQUERY_INCLUDED')) { include phpAds_path . '/libraries/lib-view-query.inc.php'; } if ($campaignid > 0) { $precondition = " AND " . $phpAds_config['tbl_campaigns'] . ".campaignid=" . $campaignid . " "; } elseif ($clientid > 0) { $precondition = " AND " . $phpAds_config['tbl_campaigns'] . ".clientid=" . $clientid . " "; } else { $precondition = ''; } $select = phpAds_buildQuery($what, $remaining == '', $precondition); $res = phpAds_dbQuery($select); // Build array for further processing... $rows = array(); $prioritysum = 0; while ($tmprow = phpAds_dbFetchArray($res)) { // weight of 0 disables the banner if ($tmprow['priority']) { $prioritysum += $tmprow['priority']; $rows[] = $tmprow; } } $cache = array($rows, $what, $prioritysum); phpAds_cacheStore($cacheid, $cache); // Unpack cache list($rows, $what, $prioritysum) = $cache; } else { // Unpack cache list($rows, $what, $prioritysum) = $cache; } // Build preconditions $excludeBannerID = array(); $excludeCampaignID = array(); $includeBannerID = array(); $includeCampaignID = array(); if (is_array($context)) { for ($i = 0; $i < count($context); $i++) { list($key, $value) = each($context[$i]); $type = 'bannerid'; $valueArray = explode(':', $value); if (count($valueArray) == 1) { list($value) = $valueArray; } else { list($type, $value) = $valueArray; } if ($type == 'bannerid') { switch ($key) { case '!=': $excludeBannerID[$value] = true; break; case '==': $includeBannerID[$value] = true; break; } } if ($type == 'campaignid') { switch ($key) { case '!=': $excludeCampaignID[$value] = true; break; case '==': $includeCampaignID[$value] = true; break; } } } } $maxindex = sizeof($rows); while ($prioritysum && sizeof($rows)) { $low = 0; $high = 0; $ranweight = $prioritysum > 1 ? mt_rand(0, $prioritysum - 1) : 0; for ($i = 0; $i < $maxindex; $i++) { if (is_array($rows[$i])) { $low = $high; $high += $rows[$i]['priority']; if ($high > $ranweight && $low <= $ranweight) { $postconditionSucces = true; // Excludelist banners if (isset($excludeBannerID[$rows[$i]['bannerid']])) { $postconditionSucces = false; } elseif (isset($excludeCampaignID[$rows[$i]['clientid']])) { $postconditionSucces = false; } elseif (sizeof($includeBannerID) && !isset($includeBannerID[$rows[$i]['bannerid']])) { $postconditionSucces = false; } elseif (sizeof($includeCampaignID) && !isset($includeCampaignID[$rows[$i]['clientid']])) { $postconditionSucces = false; } elseif ($richmedia == false && ($rows[$i]['contenttype'] != 'jpeg' && $rows[$i]['contenttype'] != 'gif' && $rows[$i]['contenttype'] != 'png')) { $postconditionSucces = false; } elseif (phpAds_isAdBlocked($rows[$i]['bannerid'], $rows[$i]['block'])) { $postconditionSucces = false; } elseif (phpAds_isAdCapped($rows[$i]['bannerid'], $rows[$i]['capping'], $rows[$i]['session_capping'])) { $postconditionSucces = false; } if ($postconditionSucces == false) { // Failed one of the postconditions // Delete this row and adjust $prioritysum $prioritysum -= $rows[$i]['priority']; $rows[$i] = ''; // Break out of the for loop to try again break; } // Banner was not on exclude list // and was on include list (if one existed) // Now continue with ACL check if ($phpAds_config['acl']) { if (phpAds_aclCheck($rows[$i], $source)) { $rows[$i]['zoneid'] = 0; return $rows[$i]; } // Matched, but phpAds_aclCheck failed. // Delete this row and adjust $prioritysum $prioritysum -= $rows[$i]['priority']; $rows[$i] = ''; // Break out of the for loop to try again break; } else { // Don't check ACLs, found banner! $rows[$i]['zoneid'] = 0; return $rows[$i]; } } } } } return $remaining; }
function phpAds_fetchBannerZone($remaining, $clientid, $campaignid, $context = 0, $source = '', $richmedia = true) { global $phpAds_config; global $phpAds_followedChain; // Get first part, store second part $what = strtok($remaining, '|'); $remaining = strtok(''); $zoneid = substr($what, 5); // Check if zone was already evaluated in the chain if (isset($phpAds_followedChain) && in_array($zoneid, $phpAds_followedChain)) { return $remaining; } else { $phpAds_followedChain[] = $zoneid; } // Get cache if (!defined('LIBVIEWCACHE_INCLUDED')) { include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php'; } $cache = phpAds_cacheFetch('what=zone:' . $zoneid); if (!$cache) { $zoneres = phpAds_dbQuery("SELECT * FROM " . $phpAds_config['tbl_zones'] . " WHERE zoneid='" . $zoneid . "'"); if ($zone = phpAds_dbFetchArray($zoneres)) { // No linked banners if ($remaining == '') { $remaining = $zone['chain']; } if ($zone['what'] == '') { return $remaining; } if (!defined('LIBVIEWQUERY_INCLUDED')) { include phpAds_path . '/libraries/lib-view-query.inc.php'; } $precondition = ''; // Size preconditions if ($zone['width'] > -1) { $precondition .= " AND " . $phpAds_config['tbl_banners'] . ".width = " . $zone['width'] . " "; } if ($zone['height'] > -1) { $precondition .= " AND " . $phpAds_config['tbl_banners'] . ".height = " . $zone['height'] . " "; } // Text Ads preconditions // Matching against the value instead of the constant phpAds_ZoneText (3). // Didn't want to include the whole lib-zones just for a constant if ($zone['delivery'] == 3) { $precondition .= " AND " . $phpAds_config['tbl_banners'] . ".storagetype = 'txt' "; } else { $precondition .= " AND " . $phpAds_config['tbl_banners'] . ".storagetype <> 'txt' "; } $select = phpAds_buildQuery($zone['what'], false, $precondition); $res = phpAds_dbQuery($select); // Build array for further processing... $rows = array(); $prioritysum = 0; while ($tmprow = phpAds_dbFetchArray($res)) { // weight of 0 disables the banner if ($tmprow['priority']) { $prioritysum += $tmprow['priority']; $rows[] = $tmprow; } } $cache = array($zone['zoneid'], $rows, $zone['what'], $prioritysum, $zone['chain'], $zone['prepend'], $zone['append']); phpAds_cacheStore('what=zone:' . $zone['zoneid'], $cache); // Unpack cache list($zoneid, $rows, $what, $prioritysum, $chain, $prepend, $append) = $cache; } else { // Zone not found return $remaining; } } else { // Unpack cache list($zoneid, $rows, $what, $prioritysum, $chain, $prepend, $append) = $cache; if ($remaining == '') { $remaining = $chain; } if (count($rows) == 0) { return $remaining; } } // Build preconditions $excludeBannerID = array(); $excludeCampaignID = array(); $includeBannerID = array(); $includeCampaignID = array(); if (is_array($context)) { for ($i = 0; $i < count($context); $i++) { list($key, $value) = each($context[$i]); $type = 'bannerid'; $valueArray = explode(':', $value); if (count($valueArray) == 1) { list($value) = $valueArray; } else { list($type, $value) = $valueArray; } if ($type == 'bannerid') { switch ($key) { case '!=': $excludeBannerID[$value] = true; break; case '==': $includeBannerID[$value] = true; break; } } if ($type == 'campaignid') { switch ($key) { case '!=': $excludeCampaignID[$value] = true; break; case '==': $includeCampaignID[$value] = true; break; } } } } $maxindex = sizeof($rows); while ($prioritysum && sizeof($rows)) { $low = 0; $high = 0; $ranweight = $prioritysum > 1 ? mt_rand(0, $prioritysum - 1) : 0; for ($i = 0; $i < $maxindex; $i++) { if (is_array($rows[$i])) { $low = $high; $high += $rows[$i]['priority']; if ($high > $ranweight && $low <= $ranweight) { $postconditionSucces = true; // Excludelist banners if (isset($excludeBannerID[$rows[$i]['bannerid']])) { $postconditionSucces = false; } elseif (isset($excludeCampaignID[$rows[$i]['campaignid']])) { $postconditionSucces = false; } elseif (sizeof($includeBannerID) && !isset($includeBannerID[$rows[$i]['bannerid']])) { $postconditionSucces = false; } elseif (sizeof($includeCampaignID) && !isset($includeCampaignID[$rows[$i]['campaignid']])) { $postconditionSucces = false; } elseif ($richmedia == false && ($rows[$i]['contenttype'] != 'jpeg' && $rows[$i]['contenttype'] != 'gif' && $rows[$i]['contenttype'] != 'png')) { $postconditionSucces = false; } elseif (phpAds_isAdBlocked($rows[$i]['bannerid'], $rows[$i]['block'])) { $postconditionSucces = false; } elseif (phpAds_isAdCapped($rows[$i]['bannerid'], $rows[$i]['capping'], $rows[$i]['session_capping'])) { $postconditionSucces = false; } if ($postconditionSucces == false) { // Failed one of the postconditions // Delete this row and adjust $prioritysum $prioritysum -= $rows[$i]['priority']; $rows[$i] = ''; // Break out of the for loop to try again break; } // Banner was not on exclude list // and was on include list (if one existed) // Now continue with ACL check if ($phpAds_config['acl']) { if (phpAds_aclCheck($rows[$i], $source)) { $rows[$i]['zoneid'] = $zoneid; $rows[$i]['append'] = $append; $rows[$i]['prepend'] = $prepend; return $rows[$i]; } // Matched, but phpAds_aclCheck failed. // Delete this row and adjust $prioritysum $prioritysum -= $rows[$i]['priority']; $rows[$i] = ''; // Break out of the for loop to try again break; } else { // Don't check ACLs, found banner! $rows[$i]['zoneid'] = $zoneid; $rows[$i]['append'] = $append; $rows[$i]['prepend'] = $prepend; return $rows[$i]; } } } } } return $remaining; }