comparison mod_ogp/mod_ogp.lua @ 4255:38da10e4b593

mod_ogp: Update parsing logic to catch more cases
author Seve Ferrer <seve@delape.net>
date Wed, 18 Nov 2020 13:48:07 +0100
parents a4e182d7ff0a
children dbfda7f5522d
comparison
equal deleted inserted replaced
4254:a4e182d7ff0a 4255:38da10e4b593
28 local to = room.jid 28 local to = room.jid
29 local from = room and room.jid or module.host 29 local from = room and room.jid or module.host
30 local fastening = st.message({to = to, from = from}):tag("apply-to", {xmlns = "urn:xmpp:fasten:0", id = origin_id}) 30 local fastening = st.message({to = to, from = from}):tag("apply-to", {xmlns = "urn:xmpp:fasten:0", id = origin_id})
31 local found_metadata = false 31 local found_metadata = false
32 local message_body = "" 32 local message_body = ""
33 for property, content in response_body:gmatch(ogp_pattern) do 33
34 module:log("info", property .. "\t" .. content) 34 local meta_pattern = [[<meta (.-)/?>]]
35 fastening:tag( 35 for match in response_body:gmatch(meta_pattern) do
36 "meta", 36 local property = match:match([[property=%s*["']?(og:.-)["']?%s]])
37 { 37 if not property then
38 xmlns = "http://www.w3.org/1999/xhtml", 38 property = match:match([[property=["']?(og:.-)["']$]])
39 property = property, 39 end
40 content = content 40
41 } 41 local content = match:match([[content=%s*["'](.-)["']%s]])
42 ):up() 42 if not content then
43 found_metadata = true 43 content = match:match([[content=["']?(.-)["']$]])
44 message_body = message_body .. property .. "\t" .. content .. "\n" 44 end
45 if not content then
46 content = match:match([[content=(.-) property]])
47 end
48 if not content then
49 content = match:match([[content=(.-)$]])
50 end
51
52 if property and content then
53 module:log("info", property .. "\t" .. content)
54 fastening:tag(
55 "meta",
56 {
57 xmlns = "http://www.w3.org/1999/xhtml",
58 property = property,
59 content = content
60 }
61 ):up()
62 found_metadata = true
63 message_body = message_body .. property .. "\t" .. content .. "\n"
64 end
45 end 65 end
46 for content, property in response_body:gmatch(ogp_pattern2) do 66
47 module:log("info", property .. "\t" .. content)
48 fastening:tag(
49 "meta",
50 {
51 xmlns = "http://www.w3.org/1999/xhtml",
52 property = property,
53 content = content
54 }
55 ):up()
56 found_metadata = true
57 message_body = message_body .. property .. "\t" .. content .. "\n"
58 end
59 67
60 if found_metadata then 68 if found_metadata then
61 mod_muc.get_room_from_jid(room.jid):broadcast_message(fastening) 69 mod_muc.get_room_from_jid(room.jid):broadcast_message(fastening)
62 end 70 end
63 module:log("info", tostring(fastening)) 71 module:log("info", tostring(fastening))