<? Php
/*************************************** ****************
Author: Wu zhenheng (Biz) -- phpscript
E-mail: wuzhenheng@china.com
Web: http://phpscript.osh.com.cn
File Name: AdRotator. class. php3
Copyright:
If you use this file, please write an email to the author
If you have any questions, contact the author.
Thank you for your attention!
**************************************** ****************/
/*
Advertising bar Management Program
Public method
GetAdvertisement ($ adfile)
Parameters
Target =
Width =
Height =
Border =
Redirect =
*/
Class AdRotator {
Var $ Target = "_ blank ";
Var $ Width = "460 ";
Var $ Height = "60 ";
Var $ Border = 0;
Var $ Redirect = "";
Var $ BannerData = array ();
Var $ RandTemp = 1;
Function AdRotator ()
{
}
/*
Public
Returns the link string of the advertisement.
*/
Function GetAdvertisement ($ adfile)
{
If (count ($ this-> BannerData) = 0)
{
$ This-> BannerData = $ this-> ReadAdFile ($ adfile );
}
$ AdData = $ this-> BannerData;
$ Uplimited = count ($ AdData );
// Generate a random ID
Srand (double) microtime () * 1000000000000000000 );
$ Id = @ rand (1, $ uplimited );
While ($ this-> RandTemp = $ id)
{
Srand (double) microtime () * 1000000000000000000 );
// $ Id = @ rand (1, count ($ AdData ));
$ Id = @ rand (1, $ uplimited );
}
$ This-> RandTemp = $ id;
// Echo $ id;
// Echo count ($ AdData );
// Echo $ AdData [5] ["image"];
$ LinkString = "<a href =" ". $ this-> Redirect;
$ LinkString. = "? Url = ". $ AdData [$ id] [" url "];
$ LinkString. = "" Target = "". $ this-> Target;
$ LinkString. = "" Title = "". $ AdData [$ id] ["title"];
$ LinkString. = ""> ";
$ LinkString. = " Border;
$ LinkString. = "" src = "". $ AdData [$ id] ["image"];
$ LinkString. = "" width = "". $ this-> Width;
$ LinkString. = "" height = "". $ this-> Height;
$ LinkString. = ""> ";
$ LinkString. = "</a> ";
// Echo $ LinkString;
Return $ LinkString;
}
/*
Private
Basic settings for reading files
*/
Function ReadAdFile ($ adfile)
{
$ FP = fopen ($ adfile, "r ");
While ($ buffer = @ fgets ($ FP, 1024 ))
{
If (! Eregi ("#", $ buffer ))
{
If (eregi ("^ *", $ buffer ))
{
$ Switchto = "off ";
}
$ SetTemp = split ("=", $ buffer );
If ($ switchto = "")
{
Switch ($ SetTemp [0])
{
Case "REDIRECT ":
$ This-> Redirect = $ SetTemp [1];
Break;
Case "WIDTH ":
$ This-> WIDTH = $ SetTemp [1];
Break;
Case "HEIGHT ":
$ This-> HEIGHT = $ SetTemp [1];
Break;
Case "BORDER ":
$ This-> BORDER = $ SetTemp [1];
Break;
Case "TARGET ":
$ This-> Target = $ SetTemp [1];
Break;
}
}
Else
{
Switch ($ SetTemp [0])
{
Case "image ":
$ I ++;
$ BannerData [$ I] ["image"] = $ SetTemp [1];
// Echo "<br>"; echo $ buffer; echo $ SetTemp [1];
// Echo $ BannerData [$ I] ["image"];
Break;
Case "url ":
$ BannerData [$ I] ["url"] = $ SetTemp [1];
Break;
Case "title ":
$ BannerData [$ I] ["title"] = $ SetTemp [1];
Break;
Case "rate ":
$ BannerData [$ I] ["rate"] = $ SetTemp [1];
Break;
} // End of switch
} // End of if ($ switch)
} // End of if (#)
} // End of while
Return $ BannerData;
} // End of function
} // End of class
/*
Usage
Advertisement placement file format banner.txt
------ Start ---
REDIRECT =./adredir. asp
WIDTH = 468
HEIGHT = 60
BORDER = 0
*
# Note
# XX Company advertisement 1
Image = ../banner/1.gif
Url = http: // www. asps0ite. com1
Title = One
Rate = 30
---- End -----
Note:
Similar to ASP ad Components
* Indicates the setting. Others are image settings #: indicates the annotation.
---- Use -----
$ Banner = new AdRotator ();
Echo $ banner-> GetAdvertisement ("./banner.txt ");
Echo $ banner-> GetAdvertisement ("./banner.txt ");
Echo $ banner-> GetAdvertisement ("./banner.txt ");
*/
?>
[This article is copyrighted by the author and osuo. If you need to reprint it, please indicate the author and its source]