after a long journey I managed to ajax-load my openx-ads with a combination of jquery an php.
You need is
- an openx-server on your own and access to /{openxPath}/www/delivery/alocal.php.
- a little wrapper that makes the ad-script ajaxable
- an ajax-loader
The third and easiest part is the ajax-loader:
$(document).ready( function() {
$.ajax({
url: "http://{urlToYourOpenxWrapper/adwrapper.php",
type: "POST",
data: {m:'f'}, // 'code' of ad to load
async: false,
dataType: 'html'
}).done(function (answer) {
$('#footerBanner').html(answer);
});
});
The second part is a little bit tricky an maybe not future-proof. But for 2.8.11 it is working. For security reasons I made a mapping from characters to zone-ids. I don't know if this is really necessary.
adwrapper.php:
define('MAX_PATH', 'pathToYoutOpenXServer');
if (@include_once(MAX_PATH . '/www/delivery/alocal.php')) {
if (!isset($phpAds_context)) {
$phpAds_context = array();
}
switch ($_POST["m"]) {
case 'f': // code of the ad to load
$zoneId = 12;
$bannerTarget = 'footerBanner zone_' . $zoneId;
$bannerCode = view_local('', 12, 0, 0, '', '', '0', $phpAds_context, '');
break;
}
// get banner id
$regex = '/(.*)(ox_[^\']*)(.*)/';
preg_match($regex, $bannerCode['html'], $matches);
$oxId = $matches[2];
// compile new insert code
$replaceWith = '$("' . $oxId . '").after';
$banner = str_replace('document.write', $replaceWith, $bannerCode['html']);
$banner = str_replace('<script type=\'text/javascript\' src=\'http://openx.lift-online.de/www/delivery/fl.js\'></script>' ,
'<!-- replaced -->' ,
$banner);
// use a single object for each ad to prevent problem in multitasking
$banner = str_replace('ox_swf', 'ox_swf_' . $zoneId, $banner);
// sometime the oxId (unique Id???) is the same and than zones are mixed
// so I append the zoneId to the oxId
$banner = str_replace($oxId, $oxId . '_' . $zoneId, $banner);
echo '<div class="' . $bannerTarget . '">' . $banner . '</div>';
}