پودمان:Ayat-Navigator

از اسلامیکال
نسخهٔ تاریخ ‏۱۲ دسامبر ۲۰۲۳، ساعت ۱۴:۲۵ توسط Haghjoo (بحث | مشارکت‌ها) (prev_aye)
(تفاوت) → نسخهٔ قدیمی‌تر | نمایش نسخهٔ فعلی (تفاوت) | نسخهٔ جدیدتر ← (تفاوت)
پرش به ناوبری پرش به جستجو

توضیحات این پودمان می‌تواند در پودمان:Ayat-Navigator/توضیحات قرار گیرد.

require('strict')

local p = {}
local args = {}

local num_con = require('Module:Numeral converter').convert
local getArgs = require('Module:Arguments').getArgs
--local cfg = mw.loadData('Module:Ayat-Navigator/configs')

local function getData(sure, data_type)
	if (data_type=="len") then
		return require('Module:Ayat-Navigator/Sure-Lengths')
	end
	
	if (data_type=="joze_hezb") then
		return require('Module:Ayat-Navigator/Joze-Hezb')
	end
		
	if (data_type=="aye") then
		return require('Module:Ayat-Navigator/Q' .. sure)
	end
	
	if (data_type=="name_num") then
		return require('Module:Ayat-Navigator/nums-names')
	end

	local title = mw.title.new('Module:Ayat-Navigator/' .. sure)
		if not (title and title.exists) then return nil end
	return require('Module:Ayat-Navigator/' .. sure)
end

function p.named_gen(frame)
	local listitems = ""

	args = getArgs(frame)
	
	local sure_num = args["sure_num"]

	if getData(num_con("en", sure_num), "ayat_data") then
		local data = getData(num_con("en", sure_num), "ayat_data")

		if data.ayat_namdar then
			for k, v in pairs(data.ayat_namdar) do
				listitems = listitems .. '\n* ' .. v
			end
		end
	end
	
	return listitems
end

function p.ayat_gen(frame)
	local listitems = ""

	args = getArgs(frame)
	
	local aye_num = num_con("en", args["aye_num"])
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	local sure = args["sure"]
	
	if getData(sure_num, "len") then
		local data = getData(sure_num, "len")
		
		if tonumber(aye_num) then
			for i = 1, data.lengths[sure_num] do
				listitems = listitems ..
					'\n* [[آیه ' .. num_con("fa", i) .. ' سوره ' .. sure .. '|'
					.. num_con("fa", i) .. ']]'
			end
		end
	end
	
	return listitems
end

function p.mortabet(frame)
	local listitems = ""

	args = getArgs(frame)
	
	local sure_num = args["sure_num"]

	if getData(num_con("en", sure_num), "ayat_data") then
		local data = getData(num_con("en", sure_num), "ayat_data")
		
		if data.mortabet then
			for k, v in pairs(data.mortabet) do
				listitems = listitems .. '\n* ' .. v
			end
		end
	end
	
	return listitems
end

local function hezb_calculator(surenum, ayenum)
	if getData(surenum, "joze_hezb") and
	   tonumber(surenum) and
	   tonumber(ayenum) then
		local data = getData(surenum, "joze_hezb")
		local hezbs = data.hezbs
		
		for i= 1, 120 do
			local hezb_ini_sure = tonumber(hezbs[i].AzAvaleAye[1])
			local hezb_fin_sure = tonumber(hezbs[i].TaAkharAye[1])
			local hezb_ini_aye = tonumber(hezbs[i].AzAvaleAye[2])
			local hezb_fin_aye = tonumber(hezbs[i].TaAkharAye[2])
			
			if (hezb_ini_sure <= surenum) and
			   (hezb_fin_sure >= surenum) and
			   (hezb_ini_sure == hezb_fin_sure) then
			   if (hezb_ini_aye <= ayenum) and
			      (hezb_fin_aye >= ayenum) then
			      return i
		       end
		    elseif (hezb_ini_sure <= surenum) and
			       (hezb_fin_sure >= surenum) and
			       (hezb_ini_sure < hezb_fin_sure) then
	               if (surenum == hezb_ini_sure) then
	                  if (hezb_ini_aye <= ayenum) then
	                     return i
	                  end
	               elseif (surenum > hezb_ini_sure) and
	               	      (surenum < hezb_fin_sure) then
	               	      return i
	               elseif (surenum == hezb_fin_sure) then
	           	          if (ayenum <= hezb_fin_aye) then
	               	         return i
	               	      end
	               end
	        end
		end
	end
end

function p.get_hezb(frame)
	args = getArgs(frame)
	
	local aye_num = tonumber(num_con("en", args["aye_num"]))
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	
	return hezb_calculator(sure_num, aye_num)
end

