1 <?php
2
3 /**
4 * Functions for setting up and executing the Vanilla framework TinyMCE
5 * accordion plugin which enhances it with the ability to add accordion
6 * elements to WordPress texts.
7 *
8 * @author Nevma, http://www.nevma.gr, info@wnevma.gr
9 *
10 * @license http://www.gnu.org/licenses/gpl-3.0.en.html GPLv3
11 */
12
13
14
15 /**
16 * Sets actions and filters necessary for the Vanilla TinyMCE accordion
17 * plugin.
18 *
19 * @return void
20 */
21
22 function vanilla_tinymce_accordion_add_plugin_action () {
23
24 add_filter( 'mce_buttons_2', 'vanilla_tinymce_accordion_add_button' );
25 add_filter( 'mce_external_plugins', 'vanilla_tinymce_accordion_add_plugin_js' );
26
27 add_action( 'admin_head', 'vanilla_tinymce_accordion_add_plugin_css' );
28
29 }
30
31 add_action( 'admin_init', 'vanilla_tinymce_accordion_add_plugin_action' );
32
33
34
35 /**
36 * Adds the Vanilla TinyMCE accordion plugin.
37 *
38 * @param array $plugin_array The array with the TinyMCE plugins to load.
39 *
40 * @return array The array enhanced.
41 */
42
43 function vanilla_tinymce_accordion_add_plugin_js ( $plugin_array ) {
44
45 $plugin_array['vanillaaccordion'] = get_template_directory_uri() . '/inc/vanilla/tinymce/js/vanilla-tinymce-accordion.js';
46
47 return $plugin_array;
48
49 }
50
51
52
53 /**
54 * Adds the CSS styles for the Vanilla TinyMCE accordion plugin.
55 *
56 * @return void
57 */
58
59 function vanilla_tinymce_accordion_add_plugin_css () {
60
61 wp_enqueue_style( 'vanilla-tinymce-accordion', get_template_directory_uri() . '/inc/vanilla/tinymce/css/vanilla-tinymce-accordion.css', false );
62
63 }
64
65
66
67 /**
68 * Adds the buttons of the Vanilla TinyMCE accordion plugin.
69 *
70 * @param array $button The array with the TinyMCE buttons of the current
71 * editor toolbar row to load.
72 *
73 * @return void
74 */
75
76 function vanilla_tinymce_accordion_add_button ( $buttons ) {
77
78 array_push( $buttons, 'accordion' );
79
80 return $buttons;
81
82 }
83
84
85
86 /**
87 * Implements the accordion element shortcode.
88 *
89 * @param array $atts The attributes added to the shortcode.
90 * @param string $content The text content inside the shortcode.
91 *
92 * @return string The result of the accordion shortcode execution.
93 */
94
95 function vanilla_tinymce_accordion_shortcode ( $atts, $content='' ) {
96
97 $result = '' .
98 '<div class = "responsiville-accordion">' .
99 do_shortcode( vanilla_tinymce_wpautopbr( $content ) ) .
100 '</div>';
101
102 // Remove extraneous line breaks between accordion internal elements.
103
104 $result = preg_replace( '/\/div>\s*<br\s*\/>\s*<div/', '/div><div', $result );
105
106 return $result;
107
108 }
109
110 add_shortcode( 'accordion', 'vanilla_tinymce_accordion_shortcode' );
111
112
113
114 /**
115 * Implements the accordion panel element shortcode.
116 *
117 * @param array $atts The attributes added to the shortcode.
118 * @param string $content The text content inside the shortcode.
119 *
120 * @return string The result of the accordion panel shortcode execution.
121 */
122
123 function vanilla_tinymce_accordion_panel_shortcode ( $atts, $content='' ) {
124
125 return '' .
126 '<div class = "responsiville-accordion-panel">' .
127 do_shortcode( vanilla_tinymce_wpautopbr( $content ) ) .
128 '</div>';
129
130 }
131
132 add_shortcode( 'accordion-panel', 'vanilla_tinymce_accordion_panel_shortcode' );
133
134
135
136 /**
137 * Implements the accordion header element shortcode.
138 *
139 * @param array $atts The attributes added to the shortcode.
140 * @param string $content The text content inside the shortcode.
141 *
142 * @return string The result of the accordion header shortcode execution.
143 */
144
145 function vanilla_tinymce_accordion_header_shortcode ( $atts, $content='' ) {
146
147 return '' .
148 '<div class = "responsiville-accordion-header">' .
149 do_shortcode( vanilla_tinymce_wpautopbr( $content ) ) .
150 '</div>';
151
152 }
153
154 add_shortcode( 'accordion-header', 'vanilla_tinymce_accordion_header_shortcode' );
155
156
157
158 /**
159 * Implements the accordion excerpt element shortcode.
160 *
161 * @param array $atts The attributes added to the shortcode.
162 * @param string $content The text content inside the shortcode.
163 *
164 * @return string The result of the accordion excerpt shortcode execution.
165 */
166
167 function vanilla_tinymce_accordion_excerpt_shortcode ( $atts, $content='' ) {
168
169 return '' .
170 '<div class = "responsiville-accordion-excerpt">' .
171 do_shortcode( vanilla_tinymce_wpautopbr( $content ) ) .
172 '</div>';
173
174 }
175
176 add_shortcode( 'accordion-excerpt', 'vanilla_tinymce_accordion_excerpt_shortcode' );
177
178
179
180 /**
181 * Implements the accordion content element shortcode.
182 *
183 * @param array $atts The attributes added to the shortcode.
184 * @param string $content The text content inside the shortcode.
185 *
186 * @return string The result of the accordion content shortcode execution.
187 */
188
189 function vanilla_tinymce_accordion_content_shortcode ( $atts, $content='' ) {
190
191 return '' .
192 '<div class = "responsiville-accordion-content">' .
193 do_shortcode( vanilla_tinymce_wpautopbr( $content ) ) .
194 '</div>';
195
196 }
197
198 add_shortcode( 'accordion-content', 'vanilla_tinymce_accordion_content_shortcode' );
199
200 ?>