Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
ad_channel.inc uses its own path matching which does not work on localhost sites. Drupal core provides drupal_match_path() which should be used instead.
The current check in ad_channel_cache_filter() can be simplified to
foreach ($channels['ads'][$aid] as $chid) {
$channel = $channels['channels'][$chid];
$display_by_url = $channel->display;
$urls = unserialize($channel->urls);
$path = drupal_get_path_alias($_GET['q']);
// Compare with the internal and path alias (if any).
$page_match = drupal_match_path($path, $urls);
_debug_echo("ad_channel_cache: checking aid($aid) against channel($chid) path(". adserve_variable($search) .") regexp($regexp) match($match) display[$display_by_url]");
// display ad on all except matching urls
if ($display_by_url == 0) {
if (empty($urls) || !$page_match) {
_debug_echo("ad_channel_cache: aid($aid) is valid");
$valid_ads[$chid][] = $aid;
if ($nochannel_display == 1) {
$nochannel_percent[$chid] = $channel->no_channel_percent;
_debug_echo("ad_channel_cache: channel($chid) no_channel_percent($nochannel_percent[$chid])");
}
else {
_debug_echo("ad_channel_cache: channel($chid)");
}
break;
}
}
// display ad on matching urls
else {
if (!empty($urls) && $page_match) {
_debug_echo("ad_channel_cache: aid($aid) is valid");
$valid_ads[$chid][] = $aid;
if ($nochannel_display == 1) {
$nochannel_percent[$chid] = $channel->no_channel_percent;
_debug_echo("ad_channel_cache: channel($chid) no_channel_percent($nochannel_percent[$chid])");
}
else {
_debug_echo("ad_channel_cache: channel($chid)");
}
break;
}
}
// no match so we didn't hit a break, ad is not valid
_debug_echo("ad_channel_cache: aid($aid) is not valid");
}