* utility to edit the Thumbnailer HTML so that if an original image exists, the normal 600x600 image links to it and says so
* for BLEM2002, May 2002

thisdir = GETDIR("Please point to the directory where the normal web pages and images are...")
IF EMPTY(thisdir)
	WAIT WINDOW "You didn't specify a directory where the web files start..."
	RETURN
ENDIF

testfiles = ADIR(htmlfiles, thisdir + "\*.html")


IF testfiles < 1
	WAIT WINDOW "Didn't find any .html files in the directory " + thisdir
ELSE
	FOR i = 1 TO testfiles
	IF LOWER(SUBSTR(htmlfiles[i,1],1,1)) = "p"
		imagename = STRTRAN(ALLTRIM(htmlfiles[i,1]), ".HTML", "")
	*		IF FILE(thisdir + "\originals\" + imagename + ".jpg")
				DO htmledit WITH imagename
	*		ENDIF
	ENDIF
	ENDFOR
ENDIF
RETURN


PROCEDURE htmledit
PARAMETERS in_name
WAIT WINDOW "Now changing file " + (thisdir) + in_name NOWAIT
thispage = FILETOSTR(thisdir + "\" + in_name + ".html")
IF ! "click for original file" $ thispage
	*thisimage = STREXTRACT(thispage, [<img src="],["])
	imgstarts = AT([<img src="], thispage)
	thumbrefstarts = AT([<a href="Thumbs/], thispage)
	thumbref = SUBSTR(thispage, thumbrefstarts, imgstarts-thumbrefstarts)
	thispage = STRTRAN(thispage, thumbref, [<A HREF="originals/] + in_name + [.jpg" target="_new">])
	thispage = STRTRAN(thispage, ["></a>], [ click for original file"></a>])
	*thispage = STRTRAN(thispage, "</a>" + CHR(13) + CHR(10) + UPPER(in_name) + ".jpg", "</a>" + CHR(13) + CHR(10) + UPPER(in_name) + ".jpg" + [<BR>Click here for the larger original file, <A HREF="./originals/] + in_name + [.jpg">] + in_name + [</A><BR>])
	_cliptext = thispage
	*SUSPEND

	ERASE (thisdir + "\" + in_name + ".html")
	STRTOFILE(thispage, thisdir + "\" + in_name + ".html")
ENDIF
RETURN





PROCEDURE htmledit_old
PARAMETERS in_name
WAIT WINDOW "Now changing file " + (thisdir) + in_name + ".html" NOWAIT
CREATE CURSOR htmltemp (line1 C(200))
APPEND FROM (thisdir + "\" + in_name + ".html") TYPE SDF
* BROWSE
LOCATE FOR line1 = UPPER(in_name) + ".jpg"
* IF NOT "Click here for the larger original" $ line1
REPLACE line1 WITH [<BR>Click here for the larger original file, <A HREF="./originals/] + in_name + [.jpg">] + in_name + [</A><BR>]
ERASE (thisdir + "\" + in_name + ".html")
SET CONSOLE OFF
SET ALTERNATE TO (thisdir + "\" + in_name + ".html")
SET ALTERNATE ON
SCAN
	?? ALLTRIM(line1)
	?
ENDSCAN
SET ALTERNATE OFF
SET ALTERNATE TO
SET CONSOLE ON
* ENDIF
RETURN



PROCEDURE htmledit_ll
* oops -- this writes over the existing text
PARAMETERS in_name
thisfile = (thisdir + "\" + in_name + ".html")
testopen=FOPEN(thisfile,2)
IF testopen >=1
	WAIT WINDOW "Now changing file " + (thisfile) NOWAIT
	DO WHILE NOT FEOF(testopen)
		line1 = FGETS(testopen)
		IF lower(line1) = LOWER("<br>" + in_name + ".JPG")
			WAIT WINDOW "About to change " + ALLTRIM(line1) + CHR(13) + " to " + SUBSTR(line1,1,4) + [Click here for the larger original file, <A HREF="] + LOWER(STRTRAN(thisdir, "D:\WEBHOST", "/") + "originals/" + in_name + ".jpg") + [">] + ALLTRIM(SUBSTR(line1,5)) + [</A>]
			testwrite = FPUTS(testopen, SUBSTR(line1,1,4) + [Click here for the larger original file, <A HREF="] + LOWER(STRTRAN(thisdir, "D:\WEBHOST\", "/") + "originals/" + in_name + ".jpg") + [">] + ALLTRIM(SUBSTR(line1,5)) + [</A><] + CHR(13))
			IF testwrite < 1 
				WAIT WINDOW "Didn't rewrite the HTML file..."
			ENDIF
			EXIT
		ENDIF
	ENDDO
ELSE
	WAIT WINDOW "Couldn't open " + thisfile
ENDIF
=FCLOSE(testopen)
RETURN


