Merge 0.9->0.10
[prosody.git] / util / dataforms.lua
index 52924841a0dc4fcc98907ed2eb96f9891c1cdbfe..b2988ae7e5a99df56d6c86d80bcf024086f31cbd 100644 (file)
@@ -1,7 +1,7 @@
 -- Prosody IM
 -- Copyright (C) 2008-2010 Matthew Wild
 -- Copyright (C) 2008-2010 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
@@ -38,7 +38,7 @@ function form_t.form(layout, data, formtype)
                form:tag("field", { type = field_type, var = field.name, label = field.label });
 
                local value = (data and data[field.name]) or field.value;
-               
+
                if value then
                        -- Add value, depending on type
                        if field_type == "hidden" then
@@ -93,11 +93,20 @@ function form_t.form(layout, data, formtype)
                                end
                        end
                end
-               
+
+               local media = field.media;
+               if media then
+                       form:tag("media", { xmlns = "urn:xmpp:media-element", height = media.height, width = media.width });
+                       for _, val in ipairs(media) do
+                               form:tag("uri", { type = val.type }):text(val.uri):up()
+                       end
+                       form:up();
+               end
+
                if field.required then
                        form:tag("required"):up();
                end
-               
+
                -- Jump back up to list of fields
                form:up();
        end
@@ -112,7 +121,7 @@ function form_t.data(layout, stanza)
 
        for _, field in ipairs(layout) do
                local tag;
-               for field_tag in stanza:childtags() do
+               for field_tag in stanza:childtags("field") do
                        if field.name == field_tag.attr.var then
                                tag = field_tag;
                                break;