Modul:Citace

Z Enviwiki
Skočit na navigaci Skočit na vyhledávání


Prozatímní dokumentace

Nejdůležitější změny proti starým šablonám:

  • Přidána podpora pro harvardské citace, vázaná na parametr ref = harv
  • Zrušena mezera před dvojtečkou - dle ISO 690 z dubna 2011, https://www.citace.com/CSN-ISO-690
  • Revize zavlečených mezer dle zásady: mezeru vkládat co nejpozději.
  • Ošetřeny duplikované koncové tečky.

--Jvs 30. 12. 2017, 10:45 (CET)

Odkazy:



local p = {
}

function p.trace(c, dbgInfo, s)
  table.insert(c.r, "{p." .. dbgInfo.name .. (s and s or "") .. "}")
end

function p.citaceInit(c)
  c.r = {} -- result
  c.state = {}

  if type(c.frame.callParserFunction) == 'function' then
    -- running as wiki module
    local aModule = require('Modul:Arguments')
    c.args = aModule.getArgs(c.frame)
    c.parentArgs = aModule.getArgs(c.frame:getParent())
    p.frame = c.frame -- zmena reseni, 30.12.2017 12:30:06
  else
    -- running in console
    c.localTest = 1
    c.args = c.frame
    c.parentArgs = {}
    -- makety vybranych fci pro lokalni testovani
    mw = {
      uri = {
        encode = p.identity
      }
    }
    -- debugging options
    c.noCoins = 1
    c.trace = 1
    -- c.dbg = 1
  end

  if c.trace then p.trace(c, debug.getinfo(1, "n"), ':' .. c.type) end

  -- zpětná kompatibilita
  p.convertUnderscoreArgs(c.args)
  p.provideArgs(c.args, {
    -- ["SRC"] = "DEST",
    ["příjmení"] = "příjmení1",
    ["jméno"] = "jméno1",
    ["autor"] = "autor1",
    ["odkaz na autora"] = "odkaz na autora1",

    ["příjmení sestavitele"] = "příjmení sestavitele1",
    ["jméno sestavitele"] = "jméno sestavitele1",
    ["sestavitel"] = "sestavitel1",
    ["odkaz na sestavitele"] = "odkaz na sestavitele1",

    ["noviny"] = "periodikum",
    ["časopis"] = "periodikum",
    ["odkaz na noviny"] = "odkaz na periodikum",
    ["odkaz na časopis"] = "odkaz na periodikum",

    ["datum vydání"] = "datum",
    ["den vydání"] = "den",
    ["měsíc vydání"] = "měsíc",
    ["rok vydání"] = "rok",
    ["stránky"] = "strany",
    ["poznámka"] = "poznámky",
    ["titulorig"] = "titul původní",
    ["url alt"] = "url2",
  })

  c.printAnchor = not p.empty(c.args.ref)
  c.useHarvardFormat = c.printAnchor and c.args["typ refu"] ~= "normální"

  if c.dbg then
    table.insert(c.r, "((DBG: ")
    for k, v in pairs(c.args) do
      table.insert(c.r, k .. ' = ' .. v .. ';')
    end
    table.insert(c.r, "((PARENT)): ")
    for k, v in pairs(c.parentArgs) do
      table.insert(c.r, k .. ' = ' .. v .. ';')
    end
    table.insert(c.r, " DBG_END))\n")
  end
end

