Mercurial > prosody-modules
comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 393:20ef4a289d7d
mod_muc_log_http: Improved page titles a little.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 02:21:40 +0500 |
parents | 369e665ae471 |
children | 1a575bcbc843 |
comparison
equal
deleted
inserted
replaced
392:369e665ae471 | 393:20ef4a289d7d |
---|---|
67 return true; | 67 return true; |
68 end | 68 end |
69 return false; | 69 return false; |
70 end | 70 end |
71 | 71 |
72 function createDoc(body) | |
73 assert(body, "<nil> HTTP response"); | |
74 body = body:gsub("%%", "%%%%"); | |
75 return html.doc:gsub("###BODY_STUFF###", body); | |
76 end | |
77 | |
78 function urlunescape (escapedUrl) | |
79 escapedUrl = escapedUrl:gsub("+", " ") | |
80 escapedUrl = escapedUrl:gsub("%%(%x%x)", function(h) return strchar(tonumber(h,16)) end) | |
81 escapedUrl = escapedUrl:gsub("\r\n", "\n") | |
82 return escapedUrl | |
83 end | |
84 | |
85 local function htmlEscape(t) | 72 local function htmlEscape(t) |
86 if t then | 73 if t then |
87 t = t:gsub("<", "<"); | 74 t = t:gsub("<", "<"); |
88 t = t:gsub(">", ">"); | 75 t = t:gsub(">", ">"); |
89 t = t:gsub("(http://[%a%d@%.:/&%?=%-_#%%~]+)", function(h) | 76 t = t:gsub("(http://[%a%d@%.:/&%?=%-_#%%~]+)", function(h) |
96 t = ""; | 83 t = ""; |
97 end | 84 end |
98 return t; | 85 return t; |
99 end | 86 end |
100 | 87 |
88 function createDoc(body, title) | |
89 assert(body, "<nil> HTTP response"); | |
90 body = body:gsub("%%", "%%%%"); | |
91 return html.doc:gsub("###BODY_STUFF###", body) | |
92 :gsub("<title>muc_log</title>", "<title>"..(title and htmlEscape(title) or "Chatroom logs").."</title>"); | |
93 end | |
94 | |
95 function urlunescape (escapedUrl) | |
96 escapedUrl = escapedUrl:gsub("+", " ") | |
97 escapedUrl = escapedUrl:gsub("%%(%x%x)", function(h) return strchar(tonumber(h,16)) end) | |
98 escapedUrl = escapedUrl:gsub("\r\n", "\n") | |
99 return escapedUrl | |
100 end | |
101 | |
101 local function generateComponentListSiteContent() | 102 local function generateComponentListSiteContent() |
102 local components = ""; | 103 local components = ""; |
103 for component,host in pairs(hosts) do | 104 for component,host in pairs(hosts) do |
104 if host.modules.muc and host.modules.muc_log then | 105 if host.modules.muc and host.modules.muc_log then |
105 components = components .. html.components.bit:gsub("###COMPONENT###", component); | 106 components = components .. html.components.bit:gsub("###COMPONENT###", component); |
106 end | 107 end |
107 end | 108 end |
108 return html.components.body:gsub("###COMPONENTS_STUFF###", components); | 109 return (html.components.body:gsub("###COMPONENTS_STUFF###", components)); |
109 end | 110 end |
110 | 111 |
111 local function generateRoomListSiteContent(component) | 112 local function generateRoomListSiteContent(component) |
112 local rooms = ""; | 113 local rooms = ""; |
113 if prosody.hosts[component] and prosody.hosts[component].muc ~= nil then | 114 if prosody.hosts[component] and prosody.hosts[component].muc ~= nil then |
115 local node = splitJid(jid); | 116 local node = splitJid(jid); |
116 if not room._data.hidden and node then | 117 if not room._data.hidden and node then |
117 rooms = rooms .. html.rooms.bit:gsub("###ROOM###", node):gsub("###COMPONENT###", component); | 118 rooms = rooms .. html.rooms.bit:gsub("###ROOM###", node):gsub("###COMPONENT###", component); |
118 end | 119 end |
119 end | 120 end |
120 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component); | 121 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component), "Chatroom logs for "..component; |
121 end | 122 end |
122 end | 123 end |
123 | 124 |
124 -- Calendar stuff | 125 -- Calendar stuff |
125 local function get_days_for_month(month, year) | 126 local function get_days_for_month(month, year) |
318 tmp = tmp:gsub("###NEXT_ROOM###", nextRoom == "" and node or nextRoom); | 319 tmp = tmp:gsub("###NEXT_ROOM###", nextRoom == "" and node or nextRoom); |
319 tmp = tmp:gsub("###ROOMS###", rooms); | 320 tmp = tmp:gsub("###ROOMS###", rooms); |
320 tmp = tmp:gsub("###ROOMTOPIC###", topic); | 321 tmp = tmp:gsub("###ROOMTOPIC###", topic); |
321 tmp = tmp:gsub("###SINCE###", since); | 322 tmp = tmp:gsub("###SINCE###", since); |
322 tmp = tmp:gsub("###TO###", to); | 323 tmp = tmp:gsub("###TO###", to); |
323 return tmp:gsub("###JID###", bareRoomJid); | 324 return tmp:gsub("###JID###", bareRoomJid), "Chatroom logs for "..bareRoomJid; |
324 end | 325 end |
325 | 326 |
326 local function parseIqStanza(stanza, timeStuff, nick) | 327 local function parseIqStanza(stanza, timeStuff, nick) |
327 local text = nil; | 328 local text = nil; |
328 local victim = nil; | 329 local victim = nil; |
629 tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or ""); | 630 tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or ""); |
630 tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or ""); | 631 tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or ""); |
631 tmp = tmp:gsub("###NEXT_LINK###", nextDay or ""); | 632 tmp = tmp:gsub("###NEXT_LINK###", nextDay or ""); |
632 tmp = tmp:gsub("###PREVIOUS_LINK###", previousDay or ""); | 633 tmp = tmp:gsub("###PREVIOUS_LINK###", previousDay or ""); |
633 | 634 |
634 return tmp; | 635 return tmp, "Chatroom logs for "..bareRoomJid.." ("..tostring(os_date("%A, %B %d, %Y", os_time(temptime)))..")"; |
635 end | 636 end |
636 end | 637 end |
637 end | 638 end |
638 | 639 |
639 function handle_request(method, body, request) | 640 function handle_request(method, body, request) |