Mercurial > prosody-modules
comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 583:a634b116c694
mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 25 Jan 2012 06:58:53 +0500 |
parents | 92ff305e7e32 |
children | adcb751f22f3 |
comparison
equal
deleted
inserted
replaced
582:92ff305e7e32 | 583:a634b116c694 |
---|---|
238 local webPath = webPath or "" | 238 local webPath = webPath or "" |
239 local year = year; | 239 local year = year; |
240 if year > 2000 then | 240 if year > 2000 then |
241 year = year - 2000; | 241 year = year - 2000; |
242 end | 242 end |
243 local bareDay = str_format("%.02d%.02d%.02d", year, month, day); | 243 local bareDay = str_format("20%.02d-%.02d-%.02d", year, month, day); |
244 room = urlencode(room); | 244 room = urlencode(room); |
245 local attributes, err = lfs.attributes(path.."/"..bareDay.."/"..room..".dat") | 245 local attributes, err = lfs.attributes(path.."/"..str_format("%.02d%.02d%.02d", year, month, day).."/"..room..".dat") |
246 if attributes ~= nil and attributes.mode == "file" then | 246 if attributes ~= nil and attributes.mode == "file" then |
247 local s = html.days.bit; | 247 local s = html.days.bit; |
248 s = s:gsub("###BARE_DAY###", webPath .. bareDay); | 248 s = s:gsub("###BARE_DAY###", webPath .. bareDay); |
249 s = s:gsub("###DAY###", day); | 249 s = s:gsub("###DAY###", day); |
250 return s; | 250 return s; |
444 end | 444 end |
445 return ret; | 445 return ret; |
446 end | 446 end |
447 | 447 |
448 local function incrementDay(bare_day) | 448 local function incrementDay(bare_day) |
449 local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)"); | 449 local year, month, day = bare_day:match("^20(%d%d)-(%d%d)-(%d%d)$"); |
450 local leapyear = false; | 450 local leapyear = false; |
451 module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year)) | 451 module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year)) |
452 | 452 |
453 day = tonumber(day); | 453 day = tonumber(day); |
454 month = tonumber(month); | 454 month = tonumber(month); |
480 day = 1; | 480 day = 1; |
481 end | 481 end |
482 else | 482 else |
483 day = day + 1; | 483 day = day + 1; |
484 end | 484 end |
485 return strformat("%.02d%.02d%.02d", year, month, day); | 485 return strformat("20%.02d-%.02d-%.02d", year, month, day); |
486 end | 486 end |
487 | 487 |
488 local function findNextDay(bareRoomJid, bare_day) | 488 local function findNextDay(bareRoomJid, bare_day) |
489 local node, host, resource = splitJid(bareRoomJid); | 489 local node, host, resource = splitJid(bareRoomJid); |
490 local day = incrementDay(bare_day); | 490 local day = incrementDay(bare_day); |
504 return day; | 504 return day; |
505 end | 505 end |
506 end | 506 end |
507 | 507 |
508 local function decrementDay(bare_day) | 508 local function decrementDay(bare_day) |
509 local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)"); | 509 local year, month, day = bare_day:match("^20(%d%d)-(%d%d)-(%d%d)$"); |
510 local leapyear = false; | 510 local leapyear = false; |
511 module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year)) | 511 module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year)) |
512 | 512 |
513 day = tonumber(day); | 513 day = tonumber(day); |
514 month = tonumber(month); | 514 month = tonumber(month); |
538 end | 538 end |
539 end | 539 end |
540 else | 540 else |
541 day = day - 1; | 541 day = day - 1; |
542 end | 542 end |
543 return strformat("%.02d%.02d%.02d", year, month, day); | 543 return strformat("20%.02d-%.02d-%.02d", year, month, day); |
544 end | 544 end |
545 | 545 |
546 local function findPreviousDay(bareRoomJid, bare_day) | 546 local function findPreviousDay(bareRoomJid, bare_day) |
547 local node, host, resource = splitJid(bareRoomJid); | 547 local node, host, resource = splitJid(bareRoomJid); |
548 local day = decrementDay(bare_day); | 548 local day = decrementDay(bare_day); |
567 local year; | 567 local year; |
568 local month; | 568 local month; |
569 local day; | 569 local day; |
570 local tmp; | 570 local tmp; |
571 local node, host, resource = splitJid(bareRoomJid); | 571 local node, host, resource = splitJid(bareRoomJid); |
572 local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)"); | 572 local year, month, day = bare_day:match("^20(%d%d)-(%d%d)-(%d%d)$"); |
573 local previousDay = findPreviousDay(bareRoomJid, bare_day); | 573 local previousDay = findPreviousDay(bareRoomJid, bare_day); |
574 local nextDay = findNextDay(bareRoomJid, bare_day); | 574 local nextDay = findNextDay(bareRoomJid, bare_day); |
575 local temptime = {day=0, month=0, year=0}; | 575 local temptime = {day=0, month=0, year=0}; |
576 local path = data_getpath(node, host, datastore); | 576 local path = data_getpath(node, host, datastore); |
577 path = path:gsub("/[^/]*$", ""); | 577 path = path:gsub("/[^/]*$", ""); |
585 temptime.month = tonumber(month) | 585 temptime.month = tonumber(month) |
586 temptime.year = tonumber(year) | 586 temptime.year = tonumber(year) |
587 calendar = createMonth(temptime.month, temptime.year, {callback=perDayCallback, path=path, room=node, webPath="../"}) or "" | 587 calendar = createMonth(temptime.month, temptime.year, {callback=perDayCallback, path=path, room=node, webPath="../"}) or "" |
588 | 588 |
589 if bare_day ~= nil then | 589 if bare_day ~= nil then |
590 local data = data_load(node, host, datastore .. "/" .. bare_day); | 590 local data = data_load(node, host, datastore .. "/" .. bare_day:match("^20(.*)"):gsub("-", "")); |
591 if data ~= nil then | 591 if data ~= nil then |
592 for i=1, #data, 1 do | 592 for i=1, #data, 1 do |
593 local stanza = lom.parse(data[i]); | 593 local stanza = lom.parse(data[i]); |
594 if stanza ~= nil and stanza.attr ~= nil and stanza.attr.time ~= nil then | 594 if stanza ~= nil and stanza.attr ~= nil and stanza.attr.time ~= nil then |
595 local timeStuff = html.day.time:gsub("###TIME###", stanza.attr.time):gsub("###UTC###", stanza.attr.utc or stanza.attr.time); | 595 local timeStuff = html.day.time:gsub("###TIME###", stanza.attr.time):gsub("###UTC###", stanza.attr.utc or stanza.attr.time); |
662 elseif not node then -- room list for component | 662 elseif not node then -- room list for component |
663 return createDoc(generateRoomListSiteContent(host)); | 663 return createDoc(generateRoomListSiteContent(host)); |
664 elseif not day then -- room's listing | 664 elseif not day then -- room's listing |
665 return createDoc(generateDayListSiteContentByRoom(node.."@"..host)); | 665 return createDoc(generateDayListSiteContentByRoom(node.."@"..host)); |
666 else | 666 else |
667 if not day:match("^20(%d%d)-(%d%d)-(%d%d)$") then | |
668 local y,m,d = day:match("^(%d%d)(%d%d)(%d%d)$"); | |
669 if not y then | |
670 return { status = "404 Not found", body = "Unknown URL" }; | |
671 end | |
672 return { status = "301 Moved Permanently", | |
673 headers = { ["Location"] = request.url.path:match("^/muc_log/+[^/]*/*[^/]*").."/20"..y.."-"..m.."-"..d.."/" } }; | |
674 end | |
667 local room = hosts[host].modules.muc.rooms[node.."@"..host]; | 675 local room = hosts[host].modules.muc.rooms[node.."@"..host]; |
668 return createDoc(parseDay(node.."@"..host, room._data.subject or "", day:gsub("%-", ""))); | 676 return createDoc(parseDay(node.."@"..host, room._data.subject or "", day)); |
669 end | 677 end |
670 end | 678 end |
671 | 679 |
672 local function readFile(filepath) | 680 local function readFile(filepath) |
673 local f,err = io_open(filepath, "r"); | 681 local f,err = io_open(filepath, "r"); |