comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 974:224e3745c1b3

mod_muc_log_http: use datamanager's encoding function to encode room names.
author Marco Cirillo <maranda@lightwitch.org>
date Sun, 07 Apr 2013 19:03:55 +0200
parents 1db6d5028b3d
children 08628703456a
comparison
equal deleted inserted replaced
973:1db6d5028b3d 974:224e3745c1b3
7 local tostring = _G.tostring; 7 local tostring = _G.tostring;
8 local strchar = string.char; 8 local strchar = string.char;
9 local strformat = string.format; 9 local strformat = string.format;
10 local splitJid = require "util.jid".split; 10 local splitJid = require "util.jid".split;
11 local config_get = require "core.configmanager".get; 11 local config_get = require "core.configmanager".get;
12 local urlencode = require "net.http".urlencode;
13 local urldecode = require "net.http".urldecode; 12 local urldecode = require "net.http".urldecode;
14 local http_event = require "net.http.server".fire_event; 13 local http_event = require "net.http.server".fire_event;
15 local data_load, data_getpath = datamanager.load, datamanager.getpath; 14 local data_load, data_getpath = datamanager.load, datamanager.getpath;
16 local datastore = "muc_log"; 15 local datastore = "muc_log";
17 local urlBase = "muc_log"; 16 local urlBase = "muc_log";
26 local lom = require "lxp.lom"; 25 local lom = require "lxp.lom";
27 local lfs = require "lfs"; 26 local lfs = require "lfs";
28 local html = {}; 27 local html = {};
29 local theme; 28 local theme;
30 29
30 -- encoding function
31 local p_encode = datamanager.path_encode;
32
31 local function checkDatastorePathExists(node, host, today, create) 33 local function checkDatastorePathExists(node, host, today, create)
32 create = create or false; 34 create = create or false;
33 local path = data_getpath(node, host, datastore, "dat", true); 35 local path = data_getpath(node, host, datastore, "dat", true);
34 path = path:gsub("/[^/]*$", ""); 36 path = path:gsub("/[^/]*$", "");
35 37
211 local year = year; 213 local year = year;
212 if year > 2000 then 214 if year > 2000 then
213 year = year - 2000; 215 year = year - 2000;
214 end 216 end
215 local bareDay = str_format("20%.02d-%.02d-%.02d", year, month, day); 217 local bareDay = str_format("20%.02d-%.02d-%.02d", year, month, day);
216 room = urlencode(room); 218 room = p_encode(room);
217 local attributes, err = lfs.attributes(path.."/"..str_format("%.02d%.02d%.02d", year, month, day).."/"..room..".dat") 219 local attributes, err = lfs.attributes(path.."/"..str_format("%.02d%.02d%.02d", year, month, day).."/"..room..".dat")
218 if attributes ~= nil and attributes.mode == "file" then 220 if attributes ~= nil and attributes.mode == "file" then
219 local s = html.days.bit; 221 local s = html.days.bit;
220 s = s:gsub("###BARE_DAY###", webPath .. bareDay); 222 s = s:gsub("###BARE_DAY###", webPath .. bareDay);
221 s = s:gsub("###DAY###", day); 223 s = s:gsub("###DAY###", day);