Documentation for this module may be created at Events/doc

local p = {}
local newline = "\r\n"
local tabchar = "	"

function makeURL(title)
	-- return '/wiki/index.php?title=' .. title
	return '/wiki/' .. title
end

function left(text, digits)
	return text:sub(1, digits)
end
function extractlfc(text)
	space = string.find(text, ":")
	if space == nil then return extractnumbers(text) end
	return extractnumbers(string.sub(text, 1, space-1))
end
function extractnumbers(text)
	res, _ = text:gsub("%D+", "")
	return res
end

function findevent(name, results)
	name = extractnumbers(name)
	for i = #results,2,-1 do
		local eventname = extractnumbers( results[i]["name"] )
		if name == eventname then return i end
	end
	return -1
end

function haskey(results, key)
	return results[key] ~= nil
end

function p.Infobox(frame)
	local HTML = ''
	local style = 0
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end	
	local results = require("Module:Results")
	local eventname = ""
	if origArgs["event"] ~= nil then 
		eventname = origArgs["event"]
	elseif origArgs[1] ~= nil then
		eventname = origArgs[1] 
	end
	if extractnumbers(eventname) == "" then
		if style == 0 then HTML = HTML .. '{| class="wikitable eventstable"' .. newline .. '|-' .. newline .. '! Picture' .. newline .. '! Name' .. newline ..  '! ' .. newline .. '! Date' .. newline .. '! Venue' .. newline .. '! Location' .. newline end
		if style == 1 then HTML = HTML .. '<div class="equal ministat-container" style="width: 100%">' end

		for i = #results,2,-1 do
			local event = results[i]
			local lfccode = extractlfc(event["name"])
			local date = "N/A"
			local venue = date
			local place = "TBD"
			local image = "https://lingeriefc.com/wiki/images/2/20/LFCthumb.jpg"
			if style == 0 then image = "" end
			if haskey(event, "thumb") then image = event["thumb"] end
			local eventimage = '<IMG class="events-image" SRC="' .. image .. '" class="lfc-events-thumbnail">'
			if style == 0 and image == "" then eventimage = "" end
			if style == 0 then 
				if event["file"] == "" or event["file"] == null then 
					eventimage = '[[Image:BiggerLogo.png|class=events-defaultimage|link=Event:' .. event["name"] .. ']]'
				else 
					eventimage = '[[Image:' .. event["file"] .. '|class=events-image|link=Event:' .. event["name"] .. ']]'
				end
			end
			if haskey(event, "date") then date = event["date"] end 
			if haskey(event, "venue") then 
				venue = event["venue"]
				if venue ~= "TBD" then
					if style == 0 then
						if venue ~= "" then venue = '[[Template:' .. venue:gsub("%&", "%%26") .. '|' .. venue .. ']]' else venue = "Unknown" end
					else 
						venue = '<A HREF="' .. makeURL('Template:' .. venue:gsub("%&", "%%26")) .. '">' .. venue .. '</A>'
					end
				end
			end
			if haskey(event, "place") then 
				place = event["place"]
				if place ~= "TBD" then place = frame:preprocess("{{Place|" .. place .. "}}") end
			end

			local eventname = event["name"]
			local TDL = newline .. '| style="vertical-align:middle !important;" | '
			local TDC = newline .. '| style="text-align:center; vertical-align:middle !important;" | '
			if style == 0 then 
				HTML = HTML .. newline .. '|- style="vertical-align:middle;"' .. newline  .. "| " .. eventimage 
				if venue == "TBD" or place == "TBD" then
					HTML = HTML .. newline ..TDL .. eventname
					HTML = HTML .. newline .. TDC
				else
				 	HTML = HTML .. newline .. TDL .. "[[Event:" .. eventname .. "|" .. eventname .. "]]"
				 	eventname = eventname:gsub(" ", "%%20")
				 	HTML = HTML .. ' [https://lingeriefc.com/wiki/Event:' .. eventname .. '?action=edit <i class="fa fa-fw fa-pencil fa-2x"></i>]'
					HTML = HTML .. newline .. TDC 
				end
		 		if haskey(results[1], "LFC" .. lfccode) then
				 	HTML = HTML .. '<!-- Begin BUY code -->' .. frame:preprocess(" {{Buy|LFC" .. lfccode .. "|3}}") .. '<!-- BUY CODE FOUND FOR LFC' .. lfccode .. '-->'
				else 
					HTML = HTML .. '<!-- BUY CODE NOT FOUND FOR LFC' .. lfccode .. '-->'
		 		end
				HTML = HTML .. TDC .. date
				HTML = HTML .. TDC .. venue
				HTML = HTML .. TDC .. place
			else
				if venue ~= "TBD" and place ~= "TBD" then
					eventurl = makeURL('Event:' .. eventname)
					eventimage = '<A href="' .. eventurl .. '">' .. eventimage  .. '</A>'
					eventname = '<A href="' .. eventurl .. '">' .. eventname  .. "</A>"
				end
				HTML = HTML .. '<div class="ministat-right col-xs-5 col-sm-3 col-md-2 ministat-fighter ministat-event">' .. eventimage .. '</DIV>'
				HTML = HTML .. '<div class="ministat-left col-xs-7 col-sm-3 col-md-2 ministat-fighter"><STRONG>' .. eventname .. '</STRONG><BR>' .. date .. '<br>' .. venue .. '<br>' .. place 
				if haskey(results[1], "LFC" .. lfccode) then
					HTML = HTML .. '<div class="ministat-icons">' .. frame:preprocess(" {{Buy|LFC" .. lfccode .. "}}") .. '</DIV>'
				end
				HTML = HTML .. '</DIV>'
			end
		end
		if style == 0 then HTML = HTML .. newline .. "|}" else HTML = HTML .. newline .. '</div>' end
	else
		local eventindex = findevent(eventname, results)
		local event = results[eventindex]

		HTML = "{{Infobox Wrestling event"
		if haskey(event, "name") then HTML = HTML .. newline  .. "|name=" .. event["name"] end
		if haskey(event, "image") then HTML = HTML .. newline  .. "|image=" .. event["file"] end
		if haskey(event, "date") then HTML = HTML .. newline  .. "|date=" .. event["date"] end
		if haskey(event, "time") then 
			HTML = HTML .. newline  .. "|time=" .. totime(event["time"], 0) .. " ET / " .. totime(event["time"], -1) .. " CT / " .. totime(event["time"], -2) .. " MT / " .. totime(event["time"], -3) .. " PT"
		end
		if haskey(event, "venue") then HTML = HTML .. newline  .. "|venue=[[Template:" .. event["venue"] .. "]]" end
		if haskey(event, "place") then HTML = HTML .. newline  .. "|city={{Place|" .. event["place"] .. "}}" end
		if haskey(event, "imdb") then HTML = HTML .. newline  .. "|imdb=" .. event["imdb"] end
		HTML = HTML .. newline .. "}}"
		HTML = frame:preprocess(HTML)

		HTML = '<DIV CLASS="wiki-container"><DIV ID="infoheader" CLASS="row lfcresponsive"><DIV ID="lfcvideo" CLASS="col-md-8 nopadding" STYLE="padding-top: 0px;padding-bottom: 0px;"></DIV><DIV CLASS="col-md-4 nopadding" ID="lfcbox">' .. HTML .. '</DIV></DIV></DIV>'
	end
	return HTML
end

function totime(number, timezoneoffset)
	number = tonumber(number) + (tonumber(timezoneoffset)*100)
	if number < 0 then number = number + 2400 end
	if number > 2399 then number = number - 2400 end

	local hours = math.floor(number/100)
	local minutes = number - (hours*100)
	local ampm = "am"
	if hours > 11 then
		ampm = "pm"
		hours = hours - 12
	end
	if hours == 0 then hours = 12 end
	if minutes < 10 then minutes = "0" .. minutes end
	return hours .. ":" .. minutes .. " " .. ampm
end

return p


© 2019 • Lingerie Fighting Championships / Terms / Privacy