Module:LNDB

local p = {} local nxb_dengeki = mw.loadData( 'Module:LNDB/Dengeki' ) local nxb_fantasia = mw.loadData( 'Module:LNDB/Fantasia' ) local nxb_sneaker = mw.loadData( 'Module:LNDB/Sneaker' ) local nxb_mf = mw.loadData( 'Module:LNDB/MF' ) local nxb_famitsu = mw.loadData( 'Module:LNDB/Famitsu' ) local nxb_dashx = mw.loadData( 'Module:LNDB/DashX' ) local nxb_ga = mw.loadData( 'Module:LNDB/GA' ) local nxb_hj = mw.loadData( 'Module:LNDB/HJ' ) local nxb_gagaga = mw.loadData( 'Module:LNDB/GAGAGA' ) local nxb_kodansha = mw.loadData( 'Module:LNDB/Kodansha' ) local nxb_overlap = mw.loadData( 'Module:LNDB/Overlap' ) local nxb_monster= mw.loadData( 'Module:LNDB/Monster' )

local _header = "font-weight:bold;text-align:left;color:white;padding:0.75em 1.5em;" local _rdate = "background:#f6f6f6;text-transform: uppercase;font-size:75%;text-align:center;padding:0.75em 1.5em;" local _id = "font-size:95%;font-style:italic;padding:0.75em 1.5em;" local _title = "width:350px;font-size:95%;font-style:italic;padding:0.75em 1.5em;" local _personnel = "width:150px;font-size:95%;font-style:italic;padding:0.75em 1.5em;" local _list = {} local _tablestart = "\" local _tableend = "\"

local _calendarstart = "\" local _calendarend = "\" local _cheaderstart = "\" local _cheaderend = "\" local _cdatestart = "\" local _cdatestart2 = "\" local _cdateend = "\" local _ceventstart = "\" local _ceventstart2 = "\" local _ceventend = "\" local _ccellstart = "\" local _ccellend = "\" local _crowstart = "\" local _crowend = "\"

local function _generatetable(frame) local count = 0 local rdate, id, title, author, illustrator, header, sheader local rows = {} --   --Get Time Query-- --   timestamp = tostring(frame.timestamp) ---   --Get Publisher Query-- ---   pub = tostring(frame.publisher)

