Documentation for this module may be created at Image/doc

local p = {}
 
local origArgs
local root
local args = {}

function image(file)
	print( '[[File:' .. file .. ']]' )
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:gsub("uploads/", "")
	end
	if contains(url, "/uploads/") then 
		url = url:gsub(" ", "-"):gsub("'", "-")
	end
	print( '<A HREF="' .. url .. '" class="athumb strip col-lg-2 col-md-3 col-sm-4 col-xs-6"><IMG SRC="https://lingeriefc.com/thumb.php?filename=' .. url .. '&size=shop_thumbnail" ALT="' .. alt .. '" CLASS="thumb"></A> ' )
end

function makethumb2(name, number, total, ext)
	local padding = ''
	if number < 10 and total > 9 then padding = '0' end
	if number < 100 and total > 99 then padding = padding  .. '0' end
	if contains(name, "#") then
		local hashes = countoccurences(name, "#")
		hashes = string.rep("#", hashes)
		name = name:gsub(hashes, padding .. number)
	else
		name = 'wiki_' .. name .. '_' .. padding .. number .. '.' .. ext
	end
	makethumb('https://lingeriefc.com/wp-content/uploads/' .. name, name)
end

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

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

function handlebulk(index, limit)
	if origArgs['name' .. index] and origArgs['name'  .. index] ~= '' and origArgs['images' .. index] and origArgs['images' .. index] ~= '' then
		local current = 0
		local ext = "jpg"
		local name = origArgs['name' .. index] 
		local duplicates = {}
		if origArgs['duplicates' .. index] and origArgs['duplicates' .. index] ~= '' then
			duplicates = split(origArgs['duplicates' .. index], ",")
		end
		if origArgs['ext' .. index] ~= nil then ext = origArgs['ext' .. index] end
		if isnumber(origArgs['images' .. index]) then
			local total = tonumber(origArgs['images' .. index])
			while current < total and limit > 0 do
				current = current + 1
				if not_has_value(duplicates, tostring(current)) then
					makethumb2(name, current, total, ext)
				end
				limit = limit - 1
			end
			return total
		else
			local numbers = splitnumbers(origArgs['images' .. index])
			local total = biggest(numbers)
			while current < #numbers and limit > 0 do
				current = current + 1
				limit = limit - 1
				if isnumber(numbers[current]) then
					makethumb2(name, tonumber(numbers[current]), total, ext)
				else
					makethumb(numbers[current], numbers[current])
				end
			end
			return #numbers
		end
	end
	return 0
end

function debugt(numbers)
	local current = 0
	while current < #numbers do
		current = current + 1
		print("<BR>" .. current .. ": " .. numbers[current])
	end
	print("<BR>MAX: " .. biggest(numbers))
