Module:SiteList: Difference between revisions

From Porn Base Central
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 114: Line 114:
}
}


function p.site(frame)
function p.site(args)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'})
local site = getSite(args.site)
local site = getSite(args.site)


Line 167: Line 166:
end
end


local result = string.format(
local result = ''
'|-\n| style="%s" | %s\n| style="text-align:center;vertical-align:middle;" | %s%s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="width: 0px; padding: 0px; border: none;" |\n',
style,
siteType and siteType:gsub("^%l", string.upper) or 'Website',
linkOrLabel,
categoryLink,
alias,
notes
)

local ns = mw.title.getCurrentTitle().namespace
local ns = mw.title.getCurrentTitle().namespace
if ns == 0 then
if ns == 0 then
Line 195: Line 185:
end
end


return {
return {
style = style,
style = style,
siteType = siteType and siteType:gsub("^%l", string.upper) or 'Website',
siteType = siteType and siteType:gsub("^%l", string.upper) or 'Website',
linkOrLabel = linkOrLabel,
linkOrLabel = linkOrLabel,
categoryLink = categoryLink,
categoryLink = categoryLink,
alias = alias,
alias = alias,
notes = notes,
notes = notes,
additionalInfo = result
additionalInfo = result -- ваш код для добавления информации категории
}
}
else
else
return nil
return string.format('|-\n| colspan="4" style="text-align:center;vertical-align:middle;color:red;font-weight:bold;" | Error: invalid site parameter: %s. See [[PBC:SiteList|PBC:SiteList for documentation]] \n| style="width: 0px; padding: 0px; border: none;" |\n', args.site)
end
end
end
end
Line 214: Line 204:
for i, site in ipairs(args.list) do
for i, site in ipairs(args.list) do
local siteData = p.site({args = {site = site}})
local siteData = p.site({site = site, id = args.id, sceneid = args.sceneid, alias = args.alias, notes = args.notes})
if siteData then
if siteData then
table.insert(sites, siteData)
table.insert(sites, siteData)

Revision as of 08:58, 23 July 2023

Documentation for this module may be created at Module:SiteList/doc

local p = {}

local sites = {
    website1 = {
        label = 'Website 1',
        type = 'website',
        aliases = {'website1', 'website1.com', 'website1com'},
        url = 'https://website1.com/',
        sceneUrl = 'https://website1.com/updates/',
        modelUrl = 'https://website1.com/models/',
        suffix = '?ats=eyJhIjoyOTQwNzMsImMiOjU3MTMxNDM3LCJuIjoyMiwicyI6MjA2LCJlIjo3NzczLCJwIjoyfQ==',
        category = {'Website 1 models', 'Website 1 Videos', 'Website 1 Performers'},
        network = 'Network1 Network',
    },
    website2 = {
        label = 'Website 2',
        type = 'website',
        aliases = {'website2', 'website2.com', 'website2com'},
        url = 'https://website2.com/',
        sceneUrl = 'https://website2.com/scene/',
        modelUrl = 'https://website2.com/people/',
        suffix = '',
        category = 'Website 2 models',
        network = 'Network2 Network',
    },
    website3 = {
        label = 'Website 3',
        type = 'studio',
        aliases = {'website3', 'website3.com', 'website3com'},
        url = 'https://website3.com/',
        sceneUrl = 'https://website3.com/videos/',
        modelUrl = 'https://website3.com/performers/',
        suffix = '.html',
        category = 'Website 3 models',
        network = 'Network3 Network',
	    list = 'List of Website3 actors',
    },
    website4 = {
        label = 'Website 4',
        type = 'website',
        aliases = {'website4', 'website4.com', 'website4com'},
        url = 'https://website4.com/',
        sceneUrl = 'https://website4.com/videos/',
        modelUrl = 'https://website4.com/performers/',
        suffix = '.html',
        category = 'Website 4 models',
        network = '',
    },
    website5 = {
        label = 'Website 5',
        type = 'studio',
        aliases = {'website5', 'website5.com', 'website5com'},
        url = 'https://website5.com/',
        sceneUrl = '',
        modelUrl = 'https://website5.com/models/',
        suffix = '',
        category = 'Website 5 models',
        network = 'Network5 Network',
    },
    website6 = {
        label = 'Website 6',
        type = 'website',
        aliases = {'website6', 'website6.com', 'website6com'},
        url = '',
        sceneUrl = '',
        modelUrl = '',
        suffix = '',
        category = '',
        network = '',
    },
    website7 = {
        label = 'Website 7',
        type = 'website',
        aliases = {'website7', 'website7.com', 'website7com'},
        url = 'https://website7.com/',
        sceneUrl = 'https://website7.com/videos/',
        modelUrl = 'https://website7.com/performers/',
        suffix = '?ats=eyJhIjoyOTQwNzMsImMiOjU3MTMxNDM3LCJuIjoyMiwicyI6MjA2LCJlIjo3NzczLCJwIjoyfQ==',
        category = 'Website 7 models',
        network = 'Network7 Network',
	    idtonum = 'y',
	    list = 'List of Website7 actors',
    },
    website8 = {
        label = 'Website 8',
        type = 'website',
        aliases = {'website8', 'website8.com', 'website8com'},
        url = 'https://website8.com/',
        sceneUrl = 'https://website8.com/videos/',
        modelUrl = 'https://website8.com/performers/',
        suffix = '?ats=eyJhIjoyOTQwNzMsImMiOjU3MTMxNDM3LCJuIjoyMiwicyI6MjA2LCJlIjo3NzczLCJwIjoyfQ==',
        category = 'Website 8 models',
        network = 'Network8 Network',
	    idtonum = '',
	    list = '',
	    archiveURL = 'https://archive.ph/sBCAl',
	    archived = 'y',
    },
    website9 = {
        label = 'Website 9',
        type = 'website',
        aliases = {'website9', 'website9.com', 'website9com'},
        url = 'https://website9.com/',
        sceneUrl = 'https://website9.com/videos/',
        modelUrl = 'https://website9.com/performers/',
        suffix = '?ats=eyJhIjoyOTQwNzMsImMiOjU3MTMxNDM3LCJuIjoyMiwicyI6MjA2LCJlIjo3NzczLCJwIjoyfQ==',
        category = 'Website 9 models',
        network = 'Network9 Network',
	    idtonum = 'y',
	    list = 'List of Website9 actors',
	    archiveURL = 'https://archive.ph/NSAHAga',
	    archived = 'y',
    },
}

