PHP AD Load Class Usage instance, PHP load usage Instance _php tutorial

Source: Internet
Author: User

PHP AD Load Class Usage instance, PHP load usage instance


This article describes the use of the PHP ad load class, very practical. Share to everyone for your reference. Here's how:

The PHP AD Load class supports asynchronous and synchronous loading. Needs to be implemented using jquery.

The ADLoader.class.php class file is as follows:

<?php/** AD Load Management class * date:2013-08-04 * author:fdipzone * ver:1.0 * * Func: * Public Load load AD collection * Public Setconfig AD Configuration * Private getads Create ad set based on channel * Private Genzoneid zoneid base64_encode processing * Private genhtml generation   Ad HTML * Private Checkbrowser Check if the browser needs to be loaded synchronously */class adloader{//class start private static $_ads = Array ();    Ad set private static $_step = 300;   Ad load Interval private static $_async = true; Whether to asynchronously load the private static $_config = Array ();  Ad settings file private static $_jsclass = null; Ad JS class/** load AD collection * @param String $channel column, corresponding config file * @param int $step ad load interval * @param boolean $a Whether sync loads asynchronously */public static function load ($channel = ', $step = ', $async = ') {if (Isset ($step) && Is_numer     IC ($step) && $step >0) {self::$_step = $step;     } if (Isset ($async) && Is_bool ($async)) {self::$_async = $async;   }//To determine if the browser, such as IE, enforces the use of synchronous loading if (!self::checkbrowser ()) {    Self::$_async = false;     } self::getads ($channel);      Self::genzoneid ();   return self::genhtml (); }/** set config * @param string $config AD configuration * @param string $jsclass JS class file path */public static function set     Config ($config =array (), $jsclass = ") {self::$_config = $config;   Self::$_jsclass = $jsclass;  /** Create ad set based on channel * @param String $channel column */private static function getads ($channel = ") {$AD _config     = Self::$_config;     if ($AD _config!=null) {self::$_ads = Isset ($AD _config[$channel])? $AD _config[$channel]: $AD _config[' default '; }}/** ZoneID base64_encode processing */private static function Genzoneid () {///synchronous loading ad does not need to process ZoneID if (!self::$_a     Sync) {return;     } $ads = Self::$_ads; For ($i =0, $len =count ($ads), $i < $len, $i + +) {if (Isset ($ads [$i] [' ZoneID ']) {$ads [$i] [' zoneid '] = Base64_enc       Ode (' Var zoneid= '. $ads [$i] [' ZoneID ']. '; ');   }} self::$_ads = $ads; }/**into AD HTML */private static function genhtml () {$ads = Self::$_ads;     $html = Array ();        if (self::$_jsclass!=null && $ads) {Array_push ($html, ');           Synchronization requires pre-loading if (!self::$_async) {foreach ($ads as $ad) {Array_push ($html, ');           Array_push ($html, ");         Array_push ($html, ");     }} array_push ($html, ");   } return implode ("\ r \ n", $html);     /** determines whether the browser needs to force a synchronous load */private static function Checkbrowser () {$user _agent = $_server[' http_user_agent '];     if (Strstr ($user _agent, ' MSIE ')! = ') {return false;   } return true; }}//class end?>

The

adconfig.php file is as follows:

<?php/** AD Profile **/return array (' Case_openx ' + = Array (' type ' = ' = ' OpenX ', ' domid ' =        > ' ad_728x90 ', ' zoneid ' = ' 452 ', array (' type ' = ' OpenX ', ' domid ' = ' ad_300x250 ', ' ZoneID ' + 449), array (' type ' = ' = ' OpenX ', ' domid ' = ' ad_l2_300x250 ', ' ZoneID '       ' = = 394), ' case_url ' = = Array (' type ' = ' = ' url ', ' domid ' = ' ad_728x90 ',       ' url ' = ' adurl.php?zoneid=452 '), Array (' type ' = ' = ' url ', ' domid ' = ' ad_300x250 '),       ' url ' = ' adurl.php?zoneid=449 '), Array (' type ' = ' = ' url ', ' domid ' = ' ad_l2_300x250 '),       ' url ' = ' adurl.php?zoneid=394 '), ' case_sync_openx ' = = Array (' type ' = ' OpenX ',  ' Domid ' = ' ad_728x90 ', ' ZoneID ' and ' 452 ', array (' type ' = ' OpenX ', ' domid ' = = ' ad_300x250 ', ' ZoNeid ' + 449), array (' type ' = ' OpenX ', ' domid ' = ' ad_l2_300x250 ', ' zoneid ' = 39 4), ' default ' = = Array (' type ' = ' = ' OpenX ', ' domid ' = ' ad_728x90 ', ' Zon     EId ' = + 452 ', array (' type ' = ' OpenX ', ' domid ' = ' ad_300x250 ', ' zoneid ' = 449  ), Array (' type ' = ' OpenX ', ' domid ' = ' ad_l2_300x250 ', ' zoneid ' = + 394),); ?>

The

Adloader.js file is as follows:

/** Asynchronous Load AD * date:2013-08-04 * author:fdipzone * ver:1.0 */var Adloader = (function () {var _ads = [],//AD Set  Hop _step = 300,//AD load Interval _async = True,//whether asynchronously loading _loaded = 0;       Number of ads already loaded/** Loadad loop load AD * @param int c Number of ads */function Loadad (c) {if (_loaded>=_ads.length) {     return; if ($ (' # ' +_ads[c].domid). length>0) {//Determine if DOM exists if (_async) {//Asynchronous execution Craploader.loadscript (GETSCR           IPT (_ads[c]), _ads[c].domid, {success:function () {completead ();              }         });         }else{//will be loaded synchronously displays var Ad_container = $ (' # ' +_ads[c].domid+ ' _container '); Ad_container.find (' embed '). attr (' wmode ', ' Transparent '). End (). Find (' object '). each (function (k, v) {V.wmode = ' tran Sparent ';         Turn flash to Transparent});         $ (' # ' +_ads[c].domid) [0].appendchild (Ad_container[0]);                  Ad_container.show ();       Completead (); }}else{//DOM does not exist Completead ();     }}/** after loading the ad processing */function Completead () {_loaded + +;     SetTimeout (function () {Loadad (_loaded);       }, _step);      }/** Get AD * @param Array AD parameters */function GetScript (AD) {var ret = null; Switch (ad.type) {case ' OpenX '://OpenX code AD ret = ' data:text/javascript;base64, ' + Ad.zoneid + ' dmfyig0z X3ugpsaobg9jyxrpb24uchjvdg9jb2w9psdodhrwczonpydodhrwczovl2fkcy5ubwcuy29tlmhrl3d3dy9kzwxpdmvyes9hanmucghwjzonahr0cdovl2fkc Y5ubwcuy29tlmhrl3d3dy9kzwxpdmvyes9hanmucghwjyk7cnzhcibtm19yid0gtwf0ac5mbg9vcihnyxrolnjhbmrvbsgpkjk5otk5otk5otk5ktskawygkc fkb2n1bwvudc5nqvhfdxnlzckgzg9jdw1lbnqutufyx3vzzwqgpsanlcc7cmrvy3vtzw50lndyaxrlicgiphnjciirimlwdcb0exblpsd0zxh0l2phdmfzy3j pchqnihnyyz0niittm191ktskzg9jdw1lbnqud3jpdgugkci/ em9uzwlkpsigkyb6b25lawqpowpkb2n1bwvudc53cml0zsaojyzhbxa7y2i9jyarig0zx3ipowppziaozg9jdw1lbnqutufyx3vzzwqgit0gjywnksbkb2n1b Wvudc53cml0zsaoiizhbxa7zxhjbhvkzt0iicsgzg9jdw1lbnqutufyx3vzzwqpowpkb2n1bwvudc53cml0zsaozg9jdw1lbnquy2hhcnnldca/iccmyw1wo2noyxjzzxq9jytkb2n1bwvudc5jagfyc2v0idogkgrvy3vtzw50lmnoyxjhy3rlclnldca/ iccmyw1wo2noyxjzzxq9jytkb2n1bwvudc5jagfyywn0zxjtzxqgoianjykpowpkb2n1bwvudc53cml0zsaoiizhbxa7bg9jpsigkyblc2nhcguod2luzg93l Mxvy2f0aw9uksk7cmlmichkb2n1bwvudc5yzwzlcnjlcikgzg9jdw1lbnqud3jpdgugkcimyw1wo3jlzmvyzxi9iiarigvzy2fwzshkb2n1bwvudc5yzwzlcn Jlcikpowppziaozg9jdw1lbnquy29udgv4dckgzg9jdw1lbnqud3jpdgugkcimy29udgv4dd0iicsgzxnjyxblkgrvy3vtzw50lmnvbnrlehqpktskawygkgr vy3vtzw50lm1tbv9mbykgzg9jdw1lbnqud3jpdgugkcimyw1wo21tbv9mbz0xiik7cmrvy3vtzw50lndyaxrlicgijz48xc9zy3iikyjpchq+         Iik7 ';              Break         Case ' URL '://url AD ret = Ad.url;     Break   } return ret;  /** Sync Load AD * @param Array AD parameters */function Writead (AD) {switch (ad.type) {case ' OpenX ': var M3_u = (location.protocol== ' https: '? ')         https://ads.nmg.com.hk/www/delivery/ajs.php ': ' http://ads.nmg.com.hk/www/delivery/ajs.php ');         var m3_r = Math.floor (Math.random () *99999999999); if (!doCument. max_used) document.         max_used = ', '; document.write ("
 
  
&LT;\/SCR "+" ipt> ");        Break         Case ' URL ': document.write (');     Break }} obj = {/** load ad * @param Array ads AD set * @param int step ad load Interval * @param boolean async tru        E: Asynchronous Load false: Synchronous loading */load:function (ads, step, async) {_ads = ads;       if (typeof (step)! = ' undefined ') {_step = step;       } if (typeof (async) = ' undefined ') {_async = async;     } loadad (_loaded);       },/** pre-load AD */preload:function (AD) {if ($ (' # ' +ad.domid). length>0) {//To determine if the DOM exists Writead (AD);  }}} return obj;  }()); /* Craploader */var Craploader = (function () {var ishijacked = false, queue = [], InputBuffer = [], WRI   Tebuffer = {}, loading = 0, Elementcache = {}, returnedelements = [], Splitscriptsregex =/(   <?php function Showad ($channel = ", $step =", $async = ") {include (' ADLoader.class.php ');    $ad _config = include (' adconfig.php ');    Adloader::setconfig ($ad _config, ' adloader.js ');   Return Adloader::load ($channel, $step, $async); } Echo Showad (' Case_openx ');  Asynchronously loads//echo showad (' Case_url '); URL mode asynchronously loaded//echo Showad (' Case_sync_openx ', +, false); Synchronous loading?> 
 

The adurl.php file is as follows:

<?php$zoneid = isset ($_get[' ZoneID ')? Intval ($_get[' ZoneID '): 0; if ($zoneid) {?> var ZoneID = <?= $zoneid?>; var m3_u = (location.protocol== ' https: '? ') https://ads.nmg.com.hk/www/delivery/ajs.php ': ' http://ads.nmg.com.hk/www/delivery/ajs.php '); var m3_r = Math.floor (Math.random () *99999999999); if (!document. max_used) document. max_used = ', '; document.write ("
 
  
   <\/scr "+" ipt> "); <? }?>
  
 

The complete example of the source of this article click here to download this site.

I hope this article is helpful to everyone's PHP programming.


The use of classes in PHP

class MyClass
{
function ShowError ($msg)
{
$msg =trim ($msg);
echo "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.