end 
function splitnumbers(numbers)
	numbers = split(numbers:gsub(" ", ""), ",")
	local current = 0
	local curr2 = 0
	local range = {}
	local ret = {}
	while current < #numbers do
		current = current + 1
		if contains(numbers[current], "-") then
			range = split(numbers[current], "-")
			for curr2=range[1],range[2] do
				ret[#ret+1] = curr2
			end
		else
			ret[#ret+1] = numbers[current]
		end
	end
	return ret
end
function biggest(t)
	local current = 0
	local maximum = 0
	while current < #t do
		current = current + 1
		if isnumber(t[current]) then
			if tonumber(t[current]) > maximum then 
				maximum = tonumber(t[current])
			end
		end
	end
	return maximum
end
function isnumber(value)
	return tonumber(value) ~= nil 
end
function not_has_value (tab, val)
    for index, value in ipairs(tab) do
        if value == val then
            return false
        end
    end
    return true
end

function split(str, pat)
   local t = {}  -- NOTE: use {n = 0} in Lua-5.0
   local fpat = "(.-)" .. pat
   local last_end = 1
   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 getbetween(text, start, finish)
	return string.match(text, start .. "(.-)" .. finish)
end
function right(text, digits)
	return text:sub(-digits)
end
function left(text, digits)
	return text:sub(1, digits)
end
function mid(text, startat, length)
	return string.sub(text, startat, startat + length)   -- from character 7 until and including 9
end
function len(text)
	return text:len()
end
function countoccurences(text, lookfor)
	local _, count = string.gsub(text, lookfor, "")
	return count
end
function finddomain(URL)
	if left(URL, 5) == "https" then URL = right(URL, len(URL) - 8) else URL = right(URL, len(URL) - 7) end
	local start = string.find(URL, "/")
	if start ~= nil then URL = left(URL, start-1) end
	local _, count = string.gsub(URL, "%.", "")
	if count  == 2 then
		start = string.find(URL, "%.")
		if start ~= nil then URL = right(URL, len(URL) - start) end
	end 
	start = string.find(URL, "%.")
	if start ~= nil then URL = left(URL, start-1) end
	return URL
end

function p.EmbedInstagram(frame)
	local i = 1
	local index = 1
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	local root = ""
	local sidebar = '<DIV CLASS="carousel-sidebar col-md-2">'
	if args.child ~= 'yes' then
		while origArgs[i] and origArgs[i] ~= '' do
			local url = trim(origArgs[i])
			if right(url, 1) ~= "/" then url = url .. "/" end
			local HTML = '<IMG SRC="' .. url .. 'media/?size=l" CLASS="InstagramSlides">'
			root = root .. HTML
			sidebar = sidebar .. '<IMG SRC="' .. url .. 'media/?size=t" CLASS="Instagram-thumb" ONCLICK="showDivs(' .. i .. ');">'
			i = i + 1
		end
	end
	return '<DIV CLASS="carousel">' .. sidebar .. '</DIV><DIV CLASS="carousel-frame col-md-10"><button class="w3-button w3-display-left" onclick="plusDivs(-1);">&#10094;</button><button class="w3-button w3-display-right" onclick="plusDivs(+1);">&#10095;</button>' .. root .. '</DIV></DIV>'
end

function p.Embed(frame)
	local i = 1
	local index = 1
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	local root = ""
	if args.child ~= 'yes' then
		while origArgs[i] and origArgs[i] ~= '' do
			local url = trim(origArgs[i])
			local domain = finddomain(url)
			local HTML = '<DIV CLASS="oembed col-md-6" DOMAIN="' .. domain .. '">' .. url .. '</DIV>'
			root = root .. HTML
			i = i + 1
		end
	end
	return root
end

function combine(URL, text)
	if left(text, 1) == "/" then
		text = right(text, text:len() - 1)
	end
	if right(URL, 1) == "/" then
		return URL .. text
	end
	return URL .. "/" .. text
end

function p.InfoboxImage(frame)
	local i = 1
	local index = 1
	local limit = 999999
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if args.child ~= 'yes' then
		root = mw.html.create('div'):addClass("row")
		if origArgs["limit"] ~= nil then
			limit = tonumber(origArgs["limit"])
		end
		limit = limit - handlebulk("", limit)
		local currentimages = 1
		while currentimages > 0 and limit > 0 do
			currentimages = handlebulk(index, limit)
			limit = limit - currentimages
			index = index + 1
		end
		while origArgs[i] and origArgs[i] ~= '' and limit > 0 do
			url = trim(origArgs[i])
			if string.find(url, "://") or string.find(url, "uploads/") then
				makethumb(url, url)
			else
				image(url)
			end
			i = i + 1
			limit = limit - 1
		end
		local HTML = ""
		if origArgs["edit"] ~= nil then
			if not contains(origArgs["edit"], "'") then
				local api = require("Module:Fightcard")
				origArgs["edit"] = api.nickname2(origArgs["edit"], frame)
			end
			HTML = '<A HREF="/wiki/index.php?title=Template:Images:' .. origArgs["edit"] .. '&action=edit" class="requirelogin"><i class="fa fa-fw fa-pencil"></i></A><A HREF="/wiki/index.php?title=Images"><i class="fa fa-fw fa-file-image-o requirelogin"></i></A>'
		end
		return '<DIV Class="image-container">' .. tostring(root)  .. '</DIV>' .. HTML
	end
end
function contains(text, texttofind)
	return string.find(text, texttofind) ~= nil
end
function p.Youtube(frame)
	local i = 1
	local html = ""
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if args.child ~= 'yes' then
		if #origArgs > 1 then 
			html = html .. '<div class="row">'
		end
		while origArgs[i] and origArgs[i] ~= '' do
			url = trim(origArgs[i])
			html = html .. '<iframe src="https://www.youtube.com/embed/' .. url .. '" frameborder="0" allowfullscreen class="col-md-4 youtube_padding" STYLE="margin-bottom: 10px;"></iframe>'
			i = i + 1
		end
		if #origArgs > 1 then 
			html = html .. '</div>'
		end
	end
	return '<div class="row youtubecontainer">' ..html .. '</div>'
end


function p.SEO(frame)
	local i = 1
	local html = ""
	root = mw.html.create('table')
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	if args.child ~= 'yes' then
		for index, value in pairs(origArgs) do
			if index == "description" then 
				html = html .. tostring(root:wikitext('{{#tag:metadesc | ' .. value  .. ' }}'))
			else
				html = html  .. '<meta name="' .. index .. '" content="' .. value .. '"/>'
			end
		end
	end
	return '<seo>' .. html .. '</seo>'
end

return p


© 2019 • Lingerie Fighting Championships / Terms / Privacy