PHP AD Loading class

Source: Internet
Author: User

PHP ad loading class, which supports asynchronous and synchronous loading. Need to use jquery

ADLoader.class.php

<?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 collection based on Channel * Private Genzoneid ZoneID base 64_encode processing * Private genhtml generate AD HTML * Private Checkbrowser check whether the browser needs to be loaded synchronously/class adloader{/CLA     SS start private static $_ads = Array ();        Ad collection private static $_step = 300;      Ad loading interval private static $_async = true;  Whether the private static $_config = Array () is loaded asynchronously;    Ad settings file private static $_jsclass = null; Ad JS class/** load AD collection * @param String $channel column, corresponding config file * @param int $step Wide  
        Load Interval * @param boolean $async whether to load asynchronously/public static function load ($channel = ', $step = ', $async = ') {  
        if (Isset ($step) && is_numeric ($step) && $step >0) {self::$_step = $step;  
}      
        if (Isset ($async) && Is_bool ($async)) {self::$_async = $async;  
        //Judge The browser, such as IE enforces the use of synchronous load 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 Setconfig ($config =array (), $jsclass = ') {self::$_config = $config;  
    Self::$_jsclass = $jsclass; /** Create an ad collection based on Channel * @param String $channel column/private static function Getads ($cha  
        Nnel= ') {$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 load advertisement does not need to process ZoneID if (!self::$_async) {R  
        Eturn;  
        } $ads = Self::$_ads; For ($i =0, $len =count ($ads); $i < $len; $i + +) {if (Isset ($ads [$i] [' ZoneID ']) {$ads [$i] [' Zon]  
            EId '] = Base64_encode (' var zoneid= '. $ads [$i] [' ZoneID ']. ';  
    } self::$_ads = $ads;  
        /** Generate AD HTML */private static function genhtml () {$ads = Self::$_ads;  
        $html = Array (); if (self::$_jsclass!=null && $ads) {Array_push ($html, ' <script type= ' text/javascript ' src= '. Self: : $_jsclass. ' "  
      
            ></script> '); Synchronization requires preload if (!self::$_async) {foreach ($ads as $ad) {Array_push ($ht ML, ' <div id= '. $ad [' Domid ']. '  
                    _container "style=" Display:none ">"); Array_push ($html, ' <sCript type= "Text/javascript" >);  
                    Array_push ($html, ' Adloader.preload json_encode ($ad); ');  
                    Array_push ($html, ' </script> ');  
                Array_push ($html, ' </div> ');  
            } array_push ($html, ' <script type= ' text/javascript ' > ');  
            Array_push ($html, ' var ads= '. Json_encode ($ads). ';  
            Array_push ($html, ' $ (document). Ready (function () {adloader.load (ads, '. Self::$_step. ', '. Intval (Self::$_async); ');  
        Array_push ($html, ' </script> ');  
    Return implode ("RN", $html); /** determines whether the browser that needs to be forced to load synchronously */private static function Checkbrowser () {$user _agent = $_server  
        [' Http_user_agent '];  
        if (Strstr ($user _agent, ' msie ')!= ') {return false;  
    return true; }//Class end?>

Adconfig.php

<?php/** AD configuration file **/return array (' Case_openx ' => array (' Typ  
            E ' => ' 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 ', ' ur L ' => ' Adurl.php?zoneid=394 ')), ' Case_sync_openx ' => Array (Array (' type ' => ' OpenX ') , ' Domid ' => ' ad_728x90 ', ' ZoneID ' => 452), Array (' t Ype ' => ' OpenX ', ' domid ' => ' ad_300x250 ', ' ZoneID ' => 449), Arra  
        Y (' type ' => ' OpenX ', ' domid ' => ' ad_l2_300x250 ', ' ZoneID ' => 394 ), ' Default ' => array (' type ' => ' OpenX ', ' d OmId ' => ' ad_728x90 ', ' ZoneID ' => 452), Array (' type ' => ' OpenX ' , ' Domid ' => ' ad_300x250 ', ' ZoneID ' => 449), Array ('  
      
Type ' => ' OpenX ', ' domid ' => ' ad_l2_300x250 ', ' ZoneID ' => 394),  
      
); ? "; 

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/

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.