local st = require "util.stanza"; local datetime = require"util.datetime"; local jid_split = require"util.jid".split; local nodeprep = require"util.encodings".stringprep.nodeprep; local uuid = require"util.uuid".generate; local it = require"util.iterators"; local gettime = require"socket".gettime; local url = require"socket.url"; local xml_escape = st.xml_escape; local t_concat = table.concat; local archive = module:open_store("muc_log", "archive"); -- Support both old and new MUC code local mod_muc = module:depends"muc"; local rooms = rawget(mod_muc, "rooms"); local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end; local new_muc = not rooms; if new_muc then rooms = module:shared"muc/rooms"; end local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or function (jid) return rooms[jid]; end local function get_room(name) local jid = name .. '@' .. module.host; return get_room_from_jid(jid); end module:depends"http"; local function render(template, values) --[[ DOC {name} is substituted for values["name"] and is XML escaped {name!} is substituted without XML escaping {name?} is optional and is replaced with an empty string if no value exists {name# sub-template } renders a sub-template using an array of values ]] return (template:gsub("%b{}", function (block) local name, opt, e = block:sub(2, -2):match("([%a_][%w_]*)(%p?)()"); local value = values[name]; if opt == '#' then if not value or not value[1] then return ""; end local out, subtpl = {}, block:sub(e+1, -2); for i=1, #value do out[i] = render(subtpl, value[i]); end return t_concat(out); end if value ~= nil then if type(value) ~= "string" then value = tostring(value); end if opt ~= '!' then return xml_escape(value); end return value; elseif opt == '?' then return block:sub(e+1, -2); end end)); end -- TODO Move template into a file local template = [=[