-   --Dengeki Bunko-- -   if (pub == "dengeki") then for k, v in spairs(nxb_dengeki) do           if string.sub(nxb_dengeki[k].d,3,6) == timestamp then _list[#_list+1] = nxb_dengeki[k] datestamp = string.sub(nxb_dengeki[k].d,1,2) end end sheader = "background:linear-gradient(#3c3c3c,black);background: -moz-linear-gradient(#3c3c3c,black);background: -o-linear-gradient(#3c3c3c,black);background: -webkit-linear-gradient(#3c3c3c,black);".._header end --   --Fantasia Bunko-- --   if (pub == "fantasia") then for k, v in spairs(nxb_fantasia) do           if string.sub(nxb_fantasia[k].d,3,6) == timestamp then _list[#_list+1] = nxb_fantasia[k] datestamp = string.sub(nxb_fantasia[k].d,1,2) end end sheader = "background:linear-gradient(#C25151,#A52A2A);background: -moz-linear-gradient(#C25151,#A52A2A);background: -o-linear-gradient(#C25151,#A52A2A);background: -webkit-linear-gradient(#C25151,#A52A2A);".._header end -   --Sneaker Bunko-- -   if (pub == "sneaker") then for k, v in spairs(nxb_sneaker) do           if string.sub(nxb_sneaker[k].d,3,6) == timestamp then _list[#_list+1] = nxb_sneaker[k] datestamp = string.sub(nxb_sneaker[k].d,1,2) end end sheader = "background:linear-gradient(#FCA356,#f47100);background: -moz-linear-gradient(#FCA356,#f47100);background: -o-linear-gradient(#FCA356,#f47100);background: -webkit-linear-gradient(#FCA356,#f47100);".._header end --MF Bunko-- if (pub == "mf") then for k, v in spairs(nxb_mf) do           if string.sub(nxb_mf[k].d,3,6) == timestamp then _list[#_list+1] = nxb_mf[k] datestamp = string.sub(nxb_mf[k].d,1,2) end end sheader = "background:linear-gradient(#2ED1B0,#01b18d);background: -moz-linear-gradient(#2ED1B0,#01b18d);background: -o-linear-gradient(#2ED1B0,#01b18d);background: -webkit-linear-gradient(#2ED1B0,#01b18d);".._header end -   --Famitsu Bunko-- -   if (pub == "famitsu") then for k, v in spairs(nxb_famitsu) do           if string.sub(nxb_famitsu[k].d,3,6) == timestamp then _list[#_list+1] = nxb_famitsu[k] datestamp = string.sub(nxb_famitsu[k].d,1,2) end end sheader = "background:linear-gradient(#E83131,#d40000);background: -moz-linear-gradient(#E83131,#d40000);background: -o-linear-gradient(#E83131,#d40000);background: -webkit-linear-gradient(#E83131,#d40000);".._header end --Dash X Bunko-- if (pub == "dashx") then for k, v in spairs(nxb_dashx) do           if string.sub(nxb_dashx[k].d,3,6) == timestamp then _list[#_list+1] = nxb_dashx[k] datestamp = string.sub(nxb_dashx[k].d,1,2) end end sheader = "background:linear-gradient(#A437CC,#7D00AB);background: -moz-linear-gradient(#A437CC,#7D00AB);background: -o-linear-gradient(#A437CC,#7D00AB);background: -webkit-linear-gradient(#A437CC,#7D00AB);".._header end --GA Bunko-- if (pub == "ga") then for k, v in spairs(nxb_ga) do           if string.sub(nxb_ga[k].d,3,6) == timestamp then _list[#_list+1] = nxb_ga[k] datestamp = string.sub(nxb_ga[k].d,1,2) end end sheader = "background:linear-gradient(#75BFEB,#017DC7);background: -moz-linear-gradient(#75BFEB,#017DC7);background: -o-linear-gradient(#75BFEB,#017DC7);background: -webkit-linear-gradient(#75BFEB,#017DC7);".._header end --HJ Bunko-- if (pub == "hj") then for k, v in spairs(nxb_hj) do           if string.sub(nxb_hj[k].d,3,6) == timestamp then _list[#_list+1] = nxb_hj[k] datestamp = string.sub(nxb_hj[k].d,1,2) end end sheader = "background:linear-gradient(#D2E87B,#BADB32);background: -moz-linear-gradient(#D2E87B,#BADB32);background: -o-linear-gradient(#D2E87B,#BADB32);background: -webkit-linear-gradient(#D2E87B,#BADB32);".._header end --GAGAGA Bunko-- if (pub == "gagaga") then for k, v in spairs(nxb_gagaga) do           if string.sub(nxb_gagaga[k].d,3,6) == timestamp then _list[#_list+1] = nxb_gagaga[k] datestamp = string.sub(nxb_gagaga[k].d,1,2) end end sheader = "background:linear-gradient(#4574BF,#003EA1);background: -moz-linear-gradient(#4574BF,#003EA1);background: -o-linear-gradient(#4574BF,#003EA1);background: -webkit-linear-gradient(#4574BF,#003EA1);".._header end

-   --Kodansha Ranobe Bunko-- -   if (pub == "kodansha") then for k, v in spairs(nxb_kodansha) do           if string.sub(nxb_kodansha[k].d,3,6) == timestamp then _list[#_list+1] = nxb_kodansha[k] datestamp = string.sub(nxb_kodansha[k].d,1,2) end end sheader = "background:linear-gradient(#FFD5C4,#FFB091);background: -moz-linear-gradient(#FFD5C4,#FFB091);background: -o-linear-gradient(#FFD5C4,#FFB091);background: -webkit-linear-gradient(#FFD5C4,#FFB091);".._header end -   --Overlap Bunko-- -   if (pub == "overlap") then for k, v in spairs(nxb_overlap) do           if string.sub(nxb_overlap[k].d,3,6) == timestamp then _list[#_list+1] = nxb_overlap[k] datestamp = string.sub(nxb_overlap[k].d,1,2) end end sheader = "background:linear-gradient(#dcd189,#CCBD5E);background: -moz-linear-gradient(#dcd189,#CCBD5E);background: -o-linear-gradient(#dcd189,#CCBD5E);background: -webkit-linear-gradient(#dcd189,#CCBD5E);".._header end

-   --Monster Bunko-- -   if (pub == "monster") then for k, v in spairs(nxb_monster) do           if string.sub(nxb_monster[k].d,3,6) == timestamp then _list[#_list+1] = nxb_monster[k] datestamp = string.sub(nxb_monster[k].d,1,2) end end sheader = "background:linear-gradient(#4E9C60,#00731B);background: -moz-linear-gradient(#4E9C60,#00731B);background: -o-linear-gradient(#4E9C60,#00731B);background: -webkit-linear-gradient(#4E9C60,#00731B);".._header end header = "\<tr\>\<th\ style='"..sheader.."'\>#\</th\>\<th\ style='"..sheader.."'\>Tác phẩm\</th\>\<th\ style='"..sheader.."'\>Tác giả\</th\>\<th\ style='"..sheader.."'\>Minh họa\</th\>" rdate = "\<tr\>\<td colspan='4' style='".._rdate.."'\>"..datemonth(datestamp..timestamp).."\</td\>\</tr\>" --Application Code-- for k, v in spairs(_list) do       count = count + 1 if (count % 2 ==0) then id = "\<td style='background:#f6f6f6;".._id.."'\>"..count.."\</td\>" title = "\<td style='background:#f6f6f6;".._title.."'\>".._list[k].tr.."\</td\>" author = "\<td style='background:#f6f6f6;".._personnel.."'\>".._list[k].ar.."\</td\>" illustrator = "\<td style='background:#f6f6f6;".._personnel.."'\>".._list[k].ir.."\</td\>" else id = "\<td style='background:#e9e9e9;".._id.."'\>"..count.."\</td\>" title = "\<td style='background:#e9e9e9;".._title.."'\>".._list[k].tr.."\</td\>" author = "\<td style='background:#e9e9e9;".._personnel.."'\>".._list[k].ar.."\</td\>" illustrator = "\<td style='background:#e9e9e9;".._personnel.."'\>".._list[k].ir.."\</td\>" end rows[#rows+1] = "\<tr\>"..id..title..author..illustrator.."\</tr\>" end return _tablestart..header..rdate..table.concat(rows,'').._tableend end

local function _generatecalendar(frame)

local datestamp = {} local timestamp = {}

--Get Date-- for k, v in spairs(nxb_dengeki) do       if string.sub(nxb_dengeki[k].d,3,6) == frame.args[1] then datestamp['Dengeki Bunko'] = tonumber(string.sub(nxb_dengeki[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Dengeki Bunko'] break end end for k, v in spairs(nxb_fantasia) do       if string.sub(nxb_fantasia[k].d,3,6) == frame.args[1] then datestamp['Fantasia Bunko'] = tonumber(string.sub(nxb_fantasia[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Fantasia Bunko'] break end end for k, v in spairs(nxb_sneaker) do       if string.sub(nxb_sneaker[k].d,3,6) == frame.args[1] then datestamp['Sneaker Bunko'] = tonumber(string.sub(nxb_sneaker[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Sneaker Bunko'] break end end for k, v in spairs(nxb_mf) do       if string.sub(nxb_mf[k].d,3,6) == frame.args[1] then datestamp['MF Bunko J'] = tonumber(string.sub(nxb_mf[k].d,1,2)) timestamp[#timestamp+1] = datestamp['MF Bunko J'] break end end for k, v in spairs(nxb_famitsu) do       if string.sub(nxb_famitsu[k].d,3,6) == frame.args[1] then datestamp['Famitsu Bunko'] = tonumber(string.sub(nxb_famitsu[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Famitsu Bunko'] break end end for k, v in spairs(nxb_dashx) do       if string.sub(nxb_dashx[k].d,3,6) == frame.args[1] then datestamp['Dash X Bunko'] = tonumber(string.sub(nxb_dashx[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Dash X Bunko'] break end end for k, v in spairs(nxb_ga) do       if string.sub(nxb_ga[k].d,3,6) == frame.args[1] then datestamp['GA Bunko'] = tonumber(string.sub(nxb_ga[k].d,1,2)) timestamp[#timestamp+1] = datestamp['GA Bunko'] break end end for k, v in spairs(nxb_hj) do       if string.sub(nxb_hj[k].d,3,6) == frame.args[1] then datestamp['HJ Bunko'] = tonumber(string.sub(nxb_hj[k].d,1,2)) timestamp[#timestamp+1] = datestamp['HJ Bunko'] break end end for k, v in spairs(nxb_gagaga) do       if string.sub(nxb_gagaga[k].d,3,6) == frame.args[1] then datestamp['GAGAGA Bunko'] = tonumber(string.sub(nxb_gagaga[k].d,1,2)) timestamp[#timestamp+1] = datestamp['GAGAGA Bunko'] break end end for k, v in spairs(nxb_kodansha) do       if string.sub(nxb_kodansha[k].d,3,6) == frame.args[1] then datestamp['Kodansha Ranobe Bunko'] = tonumber(string.sub(nxb_kodansha[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Kodansha Ranobe Bunko'] break end end for k, v in spairs(nxb_overlap) do       if string.sub(nxb_overlap[k].d,3,6) == frame.args[1] then datestamp['Overlap Bunko'] = tonumber(string.sub(nxb_overlap[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Overlap Bunko'] break end end for k, v in spairs(nxb_monster) do       if string.sub(nxb_monster[k].d,3,6) == frame.args[1] then datestamp['Monster Bunko'] = tonumber(string.sub(nxb_monster[k].d,1,2)) timestamp[#timestamp+1] = datestamp['Monster Bunko'] break end end

_month = tonumber(string.sub(frame.args[1],1,2)) _year = tonumber(string.sub(frame.args[1],3,4)) + 2000 local _firstdate, _datelength local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } _datelength = days_in_month[_month] if (_month == 2) then if (math.mod(_year,4) == 0) then if (math.mod(_year,100) == 0)then if (math.mod(_year,400) == 0) then _datelength = 29 end else _datelength = 29 end end end -   --Set Timestamp-- -   tmp = os.time{year=_year, month=_month, day=1} _firstdate = os.date("*t",tmp).wday

table.sort(timestamp) local d = {} local hash = {} local t = {} for k, v in spairs(timestamp) do       if (not hash[v]) then d[#d+1] = v           hash[v] = true t[#t+1] = kvalue(datestamp,v) end end

---   --Generating Calendar-- ---   local ccell = {} local cvalue = {} for i=1,42 do       ccell[i] = "" cvalue[i] = " " end for i=_firstdate,_firstdate-1+_datelength do       ccell[i] = i+1-_firstdate end for k, v in spairs(d) do       cvalue[v+_firstdate-1] = t[k] end thisrow = {} thiscell = {} calendarheader = _cheaderstart..monthyear(frame.args[1]).._cheaderend calendardate = _cdatestart2.."Chủ Nhật".._cdateend.._cdatestart2.."Thứ Hai".._cdateend.._cdatestart2.."Thứ Ba".._cdateend.._cdatestart2.."Thứ Tư".._cdateend.._cdatestart2.."Thứ Năm".._cdateend.._cdatestart2.."Thứ Sáu".._cdateend.._cdatestart2.."Thứ Bảy".._cdateend for i=1,6 do       if i == 6 then if (_firstdate+_datelength<=35) then break end end for j=1,7 do           if (ccell[(i-1)*7+j] ~= "") then thiscell[j] = _ccellstart.._cdatestart..ccell[(i-1)*7+j].._cdateend.._ceventstart..cvalue[(i-1)*7+j].._ceventend.._ccellend else thiscell[j] = _ccellstart.._cdatestart2..ccell[(i-1)*7+j].._cdateend.._ceventstart2..cvalue[(i-1)*7+j].._ceventend.._ccellend end end thisrow[i] = _crowstart..table.concat(thiscell,' ').._crowend end return _calendarstart..calendarheader..calendardate.."\<div style='margin-bottom:15px;'\>\</div\>"..table.concat(thisrow,' ').._calendarend end

function spairs(t) local keys = {} for k in pairs(t) do keys[#keys+1] = k end table.sort(keys) local i = 0 return function i = i + 1 if keys[i] then return keys[i], t[keys[i]] end end end

function datemonth(timestamp) return "ngày \<b\>"..string.sub(timestamp,1,2).."\</b\> tháng \<b\>"..string.sub(timestamp,3,4).."\</b\> năm \<b\>20"..string.sub(timestamp,5,6).."\</b\>" end

function monthyear(timestamp) return "tháng "..string.sub(timestamp,1,2).." năm 20"..string.sub(timestamp,3,4) end

function kvalue(t,value) r = "" for k, v in spairs(t) do       if v == value then if r == "" then r = k           else r = r.."\<br\>"..k           end end end return r end

function p.dengeki(frame) arg = {timestamp=frame.args[1],publisher='dengeki'} return _generatetable(arg) end

function p.fantasia(frame) arg = {timestamp=frame.args[1],publisher='fantasia'} return _generatetable(arg) end

function p.sneaker(frame) arg = {timestamp=frame.args[1],publisher='sneaker'} return _generatetable(arg) end

function p.mf(frame) arg = {timestamp=frame.args[1],publisher='mf'} return _generatetable(arg) end

function p.famitsu(frame) arg = {timestamp=frame.args[1],publisher='famitsu'} return _generatetable(arg) end

function p.dashx(frame) arg = {timestamp=frame.args[1],publisher='dashx'} return _generatetable(arg) end

function p.ga(frame) arg = {timestamp=frame.args[1],publisher='ga'} return _generatetable(arg) end

function p.hj(frame) arg = {timestamp=frame.args[1],publisher='hj'} return _generatetable(arg) end

function p.gagaga(frame) arg = {timestamp=frame.args[1],publisher='gagaga'} return _generatetable(arg) end

function p.kodansha(frame) arg = {timestamp=frame.args[1],publisher='kodansha'} return _generatetable(arg) end

function p.overlap(frame) arg = {timestamp=frame.args[1],publisher='overlap'} return _generatetable(arg) end

function p.monster(frame) arg = {timestamp=frame.args[1],publisher='monster'} return _generatetable(arg) end

function p.calendar(frame) return _generatecalendar(frame) end return p