author | Myhailo Danylenko <isbear@ukrpost.net> |
Sun, 22 Jul 2012 15:35:57 +0300 | |
changeset 122 | 9a803cc75245 |
parent 121 | 75a7d595817c |
permissions | -rw-r--r-- |
62 | 1 |
|
70 | 2 |
local lm = require 'lm' |
3 |
local vcard = require 'lm.vcard' |
|
4 |
local base64 = require 'base64' |
|
5 |
local mime = require 'mime-type' |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
6 |
|
68
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
7 |
main.command ( 'vcard-temp', |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
8 |
function ( args ) |
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
70
diff
changeset
|
9 |
local connection = main.connection () |
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
70
diff
changeset
|
10 |
if not connection then |
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
70
diff
changeset
|
11 |
print "You are not online!" |
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
70
diff
changeset
|
12 |
return |
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
70
diff
changeset
|
13 |
end |
70 | 14 |
local who |
15 |
local action = args[1] |
|
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
70
diff
changeset
|
16 |
local conn = lm.connection.bless ( connection ) |
70 | 17 |
if not action then |
18 |
who = conn:jid():gsub ( '/.*', '' ) |
|
19 |
elseif action == 'photo' then |
|
20 |
local file = args[2] |
|
21 |
if not file then |
|
22 |
print ( 'You must specify filename' ) |
|
23 |
return |
|
24 |
end |
|
25 |
who = conn:jid():gsub ( '/.*', '' ) |
|
26 |
vcard.retrieve ( conn, who, |
|
27 |
function ( form, submit, reject ) |
|
28 |
local h = io.open ( file, 'r' ) |
|
29 |
if not h then |
|
30 |
print ( 'Cannot open file ' .. file ) |
|
31 |
reject ( form, |
|
32 |
function () |
|
33 |
print ( 'Photo publication cancelled' ) |
|
34 |
end, |
|
35 |
function ( mesg ) |
|
36 |
print ( 'Photo publication cancellation error: ' .. mesg ) |
|
37 |
end ) |
|
38 |
return |
|
39 |
end |
|
40 |
local data = h:read ( '*a' ) |
|
41 |
h:close () |
|
42 |
local mtype = mime.type ( file ) |
|
43 |
local ptype = form:field ( 'PHOTO/TYPE' ) |
|
44 |
if ptype then |
|
45 |
ptype:value ( mtype ) |
|
46 |
else |
|
47 |
form:add ( 'PHOTO/TYPE', { value = mtype } ) |
|
48 |
end |
|
49 |
local pdata = form:field ( 'PHOTO/BINVAL' ) |
|
50 |
if pdata then |
|
51 |
pdata:value ( base64.encode ( data ) ) |
|
52 |
else |
|
53 |
form:add ( 'PHOTO/BINVAL', { value = base64.encode ( data ) } ) |
|
54 |
end |
|
55 |
submit ( form, |
|
56 |
function () |
|
57 |
print ( 'Photo published' ) |
|
58 |
end, |
|
59 |
function ( mesg ) |
|
60 |
print ( 'Photo publication error: ' .. mesg ) |
|
61 |
end ) |
|
62 |
end, |
|
63 |
function ( mesg ) |
|
64 |
print ( 'Vcard obtaining error: ' .. mesg ) |
|
65 |
end ) |
|
66 |
return |
|
67 |
elseif action == '.' then |
|
68 |
who = main.current_buddy () |
|
69 |
else |
|
70 |
who = action |
|
71 |
end |
|
72 |
vcard.retrieve ( conn, who, |
|
68
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
73 |
function ( form, submit, reject ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
74 |
insert_form ( form, |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
75 |
function ( form ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
76 |
submit ( form, |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
77 |
function () |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
78 |
print ( 'Vcard changed' ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
79 |
end, |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
80 |
function ( mesg ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
81 |
print ( 'Vcard changing error: ' .. mesg ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
82 |
end ) |
62 | 83 |
end, |
68
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
84 |
function ( form ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
85 |
reject ( form, |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
86 |
function () |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
87 |
print ( 'Vcard changing cancelled' ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
88 |
end, |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
89 |
function ( mesg ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
90 |
print ( 'Vcard changing cancellation error: ' .. mesg ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
91 |
end ) |
62 | 92 |
end ) |
68
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
93 |
end, |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
94 |
function ( mesg ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
95 |
print ( 'Vcard obtaining error: ' .. mesg ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
96 |
end ) |
742878c74b8e
Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
97 |
end, true, 'jid' ) |
62 | 98 |
|
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
70
diff
changeset
|
99 |
-- vim: se ts=4 sw=4: -- |