function p.get_joze(frame)
	args = getArgs(frame)
	
	local aye_num = tonumber(num_con("en", args["aye_num"]))
	local sure_num = tonumber(num_con("en", args["sure_num"]))

	if getData(sure_num, "joze_hezb") then
		local data = getData(sure_num, "joze_hezb")
		local hezbs = data.hezbs
		local hezb = hezb_calculator(sure_num, aye_num)
		
		for i= 1, 120 do
			if (hezb == i) then
				return hezbs[i].JozeHezb[1]
			end
		end
	end
end

function p.get_tarjoms(frame)
	args = getArgs(frame)
	
	local aye_num = tonumber(num_con("en", args["aye_num"]))
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	local motarjem = args["motarjem"]
	
	if (motarjem == "خرمشاهی") then
		motarjem = "Khoramshahi"
	elseif (motarjem == "گمشادزهی") then
		motarjem = "Gomshadzehi"
	else
		motarjem = ""
	end
	
	if not (aye_num and sure_num and motarjem) then
		return
	end

	if getData(num_con("en", sure_num), "tarjoms") then
		local data = getData(num_con("en", sure_num), "tarjoms")
		
		return data.tarjoms[aye_num][motarjem]
	end
end

function p.get_aye(frame)
	args = getArgs(frame)
	
	local aye_num = tonumber(num_con("en", args["aye_num"]))
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	local sure_name = args["sure_name"]

	if aye_num and sure_num and not sure_name then
		if getData(sure_num, "aye") then
			local data = getData(sure_num, "aye")
			return data.ayat[aye_num]
		end
	elseif aye_num and not sure_num and sure_name then
		if getData(sure_name, "name_num") then
			local suresnums = getData(sure_num, "name_num")
			if suresnums.names_nums[sure_name] then
				local surenum = suresnums.names_nums[sure_name]
				if getData(surenum, "aye") then
					local data = getData(surenum, "aye")
					return data.ayat[aye_num]
				end
			end
		end
	end
end

function p.next_aye(frame)
	args = getArgs(frame)
	
	local aye_num = tonumber(num_con("en", args["aye_num"]))
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	local sure_name = args["sure_name"]
	
	local data_len = getData("", "len")
	local data_nn = getData("", "name_num")

	local sure_name_next
	
	if (sure_num < 114) then
		sure_name_next = data_nn.nums_names[sure_num+1]
	elseif ((sure_num == 114) and (aye_num < 6)) then
		sure_name_next = data_nn.nums_names[sure_num]
	elseif ((sure_num == 114) and (aye_num == 6)) then
		sure_name_next = data_nn.nums_names[1]
	else
		return "آیه بعد"
	end
	
	local sure_len = data_len.lengths
	
	if (aye_num < sure_len[sure_num]) then
		return "[[آیه " .. num_con("fa", aye_num+1) .. " سوره " .. sure_name .."|آیه بعد]]"
	elseif (aye_num == sure_len[sure_num]) then
		return "[[آیه " .. num_con("fa", "1") .. " سوره " .. sure_name_next .."|آیه بعد]]"
	else
		return "آیه بعد"
	end
end

function p.prev_aye(frame)
	args = getArgs(frame)
	
	local aye_num = tonumber(num_con("en", args["aye_num"]))
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	local sure_name = args["sure_name"]
	
	local data_nn = getData("", "name_num")
	local data_len = getData("", "len")
	local sure_len = data_len.lengths

	if ((aye_num > 1) and (sure_num == 1)) then
		return "[[آیه " .. num_con("fa", aye_num-1) .. " سوره " .. sure_name .."|آیه قبل]]"
	elseif ((aye_num > 1) and (sure_num > 1)) then
		return "[[آیه " .. num_con("fa", aye_num-1) .. " سوره " .. sure_name .."|آیه قبل]]"
	elseif ((aye_num == 1) and (sure_num > 1)) then
		local sure_name_prev = data_nn.nums_names[sure_num-1]
		return "[[آیه " .. num_con("fa", sure_len[sure_num-1]) .. " سوره " .. sure_name_prev .."|آیه قبل]]"
	elseif ((aye_num == 1) and (sure_num == 1)) then
		local sure_name_prev = data_nn.nums_names[114]
		return "[[آیه " .. num_con("fa", sure_len[114]) .. " سوره " .. sure_name_prev .."|آیه قبل]]"
	else
		return "آیه قبل"
	end
end

function p.get_sure_len(frame)
	args = getArgs(frame)
	
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	
	local data_len = getData("", "len")
	local sure_len = data_len.lengths
	
	return sure_len[sure_num]
end

function p.get_sure_name(frame)
	args = getArgs(frame)
	
	local sure_num = tonumber(num_con("en", args["sure_num"]))
	local data_nn = getData("", "name_num")

	if ((sure_num <= 114) and (sure_num >= 1)) then
		return data_nn.nums_names[sure_num]
	end
end

return p