function p.citaceMonografie(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceMonografie'
  p.citaceInit(c)
  local t = {} -- temp
  local i

  table.insert(c.r, '<cite class="book" style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = true })
  p.citTitle(c)
  p.citOtherPersons(c)
  p.citEdition(c)
  p.citVolume(c)
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citNumberOfVolumesPagesAppendices(c)
  p.citBookSeries(c)
  p.citUrl(c)
  p.citIsbn(c)
  p.citDoi(c)
  p.citOclc(c)
  p.citId(c)
  p.citChapterPage(c)
  p.citLanguage(c)
  p.citNotes(c)

  table.insert(c.r, '</cite>')
  p.citCoinsMonografie(c)
  return table.concat(c.r)
end

function p.citaceElMonografie(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceElMonografie'
  p.citaceInit(c)
  local t = {} -- temp
  local i

  table.insert(c.r, '<cite class="book" style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = true })
  p.citTitle(c)
  p.citOtherPersons(c)
  p.citEdition(c)
  -- p.citVolume(c)
  p.citPlacePublisher(c)
  p.citDate(c)
  -- p.citNumberOfVolumesPagesAppendices(c)
  p.citBookSeries(c)
  p.citChapterPage(c)
  p.citNotes(c)
  p.citUrl(c)
  p.citIsbn(c)
  p.citDoi(c)
  -- p.citOclc(c)
  p.citId(c)
  p.citLanguage(c)

  table.insert(c.r, '</cite>')
  p.citCoinsMonografie(c)
  return table.concat(c.r)
end

function p.citacePeriodika(frame)
  local c = {
    frame = frame
  }
  c.type = 'citacePeriodika'
  p.citaceInit(c)
  local t = {} -- temp
  local i

  p.supplyPeriodical(c)

  table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = false })
  p.citTitle(c)
  p.citOtherPersons(c)
  -- table.insert(c.r, " ")
  p.citPeriodical(c)
  -- table.insert(c.r, " ")
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citYearNumberPage(c)
  -- table.insert(c.r, ".")
  p.citNotes(c)
  p.citUrl(c)
  p.citIssn(c)
  p.citIsbn(c)
  p.citDoi(c)
  p.citPmid(c)
  p.citBibcode(c)
  p.citArxiv(c)
  p.citId(c)
  p.citLanguage(c)

  p.checkPeriodical(c)

  table.insert(c.r, '</cite>')
  p.citCoinsPeriodikum(c)
  return table.concat(c.r)
end

function p.citaceElPeriodika(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceElPeriodika'
  p.citaceInit(c)
  local t = {} -- temp
  local i

  p.supplyPeriodical(c)

  table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 7, honorCorporation = false })
  p.citTitle(c)
  p.citOtherPersons(c)
  -- table.insert(c.r, " ")
  p.citPeriodical(c)
  -- table.insert(c.r, " ")
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citYearNumberPage(c)
  -- table.insert(c.r, ".")
  p.citNotes(c)
  p.citUrl(c)
  p.citIssn(c)
  p.citIsbn(c)
  p.citArxiv(c)
  p.citDoi(c)
  p.citBibcode(c)
  p.citPmid(c)
  p.citId(c)
  p.citLanguage(c)

  p.checkPeriodical(c)

  table.insert(c.r, '</cite>')
  p.citCoinsPeriodikum(c)
  return table.concat(c.r)
end

function p.citaceSborniku(frame)
  local c = {
    frame = frame
  }
  c.type = 'citaceSborniku'
  p.citaceInit(c)
  local t = {}
  local i

  table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
  p.citAnchorId(c)
  table.insert(c.r, '>')
  p.citAuthors(c, { maxAuthors = 3, honorCorporation = true })
  p.citTitle(c)
  table.insert(c.r, ' In: ')
  p.citCompilers(c, { maxAuthors = 3, honorCorporation = true })
  p.citCompilation(c)
  p.citEdition(c)
  p.citPlacePublisher(c)
  p.citDate(c)
  p.citNotes(c)
  p.citUrl(c)
  p.citIsbn(c)
  p.citIssn(c)
  p.citDoi(c)
  p.citId(c)
  p.citVolume(c)
  p.citChapterPage(c)
  p.citLanguage(c)
  table.insert(c.r, '</cite>')
  -- p.citCoinsSbornik(c)

  return table.concat(c.r)
end

function p.debug(frame)

  --[[
  if frame.callParserFunction ~= nil and type(callParserFunction) == 'function' then
   local aModule = require('Modul:Arguments')
   local args = aModule.getArgs(frame)
  end
  --]]

  -- local a = '';
  -- return 'Titul: ' .. args.titul .. ';'

  result = {}

  table.insert(result, type(frame))


  for k, v in pairs(frame) do
    table.insert(result, k .. ' = ' .. type(v) .. '; ')
  end

  return table.concat(result)
end

function p.nowiki(c, txt)
  if type(c.frame.extensionTag) == 'function' then
    return c.frame:extensionTag('nowiki', (txt and txt or ''), {})
  else
    if not p.empty(txt) then
      return "<nowiki>" .. txt .. "</nowiki>"
    else
      return "<nowiki/>"
    end
  end
end

function p.identity(x)
  return x
end

function p.empty(x)
  -- return x == nil or x == 0 or x == ""
  return x == nil or x == ""
end

-- vrátí první neprázdný argument
function p.coalesce(x, y)
  return ((x and x ~= "") and x or ((y and y ~= "") and y or ""))
end

function p.coalesceN(len, args)
  for i = 1, len do
    local v = args[i]
    if v ~= nil and v ~= "" then
      return v
    end
  end
  return ""
end

function p.provideArg(args, x, y)
  if args[x] == nil then
    args[x] = args[y]
  end
end

function p.convertUnderscoreArgs(args)
  local t = {}
  for k, v in pairs(args) do
  	k = tostring(k)
    t.k, t.count = k:gsub('_', ' ')
    if t.k ~= k then
      args[t.k] = v
    end
  end
end

function p.provideArgs(args, map)
  for src, dest in pairs(map) do
    if (args[dest] == nil or args[dest] == "") and (args[src] ~= nil and args[src] ~= "") then
      args[dest] = args[src]
    end
  end
end

function p.plural(num, s1, s2, s3)
  num = tonumber(num) or 0
  return (num == 1 and s1) or (1 < num and num < 5 and s2 or s3)
end

function p.lastChar(s)
  if p.frame then
    return mw.ustring.sub(s, -1)
  else
    return string.sub(s, -1)
  end
end

-- nevim, zda lze nejak nastavit locale pro systemovy upper
function p.upper(s)
  -- return "<span style='text-transform: uppercase'>" .. s .. "</span>"
  if p.frame then
    -- return p.frame:callParserFunction('uc', s)
    return mw.ustring.upper(s)
  else
    return s:upper()
  end
end

function p.upperFirst(s)
  if p.frame then
    return p.upper(mw.ustring.sub(s, 1, 1)) .. mw.ustring.sub(s, 2)
  else
    return p.upper(s:sub(1, 1)) .. s:sub(2)
  end
end

function p.wikilink(odkaz, popis)
  if not p.empty(odkaz) then
    if not p.empty(popis) then
      return "[[" .. odkaz .. "|" .. popis .. "]]"
    else
      return "[[" .. odkaz .. "]]"
    end
  else
    return popis
  end
end

function p.wikiextlink(odkaz, popis)
  if not p.empty(odkaz) then
    if not p.empty(popis) then
      return "[" .. odkaz .. " " .. popis .. "]"
    else
      return "[" .. odkaz .. "]"
    end
  else
    return popis
  end
end

function p.date(args, params)
  local r = {}
  local postfix = ""
  if (params and params.postfix) then
    postfix = params.postfix
  end

  if not p.empty(args["datum" .. postfix]) then
    table.insert(r, ""
      .. args["datum" .. postfix]
    )
  elseif not p.empty(args["rok" .. postfix]) then
    table.insert(r, ""
      .. args["rok" .. postfix]
      .. (not p.empty(args["měsíc" .. postfix])
        and "-" .. args["měsíc" .. postfix] .. (not p.empty(args["den" .. postfix]) and "-" .. args["den" .. postfix] or "")
        or ""
      )
    )
  end
  return table.concat(r)
end

function p.dateCs(args, params)
  local r = {}
  if not p.empty(args["datum"]) then
    table.insert(r, ""
      .. args["datum"]
    )
  elseif not p.empty(args["rok"]) then
    table.insert(r, ""
      .. (not p.empty(args["měsíc"])
        and (not p.empty(args["den"]) and args["den"] .. ". " or "")
          -- za měsícem vyjádřeným číslem uvedeme tečku
          .. args["měsíc"] .. (string.match(args["měsíc"], "^[0-9]+$") and "." or "") .. " "
        or ""
      )
      .. args["rok"]
    )
  end
  return table.concat(r)
end

function p.style(c)
  return (not p.empty(c.args['background']) and "background:" .. c.args['background'] .. ";" or "")
end

function p.supplyPeriodical(c)
  local t = {}
  if p.empty(c.args["periodikum"]) and not p.empty(c.args["url"]) then
    t.urlRegex = "^https?://([^/]*)"
    if p.frame then
      t.periodikum = mw.ustring.match(c.args["url"], t.urlRegex)
    else
      t.periodikum = string.match(c.args["url"], t.urlRegex)
    end
    if t.periodikum then
      c.args["periodikum"] = t.periodikum
    end
  end
end

-- *** Pomocné funkce přidávající výstup do pole c.r ***
-- Odkazy pro harvardské citace
-- Srovnej cs:Modul:Footnotes / core() / grep CITEREF
-- Srovnej en:Module:Citation/CS1 fce / anchor_id() -- tam je trochu jiné řešení, bere v úvahu více polí
function p.citAnchorId(c)
  local t = {}
  if c.printAnchor then
    if c.args.ref == "harv" then
      t.r = {}
      if not p.empty(c.args["příjmení1"]) then
        for i = 1, 4 do
          if not p.empty(c.args["příjmení" .. i]) then
            table.insert(t.r, c.args["příjmení" .. i])
          end
        end
        if not p.empty(c.args["rok"]) then
          table.insert(t.r, c.args["rok"])
        end
      end
      t.ref = "CITEREF" .. table.concat(t.r)
    else
      t.ref = "CITEREF" .. c.args.ref
    end
    table.insert(c.r, ' id="' .. t.ref .. '"')
  end
end

function p.citAuthors(c, params)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}, i

  if params.honorCorporation and not p.empty(c.args["korporace"]) then
    c.state.lastAuthor = c.args["korporace"]
    table.insert(c.r, ""
      .. p.wikilink(c.args["odkaz na korporaci"], c.args["korporace"])
    )
  else
    for i = 1, params.maxAuthors do
      p.citAuthor(t, c, i)
    end
  end

  -- if not p.empty(c.args["korporace"]) or not p.empty(c.args["autor1"]) or not p.empty(c.args["příjmení1"]) then
  if not p.empty(c.state.lastAuthor) then
    if not p.empty(c.args["spoluautoři"]) then
      c.state.lastAuthor = c.args["spoluautoři"]
      table.insert(c.r, ", " .. c.args["spoluautoři"])
    end
  end

  if c.useHarvardFormat and not p.empty(c.args["rok"]) then
    c.state.lastAuthor = c.args["rok"]
    table.insert(c.r, ", " .. c.args["rok"])
  end

  -- pokud posledni jmeno nekonci teckou, pak ji vlozime
  -- DBG
  if nil and c.state.lastAuthor then
    table.insert(c.r, "[" .. c.state.lastAuthor .. "/" .. p.lastChar(c.state.lastAuthor) .. "]")
  end

  if c.state.lastAuthor and p.lastChar(c.state.lastAuthor) ~= '.' then
    table.insert(c.r, ".")
  end
