Source Code for user.html.macros.imgFileRef

on imgFileRef (imgname, explanation=nil, hspace="", align="", usemap="", ismap=false,  border=0, pageTable=nil, glossref="", vspace="", height="", width="", name="", id="", style="", class="", imgFolder = nil) {
     «imgFileRef © 1998 by Philip Suh <phil@filsa.net>.
          «Terms of Use:
               «Permission granted to use and redistribute this script
               «only if this documentation and copyright statement are
               «included and unmodified.  Use of this script is governed
               «by the full copyright statement, available from the Script Archive.
          «From the filsa.net Frontier Script Archive:
               «Full documentation, updates, and other scripts are available from
               «http://www.filsa.net/frontier/scripts/
          «Credits
               «Based on code from Userland's imageRef and html.getImageData
               «why reinvent the wheel?
          «Docs -- version 1 Fri, Jul 17, 1998 at 10:44:20 PM by PS
               «this macro will create <img> tags with relative URL's
                    «to images in a user specified folder
               «
               «imgName
                    «the name of the image--MUST include the proper suffix
                         «i.e., logo.gif or menubar.jpg
                    «required
               «imgFolder
                    «the folder in which the images are stored
                    «MUST be child of the siteRootFolder
                         «(#ftpSite.folder)
                    «MUST be partial path relative to the siteRootFolder
                    «example:
                         « if your site is at 
                              «C://websites/mysite/
                         «and your images folder is at
                              «C://websites/mysite/extras/myimages/
                         «your imgFolder parameter should be
                              «"extras/myimages/"
                    «You can set the imageFolder with a directive as well
                         «#imgFileRef_folder "extras/myimages/"
                         «which sets the folder globally for all uses of the
                         «imgFileRef macro.  Of course, this can be overridden
                         «on a case by case basis by using the imgFolder parameter
                    «optional
                         «but if this param is not defined, you need to use
                         « the #imgFileRef_folder directive
               «
               «Other params are standard img tag params.
                    «You know what to do.
               «not supported: low src, rollsource
               «
               «Image caching:
                    «This macro keeps track of height/width values of
                    «file based images. The cache defaults to being on, 
                    «and is flushed whenever you startup Frontier.
                    «To override the cache, turn it off with this directive:
                    «#imgFileRef_useCache false
     
     if pageTable == nil {
          try {
               pageTable = html.data.pagetable}
          else {
               pageTable = @websites.["#data"]}};
     if imgFolder == nil {
          try {
               imgFolder = pagetable^.imgFileRef_folder}
          else {
               scripterror ("imgFileRef: The images folder hasn't been defined.  Call the macro with the imgFolder parameter or use the #imgFileRef_folder directive to specify the  folder.")}};
     if not file.isfolder (pagetable^.ftpsite^.folder + imgFolder) {
          scripterror ("imgFileRef: Can't continue because, well, you screwed up.<g> " + pagetable^.ftpsite^.folder + imgFolder + " is not, as far as I can tell, a folder. What do you think?")};
     
     local {
          htmlText = "";
          imgspec;
          imgpath;
          hwstring};
     
     on add (s) {
          htmlText = htmlText + s};
     
     bundle { // does image exist?
          imgspec = pagetable^.ftpsite^.folder + imgFolder + imgName;
          if not file.exists (imgSpec) {
               scripterror ("imgFileRef: Can't continue because there is no file named  " +imgName + " in the folder '" + pagetable^.ftpsite^.folder + imgFolder + "'.")}};
     bundle { //build the path to the image
          local (nomad, subdirpath, pathch, pagepath, imgsubpath);
          pathch = file.getpathchar ();
          subdirpath = pagetable^.subdirectorypath;
          imgsubpath = imgFolder;
          
          loop {
               imgpath = string.nthfield (imgsubpath, pathch, 1);
               pagepath = string.nthfield (subdirpath, pathch, 1);
               if imgpath != pagepath {
                    break};
               imgsubpath = string.mid ( imgsubpath, sizeOf (imgpath) + 2, infinity);
               subdirpath = string.mid ( subdirpath, sizeOf (pagepath) + 2, infinity)};
          subdirpath = string.popTrailing (subdirpath, pathch);
          if subdirpath != "" { // glory be to Michael sattler, who fixed this bug
               «Mon, Aug 24, 1998 at 9:36:26 AM by PS
               subdirpath = string.filledstring ("../", string.countfields (subdirpath, pathch) )};
          imgsubpath =  subdirpath + imgsubpath;
          imgsubpath = string.replaceAll (imgsubpath, pathch, "/");
          
          imgpath = imgsubpath + imgName};
     bundle { //get height and width of image
          local ( imgType = string.nthfield (imgName, ".", string.countfields (imgName, ".")) );
          local ( h, w);
          if {"gif", "jpeg", "jpg"} contains string.lower (imgType) {
               local (flfound = false);
               local (flcache = html.getPref ("imgFileRef_useCache", pageTable));
               local (cachedImageData);
               if flcache { // get height and width from the image cache
                    «Thursday, January 15, 1998 at 3:55:21 PM by PBS
                    local (adrCache = @system.temp.htmlImageCache);
                    if not defined (adrCache^) {
                         new (tableType, adrCache)};
                    cachedImageData = @adrCache^.[imgPath];
                    if defined (cachedImageData^) {
                         h = cachedImageData^.height;
                         w = cachedImageData^.width;
                         flfound = true}};
               if not flfound {
                    case imgType {
                         "gif" {
                              hwList = html.getGifHeightWidth (imgspec)};
                         "jpg";
                         "jpeg" {
                              hwList = html.getJpegHeightWidth (imgspec)}};
                    h = hwList [1];
                    w = hwList [2];
                    if flcache {
                         new (tableType, cachedImageData);
                         cachedImageData^.height = h;
                         cachedImageData^.width = w}}};
          
          if height == "" {
               height = h};
          if width == "" {
               width = w};
          if height != 0 { //we may have failed to get image size
               hwstring = "height=" + height + " "};
          if width != 0 {
               hwstring = hwstring + "width=" + width}};
     bundle { //build html text
          if name == "" { //optional name parameter
               add ("<img src=\"" + imgPath + "\" " + hwstring)}
          else {
               add ("<img name=\"" + name + "\" src=\"" + imgPath + "\" " + hwstring)};
          
          if id != "" {
               add (" id=\"" + id + "\"")};
          «if lowsrc != "" // not supported
               «local (lowSrcData = html.getImageData (lowsrc, pageTable))
               «add (" lowsrc=\"" + lowSrcData.url + "\"")
          if hspace != "" {
               add (" hspace=" + hspace)};
          if vspace != "" {
               add (" vspace=" + vspace)};
          if align != "" {
               add (" align=" + align)};
          if usemap != "" {
               add (" usemap=\"#" + usemap + "\"")};
          if ismap {
               add (" ismap")};
          «if rollsrc != "" // not supported
               «local (rollData = html.getImageData (rollsrc, pageTable))
               «add (" onmouseout=\"this.src='" + imageTable.url + "'\"")
               «add (" onmouseover=\"this.src='" + rollData.url + "'\"")
          if style != "" {
               add (" style=\"" + style + "\"")};
          if class != "" {
               add (" class=\"" + class + "\"")};
          if explanation != "" and explanation == nil {
               explanation = string.popsuffix(imgName) + " picture"};
          if explanation != "" {
               add (" alt=\"" + explanation + "\"")};
          add (" border=" + border); «Wed, Dec 25, 1996 at 7:33:16 AM by DW
          add (">")};
     return (htmltext)}

Go back to the main page for this script