Line 927: Line 927:
 
if results[1][id] ~= nil then
 
if results[1][id] ~= nil then
 
if style == 2 and results[1][id]["streamsku"] ~= nil then
 
if style == 2 and results[1][id]["streamsku"] ~= nil then
HTML = '<DIV CLASS="buylfc row"><DIV CLASS="col-md-12">Please purchase one of the following or <A HREF="/my-account">login</A> to watch this video:</DIV><DIV CLASS="col-md-6">'
+
HTML = '<DIV CLASS="buylfc row"><DIV CLASS="col-md-12">Please purchase the following or <A HREF="/my-account">login</A> to watch this video:</DIV><DIV CLASS="col-md-offset-3 col-md-6">'
 
HTML = HTML .. '[products ids="40055" columns="1" class="embeddedproduct"]'
 
HTML = HTML .. '[products ids="40055" columns="1" class="embeddedproduct"]'
HTML = HTML .. '</DIV><DIV CLASS="col-md-6">'
+
HTML = HTML .. '</DIV><!--DIV CLASS="col-md-6">'
 
HTML = HTML .. '[products ids="' .. results[1][id]["streamsku"] .. '" columns="1" class="embeddedproduct"]'
 
HTML = HTML .. '[products ids="' .. results[1][id]["streamsku"] .. '" columns="1" class="embeddedproduct"]'
HTML = HTML .. '</DIV></DIV>'
+
HTML = HTML .. '</DIV--><DIV CLASS="col-md-3"></DIV></DIV>'
 
else
 
else
 
if style == 3 then HTML = '<DIV ALIGN="CENTER" CLASS="buylfc">' end
 
if style == 3 then HTML = '<DIV ALIGN="CENTER" CLASS="buylfc">' end

Latest revision as of 14:33, 11 June 2019

Documentation for this module may be created at Fightcard/doc

local p = {}
 
local args = {}
local origArgs
local root
local monthnames = {"January","February","March","April","May", "June", "July", "August", "September", "October", "November", "December"}
local nopages = {"Roni Taylor", "Arik Loegen", "Jason Parsons", "Johnny D. Struxion", "Joel Kane", "Mike Adams", "Mike Modest", "Lizzie Hunter", "Leon Hater", "A.J. Kirsch"}
local nonicks = {"Cali Cat", "Mona Jones", "Bella Ink", "Sybill Starr"}
local nicknames = {}
	nicknames['Allie Parks'] = 'Babydoll'
	nicknames['Jesabella Marie'] = 'Fire Queen'
	nicknames['Lexey Rocha'] = 'DethAngel'
	nicknames['Katie Forbes'] = 'The Bombshell'
	nicknames['Lina Inverse'] = 'The Dragon Spooker'
	nicknames['Violeta Sunic'] = 'Dark Force'
	nicknames['Jenny Valentine'] = 'Bloody'
	nicknames['Jolene Hexx'] = 'The Valkyrie'
	nicknames['Teri London'] = 'Feisty Fists'
	nicknames['Andreea Vladoi'] = 'The Storm'
	nicknames['Roxy Michaels'] = 'Roundhouse'
	nicknames['Jessie Santos'] = 'El Toro'
	nicknames['Piper Rose'] = 'Code Red'
	nicknames['Maxine Frost'] = 'The Boss'
	nicknames['Maya Veljkovic'] = 'Hellfire'
	nicknames['Lauren Fogle'] = 'The Animal'
	nicknames['MaiNe Morgan'] = 'Main Event'
	nicknames['Stacey Lentz'] = 'Full Contact'
	nicknames['Karly Zucker'] = 'Zuke'
	nicknames['Julie Ginther'] = 'Squeeze'
	nicknames['Natasha Rodriguez'] = 'Rattlesnake'
	nicknames['Audrey Monique'] = 'The Mongoose'
	nicknames['Shelly DaSilva'] = 'Aphrodite'
	nicknames['Danielle St. Pierre'] = 'Cow Belle'
	nicknames['Raya Ryans'] = 'Sugar Ray'
	nicknames['Feather Hadden'] = 'The Hammer'
	nicknames['Shay Mazzato'] = 'The Fox'
	nicknames['Sheila Cardinal'] = 'Crash'
	nicknames['Serina Kyle'] = 'Honey Punch'
	nicknames['Holly Mei'] = 'The Lotus'
	nicknames['Jenevieve Hexxx'] = 'The Sorceress'
	nicknames['Riley Norris'] = 'Nuclear'
	nicknames['Kris Blackwell'] = 'The Raven'
	nicknames['Chloe Cameron'] = 'Ladykillah'
	nicknames['Michelle Blanchard'] = 'Scrapper'
	nicknames['Tara Gaddy'] = 'Guillotine'
	nicknames['Suzanne Nakata'] = 'Hawaiian Punch'
	nicknames['Helen Mei'] = 'Ignite'
	nicknames['Samiha Glam'] = 'The Goddess'
	nicknames['Sara Dee'] = 'Double'
	nicknames['Jody Connacher'] = 'Conquering Angel'
	nicknames['Beth Moore'] = 'Mount Crush'
	nicknames['Chelsea London'] = 'Feisty Fists'
	nicknames['Brenda Jones'] = 'Juice'
	nicknames['Megan Doll'] = 'Baby'
	nicknames['Robyn Hawkens'] = 'Ruthless'
	nicknames['Roxanne Romaro']= 'The Viper'
	nicknames['Susan Cordell'] = 'Tatia'
	nicknames['Karmen Moon'] = 'Cherry Bomb'
	nicknames['Monica Garcia'] = 'Flowerbomb'
	nicknames['Rochelle Rodgers'] = 'Rampage'
	nicknames['Agatha Carter'] = 'Cannibal'
	nicknames['C.J. Kellerman'] = 'Ice Cold'
	nicknames['Jessica Vattiera'] = 'Sekhmet'
	nicknames['Tomiko Tajima'] = 'The Temptress'
	nicknames['Tasia Lockran'] = 'Thrash'
	nicknames['Jenn Repp'] = 'The Real Deal'
	nicknames['Gypsy Bae'] = 'Top Shelf'
	nicknames['Lisa Danielle'] = 'Onyx'
	nicknames['Andrea Morales'] = 'The Muse'
	nicknames['Gemma Giuliana'] = 'Jersey Babe'

local stylesynonyms = {}
	stylesynonyms["Wrestling"] = "Wrestler"
	stylesynonyms["Kickboxing"] = "Kickboxer"
	stylesynonyms["Scrapping"] = "Scrapper"
	stylesynonyms["Brawling"] = "Brawler"
	stylesynonyms["Ju-Jitsu"] = "Ju Jitsu"
	stylesynonyms["Muay-Thai"] = "Muay Thai"
local countries = {}
	countries["Canada"] = {AB="Alberta", BC="British Columbia", MB="Manitoba", NB="New Brunswick", NL="Newfoundland and Labrador", NS="Nova Scotia", NT="Northwest Territories", NU="Nunavut", ON="Ontario", PE="Prince Edward Island", QC="Quebec", SK="Saskatchewan", YT="Yukon"}
	countries["USA"] = {AL="Alabama", AK="Alaska", AZ="Arizona", AR="Arkansas", CA="California", CO="Colorado", CT="Connecticut", DE="Delaware", FL="Florida", GA="Georgia", HI="Hawaii", ID="Idaho", IL="Illinois", IN="Indiana", IA="Iowa", KS="Kansas", KY="Kentucky", LA="Louisiana", ME="Maine", MD="Maryland", MA="Massachusetts", MI="Michigan", MN="Minnesota", MS="Mississippi", MO="Missouri", MT="Montana", NE="Nebraska", NV="Nevada", NH="New Hampshire", NJ="New Jersey", NM="New Mexico", NY="New York", NC="North Carolina", ND="North Dakota", OH="Ohio", OK="Oklahoma", OR="Oregon", PA="Pennsylvania", RI="Rhode Island", SC="South Carolina", SD="South Dakota", TN="Tennessee", TX="Texas", UT="Utah", VT="Vermont", VA="Virginia", WA="Washington", WV="West Virginia", WI="Wisconsin", WY="Wyoming", AS="American Samoa", DC="District of Columbia", FM="Federated States of Micronesia", GU="Guam", MH="Marshall Islands", MP="Northern Mariana Islands", PW="Palau", PR="Puerto Rico", VI="Virgin Islands", AE="Armed Forces Africa", AA="Armed Forces Americas", AE="Armed Forces Canada", AE="Armed Forces Europe", AE="Armed Forces Middle East", AP="Armed Forces Pacific"}
local events = {}
	events[1] = 'Las Vegas'
	events[2] = events[1]
	events[3] = 'Reno'
	events[4] = events[1]
	events[5] = events[1]
	events[6] = 'Palm Springs'
	events[7] = 'Los Angeles'
	events[8] = events[1]
	events[9] = events[1]
	events[10] = events[1]
	events[11] = 'Phoenix'
	events[12] = events[1]
	events[13] = 'New York'
	events[14] = events[7]
	events[15] = events[1]
	events[16] = events[1]
	events[17] = events[1]
	events[18] = 'Lace vs. Leather'
	events[19] = 'Hadden vs. Mei'
	events[20] = "A Midsummer Night's Dream"
	events[21] = "Naughty 'n Nice"
	events[22] = 'Costume Brawl'
	events[23] = 'Guilty Pleasures'
	events[24] = 'Eurobash'
	events[25] = "Showdown At Sam's Town"
	events[26] = "Booty Camp"
	events[27] = "Sexy, Nerdy, Inked & Curvy"

local function preprocessSingleArg(argName)
    -- If the argument exists and isn't blank, add it to the argument table.
    -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
    if origArgs[argName] and origArgs[argName] ~= '' then
        args[argName] = origArgs[argName]
    end
end

function trim(s)
	if s == nil then return "" end
	return (s:gsub("^%s*(.-)%s*$", "%1"))
end

local function getnickname(fighter, frame)
	fighter = trim(fighter):gsub("‘", "'"):gsub("’", "'"):gsub("“", "'"):gsub("”", "'"):gsub('"', "'")
	nickname = ''
	if nicknames[fighter] ~= nil then 
		nickname = nicknames[fighter]
	end
	if nickname ~= '' then 
		space = string.find(fighter, " ")
		left = string.sub(fighter, 1, space-1) 
		right = string.sub(fighter, -string.len(fighter)  + space)
		fighter = left .. " '" .. nickname .. "' " .. right
	end
	return fighter
end

local function vscard(frame, eventname, eventtype)
	index=eventname:gsub("event", "")
	preprocessSingleArg(eventname)
	preprocessSingleArg(eventname .. 'vs')
	preprocessSingleArg("method" .. index)
	preprocessSingleArg("round" .. index)
	if args[eventname] ~= nil and args[eventname .. "vs"] ~= nil then
		root:wikitext('<DIV CLASS="equal vs-container">')
		results = '<DIV CLASS="col-md-3"></DIV>'
		if args["method" .. index] ~= nil and args["round" .. index] ~= nil then
			results = '<DIV CLASS="col-md-1"><DIV CLASS="vertical-center">' .. args["method" .. index] .. '</DIV></DIV><DIV CLASS="col-md-2"><DIV CLASS="vertical-center pull-right">' .. args["round" .. index] .. '</DIV></DIV>'
		end
		firstfighter = getnickname(args[eventname], frame)
		secondfighter = getnickname(args[eventname .. "vs"], frame)
		if eventtype == 1 then
			root:wikitext('<DIV CLASS="col-xs-12 text-center"><h2>Main Event / Title Bout</h2></DIV>')
		end 
		root:wikitext(frame:expandTemplate{ title = 'Ministats:' .. firstfighter , args = { '|' } } .. 
					'<DIV CLASS="col-md-4 col-xs-12 event-vs2" align="center"><DIV CLASS="clear:both;"></DIV></DIV>' ..
					frame:expandTemplate{ title = 'Ministats:' .. secondfighter, args = { '|' } } ..
					results )
		root:wikitext('</DIV>')
	end
end
 
function print(text)
	root:wikitext(text)
end

function p.nickname2(fighter, frame)
	return getnickname(fighter, frame)
end

