PluginProbe
Easy Bootstrap Shortcode / trunk
Easy Bootstrap Shortcode vtrunk
trunk 2.4.0 2.5 3.4 3.5 3.6 3.7 4.0.0 4.4 4.5 4.5.4 5.0.0 5.0.1 5.0.2
easy-bootstrap-shortcodes / shortcode / dropdown / plugin_shortcode.php

plugin_shortcode.php in Easy Bootstrap Shortcode trunk, at shortcode/dropdown/plugin_shortcode.php

105 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 use EBS\Security\Sanitizer;
6
7 function osc_theme_dropdown( $params, $content = null ) {
8 $atts = shortcode_atts(
9 array(
10 'dropup' => '',
11 'class' => '',
12 ),
13 $params
14 );
15
16 $content = str_replace( ']<br />', ']', $content );
17 $content = str_replace( "]<br />\n", ']', $content );
18 $content = str_replace( "<br />\n[", '[', $content );
19
20 $dropup = 'dropup' === $atts['dropup'] ? 'dropup' : '';
21 $class = Sanitizer::class_list( $atts['class'] );
22
23 $out = '<div class="btn-group ' . $dropup . ' ' . $class . EBS_CONTAINER_CLASS . '">' . do_shortcode( $content ) . '</div>';
24 $out .= "
25 <script>
26 jQuery(document).ready(function(){
27 jQuery('.dropdown-toggle').dropdown();
28 });
29 </script>
30 ";
31
32 return $out;
33 }
34
35 ebs_backward_compatibility_callback( 'dropdown', 'osc_theme_dropdown' );
36
37 function osc_theme_dropdown_head( $params, $content = null ) {
38 $atts = shortcode_atts(
39 array(
40 'size' => '',
41 'style' => '',
42 'split' => '',
43 ),
44 $params
45 );
46
47 $size = Sanitizer::class_list( $atts['size'] );
48 $style = Sanitizer::class_list( $atts['style'] );
49 $content = do_shortcode( $content );
50 $out = '';
51
52 if ( 'split' === $atts['split'] ) {
53 $out = '<button type="button" class="btn ' . $size . ' ' . $style . EBS_CONTAINER_CLASS . '">' . $content . '</button>';
54 $out .= '<button type="button" class="btn ' . $size . ' ' . $style . EBS_CONTAINER_CLASS . ' dropdown-toggle" data-toggle="dropdown">';
55 $out .= '<span class="caret' . EBS_CONTAINER_CLASS . '"></span></button>';
56 } else {
57 $out = ' <button type="button" class="btn ' . $size . ' ' . $style . EBS_CONTAINER_CLASS . ' dropdown-toggle" data-toggle="dropdown">';
58 $out .= $content . ' <span class="caret' . EBS_CONTAINER_CLASS . '"></span> </button>';
59 }
60
61 return $out;
62 }
63
64 ebs_backward_compatibility_callback( 'dropdownhead', 'osc_theme_dropdown_head' );
65
66 function osc_theme_dropdown_body( $params, $content = null ) {
67 $content = str_replace( ']<br />', ']', $content );
68 $content = str_replace( "]<br />\n", ']', $content );
69 $content = str_replace( "<br />\n[", '[', $content );
70
71 $out = '<ul class="dropdown-menu' . EBS_CONTAINER_CLASS . '" role="menu">' . do_shortcode( $content ) . '</ul>';
72
73 return $out;
74 }
75
76 ebs_backward_compatibility_callback( 'dropdownbody', 'osc_theme_dropdown_body' );
77
78 function osc_theme_dropdown_items( $params, $content = null ) {
79 $atts = shortcode_atts(
80 array(
81 'type' => '',
82 'link' => '',
83 'disabled' => '',
84 ),
85 $params
86 );
87
88 $out = '';
89 $link = Sanitizer::url( $atts['link'] );
90
91 if ( 'divider' === $atts['type'] ) {
92 $out = '<li class="divider' . EBS_CONTAINER_CLASS . '"></li>';
93 } elseif ( 'menuitem' === $atts['type'] ) {
94 if ( 'disabled' === $atts['disabled'] ) {
95 $out = '<li class="disabled' . EBS_CONTAINER_CLASS . '"><a class="' . EBS_CONTAINER_CLASS . '" href="' . $link . '">' . do_shortcode( $content ) . '</a></li>';
96 } else {
97 $out = '<li><a class="' . EBS_CONTAINER_CLASS . '" href="' . $link . '">' . do_shortcode( $content ) . '</a></li>';
98 }
99 }
100
101 return $out;
102 }
103
104 ebs_backward_compatibility_callback( 'dropdownitem', 'osc_theme_dropdown_items' );
105