comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 179:af6143756a9e

mod_muc_log_http: started new prosody theme
author Thilo Cestonaro <thilo@cestona.ro>
date Thu, 17 Jun 2010 11:16:12 +0200
parents 2620bc59cca3
children f29be6c49501
comparison
equal deleted inserted replaced
178:62f47a93b5b7 179:af6143756a9e
212 end 212 end
213 end 213 end
214 if i < days + 1 then 214 if i < days + 1 then
215 local tmp = tostring("<span style='color:#DDDDDD'>"..tostring(i).."</span>"); 215 local tmp = tostring("<span style='color:#DDDDDD'>"..tostring(i).."</span>");
216 if dayCallback ~= nil and dayCallback.callback ~= nil then 216 if dayCallback ~= nil and dayCallback.callback ~= nil then
217 tmp = dayCallback.callback(dayCallback.path, i, month, year, dayCallback.room); 217 tmp = dayCallback.callback(dayCallback.path, i, month, year, dayCallback.room, dayCallback.webPath);
218 end 218 end
219 if tmp == nil then 219 if tmp == nil then
220 tmp = tostring("<span style='color:#DDDDDD'>"..tostring(i).."</span>"); 220 tmp = tostring("<span style='color:#DDDDDD'>"..tostring(i).."</span>");
221 else 221 else
222 logAvailableForMinimumOneDay = true; 222 logAvailableForMinimumOneDay = true;
277 return "<div name='yearDiv' style='padding: 40px; text-align: center;'>" .. html.year.title:gsub("###YEAR###", tostring(year)) .. htmlStr .. "</div><br style='clear:both;'/> \n"; 277 return "<div name='yearDiv' style='padding: 40px; text-align: center;'>" .. html.year.title:gsub("###YEAR###", tostring(year)) .. htmlStr .. "</div><br style='clear:both;'/> \n";
278 end 278 end
279 return ""; 279 return "";
280 end 280 end
281 281
282 local function perDayCallback(path, day, month, year, room) 282 local function perDayCallback(path, day, month, year, room, webPath)
283 local webPath = webPath or ""
283 local year = year; 284 local year = year;
284 if year > 2000 then 285 if year > 2000 then
285 year = year - 2000; 286 year = year - 2000;
286 end 287 end
287 local bareDay = str_format("%.02d%.02d%.02d", year, month, day); 288 local bareDay = str_format("%.02d%.02d%.02d", year, month, day);
288 local attributes, err = lfs.attributes(path.."/"..bareDay.."/"..room..".dat") 289 local attributes, err = lfs.attributes(path.."/"..bareDay.."/"..room..".dat")
289 if attributes ~= nil and attributes.mode == "file" then 290 if attributes ~= nil and attributes.mode == "file" then
290 local s = html.days.bit; 291 local s = html.days.bit;
291 s = s:gsub("###BARE_DAY###", bareDay); 292 s = s:gsub("###BARE_DAY###", webPath .. bareDay);
292 s = s:gsub("###DAY###", day); 293 s = s:gsub("###DAY###", day);
293 return s; 294 return s;
294 end 295 end
295 return; 296 return;
296 end 297 end
300 local arrDays = {}; 301 local arrDays = {};
301 local tmp; 302 local tmp;
302 local node, host, resource = splitJid(bareRoomJid); 303 local node, host, resource = splitJid(bareRoomJid);
303 local path = data_getpath(node, host, datastore); 304 local path = data_getpath(node, host, datastore);
304 local room = nil; 305 local room = nil;
306 local nextRoom = "";
307 local previousRoom = "";
308 local rooms = "";
305 local attributes = nil; 309 local attributes = nil;
310 local since = "";
311 local to = "";
312 local topic = "";
306 313
307 path = path:gsub("/[^/]*$", ""); 314 path = path:gsub("/[^/]*$", "");
308 attributes = lfs.attributes(path); 315 attributes = lfs.attributes(path);
309 if muc_hosts ~= nil and muc_hosts[host] and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bareRoomJid] ~= nil then 316 if muc_hosts ~= nil and muc_hosts[host] and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bareRoomJid] ~= nil then
317 local found = 0;
318 for jid, room in pairs(prosody.hosts[host].muc.rooms) do
319 local node = splitJid(jid)
320 if not room._data.hidden and node then
321 if found == 0 then
322 previousRoom = node
323 elseif found == 1 then
324 nextRoom = node
325 found = -1
326 end
327 if jid == bareRoomJid then
328 found = 1
329 end
330
331 rooms = rooms .. html.days.rooms.bit:gsub("###ROOM###", node);
332 end
333 end
334
310 room = prosody.hosts[host].muc.rooms[bareRoomJid]; 335 room = prosody.hosts[host].muc.rooms[bareRoomJid];
311 if room._data.hidden then 336 if room._data.hidden then
312 room = nil 337 room = nil
313 end 338 end
314 end 339 end
315 if attributes ~= nil and room ~= nil then 340 if attributes ~= nil and room ~= nil then
341 local first = 1;
316 local alreadyDoneYears = {}; 342 local alreadyDoneYears = {};
343 local temptime = {day=0, month=0, year=0};
344 topic = room._data.subject
345 if topic:len() > 60 then
346 topic = topic:sub(1, topic:find(" ", 50)) .. " ..."
347 end
317 for folder in lfs.dir(path) do 348 for folder in lfs.dir(path) do
318 local year, month, day = folder:match("^(%d%d)(%d%d)(%d%d)"); 349 local year, month, day = folder:match("^(%d%d)(%d%d)(%d%d)");
319 if year ~= nil and alreadyDoneYears[year] == nil then 350 if year ~= nil and alreadyDoneYears[year] == nil then
351 temptime.day = tonumber(day)
352 temptime.month = tonumber(month)
353 temptime.year = 2000 + tonumber(year)
354 if first == 1 then
355 to = tostring(os_date("%B %Y", os_time(temptime)))
356 first = 0
357 end
358
359 since = tostring(os_date("%B %Y", os_time(temptime)))
360 module:log("debug", "creating overview for: " .. tostring(since))
320 days = createYear(year, {callback=perDayCallback, path=path, room=node}) .. days; 361 days = createYear(year, {callback=perDayCallback, path=path, room=node}) .. days;
321 alreadyDoneYears[year] = true; 362 alreadyDoneYears[year] = true;
322 end 363 end
323 end 364 end
324 end 365 end
325 366
326 if days ~= "" then 367 if days ~= "" then
327 tmp = html.days.body:gsub("###DAYS_STUFF###", days); 368 tmp = html.days.body:gsub("###DAYS_STUFF###", days);
369 tmp = tmp:gsub("###PREVIOUS_ROOM###", previousRoom == "" and node or previousRoom);
370 tmp = tmp:gsub("###NEXT_ROOM###", nextRoom == "" and node or nextRoom);
371 tmp = tmp:gsub("###ROOMS###", rooms);
372 tmp = tmp:gsub("###ROOMTOPIC###", topic);
373 tmp = tmp:gsub("###SINCE###", since);
374 tmp = tmp:gsub("###TO###", to);
328 return tmp:gsub("###JID###", bareRoomJid); 375 return tmp:gsub("###JID###", bareRoomJid);
329 end 376 end
330 end 377 end
331 378
332 local function parseIqStanza(stanza, timeStuff, nick) 379 local function parseIqStanza(stanza, timeStuff, nick)
569 local tmp; 616 local tmp;
570 local node, host, resource = splitJid(bareRoomJid); 617 local node, host, resource = splitJid(bareRoomJid);
571 local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)"); 618 local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)");
572 local previousDay = findPreviousDay(bareRoomJid, bare_day); 619 local previousDay = findPreviousDay(bareRoomJid, bare_day);
573 local nextDay = findNextDay(bareRoomJid, bare_day); 620 local nextDay = findNextDay(bareRoomJid, bare_day);
621 local temptime = {day=0, month=0, year=0};
622 local path = data_getpath(node, host, datastore);
623 path = path:gsub("/[^/]*$", "");
624 local calendar = ""
625
626 if tonumber(year) <= 99 then
627 year = year + 2000;
628 end
629
630 temptime.day = tonumber(day)
631 temptime.month = tonumber(month)
632 temptime.year = tonumber(year)
633 calendar = createMonth(temptime.month, temptime.year, {callback=perDayCallback, path=path, room=node, webPath="../"}) or ""
574 634
575 if bare_day ~= nil then 635 if bare_day ~= nil then
576 local data = data_load(node, host, datastore .. "/" .. bare_day); 636 local data = data_load(node, host, datastore .. "/" .. bare_day);
577 if data ~= nil then 637 if data ~= nil then
578 for i=1, #data, 1 do 638 for i=1, #data, 1 do
607 end 667 end
608 end 668 end
609 end 669 end
610 if ret ~= "" then 670 if ret ~= "" then
611 if nextDay then 671 if nextDay then
612 nextDay = html.day.dayLink:gsub("###DAY###", nextDay):gsub("###TEXT###", "next day &gt;&gt;") 672 nextDay = html.day.dayLink:gsub("###DAY###", nextDay):gsub("###TEXT###", "&gt;")
613 end 673 end
614 if previousDay then 674 if previousDay then
615 previousDay = html.day.dayLink:gsub("###DAY###", previousDay):gsub("###TEXT###", "&lt;&lt; previous day"); 675 previousDay = html.day.dayLink:gsub("###DAY###", previousDay):gsub("###TEXT###", "&lt;");
616 end 676 end
617 ret = ret:gsub("%%", "%%%%"); 677 ret = ret:gsub("%%", "%%%%");
618 tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid); 678 tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid);
619 tmp = tmp:gsub("###YEAR###", year):gsub("###MONTH###", month):gsub("###DAY###", day); 679 tmp = tmp:gsub("###CALENDAR###", calendar);
680 tmp = tmp:gsub("###DATE###", tostring(os_date("%A, %B %d, %Y", os_time(temptime))));
620 tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject)); 681 tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject));
621 tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or ""); 682 tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or "");
622 tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or ""); 683 tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or "");
623 tmp = tmp:gsub("###NEXT_LINK###", nextDay or ""); 684 tmp = tmp:gsub("###NEXT_LINK###", nextDay or "");
624 tmp = tmp:gsub("###PREVIOUS_LINK###", previousDay or ""); 685 tmp = tmp:gsub("###PREVIOUS_LINK###", previousDay or "");