Tuesday, August 18, 2009 at 7:35 PM.
photoFanSuite.downloadImage
on downloadImage (url, adrimg, adrfeed, thumbtext) { <<Changes <<11/29/08; 7:22:33 AM by DW <<Add param, thumbtext, an img element that displays the thumbnail if there is one, the emtpy string if none. Strip the markup from the description to prevent the redundan display of thumbnails there (Flickr does this). <<2/20/08; 6:26:52 PM by DW <<Don't let the created and modified dates be in the future. <<2/2/08; 4:55:09 PM by DW <<Set the created and modified dates of the image files using the pubdate in the image table, if provided. <<11/30/07; 12:12:59 PM by DW <<Convert to using the new photo viewer page in the logging code. <<11/29/07; 12:42:32 PM by DW <<Upgrade logging to use the info passed from adrfeed. <<11/23/07; 1:45:21 PM by DW <<startticks was being set before we enter the wait loop, so the total time elapsed in the log would reflect (mostly) the amount of time we had to wait to start downloading. <<11/23/07; 1:30:27 PM by DW <<Change "Image download" to "Download" in the log. <<11/21/07; 10:18:55 AM by DW <<Hot-up the domain in the log html text so it points at the picture we downloaded. Should help to debug. <<11/21/07; 6:19:49 AM by DW <<Link the small version of the image to the full one. <<11/21/07; 6:06:50 AM by DW <<Pass the image html to the log. <<11/20/07; 9:26:17 PM by DW <<Include a thumb of the image in the log. <<11/20/07; 1:12:21 PM by DW <<Make sure system.temp.flickrRivr.ctConcurrentDownloads doesn't go above user.flickrRivr.maxThreads. <<11/20/07; 12:31:43 PM by DW <<Log the download of each image. <<11/6/07; 9:12:58 AM by DW <<Add optional param, subfoldername. <<Don't delete the image sub-table, it's how we keep from reading files twice. <<11/3/07; 12:26:41 PM by DW <<Disable debugging messages on tcp.httpReadUrl call. <<10/31/07; 12:39:20 PM by DW <<No Error Info windows. The user doesn't care if a download results in an error. <<5/8/07; 2:12:49 PM by DW <<If the file is too small to keep, don't write it to disk, and delete the image table. <<4/22/07; 8:47:21 PM by DW <<Log file downloads. <<4/22/07; 12:12:27 PM by DW <<Created. Factored into a separate routine so each download can run in its own thread. local (now = clock.now ()); adrfeed^.ctPicsDownloaded++; adrfeed^.whenLastPicDownloaded = now; local (serialnum = user.photoFan.prefs.serialnum++, folder = adrfeed^.folder); <<bundle //set folder <<local (day, month, year, hour, minute, second, pc = file.getpathchar ()) <<date.get (clock.now (), @day, @month, @year, @hour, @minute, @second) <<folder = folder + year + pc + string.padwithzeros (month, 2) + pc + string.padwithzeros (day, 2) + pc local (f = folder + "pic" + string.padwithzeros (serialnum, 6) + ".jpg"); file.surefilepath (f); local (s = "", secs, startticks); bundle { //read the file startticks = clock.ticks (); try {s = tcp.httpreadurl (url, flmessages:false)}; secs = double (clock.ticks () - startticks) / 60; adrimg^.ctSecsToRead = secs}; if sizeof (s) >= user.photoFan.prefs.sizeSmallestImage { //big enough to keep file.writewholefile (f, s); if defined (adrimg^.pubdate) { //2/2/08 by DW local (thedate = adrimg^.pubdate); if thedate > now { //2/20/08 by DW thedate = now}; file.setcreated (f, thedate); file.setmodified (f, thedate)}; adrimg^.f = f; adrimg^.whenRead = now; bundle { //log the download, 11/29/07 by DW local (htmltext); bundle { //set htmltext local (phototitle); if adrimg^.title != "" { phototitle = adrimg^.title} else { phototitle = file.filefrompath (adrimg^.f)}; local (fileurl = string.delete (adrimg^.f, 1, sizeof (user.photoFan.prefs.screenSaverFolder))); fileurl = photoFanSuite.data.urls.picViewerPage + string.replaceall (fileurl, file.getpathchar (), "/"); fileurl = fileurl + "&title=" + string.urlencode (phototitle); local (photolink = "<a href=\"" + fileurl + "\">" + phototitle + "</a>"); local (feedurl = adrfeed^.link); if feedurl == "" { feedurl = nameof (adrfeed^)}; local (feedlink = "<a href=\"" + feedurl + "\">" + adrfeed^.title + "</a>"); local (sizestring = string.megabytestring (file.size (adrimg^.f))); htmltext = "<p>" + photolink + " (" + sizestring + ") downloaded from " + feedlink + ".</p>"; if sizeof (adrimg^.description) > 0 { local (s = searchengine.stripmarkup (adrimg^.description)); if sizeof (s) > 0 { htmltext = htmltext + "<p>" + s + "</p>"}}; if sizeof (thumbtext) > 0 { //11/28/08 by DW htmltext = htmltext + "<p><a href=\"" + url + "\">" + thumbtext + "</a></p>"}}; photoFanSuite.addToLog ("Download", htmltext, startticks)}}; <<bundle //log the download, old version <<local (sizestring = string.megabytestring (file.size (f))) <<local (ul = string.urlsplit (url), domain = ul [2]) <<local (fileurl = string.delete (f, 1, sizeof (user.photoFan.prefs.screenSaverFolder))) <<fileurl = photoFanSuite.data.urls.picViewer + string.replaceall (fileurl, file.getpathchar (), "/") <<local (imghtml = " ") <<try //set imghtml <<local (hw = html.getJpegHeightWidth (f), h = 50) <<local (w = hw [2] * (double (h) / double (hw [1]))) <<imghtml = "<a href=\"" + fileurl + "\"><img src=\"" + fileurl + "\" height=\"" + h + "\" width=\"" + number (w) + "\" border=\"0\"></a>" <<local (htmltext = "<a href=\"" + fileurl + "\">" + file.filefrompath (f) + "</a> downloaded from <a href=\"" + url + "\">" + domain + "</a> (" + sizestring + ")") <<photoFanSuite.addToLog ("Download", htmltext, startticks, imghtml) system.temp.photoFan.ctConcurrentDownloads--}; bundle { //test code local (url = "http:///static.flickrfan.org/ap/2007/11/23/0271.jpg"); url = "http:///static.flickrfan.org/ap/2007/11/24/0314.jpg"; local (adrimg = @user.photoFan.images.[url]); local (adrfeed = @user.photoFan.feeds.["http://static.flickrfan.org/ap/rss.xml"]); adrfeed = @user.photoFan.feeds.["http://api.flickr.com/services/feeds/photos_public.gne?lang=en-us&format=rss_200&id=98251250@N00"]; downloadImage (url, adrimg, adrfeed)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.