'',
'host' => 'web.adblade.com',
'protocol' => 'http',
'type' => 2,
'width' => 1,
'height' => 1,
),
$atts
);
// do nothing if no container id was set
if (empty($a['container_id'])) {
return '';
}
return sprintf(
'',
$a['container_id'], $a['host'], $a['protocol'], $a['width'], $a['height'], $a['type'], $a['protocol'], $a['host']
);
}
add_shortcode('adblade', 'adblade_func');
/**
* Add scripts to page.
*/
add_action('wp_enqueue_scripts', 'adblade_enqueue_scripts');
function adblade_enqueue_scripts() {
wp_enqueue_script('blockadblock', plugins_url() . '/ablade/js/blockadblock.js');
wp_enqueue_script('log-ab', plugins_url() . '/ablade/js/log-ab.php');
}
/**
* Make requests to the adblade servers.
* @param $host
* $param $path
*/
function adblade_proxy($host, $path) {
// make sure it is an adblade domain
if (strpos($host, 'adblade') === false) {
return;
}
$bypassUrl = plugins_url() . '/ablade/bypass.php?path=';
$replacements = array(
'http://staticd.cdn.adblade.com' => $bypassUrl,
'https://staticd.cdn.adblade.com' => $bypassUrl,
'ad_type_1' => 'blade_type_1'
);
// make the request
$response = wp_remote_get(
sprintf('http://%s%s', $host, $path),
array(
'user-agent' => 'Adblade WordPress plugin',
'headers' => array(
'X-Forwarded-For' => array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']
)
)
);
// add the content type header, if one was sent from adblade
if (array_key_exists('content-type', $response['headers'])) {
header('Content-type: ' . $response['headers']['content-type']);
}
// replace anything that an ad blocker might not like
echo str_replace(array_keys($replacements), array_values($replacements), $response['body']);
}