11<?php
22use dokuwiki \Form \Form ;
33use dokuwiki \plugin \sync \ProfileManager ;
4+ use dokuwiki \plugin \sync \SyncException ;
45
56// must be run within Dokuwiki
67if (!defined ('DOKU_INC ' )) die ();
@@ -26,7 +27,11 @@ function __construct() {
2627 global $ INPUT ;
2728
2829 $ this ->profileManager = new ProfileManager ();
29- $ this ->profno = $ INPUT ->int ('no ' , false );
30+ if ($ INPUT ->str ('no ' ) == 'none ' ) {
31+ $ this ->profno = -1 ;
32+ } else {
33+ $ this ->profno = $ INPUT ->int ('no ' , -1 );
34+ }
3035 }
3136
3237 /**
@@ -104,7 +109,7 @@ function handle() {
104109 $ this ->profno = $ this ->profileManager ->setProfileConfig ($ this ->profno , $ profile );
105110 msg ('profile saved ' , 1 );
106111 }
107- } catch (\ dokuwiki \ plugin \ sync \ SyncException $ e ) {
112+ } catch (SyncException $ e ) {
108113 msg (hsc ($ e ->getMessage ()), -1 );
109114 }
110115 }
@@ -149,7 +154,7 @@ function html() {
149154 ob_flush ();
150155
151156 echo '<p> ' . $ this ->getLang ('syncdone ' ) . '</p> ' ;
152- } elseif ($ _REQUEST ['startsync ' ] && $ this ->profno !== '' ) {
157+ } elseif ($ _REQUEST ['startsync ' ] && $ this ->profno !== - 1 ) {
153158 // get sync list
154159 list ($ lnow , $ rnow ) = $ this ->_getTimes ();
155160 $ pages = array ();
@@ -188,9 +193,9 @@ function html() {
188193
189194 echo '<div class="sync_left"> ' ;
190195 $ this ->profileDropdown ();
191- if ($ this ->profno !== false ) {
196+ if ($ this ->profno !== - 1 ) {
192197 echo '<br /> ' ;
193- $ this ->_profileView ();
198+ $ this ->profileInfo ();
194199 }
195200 echo '</div> ' ;
196201 echo '<div class="sync_right"> ' ;
@@ -199,6 +204,38 @@ function html() {
199204 }
200205 }
201206
207+ /**
208+ * Check connection for choosen profile and display last sync date.
209+ */
210+ protected function profileInfo () {
211+ try {
212+ $ profile = $ this ->profileManager ->getProfile ($ this ->profno );
213+ $ version = $ profile ->getRemotVersion ();
214+ $ ltime = $ profile ->getConfig ('ltime ' );
215+ } catch (SyncException $ e ) {
216+ echo '<div class="error"> ' . $ this ->getLang ('noconnect ' ) . '<br /> ' . hsc ($ e ->getMessage ()) . '</div> ' ;
217+ return ;
218+ }
219+
220+ $ form = new Form (
221+ [
222+ 'action ' => wl ('' , ['do ' => 'admin ' , 'page ' => 'sync ' ], false , '& ' ),
223+ 'method ' => 'POST ' ,
224+ ]
225+ );
226+ $ form ->setHiddenField ('no ' , $ this ->profno );
227+ $ form ->addFieldsetOpen ($ this ->getLang ('syncstart ' ));
228+ $ form ->addHTML ('<p> ' . $ this ->getLang ('remotever ' ) . ' ' . hsc ($ version ) . '</p> ' );
229+ if ($ ltime ) {
230+ $ form ->addHTML ('<p> ' . $ this ->getLang ('lastsync ' ) . ' ' . dformat ($ ltime ) . '</p> ' );
231+ } else {
232+ $ form ->addHTML ('<p> ' . $ this ->getLang ('neversync ' ) . '</p> ' );
233+ }
234+ $ form ->addButton ('startsync ' , $ this ->getLang ('syncstart ' ))->attr ('type ' , 'submit ' );
235+ $ form ->addFieldsetClose ();
236+ echo $ form ->toHTML ();
237+ }
238+
202239 /**
203240 * Dropdown list of available sync profiles
204241 */
@@ -210,8 +247,8 @@ protected function profileDropdown() {
210247 ]
211248 );
212249
213- $ profiles = $ this ->profileManager -> getProfileLabels () ;
214- $ profiles[ '' ] = $ this ->getLang ( ' newprofile ' );
250+ $ profiles = [ ' none ' => $ this ->getLang ( ' newprofile ' )] ;
251+ $ profiles = array_merge ( $ profiles , $ this ->profileManager -> getProfileLabels () );
215252
216253 $ form ->addFieldsetOpen ($ this ->getLang ('profile ' ));
217254 $ form ->addDropdown ('no ' , $ profiles )->val ($ this ->profno );
@@ -233,7 +270,7 @@ protected function profileForm() {
233270 ]
234271 );
235272
236- if ($ this ->profno === false ) {
273+ if ($ this ->profno === - 1 ) {
237274 $ legend = $ this ->getLang ('create ' );
238275 $ profile = $ this ->profileManager ->getEmptyConfig ();
239276 } else {
@@ -242,15 +279,15 @@ protected function profileForm() {
242279 }
243280
244281 $ depths = [
245- ['label ' => $ this ->getLang ('level0 ' ), ' attr ' => [ ' value ' => ' 0 ' ] ],
246- ['label ' => $ this ->getLang ('level1 ' ), ' attr ' => [ ' value ' => ' 1 ' ] ],
247- ['label ' => $ this ->getLang ('level2 ' ), ' attr ' => [ ' value ' => ' 2 ' ] ],
248- ['label ' => $ this ->getLang ('level3 ' ), ' attr ' => [ ' value ' => ' 3 ' ] ],
282+ ['label ' => $ this ->getLang ('level0 ' )],
283+ ['label ' => $ this ->getLang ('level1 ' )],
284+ ['label ' => $ this ->getLang ('level2 ' )],
285+ ['label ' => $ this ->getLang ('level3 ' )],
249286 ];
250287 $ types = [
251- ['label ' => $ this ->getLang ('type0 ' ), ' attr ' => [ ' value ' => ' 0 ' ] ],
252- ['label ' => $ this ->getLang ('type1 ' ), ' attr ' => [ ' value ' => ' 1 ' ] ],
253- ['label ' => $ this ->getLang ('type2 ' ), ' attr ' => [ ' value ' => ' 2 ' ] ],
288+ ['label ' => $ this ->getLang ('type0 ' )],
289+ ['label ' => $ this ->getLang ('type1 ' )],
290+ ['label ' => $ this ->getLang ('type2 ' )],
254291 ];
255292
256293 $ form ->addFieldsetOpen ($ legend );
@@ -265,13 +302,13 @@ protected function profileForm() {
265302 $ form ->addDropdown ('prf[type] ' , $ types , $ this ->getLang ('type ' ))->val ($ profile ['type ' ]);
266303 $ form ->addButton ('' , $ this ->getLang ('save ' ))->attr ('type ' , 'submit ' );
267304
268- if ($ this ->profno !== false && !empty ($ profile ['ltime ' ])) {
305+ if ($ this ->profno !== - 1 && !empty ($ profile ['ltime ' ])) {
269306 echo '<small> ' . $ this ->getLang ('changewarn ' ) . '</small> ' ;
270307 }
271308
272309 $ form ->addFieldsetClose ();
273310
274- if ($ this ->profno !== false ) {
311+ if ($ this ->profno !== - 1 ) {
275312 $ form ->addFieldsetOpen ($ this ->getLang ('delete ' ));
276313 $ form ->addButton ('sync__delete ' , $ this ->getLang ('delete ' ));
277314 $ form ->addFieldsetClose ();
@@ -300,37 +337,6 @@ function _profileSave() {
300337 io_saveFile ($ profiles , serialize ($ this ->profiles ));
301338 }
302339
303- /**
304- * Check connection for choosen profile and display last sync date.
305- */
306- function _profileView () {
307- if (!$ this ->_connect ()) return ;
308-
309- global $ conf ;
310- $ no = $ this ->profno ;
311-
312- $ ok = $ this ->client ->query ('dokuwiki.getVersion ' );
313- $ version = '' ;
314- if ($ ok ) $ version = $ this ->client ->getResponse ();
315-
316- echo '<form action="" method="post"> ' ;
317- echo '<input type="hidden" name="no" value=" ' . hsc ($ no ) . '" /> ' ;
318- echo '<fieldset><legend> ' . $ this ->getLang ('syncstart ' ) . '</legend> ' ;
319- if ($ version ) {
320- echo '<p> ' . $ this ->getLang ('remotever ' ) . ' ' . hsc ($ version ) . '</p> ' ;
321- if ($ this ->profiles [$ no ]['ltime ' ]) {
322- echo '<p> ' . $ this ->getLang ('lastsync ' ) . ' ' . strftime ($ conf ['dformat ' ], $ this ->profiles [$ no ]['ltime ' ]) . '</p> ' ;
323- } else {
324- echo '<p> ' . $ this ->getLang ('neversync ' ) . '</p> ' ;
325- }
326- echo '<input name="startsync" type="submit" value=" ' . $ this ->getLang ('syncstart ' ) . '" class="button" /> ' ;
327- } else {
328- echo '<p class="error"> ' . $ this ->getLang ('noconnect ' ) . '<br /> ' . hsc ($ this ->client ->getErrorMessage ()) . '</p> ' ;
329- }
330- echo '</fieldset> ' ;
331- echo '</form> ' ;
332- }
333-
334340 /**
335341 * Lock files that will be modified on either side.
336342 *
0 commit comments