Clear["@"]; (********** INPUT STARTS **********) (* HTML/pictures/archives-directory *) dir0="c:\\html\\pictures\\archives"; (* working directory *) dirwork="c:\\sergeev\\umassd\\html\\maintain"; test=0; (* 1 for testing *) firstyear=1996; mroll=400; (* max. possible number of rolls *) myear=2004; (* the last year *) {charleft,charright}={50,40}; (* number of characters in a shortened title *) (* Used only in ticker applet *) baseurl="http://www.asergeev.com/"; keywords="travelogue, pictures, documentary photographs, photos, images, photo album, gallery, daily snapshots, image archives, show, foto, scenery, nature, travel, tourism, wildlife, fotki"; (* for "the Middle East" *) keywords1="travelogue, pictures, Israel, Palestine, documentary photographs, photos, images, tmunot, photo album, gallery, daily snapshots, image archives, show, foto, scenery, nature, travel, tourism, wildlife, fotki"; (********** INPUT ENDS **********) Off[General::"spell",General::"spell1"]; iprint=0; SetDirectory[dirwork]; <"A", "11"->"B","12"->"C","13"->"D","14"->"E","15"->"F"}); <hex[r]<>hex[g]<>hex[b]; picsize[roll,fn]=ToString[x]<>"x"<>ToString[y]; ,{n,mcdata}]; ,{nroll,mrolls0}]; ,{nyear,myears}]; (* Further, years -> yyears, to avoid confusion *) (********** Reading links data file *) flinks=ToFileName[dir0,"links.txt"]; ldata=ReadList[flinks,Record,RecordSeparators -> {"#"}]; mldata=Length[ldata]; (* Defining root directory *) rootdir=""; Do[ndata=ldata[[n]]; nd=ReadList[StringToStream[ndata],Word]; If[nd[[1]]=="ROOTDIRECTORY", rootdir=nd[[2]]] ,{n,mldata}]; mrep=icol=0; rootdir0="../.."; (* relatively to pictures/archives *) of=OpenWrite[ToFileName[dir0,"links.htm"],PageWidth->Infinity, FormatType->OutputForm]; ""//p; ""//p; "List of links that are automatically added to picture captions where possible"//p; ""//p; "

Testing links

"//p; "

The following list contains links that are automatically added to picture captions.
It was created from the data file links.txt automatically for easy view and testing of these links.