end

function p.citAuthor(t, c, i)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t["autor"] = nil

  if not p.empty(c.args["autor" .. i]) then
    t["autor"] = c.args["autor" .. i]
  elseif not p.empty(c.args["příjmení" .. i]) then
    t["autor"] = p.upper(c.args["příjmení" .. i])
      .. (not p.empty(c.args["jméno" .. i]) and (', ' .. c.args["jméno" .. i]) or "")
    ;
  end

  if t["autor"] ~= nil then
    c.state.lastAuthor = t.autor
    table.insert(c.r, ""
      .. (i == 1 and "" or "; ")
      .. p.wikilink(c.args["odkaz na autora" .. i], t.autor)
    )
  end
end

function p.citCompilers(c, params)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}, i

  if params.honorCorporation and not p.empty(c.args["sestavující korporace"]) then
    c.state.lastCompiler = c.args["sestavující korporace"]
    table.insert(c.r, ""
      .. p.wikilink(c.args["odkaz na sestavující korporaci"], c.args["sestavující korporace"])
    )
  else
    for i = 1, 1 do
      p.citCompiler(c, t, i)
    end
  end

  if not p.empty(c.state.lastCompiler) then
    if not p.empty(c.args["spolusestavitelé"]) then
      c.state.lastCompiler = c.args["spolusestavitelé"]
      table.insert(c.r, ", " .. c.args["spolusestavitelé"])
    else
      for i = 2, params.maxAuthors do
        p.citCompiler(c, t, i)
      end
    end
  end

  -- pokud posledni jmeno nekonci teckou, pak ji vlozime
  if c.state.lastCompiler ~= nil and p.lastChar(c.state.lastCompiler) ~= '.' then
    table.insert(c.r, ".")
  end
