@@ -43,25 +43,7 @@ public function writeDefaultsToJSINFO(Event $event, $param)
4343 {
4444 global $ JSINFO ;
4545
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 ();
6547
6648 if (!isset ($ JSINFO ['plugins ' ])) {
6749 $ JSINFO ['plugins ' ] = [];
@@ -88,22 +70,24 @@ public function writeDefaultsToJSINFO(Event $event, $param)
8870 */
8971 public function renderFromInstructions (Event $ event , $ param )
9072 {
91- if ($ event ->data ['name ' ] !== 'gallery ' ) {
73+ if ($ event ->data ['name ' ] !== 'gallery_main ' ) {
9274 return ;
9375 }
9476 $ event ->preventDefault ();
9577 $ event ->stopPropagation ();
9678
9779 $ node = new Node ('dwplugin_gallery ' );
98- // FIXME we may have to parse the namespace from the original syntax ?
9980 $ data = $ event ->data ['data ' ];
100- $ ns = $ data ['ns ' ];
81+ // FIXME source can be something other than namespace
82+ [$ ns , $ options ] = $ data ;
10183
10284 if (cleanID ($ ns ) === $ ns ) {
10385 $ ns = ': ' . $ ns ;
10486 }
10587 $ node ->attr ('namespace ' , $ ns );
106- foreach ($ data as $ name => $ value ) {
88+
89+ $ attrs = $ this ->optionsToAttrs ($ options );
90+ foreach ($ attrs as $ name => $ value ) {
10791 $ node ->attr ($ name , $ value );
10892 }
10993 $ event ->data ['renderer ' ]->nodestack ->add ($ node );
@@ -156,4 +140,56 @@ public function renderAttributesToHTML(Event $event, $param)
156140 $ html = p_render ('xhtml ' , p_get_instructions ($ syntax ), $ info );
157141 echo $ html ;
158142 }
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+ }
159195}
0 commit comments