Modul:Musikcharts/certifications

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus


local p = {}
	
p.certicon = function (frame, certification, icontype, size)
	
	local certtable = {
		["S"] = {"silver", "silber"},
		["G"] = {"gold", "gold"},
		["P"] = {"platinum", "platin"},
		["D"] = {"diamond", "diamant"}
	}
	local numbers =  { "", "Double", "Triple", "Quadruple", "Quintuple", "Sextuple", "Septuple", "Octuple", "Nonuple", "Decuple" }
	local numbers2 = { "", "Doppel", "Drei", "Vier", "Fünf", "Sechs", "Sieben", "Acht", "Neun", "Zehn", "Elf", "Zwölf" }
	
	local certraw = certification or frame.args[1]
	local icontype = icontype or frame.args["icontype"]
	
	-- delete strip markers
	if certraw then
		certraw = mw.text.unstrip( certraw )
	else
		certraw = ""
	end
	
	local icon
	if string.match (certraw, "%[%[Datei:") or string.match (certraw, "%[%[File:") or string.match (certraw, "%[%[Bild:") then
		icon = certraw
	end
	
	local certraw2
	if string.match (certraw, ".%+") then
		certraw, certraw2 = string.match (certraw, "(.+)%+(.+)")
	end

	-- find brackets
	local brackets
	local brackets2
	if string.match (certraw, "%(") then
		certraw, brackets = string.match (certraw, "(.+)%((.-)%)")
	end
	if certraw2 then
		if string.match (certraw2, "%(") then
			certraw2, brackets2 = string.match (certraw2, "(.+)%((.-)%)")
		end
	end
	
	local number
	local number2
	if string.match(certraw, "%d+") then
		number = string.match(certraw, "(%d+)")
	else
		number = 1
	end
	if certraw2 then
		number2 = string.match(certraw2, "(%d+)") or 1
	end
	
	local certname
	local certname2
	for key, value in pairs (certtable) do
		if string.match (certraw, key) then
			certname = key
		end
		if certraw2 then
			if string.match (certraw2, key) then
				certname2 = key
			end
		end
	end
	
	local oldicon
	local tooltip
	local tooltip2
	local newicon
	local texticon
	local supicon
	local caption
	local caption2
	local capcertname
	local capcertname2
	if certtable[certname] then
		capcertname = string.gsub(certtable[certname][2], "^%l", string.upper)
	else
		capcertname = certname
	end
	if certtable[certname2] then
		capcertname2 = string.gsub(certtable[certname2][2], "^%l", string.upper)
	else
		capcertname2 = certname2 or ""
	end
	
	-- direct files
	if not certtable[certname] then
		icon = certraw
	else
		
	-- create tooltip and caption
		if tonumber(number) > 1 then
			if tonumber(number) == 2 then
				tooltip = numbers2[tonumber(number)] .. certtable[certname][2]
			elseif tonumber(number) < 13 then
				tooltip = numbers2[tonumber(number)] .. "fach" .. certtable[certname][2]
			else
				tooltip = number .. "-fach-" .. capcertname
			end
			caption = number .. "×&nbsp;" .. capcertname
		else
			tooltip = capcertname
			caption = tooltip
		end
		if brackets then
			tooltip = tooltip .. " (" .. brackets .. ")"
			caption = caption .. " (" .. brackets .. ")"
		end
		if certraw2 then
			if tonumber(number2) > 1 then
				if tonumber(number2) == 2 then
					tooltip2 = numbers2[tonumber(number2)] .. certtable[certname2][2]
				elseif tonumber(number2) < 13 then
					tooltip2 = numbers2[tonumber(number2)] .. "fach" .. certtable[certname2][2]
				else
					tooltip2 = number2 .. "-fach-" .. capcertname2
				end
				caption2 = number2 .. "×&nbsp;" .. capcertname2
			else
				tooltip2 = capcertname2
				caption2 = tooltip2
			end
		end
		if brackets2 then
			tooltip2 = tooltip2 .. " (" .. brackets2 .. ")"
			caption2 = caption2 .. " (" .. brackets2 .. ")"
		end
		if tooltip2 then
			tooltip = tooltip .. "&nbsp;+ " .. tooltip2
		end
		if caption2 then
			caption = caption .. "&nbsp;+ " .. caption2
		end
		
	-- create old files
		local certfile = ""
		local certfile2 = ""
