mod_muc_log_http/muc_log_http/mod_muc_log_http.lua
author Thilo Cestonaro <thilo@cestona.ro>
Tue, 08 Dec 2009 21:29:41 +0100
changeset 108 4c2b35e3d979
parent 107 0e4e000e3de9
child 115 5e657a305c88
permissions -rw-r--r--
mod_muc_log_http: corrected the merged stuff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     1
-- Copyright (C) 2009 Thilo Cestonaro
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     2
-- 
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     3
-- This project is MIT/X11 licensed. Please see the
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     4
-- COPYING file in the source package for more information.
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     5
--
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
     6
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 prosody = prosody;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     8
local tabSort = table.sort;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     9
local tonumber = _G.tonumber;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    10
local tostring = _G.tostring;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    11
local strformat = string.format;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    12
local splitJid = require "util.jid".split;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    13
local config_get = require "core.configmanager".get;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    14
local httpserver = require "net.httpserver";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    15
local datamanager = require "util.datamanager";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    16
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
    17
local datastore = "muc_log";
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
    18
local urlBase = "muc_log";
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    19
local muc_hosts = {};
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    20
local config = nil;
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
    21
local tostring = _G.tostring;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
    22
local tonumber = _G.tonumber;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
    23
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
    24
local str_format = string.format;
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
    25
local io_open = io.open;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
    26
