annotate mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 1016:9f7c97e55593

mod_broadcast: Allow overriding from address on the broadcast stanza
author Matthew Wild <mwild1@gmail.com>
date Sun, 19 May 2013 22:25:54 +0100
parents 290c21a5e0ee
children 043189eb41bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
1 module:depends("http");
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
2
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
3 local prosody = prosody;
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
4 local hosts = prosody.hosts;
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
5 local my_host = module:get_host();
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
6 local tabSort = table.sort;
116
f68a781efe81 mod_muc_log_http: support escaped urls
Thilo Cestonaro <thilo@cestona.ro>
parents: 115
diff changeset
7 local strchar = string.char;
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
8 local strformat = string.format;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
9 local splitJid = require "util.jid".split;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
10 local config_get = require "core.configmanager".get;
344
2b0f2160fc61 mod_muc_log_http: Fix room name encoding/decoding (for UTF-8 room names)
Joseph Wallace <JosephWallace@letu.edu>
parents: 343
diff changeset
11 local urldecode = require "net.http".urldecode;
973
1db6d5028b3d mod_muc_log_http: rename fire_server_event to fire_event.
Marco Cirillo <maranda@lightwitch.org>
parents: 972
diff changeset
12 local http_event = require "net.http.server".fire_event;
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
13 local data_load, data_getpath = datamanager.load, datamanager.getpath;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
14 local datastore = "muc_log";
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
15 local urlBase = "muc_log";
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
16 local config = nil;
977
f178318c9aeb mod_muc_log_http: remove overlapping imports.
Marco Cirillo <maranda@lightwitch.org>
parents: 975
diff changeset
17 local tostring, tonumber = tostring, tonumber;
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
18 local os_date, os_time = os.date, os.time;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
19 local str_format = string.format;
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
20 local io_open = io.open;
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
21 local themesParent = (module.path and module.path:gsub("[/\\][^/\\]*$", "") or (prosody.paths.plugins or "./plugins") .. "/muc_log_http") .. "/themes";
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
22
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
23 local lom = require "lxp.lom";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
24 local lfs = require "lfs";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
25 local html = {};
183
9d4fd01443eb mod_muc_log_http: ensure to have the default being "prosody"
Thilo Cestonaro <thilo@cestona.ro>
parents: 180
diff changeset
26 local theme;
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
27
975
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
28 -- Helper Functions
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
29
975
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
30 local p_encode = datamanager.path_encode;
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
31 local function store_exists(node, host, today)
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
32 if lfs.attributes(data_getpath(node, host, datastore .. "/" .. today), "mode") then return true; else return false; end
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
33 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
34
975
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
35 -- Module Definitions
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
36
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
37 local function htmlEscape(t)
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
38 if t then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
39 t = t:gsub("<", "&lt;");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
40 t = t:gsub(">", "&gt;");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
41 t = t:gsub("(http://[%a%d@%.:/&%?=%-_#%%~]+)", function(h)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
42 h = urlunescape(h)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
43 return "<a href='" .. h .. "'>" .. h .. "</a>";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
44 end);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
45 t = t:gsub("\n", "<br />");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
46 t = t:gsub("%%", "%%%%");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
47 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
48 t = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
49 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
50 return t;
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
51 end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
52
393
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
53 function createDoc(body, title)
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
54 if not body then return "" end
393
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
55 body = body:gsub("%%", "%%%%");
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
56 return html.doc:gsub("###BODY_STUFF###", body)
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
57 :gsub("<title>muc_log</title>", "<title>"..(title and htmlEscape(title) or "Chatroom logs").."</title>");
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
58 end
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
59
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
60 function urlunescape (escapedUrl)
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
61 escapedUrl = escapedUrl:gsub("+", " ")
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
62 escapedUrl = escapedUrl:gsub("%%(%x%x)", function(h) return strchar(tonumber(h,16)) end)
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
63 escapedUrl = escapedUrl:gsub("\r\n", "\n")
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
64 return escapedUrl
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
65 end
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
66
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
67 local function generateRoomListSiteContent(component)
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
68 local rooms = "";
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
69 local component_host = hosts[component];
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
70 if component_host and component_host.muc ~= nil then
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
71 for jid, room in pairs(component_host.muc.rooms) do
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
72 local node = splitJid(jid);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
73 if not room._data.hidden and node then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
74 rooms = rooms .. html.rooms.bit:gsub("###ROOM###", node):gsub("###COMPONENT###", component);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
75 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
76 end
393
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
77 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component), "Chatroom logs for "..component;
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
78 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
79 end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
80
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
81 -- Calendar stuff
386
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
82 local function get_days_for_month(month, year)
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
83 if month == 2 then
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
84 local is_leap_year = (year % 4 == 0 and year % 100 ~= 0) or year % 400 == 0;
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
85 return is_leap_year and 29 or 28;
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
86 elseif (month < 8 and month%2 == 1) or (month >= 8 and month%2 == 0) then
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
87 return 31;
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
88 end
386
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
89 return 30;
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
90 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
91
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
92 local function createMonth(month, year, dayCallback)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
93 local htmlStr = html.month.header;
386
d54dbbfda3bb mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents: 385
diff changeset
94 local days = get_days_for_month(month, year);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
95 local time = os_time{year=year, month=month, day=1};
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
96 local dow = tostring(os_date("%a", time))
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
97 local title = tostring(os_date("%B", time));
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
98 local weekDays = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
99 local weekDay = 0;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
100 local weeks = 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
101 local logAvailableForMinimumOneDay = false;
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
102
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
103 local weekDaysHtml = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
104 for _, tmp in ipairs(weekDays) do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
105 weekDaysHtml = weekDaysHtml .. html.month.weekDay:gsub("###DAY###", tmp) .. "\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
106 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
107
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
108 htmlStr = htmlStr:gsub("###TITLE###", title):gsub("###WEEKDAYS###", weekDaysHtml);
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
109
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
110 for i = 1, 31 do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
111 weekDay = weekDay + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
112 if weekDay == 1 then htmlStr = htmlStr .. "<tr>\n"; end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
113 if i == 1 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
114 for _, tmp in ipairs(weekDays) do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
115 if dow ~= tmp then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
116 htmlStr = htmlStr .. html.month.emptyDay .. "\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
117 weekDay = weekDay + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
118 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
119 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
120 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
121 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
122 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
123 if i < days + 1 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
124 local tmp = tostring(i);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
125 if dayCallback ~= nil and dayCallback.callback ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
126 tmp = dayCallback.callback(dayCallback.path, i, month, year, dayCallback.room, dayCallback.webPath);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
127 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
128 if tmp == nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
129 tmp = tostring(i);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
130 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
131 logAvailableForMinimumOneDay = true;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
132 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
133 htmlStr = htmlStr .. html.month.day:gsub("###DAY###", tmp) .. "\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
134 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
135
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
136 if i >= days then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
137 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
138 end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
139
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
140 if weekDay == 7 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
141 weekDay = 0;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
142 weeks = weeks + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
143 htmlStr = htmlStr .. "</tr>\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
144 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
145 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
146
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
147 if weekDay + 1 < 8 or weeks < 6 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
148 weekDay = weekDay + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
149 if weekDay > 7 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
150 weekDay = 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
151 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
152 if weekDay == 1 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
153 weeks = weeks + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
154 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
155 for y = weeks, 6 do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
156 if weekDay == 1 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
157 htmlStr = htmlStr .. "<tr>\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
158 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
159 for i = weekDay, 7 do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
160 htmlStr = htmlStr .. html.month.emptyDay .. "\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
161 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
162 weekDay = 1
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
163 htmlStr = htmlStr .. "</tr>\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
164 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
165 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
166 htmlStr = htmlStr .. html.month.footer;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
167 if logAvailableForMinimumOneDay then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
168 return htmlStr;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
169 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
170 end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
171
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
172 local function createYear(year, dayCallback)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
173 local year = year;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
174 local tmp;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
175 if tonumber(year) <= 99 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
176 year = year + 2000;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
177 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
178 local htmlStr = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
179 for i=1, 12 do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
180 tmp = createMonth(i, year, dayCallback);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
181 if tmp then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
182 htmlStr = htmlStr .. "<div style='float: left; padding: 5px;'>\n" .. tmp .. "</div>\n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
183 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
184 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
185 if htmlStr ~= "" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
186 return "<div name='yearDiv' style='padding: 40px; text-align: center;'>" .. html.year.title:gsub("###YEAR###", tostring(year)) .. htmlStr .. "</div><br style='clear:both;'/> \n";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
187 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
188 return "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
189 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
190
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
191 local function perDayCallback(path, day, month, year, room, webPath)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
192 local webPath = webPath or ""
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
193 local year = year;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
194 if year > 2000 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
195 year = year - 2000;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
196 end
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
197 local bareDay = str_format("20%.02d-%.02d-%.02d", year, month, day);
974
224e3745c1b3 mod_muc_log_http: use datamanager's encoding function to encode room names.
Marco Cirillo <maranda@lightwitch.org>
parents: 973
diff changeset
198 room = p_encode(room);
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
199 local attributes, err = lfs.attributes(path.."/"..str_format("%.02d%.02d%.02d", year, month, day).."/"..room..".dat");
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
200 if attributes ~= nil and attributes.mode == "file" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
201 local s = html.days.bit;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
202 s = s:gsub("###BARE_DAY###", webPath .. bareDay);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
203 s = s:gsub("###DAY###", day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
204 return s;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
205 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
206 return;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
207 end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
208
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
209 local function generateDayListSiteContentByRoom(bareRoomJid)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
210 local days = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
211 local arrDays = {};
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
212 local tmp;
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
213 local node, host = splitJid(bareRoomJid);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
214 local path = data_getpath(node, host, datastore);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
215 local room = nil;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
216 local nextRoom = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
217 local previousRoom = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
218 local rooms = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
219 local attributes = nil;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
220 local since = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
221 local to = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
222 local topic = "";
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
223 local component = hosts[host];
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
224
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
225 if not(component and component.muc and component.muc.rooms[bareRoomJid]) then
579
513aa6fed9e9 mod_muc_log_http: Don't return a page on missing rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 578
diff changeset
226 return;
513aa6fed9e9 mod_muc_log_http: Don't return a page on missing rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 578
diff changeset
227 end
513aa6fed9e9 mod_muc_log_http: Don't return a page on missing rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 578
diff changeset
228
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
229 path = path:gsub("/[^/]*$", "");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
230 attributes = lfs.attributes(path);
390
8090d246c268 mod_muc_log_http: Removed some more code. Module now no longer attempts to track muc_log hosts on its own.
Waqas Hussain <waqas20@gmail.com>
parents: 389
diff changeset
231 do
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
232 local found = 0;
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
233 for jid, room in pairs(component.muc.rooms) do
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
234 local node = splitJid(jid)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
235 if not room._data.hidden and node then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
236 if found == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
237 previousRoom = node
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
238 elseif found == 1 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
239 nextRoom = node
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
240 found = -1
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
241 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
242 if jid == bareRoomJid then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
243 found = 1
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
244 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
245
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
246 rooms = rooms .. html.days.rooms.bit:gsub("###ROOM###", node);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
247 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
248 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
249
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
250 room = component.muc.rooms[bareRoomJid];
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
251 if room._data.hidden then
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
252 room = nil;
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
253 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
254 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
255 if attributes ~= nil and room ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
256 local alreadyDoneYears = {};
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
257 topic = room._data.subject or "(no subject)"
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
258 if topic:len() > 135 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
259 topic = topic:sub(1, topic:find(" ", 120)) .. " ..."
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
260 end
391
99e7ef4fc7d2 mod_muc_log_http: Properly sort calendar listing.
Waqas Hussain <waqas20@gmail.com>
parents: 390
diff changeset
261 local folders = {};
99e7ef4fc7d2 mod_muc_log_http: Properly sort calendar listing.
Waqas Hussain <waqas20@gmail.com>
parents: 390
diff changeset
262 for folder in lfs.dir(path) do table.insert(folders, folder); end
99e7ef4fc7d2 mod_muc_log_http: Properly sort calendar listing.
Waqas Hussain <waqas20@gmail.com>
parents: 390
diff changeset
263 table.sort(folders);
99e7ef4fc7d2 mod_muc_log_http: Properly sort calendar listing.
Waqas Hussain <waqas20@gmail.com>
parents: 390
diff changeset
264 for _, folder in ipairs(folders) do
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
265 local year, month, day = folder:match("^(%d%d)(%d%d)(%d%d)");
392
369e665ae471 mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents: 391
diff changeset
266 if year then
369e665ae471 mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents: 391
diff changeset
267 to = tostring(os_date("%B %Y", os_time({ day=tonumber(day), month=tonumber(month), year=2000+tonumber(year) })));
369e665ae471 mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents: 391
diff changeset
268 if since == "" then since = to; end
369e665ae471 mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents: 391
diff changeset
269 if not alreadyDoneYears[year] then
369e665ae471 mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents: 391
diff changeset
270 module:log("debug", "creating overview for: %s", to);
369e665ae471 mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents: 391
diff changeset
271 days = createYear(year, {callback=perDayCallback, path=path, room=node}) .. days;
369e665ae471 mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents: 391
diff changeset
272 alreadyDoneYears[year] = true;
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
273 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
274 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
275 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
276 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
277
388
75aea9752062 mod_muc_log_http: Generate room calendar page even when there is no log data.
Waqas Hussain <waqas20@gmail.com>
parents: 387
diff changeset
278 tmp = html.days.body:gsub("###DAYS_STUFF###", days);
75aea9752062 mod_muc_log_http: Generate room calendar page even when there is no log data.
Waqas Hussain <waqas20@gmail.com>
parents: 387
diff changeset
279 tmp = tmp:gsub("###PREVIOUS_ROOM###", previousRoom == "" and node or previousRoom);
75aea9752062 mod_muc_log_http: Generate room calendar page even when there is no log data.
Waqas Hussain <waqas20@gmail.com>
parents: 387
diff changeset
280 tmp = tmp:gsub("###NEXT_ROOM###", nextRoom == "" and node or nextRoom);
75aea9752062 mod_muc_log_http: Generate room calendar page even when there is no log data.
Waqas Hussain <waqas20@gmail.com>
parents: 387
diff changeset
281 tmp = tmp:gsub("###ROOMS###", rooms);
75aea9752062 mod_muc_log_http: Generate room calendar page even when there is no log data.
Waqas Hussain <waqas20@gmail.com>
parents: 387
diff changeset
282 tmp = tmp:gsub("###ROOMTOPIC###", topic);
75aea9752062 mod_muc_log_http: Generate room calendar page even when there is no log data.
Waqas Hussain <waqas20@gmail.com>
parents: 387
diff changeset
283 tmp = tmp:gsub("###SINCE###", since);
75aea9752062 mod_muc_log_http: Generate room calendar page even when there is no log data.
Waqas Hussain <waqas20@gmail.com>
parents: 387
diff changeset
284 tmp = tmp:gsub("###TO###", to);
393
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
285 return tmp:gsub("###JID###", bareRoomJid), "Chatroom logs for "..bareRoomJid;
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
286 end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
287
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
288 local function parseIqStanza(stanza, timeStuff, nick)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
289 local text = nil;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
290 local victim = nil;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
291 if(stanza.attr.type == "set") then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
292 for _,tag in ipairs(stanza) do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
293 if tag.tag == "query" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
294 for _,item in ipairs(tag) do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
295 if item.tag == "item" and item.attr.nick ~= nil and item.attr.role == 'none' then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
296 victim = item.attr.nick;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
297 for _,reason in ipairs(item) do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
298 if reason.tag == "reason" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
299 text = reason[1];
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
300 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
301 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
302 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
303 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
304 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
305 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
306 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
307 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
308 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
309 if victim ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
310 if text ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
311 text = html.day.reason:gsub("###REASON###", htmlEscape(text));
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
312 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
313 text = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
314 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
315 return html.day.kick:gsub("###TIME_STUFF###", timeStuff):gsub("###VICTIM###", victim):gsub("###REASON_STUFF###", text);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
316 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
317 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
318 return;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
319 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
320
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
321 local function parsePresenceStanza(stanza, timeStuff, nick)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
322 local ret = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
323 local showJoin = "block"
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
324
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
325 if config and not config.showJoin then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
326 showJoin = "none";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
327 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
328
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
329 if stanza.attr.type == nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
330 local showStatus = "block"
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
331 if config and not config.showStatus then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
332 showStatus = "none";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
333 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
334 local show, status = nil, "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
335 local alreadyJoined = false;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
336 for _, tag in ipairs(stanza) do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
337 if tag.tag == "alreadyJoined" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
338 alreadyJoined = true;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
339 elseif tag.tag == "show" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
340 show = tag[1];
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
341 elseif tag.tag == "status" and tag[1] ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
342 status = tag[1];
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
343 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
344 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
345 if alreadyJoined == true then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
346 if show == nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
347 show = "online";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
348 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
349 ret = html.day.presence.statusChange:gsub("###TIME_STUFF###", timeStuff);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
350 if status ~= "" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
351 status = html.day.presence.statusText:gsub("###STATUS###", htmlEscape(status));
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
352 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
353 ret = ret:gsub("###SHOW###", show):gsub("###NICK###", nick):gsub("###SHOWHIDE###", showStatus):gsub("###STATUS_STUFF###", status);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
354 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
355 ret = html.day.presence.join:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
356 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
357 elseif stanza.attr.type ~= nil and stanza.attr.type == "unavailable" then
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
358
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
359 ret = html.day.presence.leave:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
360 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
361 return ret;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
362 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
363
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
364 local function parseMessageStanza(stanza, timeStuff, nick)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
365 local body, title, ret = nil, nil, "";
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
366
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
367 for _,tag in ipairs(stanza) do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
368 if tag.tag == "body" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
369 body = tag[1];
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
370 if nick ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
371 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
372 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
373 elseif tag.tag == "nick" and nick == nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
374 nick = htmlEscape(tag[1]);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
375 if body ~= nil or title ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
376 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
377 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
378 elseif tag.tag == "subject" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
379 title = tag[1];
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
380 if nick ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
381 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
382 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
383 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
384 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
385 if nick ~= nil and body ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
386 body = htmlEscape(body);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
387 local me = body:find("^/me");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
388 local template = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
389 if not me then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
390 template = html.day.message;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
391 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
392 template = html.day.messageMe;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
393 body = body:gsub("^/me ", "");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
394 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
395 ret = template:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick):gsub("###MSG###", body);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
396 elseif nick ~= nil and title ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
397 title = htmlEscape(title);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
398 ret = html.day.titleChange:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick):gsub("###TITLE###", title);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
399 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
400 return ret;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
401 end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
402
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
403 local function incrementDay(bare_day)
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
404 local year, month, day = bare_day:match("^20(%d%d)-(%d%d)-(%d%d)$");
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
405 local leapyear = false;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
406 module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year))
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
407
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
408 day = tonumber(day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
409 month = tonumber(month);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
410 year = tonumber(year);
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
411
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
412 if year%4 == 0 and year%100 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
413 if year%400 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
414 leapyear = true;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
415 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
416 leapyear = false; -- turn of the century but not a leapyear
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
417 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
418 elseif year%4 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
419 leapyear = true;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
420 end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
421
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
422 if (month == 2 and leapyear and day + 1 > 29) or
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
423 (month == 2 and not leapyear and day + 1 > 28) or
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
424 (month < 8 and month%2 == 1 and day + 1 > 31) or
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
425 (month < 8 and month%2 == 0 and day + 1 > 30) or
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
426 (month >= 8 and month%2 == 0 and day + 1 > 31) or
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
427 (month >= 8 and month%2 == 1 and day + 1 > 30)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
428 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
429 if month + 1 > 12 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
430 year = year + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
431 month = 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
432 day = 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
433 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
434 month = month + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
435 day = 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
436 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
437 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
438 day = day + 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
439 end
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
440 return strformat("20%.02d-%.02d-%.02d", year, month, day);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
441 end
179
af6143756a9e mod_muc_log_http: started new prosody theme
Thilo Cestonaro <thilo@cestona.ro>
parents: 146
diff changeset
442
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
443 local function findNextDay(bareRoomJid, bare_day)
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
444 local node, host = splitJid(bareRoomJid);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
445 local day = incrementDay(bare_day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
446 local max_trys = 7;
179
af6143756a9e mod_muc_log_http: started new prosody theme
Thilo Cestonaro <thilo@cestona.ro>
parents: 146
diff changeset
447
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
448 module:log("debug", day);
975
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
449 while(not store_exists(node, host, day)) do
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
450 max_trys = max_trys - 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
451 if max_trys == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
452 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
453 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
454 day = incrementDay(day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
455 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
456 if max_trys == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
457 return nil;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
458 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
459 return day;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
460 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
461 end
179
af6143756a9e mod_muc_log_http: started new prosody theme
Thilo Cestonaro <thilo@cestona.ro>
parents: 146
diff changeset
462
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
463 local function decrementDay(bare_day)
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
464 local year, month, day = bare_day:match("^20(%d%d)-(%d%d)-(%d%d)$");
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
465 local leapyear = false;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
466 module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year))
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
467
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
468 day = tonumber(day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
469 month = tonumber(month);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
470 year = tonumber(year);
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
471
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
472 if year%4 == 0 and year%100 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
473 if year%400 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
474 leapyear = true;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
475 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
476 leapyear = false; -- turn of the century but not a leapyear
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
477 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
478 elseif year%4 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
479 leapyear = true;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
480 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
481
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
482 if day - 1 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
483 if month - 1 == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
484 year = year - 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
485 month = 12;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
486 day = 31;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
487 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
488 month = month - 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
489 if (month == 2 and leapyear) then day = 29
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
490 elseif (month == 2 and not leapyear) then day = 28
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
491 elseif (month < 8 and month%2 == 1) or (month >= 8 and month%2 == 0) then day = 31
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
492 else day = 30
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
493 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
494 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
495 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
496 day = day - 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
497 end
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
498 return strformat("20%.02d-%.02d-%.02d", year, month, day);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
499 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
500
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
501 local function findPreviousDay(bareRoomJid, bare_day)
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
502 local node, host = splitJid(bareRoomJid);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
503 local day = decrementDay(bare_day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
504 local max_trys = 7;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
505 module:log("debug", day);
975
08628703456a mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents: 974
diff changeset
506 while(not store_exists(node, host, day)) do
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
507 max_trys = max_trys - 1;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
508 if max_trys == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
509 break;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
510 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
511 day = decrementDay(day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
512 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
513 if max_trys == 0 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
514 return nil;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
515 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
516 return day;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
517 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
518 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
519
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
520 local function parseDay(bareRoomJid, roomSubject, bare_day)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
521 local ret = "";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
522 local year;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
523 local month;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
524 local day;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
525 local tmp;
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
526 local node, host = splitJid(bareRoomJid);
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
527 local year, month, day = bare_day:match("^20(%d%d)-(%d%d)-(%d%d)$");
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
528 local previousDay = findPreviousDay(bareRoomJid, bare_day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
529 local nextDay = findNextDay(bareRoomJid, bare_day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
530 local temptime = {day=0, month=0, year=0};
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
531 local path = data_getpath(node, host, datastore);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
532 path = path:gsub("/[^/]*$", "");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
533 local calendar = ""
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
534
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
535 if tonumber(year) <= 99 then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
536 year = year + 2000;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
537 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
538
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
539 temptime.day = tonumber(day)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
540 temptime.month = tonumber(month)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
541 temptime.year = tonumber(year)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
542 calendar = createMonth(temptime.month, temptime.year, {callback=perDayCallback, path=path, room=node, webPath="../"}) or ""
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
543
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
544 if bare_day then
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
545 local data = data_load(node, host, datastore .. "/" .. bare_day:match("^20(.*)"):gsub("-", ""));
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
546 if data then
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
547 for i=1, #data, 1 do
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
548 local stanza = lom.parse(data[i]);
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
549 if stanza and stanza.attr and stanza.attr.time then
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
550 local timeStuff = html.day.time:gsub("###TIME###", stanza.attr.time):gsub("###UTC###", stanza.attr.utc or stanza.attr.time);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
551 if stanza[1] ~= nil then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
552 local nick;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
553 local tmp;
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
554
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
555 -- grep nick from "from" resource
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
556 if stanza[1].attr.from then -- presence and messages
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
557 nick = htmlEscape(stanza[1].attr.from:match("/(.+)$"));
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
558 elseif stanza[1].attr.to then -- iq
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
559 nick = htmlEscape(stanza[1].attr.to:match("/(.+)$"));
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
560 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
561
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
562 if stanza[1].tag == "presence" and nick then
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
563 tmp = parsePresenceStanza(stanza[1], timeStuff, nick);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
564 elseif stanza[1].tag == "message" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
565 tmp = parseMessageStanza(stanza[1], timeStuff, nick);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
566 elseif stanza[1].tag == "iq" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
567 tmp = parseIqStanza(stanza[1], timeStuff, nick);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
568 else
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
569 module:log("info", "unknown stanza subtag in log found. room: %s; day: %s", bareRoomJid, year .. "/" .. month .. "/" .. day);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
570 end
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
571 if tmp then
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
572 ret = ret .. tmp
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
573 tmp = nil;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
574 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
575 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
576 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
577 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
578 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
579 if ret ~= "" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
580 if nextDay then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
581 nextDay = html.day.dayLink:gsub("###DAY###", nextDay):gsub("###TEXT###", "&gt;")
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
582 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
583 if previousDay then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
584 previousDay = html.day.dayLink:gsub("###DAY###", previousDay):gsub("###TEXT###", "&lt;");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
585 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
586 ret = ret:gsub("%%", "%%%%");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
587 tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
588 tmp = tmp:gsub("###CALENDAR###", calendar);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
589 tmp = tmp:gsub("###DATE###", tostring(os_date("%A, %B %d, %Y", os_time(temptime))));
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
590 tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject));
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
591 tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or "");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
592 tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or "");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
593 tmp = tmp:gsub("###NEXT_LINK###", nextDay or "");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
594 tmp = tmp:gsub("###PREVIOUS_LINK###", previousDay or "");
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
595
393
20ef4a289d7d mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents: 392
diff changeset
596 return tmp, "Chatroom logs for "..bareRoomJid.." ("..tostring(os_date("%A, %B %d, %Y", os_time(temptime)))..")";
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
597 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
598 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
599 end
119
e6592d8305cb mod_muc_log_http: support next, previous day calculations from one month/year to the next or visa versa
Thilo Cestonaro <thilo@cestona.ro>
parents: 118
diff changeset
600
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
601 local function handle_error(code, err) return http_event("http-error", { code = code, message = err }); end
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
602 function handle_request(event)
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
603 local response = event.response;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
604 local request = event.request;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
605 local room;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
606
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
607 local node, day, more = request.url.path:match("^/"..urlBase.."/+([^/]*)/*([^/]*)/*(.*)$");
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
608 if more ~= "" then
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
609 response.status_code = 404;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
610 return response:send(handle_error(response.status_code, "Unknown URL."));
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
611 end
382
19469f3ad6d6 mod_muc_log_http: Cleaned up URL parsing.
Waqas Hussain <waqas20@gmail.com>
parents: 381
diff changeset
612 if node == "" then node = nil; end
19469f3ad6d6 mod_muc_log_http: Cleaned up URL parsing.
Waqas Hussain <waqas20@gmail.com>
parents: 381
diff changeset
613 if day == "" then day = nil; end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
614
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
615 node = urldecode(node);
119
e6592d8305cb mod_muc_log_http: support next, previous day calculations from one month/year to the next or visa versa
Thilo Cestonaro <thilo@cestona.ro>
parents: 118
diff changeset
616
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
617 if not html.doc then
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
618 response.status_code = 500;
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
619 return response:send(handle_error(response.status_code, "Muc Theme is not loaded."));
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
620 end
384
79983e658bb5 mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents: 383
diff changeset
621
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
622
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
623 if node then room = hosts[my_host].modules.muc.rooms[node.."@"..my_host]; end
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
624 if node and not room then
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
625 response.status_code = 404;
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
626 return response:send(handle_error(response.status_code, "Room doesn't exist."));
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
627 end
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
628 if room and room._data.hidden then
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
629 response.status_code = 404;
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
630 return response:send(handle_error(response.status_code, "There're no logs for this room."));
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
631 end
384
79983e658bb5 mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents: 383
diff changeset
632
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
633
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
634 if not node then -- room list for component
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
635 return response:send(createDoc(generateRoomListSiteContent(my_host)));
384
79983e658bb5 mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents: 383
diff changeset
636 elseif not day then -- room's listing
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
637 return response:send(createDoc(generateDayListSiteContentByRoom(node.."@"..my_host)));
384
79983e658bb5 mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents: 383
diff changeset
638 else
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
639 if not day:match("^20(%d%d)-(%d%d)-(%d%d)$") then
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
640 local y,m,d = day:match("^(%d%d)(%d%d)(%d%d)$");
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
641 if not y then
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
642 response.status_code = 404;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
643 return response:send(handle_error(response.status_code, "No entries for that year."));
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
644 end
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
645 response.status_code = 301;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
646 response.headers = { ["Location"] = request.url.path:match("^/"..urlBase.."/+[^/]*").."/20"..y.."-"..m.."-"..d.."/" };
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
647 return response:send();
583
a634b116c694 mod_muc_log_http: Use YYYY-MM-DD in URLs instead of the confusing YYMMDD.
Waqas Hussain <waqas20@gmail.com>
parents: 582
diff changeset
648 end
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
649
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
650 local body = createDoc(parseDay(node.."@"..my_host, room._data.subject or "", day));
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
651 if body == "" then
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
652 response.status_code = 404;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
653 return response:send(handle_error(response.status_code, "Day entry doesn't exist."));
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
654 end
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
655 return response:send(body);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
656 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
657 end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
658
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
659 local function readFile(filepath)
581
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
660 local f,err = io_open(filepath, "r");
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
661 if not f then return f,err; end
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
662 local t = f:read("*all");
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
663 f:close()
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
664 return t;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
665 end
344
2b0f2160fc61 mod_muc_log_http: Fix room name encoding/decoding (for UTF-8 room names)
Joseph Wallace <JosephWallace@letu.edu>
parents: 343
diff changeset
666
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
667 local function loadTheme(path)
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
668 for file in lfs.dir(path) do
581
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
669 if file:match("%.html$") then
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
670 module:log("debug", "opening theme file: " .. file);
581
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
671 local content,err = readFile(path .. "/" .. file);
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
672 if not content then return content,err; end
582
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
673
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
674 -- html.a.b.c = content of a_b_c.html
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
675 local tmp = html;
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
676 for idx in file:gmatch("([^_]*)_") do
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
677 tmp[idx] = tmp[idx] or {};
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
678 tmp = tmp[idx];
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
679 end
92ff305e7e32 mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents: 581
diff changeset
680 tmp[file:match("([^_]*)%.html$")] = content;
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
681 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
682 end
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
683 return true;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
684 end
348
03e1dc036a28 mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents: 344
diff changeset
685
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
686 function module.load()
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
687 config = module:get_option_table("muc_log_http_config", {});
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
688 if config.showStatus == nil then config.showStatus = true; end
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
689 if config.showJoin == nil then config.showJoin = true; end
1004
290c21a5e0ee mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
Marco Cirillo <maranda@lightwitch.org>
parents: 977
diff changeset
690 if config.urlBase and type(config.urlBase) == "string" then urlBase = config.urlBase; end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
691
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
692 theme = config.theme or "prosody";
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
693 local themePath = themesParent .. "/" .. tostring(theme);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
694 local attributes, err = lfs.attributes(themePath);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
695 if attributes == nil or attributes.mode ~= "directory" then
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
696 module:log("error", "Theme folder of theme \"".. tostring(theme) .. "\" isn't existing. expected Path: " .. themePath);
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
697 return false;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
698 end
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
699
581
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
700 local themeLoaded,err = loadTheme(themePath);
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
701 if not themeLoaded then
a9a97df60b8c mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents: 580
diff changeset
702 module:log("error", "Theme \"%s\" is missing something: %s", tostring(theme), err);
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
703 return false;
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
704 end
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
705
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
706 module:provides("http", {
972
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
707 default_path = urlBase,
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
708 route = {
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
709 ["GET /*"] = handle_request;
61b63affd402 mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents: 970
diff changeset
710 }
970
adcb751f22f3 mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 583
diff changeset
711 });
380
5ef71af77ae2 mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents: 348
diff changeset
712 end