--[[		if tonumber(number) > 1 then			ONLY SINGLE FILES
			if tonumber(number) < 11 then
				certfile = numbers[tonumber(number)] .. " "
			else
				certfile = "Decuple "
			end
		end
		if certraw2 then
			if tonumber(number2) > 1 then
				if tonumber(number2) < 11 then
					certfile2 = numbers[tonumber(number2)] .. " "
				else
					certfile2 = "Decuple "
				end
			end
		end ]]
		certfile = certfile .. certtable[certname][1] .. " record icon.svg"
		if certraw2 and certtable[certname2] then
			certfile = certfile .. "|15px|link=]][[File:" .. certfile2 .. certtable[certname2][1] .. " record icon.svg"
		end
		
	-- create old icon style
		oldicon = "<div class='charts-certc'>[[File:" .. certfile .. "|15px|link=|alt=" .. tooltip .. "]]"
		oldicon = oldicon .. "<span class='charts-certt'>" .. tooltip .."<i></i></span></div>"
		
	-- create new icon style
		if not size then
			size = "17"
		end
		newicon = "<div class='charts-certc'><div class='charts-cert'>[[File:" .. certtable[certname][1] .. " record icon2.svg|"
		newicon = newicon .. size .. "px|link=|alt=" .. tooltip .. "]]"
		if tonumber(number) then
			if tonumber(number) > 1 then
				newicon = newicon .. "<div class='charts-certn'"
				if tonumber(number2) then
					newicon = newicon .. " style='left:50%; z-index:10;'"
				end
				newicon = newicon .. ">×" .. number .. "</div>"
			end
		end
		newicon = newicon .. "</div>"
		if certraw2 and certtable[certname2] then
			newicon = newicon .. "<div class='charts-cert' style='margin-left:-8px'>[[File:" .. certtable[certname2][1] .. " record icon2.svg|"
			newicon = newicon .. size .. "px|link=|alt=" .. tooltip .. "]]"
			if tonumber(number2) then
				if tonumber(number2) > 1 then
					newicon = newicon .. "<div class='charts-certn'>×" .. number2 .. "</div>"
				end
			end
			newicon = newicon .. "</div>"
		end
		newicon = newicon .. "<span class='charts-certt'>" .. tooltip .."<i></i></span></div>"
		
	-- create sup icon style
		supicon = "<div class='charts-certc'><div class='charts-cert'>[[File:" .. certtable[certname][1] .. " record icon.svg|15px|link=|alt=" .. tooltip .. "]]"
		if tonumber(number) then
			if tonumber(number) > 1 then
				supicon = supicon .. "<div class='charts-certn'"
				if tonumber(number2) then
					supicon = supicon .. " style='left:50%; z-index:10;'"
				end
				supicon = supicon .. ">×" .. number .. "</div>"
			end
		end
		supicon = supicon .. "</div>"
		if certraw2 and certtable[certname2] then
			supicon = supicon .. "<div class='charts-cert' style='margin-left:-5px'>[[File:" .. certtable[certname2][1] .. " record icon.svg|15px|link=|alt=" .. tooltip .. "]]"
			if tonumber(number2) then
				if tonumber(number2) > 1 then
					supicon = supicon .. "<div class='charts-certn'>×" .. number2 .. "</div>"
				end
			end
			supicon = supicon .. "</div>"
		end
		supicon = supicon .. "<span class='charts-certt'>" .. tooltip .."<i></i></span></div>"

	-- create text icon
		texticon = "[[File:" .. certfile .. "|15px|link=]]&nbsp;" .. caption
	end
	
	local ret = ""
	if icon then 
		ret = ret .. "<div style='display:inline-block;'>" .. icon .. "</div>"
	elseif icontype == "text" then
		ret = texticon
	elseif icontype == "sup" then
		ret = supicon
	elseif icontype == "new" then
		ret = ret .. newicon
	elseif icontype == "old" then
		ret = ret .. oldicon
	else
		ret = ret .. supicon
	end
	

	return ret

end

return p