-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.php
532 lines (386 loc) · 14 KB
/
plugin.php
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<?php
/*
Plugin Name: Bootstrap Shortcodes for WordPress
Plugin URI: http://logoscreative.co
Description: Add shortcodes allowing common Bootstrap components to be used in the Visual Editor
Version: 1.0.1
Author: Cliff Seal
Author URI: http://logoscreative.co
Author Email: [email protected]
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
class BootstrapShortcodes {
function __construct() {
add_shortcode( 'collapse', array( $this, 'bs_collapse_func' ) );
add_shortcode( 'tabs', array( $this, 'bs_tabs_func' ) );
add_shortcode( 'tab', array( $this, 'bs_tab_func' ) );
add_shortcode( 'tabcontent-group', array( $this, 'bs_tab_content_group_func' ) );
add_shortcode( 'tabcontent', array( $this, 'bs_tab_content_func' ) );
add_shortcode( 'button', array( $this, 'bs_button_func' ) );
add_shortcode( 'btngroup', array( $this, 'bs_btngrp_func' ) );
add_shortcode( 'row', array( $this, 'bs_row_func' ) );
add_shortcode( 'inner-row', array( $this, 'bs_row_func' ) );
add_shortcode( 'inner-inner-row', array( $this, 'bs_row_func' ) );
add_shortcode( 'col', array( $this, 'bs_span_func' ) );
add_shortcode( 'inner-col', array( $this, 'bs_span_func' ) );
add_shortcode( 'inner-inner-col', array( $this, 'bs_span_func' ) );
add_shortcode( 'jumbotron', array( $this, 'bs_hero_func' ) );
add_shortcode( 'well', array( $this, 'bs_well_func' ) );
add_shortcode( 'icon', array( $this, 'bs_icon_func' ) );
add_shortcode( 'thumbnail', array( $this, 'bs_thumbnail_func' ) );
add_shortcode( 'container', array( $this, 'bs_container_func' ) );
add_shortcode( 'lead', array( $this, 'bs_lead_func' ) );
// Deprecated
add_shortcode( 'hero', array( $this, 'bs_hero_func' ) );
add_shortcode( 'thumbnails', array( $this, 'bs_thumbnails_func' ) );
add_shortcode( 'span', array( $this, 'bs_span_func' ) );
add_shortcode( 'inner-span', array( $this, 'bs_span_func' ) );
add_shortcode( 'inner-inner-span', array( $this, 'bs_span_func' ) );
// Run this after the shortcodes so we can do stuff
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 11 );
add_filter( 'widget_text', 'do_shortcode' );
}
/* Helper public function */
public function bs_slug($str) {
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return $str;
}
/* Collapse: http://getbootstrap.com/javascript/#collapse */
/* [collapse title=null element="h2" open=false][/collapse] */
public function bs_collapse_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'title' => '',
'element' => 'h2',
'open' => false,
'plusicon' => true
),
$atts
)
);
$idnum = rand(1,500);
$open == true ? $open = ' in' : $open = '';
$plusicon == true ? $plusicon = ' +' : $plusicon = '';
$collapse_content = "<" . $element . "><a data-toggle='collapse' data-target='#coll" . $idnum . "' class='pointer'>" . $title . $plusicon . "</a></" . $element . "><div id='coll" . $idnum . "' class='collapse" . $open . "'>" . do_shortcode($content) . "</div>";
return $collapse_content;
}
/* Tabs: http://getbootstrap.com/javascript/#tabs */
/* [tabs class=null][/tabs] */
public function bs_tabs_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'class' => ''
),
$atts
)
);
if ( $class != '' ) {
$class = " " . $class;
}
$tabs_content = "<ul class='nav nav-tabs" . $class . "'>" . do_shortcode($content) . "</ul>";
return $tabs_content;
}
/* Tab: http://getbootstrap.com/javascript/#tabs */
/* [tab title="default" active=false class=null icon=null element=null] */
public function bs_tab_func($atts) {
extract(
shortcode_atts(
array(
'title' => 'default',
'active' => false,
'class' => '',
'icon' => '',
'element' => ''
),
$atts
)
);
if ( $class != '' ) {
$class = " " . $class;
}
if ( $active == true ) {
$active = " class='active" . $class . "'";
} else {
$active = " class='" . $class . "'";
}
$tab_content = "<li" . $active . ">";
if ( $element != '' ) {
$tab_content .= "<" . $element . ">";
}
$tab_content .= "<a href='#" . $this->bs_slug($title) . "' data-toggle='tab'>";
if ( $icon != '' ) {
$tab_content .= "<i class='fa fa-" . $icon . " fa-white fa-2x'></i><br />";
}
$tab_content .= do_shortcode($title) . "</a>";
if ( $element != '' ) {
$tab_content .= "</" . $element . ">";
}
$tab_content .= "</li>";
return $tab_content;
}
/* Tab Content Group: http://getbootstrap.com/javascript/#tabs */
/* [tabcontent-group][/tabcontent-group] */
public function bs_tab_content_group_func($atts, $content = null) {
$tab_content_group_content = "<div class='tab-content'>" . do_shortcode($content) . "</div>";
return $tab_content_group_content;
}
/* Tab Content: http://getbootstrap.com/javascript/#tabs */
/* [tabcontent title=null class=null active=false fade=false][/tabcontent] */
public function bs_tab_content_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'title' => 'default',
'class' => '',
'active' => false,
'fade' => false
),
$atts
)
);
if ( $active == true ) {
$active = " in active";
} else {
$active = "";
}
if ( $fade == true ) {
$fade = " fade";
} else {
$fade = "";
}
$tab_content = "<div class='tab-pane" . $fade . $active . "' id='" . $this->bs_slug($title) . "'>" . do_shortcode($content) . "</div>";
return $tab_content;
}
/* Buttons: http://getbootstrap.com/css/#buttons */
/* [button text=null link=null style=null size=null icon=null iconwhite=false class=null newwindow=false] */
public function bs_button_func($atts) {
extract(
shortcode_atts(
array(
'text' => '',
'link' => '',
'style' => '',
'size' => '',
'icon' => '',
'iconwhite' => false,
'class' => '',
'newwindow' => false
),
$atts
)
);
if ( $style != '' ) {
$style = " btn-" . $style;
}
if ( $size != '' ) {
if ( $size == 'mini' ) {
$size = 'xs';
} elseif ( $size == 'small' ) {
$size = 'sm';
} elseif ( $size == 'large' ) {
$size = 'lg';
}
$size = " btn-" . $size;
}
$iconwhite == true ? $iconclr = " fa-white" : $iconclr = "";
if ( $icon != '' ) {
$icon = " <i class='fa fa-" . $icon . $iconclr . "'></i>";
}
if ( $class != '' ) {
$class = " " . $class;
}
$newwindow == true ? $newwindow = " target='_blank'" : $newwindow = "";
if ( $link != '' ) {
$button_content = "<a href='" . $link . "' class='btn" . $style . $size . $class . "'" . $newwindow . ">" . $text . $icon . "</a>";
} else {
$button_content = "<button class='btn" . $style . $size . $class . "'>" . $text . $icon . "</button>";
}
return $button_content;
}
/* Button Group: http://getbootstrap.com/components/#btn-groups */
/* [btngroup class=null][/btngroup] */
public function bs_btngrp_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'class' => ''
),
$atts
)
);
if ( $class != '' ) {
$class = " " . $class;
}
$btngrp_content = "<div class='btn-group" . $class . "'>" . do_shortcode($content) . "</div>";
return $btngrp_content;
}
/* Row: http://getbootstrap.com/css/#grid */
/* [row class=null rowid=null] */
public function bs_row_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'class' => '',
'rowid' => ''
),
$atts
)
);
if ( $class != '' ) {
$class = " " . $class;
}
if ( $rowid != '' ) {
$rowid = " id='" . $rowid . "'";
}
$row_content = "<div class='row" . $class . "'" . $rowid . ">" . do_shortcode($content) . "</div>";
return $row_content;
}
/* Col: http://getbootstrap.com/css/#grid */
/* [col width=12 offset=0 class=null spanid=null] */
public function bs_span_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'width' => 12,
'offset' => 0,
'class' => '',
'spanid' => ''
),
$atts
)
);
$offset != '0' ? $offset = " col-md-offset-" . $offset : $offset = "";
if ( $class != '' ) {
$class = " " . $class;
}
if ( $spanid != '' ) {
$spanid = " id='" . $spanid . "'";
}
$span_content = "<div class='col-md-" . $width . $offset . $class . "'" . $spanid . ">" . do_shortcode($content) . "</div>";
return $span_content;
}
/* Jumbotron: http://getbootstrap.com/components/#jumbotron */
/* [jumbotron][/jumbotron] */
public function bs_hero_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'class' => ''
),
$atts
)
);
if ( $class !== '' ) {
$class = " " . $class;
}
$hero_content = "<div class='jumbotron" . $class . "'>" . do_shortcode($content) . "</div>";
return $hero_content;
}
/* Well: http://getbootstrap.com/components/#wells */
/* [well size=null class=null][/well] */
public function bs_well_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'size' => false,
'class' => ''
),
$atts
)
);
if ( $class !== '' ) {
$class = " " . $class;
}
$size != '' ? $size = " well-" . $size : $size = "";
$well_content = "<div class='well" . $size . $class . "'>" . do_shortcode($content) . "</div>";
return $well_content;
}
/* Icon: http://fortawesome.github.com/Font-Awesome/ */
/* [icon type=null class=null] */
public function bs_icon_func($atts) {
extract(
shortcode_atts(
array(
'type' => '',
'class' => ''
),
$atts
)
);
if ( $class !== '' ) {
$class = " " . $class;
}
$icon_content = "<i class='fa fa-" . $type . $class . "'></i>";
return $icon_content;
}
/* There's no reason for a thumbnail wrapper now. */
public function bs_thumbnails_func($atts, $content = null) {
return do_shortcode($content);
}
/* Thumbnail: http://getbootstrap.com/components/#thumbnails */
/* [thumbnail size=4 src=null title=null content=null class=null][/thumbnail] */
public function bs_thumbnail_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'size' => 4,
'src' => '',
'title' => '',
'class' => ''
),
$atts
)
);
$thumbnail_content = '
<div class="col-md-' . $size . ' ' . $class . '"><div class="thumbnail"><img src="' . $src. '" alt="' . $title . '"><div class="caption"><h3>' . $title . '</h3>' . do_shortcode($content) . '</div></div></div>';
return $thumbnail_content;
}
/* Container: http://getbootstrap.com/css/#overview-container */
/* [container class=null fluid=false][/container] */
public function bs_container_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'class' => '',
'fluid' => false
),
$atts
)
);
if ( $fluid === true ) {
$divclass = "-fluid";
} else {
$divclass = "";
}
if ( $class !== '' ) {
$divclass = " " . $class;
}
$container_content = "<div class='container" . $divclass . "'>" . do_shortcode($content) . "</div>";
return $container_content;
}
/* Lead: http://twitter.github.com/bootstrap/components.html#typography */
/* [lead][/lead] */
public function bs_lead_func($atts, $content = null) {
extract(
shortcode_atts(
array(
'class' => ''
),
$atts
)
);
if ( $class !== '' ) {
$class = " " . $class;
}
$lead_content = "<span class='lead" . $class . "'>" . do_shortcode($content) . "</span>";
return $lead_content;
}
}
$bsshortcodes = New BootstrapShortcodes();