function p.nickname(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if origArgs['name'] == nil then 
		local fighter = origArgs[1]
	else
		local fighter = origArgs['name']
	end
	return getnickname(fighter, frame)
end
function p.url(frame)
	origArgs = frame:getParent().args
	return getwikiurl(origArgs['name'])
end
function p.ministatsurl(frame)
	origArgs = frame:getParent().args
	return getwikiurl(origArgs['name'],"Template:Ministats")
end

function getwikiurl(fighter, namespace)
	if namespace == nil then
		namespace = ""
	else
		namespace = namespace .. ":" 
	end
	return makeURL(namespace .. getnickname(fighter, frame))
end

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

function allfighters(frame, HTML)
	local start = HTML:find("{") 
	while start ~= nil do
		local finish = HTML:find("}", start) 
		if finish ~= nil then 
			local currentfighter = HTML:sub(start+1, finish-1)
			local HREF = fighterHREF(currentfighter, frame)
			HTML = HTML:gsub("{" .. currentfighter .. "}",    HREF)
			start = HTML:find("{", finish) 
		else
			start = nil
		end
	end
	return HTML
end

function p.episode(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if args.child ~= 'yes' then
		local HTML = ""
		local i = 1
		HTML = HTML .. '<div class="rows"><div class="row title"><div class="col-md-4">Episode / Duration</div><div class="col-md-4">Synopsis</div><div class="col-md-4">Starring</div></div>'
		while origArgs['episode' .. i] and origArgs['episode' .. i] ~= '' do
			HTML = HTML .. '<div class="row entry"><div class="col-md-4 center">Episode ' .. origArgs['episode' .. i] .. ' (' ..  origArgs['duration' .. i] .. ')<P>'
			local URL = FiletoHTML(origArgs['file' .. i], frame)
			HTML = HTML .. '<A HREF="/wiki/File:' .. origArgs['file' .. i] .. '"><IMG SRC="' .. URL .. '"></A>'

			local e = 1
			local HTML2 = ""
			while origArgs['thumb' .. i .. "_" .. e] and origArgs['thumb' .. i .. "_" .. e] ~= '' do
				HTML2 = HTML2 .. makethumb(origArgs['thumb' .. i .. "_" .. e], origArgs['thumb' .. i .. "_" .. e])
				e = e + 1
			end
			if #HTML2 > 0 then
				HTML = HTML .. '<DIV Class="image-container">' .. HTML2 .. '</DIV>'
			end

			HTML = HTML .. '</P></div><div class="col-md-4"><P>' .. allfighters(frame, origArgs['summary' .. i]:gsub('<P>', '</P><P>'))  .. '</P>' 
			HTML = HTML .. '</div><div class="col-md-3">' .. starring(split(origArgs["starring" .. i], ","))
			if origArgs['outfits' .. i] and origArgs['outfits' .. i] ~= '' then 
				HTML = HTML .. '<BR><P>Outfits: ' .. origArgs['outfits' .. i]
			end
			if origArgs['joelinapool' .. i] and origArgs['joelinapool' .. i] ~= '' then
				HTML = HTML .. '<BR><P>Joel gets thrown in a pool by: ' .. fighterHREF(origArgs['joelinapool' .. i], frame)
			end
			HTML = HTML .. '</div></div>'
			i = i + 1
		end
		return HTML .. '</DIV>'
	end
end
function FiletoHTML(filename, frame)
	return  frame:callParserFunction( 'filepath', {filename} )
end
function makethumb(url, alt)
	url = url:gsub("http://lingeriefc.com/", "https://lingeriefc.com/"):gsub("http://www.lingeriefc.com/", "https://www.lingeriefc.com/")
	if not contains(url, "http") then 
		url = 'https://lingeriefc.com/wp-content/uploads/' .. url
	end
	return '<A HREF="' .. url .. '" class="athumb strip col-sm-6 col-sm-6 col-sm-6 col-xs-6"><IMG SRC="https://lingeriefc.com/thumb.php?filename=' .. url .. '&size=shop_thumbnail" ALT="' .. alt .. '" CLASS="thumb"></A> ' 
end

function starring(fighters)
	local categoryOrder = { }
	for i,k in pairs(fighters) do
		table.insert(categoryOrder, trim(k))
	end
	table.sort(categoryOrder)
	local HTML = ""
	for i = 1, #categoryOrder do
		local currentfighter = categoryOrder[i]
		if i == #categoryOrder then
			if i > 1 then HTML = HTML .. " and " end
		elseif i > 1 then
			HTML = HTML .. ", "
		end
		HTML = HTML .. fighterHREF(currentfighter, frame)
		i = i + 1
	end
	return HTML
end

function p.starring(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if args.child ~= 'yes' then
		root = mw.html.create('table')
		local i = 1
		return "Starring: " .. starring(origArgs) .. "."
	end
end

function toHTML(HTML)
	root = mw.html.create('table')
	root:wikitext("{{#tag:html|" .. HTML .. "}}")
	return tostring(root)
end

function p.sort(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end

	if args.child ~= 'yes' then
		root = mw.html.create('table')
		local i = 1

		local categoryOrder = { }
		for i,k in pairs(origArgs) do
			table.insert(categoryOrder, k)
		end
		table.sort(categoryOrder)

		local currentletter = ""
		-- root:wikitext('<DIV class="equal ministat-container" style="width: 100%; display: flex !important; justify-content: space-between !important;">')
		-- root:wikitext('<DIV class="equal ministat-container" style="width: 100%; display: flex !important; justify-content: center !important;">')
		root:wikitext('<DIV CLASS="row lfccard-sort lfccard-responsive nopadding">')
		for i = 1, #categoryOrder do
			local currentfighter = categoryOrder[i]
			root:wikitext('<DIV CLASS="col-md-3 col-sm-6 col-xs-6 nopadding">')
			root:wikitext(frame:expandTemplate{ title = 'Ministats:' .. getnickname(currentfighter, frame) , args = { '|' } })
			root:wikitext('</DIV>')
			i = i + 1
		end
		root:wikitext('</DIV>')
		return tostring(root)
	end
end

function p.nosort(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if args.child ~= 'yes' then
		root = '<DIV class="equal ministat-container ministat-nosort" style="width: 100%; display: flex !important; justify-content: space-between !important;"> '
		local categoryOrder =  split(origArgs["order"], ",")
		for i = 1, #categoryOrder do
			local currentfighter = origArgs[ categoryOrder[i] ]
			if currentfighter ~= nil and currentfighter ~= "" then
				local subtext = origArgs[ categoryOrder[i] .. "Text" ]
				if subtext == nil then subtext = "" end
				root = root .. '<DIV CLASS="nosort col-xs-12 col-sm-6 col-md-4"><DIV CLASS="nosort-col">' .. categoryOrder[i] .. '</DIV><DIV CLASS="nosort-subcol">' .. subtext .. "</DIV>" .. frame:expandTemplate{ title = 'Ministats:' .. getnickname(currentfighter, frame) , args = { '|' } } .. '</DIV>'
			else
				i = #categoryOrder
			end
			i = i + 1
		end
		return root .. '</DIV>'
	end
end

function p.getall(frame)
	local HTML = "local nicknames = {}\r\n"
	local fighter= ""
	local stats = ""
	for key, value in pairs(nicknames) do
		HTML = HTML .. getnickandstats(key, value, frame)
	end
	for i = 1, #nonicks do
		HTML = HTML .. getnickandstats(nonicks[i], "", frame)
		i = i + 1
	end
	return HTML .. "\r\nlocal stylesynonyms = {}"
end
function getnickandstats(key, value, frame)
	local fighter =  getnickname(key, frame)
	local stats = getfighterstats(frame, fighter)
	if stats == nil then stats = "" end
	return "\r\n	nicknames['" .. key .. "'] = '" .. value .. "' stats[" .. stats .. ']<BR>'
end

function stripnickname(fighter)
	local char = "'"
	local start = string.find(fighter, char, 1)
	if start == nil then 
		char = string.char(38)
		start = string.find(fighter, char, 1) 
	end
	if start ~= nil then
		local finish = string.find(fighter, char, start+1) 
		if finish ~= nil then 
			left = string.sub(fighter, 1, start-1) 
			right = string.sub(fighter, -string.len(fighter)  + finish)
			fighter = trim(left) .. " " .. trim(right) -- .. " START: " .. start .. " END: " .. finish .. " CHAR: " .. char .. " BYTE: " .. string.byte(char) .. " SHOULD BE: " .. string.byte("'")
-- else fighter = trim(left) .. " " .. trim(right) .. " START: " .. start .. " END: not found CHAR: " .. char .. " BYTE: " .. string.byte(char) .. " SHOULD BE: " .. string.byte("'")
		end
-- else fighter = trim(left) .. " " .. trim(right) .. " START: not found CHAR: " .. char .. " BYTE: " .. string.byte(char) .. " SHOULD BE: " .. string.byte("'")
	end
	return fighter:gsub("#39;", ""):gsub("  ", " ")
end

function textcontains(text, searchfor)
	if text == nil or searchfor == nil then return false end
	local start = string.find(text:lower(), searchfor:lower(), 1)
	return start ~= nil
end

function p.random(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	local quantity = 4
	local prevfighter = {}
	math.randomseed( os.time() )
	if origArgs ["quantity"] ~= nil and isnumber(origArgs ["quantity"]) then quantity = tonumber(origArgs ["quantity"]) end
	root = mw.html.create('table')
	-- root:wikitext('<DIV class="equal ministat-container" style="width: 100%; display: flex !important; justify-content: space-between !important;">')
	root:wikitext('<DIV CLASS="row lfccard-responsive lfccard-random nopadding">')
	-- root.wikitext( debugtable(origArgs ) )

	local title = mw.title.getCurrentTitle()
	prevfighter[#prevfighter+1] = stripnickname(title.fullText)
	prevfighter[#prevfighter+1] = "Chelsea London" -- remove once she has a picture

	for i = 1, quantity do
		local currentfighter = ""
		while currentfighter == "" or contains(prevfighter, currentfighter) or currentfighter == "Lina Inverse"  do
			currentfighter = randFrom(nicknames)
		end
		prevfighter[#prevfighter+1] = currentfighter
		root:wikitext('<DIV CLASS="col-md-3 col-sm-6 col-xs-6 nopadding">')
		root:wikitext(frame:expandTemplate{ title = 'Ministats:' .. getnickname(currentfighter, frame) , args = { '|' } })
		root:wikitext('</DIV>')
		i = i + 1
	end
	root:wikitext('</DIV>')
	return tostring(root)
end

function p.fightcard(frame)
	-- If called via #invoke, use the args passed into the invoking template. Otherwise, for testing purposes, assume args are being passed directly in.
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if args.child ~= 'yes' then
		root = mw.html.create('table')
		preprocessSingleArg("round1")
		preprocessSingleArg("method1")
		local i = 1
		if args["round1"] ~= nil and args["method1"] ~= nil then
			root:wikitext('<DIV CLASS="row border-bottom"><DIV CLASS="col-md-4">Winner</DIV><DIV CLASS="col-md-1"></DIV><DIV CLASS="col-md-4">Loser</DIV><DIV CLASS="col-md-1">Method</DIV><DIV CLASS="col-md-1 pull-right">Round</DIV></DIV>')
		end
		while origArgs['event' .. i] and origArgs['event' .. i] ~= '' do
			vscard(frame, 'event' .. i, 0)
			i = i + 1
		end
		vscard(frame, 'main', 1)
	end
	return '<DIV><div class="clearfix"></div>' .. tostring(root) .. '</DIV>'
end

function p.statcard(frame, testdata)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = args
	end
	local dotest = 0
	if testdata ~= nil then 
		origArgs = testdata 
		dotest = 1 
	end

	local i = 1
	if args.child ~= 'yes' or dotest == 1 then
		root = mw.html.create('span')
		while (origArgs['event' .. i] and origArgs['event' .. i] ~= '') or origArgs['winner' .. i] do
			fighterstats(frame, i)
			i = i + 1
		end
	end
	return '<TABLE CLASS="wikitable sortable table jquery-tablesorter event-results">' .. tostring(root) .. '</TABLE>'
end


function debugtable(t)
	local n = 0
	local tempstr = "<BR>Table data<BR>"
	for i, o in pairs(t) do
		n = n + 1
		tempstr = tempstr  .. "Item: '" .. n .. "' Key: '" .. i .. "' Value: '" .. o .. "'<BR>"
	end
	return tempstr
end

function randFrom( t )
	local choice = "F"
	local n = 0
	for i, o in pairs(t) do
		n = n + 1
		if math.random() < (1/n) then
			choice = i      
		end
	end
	return choice 
end
function contains(table, val)
	for i=1,#table do
		if table[i] == val then 
			return true
		end
	end
	return false
end
function isnumber(value)
	return tonumber(value) ~= nil 
end
function round(num, numDecimalPlaces)
	local mult = 10^(numDecimalPlaces or 0)
	return math.floor(num * mult + 0.5) / mult
end
function isheight(value)
	return isnumber( value:gsub("'", ""):gsub('"', "") )
end
function convertheighttometric(height)
	local newheight = split(height:gsub('"', ""), "'")
	local inches = tonumber(newheight[1]) * 12 + tonumber(newheight[2])
	local cm = inches * 2.54
	return round(cm, 0)
end
function convertheighttoimperial(cm)
	local inches = tonumber(cm) * 0.393701
	local feet = math.floor(inches/12)
	inches = inches - (feet*12)
	return feet .. "'" .. inches .. '"'
end
function processbirthplace(place)
	if place == "" or place == "Unknown" then return "Unknown" end
	local country = ""
	local data = split(place, "%(")
	if #data == 2 then country = data[2]:gsub("%)", "") end
	place = trim(place:gsub("%(", ""):gsub("%)", ""):gsub(country, ""))
	local city = place
	data = split(place, ",")
	if #data > 0 then city = trim(data[1]) end
	local province = ""
	local fullprovince = ""
	if #data == 2 then 
		province = trim(data[2]) 
		fullprovince = trim(provincename(province, country))
	end
	if #fullprovince  == 0 then fullprovince = province end
	-- local HTML =  trim(makeHREF(city .. maketitleparam(province, ", " .. fullprovince) .. maketitleparam(country, " (" .. country .. ")"), city))
	-- if province then HTML = trim(HTML) .. ", " .. makeHREF(fullprovince .. maketitleparam(country, " (" .. country .. ")"), province) end
	-- if country then HTML = trim(HTML) .. " " .. makeHREF(country, '<IMG SRC="/wiki/images/flags/' .. country:gsub(" ", "-") .. '.png" class="flag">') end
	country=trim(country:gsub(" ", "-"))

	local HTML =  city
	if province ~= "" or country ~= "" then 
		HTML = trim(HTML) .. ", " .. province 
	end
	if country ~= "" and #country > 0 then 
		HTML = trim(HTML) .. " " .. country ..  ' <IMG SRC="/wiki/images/flags/' .. country .. '.png" class="flag">'
	end

	return HTML
end
function p.place(frame)
	origArgs = frame:getParent().args
	return processbirthplace(origArgs[1], frame)
end
function maketitleparam(var, text, isfalse)
	if trim(text) == "," then text = "" end
	if var then return text end
	if isfalse == nil then return "" end
	return isfalse
end
function provincename(province, country)
	if countries[country] ~= nil then
		if countries[country][province] ~= nil then
			return countries[country][province]
		end
	end
	return province
end

function makeHREF(Title, Text)
	Title = trim(Title):gsub("  ", " ")
	if Text == nil then Text = Title end
	return '<A HREF="' .. makeURL(Title) .. '">' .. Text .. '</A>'
end
function processStyle(style)
	if style == "" then return "Unknown" end
	local styles = split(style, ",")
	style = styles[1]
	if stylesynonyms[style] ~= nil then 
		style = stylesynonyms[style]
	end
	local HTML = makeHREF(style)
	if #styles > 1 then HTML = HTML .. ", " .. processStyle(styles[2]) end
	return HTML
end
function processStats(stats)
	if stats == "" then return "Unknown" end
	stats = split(stats, "-")
	local HTML = " " .. stats[1] .. "-" .. stats[2]
	if #stats == 3 then 
		HTML = HTML  .. "-" .. stats[3]
	end
	return '<span class="stats">' .. HTML .. '</span>'
end
function processData(Title, Value)
	if Value == "" or Value == "Unknown" then return "" end
	return '<span>' .. Title .. ': </span>' .. Value .. '<br>'
end
function iif(value, iftrue, iffalse)
	if value then return iftrue end
	if iffalse == nil then return "" end
	return ""
end

function getRootFrame(frame)
	while frame:getParent() ~= nil do
		frame = frame:getParent()
	end 
	return frame
end

function plural(text, number)
	if tonumber(number) == 1 then return text end
	return text .. "s"
end

function socialmedia(link, basehref, image)
	if link ~= "" and link ~= nil then 
		return '<A HREF="' .. basehref .. link .. '" target="_blank"><IMG CLASS="lfccard-socialimage" SRC="/photoswipe/img/' .. image .. '.png"></A>'
	end
	return ""
end

function p.ministats(frame)
	local fightertype = "fighter"
	local wastype = fightertype
	local needscols = true
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if origArgs["type"] ~= "" and origArgs["type"] ~= nil then -- and fightertype ~= "fighter" then 
		wastype = origArgs["type"]
		fightertype = origArgs["type"] .. " ministat-notfighter"
	end
	if isnumber(origArgs["weight"]) then 
		origArgs["weight"] = origArgs["weight"] .. " lbs/" .. round(origArgs["weight"] * 0.4535, 0) .. " kg"
	end
	origArgs["height"] = origArgs["height"]:gsub("’", "'"):gsub("”", '"'):gsub("″", '"')
	if isnumber(origArgs["height"]) then -- metric
		origArgs["height"] = convertheighttoimperial(origArgs["height"]) .. "/" .. origArgs["height"] .. " cm"
	elseif isheight(origArgs["height"]) then -- imperial
		origArgs["height"] = origArgs["height"] .. "/" .. convertheighttometric(origArgs["height"]) .. " cm"
	end
	if origArgs["image"] == nil or origArgs["image"] == "" then
		origArgs["image"] = "https://lingeriefc.com/wp-content/uploads/34565436456546.jpg"
	end
	origArgs["image"] = origArgs["image"]:gsub("http://lingeriefc", "https://lingeriefc")
	origArgs["birthplace"] = processbirthplace(origArgs["birthplace"])
	local fighter = getnickname(origArgs["name"], frame);
	local url = fighterurl(fighter)
	local html = ""
	if fightertype == "fighter" or  wastype == "contestant" or wastype == "personality" then
		local imagetype = "contestant"
		html = '<DIV ID="' .. fighter  .. '" CLASS="lfccard ' .. fightertype  .. '"><IMG CLASS="lfccard-bg" SRC="/photoswipe/img/' .. imagetype .. '.png"><DIV CLASS="lfccard-name">'
		if wastype == "personality" then
			html = '<DIV CLASS="row"><div class="col-md-3" style="min-width: 278px;" oldclass="equal ministat-container ministat-single">' .. html .. fighter
			html = html .. '</DIV><DIV CLASS="lfccard-thumbcontainer"><IMG CLASS="lfccard-image" SRC="' .. origArgs["image"]  .. '"></DIV><DIV CLASS="lfccard-role">' .. origArgs["role"]
		else
			html = html .. '<A HREF="' .. url .. '" class="fighterurl">' .. fighter .. '</A></DIV>'
			html = html .. '<A HREF="' .. getwikiurl(fighter, "Template:Ministats") .. '?action=edit" CLASS="lfccard-edit requirelogin"><I CLASS="fa fa-fw fa-pencil fa-2x"></I></A>'
			html = html .. '<DIV CLASS="lfccard-thumbcontainer"><A HREF="' .. url .. '"><IMG CLASS="lfccard-image" SRC="' .. origArgs["image"]  .. '"></A></DIV>'
			html = html .. '<DIV CLASS="lfccard-styles">' .. processStyle(origArgs["style"])
		end
		html = html .. '</DIV><DIV CLASS="lfccard-socialmedia">'
		html = html .. socialmedia(origArgs["facebook"], "https://facebook.com/", "facebook")
		html = html .. socialmedia(origArgs["twitter"], "https://twitter.com/", "twitter")
		html = html .. socialmedia(origArgs["instagram"], "https://instagram.com/", "instagram")
		html = html .. socialmedia(origArgs["youtube"], "https://www.youtube.com/channel/", "youtube")
		html = html .. socialmedia(origArgs["email"], "mailto:", "email")
		-- html = html .. socialmedia(origArgs["imdb"], "", "imdb")
		if origArgs["sponsor"] ~= "" and origArgs["sponsor"] ~= nil then 
			html = html .. socialmedia(origArgs["sponsor"], "https://lingeriefc.com/product/", "customtiny")
		end
		html = html .. '</DIV><DIV CLASS="lfccard-stats">' .. processData('Height', origArgs["height"]) .. processData('Weight', origArgs["weight"]) .. processData('Birthplace', origArgs["birthplace"]) .. '</DIV>'
		local tiny = getfighterstats(frame, origArgs["name"])
		if origArgs["tiny"] ~= "" and origArgs["tiny"] ~= nil then  end
		html = html .. '<DIV CLASS="lfccard-small">' .. tiny .. '</DIV>'
		if wastype == "personality" then return html .. '</DIV></DIV>' end
		return html .. '</DIV CLASS="endcard">'
	end

	html = '<DIV class="ministat-left ' .. iif(needscols, 'col-xs-7 col-sm-3 col-md-2') .. ' ministat-' .. fightertype .. '"><A HREF="' .. url .. '" class="fighterurl">'  .. '<strong>' .. fighter .. '</strong></a><br>'
	origArgs["stats"] = getfighterstats(frame, origArgs["name"])

	if origArgs["stats"] ~= "0-0" then html = html .. processData(makeHREF('Stats'), processStats(origArgs["stats"])) end
	html = html .. processData('Style', processStyle(origArgs["style"]))
	html = html .. processData('Height', origArgs["height"]) .. processData('Weight', origArgs["weight"])
	html = html .. processData('Birthplace', origArgs["birthplace"])

	if origArgs["fighters"] ~= "" and origArgs["fighters"] ~= nil then 
		html = html .. origArgs["fighters"]  .. plural(' Fighter', origArgs["fighters"])
	end

	html = html .. '<DIV CLASS="clearfix"></DIV><DIV CLASS="ministat-icons">'
	if origArgs["facebook"] ~= "" and origArgs["facebook"] ~= nil then 
		html = html .. '<A HREF="https://facebook.com/' .. origArgs["facebook"] .. '" target="_blank"><i class="fa fa-fw fa-facebook fa-2x"></i></A>'
	end
	if origArgs["twitter"] ~= "" and origArgs["twitter"] ~= nil then 
		html = html .. '<A HREF="https://twitter.com/' .. origArgs["twitter"] .. '" target="_blank"><i class="fa fa-fw fa-twitter fa-2x"></i></A>'
	end
	if origArgs["instagram"] ~= "" and origArgs["instagram"] ~= nil then 
		html = html .. '<A HREF="https://instagram.com/' .. origArgs["instagram"] .. '" target="_blank"><i class="fa fa-fw fa-instagram fa-2x"></i></A>'
	end
	if origArgs["youtube"] ~= "" and origArgs["youtube"] ~= nil then 
		html = html .. '<A HREF="https://www.youtube.com/channel/' .. origArgs["youtube"] .. '" target="_blank"><i class="fa fa-fw fa-youtube fa-2x"></i></A>'
	end
	html = html .. '<A HREF="' .. getwikiurl(fighter, "Template:Ministats") .. '?action=edit" class="edit-fighter requirelogin"><i class="fa fa-fw fa-pencil fa-2x"></i></A></DIV></DIV>'
	if wastype ~= "style" then
		html = html .. '<DIV class="ministat-right ' .. iif(needscols, 'col-xs-5 col-sm-3 col-md-2 ') .. 'ministat-' .. fightertype .. '">'
		html = html .. '<A HREF="' .. url .. '"><img src="' .. origArgs["image"]  .. '" class="module-ministats-thumbnail"></A></DIV>'
	end
	return html
end

function fighterurl(fighter)
	if fighter == nil then return "[NONE]" end
	fighter = fighter:gsub("‘", "'"):gsub("’", "'"):gsub("”", "'"):gsub("“", "'"):gsub('&quot;', "'")
	return makeURL(fighter)
end

function hasnonickname(fighter)
	for i = 1, #nopages do
		if isequal(fighter, nopages[i]) then 
			return true 
		end
		i = i + 1
	end
	return false
end

function fighterHREF(fighter, frame)
	if fighter:sub(1, 3) == "LFC" then
		fighter = tonumber(trim(fighter:gsub("LFC", ""):gsub(" ", "")))
		local eventname = "LFC " .. fighter .. ": " .. events[fighter]
	 	return '<A HREF="/wiki/Event:' .. eventname:gsub(" ", "_")  .. '">' .. eventname .. '</A>'  
	end
	if hasnonickname(fighter) then 
	 	return '<A HREF="/wiki/Personalities">' .. fighter .. '</A>'
	end
	fighter = getnickname(fighter, frame)
	return  '<A HREF="' .. fighterurl(fighter) .. '">' .. fighter .. '</A>'
end

function fighterWIKI(fighter, frame)
	if hasnonickname(fighter) then 
		return fighter
	end
	fighter = getnickname(fighter, frame)
	return '[[' .. fighter .. ']]'
end

function p.fighterurl(frame)
	origArgs = frame:getParent().args
	return  fighterHREF(origArgs[1], frame)
end

function p.imageurl(frame)
	origArgs = frame:getParent().args
	local fighter = origArgs[1]
	local title = ""
	local url = ""
	if fighter:sub(1, 3) == "LFC" then
		fighter = tonumber(trim(fighter:gsub("LFC", ""):gsub(" ", "")))
		title = "LFC " .. fighter .. ": " .. events[fighter]
		url = "/wiki/Images:LFC_" .. fighter
	else
		title = getnickname(fighter, frame)
		url = fighterurl("Template:Images:" .. title)
	end
 	return '<h2><span class="mw-headline" id="imagesandmore">' .. title .. ' Content</span></h2><A HREF="' .. url  .. '">Click to see more content</A>'
end

function gettemplate(frame, template)
	return mw.text.unstrip(frame:expandTemplate{ title = template, args = { '|' } }) 
end

function getfighterstats(frame, fighter)
	fighter = stripnickname(fighter)
	return getresults(frame, "stats", fighter)
	-- if fighter == nil then return "" end
	-- local stats = gettemplate(frame, 'Ministats:' .. fighter)
	-- if stats then -- go here
	-- 	return trim(getbetween(stats,  '<span class="stats">', '</span>'))
	-- end
	-- return ""
end

function winlose(frame, didlose, Text, fighter, classes)
	local stats = getfighterstats(frame, fighter)
	local td = ""
	local doFighterToo = Text == nil
	local URL = "https://lingeriefc.com/wiki/images/fighters/"
	local icon = '<IMG SRC="' .. URL .. stripnickname(fighter) .. '.jpg" onerror="imgerror(this);" class="fighter-icon fighter-'
	if didlose then
		if Text == nil then Text = "Loss" end
		td = '<td class="table-no2 ' .. classes
		if doFighterToo == false then icon = icon .. 'loser">' end
	else 
		if Text == nil then Text = "Win" end
		if isadraw(classes) then Text = "Draw" end
		td = '<td class="table-yes2 ' .. classes
		if doFighterToo == false then icon = icon .. 'winner">' end
	end
	local HTML = td .. ' table-first">' .. Text
	if doFighterToo then 
		td = '<TD STYLE="background: #C4C2C2; vertical-align: middle; text-align: center;" class="table-maybe2 table-fighter">' 
		HTML = HTML .. td .. '<SPAN CLASS="fighter-url"><A HREF="' .. fighterurl(fighter) .. '">' .. icon .. 'loser">' .. fighter .. '</A>' 
	else
		HTML = td .. ' table-fighter"><SPAN CLASS="fighter-url"><A HREF="' .. fighterurl(fighter) .. '">' .. icon .. fighter .. '</A>'
	end

	HTML = HTML .. '<BR>' .. stats .. '</SPAN></TD>'

	print(HTML)
end

function getbetween(text, start, finish)
	return string.match(text, start .. "(.-)" .. finish)
end

function isadraw(method)
	return textcontains(method, "draw")
end

function fighterstats(frame, i)
	print('<tr>')
	local fighter = ""
	local classes = ""
	local needsroundtimemethod = true
	if isadraw(origArgs['method' .. i]) then
		classes = "fighter-draw"
	end
	if origArgs['opponent' .. i] ~= nil and origArgs['opponent' .. i] ~= '' then
		if i==1 then
			root:wikitext('<tr><th>Res.</th><th>Opponent</th><th>Event</th><TH>Watch</TH><th>Method</th><th>Round</th><th>Time</th></tr>') -- <th>Location</th><th>Notes</th>
		end
		fighter = getnickname(origArgs['opponent' .. i], frame, fighter)
		winlose(frame, origArgs['result' .. i] == "lose" or origArgs['result' .. i] == "loss", nil, fighter, classes)
	else
		if isequal(origArgs['round' .. i], "TBD") or isequal(origArgs['time' .. i], "TBD") or isequal(origArgs['method' .. i], "TBD") then
			if i==1 then
				root:wikitext('<tr><th>Competitor</th><th>Competitor</th></tr>')
			end
			needsroundtimemethod =false
		elseif i==1 then
			root:wikitext('<tr><th>Winner</th><th>Loser</th><th>Method</th><th>Round</th><th>Time</th></tr>') -- <th>Notes</th>
		end
		local winner = getnickname(origArgs['winner' .. i], frame)
		winlose(frame, false, '<A HREF="' .. fighterurl(winner)  .. '">' .. winner .. '</A>', winner, classes)
		fighter = getnickname(origArgs['loser' .. i], frame)
		winlose(frame, true, '<A HREF="' .. fighterurl(fighter)  .. '">' .. fighter .. '</A>', fighter, classes)
	end
	local td = '<TD STYLE="vertical-align: middle; text-align: center;" class="no-color">'

	if origArgs['event' .. i] ~= nil then -- was "opponent"
		local location = ""
		if origArgs['location' .. i] ~= nil then location = origArgs['location' .. i] end
		print(td .. eventlocationdate(origArgs['event' .. i], '<BR>', origArgs['date' .. i]) .. '</td>')
	end
	-- if origArgs['location' .. i] ~= nil then print(td .. origArgs['location' .. i] .. '</td>') end

	if needsroundtimemethod then
		print(td ..  origArgs['method' .. i] .. '</td>')
		if origArgs['round' .. i] == nil then origArgs['round' .. i] = "" end
		if origArgs['time' .. i] == nil then origArgs['time' .. i] = "" end
		print(td ..  origArgs['round' .. i] .. '</td>')
		print(td ..  origArgs['time' .. i] .. '</td>')
	end
	-- if origArgs['note' .. i] ~= nil then
	-- 	print(td .. '<small>' .. origArgs['note' .. i] .. '</small></td></tr>')
	-- else
	-- 	print(td .. '</td></TR>')
	-- end
	print('</TR>')
end

function p.buy(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end	
	local results = require("Module:Results")
	local id = origArgs[1]
	local HTML = ''
	local number = tonumber(trim(id:gsub("LFC", ""):gsub(" ", "")))
	local eventname = nil
	if events[number] ~= nil then
		eventname = "LFC " .. number .. ": " .. events[number]
	end
	local style = 1
	if origArgs[2] ~= nil then style = tonumber(origArgs[2]) end
	local basehref = "https://lingeriefc.com/wiki/images/"
	local dvdprice = results[1]["prices"]["dvd"]
	local streamprice = results[1]["prices"]["stream"]
	if results[1][id] ~= nil then
		if style == 2 and results[1][id]["streamsku"] ~= nil then
			HTML = '<DIV CLASS="buylfc row"><DIV CLASS="col-md-12">Please purchase the following or <A HREF="/my-account">login</A> to watch this video:</DIV><DIV CLASS="col-md-offset-3 col-md-6">'
			HTML = HTML .. '[products ids="40055" columns="1" class="embeddedproduct"]'
			HTML = HTML .. '</DIV><!--DIV CLASS="col-md-6">'
			HTML = HTML .. '[products ids="' .. results[1][id]["streamsku"] .. '" columns="1" class="embeddedproduct"]'
			HTML = HTML .. '</DIV--><DIV CLASS="col-md-3"></DIV></DIV>'
		else
			if style == 3 then HTML = '<DIV ALIGN="CENTER" CLASS="buylfc">' end
			local found = false
			if results[1][id]["dvd"] ~= nil then
				found = style ~= 3
				if style == 1 then HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["dvd"] .. '/" class="buylfc buy-dvd-2" TITLE="ORDER DVD $' .. dvdprice .. '" target="_blank"><IMG SRC="' .. basehref  .. 'dvdicon.png" class="buy-icon"></A>' end
				if style == 2 then HTML = HTML .. '<A CLASS="btn btn-lg btn-danger buylfc order-now" HREF="' .. results[1][id]["dvd"] .. '/">ORDER <IMG SRC="' .. basehref  .. 'dvdicon.png" class="buy-icon"> DVD $' .. dvdprice .. '</A>' end
				-- if style == 3 then HTML = HTML .. '<A HREF="' .. results[1][id]["dvd"] .. '/" CLASS="buylfc redbutton">Order DVD</A>' end
			end
			if results[1][id]["stream"] ~= nil then
				found = true
				if style == 1 then HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["stream"] .. '/" class="buy-stream-2 buylfc" TITLE="ORDER DIGITALLY $' .. streamprice .. '" target="_blank"><IMG SRC="' .. basehref  .. 'streamicon.png" class="buy-icon"></A>' end
				if style == 2 then HTML = HTML .. '<A CLASS="btn buylfc btn-lg btn-danger order-now" HREF="' .. results[1][id]["stream"] .. '/">ORDER <IMG SRC="' .. basehref  .. 'streamicon.png" class="buy-icon"> DIGITALLY $' .. streamprice .. '</A>' end
				-- if style == 3 then HTML = HTML .. '<A HREF="' .. results[1][id]["stream"] .. '/" CLASS="redbutton buylfc">Watch Now</A>' end
				if style == 3 and eventname ~= nil then HTML = HTML .. '<A HREF="/wiki/Event:' .. eventname  .. '" CLASS="redbutton buylfc">Watch Now</A>' end
				if style == 3 and eventname == nil then HTML = HTML .. 'eventname for ' .. id .. ' not listed at the top of the modul' end
			end
			if style == 3 then HTML = HTML  .. "</DIV>" end
		end
	end 
	return HTML
end

function eventlocationdate(event, location, date)
	local id = "LFC" .. getbetween(event, "LFC ", ":")
	local results = require("Module:Results")
	local HTML = "" -- [ID = " .. id .. ']'
	local basehref = "https://lingeriefc.com/wiki/images/"
	HTML = HTML .. '</TD><TD STYLE="vertical-align: middle; text-align: center;" class="no-color">'
	if results[1][id] ~= nil then
		if results[1][id]["dvd"] ~= nil then
			-- HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["dvd"] .. '/" class="buy-dvd" TITLE="Buy DVD" target="_blank"><IMG SRC="' .. basehref  .. 'dvdicon.png" CLASS="buy-icon"></A>'
			HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["dvd"] .. '/" target="_blank">Buy DVD</A>'
		end
		if results[1][id]["stream"] ~= nil then
			if results[1][id]["dvd"] ~= nil then
				HTML = HTML .. '<BR>'
			end
			-- HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["stream"] .. '/" class="buy-stream" TITLE="Buy Online Stream" target="_blank"><IMG SRC="' .. basehref  .. 'streamicon.png" CLASS="buy-icon"></A>'
			HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["stream"] .. '/" target="_blank">Stream Online</A>'
		end
	end
	return  '<A HREF="' .. makeURL('Event:' .. event) .. '">' .. event .. '<BR class="invisible">' .. location  .. " " .. convertdate(date) .. '</A>' .. HTML
end

function convertdate(thedate)
	date = split(thedate, "-")
	if #date ~= 3 then
		date = split(thedate, " ")
		if #date == 3 then	return thedate end
		-- return "date missing, has " .. #date  .. " cols = '" .. thedate .. "'"
		return ""
	end
	local year = date[1]
	local month = date[2]
	local day = date[3]
	if tonumber(year) < 100 then
		year = "19" .. year
	end
	-- local html = td .. '<span class="sortkey" style="display:none;speak:none">00000000' .. year .. '-' .. lpad(month, 2, "0") .. '-' .. lpad(day, 2, "0")
	-- html = html .. '-0000</span><span style="white-space:nowrap">' .. monthnames[tonumber(month)] .. ' ' .. day .. ', ' .. year .. '</span></td>'

	local html = monthnames[tonumber(month)] .. ' ' .. day .. ', ' .. year
	return html
end

--- Pads str to length len with char from right
function lpad(str, len, char)
	str = tostring(str)
	if char == nil then char = ' ' end
	return string.rep(char, len - #str) .. str
end

function split(str, pat)
	local t = {}  -- NOTE: use {n = 0} in Lua-5.0
	local fpat = "(.-)" .. pat
	local last_end = 1
	if str == nil then str = "" end
	local s, e, cap = str:find(fpat, 1)
	while s do
		if s ~= 1 or cap ~= "" then
			table.insert(t,cap)
		end
		last_end = e+1
		s, e, cap = str:find(fpat, last_end)
	end
	if last_end <= #str then
		cap = str:sub(last_end)
		table.insert(t, cap)
	end
	return t
end

function isequal(text1, text2)
	if text1 == nil or text2 == nil then return false end
	return trim(text1:lower()) == trim(text2:lower())
end
function getresults(frame, type, name)
	local results = require("Module:Results")
	local wins = 0
	local losses = 0
	local draws = 0
	local decisions = 0
	local iswinner
	local isloser
	local isdecision 
	local isdraw
	local isfuture = false
	local HTML = ""
	local data = {}
	local index = 0
	local extraHTML = ""
	local delimiter = ""
	local hasshown = 0
	local Blackwins = 0
	local Pinkwins = 0
	local name2 = name:gsub(" ", ""):gsub("%.", "")

	if origArgs ~= nil then 
		if origArgs["title"] ~= nil then 
			extratext = ""
			if type == "event" then extratext = " Results" end
			if type == "fighter" then extratext = " MMA Record" end
			HTML = '<h2><span class="mw-headline" id="Results">' .. getnickname(name, frame) .. extratext .. ' </span></h2>' 
		end
	end
	if type ~= "event" and type ~= "teamscore" then
		if results[1][name2] ~= nil then
			extraHTML = '<div CLASS="prexisting-stats" >'
			if results[1][name2]["wins"] == nil and results[1][name2]["losses"] ~= nil then results[1][name2]["wins"] = 0 end
			if results[1][name2]["wins"] ~= nil then 
				wins = results[1][name2]["wins"] 
				extraHTML = extraHTML .. wins
				delimiter = "-"
				if results[1][name2]["losses"] == nil then results[1][name2]["losses"] = 0 end
			end
			if results[1][name2]["losses"] ~= nil then 
				losses = results[1][name2]["losses"] 
				extraHTML = extraHTML .. delimiter .. losses
				delimiter = "-"
			end
			if results[1][name2]["ties"] ~= nil then 
				draws = results[1][name2]["ties"]
				extraHTML = extraHTML .. delimiter .. draws 
			end
			if #delimiter > 0 then 
				extraHTML = extraHTML .. " outside the LFC"
			end
			extraHTML = extraHTML .. '</div>'
		end
	 end

	for i = #results,2,-1 do
		if type == "event" then
			if results[i]["name"] == name or i == name then 
				for p = 1, #results[i]["results"], 1 do
					hasshown = hasshown + 1
				 	data["winner" .. p] = results[i]["results"][p]["winner"]
				 	data["loser" .. p] = results[i]["results"][p]["loser"]
					data["method" .. p] = results[i]["results"][p]["method"]
				 	data["round" .. p] = results[i]["results"][p]["round"]
				 	data["time" .. p] = results[i]["results"][p]["time"]
				 	data["date" .. p] = results[i]["results"][p]["date"]
				 	if results[i]["results"][p]["note"] ~= nil then 
				 		data["note" .. p] = results[i]["results"][p]["note"]
				 	end
				end
			end
		elseif type == "black" or type == "pink" then
			if results[i]["name"] == name or i == name then 
	 	 	 	for p = 1, #results[i]["results"], 1 do
					if results[i]["results"][p]["winningteam"] ~= nil then
						if isequal(results[i]["results"][p]["winningteam"], "black") then Blackwins = Blackwins + 1 end
						if isequal(results[i]["results"][p]["winningteam"], "pink") then Pinkwins = Pinkwins + 1 end
					end
 		 	 	end
			end
		else
 	 	 	for p = 1, #results[i]["results"], 1 do
				if results[i]["results"][p]["winningteam"] ~= nil then
					if isequal(results[i]["results"][p]["winningteam"], "black") then Blackwins = Blackwins + 1 end
					if isequal(results[i]["results"][p]["winningteam"], "pink") then Pinkwins = Pinkwins + 1 end
				end
				iswinner = isequal(results[i]["results"][p]["winner"], name)
				isloser = isequal(results[i]["results"][p]["loser"], name)
				isdraw = false
				isfuture  =  isequal(results[i]["results"][p]["round"], "TBD") or isequal(results[i]["results"][p]["method"], "TBD") or isequal(results[i]["results"][p]["time"], "TBD")
				if isfuture then 
					iswinner = false
					isloser = false
				end
				if iswinner or isloser then
					isdraw = isadraw(results[i]["results"][p]["method"])
					isdecision = textcontains(results[i]["results"][p]["method"], "decision")
					index=index+1
					local opponent = ""
					if isdraw then 
						draws = draws + 1
						opponent = results[i]["results"][p]["loser"]
						if isequal(opponent, name) then opponent = results[i]["results"][p]["winner"] end
						data["result" .. index] = "draw"
					elseif iswinner then
						if isdecision then
							decisions = decisions + 1
						end
						wins = wins + 1
						opponent = results[i]["results"][p]["loser"]
						data["result" .. index] = "win"
					elseif isloser then
						losses = losses + 1
						opponent = results[i]["results"][p]["winner"]
						data["result" .. index] = "loss"
					end
					if type == "fighter" then
						hasshown = hasshown + 1
						data["opponent" .. index] = opponent
						data["event" .. index] = results[i]["name"]
						data["date" .. index] = ""
						if results[i]["date"] ~= nil then data["date" .. index] = results[i]["date"] end
						data["place" .. index] = ""
						data["location" .. index] = ""
						if results[i]["place"] ~= nil then 
							data["location" .. index] = results[i]["place"] 
						end
						data["method" .. index] = results[i]["results"][p]["method"]
				 		data["round" .. index] = results[i]["results"][p]["round"]
					 	data["time" .. index] = results[i]["results"][p]["time"]
					 	-- data["date" .. index] = results[i]["results"][p]["date"]
					 	if results[i]["results"][p]["note"] ~= nil then 
				 			data["note" .. index] = results[i]["results"][p]["note"]
					 	end
					 else
						hasshown = hasshown + 1
					end
				end
 	 	 	end
		end 
	end
	if type == "stats" then
		HTML = wins .. "-" .. losses
		if draws > 0 then HTML = HTML .. "-" .. draws end
		-- if decisions > 0 then HTML = HTML .. "-" .. decisions end
		return HTML
	end
	if type == "wins" then return wins end
	if type == "losses" then return losses end
	if type == "draws" then return draws end
	if type == "decisions" then return decisions end
	if type == "teamscore" or type == "black" or type == "pink" then 
		if type ~= "teamscore" then name2 = type end
		if isequal(name2, "Black") then return Blackwins end
		if isequal(name2, "Pink") then return Pinkwins end
	end
	if hasshown == 0 then
		return HTML .. extraHTML .. 'Coming Soon'
	end
	return HTML .. p.statcard(frame, data) .. extraHTML 
end

function p.autoresults(frame)
	local HTML = ""
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end	
	return getresults(frame, origArgs["type"], origArgs["name"])
end

local function getnicknamesplit(fighter, frame)
	fighter = stripnickname(trim(fighter)):gsub("‘", "'"):gsub("’", "'"):gsub("“", "'"):gsub("”", "'"):gsub('"', "'")
	nickname = ''
	if nicknames[fighter] ~= nil then 
		nickname = nicknames[fighter]
	end
	if nickname ~= '' then 
		fighter = fighter .. ", " .. nickname .. ", " .. getnickname(fighter, frame)
	end
	return fighter
end

function p.autosplit(frame)
	local HTML = ""
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end	
	local fighter = mw.text.decode(origArgs["1"])
	return getnicknamesplit(fighter, frame)
end

function p.autostrip(frame)
	local HTML = ""
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end	
	local fighter = mw.text.decode(origArgs["1"])
	fighter = stripnickname(trim(fighter)):gsub("‘", "'"):gsub("’", "'"):gsub("“", "'"):gsub("”", "'"):gsub('"', "'")
	return getnickname(fighter, frame)
end


return p

local p = {}

local args = {} local origArgs local root local monthnames = {"January","February","March","April","May", "June", "July", "August", "September", "October", "November", "December"} local nopages = {"Roni Taylor", "Arik Loegen", "Jason Parsons", "Johnny D. Struxion", "Joel Kane", "Mike Adams", "Mike Modest", "Lizzie Hunter", "Leon Hater", "A.J. Kirsch"} local nonicks = {"Cali Cat", "Mona Jones", "Bella Ink", "Sybill Starr"} local nicknames = {} nicknames['Allie Parks'] = 'Babydoll' nicknames['Jesabella Marie'] = 'Fire Queen' nicknames['Lexey Rocha'] = 'DethAngel' nicknames['Katie Forbes'] = 'The Bombshell' nicknames['Lina Inverse'] = 'The Dragon Spooker' nicknames['Violeta Sunic'] = 'Dark Force' nicknames['Jenny Valentine'] = 'Bloody' nicknames['Jolene Hexx'] = 'The Valkyrie' nicknames['Teri London'] = 'Feisty Fists' nicknames['Andreea Vladoi'] = 'The Storm' nicknames['Roxy Michaels'] = 'Roundhouse' nicknames['Jessie Santos'] = 'El Toro' nicknames['Piper Rose'] = 'Code Red' nicknames['Maxine Frost'] = 'The Boss' nicknames['Maya Veljkovic'] = 'Hellfire' nicknames['Lauren Fogle'] = 'The Animal' nicknames['MaiNe Morgan'] = 'Main Event' nicknames['Stacey Lentz'] = 'Full Contact' nicknames['Karly Zucker'] = 'Zuke' nicknames['Julie Ginther'] = 'Squeeze' nicknames['Natasha Rodriguez'] = 'Rattlesnake' nicknames['Audrey Monique'] = 'The Mongoose' nicknames['Shelly DaSilva'] = 'Aphrodite' nicknames['Danielle St. Pierre'] = 'Cow Belle' nicknames['Raya Ryans'] = 'Sugar Ray' nicknames['Feather Hadden'] = 'The Hammer' nicknames['Shay Mazzato'] = 'The Fox' nicknames['Sheila Cardinal'] = 'Crash' nicknames['Serina Kyle'] = 'Honey Punch' nicknames['Holly Mei'] = 'The Lotus' nicknames['Jenevieve Hexxx'] = 'The Sorceress' nicknames['Riley Norris'] = 'Nuclear' nicknames['Kris Blackwell'] = 'The Raven' nicknames['Chloe Cameron'] = 'Ladykillah' nicknames['Michelle Blanchard'] = 'Scrapper' nicknames['Tara Gaddy'] = 'Guillotine' nicknames['Suzanne Nakata'] = 'Hawaiian Punch' nicknames['Helen Mei'] = 'Ignite' nicknames['Samiha Glam'] = 'The Goddess' nicknames['Sara Dee'] = 'Double' nicknames['Jody Connacher'] = 'Conquering Angel' nicknames['Beth Moore'] = 'Mount Crush' nicknames['Chelsea London'] = 'Feisty Fists' nicknames['Brenda Jones'] = 'Juice' nicknames['Megan Doll'] = 'Baby' nicknames['Robyn Hawkens'] = 'Ruthless' nicknames['Roxanne Romaro']= 'The Viper' nicknames['Susan Cordell'] = 'Tatia' nicknames['Karmen Moon'] = 'Cherry Bomb' nicknames['Monica Garcia'] = 'Flowerbomb' nicknames['Rochelle Rodgers'] = 'Rampage' nicknames['Agatha Carter'] = 'Cannibal' nicknames['C.J. Kellerman'] = 'Ice Cold' nicknames['Jessica Vattiera'] = 'Sekhmet' nicknames['Tomiko Tajima'] = 'The Temptress' nicknames['Tasia Lockran'] = 'Thrash' nicknames['Jenn Repp'] = 'The Real Deal' nicknames['Gypsy Bae'] = 'Top Shelf' nicknames['Lisa Danielle'] = 'Onyx' nicknames['Andrea Morales'] = 'The Muse' nicknames['Gemma Giuliana'] = 'Jersey Babe'

local stylesynonyms = {} stylesynonyms["Wrestling"] = "Wrestler" stylesynonyms["Kickboxing"] = "Kickboxer" stylesynonyms["Scrapping"] = "Scrapper" stylesynonyms["Brawling"] = "Brawler" stylesynonyms["Ju-Jitsu"] = "Ju Jitsu" stylesynonyms["Muay-Thai"] = "Muay Thai" local countries = {} countries["Canada"] = {AB="Alberta", BC="British Columbia", MB="Manitoba", NB="New Brunswick", NL="Newfoundland and Labrador", NS="Nova Scotia", NT="Northwest Territories", NU="Nunavut", ON="Ontario", PE="Prince Edward Island", QC="Quebec", SK="Saskatchewan", YT="Yukon"} countries["USA"] = {AL="Alabama", AK="Alaska", AZ="Arizona", AR="Arkansas", CA="California", CO="Colorado", CT="Connecticut", DE="Delaware", FL="Florida", GA="Georgia", HI="Hawaii", ID="Idaho", IL="Illinois", IN="Indiana", IA="Iowa", KS="Kansas", KY="Kentucky", LA="Louisiana", ME="Maine", MD="Maryland", MA="Massachusetts", MI="Michigan", MN="Minnesota", MS="Mississippi", MO="Missouri", MT="Montana", NE="Nebraska", NV="Nevada", NH="New Hampshire", NJ="New Jersey", NM="New Mexico", NY="New York", NC="North Carolina", ND="North Dakota", OH="Ohio", OK="Oklahoma", OR="Oregon", PA="Pennsylvania", RI="Rhode Island", SC="South Carolina", SD="South Dakota", TN="Tennessee", TX="Texas", UT="Utah", VT="Vermont", VA="Virginia", WA="Washington", WV="West Virginia", WI="Wisconsin", WY="Wyoming", AS="American Samoa", DC="District of Columbia", FM="Federated States of Micronesia", GU="Guam", MH="Marshall Islands", MP="Northern Mariana Islands", PW="Palau", PR="Puerto Rico", VI="Virgin Islands", AE="Armed Forces Africa", AA="Armed Forces Americas", AE="Armed Forces Canada", AE="Armed Forces Europe", AE="Armed Forces Middle East", AP="Armed Forces Pacific"} local events = {} events[1] = 'Las Vegas' events[2] = events[1] events[3] = 'Reno' events[4] = events[1] events[5] = events[1] events[6] = 'Palm Springs' events[7] = 'Los Angeles' events[8] = events[1] events[9] = events[1] events[10] = events[1] events[11] = 'Phoenix' events[12] = events[1] events[13] = 'New York' events[14] = events[7] events[15] = events[1] events[16] = events[1] events[17] = events[1] events[18] = 'Lace vs. Leather' events[19] = 'Hadden vs. Mei' events[20] = "A Midsummer Night's Dream" events[21] = "Naughty 'n Nice" events[22] = 'Costume Brawl' events[23] = 'Guilty Pleasures' events[24] = 'Eurobash' events[25] = "Showdown At Sam's Town" events[26] = "Booty Camp" events[27] = "Sexy, Nerdy, Inked & Curvy"

local function preprocessSingleArg(argName)

   -- If the argument exists and isn't blank, add it to the argument table.
   -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
   if origArgs[argName] and origArgs[argName] ~=  then
       args[argName] = origArgs[argName]
   end

end

function trim(s) if s == nil then return "" end return (s:gsub("^%s*(.-)%s*$", "%1")) end

local function getnickname(fighter, frame) fighter = trim(fighter):gsub("‘", "'"):gsub("’", "'"):gsub("“", "'"):gsub("”", "'"):gsub('"', "'") nickname = if nicknames[fighter] ~= nil then nickname = nicknames[fighter] end if nickname ~= then space = string.find(fighter, " ") left = string.sub(fighter, 1, space-1) right = string.sub(fighter, -string.len(fighter) + space) fighter = left .. " '" .. nickname .. "' " .. right end return fighter end

local function vscard(frame, eventname, eventtype) index=eventname:gsub("event", "") preprocessSingleArg(eventname) preprocessSingleArg(eventname .. 'vs') preprocessSingleArg("method" .. index) preprocessSingleArg("round" .. index) if args[eventname] ~= nil and args[eventname .. "vs"] ~= nil then

root:wikitext('
') results = '
'

if args["method" .. index] ~= nil and args["round" .. index] ~= nil then

results = '
' .. args["method" .. index] .. '
' .. args["round" .. index] .. '
'

end firstfighter = getnickname(args[eventname], frame) secondfighter = getnickname(args[eventname .. "vs"], frame) if eventtype == 1 then

root:wikitext('

Main Event / Title Bout

')

end root:wikitext(frame:expandTemplate{ title = 'Ministats:' .. firstfighter , args = { '|' } } ..

'
' ..

frame:expandTemplate{ title = 'Ministats:' .. secondfighter, args = { '|' } } .. results )

root:wikitext('
')

end end

function print(text) root:wikitext(text) end

function p.nickname2(fighter, frame) return getnickname(fighter, frame) end

function p.nickname(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end if origArgs['name'] == nil then local fighter = origArgs[1] else local fighter = origArgs['name'] end return getnickname(fighter, frame) end function p.url(frame) origArgs = frame:getParent().args return getwikiurl(origArgs['name']) end function p.ministatsurl(frame) origArgs = frame:getParent().args return getwikiurl(origArgs['name'],"Template:Ministats") end

function getwikiurl(fighter, namespace) if namespace == nil then namespace = "" else namespace = namespace .. ":" end return makeURL(namespace .. getnickname(fighter, frame)) end

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

function allfighters(frame, HTML) local start = HTML:find("{") while start ~= nil do local finish = HTML:find("}", start) if finish ~= nil then local currentfighter = HTML:sub(start+1, finish-1) local HREF = fighterHREF(currentfighter, frame) HTML = HTML:gsub("{" .. currentfighter .. "}", HREF) start = HTML:find("{", finish) else start = nil end end return HTML end

function p.episode(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end if args.child ~= 'yes' then local HTML = "" local i = 1

HTML = HTML .. '
Episode / Duration
Synopsis
Starring
'

while origArgs['episode' .. i] and origArgs['episode' .. i] ~= do

HTML = HTML .. '
Episode ' .. origArgs['episode' .. i] .. ' (' .. origArgs['duration' .. i] .. ')

'

local URL = FiletoHTML(origArgs['file' .. i], frame) HTML = HTML .. '<A HREF="/wiki/File:' .. origArgs['file' .. i] .. '"><IMG SRC="' .. URL .. '"></A>'

local e = 1 local HTML2 = "" while origArgs['thumb' .. i .. "_" .. e] and origArgs['thumb' .. i .. "_" .. e] ~= do HTML2 = HTML2 .. makethumb(origArgs['thumb' .. i .. "_" .. e], origArgs['thumb' .. i .. "_" .. e]) e = e + 1 end if #HTML2 > 0 then

HTML = HTML .. '
' .. HTML2 .. '
'

end

HTML = HTML .. '

' .. allfighters(frame, origArgs['summary' .. i]:gsub('<P>', '

')) .. '

' HTML = HTML .. '
' .. starring(split(origArgs["starring" .. i], ","))

if origArgs['outfits' .. i] and origArgs['outfits' .. i] ~= then

HTML = HTML .. '

Outfits: ' .. origArgs['outfits' .. i] end if origArgs['joelinapool' .. i] and origArgs['joelinapool' .. i] ~= then HTML = HTML .. '
<P>Joel gets thrown in a pool by: ' .. fighterHREF(origArgs['joelinapool' .. i], frame) end HTML = HTML .. '</div></div>' i = i + 1 end return HTML .. '</DIV>' end end function FiletoHTML(filename, frame) return frame:callParserFunction( 'filepath', {filename} ) end function makethumb(url, alt) url = url:gsub("http://lingeriefc.com/", "https://lingeriefc.com/"):gsub("http://www.lingeriefc.com/", "https://www.lingeriefc.com/") if not contains(url, "http") then url = 'https://lingeriefc.com/wp-content/uploads/' .. url end return '<A HREF="' .. url .. '" class="athumb strip col-sm-6 col-sm-6 col-sm-6 col-xs-6"><IMG SRC="https://lingeriefc.com/thumb.php?filename=' .. url .. '&size=shop_thumbnail" ALT="' .. alt .. '" CLASS="thumb"></A> ' end function starring(fighters) local categoryOrder = { } for i,k in pairs(fighters) do table.insert(categoryOrder, trim(k)) end table.sort(categoryOrder) local HTML = "" for i = 1, #categoryOrder do local currentfighter = categoryOrder[i] if i == #categoryOrder then if i > 1 then HTML = HTML .. " and " end elseif i > 1 then HTML = HTML .. ", " end HTML = HTML .. fighterHREF(currentfighter, frame) i = i + 1 end return HTML end function p.starring(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end if args.child ~= 'yes' then root = mw.html.create('table') local i = 1 return "Starring: " .. starring(origArgs) .. "." end end function toHTML(HTML) root = mw.html.create('table') root:wikitext("" .. HTML .. "") return tostring(root) end function p.sort(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end if args.child ~= 'yes' then root = mw.html.create('table') local i = 1 local categoryOrder = { } for i,k in pairs(origArgs) do table.insert(categoryOrder, k) end table.sort(categoryOrder) local currentletter = "" -- root:wikitext('

') -- root:wikitext('
') root:wikitext('
')

for i = 1, #categoryOrder do local currentfighter = categoryOrder[i]

root:wikitext('
')

root:wikitext(frame:expandTemplate{ title = 'Ministats:' .. getnickname(currentfighter, frame) , args = { '|' } })

root:wikitext('
')

i = i + 1 end

root:wikitext('
')

return tostring(root) end end

function p.nosort(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end if args.child ~= 'yes' then

root = '
'

local categoryOrder = split(origArgs["order"], ",") for i = 1, #categoryOrder do local currentfighter = origArgs[ categoryOrder[i] ] if currentfighter ~= nil and currentfighter ~= "" then local subtext = origArgs[ categoryOrder[i] .. "Text" ] if subtext == nil then subtext = "" end

root = root .. '
' .. categoryOrder[i] .. '
' .. subtext .. "
" .. frame:expandTemplate{ title = 'Ministats:' .. getnickname(currentfighter, frame) , args = { '|' } } .. '
'

else i = #categoryOrder end i = i + 1 end

return root .. '
'

end end

function p.getall(frame) local HTML = "local nicknames = {}\r\n" local fighter= "" local stats = "" for key, value in pairs(nicknames) do HTML = HTML .. getnickandstats(key, value, frame) end for i = 1, #nonicks do HTML = HTML .. getnickandstats(nonicks[i], "", frame) i = i + 1 end return HTML .. "\r\nlocal stylesynonyms = {}" end function getnickandstats(key, value, frame) local fighter = getnickname(key, frame) local stats = getfighterstats(frame, fighter) if stats == nil then stats = "" end return "\r\n nicknames['" .. key .. "'] = '" .. value .. "' stats[" .. stats .. ']
' end

function stripnickname(fighter) local char = "'" local start = string.find(fighter, char, 1) if start == nil then char = string.char(38) start = string.find(fighter, char, 1) end if start ~= nil then local finish = string.find(fighter, char, start+1) if finish ~= nil then left = string.sub(fighter, 1, start-1) right = string.sub(fighter, -string.len(fighter) + finish) fighter = trim(left) .. " " .. trim(right) -- .. " START: " .. start .. " END: " .. finish .. " CHAR: " .. char .. " BYTE: " .. string.byte(char) .. " SHOULD BE: " .. string.byte("'") -- else fighter = trim(left) .. " " .. trim(right) .. " START: " .. start .. " END: not found CHAR: " .. char .. " BYTE: " .. string.byte(char) .. " SHOULD BE: " .. string.byte("'") end -- else fighter = trim(left) .. " " .. trim(right) .. " START: not found CHAR: " .. char .. " BYTE: " .. string.byte(char) .. " SHOULD BE: " .. string.byte("'") end return fighter:gsub("#39;", ""):gsub(" ", " ") end

function textcontains(text, searchfor) if text == nil or searchfor == nil then return false end local start = string.find(text:lower(), searchfor:lower(), 1) return start ~= nil end

function p.random(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end local quantity = 4 local prevfighter = {} math.randomseed( os.time() ) if origArgs ["quantity"] ~= nil and isnumber(origArgs ["quantity"]) then quantity = tonumber(origArgs ["quantity"]) end root = mw.html.create('table')

-- root:wikitext('
') root:wikitext('
')

-- root.wikitext( debugtable(origArgs ) )

local title = mw.title.getCurrentTitle() prevfighter[#prevfighter+1] = stripnickname(title.fullText) prevfighter[#prevfighter+1] = "Chelsea London" -- remove once she has a picture

for i = 1, quantity do local currentfighter = "" while currentfighter == "" or contains(prevfighter, currentfighter) or currentfighter == "Lina Inverse" do currentfighter = randFrom(nicknames) end prevfighter[#prevfighter+1] = currentfighter

root:wikitext('
')

root:wikitext(frame:expandTemplate{ title = 'Ministats:' .. getnickname(currentfighter, frame) , args = { '|' } })

root:wikitext('
')

i = i + 1 end

root:wikitext('
')

return tostring(root) end

function p.fightcard(frame) -- If called via #invoke, use the args passed into the invoking template. Otherwise, for testing purposes, assume args are being passed directly in. if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end if args.child ~= 'yes' then root = mw.html.create('table') preprocessSingleArg("round1") preprocessSingleArg("method1") local i = 1 if args["round1"] ~= nil and args["method1"] ~= nil then

root:wikitext('
Winner
Loser
Method
Round
')

end while origArgs['event' .. i] and origArgs['event' .. i] ~= do vscard(frame, 'event' .. i, 0) i = i + 1 end vscard(frame, 'main', 1) end

return '
' .. tostring(root) .. '
'

end

function p.statcard(frame, testdata) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = args end local dotest = 0 if testdata ~= nil then origArgs = testdata dotest = 1 end

local i = 1 if args.child ~= 'yes' or dotest == 1 then root = mw.html.create('span') while (origArgs['event' .. i] and origArgs['event' .. i] ~= ) or origArgs['winner' .. i] do fighterstats(frame, i) i = i + 1 end end

return '' .. tostring(root) .. '
'

end


function debugtable(t) local n = 0 local tempstr = "
Table data
" for i, o in pairs(t) do n = n + 1 tempstr = tempstr .. "Item: '" .. n .. "' Key: '" .. i .. "' Value: '" .. o .. "'
" end return tempstr end

function randFrom( t ) local choice = "F" local n = 0 for i, o in pairs(t) do n = n + 1 if math.random() < (1/n) then choice = i end end return choice end function contains(table, val) for i=1,#table do if table[i] == val then return true end end return false end function isnumber(value) return tonumber(value) ~= nil end function round(num, numDecimalPlaces) local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end function isheight(value) return isnumber( value:gsub("'", ""):gsub('"', "") ) end function convertheighttometric(height) local newheight = split(height:gsub('"', ""), "'") local inches = tonumber(newheight[1]) * 12 + tonumber(newheight[2]) local cm = inches * 2.54 return round(cm, 0) end function convertheighttoimperial(cm) local inches = tonumber(cm) * 0.393701 local feet = math.floor(inches/12) inches = inches - (feet*12) return feet .. "'" .. inches .. '"' end function processbirthplace(place) if place == "" or place == "Unknown" then return "Unknown" end local country = "" local data = split(place, "%(") if #data == 2 then country = data[2]:gsub("%)", "") end place = trim(place:gsub("%(", ""):gsub("%)", ""):gsub(country, "")) local city = place data = split(place, ",") if #data > 0 then city = trim(data[1]) end local province = "" local fullprovince = "" if #data == 2 then province = trim(data[2]) fullprovince = trim(provincename(province, country)) end if #fullprovince == 0 then fullprovince = province end -- local HTML = trim(makeHREF(city .. maketitleparam(province, ", " .. fullprovince) .. maketitleparam(country, " (" .. country .. ")"), city)) -- if province then HTML = trim(HTML) .. ", " .. makeHREF(fullprovince .. maketitleparam(country, " (" .. country .. ")"), province) end -- if country then HTML = trim(HTML) .. " " .. makeHREF(country, '<IMG SRC="/wiki/images/flags/' .. country:gsub(" ", "-") .. '.png" class="flag">') end country=trim(country:gsub(" ", "-"))

local HTML = city if province ~= "" or country ~= "" then HTML = trim(HTML) .. ", " .. province end if country ~= "" and #country > 0 then HTML = trim(HTML) .. " " .. country .. ' <IMG SRC="/wiki/images/flags/' .. country .. '.png" class="flag">' end

return HTML end function p.place(frame) origArgs = frame:getParent().args return processbirthplace(origArgs[1], frame) end function maketitleparam(var, text, isfalse) if trim(text) == "," then text = "" end if var then return text end if isfalse == nil then return "" end return isfalse end function provincename(province, country) if countries[country] ~= nil then if countries[country][province] ~= nil then return countries[country][province] end end return province end

function makeHREF(Title, Text) Title = trim(Title):gsub(" ", " ") if Text == nil then Text = Title end return '<A HREF="' .. makeURL(Title) .. '">' .. Text .. '</A>' end function processStyle(style) if style == "" then return "Unknown" end local styles = split(style, ",") style = styles[1] if stylesynonyms[style] ~= nil then style = stylesynonyms[style] end local HTML = makeHREF(style) if #styles > 1 then HTML = HTML .. ", " .. processStyle(styles[2]) end return HTML end function processStats(stats) if stats == "" then return "Unknown" end stats = split(stats, "-") local HTML = " " .. stats[1] .. "-" .. stats[2] if #stats == 3 then HTML = HTML .. "-" .. stats[3] end return '' .. HTML .. '' end function processData(Title, Value) if Value == "" or Value == "Unknown" then return "" end return '' .. Title .. ': ' .. Value .. '
' end function iif(value, iftrue, iffalse) if value then return iftrue end if iffalse == nil then return "" end return "" end

function getRootFrame(frame) while frame:getParent() ~= nil do frame = frame:getParent() end return frame end

function plural(text, number) if tonumber(number) == 1 then return text end return text .. "s" end

function socialmedia(link, basehref, image) if link ~= "" and link ~= nil then return '<A HREF="' .. basehref .. link .. '" target="_blank"><IMG CLASS="lfccard-socialimage" SRC="/photoswipe/img/' .. image .. '.png"></A>' end return "" end

function p.ministats(frame) local fightertype = "fighter" local wastype = fightertype local needscols = true if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end if origArgs["type"] ~= "" and origArgs["type"] ~= nil then -- and fightertype ~= "fighter" then wastype = origArgs["type"] fightertype = origArgs["type"] .. " ministat-notfighter" end if isnumber(origArgs["weight"]) then origArgs["weight"] = origArgs["weight"] .. " lbs/" .. round(origArgs["weight"] * 0.4535, 0) .. " kg" end origArgs["height"] = origArgs["height"]:gsub("’", "'"):gsub("”", '"'):gsub("″", '"') if isnumber(origArgs["height"]) then -- metric origArgs["height"] = convertheighttoimperial(origArgs["height"]) .. "/" .. origArgs["height"] .. " cm" elseif isheight(origArgs["height"]) then -- imperial origArgs["height"] = origArgs["height"] .. "/" .. convertheighttometric(origArgs["height"]) .. " cm" end if origArgs["image"] == nil or origArgs["image"] == "" then origArgs["image"] = "34565436456546.jpg" end origArgs["image"] = origArgs["image"]:gsub("http://lingeriefc", "https://lingeriefc") origArgs["birthplace"] = processbirthplace(origArgs["birthplace"]) local fighter = getnickname(origArgs["name"], frame); local url = fighterurl(fighter) local html = "" if fightertype == "fighter" or wastype == "contestant" or wastype == "personality" then local imagetype = "contestant"

html = '
<IMG CLASS="lfccard-bg" SRC="/photoswipe/img/' .. imagetype .. '.png">
'

if wastype == "personality" then

html = '
' .. html .. fighter html = html .. '
<IMG CLASS="lfccard-image" SRC="' .. origArgs["image"] .. '">
' .. origArgs["role"]

else

html = html .. '<A HREF="' .. url .. '" class="fighterurl">' .. fighter .. '</A>
'

html = html .. '<A HREF="' .. getwikiurl(fighter, "Template:Ministats") .. '?action=edit" CLASS="lfccard-edit requirelogin"></A>'

html = html .. '
<A HREF="' .. url .. '"><IMG CLASS="lfccard-image" SRC="' .. origArgs["image"] .. '"></A>
' html = html .. '
' .. processStyle(origArgs["style"])

end

html = html .. '
'

html = html .. socialmedia(origArgs["facebook"], "https://facebook.com/", "facebook") html = html .. socialmedia(origArgs["twitter"], "https://twitter.com/", "twitter") html = html .. socialmedia(origArgs["instagram"], "https://instagram.com/", "instagram") html = html .. socialmedia(origArgs["youtube"], "https://www.youtube.com/channel/", "youtube") html = html .. socialmedia(origArgs["email"], "mailto:", "email") -- html = html .. socialmedia(origArgs["imdb"], "", "imdb") if origArgs["sponsor"] ~= "" and origArgs["sponsor"] ~= nil then html = html .. socialmedia(origArgs["sponsor"], "https://lingeriefc.com/product/", "customtiny") end

html = html .. '
' .. processData('Height', origArgs["height"]) .. processData('Weight', origArgs["weight"]) .. processData('Birthplace', origArgs["birthplace"]) .. '
'

local tiny = getfighterstats(frame, origArgs["name"]) if origArgs["tiny"] ~= "" and origArgs["tiny"] ~= nil then end

html = html .. '
' .. tiny .. '
' if wastype == "personality" then return html .. '
' end return html .. '
'

end

html = '
<A HREF="' .. url .. '" class="fighterurl">' .. '' .. fighter .. '</a>
'

origArgs["stats"] = getfighterstats(frame, origArgs["name"])

if origArgs["stats"] ~= "0-0" then html = html .. processData(makeHREF('Stats'), processStats(origArgs["stats"])) end html = html .. processData('Style', processStyle(origArgs["style"])) html = html .. processData('Height', origArgs["height"]) .. processData('Weight', origArgs["weight"]) html = html .. processData('Birthplace', origArgs["birthplace"])

if origArgs["fighters"] ~= "" and origArgs["fighters"] ~= nil then html = html .. origArgs["fighters"] .. plural(' Fighter', origArgs["fighters"]) end

html = html .. '
'

if origArgs["facebook"] ~= "" and origArgs["facebook"] ~= nil then html = html .. '<A HREF="https://facebook.com/' .. origArgs["facebook"] .. '" target="_blank"></A>' end if origArgs["twitter"] ~= "" and origArgs["twitter"] ~= nil then html = html .. '<A HREF="https://twitter.com/' .. origArgs["twitter"] .. '" target="_blank"></A>' end if origArgs["instagram"] ~= "" and origArgs["instagram"] ~= nil then html = html .. '<A HREF="https://instagram.com/' .. origArgs["instagram"] .. '" target="_blank"></A>' end if origArgs["youtube"] ~= "" and origArgs["youtube"] ~= nil then html = html .. '<A HREF="https://www.youtube.com/channel/' .. origArgs["youtube"] .. '" target="_blank"></A>' end

html = html .. '<A HREF="' .. getwikiurl(fighter, "Template:Ministats") .. '?action=edit" class="edit-fighter requirelogin"></A>
'

if wastype ~= "style" then

html = html .. '
' html = html .. '<A HREF="' .. url .. '"><img src="' .. origArgs["image"] .. '" class="module-ministats-thumbnail"></A>
'

end return html end

function fighterurl(fighter) if fighter == nil then return "[NONE]" end fighter = fighter:gsub("‘", "'"):gsub("’", "'"):gsub("”", "'"):gsub("“", "'"):gsub('"', "'") return makeURL(fighter) end

function hasnonickname(fighter) for i = 1, #nopages do if isequal(fighter, nopages[i]) then return true end i = i + 1 end return false end

function fighterHREF(fighter, frame) if fighter:sub(1, 3) == "LFC" then fighter = tonumber(trim(fighter:gsub("LFC", ""):gsub(" ", ""))) local eventname = "LFC " .. fighter .. ": " .. events[fighter] return '<A HREF="/wiki/Event:' .. eventname:gsub(" ", "_") .. '">' .. eventname .. '</A>' end if hasnonickname(fighter) then return '<A HREF="/wiki/Personalities">' .. fighter .. '</A>' end fighter = getnickname(fighter, frame) return '<A HREF="' .. fighterurl(fighter) .. '">' .. fighter .. '</A>' end

function fighterWIKI(fighter, frame) if hasnonickname(fighter) then return fighter end fighter = getnickname(fighter, frame) return '' .. fighter .. '' end

function p.fighterurl(frame) origArgs = frame:getParent().args return fighterHREF(origArgs[1], frame) end

function p.imageurl(frame) origArgs = frame:getParent().args local fighter = origArgs[1] local title = "" local url = "" if fighter:sub(1, 3) == "LFC" then fighter = tonumber(trim(fighter:gsub("LFC", ""):gsub(" ", ""))) title = "LFC " .. fighter .. ": " .. events[fighter] url = "/wiki/Images:LFC_" .. fighter else title = getnickname(fighter, frame) url = fighterurl("Template:Images:" .. title) end

return '

' .. title .. ' Content

<A HREF="' .. url .. '">Click to see more content</A>'

end

function gettemplate(frame, template) return mw.text.unstrip(frame:expandTemplate{ title = template, args = { '|' } }) end

function getfighterstats(frame, fighter) fighter = stripnickname(fighter) return getresults(frame, "stats", fighter) -- if fighter == nil then return "" end -- local stats = gettemplate(frame, 'Ministats:' .. fighter) -- if stats then -- go here -- return trim(getbetween(stats, '', '')) -- end -- return "" end

function winlose(frame, didlose, Text, fighter, classes) local stats = getfighterstats(frame, fighter) local td = "" local doFighterToo = Text == nil local URL = "https://lingeriefc.com/wiki/images/fighters/" local icon = '<IMG SRC="' .. URL .. stripnickname(fighter) .. '.jpg" onerror="imgerror(this);" class="fighter-icon fighter-' if didlose then if Text == nil then Text = "Loss" end td = '<td class="table-no2 ' .. classes if doFighterToo == false then icon = icon .. 'loser">' end else if Text == nil then Text = "Win" end if isadraw(classes) then Text = "Draw" end td = '<td class="table-yes2 ' .. classes if doFighterToo == false then icon = icon .. 'winner">' end end local HTML = td .. ' table-first">' .. Text if doFighterToo then td = '<TD STYLE="background: #C4C2C2; vertical-align: middle; text-align: center;" class="table-maybe2 table-fighter">' HTML = HTML .. td .. '<A HREF="' .. fighterurl(fighter) .. '">' .. icon .. 'loser">' .. fighter .. '</A>' else HTML = td .. ' table-fighter"><A HREF="' .. fighterurl(fighter) .. '">' .. icon .. fighter .. '</A>' end

HTML = HTML .. '
' .. stats .. '</TD>'

print(HTML) end

function getbetween(text, start, finish) return string.match(text, start .. "(.-)" .. finish) end

function isadraw(method) return textcontains(method, "draw") end

function fighterstats(frame, i) print('<tr>') local fighter = "" local classes = "" local needsroundtimemethod = true if isadraw(origArgs['method' .. i]) then classes = "fighter-draw" end if origArgs['opponent' .. i] ~= nil and origArgs['opponent' .. i] ~= then if i==1 then root:wikitext('<tr><th>Res.</th><th>Opponent</th><th>Event</th><TH>Watch</TH><th>Method</th><th>Round</th><th>Time</th></tr>') -- <th>Location</th><th>Notes</th> end fighter = getnickname(origArgs['opponent' .. i], frame, fighter) winlose(frame, origArgs['result' .. i] == "lose" or origArgs['result' .. i] == "loss", nil, fighter, classes) else if isequal(origArgs['round' .. i], "TBD") or isequal(origArgs['time' .. i], "TBD") or isequal(origArgs['method' .. i], "TBD") then if i==1 then root:wikitext('<tr><th>Competitor</th><th>Competitor</th></tr>') end needsroundtimemethod =false elseif i==1 then root:wikitext('<tr><th>Winner</th><th>Loser</th><th>Method</th><th>Round</th><th>Time</th></tr>') -- <th>Notes</th> end local winner = getnickname(origArgs['winner' .. i], frame) winlose(frame, false, '<A HREF="' .. fighterurl(winner) .. '">' .. winner .. '</A>', winner, classes) fighter = getnickname(origArgs['loser' .. i], frame) winlose(frame, true, '<A HREF="' .. fighterurl(fighter) .. '">' .. fighter .. '</A>', fighter, classes) end local td = '<TD STYLE="vertical-align: middle; text-align: center;" class="no-color">'

if origArgs['event' .. i] ~= nil then -- was "opponent" local location = "" if origArgs['location' .. i] ~= nil then location = origArgs['location' .. i] end print(td .. eventlocationdate(origArgs['event' .. i], '
', origArgs['date' .. i]) .. '</td>') end -- if origArgs['location' .. i] ~= nil then print(td .. origArgs['location' .. i] .. '</td>') end

if needsroundtimemethod then print(td .. origArgs['method' .. i] .. '</td>') if origArgs['round' .. i] == nil then origArgs['round' .. i] = "" end if origArgs['time' .. i] == nil then origArgs['time' .. i] = "" end print(td .. origArgs['round' .. i] .. '</td>') print(td .. origArgs['time' .. i] .. '</td>') end -- if origArgs['note' .. i] ~= nil then -- print(td .. '' .. origArgs['note' .. i] .. '</td></tr>') -- else -- print(td .. '</td></TR>') -- end print('</TR>') end

function p.buy(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end local results = require("Module:Results") local id = origArgs[1] local HTML = local number = tonumber(trim(id:gsub("LFC", ""):gsub(" ", ""))) local eventname = nil if events[number] ~= nil then eventname = "LFC " .. number .. ": " .. events[number] end local style = 1 if origArgs[2] ~= nil then style = tonumber(origArgs[2]) end local basehref = "https://lingeriefc.com/wiki/images/" local dvdprice = results[1]["prices"]["dvd"] local streamprice = results[1]["prices"]["stream"] if results[1][id] ~= nil then if style == 2 and results[1][id]["streamsku"] ~= nil then

HTML = '
Please purchase one of the following or <A HREF="/my-account">login</A> to watch this video:
'

HTML = HTML .. '[products ids="40055" columns="1" class="embeddedproduct"]'

HTML = HTML .. '
'

HTML = HTML .. '[products ids="' .. results[1][id]["streamsku"] .. '" columns="1" class="embeddedproduct"]'

HTML = HTML .. '
'

else

if style == 3 then HTML = '
' end

local found = false if results[1][id]["dvd"] ~= nil then found = style ~= 3 if style == 1 then HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["dvd"] .. '/" class="buylfc buy-dvd-2" TITLE="ORDER DVD $' .. dvdprice .. '" target="_blank"><IMG SRC="' .. basehref .. 'dvdicon.png" class="buy-icon"></A>' end if style == 2 then HTML = HTML .. '<A CLASS="btn btn-lg btn-danger buylfc order-now" HREF="' .. results[1][id]["dvd"] .. '/">ORDER <IMG SRC="' .. basehref .. 'dvdicon.png" class="buy-icon"> DVD $' .. dvdprice .. '</A>' end -- if style == 3 then HTML = HTML .. '<A HREF="' .. results[1][id]["dvd"] .. '/" CLASS="buylfc redbutton">Order DVD</A>' end end if results[1][id]["stream"] ~= nil then found = true if style == 1 then HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["stream"] .. '/" class="buy-stream-2 buylfc" TITLE="ORDER DIGITALLY $' .. streamprice .. '" target="_blank"><IMG SRC="' .. basehref .. 'streamicon.png" class="buy-icon"></A>' end if style == 2 then HTML = HTML .. '<A CLASS="btn buylfc btn-lg btn-danger order-now" HREF="' .. results[1][id]["stream"] .. '/">ORDER <IMG SRC="' .. basehref .. 'streamicon.png" class="buy-icon"> DIGITALLY $' .. streamprice .. '</A>' end -- if style == 3 then HTML = HTML .. '<A HREF="' .. results[1][id]["stream"] .. '/" CLASS="redbutton buylfc">Watch Now</A>' end if style == 3 and eventname ~= nil then HTML = HTML .. '<A HREF="/wiki/Event:' .. eventname .. '" CLASS="redbutton buylfc">Watch Now</A>' end if style == 3 and eventname == nil then HTML = HTML .. 'eventname for ' .. id .. ' not listed at the top of the modul' end end

if style == 3 then HTML = HTML .. "
" end

end end return HTML end

function eventlocationdate(event, location, date) local id = "LFC" .. getbetween(event, "LFC ", ":") local results = require("Module:Results") local HTML = "" -- [ID = " .. id .. ']' local basehref = "https://lingeriefc.com/wiki/images/" HTML = HTML .. '</TD><TD STYLE="vertical-align: middle; text-align: center;" class="no-color">' if results[1][id] ~= nil then if results[1][id]["dvd"] ~= nil then -- HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["dvd"] .. '/" class="buy-dvd" TITLE="Buy DVD" target="_blank"><IMG SRC="' .. basehref .. 'dvdicon.png" CLASS="buy-icon"></A>' HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["dvd"] .. '/" target="_blank">Buy DVD</A>' end if results[1][id]["stream"] ~= nil then if results[1][id]["dvd"] ~= nil then HTML = HTML .. '
' end -- HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["stream"] .. '/" class="buy-stream" TITLE="Buy Online Stream" target="_blank"><IMG SRC="' .. basehref .. 'streamicon.png" CLASS="buy-icon"></A>' HTML = HTML .. '<A HREF="https://lingeriefc.com/product/' .. results[1][id]["stream"] .. '/" target="_blank">Stream Online</A>' end end return '<A HREF="' .. makeURL('Event:' .. event) .. '">' .. event .. '' .. location .. " " .. convertdate(date) .. '</A>' .. HTML end

function convertdate(thedate) date = split(thedate, "-") if #date ~= 3 then date = split(thedate, " ") if #date == 3 then return thedate end -- return "date missing, has " .. #date .. " cols = '" .. thedate .. "'" return "" end local year = date[1] local month = date[2] local day = date[3] if tonumber(year) < 100 then year = "19" .. year end -- local html = td .. '' .. monthnames[tonumber(month)] .. ' ' .. day .. ', ' .. year .. '</td>'

local html = monthnames[tonumber(month)] .. ' ' .. day .. ', ' .. year return html end

--- Pads str to length len with char from right function lpad(str, len, char) str = tostring(str) if char == nil then char = ' ' end return string.rep(char, len - #str) .. str end

function split(str, pat) local t = {} -- NOTE: use {n = 0} in Lua-5.0 local fpat = "(.-)" .. pat local last_end = 1 if str == nil then str = "" end local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end

function isequal(text1, text2) if text1 == nil or text2 == nil then return false end return trim(text1:lower()) == trim(text2:lower()) end function getresults(frame, type, name) local results = require("Module:Results") local wins = 0 local losses = 0 local draws = 0 local decisions = 0 local iswinner local isloser local isdecision local isdraw local isfuture = false local HTML = "" local data = {} local index = 0 local extraHTML = "" local delimiter = "" local hasshown = 0 local Blackwins = 0 local Pinkwins = 0 local name2 = name:gsub(" ", ""):gsub("%.", "")

if origArgs ~= nil then if origArgs["title"] ~= nil then extratext = "" if type == "event" then extratext = " Results" end if type == "fighter" then extratext = " MMA Record" end

HTML = '

' .. getnickname(name, frame) .. extratext .. '

'

end end if type ~= "event" and type ~= "teamscore" then if results[1][name2] ~= nil then

extraHTML = '
'

if results[1][name2]["wins"] == nil and results[1][name2]["losses"] ~= nil then results[1][name2]["wins"] = 0 end if results[1][name2]["wins"] ~= nil then wins = results[1][name2]["wins"] extraHTML = extraHTML .. wins delimiter = "-" if results[1][name2]["losses"] == nil then results[1][name2]["losses"] = 0 end end if results[1][name2]["losses"] ~= nil then losses = results[1][name2]["losses"] extraHTML = extraHTML .. delimiter .. losses delimiter = "-" end if results[1][name2]["ties"] ~= nil then draws = results[1][name2]["ties"] extraHTML = extraHTML .. delimiter .. draws end if #delimiter > 0 then extraHTML = extraHTML .. " outside the LFC" end

extraHTML = extraHTML .. '
'

end end

for i = #results,2,-1 do if type == "event" then if results[i]["name"] == name or i == name then for p = 1, #results[i]["results"], 1 do hasshown = hasshown + 1 data["winner" .. p] = results[i]["results"][p]["winner"] data["loser" .. p] = results[i]["results"][p]["loser"] data["method" .. p] = results[i]["results"][p]["method"] data["round" .. p] = results[i]["results"][p]["round"] data["time" .. p] = results[i]["results"][p]["time"] data["date" .. p] = results[i]["results"][p]["date"] if results[i]["results"][p]["note"] ~= nil then data["note" .. p] = results[i]["results"][p]["note"] end end end elseif type == "black" or type == "pink" then if results[i]["name"] == name or i == name then for p = 1, #results[i]["results"], 1 do if results[i]["results"][p]["winningteam"] ~= nil then if isequal(results[i]["results"][p]["winningteam"], "black") then Blackwins = Blackwins + 1 end if isequal(results[i]["results"][p]["winningteam"], "pink") then Pinkwins = Pinkwins + 1 end end

		 	 	end

end else

	 	 	for p = 1, #results[i]["results"], 1 do

if results[i]["results"][p]["winningteam"] ~= nil then if isequal(results[i]["results"][p]["winningteam"], "black") then Blackwins = Blackwins + 1 end if isequal(results[i]["results"][p]["winningteam"], "pink") then Pinkwins = Pinkwins + 1 end end iswinner = isequal(results[i]["results"][p]["winner"], name) isloser = isequal(results[i]["results"][p]["loser"], name) isdraw = false isfuture = isequal(results[i]["results"][p]["round"], "TBD") or isequal(results[i]["results"][p]["method"], "TBD") or isequal(results[i]["results"][p]["time"], "TBD") if isfuture then iswinner = false isloser = false end if iswinner or isloser then isdraw = isadraw(results[i]["results"][p]["method"]) isdecision = textcontains(results[i]["results"][p]["method"], "decision") index=index+1 local opponent = "" if isdraw then draws = draws + 1 opponent = results[i]["results"][p]["loser"] if isequal(opponent, name) then opponent = results[i]["results"][p]["winner"] end data["result" .. index] = "draw" elseif iswinner then if isdecision then decisions = decisions + 1 end wins = wins + 1 opponent = results[i]["results"][p]["loser"] data["result" .. index] = "win" elseif isloser then losses = losses + 1 opponent = results[i]["results"][p]["winner"] data["result" .. index] = "loss" end if type == "fighter" then hasshown = hasshown + 1 data["opponent" .. index] = opponent data["event" .. index] = results[i]["name"] data["date" .. index] = "" if results[i]["date"] ~= nil then data["date" .. index] = results[i]["date"] end data["place" .. index] = "" data["location" .. index] = "" if results[i]["place"] ~= nil then data["location" .. index] = results[i]["place"] end data["method" .. index] = results[i]["results"][p]["method"] data["round" .. index] = results[i]["results"][p]["round"] data["time" .. index] = results[i]["results"][p]["time"] -- data["date" .. index] = results[i]["results"][p]["date"] if results[i]["results"][p]["note"] ~= nil then data["note" .. index] = results[i]["results"][p]["note"] end else hasshown = hasshown + 1 end end

	 	 	end

end end if type == "stats" then HTML = wins .. "-" .. losses if draws > 0 then HTML = HTML .. "-" .. draws end -- if decisions > 0 then HTML = HTML .. "-" .. decisions end return HTML end if type == "wins" then return wins end if type == "losses" then return losses end if type == "draws" then return draws end if type == "decisions" then return decisions end if type == "teamscore" or type == "black" or type == "pink" then if type ~= "teamscore" then name2 = type end if isequal(name2, "Black") then return Blackwins end if isequal(name2, "Pink") then return Pinkwins end end if hasshown == 0 then return HTML .. extraHTML .. 'Coming Soon' end return HTML .. p.statcard(frame, data) .. extraHTML end

function p.autoresults(frame) local HTML = "" if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end return getresults(frame, origArgs["type"], origArgs["name"]) end

local function getnicknamesplit(fighter, frame) fighter = stripnickname(trim(fighter)):gsub("‘", "'"):gsub("’", "'"):gsub("“", "'"):gsub("”", "'"):gsub('"', "'") nickname = if nicknames[fighter] ~= nil then nickname = nicknames[fighter] end if nickname ~= then fighter = fighter .. ", " .. nickname .. ", " .. getnickname(fighter, frame) end return fighter end

function p.autosplit(frame) local HTML = "" if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end local fighter = mw.text.decode(origArgs["1"]) return getnicknamesplit(fighter, frame) end

function p.autostrip(frame) local HTML = "" if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end local fighter = mw.text.decode(origArgs["1"]) fighter = stripnickname(trim(fighter)):gsub("‘", "'"):gsub("’", "'"):gsub("“", "'"):gsub("”", "'"):gsub('"', "'") return getnickname(fighter, frame) end


return p

© 2019 • Lingerie Fighting Championships / Terms / Privacy