Banner formats
So far, the most common formats of displaying banners on Web sites rely on GIF, JPG and Flash files. For banner formats of GIF and JPG, this can be done the same way. However, when comes time to display a Flash banner on a site, the code behind it, for its display purposes, is different.
Width and Height
The first question that could come to your mind would be why do we have to pass the width and height of the banner file. As you may know, it is easy to get those values by the use of an Image object. The reason is that sometimes you may want to display the banner with a width and height different than what is defined in the banner file. As HTML allows you to do that, this can be useful sometimes. As for a Flash file, there is no easy way to know what is the base width and height. A Flash file can also be displayed without loosing that much quality even if we do not pass the proper dimensions. For those reasons, I prefer to pass the width and height as parameters.
Requirements
One requirement to use this function is to rely on a primary key for the banner identification which can be bound on a DBF table. Even if you do not have a DBF table, it is still possible to use this function by properly naming your banner files by padding them right by the use of 6 characters such as 000001.jpg.
Another requirement is to have a gcClientFat variable which holds the FAT root equivalent of your Web site. This can be adjusted to fit your own needs.
How to call it?
The process of calling this function is really simple. Here is an example:
lcHtml=GetBannerProperFormat(PrimaryKey,400,77,'This is my tooltip','Image',; 'Images/Banner/','http://www.levelextreme.com')
The GetBannerProperFormat() function
Here is the code of the GetBannerProperFormat() function:
* expN1 Banner ID * expN2 Width * expN3 Height * expM1 Tooltip * expC1 Class * expC2 Directory * expC3 URL FUNCTION GetBannerProperFormat PARAMETERS tnNoBanner,tnWidth,tnHeight,tmTooltip,tcClass,tcDirectory,tcURL LOCAL lcHtml,lcFile,llGraphic,lnNumero,lmTooltip,lcClass,lnWidth,lnHeight,lcDirectory,lcURL lcHtml='' llGraphic=.F. lnNumero=tnNoBanner lmTooltip=tmTooltip lcClass='Image' IF TYPE('tcClass')='C' lcClass=tcClass ENDIF lnWidth=tnWidth lnHeight=tnHeight lcDirectory=tcDirectory lcURL='' * If we have a URL IF TYPE('tcURL')='C' lcURL=tcURL ENDIF lcFile=lcDirectory+PADL(lnNumero,6,'0')+'.jpg' IF FILE(gcClientFat+lcFile) llGraphic=.T. ELSE lcFile=lcDirectory+PADL(lnNumero,6,'0')+'.gif' IF FILE(gcClientFat+lcFile) llGraphic=.T. ELSE lcFile=lcDirectory+PADL(lnNumero,6,'0')+'.swf' ENDIF ENDIF IF llGraphic IF LEN(lcURL)>0 lcHtml=lcHtml+'' ELSE lcHtml=lcHtml+'' ENDIF ELSE lcHtml=lcHtml+''+; ''+; ''+; ''+; ''+; '' ENDIF RETURN lcHtml
So, basically, if you have a banner table having 20 records, you should have 20 files in your banner directory. They can have different extensions as long as they are GIF, JPG or Flash files. Those are pretty much the standard files you may use for banners on Web sites. If you ever have a need to handle additional types, you may adjust the function as needed.
Overview of the generated HTML code
The following provides an overview of a generated HTML code based on a GIF file:
<A HREF=http://www.mywebsite.com> <IMG SRC=Images/Banner/000019.jpg WIDTH=132 HEIGHT=100 TITLE="My tooltip" BORDER=0 Class=Image> </A>
The following provides an overview of a generated HTML code based on a Flash file:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="400" height="77" Class=Image> <param name=movie value="Images/Banner/000037.swf"> <param name=quality value=high> <embed src="Images/Banner/000037.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi? P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="77"> </embed> </object>
Summary
The process of displaying a GIF or JPG banner is not that much difficult. Many would simply avoid using a function for that. But, this function is generic and is mostly useful when you have to deal with those Flash file. The code to generate the display of a Flash file on a Web site is much more complicated and can be simplified by the use of this function.