Модуль:SM

Материал из Справочника наблюдателя
Перейти к:навигация, поиск

(i)      Описание модуля[]

Этот модуль предназначен для реализации функций шаблона {{SM}}  и вызывается исключительно из указанного шаблона.


local p = {}

local smTab = { 
	facebook = 	{ 	link = 'https://www.facebook.com/%1',
					dig  = 'https://www.facebook.com/profile.php?id=%1',
					logo = 'Facebook.svg', 
					name = 'на Facebook',
				},
	twitter  =	{	link = 'https://twitter.com/%1',
					logo = 'Twitter.svg',
					name = 'в Твиттере',
					text = '<tt><span style="font-size:135%; font-weight:bold">@%1 </span></tt>',
					show = false,
				},
	email	=	{	link = 'mailto:%1',
					logo = 'Aiga mail.svg',
					name = '— написать письмо',
					text = "''&nbsp;%1  ''",
					show = true,
				},
	vk		=	{	link = 'https://vk.com/%1',
					logo = 'VK.svg',
					name = 'вКонтакте',
				},
	okdirect=	{	link = 'https://ok.ru/%1',
					dig  = 'https:/ok/profile/%1',
					logo = 'Ok.svg',
					name = 'в Одноклассниках',
				},
	ok		=	{	link = 'http://www.nablawiki.ru/index.php/Набла:Переход_на_одноклассники?id=%1',
					dig  = 'http://www.nablawiki.ru/index.php/Набла:Переход_на_одноклассники?id=profile/%1',
					logo = 'Ok.svg',
					name = 'в Одноклассниках',
				},
	livejournal={	link = 'http://%1.livejournal.com',
					logo = 'Livejournal 64.png',
					name = 'в Живом Журнале',
				},
	googleplus=	{	link = 'https://plus.google.com/%1',
					logo = 'Google plus.svg',
					name = 'в Google+',
				},
	mailru	=	{	link = 'http://my.mail.ru/%1',
					logo = 'Mailru.png',
					name = 'на mail.ru',
				},
	krug	=	{	link = 'http://%1.moikrug.ru',
					logo = 'Moi-krug.png',
					name = 'в Моем круге',
				},
	fb		=	'facebook',
	['фб']	=	'facebook',
	['жж']	=	'livejournal',
	lj		=	'livejournal',
	t		=	'twitter',
	['g+']	=	'googleplus',
	['вк']	=	'vk',
	}


function p.Link (frame)
	local args = frame:getParent().args
	local smtype = args[1]
	if not smtype then
		return ('Нет аргумента')
	end
	smtype = mw.ustring.lower (smtype)
	local smt = smTab [smtype]
	if not smt then
		return ('Неизвестный тип  SM')
	end
	if type (smt) == 'string' then
		smt = smTab [smt]
	end
	local alpha = args.alpha
	if not alpha then
		alpha = '|x16px|text-bottom'
	end
	
	
	local link
	if smt.dig and tonumber (args [2]) then
		link = smt.dig
	else
		link = smt.link
	end
	link = mw.ustring.gsub (link, '%%1', args [2])
			
	res = '[[Файл:' .. smt.logo .. alpha .. '|link=' ..  link .. '|'
--	if (args [3] or args.text) then
		res = res .. (args [3] or args.text or args [2])
--	else 
--		res = res .. args [2]
--	end
	res = res .. ' ' .. smt.name .. ']]'
	local show = args ['text'] or ''
	if show =='0' then
		show = false
	elseif show == '' then
		show = smt.show
	elseif show == '1' then
		show = true
	end
	if show == true then
		if smt.text then
			show = smt.text
		else
			show = '%1'
		end
	end	
	if show then
		show = '<span class="plainlinks">[' .. link .. ' &nbsp;' .. mw.ustring.gsub (show, '%%1', args [2]) .. ']</span>'
	end
	return res .. (show or '')
	
end
return p