end

function p.citCompiler(c, t, i)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t["sestavitel"] = nil

  if not p.empty(c.args["sestavitel" .. i]) then
    t["sestavitel"] = c.args["sestavitel" .. i]
  elseif not p.empty(c.args["příjmení sestavitele" .. i]) then
    t["sestavitel"] = p.upper(c.args["příjmení sestavitele" .. i])
      .. (not p.empty(c.args["jméno sestavitele" .. i]) and (', ' .. c.args["jméno sestavitele" .. i]) or "")
    ;
  end

  if t["sestavitel"] ~= nil then
    c.state.lastCompiler = t.sestavitel
    table.insert(c.r, ""
      .. (i == 1 and "" or "; ")
      .. p.wikilink(c.args["odkaz na sestavitele" .. i], t.sestavitel)
    )
  end
end

-- editor, preklad apod.
-- NOTE: texty převzaty ze šablony "citace monografie" V š. "citace periodika" byly drobné rozdíly ve std. textech.
function p.citOtherPersons(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}, i
  t.dalsi = {}

  if not p.empty(c.args["editoři"]) then
    table.insert(t.dalsi, "příprava vydání " .. c.args["editoři"])
  end
  if not p.empty(c.args["redaktoři"]) then
    table.insert(t.dalsi, "redakce " .. c.args["redaktoři"])
  end
  if not p.empty(c.args["překladatelé"]) then
    table.insert(t.dalsi, "překlad " .. c.args["překladatelé"])
  end
  if not p.empty(c.args["ilustrátoři"]) then
    table.insert(t.dalsi, "ilustrace " .. c.args["ilustrátoři"])
  end
  if not p.empty(c.args["fotografové"]) then
    table.insert(t.dalsi, "fotografie " .. c.args["fotografové"])
  end
  if not p.empty(c.args["další"]) then
    table.insert(t.dalsi, c.args["další"])
  end

  i = 0
  for k, v in pairs(t.dalsi) do
    t.v = i == 0 and " " .. p.upperFirst(v) or "; " .. v
    table.insert(c.r, t.v)
    i = i + 1
  end

  if i > 0 then
    table.insert(c.r, ".")
  end
end

function p.citTitle(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["titul"]) then
    table.insert(c.r, " ")
    if c.type == 'citaceMonografie' then
      table.insert(c.r, ""
        .. "''" .. p.nowiki(c)
        .. p.wikilink(c.args["odkaz na titul"], c.args["titul"])
        .. p.nowiki(c) .. "''"
        .. (not p.empty(c.args["titul původní"]) and " (původním názvem: ''" .. p.nowiki(c) .. c.args["titul původní"] .. p.nowiki(c) .. "'')" or "")
        .. "."
      )
    elseif c.type == 'citaceElMonografie' then
      table.insert(c.r, ""
        .. "''" .. p.nowiki(c)
        .. p.wikilink(c.args["odkaz na titul"], c.args["titul"])
        .. p.nowiki(c) .. "''"
        .. " " .. p.nowiki(c, "[") .. p.coalesceN(3, { c.args["druh nosiče"], c.args["formát"], "online" }) .. p.nowiki(c, "]")
        .. "."
      )
    else
      table.insert(c.r, ""
        .. p.wikilink(c.args["odkaz na titul"], c.args["titul"])
        .. "."
      )
    end
  end
end

function p.citCompilation(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["sborník"]) then
    table.insert(c.r, " "
      .. "''" .. p.nowiki(c)
      .. p.wikilink(c.args["odkaz na sborník"], c.args["sborník"])
      .. p.nowiki(c) .. "''"
      .. "."
    )
  end
end

function p.citPeriodical(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["periodikum"]) then
    table.insert(c.r, " "
      .. "''" .. p.nowiki(c)
      .. p.wikilink(c.args["odkaz na periodikum"], c.args["periodikum"])
      .. p.nowiki(c) .. "''"
      .. (c.type == "citaceElPeriodika"
        and " " .. p.nowiki(c, "[") .. p.coalesceN(3, { c.args["druh nosiče"], c.args["formát"], "online" }) .. p.nowiki(c, "]")
        or ""
      )
      .. "."
    )
  else
    table.insert(c.r, '<small>Chybí název periodika!</small>')
  end
end

function p.citEdition(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["vydání"]) then
    table.insert(c.r, " "
      .. c.args["vydání"] .. "."
      .. (not p.empty(c.args["typ vydání"]) and ", " .. c.args["typ vydání"] or "")
      .. " vyd."
    )
  end
end

function p.citVolume(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["svazek"]) then
    table.insert(c.r, " "
      .. (not p.empty(c.args["typ svazku"]) and p.upperFirst(c.args["typ svazku"]) or "Svazek")
      .. " " .. c.args["svazek"] .. "."
    )
  end
end