"//p; ""//p; Do[ndata=ldata[[n]]; mark=ReadList[StringToStream[ndata],Word]//First; If[mark=="COMMENT" || mark=="ROOTDIRECTORY",Continue[]]; nd1=ReadList[StringToStream[ndata],Record,RecordSeparators->{"->"}]; If[Length[nd1]<2,Continue[]]; mrep++; icol=1-icol; refcom=StringReplace[nd1[[2]],{"ROOTDIRECTORY"->rootdir,"-NNNNN-"->"#"}]; nd2=ReadList[StringToStream[refcom],Record,RecordSeparators->{"\""}]; ref[mrep]=flankblank[nd2[[1]]]; ref1=StringReplace[ref[mrep],rootdir->rootdir0]; comm[mrep]= If[Length[nd2]<2,"",flankblank[nd2[[2]]]]; anchs=ReadList[StringToStream[nd1[[1]]],Record,RecordSeparators->{"!"}]; excl[mrep]=flankblank/@Drop[anchs,1]; (* Currently ignored *) incl[mrep]=flankblank/@ReadList[StringToStream[anchs[[1]]],Record,RecordSeparators->{"|"}]; " If[icol===0,"#FFFFFF","#E0E0E0"]<>"\">"//p; mincl=Length[incl[mrep]]; kwd=incl[mrep][[1]]; Do[kwd=kwd<>",
"<>incl[mrep][[nincl]],{nincl,2,mincl}]; refpri=ref[mrep]; If[StringLength[refpri]>33,refpri=StringTake[refpri,30]<>"..."]; ""//p; ""//p ,{n,mldata}]; "
KeywordsDescriptionurl
"<>kwd<>""<>comm[mrep]<>"ref1<>"\" TARGET=\"_blank\">"<>refpri<>""<> If[StringMatchQ[ref[mrep],"*"<>rootdir<>"*"]," (local)",""]<>"
"//p; Close[of]; (********** Finishing links HTML document *) blanksrc="../../../../../blank.gif"; urlcompress="../../"; (* Start scanning *) If[test==1,{mroll,myear}={2,1996}]; npic=0; Do[ (* year *) year=ToString[nyear]; (* Reading year caption *) filecapt=ToFileName[dir0,"captions.txt"]; data=ReadList[filecapt,Record,RecordSeparators -> {"#"}]; mrec=Length[data]; yearcap[year]=""; Do[rec=data[[nrec]]; pos=StringPosition[rec,{" ","\n",":"}]; n=pos[[1,1]]; head=StringTake[rec,n-1]; sep=StringTake[rec,{n,n}]; content=StringDrop[rec,n]//flankblank; If[head==year,yearcap[year]=StringReplace[content,{"\n"->" "}]] ,{nrec,mrec}]; (* *) yearsize[year]=0; Do[ (* roll *) roll=ToString[nroll]; dirslide=ToFileName[{dir0,"compress",year,roll,"jpeg"}]; If[FileType[dirslide]=!=Directory,Continue[]]; SetDirectory[dirslide]; fnames=FileNames["*.jpg"]; mf=Length[fnames]; rollsize[roll]=mf; yearsize[year]=yearsize[year]+mf; (* Reading roll name *) filecapt=ToFileName[{dir0,year,roll},"captions.txt"]; data=ReadList[filecapt,Record,RecordSeparators -> {"#"}]; mrec=Length[data]; rolltitle[roll]=""; Do[rec=data[[nrec]]; pos=StringPosition[rec,{" ","\n",":"}]; n=pos[[1,1]]; head=StringTake[rec,n-1]; sep=StringTake[rec,{n,n}]; content=StringDrop[rec,n]//flankblank; content=StringReplace[content,"\n"->" "]; If[head=="ROLL", If[rolltitle[roll]!="",Print["WARNING: several titles for the same roll encountered in the captions file "<>filecapt]]; rolltitle[roll]=content] ,{nrec,mrec}]; If[rolltitle[roll]=="",Print["WARNING: no title of the roll found in the captions file "<>filecapt]]; Print["#"<>roll<>" - "<>rolltitle[roll]]; (* Cycling through images *) Do[fname=fnames[[nf]]; fn=StringDrop[fname,-4]; If[StringLength[fn]>3,Continue[],npic++]; (***********) (* Reading the title of the slide from the file captions.txt *) fn1=StringReplace[fn,"000"->"-1"]; nfn=ToExpression[fn1]; capt=gcapt=""; Do[rec=data[[nrec]]; pos=StringPosition[rec,{" ","\n",":"}]; n=pos[[1,1]]; head=StringTake[rec,n-1]; sep=StringTake[rec,{n,n}]; content=StringDrop[rec,n]//flankblank; If[sep=="\n"||sep==" ", If[head==fn, If[capt!="",Print["WARNING: several captions for the same slide "<>fn<>" encountered in the caption file "<>capt]]; capt=content;Continue[]]]; If[sep==":", head1=StringReplace[head,{"000"->"-1","-"->"+"}]; range=Flatten[Release[ToExpression["{"<>head1<>"}",InputForm,Hold]/.Plus->Range]]; If[MemberQ[range,nfn], gcapt=gcapt<>"
\n"<>content;Continue[]]]; ,{nrec,mrec}]; capt=flankblank[capt]; gcapt=flankblank[gcapt]; gcapt=StringReplace[gcapt,{" "->" ","""->""}]; While[StringMatchQ[gcapt,"*<*>*"], n1=StringPosition[gcapt,"<"][[1,1]]; n2=StringPosition[gcapt,">"][[1,1]]; gcapt=If[n11,Print["#"<>fn<>"-"<>roll<>" - "<>descr[npic]]]; (**) caplink="

"<> If[capt=="", StringReplace[gcapt,{"\n"->"\n
"}],capt] <>"

#"<>fn<>"-"<>roll<>If[capt=="","
"<>rolltitle[roll],""]<>"

"; (* Adding links where possible *) Do[ pos=StringPosition[caplink,incl[nrep],Overlaps->False,IgnoreCase->True]; mpos=Length[pos]; If[mpos==0,Continue[]]; mcap=StringLength[caplink]; nref=ref[nrep]; mark="***"<>ToString[nrep]<>"***"; Do[ {pos1,pos2}=pos[[npos]]; If[pos1!=1 && !StringMatchQ[ToUpperCase[StringTake[caplink,{pos1-1}]],"@"],Continue[]]; If[pos2!=mcap && !StringMatchQ[ToUpperCase[StringTake[caplink,{pos2+1}]],"@"],Continue[]]; caplink=StringInsert[caplink,"",pos2+1]; caplink=StringInsert[caplink,"nref<>"\" TARGET=\"_blank\" ONMOUSEOVER=\"over('"<> mark<>"');return true\" ONMOUSEOUT=\"out()\">",pos1]; ,{npos,mpos,1,-1}] ,{nrep,mrep}]; Do[(* Adding descriptions of links *) ncomm=comm[nrep]; mark="***"<>ToString[nrep]<>"***"; caplink=StringReplace[caplink,mark->ncomm]; ,{nrep,mrep}]; caption[npic]=caplink; (* End reading from captfile *) yyears[npic]=year;rolls[npic]=roll;numbers[npic]=fn; If[!NumberQ[startroll[nroll]],startroll[nroll]=npic]; endroll[nroll]=npic; If[!NumberQ[startyear[nyear]],startyear[nyear]=npic]; endyear[nyear]=npic; ,{nf,mf}] ,{nroll,mroll}],{nyear,firstyear,myear}]; mpic=npic; Clear[npic]; minyear=ToExpression[yyears[1]]; maxyear=ToExpression[yyears[mpic]]; (* Cycle through all pic. *) Do[ year=yyears[npic];roll=rolls[npic];fn=numbers[npic]; nroll=ToExpression[roll]; nyear=ToExpression[year]; existb=(FileType[ToFileName[{dir0,year,roll,"jpeg"},fn<>"b.jpg"]]===File); (********************** Start writing HTML document ************************) (* *) of=OpenWrite[ToFileName[{dir0,"compress",year,roll},fn<>".htm"],PageWidth->Infinity,FormatType->OutputForm]; ""//p; ""//p; tit=shrink[description[npic],40,30,2]; If[StringLength[tit]<50,tit=StringReplace[rolltitle[roll]," - "->"-"]<>" - "<>StringReplace[tit," - "->"-"]]; titl="Photo "<>roll<>"-"<>fn<>": "<>tit; ""<>titl<>""//p; keywrds=If[StringMatchQ[description[npic],"*The Middle East*",IgnoreCase->True],keywords1,keywords]; "keywrds<>"\">"//p; des=shrink[description[npic],80,60,1]; desc="Picture Archives - Roll "<>roll<>" ("<>rolltitle[roll]<>") - Photo "<>fn<> If[StringLength[des]>4," ("<>des<>")",""]; "desc<>"\">"//p; ""//p; ""//p; ""//p; ""//p; ""//p; ""//p; ""//p; ""//p; (**) ldprev=ldnext=" "; If[npic>1, yearpr=yyears[npic-1];rollpr=rolls[npic-1];fnpr=numbers[npic-1]; ldprev="document.prev.src='"<>urlcompress<>yearpr<>"/"<>rollpr<>"/jpeg/"<>fnpr<>".jpg';" ]; If[npicurlcompress<>yearne<>"/"<>rollne<>"/jpeg/"<>fnne<>".jpg';" ]; " "BGCOLOR=\""<>color[roll,fn]<>"\" ONLOAD=\""<>ldnext<>ldprev<>"\">"//p; (* Table begins *) (* T0 *) ""//p; ""//p; ""//p; (* T1 T2 *) "
"//p; (* Slide *) bc=Floor[FileByteCount[ToFileName[{dir0,year,roll,"jpeg"},fn<>".jpg"]]/1000]; "

"//p; href="../../../"<>year<>"/"<>roll<>"/jpeg/"<>fn<>".jpg"; href1="../../../"<>year<>"/"<>roll<>"/jpeg/"<>fn<>".jpg"; href1b="../../../"<>year<>"/"<>roll<>"/jpeg/"<>fn<>"b.jpg"; psize=picsize[roll,fn]; "href<> "\" ONMOUSEOVER=\"over('Photo "<>roll<>"-"<>fn<> " was resized to square 360x360. Click to view the original "<>psize<>"');return true\" ONMOUSEOUT=\"out()\" ONCLICK=\"return launchViewer"<>If[existb,"b",""]<>"('"<> href1<>"',"<>StringReplace[psize,"x"->","]<>If[existb,",'"<>href1b<>"'",""]<> ")\">urlcompress<>year<>"/"<>roll<>"/jpeg/"<>fn<>".jpg\" WIDTH=376 HEIGHT=376 BORDER=0 ALT=\""<>descr[npic]<>"\">
"//p; "Click to view full-size image ("<>ToString[bc]<>" KB)

 "//p; "
"//p; ""//p; ""//p; (* /T2 /T1 *) "
"//p; blank="

"; (* Prev. image *) prev=If[npic==1,blank, If[rollpr==roll,"

yearpr<>"/"<>rollpr<>"/"<>fnpr<>".htm\" ONMOUSEOVER=\"over('"<>removesymb[descr[npic-1]]<>"');return true\" ONMOUSEOUT=\"out()\">\"#"<fnpr<>"-"<>rollpr<>" <---\">
Previous

", "

yearpr<>"/"<>rollpr<>"/"<>fnpr<>".htm\" ONMOUSEOVER=\"over('"<>removesymb[descr[npic-1]]<>"');return true\" ONMOUSEOUT=\"out()\">\"#"<fnpr<>"-"<>rollpr<>" <--- to the end of the previous roll\">
Previous roll of film

" ]]; prev//p; (* *) "
"//p; (* Next image *) next=If[npic==mpic,blank, If[rollne==roll,"

yearne<>"/"<>rollne<>"/"<>fnne<>".htm\" ONMOUSEOVER=\"over('"<>removesymb[descr[npic+1]]<>"');return true\" ONMOUSEOUT=\"out()\">\"--->fnne<>"-"<>rollne<>"\">
Next

", "

yearne<>"/"<>rollne<>"/"<>fnne<>".htm\" ONMOUSEOVER=\"over('"<>removesymb[descr[npic+1]]<>"');return true\" ONMOUSEOUT=\"out()\">\"--->fnne<>"-"<>rollne<>" start the next roll\">
Next roll of film

" ]]; next//p; "
"//p; "year<>"/"<>roll<>"/browser.htm\" ONMOUSEOVER=\"over('"<>rolltitle[roll]<>" ("<>ToString[rollsize[roll]]<>" pictures)');return true\" ONMOUSEOUT=\"out()\">Browse current roll of film"//p; "
"//p; (* Title *) ""//p; caption[npic]//p; ""//p; (* No-script notice *) ""//p; (* Table ends *) "
"//p; (* References *) "

"//p; ""//p; "
"//p; "year<>"/list.htm\" ONMOUSEOVER=\"over('"<>yearcap[year]<>" ("<>ToString[yearsize[year]]<>" pictures)');return true\" ONMOUSEOUT=\"out()\">Pictures-"<>year<>" |"//p; "years[[1]]<>" - "<>years[[myears]]<>"');return true\" ONMOUSEOUT=\"out()\">Picture Archives |"//p; "Selected Pictures |"//p; (*"Random Slide Show |"//p;*) "ToString[mmmpics]<> " pictures in "<>ToString[mmrolls]<>" film rolls, for "<>ToString[myears]<> " years');return true\" ONMOUSEOUT=\"out()\">List of All "<>ToString[mpic]<>" Pictures |"//p; "Technical details |"//p; "Directory of files |"//p; "A. Sergeev"//p; "

"//p; (* (* Ticker applet *) "

"//p; ""//p; ""//p; ""//p; ""//p; ""//p; ""//p; "baseurl<>"pictures/archives/1996/list.htm\">"//p; "baseurl<>"pictures/archives/1997/list.htm\">"//p; "baseurl<>"pictures/archives/1998/list.htm\">"//p; "baseurl<>"pictures/archives/1999/list.htm\">"//p; "baseurl<>"pictures/archives/2000/list.htm\">"//p; ""//p; ""//p; "

"//p; *) (* *) ""//p; If[iprint>1,Print["Roll #"<>roll<>" Slide #"<>fn<>" --- Picture #",npic]]; If[rollpr!=roll,Print["Roll #"<>roll]]; Close[of]; ,{npic,mpic}];