forked from willthames/photodeck.lrdevplugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhotoDeckAPIXSLT.lua
247 lines (225 loc) · 7.28 KB
/
PhotoDeckAPIXSLT.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
local LrXml = import 'LrXml'
local logger = import 'LrLogger'( 'PhotoDeckPublishLightroomPlugin' )
logger:enable('logfile')
local log_trace = logger:quick('trace')
local xsltheader = [====[
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/reply/*"/>
]====]
local xsltfooter = [====[
</xsl:stylesheet>
]====]
local PhotoDeckAPIXSLT = {}
PhotoDeckAPIXSLT.error = xsltheader .. [=====[
<xsl:template match='/reply'>
local t = {
error = [====[<xsl:value-of select='error'/>]====],
authmethod = [====[<xsl:value-of select='auth-method'/>]====]
}
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.ping = xsltheader .. [=====[
<xsl:template match='/reply'>
return [====[<xsl:value-of select='message'/>]====]
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.user = xsltheader .. [=====[
<xsl:template match='/reply/user'>
local t = {
firstname = [====[<xsl:value-of select='firstname'/>]====],
lastname = [====[<xsl:value-of select='lastname'/>]====],
email = "<xsl:value-of select='email'/>",
}
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.websites = xsltheader .. [=====[
<xsl:template match='/reply/websites'>
local t = {}
<xsl:for-each select='website'>
t["<xsl:value-of select='urlname'/>"] = {
hostname = "<xsl:value-of select='hostname'/>",
homeurl = "<xsl:value-of select='home-url'/>",
title = [====[<xsl:value-of select='title'/>]====],
uuid = "<xsl:value-of select='uuid'/>",
rootgalleryuuid = "<xsl:value-of select='root-gallery-uuid'/>",
}
</xsl:for-each>
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.artists = xsltheader .. [=====[
<xsl:template match='/reply/artists'>
local t = {}
<xsl:for-each select='artist'>
t["<xsl:value-of select='uuid'/>"] = {
name = "<xsl:value-of select='name'/>",
}
</xsl:for-each>
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.galleries = xsltheader .. [=====[
<xsl:template match='/reply/galleries'>
LrDate = import 'LrDate'
local PhotoDeckUtils = require 'PhotoDeckUtils'
local t = {}
<xsl:for-each select='gallery'>
t["<xsl:value-of select='uuid'/>"] = {
fullurlpath = "<xsl:value-of select='full-url-path'/>",
name = [====[<xsl:value-of select='name'/>]====],
uuid = "<xsl:value-of select='uuid'/>",
description = [====[<xsl:value-of select='description'/>]====],
urlpath = "<xsl:value-of select='url-path'/>",
parentuuid = "<xsl:value-of select='parent-uuid'/>",
publishedat = PhotoDeckUtils.XMLDateTimeToCoca("<xsl:value-of select='published-at'/>"),
mediascount = "<xsl:value-of select='medias-count'/>",
displaystyle = "<xsl:value-of select='gallery-display-style-uuid'/>",
}
</xsl:for-each>
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.gallery = xsltheader .. [=====[
<xsl:template match='/reply/gallery'>
LrDate = import 'LrDate'
local PhotoDeckUtils = require 'PhotoDeckUtils'
local t = {
fullurlpath = "<xsl:value-of select='full-url-path'/>",
name = [====[<xsl:value-of select='name'/>]====],
uuid = "<xsl:value-of select='uuid'/>",
description = [====[<xsl:value-of select='description'/>]====],
urlpath = "<xsl:value-of select='url-path'/>",
parentuuid = "<xsl:value-of select='parent-uuid'/>",
publishedat = PhotoDeckUtils.XMLDateTimeToCoca("<xsl:value-of select='published-at'/>"),
displaystyle = "<xsl:value-of select='gallery-display-style-uuid'/>",
}
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.media = xsltheader .. [=====[
<xsl:template match='/reply/media'>
local t = {
uuid = "<xsl:value-of select='uuid'/>",
<xsl:if test="file-name">
filename = [====[<xsl:value-of select='file-name'/>]====],
</xsl:if>
<xsl:if test="title">
title = [====[<xsl:value-of select='title'/>]====],
</xsl:if>
<xsl:if test="file-name">
description = [====[<xsl:value-of select='description'/>]====],
</xsl:if>
<xsl:if test="keywords">
<xsl:apply-templates select='keywords'/>
</xsl:if>
<xsl:if test="galleries">
<xsl:apply-templates select='galleries'/>
</xsl:if>
}
<xsl:if test="upload-location">
t.uploadlocation = "<xsl:value-of select='upload-location'/>"
</xsl:if>
<xsl:if test="upload-url">
t.uploadurl = "<xsl:value-of select='upload-url'/>"
</xsl:if>
<xsl:if test="upload-method">
t.uploadmethod = "<xsl:value-of select='upload-method'/>"
</xsl:if>
<xsl:if test="upload-file-param">
t.uploadfileparam = "<xsl:value-of select='upload-file-param'/>"
</xsl:if>
<xsl:if test="upload-params">
t.uploadparams = {}
<xsl:for-each select='upload-params/*'>
t.uploadparams["<xsl:value-of select='name()'/>"] = [====[<xsl:value-of select='.'/>]====]
</xsl:for-each>
</xsl:if>
return t
</xsl:template>
<xsl:template match='galleries'>
galleries = {
<xsl:for-each select='gallery'>
"<xsl:value-of select='uuid'/>",
</xsl:for-each>
},
</xsl:template>
<xsl:template match='keywords'>
keywords = {
<xsl:for-each select='keyword'>
[====[<xsl:value-of select='.'/>]====],
</xsl:for-each>
},
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.mediasInGallery = xsltheader .. [=====[
<xsl:template match='/reply/gallery/*'/>
<xsl:template match='/reply/gallery/medias'>
local t = {
<xsl:for-each select='media'>
"<xsl:value-of select='uuid'/>",
</xsl:for-each>
}
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.subGalleriesInGallery = xsltheader .. [=====[
<xsl:template match='/reply/galleries'>
local t = {}
<xsl:for-each select='gallery'>
t["<xsl:value-of select='uuid'/>"] = {
name = [====[<xsl:value-of select='name'/>]====],
parentuuid = "<xsl:value-of select='parent-uuid'/>",
subgalleriescount = "<xsl:value-of select='subgalleries-count'/>",
page = "<xsl:value-of select='page'/>",
totalpages = "<xsl:value-of select='total-pages'/>"
}
</xsl:for-each>
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.totalPages = xsltheader .. [=====[
<xsl:template match='/reply'>
return "<xsl:value-of select='total-pages'/>"
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.uploadStopWithError = xsltheader .. [=====[
<xsl:template match='/reply'>
return "<xsl:value-of select='stop-with-error'/>"
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.galleryDisplayStyles = xsltheader .. [=====[
<xsl:template match='/reply/gallery-display-styles'>
local t = {}
<xsl:for-each select='gallery-display-style'>
t["<xsl:value-of select='uuid'/>"] = {
uuid = "<xsl:value-of select='uuid'/>",
name = [====[<xsl:value-of select='name'/>]====],
}
</xsl:for-each>
return t
</xsl:template>
]=====] .. xsltfooter
PhotoDeckAPIXSLT.transform = function(xmlstring, xslt)
if xmlstring and string.sub(xmlstring, 1, 5) == '<?xml' then
-- prevent LUA code injection
local _
xmlstring, _ = string.gsub(xmlstring, '%[====%[', '')
xmlstring, _ = string.gsub(xmlstring, '%]====%]', '')
-- parse & load
--log_trace("XML: " .. xmlstring)
local xml = LrXml.parseXml(xmlstring)
local luastring = xml:transform(xslt)
--log_trace("LUA: " .. luastring)
if luastring ~= '' then
local f = assert(loadstring(luastring))
return f()
else
log_trace(xmlstring)
end
end
end
return PhotoDeckAPIXSLT