Mercurial > prosody-modules
annotate mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 1487:5410f5c30d63
mod_privacy_lists: Correctly sort the list rules by order (thanks Flow). Fixes issue #58
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 16 Aug 2014 17:55:08 +0100 |
parents | 5107278268ae |
children | 7ebec464914e |
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(); |
116
f68a781efe81
mod_muc_log_http: support escaped urls
Thilo Cestonaro <thilo@cestona.ro>
parents:
115
diff
changeset
|
6 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
|
7 local strformat = string.format; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
8 local split_jid = require "util.jid".split; |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
9 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
|
10 local urldecode = require "net.http".urldecode; |
1033
c6d4778bc0e8
mod_muc_log_http: rectify imported function name (it's fire_event).
Marco Cirillo <maranda@lightwitch.org>
parents:
1032
diff
changeset
|
11 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
|
12 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
|
13 local datastore = "muc_log"; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
14 local url_base = "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
|
15 local config = nil; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
16 local table, tostring, tonumber = table, tostring, tonumber; |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
17 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
|
18 local str_format = string.format; |
105
cef943f0a551
mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents:
104
diff
changeset
|
19 local io_open = io.open; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
20 local themes_parent = (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
|
21 |
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
22 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
|
23 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
|
24 local html = {}; |
183
9d4fd01443eb
mod_muc_log_http: ensure to have the default being "prosody"
Thilo Cestonaro <thilo@cestona.ro>
parents:
180
diff
changeset
|
25 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
|
26 |
975
08628703456a
mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents:
974
diff
changeset
|
27 -- 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
|
28 |
975
08628703456a
mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents:
974
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
33 |
975
08628703456a
mod_muc_log_http: do some more cleanup of the code.
Marco Cirillo <maranda@lightwitch.org>
parents:
974
diff
changeset
|
34 -- 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
|
35 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
36 local function html_escape(t) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
37 if t then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
38 t = t:gsub("<", "<"); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
39 t = t:gsub(">", ">"); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
40 t = t:gsub("(http://[%a%d@%.:/&%?=%-_#%%~]+)", function(h) |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
41 h = urlunescape(h) |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
42 return "<a href='" .. h .. "'>" .. h .. "</a>"; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
43 end); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
44 t = t:gsub("\n", "<br />"); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
45 t = t:gsub("%%", "%%%%"); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
46 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
47 t = ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
48 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
49 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
|
50 end |
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
51 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
52 function create_doc(body, title) |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
53 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
|
54 body = body:gsub("%%", "%%%%"); |
20ef4a289d7d
mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents:
392
diff
changeset
|
55 return html.doc:gsub("###BODY_STUFF###", body) |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
56 :gsub("<title>muc_log</title>", "<title>"..(title and html_escape(title) or "Chatroom logs").."</title>"); |
393
20ef4a289d7d
mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents:
392
diff
changeset
|
57 end |
20ef4a289d7d
mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents:
392
diff
changeset
|
58 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
59 function urlunescape (url) |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
60 url = url:gsub("+", " ") |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
61 url = url:gsub("%%(%x%x)", function(h) return strchar(tonumber(h,16)) end) |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
62 url = url:gsub("\r\n", "\n") |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
63 return url |
393
20ef4a289d7d
mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents:
392
diff
changeset
|
64 end |
1268
854a3933cfcd
mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
Waqas Hussain <waqas20@gmail.com>
parents:
1251
diff
changeset
|
65 local function urlencode(s) |
854a3933cfcd
mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
Waqas Hussain <waqas20@gmail.com>
parents:
1251
diff
changeset
|
66 return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return ("%%%02x"):format(c:byte()); end)); |
854a3933cfcd
mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
Waqas Hussain <waqas20@gmail.com>
parents:
1251
diff
changeset
|
67 end |
393
20ef4a289d7d
mod_muc_log_http: Improved page titles a little.
Waqas Hussain <waqas20@gmail.com>
parents:
392
diff
changeset
|
68 |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
69 local function get_room_from_jid(jid) |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
70 local node, host = split_jid(jid); |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
71 local component = hosts[host]; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
72 if component then |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
73 local muc = component.modules.muc |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
74 if muc and rawget(muc,"rooms") then |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
75 -- We're running 0.9.x or 0.10 (old MUC API) |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
76 return muc.rooms[jid]; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
77 elseif muc and rawget(muc,"get_room_from_jid") then |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
78 -- We're running >0.10 (new MUC API) |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
79 return muc.get_room_from_jid(jid); |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
80 else |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
81 return |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
82 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
83 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
84 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
85 |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
86 local function get_room_list(host) |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
87 local component = hosts[host]; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
88 local list = {}; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
89 if component then |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
90 local muc = component.modules.muc |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
91 if muc and rawget(muc,"rooms") then |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
92 -- We're running 0.9.x or 0.10 (old MUC API) |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
93 for _, room in pairs(muc.rooms) do |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
94 list[room.jid] = room; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
95 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
96 return list; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
97 elseif muc and rawget(muc,"each_room") then |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
98 -- We're running >0.10 (new MUC API) |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
99 for room, _ in muc.each_room() do |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
100 list[room.jid] = room; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
101 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
102 return list; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
103 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
104 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
105 end |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
106 |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
107 local function generate_room_list(host) |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
108 local rooms; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
109 |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
110 for jid, room in pairs(get_room_list(host)) do |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
111 local node = split_jid(jid); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
112 if not room._data.hidden and room._data.logging and node then |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
113 rooms = (rooms or "") .. html.rooms.bit:gsub("###ROOM###", urlencode(node)):gsub("###COMPONENT###", host); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
114 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
115 end |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
116 |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
117 if rooms then |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
118 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", host), "Chatroom logs for "..host; |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
119 end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
120 end |
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
121 |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
122 -- Calendar stuff |
386
d54dbbfda3bb
mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents:
385
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 return 31; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
129 end |
386
d54dbbfda3bb
mod_muc_log_http: Simplified calculating day count for a month.
Waqas Hussain <waqas20@gmail.com>
parents:
385
diff
changeset
|
130 return 30; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
131 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
132 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
133 local function create_month(month, year, callback) |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
134 local html_str = 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
|
135 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
|
136 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
|
137 local dow = tostring(os_date("%a", time)) |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
138 local title = tostring(os_date("%B", time)); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
139 local week_days = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
140 local week_day = 0; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
141 local weeks = 1; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
142 local _available_for_one_day = false; |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
143 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
144 local week_days_html = ""; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
145 for _, tmp in ipairs(week_days) do |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
146 week_days_html = week_days_html .. html.month.weekDay:gsub("###DAY###", tmp) .. "\n"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
147 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
148 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
149 html_str = html_str:gsub("###TITLE###", title):gsub("###WEEKDAYS###", week_days_html); |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
150 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
151 for i = 1, 31 do |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
152 week_day = week_day + 1; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
153 if week_day == 1 then html_str = html_str .. "<tr>\n"; end |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
154 if i == 1 then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
155 for _, tmp in ipairs(week_days) do |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
156 if dow ~= tmp then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
157 html_str = html_str .. html.month.emptyDay .. "\n"; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
158 week_day = week_day + 1; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
159 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
160 break; |
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 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
163 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
164 if i < days + 1 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
165 local tmp = tostring(i); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
166 if callback and callback.callback then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
167 tmp = callback.callback(callback.path, i, month, year, callback.room, callback.webpath); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
168 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
169 if tmp == nil then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
170 tmp = tostring(i); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
171 else |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
172 _available_for_one_day = true; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
173 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
174 html_str = html_str .. html.month.day:gsub("###DAY###", tmp) .. "\n"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
175 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
176 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
177 if i >= days then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
178 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
179 end |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
180 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
181 if week_day == 7 then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
182 week_day = 0; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
183 weeks = weeks + 1; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
184 html_str = html_str .. "</tr>\n"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
185 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
186 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
187 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
188 if week_day + 1 < 8 or weeks < 6 then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
189 week_day = week_day + 1; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
190 if week_day > 7 then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
191 week_day = 1; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
192 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
193 if week_day == 1 then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
194 weeks = weeks + 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
195 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
196 for y = weeks, 6 do |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
197 if week_day == 1 then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
198 html_str = html_str .. "<tr>\n"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
199 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
200 for i = week_day, 7 do |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
201 html_str = html_str .. html.month.emptyDay .. "\n"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
202 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
203 week_day = 1 |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
204 html_str = html_str .. "</tr>\n"; |
380
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 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
207 html_str = html_str .. html.month.footer; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
208 if _available_for_one_day then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
209 return html_str; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
210 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
211 end |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
212 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
213 local function create_year(year, callback) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
214 local year = year; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
215 local tmp; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
216 if tonumber(year) <= 99 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
217 year = year + 2000; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
218 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
219 local html_str = ""; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
220 for i=1, 12 do |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
221 tmp = create_month(i, year, callback); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
222 if tmp then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
223 html_str = html_str .. "<div style='float: left; padding: 5px;'>\n" .. tmp .. "</div>\n"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
224 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
225 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
226 if html_str ~= "" then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
227 return "<div name='yearDiv' style='padding: 40px; text-align: center;'>" .. html.year.title:gsub("###YEAR###", tostring(year)) .. html_str .. "</div><br style='clear:both;'/> \n"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
228 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
229 return ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
230 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
231 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
232 local function day_callback(path, day, month, year, room, webpath) |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
233 local webpath = webpath or "" |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
234 local year = year; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
235 if year > 2000 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
236 year = year - 2000; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
237 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
238 local bare_day = 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
|
239 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
|
240 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
|
241 if attributes ~= nil and attributes.mode == "file" then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
242 local s = html.days.bit; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
243 s = s:gsub("###BARE_DAY###", webpath .. bare_day); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
244 s = s:gsub("###DAY###", day); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
245 return s; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
246 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
247 return; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
248 end |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
249 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
250 local function generate_day_room_content(bare_room_jid) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
251 local days = ""; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
252 local days_array = {}; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
253 local tmp; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
254 local node, host = split_jid(bare_room_jid); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
255 local path = data_getpath(node, host, datastore); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
256 local room = nil; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
257 local next_room = ""; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
258 local previous_room = ""; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
259 local rooms = ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
260 local attributes = nil; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
261 local since = ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
262 local to = ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
263 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
|
264 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
|
265 |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
266 if not(get_room_from_jid(bare_room_jid)) then |
579
513aa6fed9e9
mod_muc_log_http: Don't return a page on missing rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
578
diff
changeset
|
267 return; |
513aa6fed9e9
mod_muc_log_http: Don't return a page on missing rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
578
diff
changeset
|
268 end |
513aa6fed9e9
mod_muc_log_http: Don't return a page on missing rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
578
diff
changeset
|
269 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
270 path = path:gsub("/[^/]*$", ""); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
271 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
|
272 do |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
273 local found = 0; |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
274 module:log("debug", generate_room_list(host)); |
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
275 for jid, room in pairs(get_room_list(host)) do |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
276 local node = split_jid(jid) |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
277 if not room._data.hidden and room._data.logging and node then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
278 if found == 0 then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
279 previous_room = node |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
280 elseif found == 1 then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
281 next_room = node |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
282 found = -1 |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
283 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
284 if jid == bare_room_jid then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
285 found = 1 |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
286 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
287 |
1268
854a3933cfcd
mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
Waqas Hussain <waqas20@gmail.com>
parents:
1251
diff
changeset
|
288 rooms = rooms .. html.days.rooms.bit:gsub("###ROOM###", urlencode(node)); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
289 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
290 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
291 |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
292 room = get_room_from_jid(bare_room_jid); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
293 if room._data.hidden or not room._data.logging then |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
294 room = nil; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
295 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
296 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
297 if attributes and room then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
298 local already_done_years = {}; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
299 topic = room._data.subject or "(no subject)" |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
300 if topic:len() > 135 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
301 topic = topic:sub(1, topic:find(" ", 120)) .. " ..." |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
302 end |
391
99e7ef4fc7d2
mod_muc_log_http: Properly sort calendar listing.
Waqas Hussain <waqas20@gmail.com>
parents:
390
diff
changeset
|
303 local folders = {}; |
99e7ef4fc7d2
mod_muc_log_http: Properly sort calendar listing.
Waqas Hussain <waqas20@gmail.com>
parents:
390
diff
changeset
|
304 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
|
305 table.sort(folders); |
99e7ef4fc7d2
mod_muc_log_http: Properly sort calendar listing.
Waqas Hussain <waqas20@gmail.com>
parents:
390
diff
changeset
|
306 for _, folder in ipairs(folders) do |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
307 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
|
308 if year then |
369e665ae471
mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents:
391
diff
changeset
|
309 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
|
310 if since == "" then since = to; end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
311 if not already_done_years[year] then |
392
369e665ae471
mod_muc_log_http: Show proper time period in the headline.
Waqas Hussain <waqas20@gmail.com>
parents:
391
diff
changeset
|
312 module:log("debug", "creating overview for: %s", to); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
313 days = create_year(year, {callback=day_callback, path=path, room=node}) .. days; |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
314 already_done_years[year] = true; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
315 end |
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 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
319 |
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
|
320 tmp = html.days.body:gsub("###DAYS_STUFF###", days); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
321 tmp = tmp:gsub("###PREVIOUS_ROOM###", previous_room == "" and node or previous_room); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
322 tmp = tmp:gsub("###NEXT_ROOM###", next_room == "" and node or next_room); |
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
|
323 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
|
324 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
|
325 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
|
326 tmp = tmp:gsub("###TO###", to); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
327 return tmp:gsub("###JID###", bare_room_jid), "Chatroom logs for "..bare_room_jid; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
328 end |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
329 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
330 local function parse_iq(stanza, time, nick) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
331 local text = nil; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
332 local victim = nil; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
333 if(stanza.attr.type == "set") then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
334 for _,tag in ipairs(stanza) do |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
335 if tag.tag == "query" then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
336 for _,item in ipairs(tag) do |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
337 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
|
338 victim = item.attr.nick; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
339 for _,reason in ipairs(item) do |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
340 if reason.tag == "reason" then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
341 text = reason[1]; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
342 break; |
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 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
346 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
347 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
348 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
349 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
350 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
351 if victim then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
352 if text then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
353 text = html.day.reason:gsub("###REASON###", html_escape(text)); |
380
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 text = ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
356 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
357 return html.day.kick:gsub("###TIME_STUFF###", time):gsub("###VICTIM###", victim):gsub("###REASON_STUFF###", text); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
358 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
359 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
360 return; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
361 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
362 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
363 local function parse_presence(stanza, time, nick) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
364 local ret = ""; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
365 local show_join = "block" |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
366 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
367 if config and not config.show_join then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
368 show_join = "none"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
369 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
370 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
371 if stanza.attr.type == nil then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
372 local show_status = "block" |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
373 if config and not config.show_status then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
374 show_status = "none"; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
375 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
376 local show, status = nil, ""; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
377 local already_joined = false; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
378 for _, tag in ipairs(stanza) do |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
379 if tag.tag == "alreadyJoined" then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
380 already_joined = true; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
381 elseif tag.tag == "show" then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
382 show = tag[1]; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
383 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
|
384 status = tag[1]; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
385 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
386 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
387 if already_joined == true then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
388 if show == nil then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
389 show = "online"; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
390 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
391 ret = html.day.presence.statusChange:gsub("###TIME_STUFF###", time); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
392 if status ~= "" then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
393 status = html.day.presence.statusText:gsub("###STATUS###", html_escape(status)); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
394 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
395 ret = ret:gsub("###SHOW###", show):gsub("###NICK###", nick):gsub("###SHOWHIDE###", show_status):gsub("###STATUS_STUFF###", status); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
396 else |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
397 ret = html.day.presence.join:gsub("###TIME_STUFF###", time):gsub("###SHOWHIDE###", show_join):gsub("###NICK###", nick); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
398 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
399 elseif 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
|
400 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
401 ret = html.day.presence.leave:gsub("###TIME_STUFF###", time):gsub("###SHOWHIDE###", show_join):gsub("###NICK###", nick); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
402 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
403 return ret; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
404 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
405 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
406 local function parse_message(stanza, time, nick) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
407 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
|
408 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
409 for _,tag in ipairs(stanza) do |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
410 if tag.tag == "body" then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
411 body = tag[1]; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
412 if nick then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
413 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
414 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
415 elseif tag.tag == "nick" and nick == nil then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
416 nick = html_escape(tag[1]); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
417 if body or title then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
418 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
419 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
420 elseif tag.tag == "subject" then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
421 title = tag[1]; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
422 if nick then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
423 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
424 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
425 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
426 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
427 if nick and body then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
428 body = html_escape(body); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
429 local me = body:find("^/me"); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
430 local template = ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
431 if not me then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
432 template = html.day.message; |
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 template = html.day.messageMe; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
435 body = body:gsub("^/me ", ""); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
436 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
437 ret = template:gsub("###TIME_STUFF###", time):gsub("###NICK###", nick):gsub("###MSG###", body); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
438 elseif nick and title then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
439 title = html_escape(title); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
440 ret = html.day.titleChange:gsub("###TIME_STUFF###", time):gsub("###NICK###", nick):gsub("###TITLE###", title); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
441 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
442 return ret; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
443 end |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
444 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
445 local function increment_day(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
|
446 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
|
447 local leapyear = false; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
448 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
|
449 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
450 day = tonumber(day); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
451 month = tonumber(month); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
452 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
|
453 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
454 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
|
455 if year%400 == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
456 leapyear = true; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
457 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
458 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
|
459 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
460 elseif year%4 == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
461 leapyear = true; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
462 end |
101
e3c09996cf7b
mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents:
94
diff
changeset
|
463 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
464 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
|
465 (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
|
466 (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
|
467 (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
|
468 (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
|
469 (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
|
470 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
471 if month + 1 > 12 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
472 year = year + 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
473 month = 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
474 day = 1; |
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 month = month + 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
477 day = 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
478 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
479 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
480 day = day + 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
481 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
|
482 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
|
483 end |
179
af6143756a9e
mod_muc_log_http: started new prosody theme
Thilo Cestonaro <thilo@cestona.ro>
parents:
146
diff
changeset
|
484 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
485 local function find_next_day(bare_room_jid, bare_day) |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
486 local node, host = split_jid(bare_room_jid); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
487 local day = increment_day(bare_day); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
488 local max_trys = 7; |
179
af6143756a9e
mod_muc_log_http: started new prosody theme
Thilo Cestonaro <thilo@cestona.ro>
parents:
146
diff
changeset
|
489 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
490 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
|
491 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
|
492 max_trys = max_trys - 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
493 if max_trys == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
494 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
495 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
496 day = increment_day(day); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
497 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
498 if max_trys == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
499 return nil; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
500 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
501 return day; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
502 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
503 end |
179
af6143756a9e
mod_muc_log_http: started new prosody theme
Thilo Cestonaro <thilo@cestona.ro>
parents:
146
diff
changeset
|
504 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
505 local function decrement_day(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
|
506 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
|
507 local leapyear = false; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
508 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
|
509 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
510 day = tonumber(day); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
511 month = tonumber(month); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
512 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
|
513 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
514 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
|
515 if year%400 == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
516 leapyear = true; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
517 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
518 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
|
519 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
520 elseif year%4 == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
521 leapyear = true; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
522 end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
523 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
524 if day - 1 == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
525 if month - 1 == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
526 year = year - 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
527 month = 12; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
528 day = 31; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
529 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
530 month = month - 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
531 if (month == 2 and leapyear) then day = 29 |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
532 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
|
533 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
|
534 else day = 30 |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
535 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
536 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
537 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
538 day = day - 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
539 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
|
540 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
|
541 end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
542 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
543 local function find_previous_day(bare_room_jid, bare_day) |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
544 local node, host = split_jid(bare_room_jid); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
545 local day = decrement_day(bare_day); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
546 local max_trys = 7; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
547 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
|
548 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
|
549 max_trys = max_trys - 1; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
550 if max_trys == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
551 break; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
552 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
553 day = decrement_day(day); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
554 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
555 if max_trys == 0 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
556 return nil; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
557 else |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
558 return day; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
559 end |
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 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
562 local function parse_day(bare_room_jid, room_subject, bare_day) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
563 local ret = ""; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
564 local year; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
565 local month; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
566 local day; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
567 local tmp; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
568 local node, host = split_jid(bare_room_jid); |
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
|
569 local year, month, day = bare_day:match("^20(%d%d)-(%d%d)-(%d%d)$"); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
570 local previous_day = find_previous_day(bare_room_jid, bare_day); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
571 local next_day = find_next_day(bare_room_jid, bare_day); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
572 local temptime = {day=0, month=0, year=0}; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
573 local path = data_getpath(node, host, datastore); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
574 path = path:gsub("/[^/]*$", ""); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
575 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
|
576 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
577 if tonumber(year) <= 99 then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
578 year = year + 2000; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
579 end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
580 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
581 temptime.day = tonumber(day) |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
582 temptime.month = tonumber(month) |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
583 temptime.year = tonumber(year) |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
584 calendar = create_month(temptime.month, temptime.year, {callback=day_callback, 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
|
585 |
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
|
586 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
|
587 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
|
588 if data then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
589 for i=1, #data, 1 do |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
590 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
|
591 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
|
592 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
|
593 if stanza[1] ~= nil then |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
594 local nick; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
595 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
|
596 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
597 -- 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
|
598 if stanza[1].attr.from then -- presence and messages |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
599 nick = html_escape(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
|
600 elseif stanza[1].attr.to then -- iq |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
601 nick = html_escape(stanza[1].attr.to:match("/(.+)$")); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
602 end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
603 |
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
|
604 if stanza[1].tag == "presence" and nick then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
605 tmp = parse_presence(stanza[1], timeStuff, nick); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
606 elseif stanza[1].tag == "message" then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
607 tmp = parse_message(stanza[1], timeStuff, nick); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
608 elseif stanza[1].tag == "iq" then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
609 tmp = parse_iq(stanza[1], timeStuff, nick); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
610 else |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
611 module:log("info", "unknown stanza subtag in log found. room: %s; day: %s", bare_room_jid, year .. "/" .. month .. "/" .. day); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
612 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
|
613 if tmp then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
614 ret = ret .. tmp |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
615 tmp = nil; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
616 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
617 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
618 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
619 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
620 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
621 if ret ~= "" then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
622 if next_day then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
623 next_day = html.day.dayLink:gsub("###DAY###", next_day):gsub("###TEXT###", ">") |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
624 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
625 if previous_day then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
626 previous_day = html.day.dayLink:gsub("###DAY###", previous_day):gsub("###TEXT###", "<"); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
627 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
628 ret = ret:gsub("%%", "%%%%"); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
629 if config.show_presences then |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
630 tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bare_room_jid); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
631 else |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
632 tmp = html.day.bodynp:gsub("###DAY_STUFF###", ret):gsub("###JID###", bare_room_jid); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
633 end |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
634 tmp = tmp:gsub("###CALENDAR###", calendar); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
635 tmp = tmp:gsub("###DATE###", tostring(os_date("%A, %B %d, %Y", os_time(temptime)))); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
636 tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", room_subject)); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
637 tmp = tmp:gsub("###STATUS_CHECKED###", config.show_status and "checked='checked'" or ""); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
638 tmp = tmp:gsub("###JOIN_CHECKED###", config.show_join and "checked='checked'" or ""); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
639 tmp = tmp:gsub("###NEXT_LINK###", next_day or ""); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
640 tmp = tmp:gsub("###PREVIOUS_LINK###", previous_day or ""); |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
641 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
642 return tmp, "Chatroom logs for "..bare_room_jid.." ("..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
|
643 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
644 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
645 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
|
646 |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
647 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
|
648 function handle_request(event) |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
649 local response = event.response; |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
650 local request = event.request; |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
651 local room; |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
652 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
653 local node, day, more = request.url.path:match("^/"..url_base.."/+([^/]*)/*([^/]*)/*(.*)$"); |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
654 |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
655 if more ~= "" then |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
656 response.status_code = 404; |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
657 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
|
658 end |
382
19469f3ad6d6
mod_muc_log_http: Cleaned up URL parsing.
Waqas Hussain <waqas20@gmail.com>
parents:
381
diff
changeset
|
659 if node == "" then node = nil; end |
19469f3ad6d6
mod_muc_log_http: Cleaned up URL parsing.
Waqas Hussain <waqas20@gmail.com>
parents:
381
diff
changeset
|
660 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
|
661 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
662 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
|
663 |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1268
diff
changeset
|
664 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
|
665 response.status_code = 500; |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
666 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
|
667 end |
384
79983e658bb5
mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents:
383
diff
changeset
|
668 |
1450
5107278268ae
mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
1343
diff
changeset
|
669 if node then room = get_room_from_jid(node.."@"..my_host); end |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
670 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
|
671 response.status_code = 404; |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
672 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
|
673 end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
674 if room and (room._data.hidden or not room._data.logging) then |
970
adcb751f22f3
mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
583
diff
changeset
|
675 response.status_code = 404; |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
676 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
|
677 end |
384
79983e658bb5
mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents:
383
diff
changeset
|
678 |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
679 if not node then -- room list for component |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1268
diff
changeset
|
680 return response:send(create_doc(generate_room_list(my_host))); |
384
79983e658bb5
mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents:
383
diff
changeset
|
681 elseif not day then -- room's listing |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
682 return response:send(create_doc(generate_day_room_content(node.."@"..my_host))); |
384
79983e658bb5
mod_muc_log_http: Cleaned up URL handling.
Waqas Hussain <waqas20@gmail.com>
parents:
383
diff
changeset
|
683 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
|
684 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
|
685 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
|
686 if not y then |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
687 response.status_code = 404; |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
688 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
|
689 end |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
690 response.status_code = 301; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
691 response.headers = { ["Location"] = request.url.path:match("^/"..url_base.."/+[^/]*").."/20"..y.."-"..m.."-"..d.."/" }; |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
692 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
|
693 end |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
694 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
695 local body = create_doc(parse_day(node.."@"..my_host, room._data.subject or "", day)); |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
696 if body == "" then |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
697 response.status_code = 404; |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
698 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
|
699 end |
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
700 return response:send(body); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
701 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
702 end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
703 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
704 local function read_file(filepath) |
581
a9a97df60b8c
mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents:
580
diff
changeset
|
705 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
|
706 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
|
707 local t = f:read("*all"); |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
708 f:close() |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
709 return t; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
710 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
|
711 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
712 local function load_theme(path) |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
713 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
|
714 if file:match("%.html$") then |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
715 module:log("debug", "opening theme file: " .. file); |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
716 local content,err = read_file(path .. "/" .. file); |
581
a9a97df60b8c
mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents:
580
diff
changeset
|
717 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
|
718 |
92ff305e7e32
mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents:
581
diff
changeset
|
719 -- 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
|
720 local tmp = html; |
92ff305e7e32
mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents:
581
diff
changeset
|
721 for idx in file:gmatch("([^_]*)_") do |
92ff305e7e32
mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents:
581
diff
changeset
|
722 tmp[idx] = tmp[idx] or {}; |
92ff305e7e32
mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents:
581
diff
changeset
|
723 tmp = tmp[idx]; |
92ff305e7e32
mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents:
581
diff
changeset
|
724 end |
92ff305e7e32
mod_muc_log_http: Reduce theme loading code.
Waqas Hussain <waqas20@gmail.com>
parents:
581
diff
changeset
|
725 tmp[file:match("([^_]*)%.html$")] = content; |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
726 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
727 end |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
728 return true; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
729 end |
348
03e1dc036a28
mod_muc_log_http: HTML overhaul. Replacing deprecated elements and style-attributes.
Florian Zeitz <florob@babelmonkeys.de>
parents:
344
diff
changeset
|
730 |
972
61b63affd402
mod_muc_log_http: more proper 0.9 port.
Marco Cirillo <maranda@lightwitch.org>
parents:
970
diff
changeset
|
731 function module.load() |
1250
d7bbacdabb8f
mod_muc_log_http: Change config option back to what it says in the docs (Thanks Alex for noticing)
Kim Alvefur <zash@zash.se>
parents:
1106
diff
changeset
|
732 config = module:get_option("muc_log_http", {}); |
1106
a53f9989a859
mod_muc_log_http: Have same default for showing presence as mod_muc_log
Kim Alvefur <zash@zash.se>
parents:
1033
diff
changeset
|
733 if module:get_option_boolean("muc_log_presences", true) then config.show_presences = true end |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
734 if config.show_status == nil then config.show_status = true; end |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
735 if config.show_join == nil then config.show_join = true; end |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
736 if config.url_base and type(config.url_base) == "string" then url_base = config.url_base; end |
94
941fd7d8b9b2
mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
737 |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
738 theme = config.theme or "prosody"; |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
739 local theme_path = themes_parent .. "/" .. tostring(theme); |
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
740 local attributes, err = lfs.attributes(theme_path); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
741 if attributes == nil or attributes.mode ~= "directory" then |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
742 module:log("error", "Theme folder of theme \"".. tostring(theme) .. "\" isn't existing. expected Path: " .. theme_path); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
743 return false; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
744 end |
105
cef943f0a551
mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents:
104
diff
changeset
|
745 |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
746 local themeLoaded,err = load_theme(theme_path); |
581
a9a97df60b8c
mod_muc_log_http: Improved theme loading, and better error reporting.
Waqas Hussain <waqas20@gmail.com>
parents:
580
diff
changeset
|
747 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
|
748 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
|
749 return false; |
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
750 end |
105
cef943f0a551
mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents:
104
diff
changeset
|
751 |
970
adcb751f22f3
mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
583
diff
changeset
|
752 module:provides("http", { |
1032
b69e5d63a4fe
mod_muc_log, mod_muc_log_http: backport changes from Metronome.
Marco Cirillo <maranda@lightwitch.org>
parents:
1021
diff
changeset
|
753 default_path = url_base, |
1251
280adf09ae12
mod_muc_log_http: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
1250
diff
changeset
|
754 route = { |
280adf09ae12
mod_muc_log_http: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
1250
diff
changeset
|
755 ["GET /*"] = handle_request; |
280adf09ae12
mod_muc_log_http: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
1250
diff
changeset
|
756 } |
970
adcb751f22f3
mod_muc_log_http: Adapt to prosody 0.9 changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
583
diff
changeset
|
757 }); |
380
5ef71af77ae2
mod_muc_log_http: Spaces -> Tabs.
Waqas Hussain <waqas20@gmail.com>
parents:
348
diff
changeset
|
758 end |