function ad_redirect in Advertisement 5.2
Same name and namespace in other branches
- 5 ad.module \ad_redirect()
- 6.3 ad.module \ad_redirect()
- 6 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 172 - An advertising system for Drupal powered websites.
Code
function ad_redirect($aid, $group = NULL, $extra = NULL, $hostid = NULL) {
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.
if (!($url = $_GET['u']) || !valid_url($url)) {
$url = referer_uri();
}
db_query("INSERT INTO {ad_clicks} (aid, uid, status, hostname, user_agent, adgroup, extra, hostid, url, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $aid, $user->uid, $status, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $group, $extra, $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', t('Clicked %type ad aid %aid hostid %hostid.', array(
'%type' => $adtype,
'%aid' => $aid,
'%hostid' => $hostid,
)));
header('Location: ' . $url);
}
else {
watchdog('ad', t('Ad redirection failed for aid %aid hostid %hostid, failed to load destination URL. ', array(
'%aid' => $aid,
'%hostid' => $hostid,
)));
drupal_goto('');
}
}