OK - I think I have working properly now. Code for plugin below. Ads don;t show up all teh time and after a bunch of refreshes they go a way for a while. This is a google thing and I guess it depends on your sites content and who is advertising? Anyway - the following seems to work for me. It is set for showing ads just before the quick reply, but you can change the ad_location in the code to show them after first post by searching and replacing
ad_showthread_beforeqr for
ad_showthread_firstpost in the plugin code...
Get your mobile adsense PHP code - here's the code Google game me (DO NOT USE THIS - GET YOUR OWN)
PHP Code:
<?php
$GLOBALS['google']['ad_type']='text';
$GLOBALS['google']['channel']='0000000000';
$GLOBALS['google']['client']='pub-0000000000000000';
$GLOBALS['google']['format']='mobile_single';
$GLOBALS['google']['https']=$_SERVER['HTTPS'];
$GLOBALS['google']['host']=$_SERVER['HTTP_HOST'];
$GLOBALS['google']['ip']=$_SERVER['REMOTE_ADDR'];
$GLOBALS['google']['markup']='xhtml';
$GLOBALS['google']['oe']='utf8';
$GLOBALS['google']['output']='xhtml';
$GLOBALS['google']['ref']=$_SERVER['HTTP_REFERER'];
$GLOBALS['google']['url']=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$GLOBALS['google']['useragent']=$_SERVER['HTTP_USER_AGENT'];
$google_dt = time();
google_set_screen_res();
function google_append_url(&$url, $param, $value) {
$url .= '&' . $param . '=' . urlencode($value);
}
function google_append_globals(&$url, $param) {
google_append_url($url, $param, $GLOBALS['google'][$param]);
}
function google_append_color(&$url, $param) {
global $google_dt;
$color_array = split(',', $GLOBALS['google'][$param]);
google_append_url($url, $param,
$color_array[$google_dt % sizeof($color_array)]);
}
function google_set_screen_res() {
$screen_res = $_SERVER['HTTP_UA_PIXELS'];
$delimiter = 'x';
if ($screen_res == '') {
$screen_res = $_SERVER['HTTP_X_UP_DEVCAP_SCREENPIXELS'];
$delimiter = ',';
}
$res_array = explode($delimiter, $screen_res);
if (sizeof($res_array) == 2) {
$GLOBALS['google']['u_w'] = $res_array[0];
$GLOBALS['google']['u_h'] = $res_array[1];
}
}
function google_get_ad_url() {
$google_ad_url = 'http://pagead2.googlesyndication.com/pagead/ads?';
$google_scheme = ($GLOBALS['google']['https'] == 'on')
? 'https://' : 'http://';
foreach ($GLOBALS['google'] as $param => $value) {
if ($param == 'client') {
google_append_url($google_ad_url, $param,
'ca-mb-' . $GLOBALS['google'][$param]);
} else if (strpos($param, 'color_') === 0) {
google_append_color($google_ad_url, $param);
} else if ((strpos($param, 'host') === 0)
|| (strpos($param, 'url') === 0)) {
google_append_url($google_ad_url, $param,
$google_scheme . $GLOBALS['google'][$param]);
} else {
google_append_globals($google_ad_url, $param);
}
}
google_append_url($google_ad_url, 'dt',
round(1000 * array_sum(explode(' ', microtime()))));
return $google_ad_url;
}
$google_ad_handle = @fopen(google_get_ad_url(), 'r');
if ($google_ad_handle) {
while (!feof($google_ad_handle)) {
echo fread($google_ad_handle, 8192);
}
fclose($google_ad_handle);
}
?>
I had to move al the functions to the top of the code block for it to work in a plug in I created a called "Google Adsense Mobile" on the showthread_start hook. Here is the working plugin code:
PHP Code:
if ($styleid == xx) {
function google_append_url(&$url, $param, $value) {
$url .= '&' . $param . '=' . urlencode($value);
}
function google_append_globals(&$url, $param) {
google_append_url($url, $param, $GLOBALS['google'][$param]);
}
function google_append_color(&$url, $param) {
global $google_dt;
$color_array = split(',', $GLOBALS['google'][$param]);
google_append_url($url, $param,
$color_array[$google_dt % sizeof($color_array)]);
}
function google_set_screen_res() {
$screen_res = $_SERVER['HTTP_UA_PIXELS'];
$delimiter = 'x';
if ($screen_res == '') {
$screen_res = $_SERVER['HTTP_X_UP_DEVCAP_SCREENPIXELS'];
$delimiter = ',';
}
$res_array = explode($delimiter, $screen_res);
if (sizeof($res_array) == 2) {
$GLOBALS['google']['u_w'] = $res_array[0];
$GLOBALS['google']['u_h'] = $res_array[1];
}
}
function google_get_ad_url() {
$google_ad_url = 'http://pagead2.googlesyndication.com/pagead/ads?';
$google_scheme = ($GLOBALS['google']['https'] == 'on')
? 'https://' : 'http://';
foreach ($GLOBALS['google'] as $param => $value) {
if ($param == 'client') {
google_append_url($google_ad_url, $param,
'ca-mb-' . $GLOBALS['google'][$param]);
} else if (strpos($param, 'color_') === 0) {
google_append_color($google_ad_url, $param);
} else if ((strpos($param, 'host') === 0)
|| (strpos($param, 'url') === 0)) {
google_append_url($google_ad_url, $param,
$google_scheme . $GLOBALS['google'][$param]);
} else {
google_append_globals($google_ad_url, $param);
}
}
google_append_url($google_ad_url, 'dt',
round(1000 * array_sum(explode(' ', microtime()))));
return $google_ad_url;
}
$GLOBALS['google']['ad_type']='text';
$GLOBALS['google']['channel']='0000000000';
$GLOBALS['google']['client']='pub-0000000000000000';
$GLOBALS['google']['format']='mobile_single';
$GLOBALS['google']['https']=$_SERVER['HTTPS'];
$GLOBALS['google']['host']=$_SERVER['HTTP_HOST'];
$GLOBALS['google']['ip']=$_SERVER['REMOTE_ADDR'];
$GLOBALS['google']['markup']='xhtml';
$GLOBALS['google']['oe']='utf8';
$GLOBALS['google']['output']='xhtml';
$GLOBALS['google']['ref']=$_SERVER['HTTP_REFERER'];
$GLOBALS['google']['url']=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$GLOBALS['google']['useragent']=$_SERVER['HTTP_USER_AGENT'];
$google_dt = time();
google_set_screen_res();
$find='"';
$replace="'";
$googlemad = '';
$google_ad_handle = @fopen(google_get_ad_url(), 'r');
if ($google_ad_handle) {
while (!feof($google_ad_handle)) {
$googlemad .= fread($google_ad_handle, 8192);
}
fclose($google_ad_handle);
}
$vbulletin->templatecache['ad_showthread_beforeqr'] = str_replace($find,$replace,$googlemad);
}
You'll see I wrapped the google code in a conditional
if ($styleid == xx) { ...
} where xx is the styleid of my mobile style - you will need to change this and removed the opening and closing php tags.
The other changes (after moving the functions to the top) were:
1. replace
PHP Code:
$google_dt = time();
google_set_screen_res();
with
PHP Code:
$google_dt = time();
google_set_screen_res();
$find='"';
$replace="'";
$googlemad = '';
2. replace
PHP Code:
echo fread($google_ad_handle, 8192);
}
fclose($google_ad_handle);
}
with
PHP Code:
$googlemad .= fread($google_ad_handle, 8192);
}
fclose($google_ad_handle);
}
$vbulletin->templatecache['ad_showthread_beforeqr'] = str_replace($find,$replace,$googlemad);
That's about it. You could modify and or duplicate this to work with other ad_locations. Current defined ad_locations in vBulletin 3.7 (and this style) and the likely best hook location for these ads are (i'm not so sure about the ones in
blue - they should work there, but there may be a more efficient place to put them. Feedback welcomed!):
ad_footer_start - global_start
ad_footer_end - global_start
ad_forumdisplay_afterthreads -
forum_display_start
ad_forumhome_afterforums -
forum_home_start
ad_header_end - global_start
ad_header_logo - global_start
ad_navbar_below - global_start
ad_showthread_beforeqr -
showthread_start
ad_showthread_firstpost -
showthread_start
Hope this helps!