defaultTitle = "Taxonomy in Flux"  
},
}
-- ------------- Avibase
e.g. https://avibase.bsc-eoc.org/species.jsp?avibaseid=9144EF4017F2D8B1  
data.avibase = {
citationArgs = {
website="Avibase",
['editor1-last']="Lepage", ['editor1-first']="Denis", --['editor1-link']="",
},
customArgs = { exclude="order,family,genus,species,taxon,id,1",
baseURL = "https://avibase.bsc-eoc.org/",
searchStr = "species.jsp?avibaseid=",
defaultTitle = "Avibase - The World Bird Database"
}
}
--[[ use default function
data.avibase.id = function (id)  
local title = "Avibase id: " .. id
local url = data.avibase.customArgs['baseURL'] .. data.avibase.customArgs['searchStr'] .. id
return title, url
end
--]]  
-- ============================= IUCN =================================================
-- for species in taxon; for species assessments, us
-- https://www.iucnredlist.org/search?query=Murexia&searchType=species
-- https://www.iucnredlist.org/search?query=aonyx&searchType=species
data.iucn = {
citationArgs = {
website="IUCN Red List of Threatened Species",
--publisher="IUCN"
},
customArgs = { exclude="family,genus,species,taxon,id,1",
baseURL = "https://www.iucnredlist.org",
searchString = "/search?query=",
searchSuffix = "&searchType=species",
defaultSuffix = "",
defaultTitle="IUCN Red List of Threatened Species"
}
}
data.iucn.genus = function(genus) return data.iucn.taxon(genus, "TITLE_ITALICS") end
data.iucn.family = function(family) return data.iucn.taxon(family) end
data.iucn.order = function(order) return data.iucn.taxon(order) end
data.iucn.taxon = function(taxon, titleItalics)
local title = firstToUpper(taxon)
if titleItalics then title = "*" .. title .. "*" end
local url = data.iucn.customArgs['baseURL'] .. data.iucn.customArgs['searchString'] .. taxon .. data.iucn.customArgs['searchSuffix']
return title, url
end  
-- ============================= ASM Mammal Diversity Database ========================
data.asm = {
citationArgs = {
website="ASM Mammal Diversity Database",
publisher="American Society of Mammalogists"
},
customArgs = { exclude="family,genus,species,taxon,id,1,2,3",
baseURL = "https://www.mammaldiversity.org/",
defaultTitle="ASM Mammal Diversity Database"  
}
}  
data.asm.species2 = function(genus, species) -- use species function below
-- old url = https://mammaldiversity.org/species-account.php?genus=ursus&species=arctos
-- new url = https://www.mammaldiversity.org/explore.html#genus=Dipodomys&species=deserti&id=1001892 (only id required)
local title = "*" .. genus .. " " .. species .. "*"
local url = data.asm.customArgs['baseURL'] .. "explore.html#genus=" .. genus .. "&species=" .. species
if templateArgs['id'] then url = url .. "&id=" .. templateArgs['id'] end
return title, url
end
data.asm.id = function(id)
--local url = data.asm.customArgs['baseURL'] .. "species-account/species-id=" .. templateArgs['id']
-- new format https://www.mammaldiversity.org/explore.html#species-id=1006310
--local url = data.asm.customArgs['baseURL'] .. "explore.html#species-id=" .. id -- templateArgs['id']
-- newer format https://www.mammaldiversity.org/explore.html#genus=Leopardus&species=colocola&id=1005993 (genus and species can be blank)  
local title = "Species-id=" .. id
local hashString = "genus=&species=&id=" .. id -- if id only, requires blank genus and species
if templateArgs['genus'] and templateArgs['species'] then
title = "*" .. templateArgs['genus'] .. " " .. templateArgs['species'] .. "* (id=" .. id ..")"
hashString = "genus=" .. templateArgs['genus'] .. "&species=" .. templateArgs['species'] .. "&id=" .. id
end
--local url = data.asm.customArgs['baseURL'] .. "explore.html#genus=&species=&id=" .. id -- templateArgs['id']
local url = data.asm.customArgs['baseURL'] .. "explore.html#" .. hashString  
return title, url
end
data.asm.species = function(genus, species)
if templateArgs['id'] then
return data.asm.id(templateArgs['id']) -- use the ASM explore page if ID given (as permalink)
end
if genus and species then -- otherwisee use the treeview page with the species info
local title = "*" .. firstToUpper(genus) .. " " .. species .. "*"
local url = data.asm.customArgs['baseURL'] .. "tree.html#genus=" .. genus .. "&species=" .. species
return title, url
end  
end  
data.asm.genus = function(genus) return data.asm.taxon(genus, "genus", "TITLE_ITALICS") end
data.asm.family = function(family) return data.asm.taxon(family, "family") end
data.asm.order = function(order) return data.asm.taxon(order, "order") end
data.asm.taxon = function(taxon, rank, titleItalics)
--https://mammaldiversity.org/#ZmVsaWRhZSZnbG9iYWxfc2VhcmNoPXRydWUmbG9vc2U9dHJ1ZQ
-- Base64.encode(felidae&global_search=true&loose=true)
local title = firstToUpper(taxon)
if titleItalics then title = "*" .. title .. "*" end
local url = data.asm.customArgs['baseURL'] .. "tree.html#" .. rank .. "=" .. taxon
-- .. '#' .. data.asm.Base64.encode(taxon.."&global_search=true&loose=false")
return title, url
end
--############################## Base64 encode and decode (used for ASM#####################
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- encoding
data.asm.Base64 = {}
data.asm.Base64.encode = function(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end
-- decoding
data.asm.Base64.decode=function(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
end
--######################## Misc ##################################
--[[ 3 approaches to handling DB:
1) use DB as website and use author for editors (if known)
(a) use via to append WoRMS
(b) use postscript to append WoRMs
(c) use publisher for WoRMS
2) use WoRMS as website and designate DB as author (recommended by WoRMS) CURRENT
(option) add editors [TODO see cite WoRMS for list]
issue: what to do about editors changing (need to use access-date)
data.WoRMS = {
citationArgs = {
author = "WoRMS",
website = "World Register of Marine Species",
--['via'] = "World Register of Marine Species",
--postscript = '&#32;from the World Register of Marine Species.'  
},
customArgs = {exclude="id,db,1",
baseURL = "http://www.marinespecies.org/aphia.php?",
searchStr = "p=taxdetails&id=",
defaultTitle="World Register of Marine Species"
}
}
data.WoRMS.id = function(id)
-- Two styles
1. http://www.marinespecies.org/aphia.php?p=taxdetails&id=14712
> WoRMS (2018). Heterobranchia. Accessed at: http://marinespecies.org/aphia.php?p=taxdetails&id=14712 on 2018-11-28
2. http://www.marinespecies.org/aphia.php?p=taxdetails&id=1057249
> MolluscaBase (2018). Ringipleura. Accessed through: World Register of Marine Species at: http://www.marinespecies.org/aphia.php?p=taxdetails&id=1057249 on 2018-11-28  
if not templateArgs['id'] then return "no id parameter detected" end
local searchStr = "p=taxdetails&id=" .. templateArgs['id']  
if templateArgs['db'] then
data.WoRMS.db (templateArgs['db'])
--[[else -- WoRMS is primary source (note cite WoRMs uses WoRMS as publisher and the db as the work)
templateArgs['via'] = nil
templateArgs['postscript'] = nil]]
end
--templateArgs['website'] = templateArgs['db'] -- alternative (and use |postscript)
--templateArgs['publisher'] = templateArgs['via']  
--page <title>WoRMS - World Register of Marine Species - Heterobranchia</title>
local title = "WoRMS taxon details: AphiaID " .. id
local url = data.WoRMS.customArgs['baseURL'] .. data.WoRMS.customArgs['searchStr'] .. id
return title, url  
end