local themesParent = (CFG_PLUGINDIR 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
    27
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    28
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
    29
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    30
--[[ LuaFileSystem 
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    31
* URL: http://www.keplerproject.org/luafilesystem/index.html
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    32
* Install: luarocks install luafilesystem
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    33
* ]]
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    34
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
    35
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    36
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    37
--[[
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    38
* Default templates for the html output.
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    39
]]--
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    40
local html = {};
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
    41
local theme = "default";
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    42
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    43
local function checkDatastorePathExists(node, host, today, create)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    44
	create = create or false;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    45
	local path = data_getpath(node, host, datastore, "dat", true);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    46
	path = path:gsub("/[^/]*$", "");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    47
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    48
	-- check existance
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    49
	local attributes, err = lfs.attributes(path);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    50
	if attributes == nil or attributes.mode ~= "directory" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    51
		module:log("warn", "muc_log folder isn't a folder: %s", path);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    52
		return false;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    53
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    54
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    55
	attributes, err = lfs.attributes(path .. "/" .. today);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    56
	if attributes == nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    57
		if create then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    58
			return lfs.mkdir(path .. "/" .. today);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    59
		else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    60
			return false;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    61
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    62
	elseif attributes.mode == "directory" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    63
		return true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    64
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    65
	return false;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    66
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    67
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    68
function createDoc(body)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    69
	if body then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    70
		return html.doc:gsub("###BODY_STUFF###", body);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    71
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    72
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    73
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    74
local function htmlEscape(t)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    75
	t = t:gsub("<", "&lt;");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    76
	t = t:gsub(">", "&gt;");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    77
	t = t:gsub("(http://[%a%d@%.:/&%?=%-_#]+)", [[<a href="%1">%1</a>]]);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    78
	t = t:gsub("\n", "<br />");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    79
	return t;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    80
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    81
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    82
function splitUrl(url)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    83
	local tmp = url:sub(string.len("/muc_log/") + 1);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    84
	local day = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    85
	local room = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    86
	local component = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    87
	local at = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    88
	local slash = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    89
	local slash2 = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    90
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    91
	slash = tmp:find("/");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    92
	if slash then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    93
	 	component = tmp:sub(1, slash - 1);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    94
		if tmp:len() > slash then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    95
			room = tmp:sub(slash + 1);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    96
			slash = room:find("/");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    97
			if slash then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    98
				tmp = room;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    99
				room = tmp:sub(1, slash - 1);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   100
				if tmp:len() > slash then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   101
					day = tmp:sub(slash + 1);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   102
					slash = day:find("/");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   103
					if slash then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   104
						day = day:sub(1, slash - 1);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   105
					end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   106
				end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   107
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   108
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   109
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   110
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   111
	return room, component, day;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   112
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   113
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   114
local function generateComponentListSiteContent()
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   115
	local components = "";
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   116
	for component,muc_host in pairs(muc_hosts or {}) do
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   117
		components = components .. html.components.bit:gsub("###COMPONENT###", component);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   118
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   119
	if components ~= "" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   120
		return html.components.body:gsub("###COMPONENTS_STUFF###", components);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   121
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   122
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   123
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   124
local function generateRoomListSiteContent(component)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   125
	local rooms = "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   126
	if prosody.hosts[component] and prosody.hosts[component].muc ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   127
		for jid, room in pairs(prosody.hosts[component].muc.rooms) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   128
			local node = splitJid(jid);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   129
			if not room._data.hidden and node then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   130
				rooms = rooms .. html.rooms.bit:gsub("###ROOM###", node):gsub("###COMPONENT###", component);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   131
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   132
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   133
		if rooms ~= "" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   134
			return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   135
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   136
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   137
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   138
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   139
-- Calendar stuff
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   140
local function getDaysForMonth(month, year)
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   141
    local daysCount = 30;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   142
    local leapyear = false;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   143
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   144
    if year%4 == 0 and year%100 == 0 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   145
        if year%400 == 0 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   146
            leapyear = true;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   147
        else
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   148
            leapyear = false; -- turn of the century but not a leapyear
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   149
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   150
    elseif year%4 == 0 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   151
        leapyear = true;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   152
    end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   153
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   154
    if month == 2 and leapyear then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   155
        daysCount = 29;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   156
    elseif month == 2 and not leapyear then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   157
        daysCount = 28;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   158
    elseif  month < 8 and month%2 == 1 or
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   159
            month >= 8 and month%2 == 0
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   160
    then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   161
        daysCount = 31;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   162
    end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   163
    return daysCount;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   164
end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   165
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   166
local function createMonth(month, year, dayCallback)
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   167
    local htmlStr = html.month.header;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   168
    local days = getDaysForMonth(month, year);
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   169
    local time = os_time{year=year, month=month, day=1};
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   170
    local dow = tostring(os_date("%a", time))
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   171
    local title = tostring(os_date("%B", time));
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   172
    local weekDays = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   173
    local weekDay = 0;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   174
    local weeks = 1;
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   175
	local logAvailableForMinimumOneDay = false;
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   176
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   177
    local weekDaysHtml = "";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   178
    for _, tmp in ipairs(weekDays) do
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   179
        weekDaysHtml = weekDaysHtml .. html.month.weekDay:gsub("###DAY###", tmp) .. "\n";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   180
    end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   181
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   182
    htmlStr = htmlStr:gsub("###TITLE###", title):gsub("###WEEKDAYS###", weekDaysHtml);
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   183
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   184
    for i = 1, 31 do
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   185
        weekDay = weekDay + 1;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   186
        if weekDay == 1 then htmlStr = htmlStr .. "<tr>\n"; end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   187
        if i == 1 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   188
            for _, tmp in ipairs(weekDays) do
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   189
                if dow ~= tmp then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   190
                    htmlStr = htmlStr .. html.month.emptyDay .. "\n";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   191
                    weekDay = weekDay + 1;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   192
                else
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   193
                    break;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   194
                end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   195
            end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   196
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   197
        if i < days + 1 then
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   198
            local tmp = tostring("<font color='#DDDDDD'>"..tostring(i).."</font>");
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   199
            if dayCallback ~= nil and dayCallback.callback ~= nil then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   200
                tmp = dayCallback.callback(dayCallback.path, i, month, year);
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   201
            end
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   202
			if tmp == nil then
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   203
            	tmp = tostring("<font color='#DDDDDD'>"..tostring(i).."</font>");
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   204
			else
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   205
				logAvailableForMinimumOneDay = true;
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   206
			end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   207
            htmlStr = htmlStr .. html.month.day:gsub("###DAY###", tmp) .. "\n";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   208
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   209
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   210
        if i >= days then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   211
            break;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   212
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   213
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   214
        if weekDay == 7 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   215
            weekDay = 0;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   216
            weeks = weeks + 1;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   217
            htmlStr = htmlStr .. "</tr>\n";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   218
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   219
    end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   220
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   221
    if weekDay + 1 < 8 or weeks < 6 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   222
        weekDay = weekDay + 1;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   223
        if weekDay > 7 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   224
            weekDay = 1;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   225
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   226
        if weekDay == 1 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   227
            weeks = weeks + 1;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   228
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   229
        for y = weeks, 6 do
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   230
            if weekDay == 1 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   231
                htmlStr = htmlStr .. "<tr>\n";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   232
            end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   233
            for i = weekDay, 7 do
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   234
                htmlStr = htmlStr .. html.month.emptyDay .. "\n";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   235
            end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   236
            weekDay = 1
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   237
            htmlStr = htmlStr .. "</tr>\n";
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   238
        end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   239
    end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   240
    htmlStr = htmlStr .. html.month.footer;
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   241
	if logAvailableForMinimumOneDay then
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   242
    	return htmlStr;
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   243
	end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   244
end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   245
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   246
local function createYear(year, dayCallback)
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   247
	local year = year;
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   248
	local tmp;
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   249
	if tonumber(year) <= 99 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   250
		year = year + 2000;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   251
	end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   252
	local htmlStr = "<div name='yearDiv' style='padding: 40px; text-align: center;'>" .. html.year.title:gsub("###YEAR###", tostring(year));
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   253
    for i=1, 12 do
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   254
		tmp = createMonth(i, year, dayCallback);
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   255
		if tmp then
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   256
        	htmlStr = htmlStr .. "<div style='float: left; padding: 5px;'>\n" .. tmp .. "</div>\n";
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   257
		end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   258
    end
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   259
	return htmlStr .. "</div><br style='clear:both;'/> \n";
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   260
end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   261
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   262
local function perDayCallback(path, day, month, year)
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   263
	local year = year;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   264
	if year > 2000 then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   265
		year = year - 2000;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   266
	end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   267
	local bareDay = str_format("%.02d%.02d%.02d", year, month, day);
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   268
	local attributes, err = lfs.attributes(path.."/"..bareDay)
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   269
	if attributes ~= nil and attributes.mode == "directory" then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   270
		local s = html.days.bit;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   271
		s = s:gsub("###BARE_DAY###", bareDay);
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   272
		s = s:gsub("###DAY###", day);
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   273
		return s;
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   274
	end
104
dc0fe152cadc mod_muc_log_http: show only months where log is actually available
Thilo Cestonaro <thilo@cestona.ro>
parents: 102
diff changeset
   275
	return;
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   276
end
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   277
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   278
local function generateDayListSiteContentByRoom(bareRoomJid)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   279
	local days = "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   280
	local arrDays = {};
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   281
	local tmp;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   282
	local node, host, resource = splitJid(bareRoomJid);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   283
	local path = data_getpath(node, host, datastore);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   284
	local room = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   285
	local attributes = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   286
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   287
	path = path:gsub("/[^/]*$", "");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   288
	attributes = lfs.attributes(path);
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   289
	if muc_hosts ~= nil and muc_hosts[host] and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bareRoomJid] ~= nil then
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   290
		room = prosody.hosts[host].muc.rooms[bareRoomJid];
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   291
		if room._data.hidden then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   292
			room = nil
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   293
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   294
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   295
	if attributes ~= nil and room ~= nil then
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   296
		local alreadyDoneYears = {};
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   297
		for file in lfs.dir(path) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   298
			local year, month, day = file:match("^(%d%d)(%d%d)(%d%d)");
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   299
			if year ~= nil and alreadyDoneYears[year] == nil then
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   300
				days = days .. createYear(year, {callback=perDayCallback, path=path});
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   301
				alreadyDoneYears[year] = true;
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   302
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   303
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   304
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   305
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   306
	if days ~= "" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   307
		tmp = html.days.body:gsub("###DAYS_STUFF###", days);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   308
		return tmp:gsub("###JID###", bareRoomJid);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   309
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   310
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   311
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   312
local function parseIqStanza(stanza, timeStuff, nick)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   313
	local text = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   314
	local victim = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   315
	if(stanza.attr.type == "set") then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   316
		for _,tag in ipairs(stanza) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   317
			if tag.tag == "query" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   318
				for _,item in ipairs(tag) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   319
					if item.tag == "item" and item.attr.nick ~= nil and tostring(item.attr.role) == 'none' then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   320
						victim = item.attr.nick;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   321
						for _,reason in ipairs(item) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   322
							if reason.tag == "reason" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   323
								text = reason[1];
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   324
								break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   325
							end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   326
						end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   327
						break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   328
					end 
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   329
				end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   330
				break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   331
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   332
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   333
		if victim ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   334
			if text ~= nil then	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   335
				text = html.day.reason:gsub("###REASON###", htmlEscape(text));
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   336
			else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   337
				text = "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   338
			end	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   339
			return html.day.kick:gsub("###TIME_STUFF###", timeStuff):gsub("###VICTIM###", victim):gsub("###REASON_STUFF###", text);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   340
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   341
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   342
	return;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   343
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   344
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   345
local function parsePresenceStanza(stanza, timeStuff, nick)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   346
	local ret = "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   347
	local showJoin = "block"
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   348
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   349
	if config and not config.showJoin then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   350
		showJoin = "none";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   351
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   352
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   353
	if stanza.attr.type == nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   354
		local showStatus = "block"
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   355
		if config and not config.showStatus then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   356
			showStatus = "none";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   357
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   358
		local show, status = nil, "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   359
		local alreadyJoined = false;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   360
		for _, tag in ipairs(stanza) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   361
			if tag.tag == "alreadyJoined" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   362
				alreadyJoined = true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   363
			elseif tag.tag == "show" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   364
				show = tag[1];
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   365
			elseif tag.tag == "status" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   366
				status = tag[1];
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   367
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   368
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   369
		if alreadyJoined == true then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   370
			if show == nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   371
				show = "online";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   372
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   373
			ret = html.day.presence.statusChange:gsub("###TIME_STUFF###", timeStuff);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   374
			if status ~= "" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   375
				status = html.day.presence.statusText:gsub("###STATUS###", htmlEscape(status));
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   376
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   377
			ret = ret:gsub("###SHOW###", show):gsub("###NICK###", nick):gsub("###SHOWHIDE###", showStatus):gsub("###STATUS_STUFF###", status);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   378
		else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   379
			ret = html.day.presence.join:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   380
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   381
	elseif stanza.attr.type ~= nil and stanza.attr.type == "unavailable" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   382
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   383
		ret = html.day.presence.leave:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   384
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   385
	return ret;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   386
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   387
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   388
local function parseMessageStanza(stanza, timeStuff, nick)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   389
	local body, title, ret = nil, nil, "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   390
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   391
	for _,tag in ipairs(stanza) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   392
		if tag.tag == "body" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   393
			body = tag[1];
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   394
			if nick ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   395
				break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   396
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   397
		elseif tag.tag == "nick" and nick == nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   398
			nick = htmlEscape(tag[1]);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   399
			if body ~= nil or title ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   400
				break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   401
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   402
		elseif tag.tag == "subject" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   403
			title = tag[1];
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   404
			if nick ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   405
				break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   406
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   407
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   408
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   409
	if nick ~= nil and body ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   410
		body = htmlEscape(body);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   411
		local me = body:find("^/me");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   412
		local template = "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   413
		if not me then			
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   414
			template = html.day.message;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   415
		else
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   416
			template = html.day.messageMe;
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   417
			body = body:gsub("^/me ", "");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   418
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   419
		ret = template:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick):gsub("###MSG###", body);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   420
	elseif nick ~= nil and title ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   421
		title = htmlEscape(title);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   422
		ret = html.day.titleChange:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick):gsub("###TITLE###", title);	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   423
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   424
	return ret;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   425
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   426
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   427
local function incrementDay(bare_day)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   428
	local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   429
	local leapyear = false;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   430
	module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year))
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   431
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   432
	day = tonumber(day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   433
	month = tonumber(month);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   434
	year = tonumber(year);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   435
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   436
	if year%4 == 0 and year%100 == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   437
		if year%400 == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   438
			leapyear = true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   439
		else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   440
			leapyear = false; -- turn of the century but not a leapyear
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   441
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   442
	elseif year%4 == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   443
		leapyear = true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   444
	end	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   445
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   446
	if (month == 2 and leapyear and day + 1 > 29) or
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   447
	   (month == 2 and not leapyear and day + 1 > 28) or
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   448
	   (month < 8 and month%2 == 1 and day + 1 > 31) or
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   449
	   (month < 8 and month%2 == 0 and day + 1 > 30) or
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   450
	   (month >= 8 and month%2 == 0 and day + 1 > 31) or
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   451
	   (month >= 8 and month%2 == 1 and day + 1 > 30)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   452
	then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   453
		if month + 1 > 12 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   454
			year = year + 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   455
		else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   456
			month = month + 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   457
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   458
	else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   459
		day = day + 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   460
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   461
	return strformat("%.02d%.02d%.02d", year, month, day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   462
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   463
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   464
local function findNextDay(bareRoomJid, bare_day)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   465
	local node, host, resource = splitJid(bareRoomJid);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   466
	local day = incrementDay(bare_day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   467
	local max_trys = 7;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   468
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   469
	module:log("debug", day);	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   470
	while(not checkDatastorePathExists(node, host, day, false)) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   471
		max_trys = max_trys - 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   472
		if max_trys == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   473
			break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   474
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   475
		day = incrementDay(day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   476
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   477
	if max_trys == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   478
		return nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   479
	else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   480
		return day;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   481
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   482
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   483
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   484
local function decrementDay(bare_day)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   485
	local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   486
	module:log("debug", tostring(day).."/"..tostring(month).."/"..tostring(year))
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   487
	day = tonumber(day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   488
	month = tonumber(month);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   489
	year = tonumber(year);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   490
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   491
	if day - 1 == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   492
		if month - 1 == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   493
			year = year - 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   494
		else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   495
			month = month - 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   496
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   497
	else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   498
		day = day - 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   499
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   500
	return strformat("%.02d%.02d%.02d", year, month, day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   501
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   502
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   503
local function findPreviousDay(bareRoomJid, bare_day)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   504
	local node, host, resource = splitJid(bareRoomJid);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   505
	local day = decrementDay(bare_day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   506
	local max_trys = 7;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   507
	module:log("debug", day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   508
	while(not checkDatastorePathExists(node, host, day, false)) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   509
		max_trys = max_trys - 1;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   510
		if max_trys == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   511
			break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   512
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   513
		day = decrementDay(day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   514
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   515
	if max_trys == 0 then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   516
		return nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   517
	else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   518
		return day;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   519
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   520
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   521
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   522
local function parseDay(bareRoomJid, roomSubject, bare_day)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   523
	local ret = "";
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   524
	local year;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   525
	local month;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   526
	local day;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   527
	local tmp;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   528
	local node, host, resource = splitJid(bareRoomJid);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   529
	local year, month, day = bare_day:match("^(%d%d)(%d%d)(%d%d)");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   530
	local previousDay = findPreviousDay(bareRoomJid, bare_day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   531
	local nextDay = findNextDay(bareRoomJid, bare_day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   532
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   533
	if bare_day ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   534
		local data = data_load(node, host, datastore .. "/" .. bare_day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   535
		if data ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   536
			for i=1, #data, 1 do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   537
				local stanza = lom.parse(data[i]);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   538
				if stanza ~= nil and stanza.attr ~= nil and stanza.attr.time ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   539
					local timeStuff = html.day.time:gsub("###TIME###", stanza.attr.time);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   540
					if stanza[1] ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   541
						local nick;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   542
						local tmp;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   543
						
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   544
						-- grep nick from "from" resource
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   545
						if stanza[1].attr.from ~= nil then -- presence and messages
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   546
							nick = htmlEscape(stanza[1].attr.from:match("/(.+)$"));
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   547
						elseif stanza[1].attr.to ~= nil then -- iq
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   548
							nick = htmlEscape(stanza[1].attr.to:match("/(.+)$"));
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   549
						end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   550
						
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   551
						if stanza[1].tag == "presence" and nick ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   552
							tmp = parsePresenceStanza(stanza[1], timeStuff, nick);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   553
						elseif stanza[1].tag == "message" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   554
							tmp = parseMessageStanza(stanza[1], timeStuff, nick);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   555
						elseif stanza[1].tag == "iq" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   556
							tmp = parseIqStanza(stanza[1], timeStuff, nick);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   557
						else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   558
							module:log("info", "unknown stanza subtag in log found. room: %s; day: %s", bareRoomJid, year .. "/" .. month .. "/" .. day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   559
						end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   560
						if tmp ~= nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   561
							ret = ret .. tmp
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   562
							tmp = nil;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   563
						end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   564
					end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   565
				end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   566
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   567
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   568
		if ret ~= "" then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   569
			if nextDay then
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   570
				nextDay = html.day.dayLink:gsub("###DAY###", nextDay):gsub("###TEXT###", "next day &gt;&gt;")
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   571
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   572
			if previousDay then
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   573
				previousDay = html.day.dayLink:gsub("###DAY###", previousDay):gsub("###TEXT###", "&lt;&lt; previous day");
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   574
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   575
			tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   576
			tmp = tmp:gsub("###YEAR###", year):gsub("###MONTH###", month):gsub("###DAY###", day);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   577
			tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject));
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   578
			tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or "");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   579
			tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or "");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   580
			tmp = tmp:gsub("###NEXT_LINK###", nextDay or "");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   581
			tmp = tmp:gsub("###PREVIOUS_LINK###", previousDay or "");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   582
			
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   583
			return tmp;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   584
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   585
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   586
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   587
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   588
function handle_request(method, body, request)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   589
	local node, host, day = splitUrl(request.url.path);
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   590
	
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   591
	if muc_hosts ~= nil then
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   592
	 	if node ~= nil and host ~= nil then
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   593
			local bare = node .. "@" .. host;
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   594
			if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil then
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   595
				if prosody.hosts[host].muc.rooms[bare] ~= nil then
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   596
					local room = prosody.hosts[host].muc.rooms[bare];
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   597
					if day == nil then
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   598
						return createDoc(generateDayListSiteContentByRoom(bare));
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   599
					else
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   600
						local subject = ""
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   601
						if room._data ~= nil and room._data.subject ~= nil then
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   602
							subject = room._data.subject;
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   603
						end
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   604
						return createDoc(parseDay(bare, subject, day));
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   605
					end
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   606
				else
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   607
					return createDoc(generateRoomListSiteContent(host));
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   608
				end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   609
			else
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   610
				return createDoc(generateComponentListSiteContent());
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   611
			end
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   612
		elseif host ~= nil then
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   613
			return createDoc(generateRoomListSiteContent(host));
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   614
		else
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   615
			return createDoc(generateComponentListSiteContent());
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   616
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   617
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   618
	return;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   619
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   620
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   621
-- Compatibility: Lua-5.1
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   622
function split(str, pat)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   623
   local t = {}  -- NOTE: use {n = 0} in Lua-5.0
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   624
   local fpat = "(.-)" .. pat
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   625
   local last_end = 1
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   626
   local s, e, cap = str:find(fpat, 1)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   627
   while s do
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   628
      if s ~= 1 or cap ~= "" then
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   629
	 table.insert(t,cap)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   630
      end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   631
      last_end = e+1
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   632
      s, e, cap = str:find(fpat, last_end)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   633
   end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   634
   if last_end <= #str then
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   635
      cap = str:sub(last_end)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   636
      table.insert(t, cap)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   637
   end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   638
   return t
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   639
end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   640
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   641
local function assign(arr, content)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   642
	local tmp = html;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   643
	local idx = nil;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   644
	for _,i in ipairs(arr) do
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   645
		if idx ~= nil then
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   646
			if tmp[idx] == nil then
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   647
				tmp[idx] = {};
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   648
			end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   649
			tmp = tmp[idx];
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   650
		end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   651
		idx = i;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   652
	end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   653
	tmp[idx] = content;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   654
end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   655
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   656
local function readFile(filepath)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   657
	local f = assert(io_open(filepath, "r"));
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   658
	local t = f:read("*all");
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   659
	f:close()
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   660
	return t;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   661
end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   662
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   663
local function loadTheme(path)
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   664
	local iter = lfs.dir(path);
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   665
    for file in iter do
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   666
        if file ~= "." and file ~= ".." then
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   667
			module:log("debug", "opening theme file: " .. file);
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   668
			local tmp = split(file:gsub("\.html$", ""), "_");
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   669
			local content = readFile(path .. "/" .. file);
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   670
			assign(tmp, content);
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   671
		end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   672
	end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   673
	return true;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   674
end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   675
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   676
function module.load()
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   677
	config = config_get("*", "core", "muc_log_http") or {};
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   678
	if config.showStatus == nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   679
		config.showStatus = true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   680
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   681
	if config.showJoin == nil then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   682
		config.showJoin = true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   683
	end
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   684
105
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   685
	theme = config.theme or "default";
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   686
	local themePath = themesParent .. "/" .. tostring(theme);
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   687
	local attributes, err = lfs.attributes(themePath);
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   688
	if attributes == nil or attributes.mode ~= "directory" then
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   689
		module:log("error", "Theme folder of theme \"".. tostring(theme) .. "\" isn't existing. expected Path: " .. themePath);
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   690
		return false;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   691
	end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   692
	
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   693
	-- module:log("debug", (require "util.serialization").serialize(html));
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   694
	if(not loadTheme(themePath)) then
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   695
		module:log("error", "Theme \"".. tostring(theme) .. "\" is missing something.");
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   696
		return false;
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   697
	end
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   698
	-- module:log("debug", (require "util.serialization").serialize(html));
cef943f0a551 mod_muc_log_http: themified ...
Thilo Cestonaro <thilo@cestona.ro>
parents: 104
diff changeset
   699
102
a10ab09096e2 mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
Thilo Cestonaro <thilo@cestona.ro>
parents: 101
diff changeset
   700
	httpserver.new_from_config({ config.http_port or true }, handle_request, { base = urlBase, ssl = false, port = 5290 });
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   701
	
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   702
	for jid, host in pairs(prosody.hosts) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   703
		if host.muc then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   704
			local enabledModules = config_get(jid, "core", "modules_enabled");
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   705
			if enabledModules then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   706
				for _,mod in ipairs(enabledModules) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   707
					if(mod == "muc_log") then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   708
						module:log("debug", "component: %s", tostring(jid));
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   709
						muc_hosts[jid] = true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   710
						break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   711
					end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   712
				end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   713
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   714
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   715
	end
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   716
	module:log("debug", "loaded mod_muc_log_http");
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   717
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   718
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   719
function module.unload()
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   720
	muc_hosts = nil;
101
e3c09996cf7b mod_muc_log_http: display available days in a calendar view
Thilo Cestonaro <thilo@cestona.ro>
parents: 94
diff changeset
   721
	module:log("debug", "unloaded mod_muc_log_http");
94
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   722
end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   723
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   724
module:add_event_hook("component-activated", function(component, config)
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   725
	if config.core and config.core.modules_enabled then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   726
		for _,mod in ipairs(config.core.modules_enabled) do
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   727
			if(mod == "muc_log") then
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   728
				module:log("debug", "component: %s", tostring(component));
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   729
				muc_hosts[component] = true;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   730
				break;
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   731
			end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   732
		end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   733
	end
941fd7d8b9b2 mod_muc_log: split into mod_muc_log and mod_muc_log_http
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   734
end);