@@ -43,25 +43,7 @@ public function writeDefaultsToJSINFO(Event $event, $param)
43
43
{
44
44
global $ JSINFO ;
45
45
46
- $ options = new Options ();
47
- $ defaults = [
48
- 'thumbnailsize ' => $ options ->thumbnailWidth . 'x ' . $ options ->thumbnailHeight ,
49
- 'imagesize ' => $ options ->lightboxWidth . 'X ' . $ options ->lightboxHeight ,
50
- 'cache ' => $ options ->cache ,
51
- 'filter ' => $ options ->filter ,
52
- 'showname ' => $ options ->showname ,
53
- 'showtitle ' => $ options ->showtitle ,
54
- 'crop ' => $ options ->crop ,
55
- 'direct ' => $ options ->direct ,
56
- 'reverse ' => $ options ->reverse ,
57
- 'recursive ' => $ options ->recursive ,
58
- 'align ' => $ options ->align ,
59
- 'cols ' => $ options ->columns ,
60
- 'limit ' => $ options ->limit ,
61
- 'offset ' => $ options ->offset ,
62
- 'paginate ' => $ options ->paginate ,
63
- 'sort ' => $ options ->sort ,
64
- ];
46
+ $ defaults = $ this ->getDefaults ();
65
47
66
48
if (!isset ($ JSINFO ['plugins ' ])) {
67
49
$ JSINFO ['plugins ' ] = [];
@@ -88,22 +70,24 @@ public function writeDefaultsToJSINFO(Event $event, $param)
88
70
*/
89
71
public function renderFromInstructions (Event $ event , $ param )
90
72
{
91
- if ($ event ->data ['name ' ] !== 'gallery ' ) {
73
+ if ($ event ->data ['name ' ] !== 'gallery_main ' ) {
92
74
return ;
93
75
}
94
76
$ event ->preventDefault ();
95
77
$ event ->stopPropagation ();
96
78
97
79
$ node = new Node ('dwplugin_gallery ' );
98
- // FIXME we may have to parse the namespace from the original syntax ?
99
80
$ data = $ event ->data ['data ' ];
100
- $ ns = $ data ['ns ' ];
81
+ // FIXME source can be something other than namespace
82
+ [$ ns , $ options ] = $ data ;
101
83
102
84
if (cleanID ($ ns ) === $ ns ) {
103
85
$ ns = ': ' . $ ns ;
104
86
}
105
87
$ node ->attr ('namespace ' , $ ns );
106
- foreach ($ data as $ name => $ value ) {
88
+
89
+ $ attrs = $ this ->optionsToAttrs ($ options );
90
+ foreach ($ attrs as $ name => $ value ) {
107
91
$ node ->attr ($ name , $ value );
108
92
}
109
93
$ event ->data ['renderer ' ]->nodestack ->add ($ node );
@@ -156,4 +140,56 @@ public function renderAttributesToHTML(Event $event, $param)
156
140
$ html = p_render ('xhtml ' , p_get_instructions ($ syntax ), $ info );
157
141
echo $ html ;
158
142
}
143
+
144
+ /**
145
+ * Get default node attributes from gallery Options object
146
+ *
147
+ * @return array
148
+ */
149
+ public function getDefaults (): array
150
+ {
151
+ $ options = new Options ();
152
+
153
+ return [
154
+ 'thumbnailsize ' => $ options ->thumbnailWidth . 'x ' . $ options ->thumbnailHeight ,
155
+ 'imagesize ' => $ options ->lightboxWidth . 'X ' . $ options ->lightboxHeight ,
156
+ 'cache ' => $ options ->cache ,
157
+ 'filter ' => $ options ->filter ,
158
+ 'showname ' => $ options ->showname ,
159
+ 'showtitle ' => $ options ->showtitle ,
160
+ 'crop ' => $ options ->crop ,
161
+ 'direct ' => $ options ->direct ,
162
+ 'reverse ' => $ options ->reverse ,
163
+ 'recursive ' => $ options ->recursive ,
164
+ 'align ' => $ options ->align ,
165
+ 'cols ' => $ options ->columns ,
166
+ 'limit ' => $ options ->limit ,
167
+ 'offset ' => $ options ->offset ,
168
+ 'paginate ' => $ options ->paginate ,
169
+ 'sort ' => $ options ->sort ,
170
+ ];
171
+ }
172
+
173
+ /**
174
+ * Convert gallery options to node attributes
175
+ *
176
+ * @param Options $options
177
+ * @return array
178
+ */
179
+ protected function optionsToAttrs ($ options )
180
+ {
181
+ $ attrs = (array )$ options ;
182
+
183
+ $ attrs ['thumbnailsize ' ] = $ options ->thumbnailWidth . 'x ' . $ options ->thumbnailHeight ;
184
+ $ attrs ['imagesize ' ] = $ options ->lightboxWidth . 'X ' . $ options ->lightboxHeight ;
185
+ $ attrs ['cols ' ] = $ options ->columns ;
186
+
187
+ unset($ attrs ['thumbnailWidth ' ]);
188
+ unset($ attrs ['thumbnailHeight ' ]);
189
+ unset($ attrs ['lightboxWidth ' ]);
190
+ unset($ attrs ['lightboxHeight ' ]);
191
+ unset($ attrs ['columns ' ]);
192
+
193
+ return $ attrs ;
194
+ }
159
195
}
0 commit comments