Jump to content

davidm

Approved members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by davidm

  1. I got ads working async in 2011 via a lot of messy workarounds. I posted how I did it on the OX forums but I think it got buried under spam and whatever else is in there. It would be good to see Revive have a way to easily do async ad loading, but until that day comes, this is what worked for me: 1. You need to use the XMLRPC interface. So you need to copy the lib/xmlrpc/php/openads-xmlrpc.inc.php file to your website. 2. This method assumes you're using jQuery and have the migration plugin enabled, as it relies on $.browser.msie checks because it turns out IE can't handle using document.write on an iframe that is created dynamically (it'll write the content to the iframe, but it won't actually process it as being HTML content and just show everything as blank). So my workaround for that is the ad code for that impression is saved to memcache, then the iframe is set to a page that just loads the impression from memcache. A bit annoying but it works. 3. I'm also assuming you have memcached installed. You can write some sort of alternative thing that uses temporary files if you don't have memcache, but this was the simplest for me. 4. Have a line similar to this in your page: $(document).ready(function() { $.getScript("//websitegoeshere.com/includes/openx.php"); }); 5. The contents of openx.php are this (note that flat-out copypasta of this code will not work): <?php ob_start('ob_gzhandler'); set_time_limit(15); header('Content-Type: application/x-javascript'); // Set $server to the location of your ad server $server = 'adservergoeshere.com'; require(ROOT_DIR . '/includes/config.php'); require(ROOT_DIR . '/includes/functions.php'); require(ROOT_DIR . '/includes/openads-xmlrpc.inc.php'); if (!isset($OA_context)) $OA_context = array(); $oaXmlRpc = new OA_XmlRpc($server, '/www/delivery/axmlrpc.php', $_SERVER['HTTPS'] ? 443 : 80, $_SERVER['HTTPS'] ? true : false, 15); $openx = array(); $adzones = array( 'headerad' => 97, 'bodyad' => 98, 'boxtop' => 99, 'boxmiddle' => 106, 'boxbottom' => 100 ); foreach ($adzones as $key => $val) { $openx[$key] = $oaXmlRpc->view('zone:' . $val, 0, '', '', 0, $OA_context, 'UTF-8'); $OA_context[] = array('!=' => 'campaignid:' . $openx[$key]['campaignid']); } foreach ($openx as $key => &$val) { $val['html'] = str_replace('&amp;', '&', $val['html']); $val['html'] = str_replace('&', '&amp;', $val['html']); if ($val['aSearch'] && $val['aReplace']) { $val['html'] = str_replace($val['aSearch'], $val['aReplace'], $val['html']); $val['html'] = str_replace(str_replace(array('{', '}'), array('[', ']'), $val['aSearch']), $val['aReplace'], $val['html']); if (extension_loaded('memcache') && (preg_match('/MSIE|Internet Explorer/i', $_SERVER['HTTP_USER_AGENT'])) && (preg_match('/^<script/i', $val['html']))) { $uid = uniqid(); $val['uid'] = $uid; $memcache = getMemcache(); $memcache->set('tmpad:' . $uid, $val['html'], MEMCACHE_COMPRESSED, time() + 120); } } //if ($_SERVER['HTTPS']) $val['logUrl'] = preg_replace('/^http:\/\//', 'https://', $val['logUrl']); } echo 'var openx = ' . json_encode($openx) . ";\n"; ?> var oxserver = "http<?php if ($_SERVER['HTTPS']) echo 's'; ?>://<?php echo $server; ?>"; $(document).ready(function() { for (var z in openx) { var adbox = $("#" + z + ".adbox"); if ($(adbox).length) { var ad = openx[z]; ad['spot'] = z; if ((ad['html'].length) || (ad['contenttype'] == 'swf')) { var adcontent = $(adbox).children(); $(adbox).empty().append($("<div>").addClass("adnote").text("Advertisement")).append($("<div>").addClass("ad").append(adcontent)); if (ad['contenttype'] == 'swf') { drawFlashAd(ad); } else { if ((ad['html'].substr(0, 7) == "<scr"+"ipt") || (ad['html'].substr(0, 7) == "<SCR"+"IPT")) { drawIFrameAd(ad); } else { $(adbox).children(".ad").html(ad['html']); } } } else { $(adbox).css({display: "none"}); } } } }); function drawIFrameAd(ad) { var oxid = "ox_" + new Date().getTime(); var iframe = $("<iframe>").attr({name: oxid, id: oxid, width: ad['width'], height: ad['height'], frameborder: 0, scrolling: "no", vspace: 0, hspace: 0, marginheight: 0, marginwidth: 0}); var content = "<html><body>" + ad['html'] + "</body></html>"; if ($.browser.msie) $(iframe).attr({src: "/includes/adpage.php?ad=" + ad['uid']}); $("#" + ad['spot'] + " > .ad").append($(iframe)); if (!$.browser.msie) { var ifrm = $("#" + oxid).get(0); ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument; ifrm.document.open(); ifrm.document.write(content); ifrm.document.close(); } drawBeacon(oxid, ad); } function drawFlashAd(ad) { $.ajax({url: oxserver + "/www/delivery/fl.js", cache: true, dataType: "script", success: function() { var oxid = "ox_" + new Date().getTime(); var oxlink = $("<a>").attr({href: ad['clickUrl']}); var oximg = $("<img>").attr({src: ad['bannerContent'], width: ad['width'], height: ad['height'], alt: ad['alt'], title: ad['alt'], border: 0}); $("#" + ad['spot'] + " > .ad").append($("<div>").attr({id: oxid}).css({display: "inline"}).append($(oxlink).append($(oximg)))); var ox_swf = new FlashObject(oxserver + "/www/images/" + ad['aRow']['filename'], oxid, ad['width'], ad['height'], ad['aRow']['pluginversion']); var oxvars = /ox_swf\.addVariable\('([^']+)', '([^']+)'\);/g; var match; while (match = oxvars.exec(ad['html'])) { ox_swf.addVariable(match[1], match[2]); } ox_swf.addParam('allowScriptAccess','always'); ox_swf.addParam('wmode', 'opaque'); ox_swf.write(oxid); drawBeacon(oxid, ad); }}); } function drawBeacon(oxid, ad) { var beacon = $("<div>").attr({id: "beacon_" + oxid}).css({position: "absolute", left: "0px", top: "0px", visibility: "hidden"}); var bimg = $("<img>").attr({src: ad['logUrl'], width: 0, height: 0, alt: ""}).css({width: "0px", height: "0px"}); $("#" + ad['spot'] + " > .ad").append($(beacon).append($(bimg))); } The config.php and functions.php includes just contain my passwords/server details and a getMemcache function (which just returns a memcache object). ROOT_DIR is just a reference to $_SERVER['DOCUMENT_ROOT'] that is auto-appended to the start of my pages. The $adzones array is a list of zone IDs for your ads. The keys should be the IDs of the zones on the page (so on your page you should have <div class="adbox" id="keyname"></div> for each ad), and the values should be their corresponding ID numbers within Revive. You'll see that there's a reference to adpage.php - this is my alternate way of getting iframe ads to work in IE. The contents of adpage.php is this: <html><body><?php require(ROOT_DIR . '/includes/config.php'); require(ROOT_DIR . '/includes/functions.php'); $memcache = getMemcache(); $adid = $_GET['ad']; if (!preg_match('/^[0-9A-Za-z]+$/', $ad)) die(); $ad = $memcache->get('tmpad:' . $adid, MEMCACHE_COMPRESSED); $memcache->delete('tmpad:' . $adid); echo $ad; ?></body></html> This should give you async loading for image/Flash ads as well as third-party ones. We haven't used other ad types here so I don't know how they'll go with this.
×
×
  • Create New...