@@ -96,31 +96,6 @@ function _tpl_action($type, $link=0, $wrapper=0, $return=0) {
96
96
}
97
97
98
98
99
- function bootstrap3_toolsevent ($ toolsname , $ items , $ view ='main ' , $ return = false ) {
100
-
101
- $ output = '' ;
102
-
103
- $ data = array (
104
- 'view ' => $ view ,
105
- 'items ' => $ items
106
- );
107
- $ hook = 'TEMPLATE_ ' .strtoupper ($ toolsname ).'_DISPLAY ' ;
108
- $ evt = new Doku_Event ($ hook , $ data );
109
- if ($ evt ->advise_before ()){
110
- foreach ($ evt ->data ['items ' ] as $ k => $ html ) $ output .= $ html ;
111
- }
112
- $ evt ->advise_after ();
113
-
114
- $ search = array ('<span> ' );
115
- $ replace = array ('<i class="fa fa-puzzle-piece fa-fw"></i> <span> ' );
116
-
117
- $ output = str_replace ($ search , $ replace , $ output );
118
-
119
- if ($ return ) return $ output ;
120
- echo $ output ;
121
-
122
- }
123
-
124
99
125
100
/**
126
101
* copied to core (available since Detritus)
@@ -160,6 +135,44 @@ function tpl_classes() {
160
135
}
161
136
162
137
138
+ /**
139
+ * Create event for tools menues
140
+ *
141
+ * @author Anika Henke <[email protected] >
142
+ * @author Giuseppe Di Terlizzi <[email protected] >
143
+ *
144
+ * @param string $toolsname name of menu
145
+ * @param array $items
146
+ * @param string $view e.g. 'main', 'detail', ...
147
+ * @param boolean $return
148
+ * @return string
149
+ */
150
+ function bootstrap3_toolsevent ($ toolsname , $ items , $ view ='main ' , $ return = false ) {
151
+
152
+ $ output = '' ;
153
+
154
+ $ data = array (
155
+ 'view ' => $ view ,
156
+ 'items ' => $ items
157
+ );
158
+ $ hook = 'TEMPLATE_ ' .strtoupper ($ toolsname ).'_DISPLAY ' ;
159
+ $ evt = new Doku_Event ($ hook , $ data );
160
+ if ($ evt ->advise_before ()){
161
+ foreach ($ evt ->data ['items ' ] as $ k => $ html ) $ output .= $ html ;
162
+ }
163
+ $ evt ->advise_after ();
164
+
165
+ $ search = array ('<span> ' );
166
+ $ replace = array ('<i class="fa fa-puzzle-piece fa-fw"></i> <span> ' );
167
+
168
+ $ output = str_replace ($ search , $ replace , $ output );
169
+
170
+ if ($ return ) return $ output ;
171
+ echo $ output ;
172
+
173
+ }
174
+
175
+
163
176
/**
164
177
* Include left or right sidebar
165
178
*
@@ -192,7 +205,7 @@ function bootstrap3_action_item($action, $icon, $return = false) {
192
205
193
206
if ($ action == 'discussion ' ) {
194
207
195
- if (tpl_getConf ('showDiscussion ' )) {
208
+ if (bootstrap3_conf ('showDiscussion ' )) {
196
209
$ out = _tpl_action ('discussion ' , 1 , 'li ' , 1 );
197
210
$ out = str_replace (array ('<bdi> ' , '</bdi> ' ), '' , $ out );
198
211
return preg_replace ('/(<a (.*?)>)/m ' , '$1<i class=" ' .$ icon .'"></i> ' , $ out );
@@ -218,6 +231,7 @@ function bootstrap3_action_item($action, $icon, $return = false) {
218
231
219
232
}
220
233
234
+
221
235
/**
222
236
* Calculate automatically the grid size for main container
223
237
*
@@ -234,29 +248,29 @@ function bootstrap3_container_grid() {
234
248
$ grids = array ();
235
249
$ result = '' ;
236
250
237
- $ showRightSidebar = page_findnearest ( tpl_getConf ( ' rightSidebar ' )) && ( $ ACT == ' show ' );
238
- $ showLeftSidebar = page_findnearest ( $ conf [ ' sidebar ' ]) && ( $ ACT == ' show ' );
239
- $ fluidContainer = tpl_getConf ('fluidContainer ' );
251
+ $ showRightSidebar = bootstrap3_conf ( ' showRightSidebar ' );
252
+ $ showLeftSidebar = bootstrap3_conf ( ' showSidebar ' );
253
+ $ fluidContainer = bootstrap3_conf ('fluidContainer ' );
240
254
241
- if (tpl_getConf ('fluidContainerBtn ' )) {
255
+ if (bootstrap3_conf ('fluidContainerBtn ' )) {
242
256
$ fluidContainer = bootstrap3_fluid_container_button ();
243
257
}
244
258
245
- if ( tpl_getConf ('showLandingPage ' )
246
- && (bool ) preg_match_all (sprintf ('/%s/ ' , tpl_getConf ('landingPages ' )), $ ID ) ) {
259
+ if ( bootstrap3_conf ('showLandingPage ' )
260
+ && (bool ) preg_match_all (sprintf ('/%s/ ' , bootstrap3_conf ('landingPages ' )), $ ID ) ) {
247
261
$ showLeftSidebar = false ;
248
262
}
249
263
250
264
if (! $ showLeftSidebar ) {
251
265
return 'container ' . (($ fluidContainer ) ? '-fluid ' : '' );
252
266
}
253
267
254
- foreach (explode (' ' , tpl_getConf ('leftSidebarGrid ' )) as $ grid ) {
268
+ foreach (explode (' ' , bootstrap3_conf ('leftSidebarGrid ' )) as $ grid ) {
255
269
list ($ col , $ media , $ size ) = explode ('- ' , $ grid );
256
270
$ grids [$ media ]['left ' ] = (int ) $ size ;
257
271
}
258
272
259
- foreach (explode (' ' , tpl_getConf ('rightSidebarGrid ' )) as $ grid ) {
273
+ foreach (explode (' ' , bootstrap3_conf ('rightSidebarGrid ' )) as $ grid ) {
260
274
list ($ col , $ media , $ size ) = explode ('- ' , $ grid );
261
275
$ grids [$ media ]['right ' ] = (int ) $ size ;
262
276
}
@@ -271,6 +285,7 @@ function bootstrap3_container_grid() {
271
285
272
286
}
273
287
288
+
274
289
/**
275
290
* Return the user home-page link
276
291
*
@@ -288,9 +303,16 @@ function bootstrap3_user_homepage_link() {
288
303
}
289
304
290
305
306
+ /**
307
+ * Check if the fluid container button is enabled (from the user cookie)
308
+ *
309
+ * @author Giuseppe Di Terlizzi <[email protected] >
310
+ *
311
+ * @return boolean
312
+ */
291
313
function bootstrap3_fluid_container_button () {
292
314
293
- if (! tpl_getConf ('fluidContainerBtn ' )) return false ;
315
+ if (! bootstrap3_conf ('fluidContainerBtn ' )) return false ;
294
316
295
317
if ( get_doku_pref ('fluidContainer ' , null ) !== null
296
318
&& get_doku_pref ('fluidContainer ' , null ) !== ''
@@ -354,6 +376,51 @@ function bootstrap3_sidebar($sidebar, $return = false) {
354
376
}
355
377
356
378
379
+ /**
380
+ * Normalize DokuWiki list items
381
+ *
382
+ * @author Giuseppe Di Terlizzi <[email protected] >
383
+ *
384
+ * @param string $html
385
+ * @return string
386
+ */
387
+ function bootstrap3_lists ($ html ) {
388
+ $ output = preg_replace ('/<div class="li">(.*?)<\/div>/ ' , '$1 ' , $ html );
389
+ return $ output ;
390
+ }
391
+
392
+
393
+
394
+ /**
395
+ * Make a Bootstrap3 Nav
396
+ *
397
+ * @author Giuseppe Di Terlizzi <[email protected] >
398
+ *
399
+ * @param string $html
400
+ * @param boolean $staked
401
+ * @param string $type (= pills, tabs)
402
+ * @return string
403
+ **/
404
+ function bootstrap3_nav ($ html , $ stacked = false , $ type = '' ) {
405
+
406
+ $ class = 'nav ' ;
407
+
408
+ if ($ stacked ) $ class .= 'nav-stacked ' ;
409
+ if ($ type ) $ class .= "nav- $ type " ;
410
+
411
+ $ class = trim ($ class );
412
+
413
+ $ output = str_replace (array ('<ul class=" ' , '<ul> ' ),
414
+ array ("<ul class= \"$ class " , "<ul class= \"$ class \"> " ),
415
+ $ html );
416
+
417
+ $ output = bootstrap3_lists ($ output );
418
+
419
+ return $ output ;
420
+
421
+ }
422
+
423
+
357
424
/**
358
425
* Print the search form in Bootstrap Style
359
426
*
@@ -511,6 +578,13 @@ function bootstrap3_tools() {
511
578
}
512
579
513
580
581
+ /**
582
+ * Return an array for a tools menu
583
+ *
584
+ * @author Giuseppe Di Terlizzi <[email protected] >
585
+ *
586
+ * @return array of tools
587
+ */
514
588
function bootstrap3_tools_menu () {
515
589
516
590
$ tools = bootstrap3_tools ();
@@ -526,6 +600,13 @@ function bootstrap3_tools_menu() {
526
600
}
527
601
528
602
603
+ /**
604
+ * Return an array for a toolbar
605
+ *
606
+ * @author Giuseppe Di Terlizzi <[email protected] >
607
+ *
608
+ * @return array of tools
609
+ */
529
610
function bootstrap3_toolbar () {
530
611
531
612
$ tools = _tpl_tools ();
@@ -544,14 +625,14 @@ function bootstrap3_toolbar() {
544
625
/**
545
626
* Get either a Gravatar URL or complete image tag for a specified email address.
546
627
*
547
- * @param string $email The email address
548
- * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
549
- * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
550
- * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
551
- * @param boolean $img True to return a complete IMG tag False for just the URL
552
- * @param array $atts Optional, additional key/value attributes to include in the IMG tag
553
- * @return String containing either just a URL or a complete image tag
554
- * @source http://gravatar.com/site/implement/images/php/
628
+ * @param string $email The email address
629
+ * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
630
+ * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
631
+ * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
632
+ * @param boolean $img True to return a complete IMG tag False for just the URL
633
+ * @param array $atts Optional, additional key/value attributes to include in the IMG tag
634
+ * @return String containing either just a URL or a complete image tag
635
+ * @source http://gravatar.com/site/implement/images/php/
555
636
*/
556
637
function get_gravatar ( $ email , $ s = 80 , $ d = 'mm ' , $ r = 'g ' , $ img = false , $ atts = array () ) {
557
638
$ url = 'http://www.gravatar.com/avatar/ ' ;
@@ -565,3 +646,104 @@ function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts
565
646
}
566
647
return $ url ;
567
648
}
649
+
650
+
651
+ /**
652
+ * Get the template metadata
653
+ *
654
+ * @author Giuseppe Di Terlizzi <[email protected] >
655
+ *
656
+ * @param string $key
657
+ * @return array
658
+ */
659
+ function bootstrap3_metadata ($ key = null ) {
660
+
661
+ $ meta = array ();
662
+ $ file = tpl_incdir () . 'conf/metadata.php ' ;
663
+ include $ file ;
664
+
665
+ if ($ key ) return $ meta [$ key ];
666
+
667
+ return $ meta ;
668
+
669
+ }
670
+
671
+
672
+ /**
673
+ * A simple wrapper for tpl_getConf
674
+ *
675
+ * @author Giuseppe Di Terlizzi <[email protected] >
676
+ *
677
+ * @param string $key
678
+ * @param mixed $default value
679
+ * @return mixed
680
+ */
681
+ function bootstrap3_conf ($ key , $ default = false ) {
682
+
683
+ global $ ACT , $ INFO , $ ID , $ conf ;
684
+
685
+ $ value = tpl_getConf ($ key , $ default );
686
+
687
+ switch ($ key ) {
688
+
689
+ case 'showTools ' :
690
+ return $ value !== 'never ' && ( $ value == 'always ' || ! empty ($ _SERVER ['REMOTE_USER ' ]) );
691
+
692
+ case 'showSearchForm ' :
693
+ return $ value !== 'never ' && ( $ value == 'always ' || ! empty ($ _SERVER ['REMOTE_USER ' ]) );
694
+
695
+ case 'showPageTools ' :
696
+ return $ value !== 'never ' && ( $ value == 'always ' || ! empty ($ _SERVER ['REMOTE_USER ' ]) );
697
+
698
+ case 'showIndividualTool ' :
699
+ return explode (', ' , $ value );
700
+
701
+ case 'showAdminMenu ' :
702
+ return $ value && $ INFO ['isadmin ' ];
703
+
704
+ case 'hideLoginLink ' :
705
+ return ! $ value || ! empty ($ _SERVER ['REMOTE_USER ' ]);
706
+
707
+ case 'hideInThemeSwitcher ' :
708
+ return explode (', ' , $ value );
709
+
710
+ case 'browserTitle ' :
711
+ return str_replace (array ('@WIKI@ ' , '@TITLE@ ' ),
712
+ array (strip_tags ($ conf ['title ' ]), tpl_pagetitle (null , true )),
713
+ $ value );
714
+
715
+ case 'showSidebar ' :
716
+ return page_findnearest ($ conf ['sidebar ' ]) && ($ ACT =='show ' );
717
+
718
+ case 'showRightSidebar ' :
719
+ return page_findnearest (tpl_getConf ('rightSidebar ' )) && ($ ACT =='show ' );
720
+
721
+ case 'landingPages ' :
722
+ return sprintf ('/%s/ ' , $ value );
723
+
724
+ }
725
+
726
+ //$type = bootstrap3_metadata($key);
727
+
728
+ //if ($type[0] == 'regex') {
729
+ // return sprintf('/%s/', $value);
730
+ //}
731
+
732
+ return $ value ;
733
+
734
+ }
735
+
736
+
737
+ /**
738
+ * Return the Bootswatch.com theme lists defined in metadata.php
739
+ *
740
+ * @author Giuseppe Di Terlizzi <[email protected] >
741
+ *
742
+ * @return array
743
+ */
744
+ function bootstrap3_bootswatch_theme_list () {
745
+
746
+ $ bootswatch_themes = bootstrap3_metadata ('bootswatchTheme ' );
747
+ return $ bootswatch_themes ['_choices ' ];
748
+
749
+ }
0 commit comments