<? 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 managementProgram
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]