-- dle ISO 690 platne od dubna 2011 uz neni vyzadovana mezera pred ":"
function p.citPlacePublisher(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if c.type == 'citacePeriodika' or c.type == 'citaceElMonografie' or c.type == 'citaceElPeriodika' then
    table.insert(c.r, ""
      .. ((not p.empty(c.args["místo"]) or not p.empty(c.args["vydavatel"])) and " " or "")
      .. "" .. (not p.empty(c.args["místo"]) and " " .. c.args["místo"] .. ": " or "")
      .. "" .. (not p.empty(c.args["vydavatel"]) and p.wikilink(c.args["odkaz na vydavatele"], c.args["vydavatel"]) or "")
    )
  else
    table.insert(c.r, ""
      .. " " .. (not p.empty(c.args["místo"]) and c.args["místo"] or "[s.l.]")
      .. ": " .. (not p.empty(c.args["vydavatel"]) and p.wikilink(c.args["odkaz na vydavatele"], c.args["vydavatel"]) or "[s.n.]")
    )
  end
end

-- NOTE: Neprehledny kod. Pokud mozno zjednodusit, pripadne take sjednotit format data.
function p.citDate(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.datum = not p.empty(c.args["datum"]) and c.args["datum"] or p.dateCs(c.args)

  if c.type == 'citaceElMonografie' or c.type == 'citaceElPeriodika' then
    if not p.empty(c.args["vydavatel"]) then
      t.finalDot = true;
    end

    if not p.empty(t.datum) then
      t.finalDot = true;
      table.insert(c.r, ""
        .. (not p.empty(c.args["vydavatel"]) and ", " .. t.datum or " " .. p.upperFirst(t.datum))
      )
    end

    if not p.empty(c.args["datum aktualizace"]) then
      t.finalDot = true;
      if not p.empty(c.args["vydavatel"]) or not p.empty(t.datum) then
        table.insert(c.r, ", " .. p.coalesce(c.args["typ aktualizace"], "rev."))
      elseif not p.empty(c.args["místo"]) then
        table.insert(c.r, " " .. p.coalesce(c.args["typ aktualizace"], "rev."))
      else
        table.insert(c.r, " " .. p.upperFirst(p.coalesce(c.args["typ aktualizace"], "rev.")))
      end
      table.insert(c.r, " " .. c.args["datum aktualizace"])
    end

    if not p.empty(c.args["datum přístupu"]) then
      t.finalDot = true;
      --if not p.empty(c.args["vydavatel"]) or not p.empty(t.datum) or not p.empty(c.args["datum aktualizace"]) then
        table.insert(c.r, " ")
      --end
      if not c.localTest and c.type == 'citaceElMonografie' then
        table.insert(c.r, "[cit. " .. p.frame:callParserFunction('#time', 'Y-m-d', c.args["datum přístupu"]) .. "]")
      else
        table.insert(c.r, "[cit. " .. c.args["datum přístupu"] .. "]")
      end
    end

    if (t.finalDot) then
      table.insert(c.r, ".")
    end
  elseif c.type == "citacePeriodika" then
    t.datum = p.dateCs(c.args)
    if c.useHarvardFormat and t.datum == c.args["rok"] then
      t.datum = ""
    end
    if not p.empty(t.datum) then
      c.state.isDatum = true
      if not p.empty(c.args["vydavatel"]) then
        table.insert(c.r, ", " .. t.datum)
      else
        table.insert(c.r, " " .. p.upperFirst(t.datum))
      end
    end
  else
    t.datum = p.dateCs(c.args) -- was p.date

    if c.useHarvardFormat and t.datum == c.args["rok"] then
      t.datum = ""
      t.finalDot = true
    end

    if t.datum ~= "" then
      table.insert(c.r, ", " .. t.datum)
    elseif not p.empty(c.args["rok copyrightu"]) then
      table.insert(c.r, ", c" .. c.args["rok copyrightu"])
    end

    if not p.empty(c.args["rok tisku"]) then
      if not p.empty(c.args["rok"]) or not p.empty(c.args["rok copyrightu"])  then
        table.insert(c.r, " (")
      else
        table.insert(c.r, ", ")
      end
      table.insert(c.r, p.dateCs(c.args, { postfix = " tisku" }) .. " tisk") -- was p.date
      if not p.empty(c.args["rok"]) or not p.empty(c.args["rok copyrightu"])  then
        table.insert(c.r, ")")
      end
    end

    if t.datum ~= "" or not p.empty(c.args["rok tisku"]) or t.finalDot then
      table.insert(c.r, ".")
    end
  end
end

-- refact/fix 1.6.2018
function p.citYearNumberPage(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.ar = {}

  if not p.empty(c.args["ročník"]) then
    table.insert(t.ar, (not p.empty(c.args["typ ročníku"]) and c.args["typ ročníku"] or "roč.") .. " " .. c.args["ročník"])
  end

  if not p.empty(c.args["číslo"]) then
    table.insert(t.ar, (not p.empty(c.args["typ čísla"]) and c.args["typ čísla"] or "čís.") .. " " .. c.args["číslo"])
  end

  if not p.empty(c.args["strany"]) then
    table.insert(t.ar, "s. " .. c.args["strany"])
  end

  -- test array length
  if #t.ar > 0 then
    if c.state.isDatum then
      table.insert(c.r, ", " .. table.concat(t.ar, ", ") .. ".")
    else
      table.insert(c.r, " " .. p.upperFirst(table.concat(t.ar, ", ")) .. ".")
    end
  elseif c.state.isDatum then
    table.insert(c.r, ".")
  end
end

-- refact 8.5.2018
function p.citChapterPage(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.ar = {}

  if not p.empty(c.args["kapitola"]) then
    table.insert(t.ar, ""
      .. (not p.empty(c.args["typ kapitoly"]) and p.upperFirst(c.args["typ kapitoly"]) or "Kapitola")
      .. " "
      .. p.wikiextlink(c.args["url kapitoly"], c.args["kapitola"])
    )
  end;
  if not p.empty(c.args["číslování"]) then
    table.insert(t.ar, c.args["číslování"])
  end
  if not p.empty(c.args["strany"]) then
    table.insert(t.ar, "s.&nbsp;" .. c.args["strany"])
  end
  if not p.empty(c.args["lokace"]) then
    table.insert(t.ar, c.args["lokace"])
  end

  -- test array length
  if #t.ar > 0 then
    table.insert(c.r, " " .. p.upperFirst(table.concat(t.ar, ", ")) .. ".")
  end
end

-- pocetSvazku, pocetStranPlusPrilohy
function p.citNumberOfVolumesPagesAppendices(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  t.pocetSvazku = ""
  if not p.empty(c.args["počet svazků"]) and (tonumber(c.args["počet svazků"]) or 0) > 1 then
    t.pocetSvazku = ""
      .. c.args["počet svazků"]
      .. "&nbsp;"
      .. p.plural(c.args["počet svazků"], "svazek", "svazky", "svazků")
    ;
  end
  if not p.empty(c.args["počet stran"]) then
    t.pocetStranPlusPrilohy = ""
      .. c.args["počet stran"] .. "&nbsp;s."
      .. (not p.empty(c.args["přílohy"]) and ", " .. c.args["přílohy"] or "")
    ;
  else
    t.pocetStranPlusPrilohy = ""
      .. (not p.empty(c.args["přílohy"]) and c.args["přílohy"] or "")
    ;
  end
  if t.pocetSvazku ~= "" then
    if (t.pocetStranPlusPrilohy ~= "") then
      table.insert(c.r, t.pocetSvazku .. " (" .. t.pocetStranPlusPrilohy .. ").")
    else
      table.insert(c.r, t.pocetSvazku .. ".")
    end
  else
    if (t.pocetStranPlusPrilohy ~= "") then
      table.insert(c.r, " " .. t.pocetStranPlusPrilohy)
      if p.lastChar(t.pocetStranPlusPrilohy) ~= "." then
        table.insert(c.r, ".")
      end
    end
  end
end

function p.citBookSeries(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["edice"]) then
    table.insert(c.r, " "
      .. "("
      .. p.upperFirst(c.args["edice"])
      .. (not p.empty(c.args["subedice"]) and ". " .. p.upperFirst(c.args["subedice"]) or "")
      .. (not p.empty(c.args["svazek edice"]) and p.nowiki(c, ';') .. " sv.&nbsp;" .. c.args["svazek edice"] or "")
      .. ")."
    )
  end
end

function p.citUrl(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}

  if c.type == 'citacePeriodika' then
    if not p.empty(c.args["url"]) then
      t.afterUrl = {}

      if not p.empty(c.args["formát"]) then
        table.insert(t.afterUrl, c.args["formát"])
      end

      if not p.empty(c.args["datum přístupu"]) then
        table.insert(t.afterUrl, "cit. " .. c.args["datum přístupu"])
      elseif not p.empty(c.args["rok přístupu"]) then
        table.insert(t.afterUrl, "cit. " .. c.args["rok přístupu"]
          .. (not p.empty(c.args["měsíc přístupu"])
            and "-" .. c.args["měsíc přístupu"] .. (not p.empty(c.args["den přístupu"]) and "-" .. c.args["den přístupu"] or "")
            or ""
          ))
        ;
      end

      t.afterUrlStr = table.concat(t.afterUrl, ", ");
      if t.afterUrlStr ~= "" then
        t.afterUrlStr = " " .. p.nowiki(c, "[") .. t.afterUrlStr .. "]"
      end

      c.state.afterUrlStr = t.afterUrlStr

      p.citUrlInnerFn(c)
    end
  else
    if not p.empty(c.args["url"]) then
      p.citUrlInnerFn(c)
    end
  end

  -- citacePeriodika
  --if not p.empty(c.args["url alt"]) then
  --table.insert(c.r, " [" .. c.args["url alt"] .. " (Alternativní odkaz)]")
  --end
  -- citaceElMonografie, citaceElPeriodika
  if not p.empty(c.args["url2"]) then
    table.insert(c.r, " "
      .. p.coalesce(c.args["dostupnost2"], "Dostupné také na:")
      .. " "
      .. p.wikiextlink(c.args["url2"])
      .. "."
    )
  end
  if not p.empty(c.args["url3"]) then
    table.insert(c.r, " "
      .. p.coalesce(c.args["dostupnost3"], "Dále dostupné na:")
      .. " "
      .. p.wikiextlink(c.args["url3"])
      .. "."
    )
  end
end

function p.citUrlInnerFn(c)
  local t = {}
  if not p.empty(c.args["url archivu"]) then
    t.liveUrl = c.args["nedostupné"] == "ne" or c.args["dead-url"] == "no" or c.args["deadurl"] == "no"
    table.insert(c.r, " "
      .. p.wikiextlink(c.args["url archivu"], p.coalesce(c.args["dostupnost"], "Dostupné v&nbsp;archivu"))
      .. ((t.liveUrl or not p.empty(c.args["datum archivace"])) and " pořízeném" or "")
      .. (t.liveUrl and " z&nbsp;" .. p.wikiextlink(c.args["url"], "originálu") or "")
      .. (not p.empty(c.args["datum archivace"]) and " dne&nbsp;" .. c.args["datum archivace"] or "")
      .. "."
    )
  else
    table.insert(c.r, " "
      .. p.wikiextlink(c.args["url"], p.coalesce(c.args["dostupnost"], "Dostupné online"))
      .. (c.state.afterUrlStr and c.state.afterUrlStr or "")
      .. "."
    )
  end
end

function p.citIsbn(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["isbn"]) then
    -- OLD
    -- table.insert(c.r, " [.[International Standard Book Number|ISBN].] [http://worldcat.org/isbn/" .. c.args["isbn"] .. " " .. c.args["isbn"] .. "].")
    -- NEW
    if c.localTest then
      table.insert(c.r, " "
        .. "{{ISBN|{{{isbn}}}}}"
        .. (not p.empty(c.args["isbn2"]) and ", {{ISBN|{{{isbn2}}}}}" or "")
        .. "."
      )
    else
      table.insert(c.r, " "
        .. c.frame:expandTemplate{title = 'ISBN', args = { c.args["isbn"] }}
        .. (not p.empty(c.args["isbn2"]) and ", " .. c.frame:expandTemplate{title = 'ISBN', args = { c.args["isbn2"] }} or "")
        .. "."
      )
    end
  end
end

function p.citIssn(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["issn"]) then
    table.insert(c.r, " [[International Standard Serial Number|ISSN]] [http://worldcat.org/issn/" .. c.args["issn"] .. " " .. c.args["issn"] .. "].")
  end;
end

function p.citDoi(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["doi"]) then
    table.insert(c.r, " [[Digital object identifier|DOI]]:[http://dx.doi.org/" .. mw.uri.encode(c.args["doi"]) .. " " .. c.args["doi"] .. "].")
  end;
end

function p.citOclc(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["oclc"]) then
    table.insert(c.r, " [[Online Computer Library Center|OCLC]] [http://worldcat.org/oclc/" .. mw.uri.encode(c.args["oclc"]) .. " " .. c.args["oclc"] .. "]")
  end;
end

function p.citPmid(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["pmid"]) then
    table.insert(c.r, " [[PubMed|PMID]] [https://www.ncbi.nlm.nih.gov/pubmed/" .. c.args["pmid"] .. " <span class='PMID'>" .. c.args["pmid"] .. "</span>].")
  end;
end

function p.citBibcode(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["bibcode"]) then
    table.insert(c.r, " [[Bibcode]]:[http://adsabs.harvard.edu/abs/" .. mw.uri.encode(c.args["bibcode"]) .. " " .. c.args["bibcode"] .. "].")
  end;
end

function p.citArxiv(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["arxiv"]) then
    table.insert(c.r, " [[arXiv]]:[http://arxiv.org/abs/" .. mw.uri.encode(c.args["arxiv"]) .. " " .. c.args["arxiv"] .. "].")
  end;
end

function p.citId(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["id"]) then
    table.insert(c.r, " " .. c.args["id"] .. ".")
  end;
end

function p.citNotes(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  if not p.empty(c.args["poznámky"]) then
    table.insert(c.r, " " .. p.upperFirst(c.args["poznámky"]) .. ".")
  end;
end

function p.checkPeriodical(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if p.empty(c.args["periodikum"]) then
    if c.localTest then
      t.chyba = '{{chyba|Chybí povinný parametr: V šabloně {{šablona|Citace periodika}} je nutno určit zdrojové "<code>periodikum</code>" odkazu!|kategorie=Údržba:Chybná volání citačních šablon|skrytý=skrytý}}'
    else
      t.chyba = c.frame:expandTemplate{title = 'chyba', args = {
        'Chybí povinný parametr: V šabloně '
          .. c.frame:expandTemplate{title = 'šablona', args = {'Citace periodika'}}
          .. ' je nutno určit zdrojové "<code>periodikum</code>" odkazu!',
        ['kategorie'] = 'Údržba:Chybná volání citačních šablon',
        ['skrytý'] = 'skrytý'
      }}
    end
    table.insert(c.r, t.chyba)
  end;
end

-- Return only primary language subtag from IETF language tag
function p.sanitizeLang(s)
  if type(s) ~= 'string' then return s end
  return mw.ustring.match(s, "^([a-z][a-z][a-z]?)-[A-Za-z][A-Za-z][A-Za-z]?$") or s
end

function p.citLanguage(c)
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if not p.empty(c.args["jazyk"]) then
    if c.localTest then
      t.jazykem = c.args["jazyk"]
    else
      t.jazykem = c.frame:expandTemplate{title = 'jazykem', args = { p.sanitizeLang(c.args["jazyk"]), toleruj = 'toleruj'}}
    end
    table.insert(c.r, " (" .. t.jazykem .. ")")
  end;
end

function p.citCoinsMonografie(c)
  if c.noCoins then return end
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if c.type == 'citaceElMonografie' then
    t.tplName = 'citaceelmonografie'
  else
    t.tplName = 'citacemonografie'
  end
  t.coins = 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfr_id=info:sid/cs.wikipedia.org:template' .. t.tplName
    .. '&rft.btitle=' .. mw.uri.encode(p.coalesce(c.args["titul"]))
    .. (not p.empty(c.args["doi"]) and "&rft_id=info:doi/" .. mw.uri.encode(c.args["doi"]) or "")
    .. (not p.empty(c.args["url"]) and "&rft_id=" .. mw.uri.encode(c.args["url"]) or "")
    .. (not p.empty(c.args["isbn"]) and "&rft.isbn=" .. mw.uri.encode(c.args["isbn"]) or "")
    .. (not p.empty(c.args["příjmení1"]) and "&rft.aulast=" .. mw.uri.encode(c.args["příjmení1"]) or "")
    .. (not p.empty(c.args["jméno1"]) and "&rft.aufirst=" .. mw.uri.encode(c.args["jméno1"]) or "")
    .. (not p.empty(c.args["autor1"]) and "&rft.au=" .. mw.uri.encode(c.args["autor1"]) or "")
    .. (not p.empty(c.args["příjmení2"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení2"] .. ", " .. p.coalesce(c.args["jméno2"])) or "")
    .. (not p.empty(c.args["autor2"]) and "&rft.au=" .. mw.uri.encode(c.args["autor2"]) or "")
    .. (not p.empty(c.args["příjmení3"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení3"] .. ", " .. p.coalesce(c.args["jméno3"])) or "")
    .. (not p.empty(c.args["autor3"]) and "&rft.au=" .. mw.uri.encode(c.args["autor3"]) or "")
    .. (not p.empty(c.args["korporace"]) and "&rft.aucorp=" .. mw.uri.encode(c.args["korporace"]) or "")
    .. (not p.empty(c.args["kapitola"]) and "&rft.atitle=" .. mw.uri.encode(c.args["kapitola"]) or "")
    .. (not p.empty(c.args["místo"]) and "&rft.place=" .. mw.uri.encode(c.args["místo"]) or "")
    .. (not p.empty(c.args["vydavatel"]) and "&rft.pub=" .. mw.uri.encode(c.args["vydavatel"]) or "")
    .. (not p.empty(c.args["rok"]) and "&rft.date=" .. mw.uri.encode(c.args["rok"]) or "")
    .. (not p.empty(c.args["vydání"]) and "&rft.edition=" .. mw.uri.encode(c.args["vydání"]) or "")
    .. (not p.empty(c.args["počet stran"]) and "&rft.tpages=" .. mw.uri.encode(c.args["počet stran"]) or "")
    .. (not p.empty(c.args["edice"]) and "&rft.series=" .. mw.uri.encode(c.args["edice"]) or "")
    .. (not p.empty(c.args["strany"]) and "&rft.pages=" .. mw.uri.encode(c.args["strany"]) or "")
  ;
  if c.localTest then
    t.coins = "(COinS:" .. t.coins .. ")"
  else
    t.coins = c.frame:expandTemplate{title = 'COinS', args = { obj = t.coins }}
  end
  table.insert(c.r, t.coins)
end

function p.citCoinsPeriodikum(c)
  if c.noCoins then return end
  if c.trace then p.trace(c, debug.getinfo(1, "n")) end
  local t = {}
  if c.type == 'citaceElPeriodika' then
    t.tplName = 'citaceelperiodika'
  else
    t.tplName = 'citaceperiodika'
  end
  t.coins = 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rfr_id=info:sid/cs.wikipedia.org:template' .. t.tplName
    .. '&rft.jtitle=' .. mw.uri.encode(p.coalesce(c.args["periodikum"]))
    .. (not p.empty(c.args["doi"]) and "&rft_id=info:doi/" .. mw.uri.encode(c.args["doi"]) or "")
    .. (not p.empty(c.args["url"]) and "&rft_id=" .. mw.uri.encode(c.args["url"]) or "")
    .. (not p.empty(c.args["titul"]) and "&rft.atitle=" .. mw.uri.encode(c.args["titul"]) or "")
    .. (not p.empty(c.args["datum"])
      and "&rft.date=" .. mw.uri.encode(c.args["datum"])
      or (not p.empty(c.args["rok"])
        and "&rft.date=" .. mw.uri.encode(c.args["rok"])
          .. (not p.empty(c.args["měsíc"])
            and "&rft.chron=" .. (not p.empty(c.args["den"])
              and mw.uri.encode(c.args["den"]) .. ". "
              or ""
            ) .. mw.uri.encode(c.args["měsíc"])
            or ""
          )
        or ""
      )
    )
    .. (not p.empty(c.args["ročník"]) and "&rft.volume=" .. mw.uri.encode(c.args["ročník"]) or "")
    .. (not p.empty(c.args["číslo"]) and "&rft.issue=" .. mw.uri.encode(c.args["číslo"]) or "")
    .. (not p.empty(c.args["strany"]) and "&rft.pages=" .. mw.uri.encode(c.args["strany"]) or "")
    .. (not p.empty(c.args["issn"]) and "&rft.issn=" .. mw.uri.encode(c.args["issn"]) or "")
    .. (not p.empty(c.args["příjmení1"]) and "&rft.aulast=" .. mw.uri.encode(c.args["příjmení1"]) or "")
    .. (not p.empty(c.args["jméno1"]) and "&rft.aufirst=" .. mw.uri.encode(c.args["jméno1"]) or "")
    .. (not p.empty(c.args["autor1"]) and "&rft.au=" .. mw.uri.encode(c.args["autor1"]) or "")
    .. (not p.empty(c.args["příjmení2"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení2"] .. ", " .. p.coalesce(c.args["jméno2"])) or "")
    .. (not p.empty(c.args["autor2"]) and "&rft.au=" .. mw.uri.encode(c.args["autor2"]) or "")
    .. (not p.empty(c.args["příjmení3"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení3"] .. ", " .. p.coalesce(c.args["jméno3"])) or "")
    .. (not p.empty(c.args["autor3"]) and "&rft.au=" .. mw.uri.encode(c.args["autor3"]) or "")
    .. (not p.empty(c.args["korporace"]) and "&rft.aucorp=" .. mw.uri.encode(c.args["korporace"]) or "")
    .. (not p.empty(c.args["místo"]) and "&rft.place=" .. mw.uri.encode(c.args["místo"]) or "")
    .. (not p.empty(c.args["vydavatel"]) and "&rft.pub=" .. mw.uri.encode(c.args["vydavatel"]) or "")
    .. (not p.empty(c.args["počet stran"]) and "&rft.tpages=" .. mw.uri.encode(c.args["počet stran"]) or "")
  ;
  if c.localTest then
    t.coins = "(COinS:" .. t.coins .. ")"
  else
    t.coins = c.frame:expandTemplate{title = 'COinS', args = { obj = t.coins }}
  end
  table.insert(c.r, t.coins)
end

return p