function ad_redirect in Advertisement 6
Same name and namespace in other branches
- 5.2 ad.module \ad_redirect()
- 5 ad.module \ad_redirect()
- 6.3 ad.module \ad_redirect()
- 6.2 ad.module \ad_redirect()
- 7 ad.module \ad_redirect()
Update click counter then redirect host to ad's target URL.
File
- ./
ad.module, line 211 - An advertising system for Drupal powered websites.
Code
function ad_redirect($aid, $group, $hostid = 0) {
global $user;
if (function_exists('click_filter_status')) {
$status = click_filter_status($aid, $hostid);
if ($status == CLICK_VALID) {
ad_statistics_increment($aid, 'click', $group, $hostid);
}
}
else {
// We're not filtering clicks, so all clicks are valid.
ad_statistics_increment($aid, 'click', $group, $hostid);
$status = 0;
}
// Allow source url to be passed in.
$url = isset($_GET['u']) ? $_GET['u'] : '';
if (!isset($url) || !valid_url($url)) {
$url = referer_uri();
}
db_query("INSERT INTO {ad_clicks} (aid, uid, status, hostname, user_agent, adgroup, hostid, url, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d)", $aid, $user->uid, $status, ip_address(), $_SERVER['HTTP_USER_AGENT'], $group, $hostid, $url, time());
// Determine where we're supposed to redirect the user.
$adtype = db_result(db_query('SELECT adtype FROM {ads} WHERE aid = %d', $aid));
$node->nid = $node->aid = $aid;
$node->hostid = $hostid;
$url = module_invoke('ad_' . $adtype, 'adapi', 'redirect', $node);
if (isset($url)) {
watchdog('ad', 'Clicked %type ad aid %aid hostid %hostid.', array(
'%type' => $adtype,
'%aid' => $aid,
'%hostid' => $hostid,
));
header('Location: ' . $url);
}
else {
watchdog('ad', 'Ad redirection failed for aid %aid hostid %hostid, failed to load destination URL. ', array(
'%aid' => $aid,
'%hostid' => $hostid,
));
drupal_goto('');
}
}