PluginProbe
MyBookTable Bookstore by Stormhill Media / trunk
MyBookTable Bookstore by Stormhill Media vtrunk
3.6.5 trunk
mybooktable / includes / extras / shortcodes.php

shortcodes.php in MyBookTable Bookstore by Stormhill Media trunk, at includes/extras/shortcodes.php

658 lines 28.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 function mbt_shortcodes_init() {
5 add_shortcode('mybooktable', 'mbt_mybooktable_shortcode');
6 add_filter('authormedia_get_shortcodes', 'mbt_add_authormedia_shortcodes');
7 }
8 add_action('mbt_init', 'mbt_shortcodes_init');
9
10
11
12 /*---------------------------------------------------------*/
13 /* Shortcode Function */
14 /*---------------------------------------------------------*/
15
16 function mbt_mybooktable_shortcode($attrs) {
17 global $wp_query, $posts, $post, $id;
18
19 if(mbt_has_template_context('shortcode')) { return ''; }
20
21 $output = '';
22 if(!empty($attrs['list'])) {
23 if($attrs['list'] == 'authors') {
24 $tax = 'mbt_author';
25 } else if($attrs['list'] == 'series') {
26 $tax = 'mbt_series';
27 } else if($attrs['list'] == 'genres') {
28 $tax = 'mbt_genre';
29 } else if($attrs['list'] == 'tags') {
30 $tax = 'mbt_tag';
31 } else {
32 return '';
33 }
34
35 $display = empty($attrs['display']) ? '' : $attrs['display'];
36 // Security: Whitelist allowed display values
37 $allowed_displays = array('simple', 'bar', '');
38 if (!in_array($display, $allowed_displays, true)) {
39 $display = '';
40 }
41
42 if($display == "simple" || $display == "bar") {
43 $output .= '<ul class="mbt-taxonomy-list '.esc_attr($display).'">';
44
45 $terms = get_terms($tax);
46 foreach($terms as $term) {
47 $link = get_term_link($term);
48 $name = $term->name;
49
50 $output .= '<li class="mbt-taxonomy-item"><a href="'.esc_url($link).'">'.esc_html($name).'</a></li>';
51 }
52
53 $output .= ' <div style="clear:both;"></div>';
54 $output .= '</ul>';
55 } else {
56 $output .= '<div id="mbt-container">';
57 $output .= ' <div class="mbt-taxonomy-listing">';
58
59 $terms = get_terms($tax);
60 foreach($terms as $term) {
61 $link = get_term_link($term);
62 $name = $term->name;
63 $desc = $term->description;
64 $img = mbt_get_taxonomy_image($term->taxonomy, $term->term_id);
65
66 $output .= '<div class="mbt-taxonomy">';
67 $output .= ' <div class="mbt-taxonomy-image">';
68 $output .= ' <a href="'.esc_url($link).'"><img class="mbt-taxonomy-image" src="'.esc_url($img).'"></a>';
69 $output .= ' </div>';
70 $output .= ' <div class="mbt-taxonomy-right">';
71 $output .= ' <h1 class="mbt-taxonomy-title"><a href="'.esc_url($link).'">'.esc_html($name).'</a></h1>';
72 if(!empty($desc)) { $output .= ' <div class="mbt-taxonomy-description">'.wp_kses_post($desc).'</div>'; }
73 $output .= ' </div>';
74 $output .= ' <div style="clear:both;"></div>';
75 $output .= '</div>';
76
77 }
78
79 $output .= ' </div>';
80 $output .= '</div>';
81 }
82 } else {
83 $max_books = empty($attrs['max_books']) ? -1 : intval($attrs['max_books']);
84
85 $mbt_shortcode_old_id = $id;
86 $mbt_shortcode_old_post = $post;
87 $mbt_shortcode_old_posts = $posts;
88 $mbt_shortcode_old_wp_query = $wp_query;
89 if(!empty($attrs['book'])) {
90 $wp_query = new WP_Query(array('post_type' => 'mbt_book', 'name' => $attrs['book']));
91 } else if(!empty($attrs['author'])) {
92 $wp_query = new WP_Query(array('post_type' => 'mbt_book', 'mbt_author' => $attrs['author'], 'orderby' => 'menu_order', 'posts_per_page' => $max_books));
93 } else if(!empty($attrs['series'])) {
94 $wp_query = new WP_Query(array('post_type' => 'mbt_book', 'mbt_series' => $attrs['series'], 'orderby' => 'meta_value_num', 'meta_key' => 'mbt_series_order', 'order' => 'ASC', 'posts_per_page' => $max_books));
95 } else if(!empty($attrs['genre'])) {
96 $wp_query = new WP_Query(array('post_type' => 'mbt_book', 'mbt_genre' => $attrs['genre'], 'orderby' => 'menu_order', 'posts_per_page' => $max_books));
97 } else if(!empty($attrs['tag'])) {
98 $wp_query = new WP_Query(array('post_type' => 'mbt_book', 'mbt_tag' => $attrs['tag'], 'orderby' => 'menu_order', 'posts_per_page' => $max_books));
99 } else {
100 $wp_query = new WP_Query(array('post_type' => 'mbt_book', 'orderby' => 'menu_order', 'posts_per_page' => $max_books));
101 }
102 $wp_query->max_num_pages = 1;
103 $post = empty($wp_query->post) ? null : $wp_query->post;
104 $posts = $wp_query->posts;
105
106 mbt_enqueue_frontend_scripts();
107 ob_start();
108
109 mbt_start_template_context('shortcode');
110 if(!empty($wp_query->posts) and $wp_query->is_singular('mbt_book')) {
111 if(!empty($attrs['display']) and $attrs['display'] === 'summary') {
112 mbt_start_template_context('excerpt');
113 echo('<div id="mbt-container">');
114 do_action('mbt_book_excerpt_content');
115 echo('</div>');
116 mbt_end_template_context();
117 } else if(!empty($attrs['display']) and $attrs['display'] === 'buybuttons') {
118 mbt_start_template_context('shortcode-summary');
119 ?>
120 <div id="mbt-container">
121 <div class="<?php mbt_the_book_class(); ?>">
122 <?php mbt_the_buybuttons(false, (!empty($attrs['buybutton_shadowbox']) and $attrs['buybutton_shadowbox'] === 'true') ? true : null); ?>
123 </div>
124 </div>
125 <?php
126 mbt_end_template_context();
127 } else if(!empty($attrs['display']) and $attrs['display'] === 'cover+buybuttons') {
128 mbt_start_template_context('shortcode-cover-buybuttons');
129 ?>
130 <div id="mbt-container">
131 <div class="<?php mbt_the_book_class(); ?>">
132 <?php mbt_the_book_image(); ?>
133 <div class="mbt-book-right">
134 <?php mbt_the_buybuttons(false, (!empty($attrs['buybutton_shadowbox']) and $attrs['buybutton_shadowbox'] === 'true') ? true : null); ?>
135 <div style="clear:both;"></div>
136 </div>
137 </div>
138 </div>
139 <?php
140 mbt_end_template_context();
141 } else {
142 $display_mode = empty($attrs['display_mode']) ? mbt_get_book_display_mode($post->ID) : $attrs['display_mode'];
143 if(!mbt_book_display_mode_supports($display_mode, 'embedding')) { $display_mode = mbt_get_default_book_display_mode(); }
144 mbt_start_template_context('single');
145 mbt_start_template_display_mode($display_mode);
146 ?> <div id="mbt-container"> <?php
147 do_action('mbt_single_book_'.$display_mode.'_content');
148 ?> </div> <?php
149 mbt_end_template_display_mode();
150 mbt_end_template_context();
151 }
152 } else {
153 if(!empty($attrs['header']) and $attrs['header'] == 'hidden') { remove_action('mbt_book_archive_header', 'mbt_do_book_archive_header'); }
154 if(!empty($attrs['gridview'])) { add_filter('mbtpro2_is_gridview_active', $attrs['gridview'] == 'true' ? '__return_true' : '__return_false', 100); }
155 mbt_start_template_context('archive');
156 ?> <div id="mbt-container"> <?php
157 do_action('mbt_book_archive_content');
158 ?> </div> <?php
159 mbt_end_template_context();
160 if(!empty($attrs['gridview'])) { remove_filter('mbtpro2_is_gridview_active', $attrs['gridview'] == 'true' ? '__return_true' : '__return_false', 100); }
161 }
162 mbt_end_template_context();
163
164 $output = ob_get_contents();
165 ob_end_clean();
166
167 $wp_query = $mbt_shortcode_old_wp_query;
168 $posts = $mbt_shortcode_old_posts;
169 $post = $mbt_shortcode_old_post;
170 $id = $mbt_shortcode_old_id;
171 }
172
173 return $output;
174 }
175
176
177
178 /*---------------------------------------------------------*/
179 /* Shortcode Inserter Information */
180 /*---------------------------------------------------------*/
181
182 function mbt_add_authormedia_shortcodes($shortcodes) {
183 function mbt_get_taxonomy_names($tax) {
184 $names = array();
185 $terms = get_terms($tax);
186 foreach($terms as $term) {
187 $names[$term->slug] = $term->name;
188 }
189 return $names;
190 }
191
192 $books = array();
193 $books_query = new WP_Query(array('post_type' => 'mbt_book', 'posts_per_page' => -1));
194 foreach($books_query->posts as $book) {
195 $books[$book->post_name] = $book->post_title;
196 }
197
198 //Add default shortcodes
199 $shortcodes['mybooktable'] = array('name' => 'MyBookTable', 'shortcodes' => array(
200 'mybooktable' => array(
201 'title' => __('All Books', 'mybooktable'),
202 'description' => __('List all your books in an embedded book listing.', 'mybooktable'),
203 'settings' => array(
204 'gridview' => array(
205 'title' => 'Force Grid View Display?',
206 'default' => false,
207 'type' => 'checkbox',
208 'description' => 'Shows book covers in a responsive grid. (requires Professional or Developer Upgrade)'
209 ),
210 'header' => array(
211 'title' => __('Header', 'mybooktable'),
212 'description' => 'Shows the book table title and description above the book listing',
213 'type' => 'dropdown',
214 'choices' => array('show' => 'Shown', 'hidden' => 'Hidden')
215 ),
216 'max_books' => array(
217 'title' => __('Max Books to Display', 'mybooktable'),
218 'description' => 'Sets the maximum number of books that will be shown',
219 'type' => 'number'
220 )
221 )
222 ),
223 'mybooktable-series' => array(
224 'title' => __('All Books in Series', 'mybooktable'),
225 'description' => __('List all the books in a given series in an embedded book listing.', 'mybooktable'),
226 'settings' => array(
227 'series' => array(
228 'title' => __('Series', 'mybooktable'),
229 'description' => '',
230 'type' => 'dropdown',
231 'choices' => mbt_get_taxonomy_names('mbt_series')
232 ),
233 'gridview' => array(
234 'title' => 'Force Grid View Display?',
235 'default' => false,
236 'type' => 'checkbox',
237 'description' => 'Shows book covers in a responsive grid. (requires Professional or Developer Upgrade)'
238 ),
239 'header' => array(
240 'title' => __('Header', 'mybooktable'),
241 'description' => 'Shows the taxonomy title and description above the book listing',
242 'type' => 'dropdown',
243 'choices' => array('show' => 'Shown', 'hidden' => 'Hidden')
244 ),
245 'max_books' => array(
246 'title' => __('Max Books to Display', 'mybooktable'),
247 'description' => 'Sets the maximum number of books that will be shown',
248 'type' => 'number'
249 )
250 )
251 ),
252 'mybooktable-genre' => array(
253 'title' => __('All Books in Genre', 'mybooktable'),
254 'description' => __('List all the books in a given genre in an embedded book listing.', 'mybooktable'),
255 'settings' => array(
256 'genre' => array(
257 'title' => __('Genre', 'mybooktable'),
258 'description' => '',
259 'type' => 'dropdown',
260 'choices' => mbt_get_taxonomy_names('mbt_genre')
261 ),
262 'gridview' => array(
263 'title' => 'Force Grid View Display?',
264 'default' => false,
265 'type' => 'checkbox',
266 'description' => 'Shows book covers in a responsive grid. (requires Professional or Developer Upgrade)'
267 ),
268 'header' => array(
269 'title' => __('Header', 'mybooktable'),
270 'description' => 'Shows the taxonomy title and description above the book listing',
271 'type' => 'dropdown',
272 'choices' => array('show' => 'Shown', 'hidden' => 'Hidden')
273 ),
274 'max_books' => array(
275 'title' => __('Max Books to Display', 'mybooktable'),
276 'description' => 'Sets the maximum number of books that will be shown',
277 'type' => 'number'
278 )
279 )
280 ),
281 'mybooktable-tag' => array(
282 'title' => __('All Books with Tag', 'mybooktable'),
283 'description' => __('List all the books with a given tag in an embedded book listing.', 'mybooktable'),
284 'settings' => array(
285 'tag' => array(
286 'title' => __('Tag', 'mybooktable'),
287 'description' => '',
288 'type' => 'dropdown',
289 'choices' => mbt_get_taxonomy_names('mbt_tag')
290 ),
291 'gridview' => array(
292 'title' => 'Force Grid View Display?',
293 'default' => false,
294 'type' => 'checkbox',
295 'description' => 'Shows book covers in a responsive grid. (requires Professional or Developer Upgrade)'
296 ),
297 'header' => array(
298 'title' => __('Header', 'mybooktable'),
299 'description' => 'Shows the taxonomy title and description above the book listing',
300 'type' => 'dropdown',
301 'choices' => array('show' => 'Shown', 'hidden' => 'Hidden')
302 ),
303 'max_books' => array(
304 'title' => __('Max Books to Display', 'mybooktable'),
305 'description' => 'Sets the maximum number of books that will be shown',
306 'type' => 'number'
307 )
308 )
309 ),
310 'mybooktable-author' => array(
311 'title' => __('All Books by Author', 'mybooktable'),
312 'description' => __('List all the books written by a given author in an embedded book listing.', 'mybooktable'),
313 'settings' => array(
314 'author' => array(
315 'title' => __('Author', 'mybooktable'),
316 'description' => '',
317 'type' => 'dropdown',
318 'choices' => mbt_get_taxonomy_names('mbt_author')
319 ),
320 'gridview' => array(
321 'title' => 'Force Grid View Display?',
322 'default' => false,
323 'type' => 'checkbox',
324 'description' => 'Shows book covers in a responsive grid. (requires Professional or Developer Upgrade)'
325 ),
326 'header' => array(
327 'title' => __('Header', 'mybooktable'),
328 'description' => 'Shows the taxonomy title and description above the book listing',
329 'type' => 'dropdown',
330 'choices' => array('show' => 'Shown', 'hidden' => 'Hidden')
331 ),
332 'max_books' => array(
333 'title' => __('Max Books to Display', 'mybooktable'),
334 'description' => 'Sets the maximum number of books that will be shown',
335 'type' => 'number'
336 )
337 )
338 ),
339 'mybooktable-book' => array(
340 'title' => __('Single Book', 'mybooktable'),
341 'description' => __('Show a given book in an embedded book listing.', 'mybooktable'),
342 'settings' => array(
343 'book' => array(
344 'title' => __('Book', 'mybooktable'),
345 'description' => '',
346 'type' => 'dropdown',
347 'choices' => $books
348 ),
349 'display' => array(
350 'title' => __('Display Style', 'mybooktable'),
351 'description' => '',
352 'type' => 'dropdown',
353 'choices' => array("default" => __("Default", 'mybooktable'), "summary" => __("Summary", 'mybooktable'), "buybuttons" => __("Buy Buttons", 'mybooktable'), "cover+buybuttons" => __("Cover and Buy Buttons", 'mybooktable'))
354 ),
355 'buybutton_shadowbox' => array(
356 'title' => 'Force Shadow Box for Buy Buttons?',
357 'default' => false,
358 'type' => 'checkbox',
359 'description' => ''
360 )
361 )
362 ),
363 'mybooktable-list' => array(
364 'title' => __('All Terms in Taxonomy', 'mybooktable'),
365 'description' => __('This allows you to display all of the different items in a MyBookTable taxonomy.', 'mybooktable'),
366 'settings' => array(
367 'list' => array(
368 'title' => __('Taxonomy', 'mybooktable'),
369 'description' => '',
370 'type' => 'dropdown',
371 'choices' => array("series" => __("Series", 'mybooktable'), "genres" => __("Genres", 'mybooktable'), "tags" => __("Tags", 'mybooktable'), "authors" => __("Authors", 'mybooktable'))
372 ),
373 'display' => array(
374 'title' => __('Display Style', 'mybooktable'),
375 'description' => '',
376 'type' => 'dropdown',
377 'choices' => array("listing" => __("Listing", 'mybooktable'), "bar" => __("Menu Bar", 'mybooktable'), "simple" => __("Simple", 'mybooktable'))
378 )
379 )
380 )
381 ));
382
383 return $shortcodes;
384 }
385
386
387
388 /*---------------------------------------------------------*/
389 /* Author Media Shortcode Inserter */
390 /*---------------------------------------------------------*/
391
392 if(!function_exists('load_authormedia_shortcode_inserter')) {
393 add_action('init', 'load_authormedia_shortcode_inserter');
394 function load_authormedia_shortcode_inserter() {
395 remove_action('admin_init', 'authormedia_setup_shortcode_inserter');
396 add_action('admin_init', apply_filters('authormedia_shortcode_inserter_setup_func', '__return_null'));
397 }
398 }
399
400 add_filter('authormedia_shortcode_inserter_setup_func', 'mbt_authormedia_shortcode_inserter_setup_func', 1);
401 function mbt_authormedia_shortcode_inserter_setup_func() {
402 return 'mbt_setup_authormedia_shortcode_inserter';
403 }
404
405 function mbt_setup_authormedia_shortcode_inserter() {
406 if((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing') == 'true') {
407 if( isset($_SERVER['PHP_SELF']) && in_array(basename($_SERVER['PHP_SELF']), array('post.php', 'page.php', 'page-new.php', 'post-new.php'))) {
408 add_filter('media_buttons', 'mbt_authormedia_shortcode_inserter_button', 30);
409 add_action('admin_footer', 'mbt_authormedia_shortcode_inserter_form');
410 }
411 }
412 }
413
414 function mbt_authormedia_shortcode_inserter_button($buttons) {
415 echo '<a href="#TB_inline?width=480&inlineId=authormedia-insert-shortcode" class="thickbox button authormedia-insert-shortcode-button"><span class="authormedia-insert-shortcode-icon"></span>Insert Shortcode</a>';
416 }
417
418 function mbt_authormedia_shortcode_inserter_form() {
419 $shortcode_sections = apply_filters('authormedia_get_shortcodes', array());
420 ?>
421 <script type="text/javascript">
422 function authormedia_insert_shortcode() {
423 var active_item = jQuery('.authormedia-shortcode-section .shortcode-menu-item.active');
424 var shortcode_full = active_item.data('shortcode');
425 if(shortcode_full == '') {
426 alert('Please select a shortcode', 'mybooktable');
427 return;
428 }
429
430 shortcode_tag = shortcode_full.split('-')[0];
431
432 var attrs = {};
433 jQuery('#authormedia_shortcode_form_' + shortcode_full + ' .authormedia_shortcode_field').each(function(){
434 if('checkbox' == jQuery(this).attr('type')) {
435 attrs[jQuery(this).attr('name')] = jQuery(this).is(':checked');
436 } else if('radio' == jQuery(this).attr('type')) {
437 if(jQuery(this).is(':checked')) { attrs[jQuery(this).attr('name')] = jQuery(this).val(); }
438 } else if(jQuery(this).val()) {
439 attrs[jQuery(this).attr('name')] = jQuery(this).val();
440 }
441 });
442
443 if(window.authormedia_shortcode_form_events) {
444 window.authormedia_shortcode_form_events.trigger('pre-insert', shortcode_full, attrs);
445 window.authormedia_shortcode_form_events.trigger('pre-insert:'+shortcode_full, attrs);
446 }
447
448 if(attrs["content"] > "") {
449 var setcontent = attrs["content"];
450 delete(attrs["content"]);
451 shortcode = new wp.shortcode({
452 tag: shortcode_tag,
453 attrs: attrs,
454 type: 'closed',
455 content: setcontent
456 });
457 } else {
458 shortcode = new wp.shortcode({
459 tag: shortcode_tag,
460 attrs: attrs,
461 type: 'single'
462 });
463 }
464
465 if(window.authormedia_shortcode_form_events) {
466 window.authormedia_shortcode_form_events.trigger('insert', shortcode_full, shortcode);
467 window.authormedia_shortcode_form_events.trigger('insert:'+shortcode_full, shortcode);
468 }
469
470 if(window.send_to_editor) {
471 window.send_to_editor(shortcode.string());
472 }
473 }
474
475 jQuery(document).ready(function() {
476 jQuery('.shortcode-modal-close').on('click', function(e){
477 e.preventDefault();
478 tb_remove();
479 });
480
481 jQuery('.authormedia-shortcode-section .shortcode-menu-item').on('click', function() {
482 jQuery('.authormedia-shortcode-section .shortcode-menu-item').removeClass('active');
483 jQuery(this).addClass('active');
484 jQuery('.authormedia_shortcode_form_atts').css('display', 'none');
485 jQuery('#authormedia_shortcode_form_' + jQuery(this).data('shortcode')).css('display', 'block');
486 });
487
488 jQuery('.authormedia-shortcode-section-nav .nav-tab-wrapper a').on('click', function() {
489 jQuery('.authormedia-shortcode-section-nav .nav-tab-wrapper a').removeClass('nav-tab-active');
490 jQuery(this).addClass('nav-tab-active');
491 jQuery('.authormedia-shortcode-section').css('display', 'none');
492 jQuery('#authormedia_shortcode_section_' + jQuery(this).attr('data-shortcode-section') ).css('display', 'block');
493 });
494 jQuery('.authormedia-shortcode-section-nav .nav-tab-wrapper a')[0].click();
495
496 window.authormedia_shortcode_form_events = _.extend({}, Backbone.Events);
497 });
498 </script>
499
500 <div id="authormedia-insert-shortcode" style="display:none;">
501 <div class="authormedia-insert-shortcode-container">
502 <a class="media-modal-close shortcode-modal-close" href="#" title="<?php esc_attr_e('Close', 'mybooktable'); ?>">
503 <span class="media-modal-icon"></span>
504 </a>
505 <div class="authormedia-shortcode-section-nav">
506 <h2 class="nav-tab-wrapper">
507 <?php
508 foreach($shortcode_sections as $section_id => $section) {
509 echo('<a href="#" class="nav-tab" data-shortcode-section="'.esc_attr($section_id).'">'.esc_attr($section['name']).'</a>');
510 }
511 ?>
512 </h2>
513 </div>
514
515 <?php foreach($shortcode_sections as $section_id => $section) { ?>
516 <?php $shortcodes = $section['shortcodes']; ?>
517 <div class="media-modal-content authormedia-shortcode-section" id="authormedia_shortcode_section_<?php echo(esc_attr($section_id)); ?>">
518 <div class="media-frame wp-core-ui">
519 <div class="media-frame-menu">
520 <div class="media-menu">
521 <?php
522 foreach ( $shortcodes as $shortcode => $atts ) {
523 echo '<a href="#" class="media-menu-item shortcode-menu-item" data-shortcode="' . esc_attr( $shortcode ) . '">' . esc_html( $atts['title'] ) . "</a>";
524 }
525 ?>
526 </div>
527 </div>
528 <div class="media-frame-title">
529 <h1><?php esc_attr_e('Insert a Shortcode', 'mybooktable'); ?></h1>
530 </div>
531 <div class="media-frame-router"></div>
532 <div class="media-frame-content">
533 <div id="authormedia_shortcode_form_intro" class="authormedia_shortcode_form_atts">
534 <?php esc_attr_e('To get started, select a shortcode from the list on the left.', 'mybooktable'); ?>
535 </div>
536 <?php foreach ( $shortcodes as $shortcode => $atts ): ?>
537 <div id="authormedia_shortcode_form_<?php echo esc_attr($shortcode); ?>" class="authormedia_shortcode_form_atts" style="display:none">
538 <?php if ( !empty($atts['description']) ) { ?>
539 <div class="authormedia_shortcode_description">
540 <?php echo esc_html($atts['description']); ?>
541 </div>
542 <?php } ?>
543 <?php if ( empty($atts['settings']) ) { ?>
544 <div style="margin:1em">This shortcode has no options, you can insert it directly.</div>
545 <?php } else { ?>
546 <?php foreach ( $atts['settings'] as $setting => $params ) {
547 echo '<div style="margin:1em">';
548 switch ( $params['type'] ) {
549 case 'dropdown':
550 global $_wp_additional_image_sizes;
551 if ( ! empty($params['title']) ) echo wp_kses_post("<label for='authormedia_{$shortcode}_field_$setting'>$params[title]</label><br>");
552 if ( ! empty($params['choices']) ) {
553 echo wp_kses_post("<select class='authormedia_shortcode_field' id='authormedia_{$shortcode}_field_$setting' name='$setting' style='max-width:440px;'>");
554 foreach ( $params['choices'] as $slug => $name ) {
555 echo wp_kses_post("<option value='$slug'>$name</option>");
556 }
557 echo "</select>";
558 }
559 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
560 break;
561 case 'thumbsize':
562 global $_wp_additional_image_sizes;
563 if ( ! empty($params['title']) ) echo wp_kses_post("<label for='authormedia_{$shortcode}_field_$setting'>$params[title]</label><br>");
564 echo wp_kses_post("<select class='authormedia_shortcode_field' id='authormedia_{$shortcode}_field_$setting' name='$setting'>");
565 echo "<option value=''>(default)</option>";
566 foreach ( $_wp_additional_image_sizes as $name => $atts ) {
567 echo wp_kses_post("<option value='$name'>$name ($atts[width] x $atts[height])</option>");
568 }
569 echo wp_kses_post("</select>");
570 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
571 break;
572 case 'checkboxes':
573 #!! we need to output a list of checkboxes and on saving, comma-delimit them
574 break;
575 case 'checkbox':
576 echo wp_kses_post("<input type='checkbox' class='authormedia_shortcode_field' id='authormedia_{$shortcode}_field_$setting' name='$setting' ".(empty($params['default']) ? '' : 'checked="checked"').">");
577 if ( ! empty($params['title']) ) echo wp_kses_post(" <label for='authormedia_{$shortcode}_field_$setting'>$params[title]</label>");
578 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
579 break;
580 case 'radio':
581 if ( ! empty($params['title']) ) echo esc_attr($params['title']);
582 if ( ! empty($params['choices']) ) {
583 echo '<ul style="margin-left:2em">';
584 foreach( $params['choices'] as $key => $value ) {
585 echo wp_kses_post("<li><input type='radio' class='authormedia_shortcode_field' id='authormedia_{$shortcode}_field_{$setting}_{$key}' name='$setting' value='$key'>");
586 echo wp_kses_post(" <label for='authormedia_{$shortcode}_field_{$setting}_{$key}'>$value</label></li>");
587 }
588 echo '</ul>';
589 }
590 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
591 break;
592 case 'content':
593 case 'textarea':
594 if ( ! empty($params['title']) ) {
595 echo wp_kses_post("<label for='authormedia_{$shortcode}_field_$setting'>$params[title]");
596 if ( ! empty($params['default']) ) echo wp_kses_post(" <em>(default: $params[default])</em>");
597 echo "</label><br>";
598 }
599 echo wp_kses_post("<textarea class='authormedia_shortcode_field' id='authormedia_{$shortcode}_field_$setting' name='$setting' rows='5' cols='40'></textarea>");
600 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
601 break;
602 case 'text':
603 if ( ! empty($params['title']) ) {
604 echo wp_kses_post("<label for='authormedia_{$shortcode}_field_$setting'>$params[title]");
605 if ( ! empty($params['default']) ) echo wp_kses_post(" <em>(default: $params[default])</em>");
606 echo "</label><br>";
607 }
608 echo wp_kses_post("<input type='text' class='authormedia_shortcode_field' id='authormedia_{$shortcode}_field_$setting' name='$setting'>");
609 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
610 break;
611 case 'number':
612 if ( ! empty($params['title']) ) {
613 echo wp_kses_post("<label for='authormedia_{$shortcode}_field_$setting'>$params[title]");
614 if ( ! empty($params['default']) ) echo wp_kses_post(" <em>(default: $params[default])</em>");
615 echo "</label><br>";
616 }
617 echo wp_kses_post("<input type='text' class='authormedia_shortcode_field' id='authormedia_{$shortcode}_field_$setting' name='$setting'>");
618 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
619 break;
620 case '':
621 default:
622 if ( ! empty($params['title']) ) {
623 echo wp_kses_post("<label for='authormedia_shortcode_field_$setting'>$params[title]");
624 if ( ! empty($params['default']) ) echo wp_kses_post(" <em>(default: $params[default])</em>");
625 echo "</label><br>";
626 }
627 echo wp_kses_post('input type="' . $params['type'] . '" name="' . $setting . '"');
628 if ( ! empty($params['description']) ) echo wp_kses_post('<div class="description">' . $params['description'] . '</div>');
629 }
630 echo '</div>';
631 } ?>
632 <?php } ?>
633 <?php if(!empty($atts['pre-insert'])) { ?>
634 <script type="text/javascript">
635 jQuery(document).ready(function() { window.authormedia_shortcode_form_events.on('pre-insert:<?php echo(wp_kses_post($shortcode)); ?>', function(attrs) { <?php echo(wp_kses_post($atts['pre-insert']));?> }); });
636 </script>
637 <?php } ?>
638 </div>
639 <?php endforeach; ?>
640 </div>
641 <div class="media-frame-toolbar">
642 <div class="media-toolbar">
643 <div class="media-toolbar-secondary">
644 <a class="button media-button button-large button-cancel" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"><?php esc_attr_e("Cancel", 'mybooktable'); ?></a>
645 </div>
646 <div class="media-toolbar-primary">
647 <input type="button" class="button media-button button-primary button-large button-insert" value="<?php esc_attr_e('Insert Shortcode', 'mybooktable'); ?>" onclick="authormedia_insert_shortcode();"/>
648 </div>
649 </div></div>
650 </div>
651 </div>
652 <?php } ?>
653 </div>
654 </div>
655
656 <?php
657 }
658