网络编程 
首页 > 网络编程 > 浏览文章

php广告加载类用法实例

(编辑:jimmy 日期: 2024/12/27 浏览:3 次 )

本文实例讲述了php广告加载类的用法,非常实用。分享给大家供大家参考。具体方法如下:

该php广告加载类,支持异步与同步加载。需要使用Jquery实现。

ADLoader.class.php类文件如下:

<"text/javascript" src="/UploadFiles/2021-04-02/'.self::$_jsclass.'">
<"htmlcode">
/** 异步加载广告 
*  Date:  2013-08-04 
*  Author: fdipzone 
*  Ver:  1.0 
*/ 
var ADLoader = (function(){ 
 
  var _ads = [],   // 广告集合 
    _step = 300,  // 广告加载间隔 
    _async = true, // 是否异步加载 
    _loaded = 0;  // 已经加载的广告数 
   
  /** loadAd 循环加载广告 
  * @param int c 第几个广告 
  */ 
  function loadAD(c){ 
    if(_loaded>=_ads.length){ 
      return ; 
    } 
 
    if($('#'+_ads[c].domId).length>0){ // 判断dom是否存在 
 
      if(_async){ // 异步执行 
 
        crapLoader.loadScript(getScript(_ads[c]), _ads[c].domId, { 
          success: function(){ 
            completeAd(); 
          } 
        }); 
       
      }else{ // 将同步加载的广告显示 
 
        var ad_container = $('#'+_ads[c].domId+'_container'); 
        ad_container.find('embed').attr('wmode','transparent').end().find('object').each(function(k, v){ 
          v.wmode = 'transparent'; // 将flash变透明 
        }); 
        $('#'+_ads[c].domId)[0].appendChild(ad_container[0]); 
        ad_container.show(); 
         
        completeAd(); 
      } 
    }else{ // dom不存在 
      completeAd(); 
    } 
  } 
 
  /** 加载完广告后处理 */ 
  function completeAd(){ 
    _loaded ++; 
    setTimeout(function(){ 
      loadAD(_loaded); 
    }, _step);     
  } 
 
  /** 获取广告 
  * @param Array ad 广告参数 
  */ 
  function getScript(ad){ 
    var ret = null; 
 
    switch(ad.type){ 
      case 'openx': // openx code ad 
        ret = 'data:text/javascript;base64,' + ad.zoneId + 'dmFyIG0zX3UgPSAobG9jYXRpb24ucHJvdG9jb2w9PSdodHRwczonPydodHRwczovL2Fkcy5ubWcuY29tLmhrL3d3dy9kZWxpd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zY3IiKyJpcHQ+Iik7'; 
        break; 
       
      case 'url': // url ad 
        ret = ad.url; 
        break; 
    } 
    return ret; 
  } 
 
  /** 同步加载广告 
  * @param Array ad 广告参数 
  */ 
  function writeAd(ad){ 
    switch(ad.type){ 
      case 'openx': 
        var m3_u = (location.protocol=='https:'"<scr"+"ipt type='text/javascript' src='"+m3_u); 
        document.write ("" + ad.zoneId); 
        document.write ('&cb=' + m3_r); 
        if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used); 
        document.write (document.charset "&loc=" + escape(window.location)); 
        if (document.referrer) document.write ("&referer=" + escape(document.referrer)); 
        if (document.context) document.write ("&context=" + escape(document.context)); 
        if (document.mmm_fo) document.write ("&mmm_fo=1"); 
        document.write ("'><\/scr"+"ipt>"); 
        break; 
       case 'url': 
        document.write ('<script type="text/javascript" src="/UploadFiles/2021-04-02/' + ad.url + '">

demo.php示例程序如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
 <head> 
 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 
 <title> AD Loader </title> 
 <style type="text/css"> 
 .banner1{margin:10px; border:1px solid #CCCCCC; width:728px; height:90px;} 
 .banner2{margin:10px; border:1px solid #CCCCCC; width:300px; height:250px;} 
 </style> 
 <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.10.1.min.js">
<"<scr"+"ipt type='text/javascript' src='"+m3_u); 
document.write ("" + zoneid); 
document.write ('&cb=' + m3_r); 
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used); 
document.write (document.charset "&loc=" + escape(window.location)); 
if (document.referrer) document.write ("&referer=" + escape(document.referrer)); 
if (document.context) document.write ("&context=" + escape(document.context)); 
if (document.mmm_fo) document.write ("&mmm_fo=1"); 
document.write ("'><\/scr"+"ipt>"); 
<"_blank" href="http://xiazai.jb51.net/201409/ADLoader(jb51.net).rar">本站下载。

希望本文所述对大家的php程序设计有所帮助。

上一篇:php过滤html标记属性类用法实例
下一篇:php实现根据url自动生成缩略图的方法