(* Web page for a given mushroom *) maintainSpecies := ( Print["Running maintainSpecies ..."]; filesample = ToFileName[{dirwork, "templates"}, "species.htm"]; checkfile[filesample]; text0 = Import[filesample, "Text"]; Do[ {{itype, kingdom, phylum, class, order, family, name, type, sciname, synonyms, link}, name} = namedata; (* see maintain-sort.m *) {kingdom, phylum, class, order, family} = If[# === "zzzUndefined", "Not assigned", #] &/@ {kingdom, phylum, class, order, family}; type1 = Replace[type, {"mushroom" -> "Fungi", "lichen" -> "Lichens", "slime mold" -> "Slime molds"}]; namehtml = sciname; familyen = ToUpperCase[family]; nofamily = "not assigned"; familyL = ToLowerCase[family]; If[familyL === nofamily, familyen = "NOT ASSIGNED to a family"]; line1 = classlinefix["kingdom > phylum > class > order"]; classlinefull = classlinefix["kingdom > phylum > class > order > family > species"]; nameL = ToLowerCase[name]; nameUnd = StringReplace[name, " " -> "_"]; nameLUnd = ToLowerCase[nameUnd]; nameen0 = commonName[name]; nameen = If[nameen0 === "", name, capitalize[nameen0] <> " (" <> name <> ")"]; nameen1 = If[nameen0 === "", name, name <> " " <> longdash <> " " <> nameen0]; usynonyms = synonymsUsed[name]; familylinken = If[familyL === nofamily, family, " family <> "\">" <> family <> ""]; classlinefullen = classlinefix["kingdom > phylum > class > order > " <> familylinken <> " > species"]; (* Common names *) ennames = commonNames[name]; nameen0 = If[ennames === {}, "", capitalize[ennames[[1]]] ]; cnamesen = ennames; mcnamesen = Length[cnamesen]; comlineen = If[mcnamesen == 0, "", If[mcnamesen == 1, cnamesen[[1]], StringJoin[Riffle[cnamesen, ", "]] ]]; comlineen1 = If[mcnamesen < 2, "", StringJoin[Riffle[Drop[cnamesen, 1], ", "]] ]; commlineen = If[mcnamesen == 0, "", If[mcnamesen == 1, "

Common name: " <> comlineen <> ".

", "

Common names: " <> comlineen <> ".

" ]]; (* Keywords *) nameid = name; allnamesen = Join[{nameid}, If[Length[ennames] < 8, ennames, Take[ennames, 7]], If[Length[synonyms] < 4, synonyms, Take[synonyms, 3]]]; enkeywords = StringJoin[Riffle[allnamesen, ", "]]; (* Synonyms *) msynonyms = Length[synonyms]; synonyms = If[MemberQ[usynonyms, #], "" <> # <> "", #] &/@ synonyms; synline = If[msynonyms == 0, "", If[msynonyms == 1, synonyms[[1]], StringJoin[Riffle[synonyms, ", "]] ]]; synlineen = If[msynonyms == 0, "", If[msynonyms == 1, "

Synonym: " <> synline <> ".

", "

Synonyms: " <> synline <> ".

" ]]; id = "id ..."; wiki = wikiEn[name]; fnames = foreignNames[name]; specnumber = 1; text = StringReplace[text0, { "APIKEY" -> apikey, "NAMERULAT" -> nameen, "KEYWORDS" -> enkeywords, "TOPNAME" -> If[nameen0 === "", "", StringReplace[nameen0, " " -> " "]], "TITLEHTML" -> nameen1, "SPECIES" -> name, "SPECNUMBER" -> ToString[specnumber], "SPECPLUS" -> StringReplace[name, " " -> "+"], "SPECLOWERUND" -> nameLUnd, "SPECBLANC" -> nameUnd, "SPECLOWBLANC" -> nameLUnd, "SPECID" -> id, "HTMLNAME" -> StringReplace[name, " " -> "%20"], "FIRSTPAR" -> wiki <> If[Head[fnames] === String && fnames =!= "" , "

" <> fnames, ""] }]; spanRead[text]; spanNew["topline"] = If[nameen0 === "", "", spanOld["topline"]]; spanNew["upperline"] = classlinefullen; spanNew["synonyms"] = synlineen; spanNew["common"] = commlineen; spanNew["choice"] = If[Head[link] === String, Clear[x]; shortlink = StringReplace[link, x:(Shortest[__] ~~ "//" ~~ Shortest[__]) ~~ "/" ~~ ___ :> x]; "
  • Data for this species were obtained from the dataset link <> "\">" <> shortlink <> ".", ""]; spanNew["wiki"] = If[wiki === "", "", spanOld["wiki"]]; spanNew["wikiref"] = If[wiki === "", "", spanOld["wikiref"]]; epilog = StringReplace[epilog0, {"program/sub/maintain-SCRIPTNAME" -> "../program/sub/maintain-species", "asergeev/" -> "../asergeev/", "\"program.htm" -> "\"../program.htm", "\"index" -> "\"../index", "background:url(" -> "background:url(../"}]; spanNew["epilog"] = epilog; picture0 = spanOld["pictures"]; pictset = picSet[name]; pictures = Table[ {roll, pic} = pict; year = toyear[roll]; capt = picCaption[roll, pic]; date = datedata[roll, pic] // DateList; psize = picsize[roll, pic]; {xsize, ysize} = psize; (*{year, roll, pic, capt, xsize, ysize, date, pop} = dat;*) alabel = "r" <> roll <> "p" <> pic; datecapt = StringCases[capt, RegularExpression["\\W+(\\w+\\W+\\w+\\W+\\w+)\\W*$"] -> "$1"]; If[datecapt =!= {}, datecapt = datecapt[[1]]; date = DateList[datecapt]; If[Head[date] === List, date = Take[date, 3]; (* Don't replace for pictures taken through microscope *) If[shootingdata["camera", roll, pic] =!= "USB Camera", capt = StringReplace[capt, datecapt -> " dateS[date, "-"] <> ".htm\">" <> datecapt <> ""]], Print["Error in date: Picture ", {year, roll, pic, capt}]]]; capt = StringReplace[capt, name -> "" <> name <> ""]; (* picture = StringReplace[picture0, {"YEAR" -> year, "ROLL" -> roll, "PIC" -> pic}]; *) link = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/" <> pic <> ".htm"; linkjpg = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> ".jpg"; filejpg = ToFileName[{dir00, "pictures", "archives", year, roll, "jpeg"}, pic <> "b.jpg"]; If[FileType[filejpg] === File, linkjpg = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "b.jpg"]; slink = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/" <> pic <> ".htm"; capt1 = " link <> "\" TARGET=\"_blank\" TITLE=\"Photo " <> roll <> "-" <> pic <> "\">\"Link\"" <> capt; (* Location. May be later: shooting data and extra large size *) filehtm = ToFileName[{dir00, "pictures", "archives", "compress", year, roll}, pic <> ".htm"]; capt2 = ""; If[FileType[filehtm] === File, texthtm = Import[filehtm, "Text"]; match = ""; s = StringCases[texthtm, match]; If[s =!= {}, s = s[[1]]; s = StringReplace[s, {"../../../../../" -> "../asergeev/", "sh('" ~~ Shortest[x___] ~~ "');" -> "", "" -> "", "staticmap?maptype" -> "staticmap?" <> "key=" <> apikey <> "&" <> "maptype", "
    "" -> "", "margin-bottom:2px;" -> "margin-bottom:0px;"}]; capt2 = capt2 <> s; geolocat = StringReplace[s, Longest[x__] ~~ "&locat=" -> ""]; geolocat = StringReplace[geolocat, "&delay=" ~~ Longest[x__] -> ""]; geolocat = ToExpression["{" <> geolocat <> "}"]; ]; match = ""; s = StringCases[texthtm, match]; If[s =!= {}, s = s[[1]]; s = StringReplace[s, {"../../../../../" -> "../asergeev/", "sh('" ~~ Shortest[x___] ~~ "');" -> "", "" -> "", "
    "" -> "", "margin-bottom:2px;" -> "margin-bottom:0px;"}]; capt2 = capt2 <> s; ]; ]; If[capt2 =!= "", capt1 = capt1 <> "
    " <> capt2]; xscale = xsizem1/xsize; yscale = ysizem1/ysize; scale = Min[xscale, yscale]; xm = Round[scale xsize]; ym = Round[scale ysize]; wthmaxt = 800; hthmaxt = 600; {pw, ph} = {xsize, ysize}; {sc1, sc2} = {wthmaxt, hthmaxt}/{xsize, ysize}; sc = Min[sc1, sc2]; {pwr, phr} = Round[sc {xsize, ysize}]; imgtrail = "ONMOUSEOVER=\"showtrail('../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "m.jpg'," <> ToString[xm] <> "," <> ToString[ym] <> ");" <> "\" ONMOUSEOUT=\"hidetrail();\""; link800 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "x.jpg"; link1200 = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> ".jpg"; link600 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "l.jpg"; link400 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "m.jpg"; link240 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "t.jpg"; img0 = " link800 <> "\" BORDER=\"0\" ALT=\"" <> addsymb[capt] <> "\">"; (* "\" BORDER=\"0\" HEIGHT=\"" <> ToString[phr] <> "\" WIDTH=\"" <> ToString[pwr] <> "\">
    "; *) pictureset = "" <> " link400 <> "\" media=\"(max-width: 400px)\"> link600 <> "\" media=\"(max-width: 600px)\"> link800 <> "\"> link800 <> "\" BORDER=\"0\" ALT=\"" <> addsymb[capt] <> "\"> "; jpg = " alabel <> "\" HREF=\"" <> linkjpg <> "\" TARGET=\"_blank\" TITLE=\"Download the picture\">" <> pictureset <> ""; "
    " <> jpg <> "
    " <> capt1 <> "
    ", {pict, pictset}] // StringJoin; spanNew["pictures"] = pictures; spanNew["locationscripts"] = spanNew["locationmap"] = ""; fileloc = ToFileName[{dir0, "loc"}, nameLUnd <> ".kmz"]; If[FileType[fileloc] === File, spanNew["locationscripts"] = spanOld["locationscripts"]; spanNew["locationmap"] = spanOld["locationmap"]]; text = text // spanReplace; diren = ToFileName[{dir0, "en"}]; checkdir1[diren]; file = ToFileName[diren, nameLUnd <> ".htm"]; Export[file, text, "Text"], {namedata, namesData}]; );