-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
664 lines (556 loc) · 18 KB
/
bootstrap.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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
<?php
/**
* TS Shortcode generator core
*
* @tsframework
* @ ver 1.0
*
* Author: Sohan Zaman (Theme Stones)
*/
if( !defined( 'TS_SCG_PATH' ) ) {
define( 'TS_SCG_PATH', plugin_dir_path( __FILE__ ) );
}
if( !defined( 'TS_SCG_URL' ) ) {
define( 'TS_SCG_URL', plugins_url( __FILE__ ) );
}
if( !class_exists( 'TS_Shortcode_Generator' ) ) :
class TS_Shortcode_Generator {
public $name = '';
public $version = 1.0;
public $url = '';
public $template;
public $title;
public $icon;
/**
* TS_Shortcode_Generator::__construct()
* Used as constructor
*
* @args - array of accepted arguments
*
* @return void
*/
public function __construct( $args ) {
global $ts_shortcode_generator_instances;
if( !is_array( $ts_shortcode_generator_instances ) ) {
$ts_shortcode_generator_instances = array();
}
$args = wp_parse_args( $args, array(
'name' => 'ts_shortcode_generator',
'title' => __( 'TS Shortcode Generator', 'ts_core' ),
'template' => null,
'author' => 'Theme Stones',
'website' => 'http://themestones.net/',
'icon' => TS_SCG_URL . '/assets/img/icon.png',
'version' => 1.0
));
$this->name = $args['name'];
$this->version = $args['version'];
$this->url = TS_SCG_PATH;
$this->template = $args['template'];
$this->title = $args['title'];
$this->icon = $args['icon'];
unset( $args['template'] );
$ts_shortcode_generator_instances[] = $args;
add_filter( 'tiny_mce_version', array( $this, 'ts_change_tmc_version' ) );
add_action( 'init', array( $this, 'ts_add_generator_buttons' ) );
add_action( 'wp_ajax_ts_shortcode_generator_' . $this->name , array( $this, 'ts_ajax_tinymce_callback' ) );
add_action( 'wp_ajax_ts_ajax_module_view_' . $this->name , array( $this, 'ts_ajax_module_view_callback' ) );
}
/**
* TS_Shortcode_Generator::ts_add_generator_buttons()
* We will add the button using the function
*
* @return void
*/
public function ts_add_generator_buttons() {
if( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) {
return;
}
if( get_user_option('rich_editing') == 'true' ) {
add_filter( 'mce_external_plugins', array( &$this, 'ts_add_tmc_plugin' ), 5 );
add_filter( 'mce_buttons', array( &$this, 'ts_register_button' ), 5 );
}
}
/**
* TS_Shortcode_Generator::ts_register_button()
* Push the button into the array
*
* @return void
*/
public function ts_register_button( $buttons ) {
global $ts_mce_activated;
$ts_mce_activated = true;
array_push( $buttons, 'separator', $this->name );
return $buttons;
}
/**
* TS_Shortcode_Generator::ts_add_tmc_plugin()
* Include our js file as a plugin of tinyMCE
*
* @return void
*/
public function ts_add_tmc_plugin( $plugin_array ) {
$plugin_array['ts_sc_generator'] = TS_SCG_URL . '/assets/js/core.js';
$plugin_array[$this->name] = TS_SCG_URL . '/assets/js/plugin-empty.js';
return $plugin_array;
}
/**
* TS_Shortcode_Generator::ts_change_tmc_version()
* We should change the version of tinyMCE after adding our plugin
*
* @return void
*/
public function ts_change_tmc_version( $version ) {
$version = $version + $this->version;
return $version;
}
/**
* TS_Shortcode_Generator::ts_ajax_tinymce_callback()
* The ajax action which is called for initialization
* This action will fetch the popup canvas markup
*
* @return html
*/
public function ts_ajax_tinymce_callback() {
if( !current_user_can('edit_pages') && !current_user_can('edit_posts') ) {
die( __( 'You do not have rights to do this!', 'ts_core' ) );
}
$template = $this->template;
require_once( TS_SCG_PATH . '/views/popup.php' );
die();
}
/**
* TS_Shortcode_Generator::ts_ajax_module_view_callback()
* The ajax action called for fetching and parsing template
* This action will fetch the template array and apply conversion on it
*
* @return html
*/
public function ts_ajax_module_view_callback() {
if ( !current_user_can('edit_pages') && !current_user_can('edit_posts') ) {
die( __( 'You do not have rights to do this!', 'ts_core' ) );
}
$template = $this->template;
$shortcodes = array();
foreach( $template as $x => $group ) {
foreach( $group['shortcodes'] as $i => $tag_args ) {
$shortcodes[$tag_args['tag'] . '_' . $x . $i] = $tag_args;
}
}
$requested = $_REQUEST['ts_tag'];
$this->tsg_parse_field_view_circle_head( $shortcodes[$requested] );
die();
}
/**
* TS_Shortcode_Generator::tsg_parse_field_view_circle_head()
* Takes php array and converts it to html markup
*
* @return html
*/
public function tsg_parse_field_view_circle_head( $args ) {
$add_more_txt = sprintf( __( 'Add more %s', 'ts_core' ), $args['title'] );
$remove_this_txt = sprintf( __( 'Remove this %s', 'ts_core' ), $args['title'] );
$root_atts = array();
$root_classes = array();
$root_classes[] = 'ts-scg-shortcode-item-root';
$root_atts[] = sprintf( 'data-shortcode-tag="%s"', esc_attr( $args['tag'] ) );
if( isset( $args['repeatable'] ) && $args['repeatable'] == true ) {
$root_atts[] = 'data-repeat="true"';
$repeatable_footer = sprintf( '<input type="button" class="repeat-add button" value="%s">', $add_more_txt );
$root_classes[] = 'tsg-repeatable-module';
$repeatable_header = '<div class="tsg-repeatable-remover"><i class="fa fa-times"></i></div>';
} else {
$root_atts[] = 'data-repeat="false"';
$repeatable_footer = '';
$repeatable_header = '';
}
if( isset( $args['sortable'] ) && $args['sortable'] == true ) {
$root_atts[] = 'data-sortable="true"';
$sortable_handle = sprintf( '<div title="%s" class="tsg-sorter-handle"><i class="fa fa-arrows"></i></div><div class="tsg-sorter-collapse"><i class="fa fa-bars"></i></div>', $remove_this_txt );
$root_classes[] = 'tsg-sortable-module';
} else {
$root_atts[] = 'data-sortable="false"';
$sortable_handle = '';
}
if( isset( $args['selftag'] ) && $args['selftag'] == true ) {
$root_atts[] = 'data-no-ending-tag="true"';
$root_classes[] = 'tsg-selftag-module';
} else {
$root_atts[] = 'data-no-ending-tag="false"';
}
if( isset( $args['content'] ) ) {
if( is_array( $args['content'] ) ) {
if( isset( $args['content']['tag'] ) ) {
$root_atts[] = 'data-content="shortcode"';
} else {
$root_atts[] = 'data-content="mixed"';
}
} else {
$root_atts[] = sprintf( 'data-content="%s"', esc_attr( $args['content'] ) );
}
} else {
$root_atts[] = 'data-content="false"';
}
$root_atts[] = sprintf( 'class="%s"', esc_attr( implode( ' ', $root_classes ) ) );
if( isset( $args['nomore'] ) && $args['nomore'] == 'true' ) {
foreach( $args['atts'] as $attr_index => $attr_args ) {
if( isset( $attr_args['advanced'] ) && $attr_args['advanced'] == 'true' ) {
unset( $args['atts'][ $attr_index ] );
}
}
}
?>
<div <?php echo implode( ' ', $root_atts ); ?>>
<div class="tsg-modules-wrapper">
<div class="tsg-module-inner">
<div class="tsg-shortcode-main-title">
<span class="label"><?php echo $args['title']; ?></span>
<span class="desc"><?php echo $args['desc']; ?></span>
<?php echo $repeatable_header; ?>
</div>
<?php if( isset( $args['atts'] ) && !isset( $args['noatts'] ) ) { ?>
<div class="ts-scg-shortcode-item-atts">
<?php foreach( $args['atts'] as $name => $atts_args ) {
$atts_args['parent_tag'] = $args['tag'];
$this->tsg_get_attr_field_elems( $name, $atts_args );
} ?>
<div class="ts-scg-shortcode-item-more-atts tsg-more-atts-closed">More <i class="fa fa-angle-double-down"></i><i class="fa fa-angle-double-up"></i></div>
</div>
<?php }
if( isset( $args['content'] ) ) {
$cont_title = ( isset( $args['content_title'] ) ? $args['content_title'] : __( 'Contents', 'ts_core' ) );
$cont_desc = ( isset( $args['content_desc'] ) ? $args['content_desc'] : __( 'Insert your contents from here', 'ts_core' ) );
?>
<div class="ts-scg-shortcode-item-content">
<div class="tsg-shortcode-main-title">
<span class="label"><?php echo $cont_title; ?></span>
<span class="desc"><?php echo $cont_desc; ?></span>
</div>
<?php
if( is_array( $args['content'] ) ) {
if( isset( $args['content']['tag'] ) ) {
$this->tsg_parse_field_view_circle_tale( $args['content'] );
} else {
foreach( $args['content'] as $mx_content ) {
if( is_array( $mx_content ) ) {
echo '<div class="tsg-mixed-shortcode-content-module" data-type="shortcode">';
$this->tsg_parse_field_view_circle_tale( $mx_content );
} else {
echo sprintf( '<div class="tsg-mixed-shortcode-content-module" data-type="%s">', $mx_content );
?>
<div class="tsg-shortcode-content-field">
<?php require( dirname(__FILE__) . sprintf( '/views/fields/%s.php', $mx_content ) ); ?>
</div>
<?php
}
echo '</div>';
}
}
} else {
?>
<div class="tsg-shortcode-content-field">
<?php require( dirname(__FILE__) . sprintf( '/views/fields/%s.php', $args['content'] ) ); ?>
</div>
<?php } ?>
</div>
<?php }
echo $sortable_handle; ?>
</div>
</div>
<?php echo $repeatable_footer; ?>
</div>
<?php
}
/**
* TS_Shortcode_Generator::tsg_parse_field_view_circle_tale()
* Alias of ::tsg_parse_field_view_circle_head()
*
* @return html
*/
public function tsg_parse_field_view_circle_tale( $args ) {
$this->tsg_parse_field_view_circle_head( $args );
}
/**
* TS_Shortcode_Generator::tsg_get_attr_field_elems()
* Used only on attribute fields
*
* @return html
*/
public function tsg_get_attr_field_elems( $name, $args, $sbs = true ) {
$def_root = $args['default'];
$field_type = $args['type'];
if( $sbs ) {
$layout_class = ' normal-sbs-view';
} else {
$layout_class = '';
}
if( isset( $args['advanced'] ) && $args['advanced'] == true ) {
$layout_class .= ' ts-shortcode-advanced-atts';
}
if( isset( $args['default'] ) ) {
$data_def = '';
$data_def .= ( is_array( $args['default'] ) ? implode( ', ', $args['default'] ) : $args['default'] );
if( $def_root == false && $field_type == 'toggle' ) {
$data_def = 'no';
} elseif( $def_root == true && $field_type == 'toggle' ) {
$data_def = 'yes';
}
} else {
$data_def = '';
}
?>
<div data-attr-default="<?php echo esc_attr( $data_def ); ?>" data-field-type="<?php echo esc_attr( $field_type ); ?>" data-attr-name="<?php echo esc_attr( $name ) ?>" class="ts-scg-attr-item<?php echo $layout_class; ?>">
<div class="ts-scg-attr-item-label">
<span class="label"><?php echo $args['title'] ?></span>
<?php if( $args['desc'] ) { ?>
<span class="desc"><?php echo $args['desc'] ?></span>
<?php } ?>
</div>
<div class="ts-scg-attr-item-value">
<?php require( dirname(__FILE__) . '/views/fields/' . $field_type . '.php' ); ?>
</div>
</div>
<?php
}
}
endif;
/**
* Required function ts_generator_add_dummy_elements()
*
* Adds dummy element to the DOM
*
* DO NOT REMOVE OR MODIFY THIS FUNCTION
*
* return void
*/
add_action( 'admin_footer', 'ts_generator_add_dummy_elements', 999 );
if( !function_exists( 'ts_generator_add_dummy_elements' ) ) {
function ts_generator_add_dummy_elements() {
global $ts_mce_activated;
if( $ts_mce_activated !== true ) {
return;
}
echo '<div id="ts-generator-overlay"><div class="tsg-loader ts-animated ts-animate-loader"></div></div><div id="ts-generator-root"></div>';
}
}
/**
* Required function ts_generator_scripts_styles()
*
* Enqueue required scripts and styles
*
* DO NOT REMOVE OR MODIFY THIS FUNCTION
*
* return void
*/
add_action( 'admin_enqueue_scripts', 'ts_generator_scripts_styles' );
if( !function_exists( 'ts_generator_scripts_styles' ) ) {
function ts_generator_scripts_styles() {
global $ts_shortcode_generator_instances;
if( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) {
return;
}
if( get_user_option('rich_editing') != 'true' ) {
return;
}
if( ! wp_script_is( 'mce-view' ) ) {
return;
}
wp_enqueue_style( 'ts-generator-styles', TS_SCG_URL . '/assets/css/generator.css', '1.0' );
wp_enqueue_style( 'ts-font-awesome', TS_SCG_URL . '/assets/css/font-awesome.min.css', '4.4.0' );
wp_enqueue_style( 'ts-select2-css', TS_SCG_URL . '/assets/css/select2.css', '1.1' );
wp_enqueue_style( 'ts-bootstrap-colorpicker-css', TS_SCG_URL . '/assets/css/bootstrap-colorpicker.min.css', '1.1' );
wp_register_script( 'ts-kia-metabox', TS_SCG_URL . '/assets/js/kia-metabox.js', array( 'jquery' ), '1.0', true );
wp_register_script( 'ts-bootstrap-colorpicker', TS_SCG_URL . '/assets/js/bootstrap-colorpicker.min.js', array( 'jquery' ), '1.0', true );
wp_register_script( 'ts-select2', TS_SCG_URL . '/assets/js/select2.min.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'ts-generator-scripts', TS_SCG_URL . '/assets/js/generator.js', array( 'jquery', 'ts-bootstrap-colorpicker', 'ts-kia-metabox', 'jquery-ui-slider', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'ts-select2' ), '1.0', true );
wp_enqueue_script( 'ts-generator-localizer', TS_SCG_URL . '/assets/js/plugin-empty.js', '', '1.0', false );
wp_localize_script( 'ts-generator-localizer', 'ts_shortcode_generator_instances', $ts_shortcode_generator_instances );
}
}
/**
* Helper function ts_get_fa_icons_array()
*
* Get list of font awesome icon classes
*
* Used from files available in this framework.
* If you wish to modify this function, do not delete the files inside. They are used to print icons in the UI.
*
* return array()
*/
if( !function_exists( 'ts_get_fa_icons_array' ) ) :
function ts_get_fa_icons_array() {
$pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s*{\s*content/';
$subject = file_get_contents( TS_SCG_URL . '/assets/css/font-awesome.css' );
preg_match_all( $pattern, $subject, $matches, PREG_SET_ORDER );
$icons = array();
foreach( $matches as $match ) {
$icons[] = $match[1];
}
return $icons;
}
endif;
/**
* Helper function return_terms_for_tsg_template()
*
* Get list of all terms of certain taxonomy
*
* @param taxonomy name default "category"
* @param return id? default true, use false to return slug
*
* return array()
*/
if( !function_exists('return_terms_for_tsg_template') ) :
function return_terms_for_tsg_template( $tax = 'category', $id = true ) {
$terms = get_terms( $tax, array( 'hide_empty' => true) );
$output = array();
foreach( $terms as $term ) {
$output[] = array(
'val' => ( $id ? $term->term_id : $term->slug ),
'label' => $term->name . ' (' . $term->count . ')',
);
}
return $output;
}
endif;
/**
* Helper function return_posts_for_tsg_template()
*
* Get list of all posts
*
* @param post type default "post"
* @param return id? default true, use false to return post title
*
* return array()
*/
if( !function_exists('return_posts_for_tsg_template') ) :
function return_posts_for_tsg_template( $type = 'post', $id = true ) {
$posts = get_posts( array(
'posts_per_page' => -1,
'post_type' => $type,
'post_status' => 'publish',
));
$output = array();
foreach( $posts as $post ) {
$output[] = array(
'val' => ( $id ? $post->ID : $post->post_name ),
'label' => $post->post_title,
);
}
return $output;
}
endif;
/**
* Helper function ts_return_cf7_array_for_scg()
*
* Get available contact form names for Contact Form 7 plugin
*
* return array()
*/
if( !function_exists( 'ts_return_cf7_array_for_scg' ) ) {
function ts_return_cf7_array_for_scg() {
$args = array(
'post_type' => 'wpcf7_contact_form',
'posts_per_page' => -1
);
$forms = get_posts( $args );
$output = array();
if( $forms ) {
foreach( $forms as $form ) {
$output[] = array(
'val' => $form->post_title,
'label' => $form->post_title,
);
}
}
return $output;
}
}
/**
* Helper function return_wc_attributes_for_tsg_template()
*
* Get product attributes for WooCommerce plugin
*
* return array()
*/
if( !function_exists('return_wc_attributes_for_tsg_template') ) :
function return_wc_attributes_for_tsg_template() {
global $wpdb;
$prefix = $wpdb->prefix;
$taxonomies = $wpdb->get_results( 'SELECT * FROM ' . $prefix . 'woocommerce_attribute_taxonomies' );
$output = array();
if( $taxonomies ) {
foreach( $taxonomies as $taxonomy ) {
$array = get_object_vars( $taxonomy );
$label = $array['attribute_label'];
$slug = $array['attribute_name'];
$terms = get_terms( 'pa_' . $slug, array( 'hide_empty' => true) );
$add = array();
$add['label'] = $label == '' ? $slug : $label;
$add['opts'] = array();
foreach( $terms as $term ) {
$add_opt = array(
'val' => $term->slug,
'label' => $term->name,
);
$add['opts'][] = $add_opt;
}
$output[] = $add;
}
}
return $output;
}
endif;
/**
* Helper function ts_get_css3_intro_animations()
*
* Get classes for animate.css if you want to use it
*
* return array()
*/
if( !function_exists('ts_get_css3_intro_animations') ) :
function ts_get_css3_intro_animations() {
$output = array();
$anims = array(
'',
'bounceIn',
'bounceInDown',
'bounceInLeft',
'bounceInRight',
'bounceInUp',
'fadeIn',
'fadeInDown',
'fadeInDownBig',
'fadeInLeft',
'fadeInLeftBig',
'fadeInRight',
'fadeInRightBig',
'fadeInUp',
'fadeInUpBig',
'flipInX',
'flipInY',
'rotateIn',
'rotateInDownLeft',
'rotateInDownRight',
'rotateInUpLeft',
'rotateInUpRight',
'slideInUp',
'slideInDown',
'slideInLeft',
'slideInRight',
'zoomIn',
'zoomInDown',
'zoomInLeft',
'zoomInRight',
'zoomInUp',
'rollIn',
'lightSpeedIn',
);
foreach( $anims as $anim ) {
$add = array();
$add['val'] = $anim;
$add['label'] = $anim;
$output[] = $add;
}
return $output;
}
endif;