function p.site(args)
    local site = getSite(args.site)

    if site then
        local url = site.url
        local isArchived = site.archived and (site.archived == 'yes' or site.archived == 'y')
        local archiveNotice = isArchived and " <small>(''Website archived'')</small>" or ''
        
        if isArchived and site.archiveURL and site.archiveURL ~= '' then
            url = site.archiveURL
        elseif isArchived then
            url = ''
        else
            if url ~= '' then
                if args.sceneid and site.sceneUrl ~= '' then
                    url = site.sceneUrl .. args.sceneid .. site.suffix
                elseif args.id and site.modelUrl ~= '' then
                    url = site.modelUrl .. args.id .. site.suffix
                end
            end
        end

        local alias = args.alias or '<div style="font-size: 1em;">' .. mw.title.getCurrentTitle().text .. '</div>'
        local notes = args.notes and '<div style="font-size: 1em;">' .. args.notes .. '</div>' or '<div style="font-size: 1em;">N/A</div>'
        local categoryLink = site.network and site.network ~= '' and string.format(' <small>([[:Category:%s|%s]])</small>', site.network, site.network) or ''
        local siteType = site.type or args[1]
        local style

        if siteType == nil or siteType == '' then
            siteType = 'Invalid type'
            style = 'background-color:#E7E7E7;text-align:center;color:red;font-weight:bold'
        elseif siteType:lower() == 'studio' then
            style = 'background-color:#DADADA;text-align:center;color:black;font-weight:bold'
        else
            style = 'background-color:#E7E7E7;text-align:center;color:black;font-weight:bold'
        end

        local linkOrLabel
        if url ~= '' then
            if site.idtonum and (site.idtonum == 'yes' or site.idtonum == 'y') and args.id then
                linkOrLabel = string.format('[%s %s #%s]%s', url, site.label, args.id, archiveNotice)
            else
                linkOrLabel = string.format('[%s %s]%s', url, site.label, archiveNotice)
            end
        else
            linkOrLabel = site.label .. archiveNotice
        end

        if site.list and site.list ~= '' then
            linkOrLabel = linkOrLabel .. string.format(' ([[%s|LIST]])', site.list)
        end

        local result = ''
		local ns = mw.title.getCurrentTitle().namespace
		if ns == 0 then
		    if type(site.category) == "table" then
		        for _, cat in pairs(site.category) do
		            if cat ~= '' then
		                result = result .. '[[Category:' .. cat .. ']]'
		            end
		        end
		    elseif site.category ~= '' then
		        result = result .. '[[Category:' .. site.category .. ']]'
		    end
		    result = result .. '[[Category:Articles in the mainspace using Template:SiteList]]'
		elseif ns == 2 then
		    result = result .. '[[Category:Articles in the userspace using Template:SiteList]]'
		elseif ns == 118 then
		    result = result .. '[[Category:Drafts using Template:SiteList]]'
		end

        return {
            style = style,
            siteType = siteType and siteType:gsub("^%l", string.upper) or 'Website',
            linkOrLabel = linkOrLabel,
            categoryLink = categoryLink,
            alias = alias,
            notes = notes,
            additionalInfo = result
        }
    else
        return nil
    end
end

function p.siteList(frame)
    local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteListTop'})
    local sites = {}
    
    for i, site in ipairs(args.list) do
        local siteData = p.site({site = site, id = args.id, sceneid = args.sceneid, alias = args.alias, notes = args.notes})
        if siteData then
            table.insert(sites, siteData)
        end
    end
    
    -- Сортируем массив сайтов по linkOrLabel
    table.sort(sites, function(a, b) return a.linkOrLabel < b.linkOrLabel end)
    
    -- Создаем итоговую строку
    local result = ''
    for _, site in ipairs(sites) do
        result = result .. string.format(
            '|-\n| style="%s" | %s\n| style="text-align:center;vertical-align:middle;" | %s%s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="width: 0px; padding: 0px; border: none;" |\n',
            site.style,
            site.siteType,
            site.linkOrLabel,
            site.categoryLink,
            site.alias,
            site.notes
        ) .. site.additionalInfo
    end
    
    return result
end

function table.contains(table, element)
  for _, value in pairs(table) do
    if value == element then
      return true
    end
  end
  return false
end

function getSite(name)
    for _, site in pairs(sites) do
        if site.label:lower() == name:lower() or table.contains(site.aliases, name:lower()) then
            return site
        end
    end
    return nil
end

return p