ajaxloading OpenX的使用jQuery和PHPOpenX、ajaxloading、PHP、jQuery

2023-09-11 00:59:52 作者:恋人手心

经过长途跋涉,我设法AJAX的载入我的OpenX,广告与jQuery的组合的PHP。

您需要的是

在自己的的OpenX服务器和访问/{openxPath}/www/delivery/alocal.php。 在一个小包装,使广告脚本ajaxable 在一个Ajax-loader在

第三个也是最容易的部分是阿贾克斯装载机:

  $(文件)。就绪(函数(){
    $阿贾克斯({
        网址:HTTP:// {urlToYourOpenxWrapper / adwrapper.php
        键入:POST,
        数据:{M:'F'},//广告'code'来加载
        异步:假的,
        数据类型:HTML
    })。完成(功能(回答){
        $('#footerBanner)HTML(答案);
    });
});
 

第二部分是有点棘手的也许不是面向未来的。但对于2.8.11这是工作。 为了安全起见,我从字符区ID的映射。我不知道这是不是真的有必要的。

adwrapper.php:

 定义(MAX_PATH','pathToYoutOpenXServer');
如果(@include_once(MAX _'/www/delivery/alocal.php')){
    如果(!使用isset($ phpAds_context)){
        $ phpAds_context =阵列();
    }
    开关($ _ POST [M]){
        案例'F':广告的// code加载
            $了zoneid = 12;
            $ bannerTarget ='footerBanner zone_。 $了zoneid;
            $横幅code = view_local('',12,0,0,'','','0',$ phpAds_context,'');
            打破;
    }
      //获取旗帜ID
    $正则表达式='/(.*)(ox_[^\']*)(.*)/';
    preg_match($正则表达式,$横幅code ['HTML'],$匹配);
    $ OXID = $火柴[2];
      //编译新的插入code
    $ replaceWith ='$('$氧化氮。')。经过';
    $旗帜= str_replace函数('文件撰写',$ replaceWith,$横幅code ['HTML']);
    $旗帜= str_replace函数('<脚本类型= \文/ JavaScript的\'SRC = \'的http://openx.lift-online.de/www/delivery/fl.js \>< / SCRIPT> ',
        '&所述;! - 取代 - >' ,
        $旗);

      //使用一个对象,为每个广告以prevent问题,在多任务处理
    $旗帜= str_replace函数('ox_swf','ox_swf_'$了zoneid,$旗帜。);

      //一段时间的氧化氮(唯一ID ???)是一样的,比区混合
      //所以我追加了zoneid到OXID
    $旗帜= str_replace函数($ OXID,$氧化氮'_'$了zoneid,$横幅。);
    回声'< D​​IV CLASS ='。$ bannerTarget。'> 。 $旗帜。 '< / DIV>';
}
 
为什么越来越少的人用jQuery

解决方案

感谢,改进,并不能失败,失败,但是从你很好的解决方案!

我只需要使用GET请求,必须添加对PHP的包装

 标题(访问控制 - 允许 - 产地:*);
标题(访问控制请求-方法:GET);
 

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>';
}

解决方案

Thanks, working on it and fail fail fail, but great solution from you !

I just need using GET request and must add on the php wrapper

header("Access-Control-Allow-Origin: *");
header("Access-Control-Request-Method: GET");