PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.64
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.64
1.2.76 1.2.75 1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 All 176 releases
userswp / vendor / ayecode / wp-super-duper / wp-super-duper.php

wp-super-duper.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.64, at vendor/ayecode/wp-super-duper/wp-super-duper.php

5,519 lines 193.6 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
6 if ( ! class_exists( 'WP_Super_Duper' ) ) {
7
8 define( 'SUPER_DUPER_VER', '1.2.32' );
9
10 /**
11 * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
12 *
13 * Should not be called direct but extended instead.
14 *
15 * Class WP_Super_Duper
16 * @since 1.0.16 change log moved to file change-log.txt - CHANGED
17 * @ver 1.1.1
18 */
19 class WP_Super_Duper extends WP_Widget {
20
21 public $version = SUPER_DUPER_VER;
22 public $font_awesome_icon_version = "5.11.2";
23 public $block_code;
24 public $options;
25 public $base_id;
26 public $settings_hash;
27 public $arguments = array();
28 public $instance = array();
29 private $class_name;
30
31 /**
32 * The relative url to the current folder.
33 *
34 * @var string
35 */
36 public $url = '';
37
38 /**
39 * Take the array options and use them to build.
40 */
41 public function __construct( $options ) {
42 global $sd_widgets;
43
44 $sd_widgets[ $options['base_id'] ] = array(
45 'name' => $options['name'],
46 'class_name' => $options['class_name'],
47 'output_types' => !empty($options['output_types']) ? $options['output_types'] : array()
48 );
49 $this->base_id = $options['base_id'];
50 // lets filter the options before we do anything
51 $options = apply_filters( "wp_super_duper_options", $options );
52 $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
53 $options = $this->add_name_from_key( $options );
54 $this->options = $options;
55
56 $this->base_id = $options['base_id'];
57 $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
58
59 // nested blocks can't work as a widget
60 if(!empty($this->options['nested-block'])){
61 if(empty($this->options['output_types'])){
62 $this->options['output_types'] = array('shortcode','block');
63 }elseif (($key = array_search('widget', $this->options['output_types'])) !== false) {
64 unset($this->options['output_types'][$key]);
65 }
66 }
67
68 // init parent
69 if(empty($this->options['output_types']) || in_array('widget',$this->options['output_types'])){
70 parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
71 }
72
73
74 if ( isset( $options['class_name'] ) ) {
75 // register widget
76 $this->class_name = $options['class_name'];
77
78 // register shortcode, this needs to be done even for blocks and widgets
79 $this->register_shortcode();
80
81
82 // Fusion Builder (avada) support
83 if ( function_exists( 'fusion_builder_map' ) ) {
84 add_action( 'init', array( $this, 'register_fusion_element' ) );
85 }
86
87 // maybe load the Bricks transformer class
88 if( class_exists('\Bricks\Elements', false) ){
89 add_action( 'init', array( $this, 'load_bricks_element_class' ) );
90 }
91
92 // register block
93 if(empty($this->options['output_types']) || in_array('block',$this->options['output_types'])){
94 add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
95 }
96 }
97
98 // add the CSS and JS we need ONCE
99 global $sd_widget_scripts;
100
101 if ( ! $sd_widget_scripts ) {
102 wp_add_inline_script( 'admin-widgets', $this->widget_js() );
103 wp_add_inline_script( 'customize-controls', $this->widget_js() );
104 wp_add_inline_style( 'widgets', $this->widget_css() );
105
106 // maybe add elementor editor styles
107 add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) );
108
109 $sd_widget_scripts = true;
110
111 // add shortcode insert button once
112 add_action( 'media_buttons', array( $this, 'wp_media_buttons' ), 1 );
113 add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
114 // generatepress theme sections compatibility
115 if ( function_exists( 'generate_sections_sections_metabox' ) ) {
116 add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) );
117 }
118
119 /* Load script on Divi theme builder page */
120 if ( ( function_exists( 'et_builder_is_tb_admin_screen' ) && et_builder_is_tb_admin_screen() ) || ( function_exists( 'et_builder_d5_enabled' ) && et_builder_d5_enabled() && isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] && et_pb_is_allowed( 'use_visual_builder' ) ) ) {
121 add_thickbox();
122 add_action( 'admin_footer', array( $this, 'shortcode_insert_button_script' ) );
123 }
124
125 if ( $this->is_preview() ) {
126 add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
127 // this makes the insert button work for elementor
128 add_action( 'elementor/editor/after_enqueue_scripts', array(
129 $this,
130 'shortcode_insert_button_script'
131 ) ); // for elementor
132 }
133 // this makes the insert button work for cornerstone
134 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) );
135
136 add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
137 add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
138
139 // add generator text to head
140 add_action( 'admin_head', array( $this, 'generator' ), 99 );
141 add_action( 'wp_head', array( $this, 'generator' ), 99 );
142 }
143
144 do_action( 'wp_super_duper_widget_init', $options, $this );
145 }
146
147 /**
148 * Load the Bricks conversion class if we are running Bricks.
149 * @return void
150 */
151 public function load_bricks_element_class() {
152 include_once __DIR__ . '/includes/class-super-duper-bricks-element.php';
153 }
154
155 /**
156 * The register widget function
157 * @return void
158 */
159 public function _register() {
160 if(empty($this->options['output_types']) || in_array('widget',$this->options['output_types'])){
161 parent::_register();
162 }
163 }
164
165 /**
166 * Add our widget CSS to elementor editor.
167 */
168 public function elementor_editor_styles() {
169 wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) );
170 }
171
172 public function register_fusion_element() {
173
174 $options = $this->options;
175
176 if ( $this->base_id ) {
177
178 $params = $this->get_fusion_params();
179
180 $args = array(
181 'name' => $options['name'],
182 'shortcode' => $this->base_id,
183 'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square',
184 'allow_generator' => true,
185 );
186
187 if ( ! empty( $params ) ) {
188 $args['params'] = $params;
189 }
190
191 fusion_builder_map( $args );
192 }
193
194 }
195
196 public function get_fusion_params() {
197 $params = array();
198 $arguments = $this->get_arguments();
199
200 if ( ! empty( $arguments ) ) {
201 foreach ( $arguments as $key => $val ) {
202 $param = array();
203 // type
204 $param['type'] = str_replace(
205 array(
206 "text",
207 "number",
208 "email",
209 "color",
210 "checkbox"
211 ),
212 array(
213 "textfield",
214 "textfield",
215 "textfield",
216 "colorpicker",
217 "select",
218
219 ),
220 $val['type'] );
221
222 // multiselect
223 if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) {
224 $param['type'] = 'multiple_select';
225 $param['multiple'] = true;
226 }
227
228 // heading
229 $param['heading'] = isset( $val['title'] ) ? $val['title'] : '';
230
231 // description
232 $param['description'] = isset( $val['desc'] ) ? $val['desc'] : '';
233
234 // param_name
235 $param['param_name'] = $key;
236
237 // Default
238 $param['default'] = isset( $val['default'] ) ? $val['default'] : '';
239
240 // Group
241 if ( isset( $val['group'] ) ) {
242 $param['group'] = $val['group'];
243 }
244
245 // value
246 if ( $val['type'] == 'checkbox' ) {
247 if ( isset( $val['default'] ) && $val['default'] == '0' ) {
248 unset( $param['default'] );
249 }
250 $param['value'] = array( '0' => __( "No", 'ayecode-connect' ), '1' => __( "Yes", 'ayecode-connect' ) );
251 } elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) {
252 $param['value'] = isset( $val['options'] ) ? $val['options'] : array();
253 } else {
254 $param['value'] = isset( $val['default'] ) ? $val['default'] : '';
255 }
256
257 // setup the param
258 $params[] = $param;
259
260 }
261 }
262
263
264 return $params;
265 }
266
267 /**
268 * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder
269 */
270 public static function maybe_cornerstone_builder() {
271 if ( did_action( 'cornerstone_before_boot_app' ) ) {
272 self::shortcode_insert_button_script();
273 }
274 }
275
276 /**
277 * A function to ge the shortcode builder picker html.
278 *
279 * @param string $editor_id
280 *
281 * @return string
282 */
283 public static function get_picker( $editor_id = '' ) {
284
285 ob_start();
286 if ( isset( $_POST['editor_id'] ) ) {
287 $editor_id = esc_attr( $_POST['editor_id'] );
288 } elseif ( isset( $_REQUEST['et_fb'] ) ) {
289 $editor_id = 'main_content_content_vb_tiny_mce';
290 }
291
292 global $sd_widgets;
293
294 // print_r($sd_widgets);exit;
295 ?>
296
297 <div class="sd-shortcode-left-wrap">
298 <?php
299 ksort( $sd_widgets );
300 // print_r($sd_widgets);exit;
301 if ( ! empty( $sd_widgets ) ) {
302 echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
303 echo "<option>" . __( 'Select shortcode', 'ayecode-connect' ) . "</option>";
304 foreach ( $sd_widgets as $shortcode => $class ) {
305 if(!empty($class['output_types']) && !in_array('shortcode', $class['output_types'])){ continue; }
306 echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
307 }
308 echo "</select>";
309
310 }
311 ?>
312 <div class="sd-shortcode-settings"></div>
313 </div>
314 <div class="sd-shortcode-right-wrap">
315 <textarea id='sd-shortcode-output' disabled></textarea>
316 <div id='sd-shortcode-output-actions'>
317 <?php if ( $editor_id != '' ) { ?>
318 <button class="button sd-insert-shortcode-button" onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { echo "'" . $editor_id . "'"; } ?>)"><?php esc_html_e( 'Insert shortcode', 'ayecode-connect' ); ?></button>
319 <?php } ?>
320 <button class="button" onclick="sd_copy_to_clipboard()"><?php esc_html_e( 'Copy shortcode' ); ?></button>
321 </div>
322 </div>
323 <?php
324 $html = ob_get_clean();
325
326 if ( wp_doing_ajax() ) {
327 echo $html;
328 $should_die = true;
329
330 // some builder get the editor via ajax so we should not die on those occasions
331 $dont_die = array(
332 'parent_tag',// WP Bakery
333 'avia_request' // enfold
334 );
335
336 foreach ( $dont_die as $request ) {
337 if ( isset( $_REQUEST[ $request ] ) ) {
338 $should_die = false;
339 }
340 }
341
342 if ( $should_die ) {
343 wp_die();
344 }
345 } else {
346 return $html;
347 }
348
349 return '';
350 }
351
352 /**
353 * Output the version in the header.
354 */
355 public function generator() {
356 $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
357 $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
358
359 // Find source plugin/theme of SD
360 $source = array();
361 if ( strpos( $file, $plugins_dir ) !== false ) {
362 $source = explode( "/", plugin_basename( $file ) );
363 } else if ( function_exists( 'get_theme_root' ) ) {
364 $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
365
366 if ( strpos( $file, $themes_dir ) !== false ) {
367 $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
368 }
369 }
370
371 echo '<meta name="generator" content="WP Super Duper v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-sd-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />';
372 }
373
374 /**
375 * Get widget settings.
376 *
377 * @since 1.0.0
378 */
379 public static function get_widget_settings() {
380 global $sd_widgets;
381
382 $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
383 if ( ! $shortcode ) {
384 wp_die();
385 }
386 $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
387 if ( ! $widget_args ) {
388 wp_die();
389 }
390 $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
391 if ( ! $class_name ) {
392 wp_die();
393 }
394
395 // invoke an instance method
396 $widget = new $class_name;
397
398 ob_start();
399 $widget->form( array() );
400 $form = ob_get_clean();
401 echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
402 echo "<style>" . $widget->widget_css() . "</style>";
403 echo "<script>" . $widget->widget_js() . "</script>";
404 ?>
405 <?php
406 wp_die();
407 }
408
409 /**
410 * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
411 *
412 * @param string $editor_id Optional. Shortcode editor id. Default null.
413 * @param string $insert_shortcode_function Optional. Insert shortcode function. Default null.
414 *
415 *@since 1.0.0
416 *
417 */
418 public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
419 global $sd_widgets, $shortcode_insert_button_once;
420 if ( $shortcode_insert_button_once ) {
421 return;
422 }
423 add_thickbox();
424
425 /**
426 * Cornerstone makes us play dirty tricks :/
427 * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed.
428 */
429 if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
430 echo '<span id="insert-media-button">';
431 }
432
433 echo self::shortcode_button( 'this', 'true' );
434
435 // see opening note
436 if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
437 echo '</span>'; // end #insert-media-button
438 }
439
440 // Add separate script for generatepress theme sections
441 if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) {
442 } else {
443 self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
444 }
445
446 $shortcode_insert_button_once = true;
447 }
448
449 /**
450 * Gets the shortcode insert button html.
451 *
452 * @param string $id
453 * @param string $search_for_id
454 *
455 * @return mixed
456 */
457 public static function shortcode_button( $id = '', $search_for_id = '' ) {
458 ob_start();
459 ?>
460 <span class="sd-lable-shortcode-inserter">
461 <a onclick="sd_ajax_get_picker(<?php echo $id;
462 if ( $search_for_id ) {
463 echo "," . $search_for_id;
464 } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
465 class="thickbox button super-duper-content-open" title="Add Shortcode">
466 <span style="vertical-align: middle;line-height: 18px;font-size: 20px;"
467 class="dashicons dashicons-screenoptions"></span>
468 </a>
469 <div id="super-duper-content-ajaxed" style="display:none;">
470 <span>Loading</span>
471 </div>
472 </span>
473
474 <?php
475 $html = ob_get_clean();
476
477 // remove line breaks so we can use it in js
478 return preg_replace( "/\r|\n/", "", trim( $html ) );
479 }
480
481 /**
482 * Makes SD work with the siteOrigin page builder.
483 *
484 * @return mixed
485 *@since 1.0.6
486 */
487 public static function siteorigin_js() {
488 ob_start();
489 ?>
490 <script>
491 /**
492 * Check a form to see what items should be shown or hidden.
493 */
494 function sd_so_show_hide(form) {
495 jQuery(form).find(".sd-argument").each(function () {
496 var $element_require = jQuery(this).data('element_require');
497
498 if ($element_require) {
499 $element_require = $element_require.replace("&#039;", "'"); // replace single quotes
500 $element_require = $element_require.replace("&quot;", '"'); // replace double quotes
501
502 if (eval($element_require)) {
503 jQuery(this).removeClass('sd-require-hide');
504 } else {
505 jQuery(this).addClass('sd-require-hide');
506 }
507 }
508 });
509 }
510
511 /**
512 * Toggle advanced settings visibility.
513 */
514 function sd_so_toggle_advanced($this) {
515 var form = jQuery($this).parents('form,.form,.so-content');
516 form.find('.sd-advanced-setting').toggleClass('sd-adv-show');
517 return false;// prevent form submit
518 }
519
520 /**
521 * Initialise a individual widget.
522 */
523 function sd_so_init_widget($this, $selector) {
524 if (!$selector) {
525 $selector = 'form';
526 }
527 // only run once.
528 if (jQuery($this).data('sd-widget-enabled')) {
529 return;
530 } else {
531 jQuery($this).data('sd-widget-enabled', true);
532 }
533
534 var $button = '<button title="<?php _e( 'Advanced Settings', 'ayecode-connect' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>';
535 var form = jQuery($this).parents('' + $selector + '');
536
537 if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) {
538 jQuery(form).append($button);
539 }
540
541 // show hide on form change
542 jQuery(form).on("change", function () {
543 sd_so_show_hide(form);
544 });
545
546 // show hide on load
547 sd_so_show_hide(form);
548 }
549
550 jQuery(function () {
551 jQuery(document).on('open_dialog', function (w, e) {
552 setTimeout(function () {
553 if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').length) {
554 if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').val() == '1') {
555 sd_so_init_widget('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced', 'div');
556 }
557 }
558 }, 200);
559 });
560 });
561 </script>
562 <?php
563 $output = ob_get_clean();
564
565 /*
566 * We only add the <script> tags for code highlighting, so we strip them from the output.
567 */
568
569 return str_replace( array(
570 '<script>',
571 '</script>'
572 ), '', $output );
573 }
574
575 /**
576 * Output the JS and CSS for the shortcode insert button.
577 *
578 * @param string $editor_id
579 * @param string $insert_shortcode_function
580 *
581 *@since 1.0.6
582 *
583 */
584 public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
585 ?>
586 <style>
587 .sd-shortcode-left-wrap {
588 float: left;
589 width: 60%;
590 }
591
592 .sd-shortcode-left-wrap .gd-help-tip {
593 float: none;
594 }
595
596 .sd-shortcode-left-wrap .widefat {
597 border-spacing: 0;
598 width: 100%;
599 clear: both;
600 margin: 0;
601 border: 1px solid #ddd;
602 box-shadow: inset 0 1px 2px rgba(0, 0, 0, .07);
603 background-color: #fff;
604 color: #32373c;
605 outline: 0;
606 transition: 50ms border-color ease-in-out;
607 padding: 3px 5px;
608 }
609
610 .sd-shortcode-left-wrap input[type=checkbox].widefat {
611 border: 1px solid #b4b9be;
612 background: #fff;
613 color: #555;
614 clear: none;
615 cursor: pointer;
616 display: inline-block;
617 line-height: 0;
618 height: 16px;
619 margin: -4px 4px 0 0;
620 margin-top: 0;
621 outline: 0;
622 padding: 0 !important;
623 text-align: center;
624 vertical-align: middle;
625 width: 16px;
626 min-width: 16px;
627 -webkit-appearance: none;
628 box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1);
629 transition: .05s border-color ease-in-out;
630 }
631
632 .sd-shortcode-left-wrap input[type=checkbox]:checked:before {
633 content: "\f147";
634 margin: -3px 0 0 -4px;
635 color: #1e8cbe;
636 float: left;
637 display: inline-block;
638 vertical-align: middle;
639 width: 16px;
640 font: normal 21px/1 dashicons;
641 speak: none;
642 -webkit-font-smoothing: antialiased;
643 -moz-osx-font-smoothing: grayscale;
644 }
645
646 #sd-shortcode-output-actions button,
647 .sd-advanced-button {
648 color: #555;
649 border-color: #ccc;
650 background: #f7f7f7;
651 box-shadow: 0 1px 0 #ccc;
652 vertical-align: top;
653 display: inline-block;
654 text-decoration: none;
655 font-size: 13px;
656 line-height: 26px;
657 height: 28px;
658 margin: 0;
659 padding: 0 10px 1px;
660 cursor: pointer;
661 border-width: 1px;
662 border-style: solid;
663 -webkit-appearance: none;
664 border-radius: 3px;
665 white-space: nowrap;
666 box-sizing: border-box;
667 }
668
669 button.sd-advanced-button {
670 background: #0073aa;
671 border-color: #006799;
672 box-shadow: inset 0 2px 0 #006799;
673 vertical-align: top;
674 color: #fff;
675 text-decoration: none;
676 text-shadow: 0 -1px 1px #006799, 1px 0 1px #006799, 0 1px 1px #006799, -1px 0 1px #006799;
677 float: right;
678 margin-right: 3px !important;
679 font-size: 20px !important;
680 }
681
682 .sd-shortcode-right-wrap {
683 float: right;
684 width: 35%;
685 }
686
687 #sd-shortcode-output {
688 background: rgba(255, 255, 255, .5);
689 border-color: rgba(222, 222, 222, .75);
690 box-shadow: inset 0 1px 2px rgba(0, 0, 0, .04);
691 color: rgba(51, 51, 51, .5);
692 overflow: auto;
693 padding: 2px 6px;
694 line-height: 1.4;
695 resize: vertical;
696 }
697
698 #sd-shortcode-output {
699 height: 250px;
700 width: 100%;
701 }
702
703 <?php if ( function_exists( 'generate_sections_sections_metabox' ) ) { ?>
704 .generate-sections-modal #custom-media-buttons > .sd-lable-shortcode-inserter {
705 display: inline;
706 }
707 <?php } ?>
708 <?php if ( function_exists( 'et_builder_is_tb_admin_screen' ) && et_builder_is_tb_admin_screen() ) { ?>
709 body.divi_page_et_theme_builder div#TB_window.gd-tb-window{z-index:9999999}
710 <?php } ?>
711 </style>
712 <?php
713 if ( class_exists( 'SiteOrigin_Panels' ) ) {
714 echo "<script>" . self::siteorigin_js() . "</script>";
715 }
716 ?>
717 <script>
718 <?php
719 if(! empty( $insert_shortcode_function )){
720 echo $insert_shortcode_function;
721 }else{
722
723 /**
724 * Function for super duper insert shortcode.
725 *
726 * @since 1.0.0
727 */
728 ?>
729 function sd_insert_shortcode($editor_id) {
730 $shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val();
731 if ($shortcode) {
732 if (!$editor_id) {
733 <?php
734 if ( isset( $_REQUEST['et_fb'] ) ) {
735 echo '$editor_id = "#main_content_content_vb_tiny_mce";';
736 } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
737 echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
738 } else {
739 echo '$editor_id = "#wp-content-editor-container textarea";';
740 }
741 ?>
742 } else {
743 $editor_id = '#' + $editor_id;
744 }
745 tmceActive = jQuery($editor_id).attr("aria-hidden") == "true" ? true : false;
746 /* GeneratePress */
747 if (jQuery('#generate-sections-modal-dialog ' + $editor_id).length) {
748 $editor_id = '#generate-sections-modal-dialog ' + $editor_id;
749 tmceActive = jQuery($editor_id).closest('.wp-editor-wrap').hasClass('tmce-active') ? true : false;
750 }
751 if (typeof tinyMCE !== 'undefined' && tinyMCE.activeEditor && tmceActive) {
752 tinyMCE.execCommand('mceInsertContent', false, $shortcode);
753 } else {
754 var $txt = jQuery($editor_id);
755 var caretPos = $txt[0].selectionStart;
756 var textAreaTxt = $txt.val();
757 var txtToAdd = $shortcode;
758 var textareaValue = textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring(caretPos);
759 $txt.focus().val(textareaValue).change().keydown().blur().keyup().keypress().trigger('input').trigger('change');
760
761 // set Divi react input value
762 var input = document.getElementById("main_content_content_vb_tiny_mce");
763 if (input) {
764 sd_setNativeValue(input, textareaValue);
765 }
766 }
767 tb_remove();
768 }
769 }
770
771 /*
772 Set the value of elements controlled via react.
773 */
774 function sd_setNativeValue(element, value) {
775 let lastValue = element.value;
776 element.value = value;
777 let event = new Event("input", {target: element, bubbles: true});
778 // React 15
779 event.simulated = true;
780 // React 16
781 let tracker = element._valueTracker;
782 if (tracker) {
783 tracker.setValue(lastValue);
784 }
785 element.dispatchEvent(event);
786 }
787 <?php } ?>
788
789 /*
790 Copies the shortcode to the clipboard.
791 */
792 function sd_copy_to_clipboard() {
793 /* Get the text field */
794 var copyText = document.querySelector("#TB_ajaxContent #sd-shortcode-output");
795 //un-disable the field
796 copyText.disabled = false;
797 /* Select the text field */
798 copyText.select();
799 /* Copy the text inside the text field */
800 document.execCommand("Copy");
801 //re-disable the field
802 copyText.disabled = true;
803 /* Alert the copied text */
804 alert("Copied the text: " + copyText.value);
805 }
806
807 /*
808 Gets the shortcode options.
809 */
810 function sd_get_shortcode_options($this) {
811 $short_code = jQuery($this).val();
812 if ($short_code) {
813 var data = {
814 'action': 'super_duper_get_widget_settings',
815 'shortcode': $short_code,
816 'attributes': 123,
817 'post_id': 321,
818 '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
819 };
820
821 if (typeof ajaxurl === 'undefined') {
822 var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>";
823 }
824
825 jQuery.post(ajaxurl, data, function (response) {
826 jQuery('#TB_ajaxContent .sd-shortcode-settings').html(response);
827
828 jQuery('#' + $short_code).on('change', 'select', function () {
829 sd_build_shortcode($short_code);
830 }); // take care of select tags
831
832 jQuery('#' + $short_code).on('change keypress keyup', 'input,textarea', function () {
833 sd_build_shortcode($short_code);
834 });
835
836 sd_build_shortcode($short_code);
837
838 // resize the window to fit
839 setTimeout(function () {
840 jQuery('#TB_ajaxContent').css('width', 'auto').css('height', '75vh');
841 }, 200);
842
843 return response;
844 });
845 }
846 }
847
848 /*
849 Builds and inserts the shortcode into the viewer.
850 */
851 function sd_build_shortcode($id) {
852 var multiSelects = {};
853 var multiSelectsRemove = [];
854
855 $output = "[" + $id;
856
857 $form_data = jQuery("#" + $id).serializeArray();
858
859 // run checks for multiselects
860 jQuery.each($form_data, function (index, element) {
861 if (element && element.value) {
862 $field_name = element.name.substr(element.name.indexOf("][") + 2);
863 $field_name = $field_name.replace("]", "");
864 // check if its a multiple
865 if ($field_name.includes("[]")) {
866 multiSelectsRemove[multiSelectsRemove.length] = index;
867 $field_name = $field_name.replace("[]", "");
868 if ($field_name in multiSelects) {
869 multiSelects[$field_name] = multiSelects[$field_name] + "," + element.value;
870 } else {
871 multiSelects[$field_name] = element.value;
872 }
873 }
874 }
875 });
876
877 // fix multiselects if any are found
878 if (multiSelectsRemove.length) {
879
880 // remove all multiselects
881 multiSelectsRemove.reverse();
882 multiSelectsRemove.forEach(function (index) {
883 $form_data.splice(index, 1);
884 });
885
886 $ms_arr = [];
887 // add multiselets back
888 jQuery.each(multiSelects, function (index, value) {
889 $ms_arr[$ms_arr.length] = {"name": "[][" + index + "]", "value": value};
890 });
891 $form_data = $form_data.concat($ms_arr);
892 }
893
894 if ($form_data) {
895 $content = '';
896 $form_data.forEach(function (element) {
897 if (element.value) {
898 $field_name = element.name.substr(element.name.indexOf("][") + 2);
899 $field_name = $field_name.replace("]", "");
900 if ($field_name == 'html') {
901 $content = element.value;
902 } else {
903 $output = $output + " " + $field_name + '="' + element.value + '"';
904 }
905 }
906 });
907 }
908 $output = $output + "]";
909
910 // check for content field
911 if ($content) {
912 $output = $output + $content + "[/" + $id + "]";
913 }
914
915 jQuery('#TB_ajaxContent #sd-shortcode-output').html($output);
916 }
917
918 /*
919 Delay the init of the textareas for 1 second.
920 */
921 (function () {
922 setTimeout(function () {
923 sd_init_textareas();
924 }, 1000);
925 })();
926
927 /*
928 Init the textareas to be able to show the shortcode builder button.
929 */
930 function sd_init_textareas() {
931 // General textareas
932 jQuery(document).on('focus', 'textarea', function () {
933 if (jQuery(this).hasClass('wp-editor-area')) {
934 // insert the shortcode button to the textarea lable if not there already
935 if (!(jQuery(this).parent().find('.sd-lable-shortcode-inserter').length || (jQuery(this).closest('.wp-editor-wrap').length && jQuery(this).closest('.wp-editor-wrap').find('.sd-lable-shortcode-inserter').length))) {
936 jQuery(this).parent().find('.quicktags-toolbar').append(sd_shortcode_button(jQuery(this).attr('id')));
937 }
938 } else {
939 // insert the shortcode button to the textarea lable if not there already
940 if (!jQuery("label[for='" + jQuery(this).attr('id') + "']").find('.sd-lable-shortcode-inserter').length) {
941 jQuery("label[for='" + jQuery(this).attr('id') + "']").append(sd_shortcode_button(jQuery(this).attr('id')));
942 }
943 }
944 });
945
946 // The below tries to add the shortcode builder button to the builders own raw/shortcode sections.
947 <?php if ( function_exists( 'et_setup_theme' ) ) { ?>
948 // DIVI
949 jQuery(document).on('focusin', '.et-fb-codemirror', function () {
950 // insert the shortcode button to the textarea lable if not there already
951 if (!jQuery(this).closest('.et-fb-form__group').find('.sd-lable-shortcode-inserter').length) {
952 jQuery(this).closest('.et-fb-form__group').find('.et-fb-form__label-text').append(sd_shortcode_button());
953 }
954 });
955 /* Divi 5 */
956 jQuery(document).on('focusin', '.et-vb-tinymce-html-input', function () {
957 var $etEl = jQuery(this).closest('.et-vb-field-richtext').find('.et-vb-field-richtext-buttons');
958 if (!$etEl.find('.sd-lable-shortcode-inserter').length) {
959 if ($etEl.find('.et-vb-switch-editor-mode').length) {
960 $etEl.find('.et-vb-switch-editor-mode').before(sd_shortcode_button());
961 } else {
962 $etEl.append(sd_shortcode_button());
963 }
964 }
965 });
966 jQuery(document).on('focusin', '.et-vb-code', function() {
967 var $etEl = jQuery(this).closest('.et-vb-field').find('.et-vb-field-label .et-vb-field-label-buttons');
968 if (!$etEl.find('.sd-lable-shortcode-inserter').length) {
969 $etEl.prepend(sd_shortcode_button());
970 $etEl.find('.sd-lable-shortcode-inserter').addClass('et-vb-field-button');
971 }
972 });
973 <?php } ?>
974
975 // Beaver
976 jQuery(document).on('focusin', '.fl-code-field', function () {
977 // insert the shortcode button to the textarea lable if not there already
978 if (!jQuery(this).closest('.fl-field-control-wrapper').find('.sd-lable-shortcode-inserter').length) {
979 jQuery(this).closest('.fl-field-control-wrapper').prepend(sd_shortcode_button());
980 }
981 });
982
983 // Fusion builder (avada)
984 jQuery(document).on('focusin', '.CodeMirror.cm-s-default', function () {
985 // insert the shortcode button to the textarea lable if not there already
986 if (!jQuery(this).parent().find('.sd-lable-shortcode-inserter').length) {
987 jQuery(sd_shortcode_button()).insertBefore(this);
988 }
989 });
990
991 // Avia builder (enfold)
992 jQuery(document).on('focusin', '#aviaTBcontent', function () {
993 // insert the shortcode button to the textarea lable if not there already
994 if (!jQuery(this).parent().parent().find('.avia-name-description ').find('.sd-lable-shortcode-inserter').length) {
995 jQuery(this).parent().parent().find('.avia-name-description strong').append(sd_shortcode_button(jQuery(this).attr('id')));
996 }
997 });
998
999 // Cornerstone textareas
1000 jQuery(document).on('focusin', '.cs-control.cs-control-textarea', function () {
1001 // insert the shortcode button to the textarea lable if not there already
1002 if (!jQuery(this).find('.cs-control-header label').find('.sd-lable-shortcode-inserter').length) {
1003 jQuery(this).find('.cs-control-header label').append(sd_shortcode_button());
1004 }
1005 });
1006
1007 // Cornerstone main bar
1008 setTimeout(function () {
1009 // insert the shortcode button to the textarea lable if not there already
1010 if (!jQuery('.cs-bar-btns').find('.sd-lable-shortcode-inserter').length) {
1011 jQuery('<li style="text-align: center;padding: 5px;list-style: none;">' + sd_shortcode_button() + '</li>').insertBefore('.cs-action-toggle-custom-css');
1012 }
1013 }, 2000);
1014
1015 // WP Bakery, code editor does not render shortcodes.
1016 // jQuery(document).on('focusin', '.wpb-textarea_raw_html', function () {
1017 // // insert the shortcode button to the textarea lable if not there already
1018 // if(!jQuery(this).parent().parent().find('.wpb_element_label').find('.sd-lable-shortcode-inserter').length){
1019 // jQuery(this).parent().parent().find('.wpb_element_label').append(sd_shortcode_button());
1020 // }
1021 // });
1022 }
1023
1024 /**
1025 * Gets the html for the picker via ajax and updates it on the fly.
1026 *
1027 * @param $id
1028 * @param $search
1029 */
1030 function sd_ajax_get_picker($id, $search) {
1031 if ($search) {
1032 $this = $id;
1033 $id = jQuery($this).closest('.wp-editor-wrap').find('.wp-editor-container textarea').attr('id');
1034 }
1035
1036 var data = {
1037 'action': 'super_duper_get_picker',
1038 'editor_id': $id,
1039 '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>'
1040 };
1041
1042 if (!ajaxurl) {
1043 var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
1044 }
1045
1046 jQuery.post(ajaxurl, data, function (response) {
1047 jQuery('#TB_ajaxContent').closest('#TB_window').addClass('gd-tb-window');
1048 jQuery('#TB_ajaxContent').html(response);
1049 //return response;
1050 }).then(function (env) {
1051 jQuery('body').on('thickbox:removed', function () {
1052 jQuery('#super-duper-content-ajaxed').html('');
1053 });
1054 });
1055 }
1056
1057 /**
1058 * Get the html for the shortcode inserter button depending on if a textarea id is available.
1059 *
1060 * @param $id string The textarea id.
1061 * @returns {string}
1062 */
1063 function sd_shortcode_button($id) {
1064 if ($id) {
1065 return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>';
1066 } else {
1067 return '<?php echo self::shortcode_button();?>';
1068 }
1069 }
1070 </script>
1071 <?php
1072 }
1073
1074 /**
1075 * Gets some CSS for the widgets screen.
1076 *
1077 * @param bool $advanced If we should include advanced CSS.
1078 *
1079 * @return mixed
1080 */
1081 public function widget_css( $advanced = true ) {
1082 ob_start();
1083 ?>
1084 <style>
1085 <?php if( $advanced ){ ?>
1086 .sd-advanced-setting {
1087 display: none;
1088 }
1089
1090 .sd-advanced-setting.sd-adv-show {
1091 display: block;
1092 }
1093
1094 .sd-argument.sd-require-hide,
1095 .sd-advanced-setting.sd-require-hide {
1096 display: none;
1097 }
1098
1099 button.sd-advanced-button {
1100 margin-right: 3px !important;
1101 font-size: 20px !important;
1102 }
1103
1104 <?php } ?>
1105
1106 button.sd-toggle-group-button {
1107 background-color: #f3f3f3;
1108 color: #23282d;
1109 cursor: pointer;
1110 padding: 10px;
1111 width: 100%;
1112 border: none;
1113 text-align: left;
1114 outline: none;
1115 font-size: 13px;
1116 font-weight: bold;
1117 margin-bottom: 1px;
1118 }
1119 .elementor-control .sd-argument select[multiple]{height:100px}
1120 .elementor-control .sd-argument select[multiple] option{padding:3px}
1121 </style>
1122 <?php
1123 $output = ob_get_clean();
1124
1125 /*
1126 * We only add the <script> tags for code highlighting, so we strip them from the output.
1127 */
1128
1129 return str_replace( array(
1130 '<style>',
1131 '</style>'
1132 ), '', $output );
1133 }
1134
1135 /**
1136 * Gets some JS for the widgets screen.
1137 *
1138 * @return mixed
1139 */
1140 public function widget_js() {
1141 ob_start();
1142 ?>
1143 <script>
1144
1145 /**
1146 * Toggle advanced settings visibility.
1147 */
1148 function sd_toggle_advanced($this) {
1149 var form = jQuery($this).parents('form,.form');
1150 form.find('.sd-advanced-setting').toggleClass('sd-adv-show');
1151 return false;// prevent form submit
1152 }
1153
1154 /**
1155 * Check a form to see what items should be shown or hidden.
1156 */
1157 function sd_show_hide(form) {
1158 jQuery(form).find(".sd-argument").each(function () {
1159
1160 var $element_require = jQuery(this).data('element_require');
1161
1162 if ($element_require) {
1163
1164 $element_require = $element_require.replace("&#039;", "'"); // replace single quotes
1165 $element_require = $element_require.replace("&quot;", '"'); // replace double quotes
1166
1167 if (eval($element_require)) {
1168 jQuery(this).removeClass('sd-require-hide');
1169 } else {
1170 jQuery(this).addClass('sd-require-hide');
1171 }
1172 }
1173 });
1174 }
1175
1176 /**
1177 * Initialise widgets from the widgets screen.
1178 */
1179 function sd_init_widgets($selector) {
1180 jQuery(".sd-show-advanced").each(function (index) {
1181 sd_init_widget(this, $selector);
1182 });
1183 }
1184
1185 /**
1186 * Initialise a individual widget.
1187 */
1188 function sd_init_widget($this, $selector, $form) {
1189 if (!$selector) {
1190 $selector = 'form';
1191 }
1192 // Only run once.
1193 if (jQuery($this).data('sd-widget-enabled')) {
1194 return;
1195 } else {
1196 jQuery($this).data('sd-widget-enabled', true);
1197 }
1198
1199 var $button = '<button title="<?php _e( 'Advanced Settings', 'ayecode-connect' );?>" style="line-height: 28px;" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>';
1200 var form = $form ? $form : jQuery($this).parents('' + $selector + '');
1201
1202 if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) {
1203 console.log('add advanced button');
1204 if (jQuery(form).find('.widget-control-save').length > 0) {
1205 jQuery(form).find('.widget-control-save').after($button);
1206 } else {
1207 jQuery(form).find('.sd-show-advanced').after($button);
1208 }
1209 } else {
1210 console.log('no advanced button, ' + jQuery($this).val() + ', ' + jQuery(form).find('.sd-advanced-button').length);
1211 }
1212
1213 /* Show hide on form change */
1214 jQuery(form).on("change", function() {
1215 sd_show_hide(form);
1216 });
1217
1218 /* Show hide on load */
1219 sd_show_hide(form);
1220 }
1221
1222 /**
1223 * Init a customizer widget.
1224 */
1225 function sd_init_customizer_widget(section) {
1226 if (section.expanded) {
1227 section.expanded.bind(function (isExpanding) {
1228 if (isExpanding) {
1229 // is it a SD widget?
1230 if (jQuery(section.container).find('.sd-show-advanced').length) {
1231 // init the widget
1232 sd_init_widget(jQuery(section.container).find('.sd-show-advanced'), ".form");
1233 }
1234 }
1235 });
1236 }
1237 }
1238
1239 /**
1240 * If on widgets screen.
1241 */
1242 jQuery(function () {
1243 // if not in customizer.
1244 if (!wp.customize) {
1245 sd_init_widgets("form");
1246 }
1247
1248 /* Init on widget added */
1249 jQuery(document).on('widget-added', function (e, widget) {
1250 /* Is it a SD widget? */
1251 if (jQuery(widget).find('.sd-show-advanced').length) {
1252 var widgetId = jQuery(widget).find('[name="widget-id"]').length ? ': ' + jQuery(widget).find('[name="widget-id"]').val() : '';
1253 console.log('widget added' + widgetId);
1254 /* Init the widget */
1255 sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form", jQuery(widget).find('.sd-show-advanced').closest('form'));
1256 }
1257 });
1258
1259 /* Init on widget updated */
1260 jQuery(document).on('widget-updated', function (e, widget) {
1261 /* Is it a SD widget? */
1262 if (jQuery(widget).find('.sd-show-advanced').length) {
1263 var widgetId = jQuery(widget).find('[name="widget-id"]').length ? ': ' + jQuery(widget).find('[name="widget-id"]').val() : '';
1264 console.log('widget updated' + widgetId);
1265 /* Init the widget */
1266 sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form", jQuery(widget).find('.sd-show-advanced').closest('form'));
1267 }
1268 });
1269 });
1270
1271 /**
1272 * We need to run this before jQuery is ready
1273 */
1274 if (wp.customize) {
1275 wp.customize.bind('ready', function () {
1276
1277 // init widgets on load
1278 wp.customize.control.each(function (section) {
1279 sd_init_customizer_widget(section);
1280 });
1281
1282 // init widgets on add
1283 wp.customize.control.bind('add', function (section) {
1284 sd_init_customizer_widget(section);
1285 });
1286
1287 });
1288
1289 }
1290 <?php do_action( 'wp_super_duper_widget_js', $this ); ?>
1291 </script>
1292 <?php
1293 $output = ob_get_clean();
1294
1295 /*
1296 * We only add the <script> tags for code highlighting, so we strip them from the output.
1297 */
1298
1299 return str_replace( array(
1300 '<script>',
1301 '</script>'
1302 ), '', $output );
1303 }
1304
1305
1306 /**
1307 * Set the name from the argument key.
1308 *
1309 * @param $options
1310 *
1311 * @return mixed
1312 */
1313 private function add_name_from_key( $options, $arguments = false ) {
1314 if ( ! empty( $options['arguments'] ) ) {
1315 foreach ( $options['arguments'] as $key => $val ) {
1316 $options['arguments'][ $key ]['name'] = $key;
1317 }
1318 } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1319 foreach ( $options as $key => $val ) {
1320 $options[ $key ]['name'] = $key;
1321 }
1322 }
1323
1324 return $options;
1325 }
1326
1327 /**
1328 * Register the parent shortcode.
1329 *
1330 * @since 1.0.0
1331 */
1332 public function register_shortcode() {
1333 add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1334 add_action( 'wp_ajax_super_duper_output_shortcode', array( $this, 'render_shortcode' ) );
1335 }
1336
1337 /**
1338 * Render the shortcode via ajax so we can return it to Gutenberg.
1339 *
1340 * @since 1.0.0
1341 */
1342 public function render_shortcode() {
1343 check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1344 if ( ! current_user_can( 'manage_options' ) ) {
1345 wp_die();
1346 }
1347
1348 // we might need the $post value here so lets set it.
1349 if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1350 $post_obj = get_post( absint( $_POST['post_id'] ) );
1351 if ( ! empty( $post_obj ) && empty( $post ) ) {
1352 global $post;
1353 $post = $post_obj;
1354 }
1355 }
1356
1357 if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1358 $is_preview = $this->is_preview();
1359 $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] );
1360 $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1361 $attributes = '';
1362 if ( ! empty( $attributes_array ) ) {
1363 foreach ( $attributes_array as $key => $value ) {
1364 if ( is_array( $value ) ) {
1365 $value = implode( ",", $value );
1366 }
1367
1368 if ( ! empty( $value ) ) {
1369 $value = wp_unslash( $value );
1370
1371 // Encode [ and ].
1372 if ( $is_preview ) {
1373 $value = $this->encode_shortcodes( $value );
1374 }
1375 }
1376 $attributes .= " " . esc_attr( sanitize_title_with_dashes( $key ) ) . "='" . esc_attr( $value ) . "' ";
1377 }
1378 }
1379
1380 $shortcode = "[" . esc_attr( $shortcode_name ) . " " . $attributes . "]";
1381
1382 $content = do_shortcode( $shortcode );
1383
1384 // Decode [ and ].
1385 if ( ! empty( $content ) && $is_preview ) {
1386 $content = $this->decode_shortcodes( $content );
1387 }
1388
1389 echo $content;
1390 }
1391 wp_die();
1392 }
1393
1394 /**
1395 * Output the shortcode.
1396 *
1397 * @param array $args
1398 * @param string $content
1399 *
1400 * @return string
1401 */
1402 public function shortcode_output( $args = array(), $content = '' ) {
1403 $_instance = $args;
1404
1405 $args = $this->argument_values( $args );
1406
1407 // add extra argument so we know its a output to gutenberg
1408 //$args
1409 $args = $this->string_to_bool( $args );
1410
1411 // if we have a enclosed shortcode we add it to the special `html` argument
1412 if ( ! empty( $content ) ) {
1413 $args['html'] = $content;
1414 }
1415
1416 if ( ! $this->is_preview() ) {
1417 /**
1418 * Filters the settings for a particular widget args.
1419 *
1420 * @param array $args The current widget instance's settings.
1421 * @param WP_Super_Duper $widget The current widget settings.
1422 * @param array $_instance An array of default widget arguments.
1423 *
1424 *@since 1.0.28
1425 *
1426 */
1427 $args = apply_filters( 'wp_super_duper_widget_display_callback', $args, $this, $_instance );
1428
1429 if ( ! is_array( $args ) ) {
1430 return $args;
1431 }
1432 }
1433
1434 $class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1435 $class .= " sdel-".$this->get_instance_hash();
1436
1437 $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
1438 $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
1439
1440 $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1441 $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1442
1443 $shortcode_args = array();
1444 $output = '';
1445 $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1446 if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) {
1447 $no_wrap = true;
1448 }
1449 $main_content = $this->output( $args, $shortcode_args, $content );
1450 if ( $main_content && ! $no_wrap ) {
1451 // wrap the shortcode in a div with the same class as the widget
1452 $output .= '<div class="' . $class . '" ' . $attrs . '>';
1453 if ( ! empty( $args['title'] ) ) {
1454 // if its a shortcode and there is a title try to grab the title wrappers
1455 $shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1456 if ( empty( $instance ) ) {
1457 global $wp_registered_sidebars;
1458 if ( ! empty( $wp_registered_sidebars ) ) {
1459 foreach ( $wp_registered_sidebars as $sidebar ) {
1460 if ( ! empty( $sidebar['before_title'] ) ) {
1461 $shortcode_args['before_title'] = $sidebar['before_title'];
1462 $shortcode_args['after_title'] = $sidebar['after_title'];
1463 break;
1464 }
1465 }
1466 }
1467 }
1468 $output .= $this->output_title( $shortcode_args, $args );
1469 }
1470 $output .= $main_content;
1471 $output .= '</div>';
1472 } elseif ( $main_content && $no_wrap ) {
1473 $output .= $main_content;
1474 }
1475
1476 // if preview show a placeholder if empty
1477 if ( $this->is_preview() && $output == '' ) {
1478 $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1479 }
1480
1481 return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this );
1482 }
1483
1484 /**
1485 * Placeholder text to show if output is empty and we are on a preview/builder page.
1486 *
1487 * @param string $name
1488 *
1489 * @return string
1490 */
1491 public function preview_placeholder_text( $name = '' ) {
1492 return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . wp_sprintf( __( 'Placeholder for: %s', 'ayecode-connect' ), $name ) . "</div>";
1493 }
1494
1495 /**
1496 * Sometimes booleans values can be turned to strings, so we fix that.
1497 *
1498 * @param $options
1499 *
1500 * @return mixed
1501 */
1502 public function string_to_bool( $options ) {
1503 // convert bool strings to booleans
1504 foreach ( $options as $key => $val ) {
1505 if ( $val == 'false' ) {
1506 $options[ $key ] = false;
1507 } elseif ( $val == 'true' ) {
1508 $options[ $key ] = true;
1509 }
1510 }
1511
1512 return $options;
1513 }
1514
1515 /**
1516 * Get the argument values that are also filterable.
1517 *
1518 * @param $instance
1519 *
1520 * @return array
1521 *@since 1.0.12 Don't set checkbox default value if the value is empty.
1522 *
1523 */
1524 public function argument_values( $instance ) {
1525 $argument_values = array();
1526
1527 // set widget instance
1528 $this->instance = $instance;
1529
1530 if ( empty( $this->arguments ) ) {
1531 $this->arguments = $this->get_arguments();
1532 }
1533
1534 if ( ! empty( $this->arguments ) ) {
1535 foreach ( $this->arguments as $key => $args ) {
1536 // set the input name from the key
1537 $args['name'] = $key;
1538 //
1539 $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1540 if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) {
1541 // don't set default for an empty checkbox
1542 } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1543 $argument_values[ $key ] = $args['default'];
1544 }
1545 }
1546 }
1547
1548 return $argument_values;
1549 }
1550
1551 /**
1552 * Set arguments in super duper.
1553 *
1554 * @return array Set arguments.
1555 *@since 1.0.0
1556 *
1557 */
1558 public function set_arguments() {
1559 return $this->arguments;
1560 }
1561
1562 /**
1563 * Get arguments in super duper.
1564 *
1565 * @return array Get arguments.
1566 *@since 1.0.0
1567 *
1568 */
1569 public function get_arguments() {
1570 if ( empty( $this->arguments ) ) {
1571 $this->arguments = $this->set_arguments();
1572 }
1573
1574 $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1575 $this->arguments = $this->add_name_from_key( $this->arguments, true );
1576
1577 if( !empty( $this->arguments['title']['value'] ) ){
1578 $this->arguments['title']['value'] = wp_kses_post( $this->arguments['title']['value'] );
1579 }
1580
1581 return $this->arguments;
1582 }
1583
1584 /**
1585 * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
1586 *
1587 * @param array $args
1588 * @param array $widget_args
1589 * @param string $content
1590 */
1591 public function output( $args = array(), $widget_args = array(), $content = '' ) {
1592
1593 }
1594
1595 /**
1596 * Add the dynamic block code inline when the wp-block in enqueued.
1597 */
1598 public function register_block() {
1599 wp_add_inline_script( 'wp-blocks', $this->block() );
1600 if ( class_exists( 'SiteOrigin_Panels' ) ) {
1601 wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1602 }
1603 }
1604
1605 /**
1606 * Check if we need to show advanced options.
1607 *
1608 * @return bool
1609 */
1610 public function block_show_advanced() {
1611
1612 $show = false;
1613 $arguments = $this->get_arguments();
1614
1615 if ( ! empty( $arguments ) ) {
1616 foreach ( $arguments as $argument ) {
1617 if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1618 $show = true;
1619 break; // no need to continue if we know we have it
1620 }
1621 }
1622 }
1623
1624 return $show;
1625 }
1626
1627 /**
1628 * Get the url path to the current folder.
1629 *
1630 * @return string
1631 */
1632 public function get_url() {
1633 $url = $this->url;
1634
1635 if ( ! $url ) {
1636 $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
1637 $content_url = untrailingslashit( WP_CONTENT_URL );
1638
1639 // Replace http:// to https://.
1640 if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
1641 $content_url = str_replace( 'http://', 'https://', $content_url );
1642 }
1643
1644 // Check if we are inside a plugin
1645 $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
1646 $url = str_replace( $content_dir, $content_url, $file_dir );
1647 $url = trailingslashit( $url );
1648 $this->url = $url;
1649 }
1650
1651 return $url;
1652 }
1653
1654 /**
1655 * Get the url path to the current folder.
1656 *
1657 * @return string
1658 */
1659 public function get_url_old() {
1660
1661 $url = $this->url;
1662
1663 if ( ! $url ) {
1664 // check if we are inside a plugin
1665 $file_dir = str_replace( "/includes", "", dirname( __FILE__ ) );
1666
1667 $dir_parts = explode( "/wp-content/", $file_dir );
1668 $url_parts = explode( "/wp-content/", plugins_url() );
1669
1670 if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) {
1671 $url = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] );
1672 $this->url = $url;
1673 }
1674 }
1675
1676
1677 return $url;
1678 }
1679
1680 /**
1681 * Generate the block icon.
1682 *
1683 * Enables the use of Font Awesome icons.
1684 *
1685 * @note xlink:href is actually deprecated but href is not supported by all so we use both.
1686 *
1687 * @param $icon
1688 *
1689 * @return string
1690 *@since 1.1.0
1691 */
1692 public function get_block_icon( $icon ) {
1693
1694 // check if we have a Font Awesome icon
1695 $fa_type = '';
1696 if ( substr( $icon, 0, 7 ) === "fas fa-" ) {
1697 $fa_type = 'solid';
1698 } elseif ( substr( $icon, 0, 7 ) === "far fa-" ) {
1699 $fa_type = 'regular';
1700 } elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) {
1701 $fa_type = 'brands';
1702 } else {
1703 $icon = "'" . $icon . "'";
1704 }
1705
1706 // set the icon if we found one
1707 if ( $fa_type ) {
1708 $fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon );
1709 $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))";
1710 }
1711
1712 return $icon;
1713 }
1714
1715 public function group_arguments( $arguments ) {
1716 if ( ! empty( $arguments ) ) {
1717 $temp_arguments = array();
1718 $general = __( "General", 'ayecode-connect' );
1719 $add_sections = false;
1720 foreach ( $arguments as $key => $args ) {
1721 if ( isset( $args['group'] ) ) {
1722 $temp_arguments[ $args['group'] ][ $key ] = $args;
1723 $add_sections = true;
1724 } else {
1725 $temp_arguments[ $general ][ $key ] = $args;
1726 }
1727 }
1728
1729 // only add sections if more than one
1730 if ( $add_sections ) {
1731 $arguments = $temp_arguments;
1732 }
1733 }
1734
1735 return $arguments;
1736 }
1737
1738 /**
1739 * Parse used group tabs.
1740 *
1741 * @since 1.1.17
1742 */
1743 public function group_block_tabs( $tabs, $arguments ) {
1744 if ( ! empty( $tabs ) && ! empty( $arguments ) ) {
1745 $has_sections = false;
1746
1747 foreach ( $this->arguments as $key => $args ) {
1748 if ( isset( $args['group'] ) ) {
1749 $has_sections = true;
1750 break;
1751 }
1752 }
1753
1754 if ( ! $has_sections ) {
1755 return $tabs;
1756 }
1757
1758 $new_tabs = array();
1759
1760 foreach ( $tabs as $tab_key => $tab ) {
1761 $new_groups = array();
1762
1763 if ( ! empty( $tab['groups'] ) && is_array( $tab['groups'] ) ) {
1764 foreach ( $tab['groups'] as $group ) {
1765 if ( isset( $arguments[ $group ] ) ) {
1766 $new_groups[] = $group;
1767 }
1768 }
1769 }
1770
1771 if ( ! empty( $new_groups ) ) {
1772 $tab['groups'] = $new_groups;
1773
1774 $new_tabs[ $tab_key ] = $tab;
1775 }
1776 }
1777
1778 $tabs = $new_tabs;
1779 }
1780
1781 return $tabs;
1782 }
1783
1784 /**
1785 * Output the JS for building the dynamic Guntenberg block.
1786 *
1787 * @return mixed
1788 *@since 1.0.9 Save numbers as numbers and not strings.
1789 * @since 1.1.0 Font Awesome classes can be used for icons.
1790 * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap.
1791 */
1792 public function block() {
1793 global $sd_is_js_functions_loaded, $aui_bs5;
1794
1795 $show_advanced = $this->block_show_advanced();
1796
1797 ob_start();
1798 ?>
1799 <script>
1800 <?php
1801 if ( ! $sd_is_js_functions_loaded ) {
1802 $sd_is_js_functions_loaded = true;
1803 ?>
1804 function sd_show_view_options($this){
1805 if(jQuery($this).html().length){
1806 jQuery($this).html('');
1807 }else{
1808 jQuery($this).html('<div class="position-absolute d-flex flex-column bg-white p-1 rounded border shadow-lg " style="top:-80px;left:-5px;"><div class="dashicons dashicons-desktop mb-1" onclick="sd_set_view_type(\'Desktop\');"></div><div class="dashicons dashicons-tablet mb-1" onclick="sd_set_view_type(\'Tablet\');"></div><div class="dashicons dashicons-smartphone" onclick="sd_set_view_type(\'Mobile\');"></div></div>');
1809 }
1810 }
1811
1812 function sd_set_view_type($device){
1813 const wpVersion = '<?php global $wp_version; echo esc_attr($wp_version); ?>';
1814 if (parseFloat(wpVersion) < 6.5) {
1815 wp.data.dispatch('core/edit-site') ? wp.data.dispatch('core/edit-site').__experimentalSetPreviewDeviceType($device) : wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType($device);
1816 } else {
1817 const editorDispatch = wp.data.dispatch('core/editor');
1818 if (editorDispatch) {
1819 editorDispatch.setDeviceType($device);
1820 }
1821 }
1822 }
1823
1824 jQuery(function(){
1825 sd_block_visibility_init();
1826 });
1827 function sd_block_visibility_init() {
1828 jQuery(document).off('change', '.bs-vc-modal-form').on('change', '.bs-vc-modal-form', function() {
1829 try {
1830 aui_conditional_fields('.bs-vc-modal-form');
1831 } catch(err) {
1832 console.log(err.message);
1833 }
1834 });
1835
1836 jQuery(document).off('click', '.bs-vc-save').on('click', '.bs-vc-save', function() {
1837 var $bsvcModal = jQuery(this).closest('.bs-vc-modal'), $bsvcForm = $bsvcModal.find('.bs-vc-modal-form'), vOutput = jQuery('#bsvc_output', $bsvcForm).val(), vOutputN = jQuery('#bsvc_output_n', $bsvcForm).val(), rawValue = '', oVal = {}, oOut = {}, oOutN = {}, iRule = 0;
1838 jQuery(this).addClass('disabled');
1839 jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule').each(function(){
1840 vRule = jQuery(this).find('.bsvc_rule').val(), oRule = {};
1841 if (vRule == 'logged_in' || vRule == 'logged_out' || vRule == 'post_author') {
1842 oRule.type = vRule;
1843 } else if (vRule == 'user_roles') {
1844 oRule.type = vRule;
1845 if (jQuery(this).find('.bsvc_user_roles:checked').length) {
1846 var user_roles = jQuery(this).find('.bsvc_user_roles:checked').map(function() {
1847 return jQuery(this).val();
1848 }).get();
1849 if (user_roles && user_roles.length) {
1850 oRule.user_roles = user_roles.join(",");
1851 }
1852 }
1853 } else if (vRule == 'gd_field') {
1854 if (jQuery(this).find('.bsvc_gd_field ').val() && jQuery(this).find('.bsvc_gd_field_condition').val()) {
1855 oRule.type = vRule;
1856 oRule.field = jQuery(this).find('.bsvc_gd_field ').val();
1857 oRule.condition = jQuery(this).find('.bsvc_gd_field_condition').val();
1858 if (oRule.condition != 'is_empty' && oRule.condition != 'is_not_empty') {
1859 oRule.search = jQuery(this).find('.bsvc_gd_field_search').val();
1860 }
1861 }
1862 } else {
1863 oRule = jQuery(document).triggerHandler('sd_block_visibility_init', [vRule, oRule, jQuery(this)]);
1864 }
1865
1866 if (Object.keys(oRule).length > 0) {
1867 iRule++;
1868 oVal['rule'+iRule] = oRule;
1869 }
1870 });
1871 if (vOutput == 'hide') {
1872 oOut.type = vOutput;
1873 } else if (vOutput == 'message') {
1874 if (jQuery('#bsvc_message', $bsvcForm).val()) {
1875 oOut.type = vOutput;
1876 oOut.message = jQuery('#bsvc_message', $bsvcForm).val();
1877 if (jQuery('#bsvc_message_type', $bsvcForm).val()) {
1878 oOut.message_type = jQuery('#bsvc_message_type', $bsvcForm).val();
1879 }
1880 }
1881 } else if (vOutput == 'page') {
1882 if (jQuery('#bsvc_page', $bsvcForm).val()) {
1883 oOut.type = vOutput;
1884 oOut.page = jQuery('#bsvc_page', $bsvcForm).val();
1885 }
1886 } else if (vOutput == 'template_part') {
1887 if (jQuery('#bsvc_tmpl_part', $bsvcForm).val()) {
1888 oOut.type = vOutput;
1889 oOut.template_part = jQuery('#bsvc_tmpl_part', $bsvcForm).val();
1890 }
1891 }
1892 if (Object.keys(oOut).length > 0) {
1893 oVal.output = oOut;
1894 }
1895 if (vOutputN == 'hide') {
1896 oOutN.type = vOutputN;
1897 } else if (vOutputN == 'message') {
1898 if (jQuery('#bsvc_message_n', $bsvcForm).val()) {
1899 oOutN.type = vOutputN;
1900 oOutN.message = jQuery('#bsvc_message_n', $bsvcForm).val();
1901 if (jQuery('#bsvc_message_type_n', $bsvcForm).val()) {
1902 oOutN.message_type = jQuery('#bsvc_message_type_n', $bsvcForm).val();
1903 }
1904 }
1905 } else if (vOutputN == 'page') {
1906 if (jQuery('#bsvc_page_n', $bsvcForm).val()) {
1907 oOutN.type = vOutputN;
1908 oOutN.page = jQuery('#bsvc_page_n', $bsvcForm).val();
1909 }
1910 } else if (vOutputN == 'template_part') {
1911 if (jQuery('#bsvc_tmpl_part_n', $bsvcForm).val()) {
1912 oOutN.type = vOutputN;
1913 oOutN.template_part = jQuery('#bsvc_tmpl_part_n', $bsvcForm).val();
1914 }
1915 }
1916 if (Object.keys(oOutN).length > 0) {
1917 oVal.outputN = oOutN;
1918 }
1919 if (Object.keys(oVal).length > 0) {
1920 rawValue = JSON.stringify(oVal);
1921 }
1922 $bsvcModal.find('[name="bsvc_raw_value"]').val(rawValue).trigger('change');
1923 $bsvcModal.find('.bs-vc-close').trigger('click');
1924 });
1925 jQuery(document).off('click', '.bs-vc-add-rule').on('click', '.bs-vc-add-rule', function() {
1926 var bsvcTmpl = jQuery('.bs-vc-rule-template').html();
1927 var c = parseInt(jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule:last').data('bs-index'));
1928 if (c > 0) {
1929 c++;
1930 } else {
1931 c = 1;
1932 }
1933 bsvcTmpl = bsvcTmpl.replace(/BSVCINDEX/g, c);
1934 jQuery('.bs-vc-modal-form .bs-vc-rule-sets').append(bsvcTmpl);
1935 jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule .bs-vc-sep-wrap').removeClass('d-none');
1936 jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule:first .bs-vc-sep-wrap').addClass('d-none');
1937 jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule:last').find('select').each(function(){
1938 if (!jQuery(this).hasClass('no-select2')) {
1939 jQuery(this).addClass('aui-select2');
1940 }
1941 });
1942 if (!jQuery(this).hasClass('bs-vc-rendering')) {
1943 if(typeof aui_init_select2 == 'function') {
1944 aui_init_select2();
1945 }
1946 if(typeof aui_conditional_fields == 'function') {
1947 aui_conditional_fields('.bs-vc-modal-form');
1948 }
1949 }
1950 });
1951 jQuery(document).off('click', '.bs-vc-remove-rule').on('click', '.bs-vc-remove-rule', function() {
1952 jQuery(this).closest('.bs-vc-rule').remove();
1953 });
1954 }
1955 function sd_block_visibility_render_fields(oValue) {
1956 if (typeof oValue == 'object' && oValue.rule1 && typeof oValue.rule1 == 'object') {
1957 for(k = 1; k <= Object.keys(oValue).length; k++) {
1958 if (oValue['rule' + k] && oValue['rule' + k].type) {
1959 var oRule = oValue['rule' + k];
1960 jQuery('.bs-vc-modal-form .bs-vc-add-rule').addClass('bs-vc-rendering').trigger('click');
1961 var elRule = jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule:last');
1962 jQuery('select.bsvc_rule', elRule).val(oRule.type);
1963 if (oRule.type == 'user_roles' && oRule.user_roles) {
1964 var user_roles = oRule.user_roles;
1965 if (typeof user_roles == 'string') {
1966 user_roles = user_roles.split(",");
1967 }
1968 if (user_roles.length) {
1969 jQuery.each(user_roles, function(i, role){
1970 elRule.find("input[value='" + role + "']").prop('checked', true);
1971 });
1972 }
1973 jQuery('select.bsvc_user_roles', elRule).val(oRule.user_roles);
1974 } else if (oRule.type == 'gd_field') {
1975 if (oRule.field) {
1976 jQuery('select.bsvc_gd_field', elRule).val(oRule.field);
1977 if (oRule.condition) {
1978 jQuery('select.bsvc_gd_field_condition', elRule).val(oRule.condition);
1979 if (typeof oRule.search != 'undefined' && oRule.condition != 'is_empty' && oRule.condition != 'is_not_empty') {
1980 jQuery('input.bsvc_gd_field_search', elRule).val(oRule.search);
1981 }
1982 }
1983 }
1984 } else {
1985 jQuery(document).trigger('sd_block_visibility_render_fields', [oRule, elRule]);
1986 }
1987
1988 jQuery('.bs-vc-modal-form .bs-vc-add-rule').removeClass('bs-vc-rendering');
1989 }
1990 }
1991
1992 if (oValue.output && oValue.output.type) {
1993 jQuery('.bs-vc-modal-form #bsvc_output').val(oValue.output.type);
1994 if (oValue.output.type == 'message' && typeof oValue.output.message != 'undefined') {
1995 jQuery('.bs-vc-modal-form #bsvc_message').val(oValue.output.message);
1996 if (typeof oValue.output.message_type != 'undefined') {
1997 jQuery('.bs-vc-modal-form #bsvc_message_type').val(oValue.output.message_type);
1998 }
1999 } else if (oValue.output.type == 'page' && typeof oValue.output.page != 'undefined') {
2000 jQuery('.bs-vc-modal-form #bsvc_page').val(oValue.output.page);
2001 } else if (oValue.output.type == 'template_part' && typeof oValue.output.template_part != 'undefined') {
2002 jQuery('.bs-vc-modal-form #bsvc_template_part').val(oValue.output.template_part);
2003 }
2004 }
2005
2006 if (oValue.outputN && oValue.outputN.type) {
2007 jQuery('.bs-vc-modal-form #bsvc_output_n').val(oValue.outputN.type);
2008 if (oValue.outputN.type == 'message' && typeof oValue.outputN.message != 'undefined') {
2009 jQuery('.bs-vc-modal-form #bsvc_message_n').val(oValue.outputN.message);
2010 if (typeof oValue.outputN.message_type != 'undefined') {
2011 jQuery('.bs-vc-modal-form #bsvc_message_type_n').val(oValue.outputN.message_type);
2012 }
2013 } else if (oValue.outputN.type == 'page' && typeof oValue.outputN.page != 'undefined') {
2014 jQuery('.bs-vc-modal-form #bsvc_page_n').val(oValue.outputN.page);
2015 } else if (oValue.outputN.type == 'template_part' && typeof oValue.outputN.template_part != 'undefined') {
2016 jQuery('.bs-vc-modal-form #bsvc_template_part_n').val(oValue.outputN.template_part);
2017 }
2018 }
2019 }
2020 }
2021 /**
2022 * Try to auto-recover blocks.
2023 */
2024 function sd_auto_recover_blocks() {
2025 var recursivelyRecoverInvalidBlockList = blocks => {
2026 const _blocks = [...blocks]
2027 let recoveryCalled = false
2028 const recursivelyRecoverBlocks = willRecoverBlocks => {
2029 willRecoverBlocks.forEach(_block => {
2030 if (!_block.isValid) {
2031 recoveryCalled = true
2032 const newBlock = recoverBlock(_block)
2033 for (const key in newBlock) {
2034 _block[key] = newBlock[key]
2035 }
2036 }
2037 if (_block.innerBlocks.length) {
2038 recursivelyRecoverBlocks(_block.innerBlocks)
2039 }
2040 })
2041 }
2042 recursivelyRecoverBlocks(_blocks)
2043 return [_blocks, recoveryCalled]
2044 }
2045 var recoverBlock = ({ name, attributes, innerBlocks }) => wp.blocks.createBlock(name, attributes, innerBlocks);
2046 var recoverBlocks = blocks => {
2047 return blocks.map(_block => {
2048 const block = _block;
2049 // If the block is a reusable block, recover the Stackable blocks inside it.
2050 if (_block.name === 'core/block') {
2051 const { attributes: { ref } } = _block
2052 const parsedBlocks = wp.blocks.parse(wp.data.select('core').getEntityRecords('postType', 'wp_block', { include: [ref] })?.[0]?.content?.raw) || []
2053 const [recoveredBlocks, recoveryCalled] = recursivelyRecoverInvalidBlockList(parsedBlocks)
2054 if (recoveryCalled) {
2055 console.log('Stackable notice: block ' + block.name + ' (' + block.clientId + ') was auto-recovered, you should not see this after saving your page.');
2056 return { blocks: recoveredBlocks, isReusable: true, ref }
2057 }
2058 } else if (_block.name === 'core/template-part' && _block.attributes && _block.attributes.theme) {
2059 var tmplPart = wp.data.select('core').getEntityRecord('postType', 'wp_template_part', _block.attributes.theme + '//' + _block.attributes.slug);
2060 var tmplPartBlocks = block.innerBlocks && block.innerBlocks.length ? block.innerBlocks : wp.blocks.parse(tmplPart?.content?.raw) || [];
2061 if (tmplPartBlocks && tmplPartBlocks.length && tmplPartBlocks.some(block => !block.isValid)) {
2062 block.innerBlocks = tmplPartBlocks;
2063 block.tmplPartId = _block.attributes.theme + '//' + _block.attributes.slug;
2064 }
2065 }
2066 if (block.innerBlocks && block.innerBlocks.length) {
2067 if (block.tmplPartId) {
2068 console.log('Template part ' + block.tmplPartId + ' block ' + block.name + ' (' + block.clientId + ') starts');
2069 }
2070 const newInnerBlocks = recoverBlocks(block.innerBlocks)
2071 if (newInnerBlocks.some(block => block.recovered)) {
2072 block.innerBlocks = newInnerBlocks
2073 block.replacedClientId = block.clientId
2074 block.recovered = true
2075 }
2076 if (block.tmplPartId) {
2077 console.log('Template part ' + block.tmplPartId + ' block ' + block.name + ' (' + block.clientId + ') ends');
2078 }
2079 }
2080 if (!block.isValid) {
2081 const newBlock = recoverBlock(block)
2082 newBlock.replacedClientId = block.clientId
2083 newBlock.recovered = true
2084 console.log('Stackable notice: block ' + block.name + ' (' + block.clientId + ') was auto-recovered, you should not see this after saving your page.');
2085 return newBlock
2086 }
2087 return block
2088 })
2089 }
2090 // Recover all the blocks that we can find.
2091 var sdBlockEditor = wp.data.select('core/block-editor');
2092 var mainBlocks = sdBlockEditor ? recoverBlocks(sdBlockEditor.getBlocks()) : null;
2093 // Replace the recovered blocks with the new ones.
2094 if (mainBlocks) {
2095 mainBlocks.forEach(block => {
2096 if (block.isReusable && block.ref) {
2097 // Update the reusable blocks.
2098 wp.data.dispatch('core').editEntityRecord('postType', 'wp_block', block.ref, {
2099 content: wp.blocks.serialize(block.blocks)
2100 }).then(() => {
2101 // But don't save them, let the user do the saving themselves. Our goal is to get rid of the block error visually.
2102 })
2103 }
2104 if (block.recovered && block.replacedClientId) {
2105 wp.data.dispatch('core/block-editor').replaceBlock(block.replacedClientId, block)
2106 }
2107 })
2108 }
2109 }
2110
2111 /**
2112 * Try to auto-recover OUR blocks if traditional way fails.
2113 */
2114 function sd_auto_recover_blocks_fallback(editTmpl) {
2115 console.log('sd_auto_recover_blocks_fallback()');
2116 var $bsRecoverBtn = jQuery(".edit-site-visual-editor__editor-canvas").contents().find('div[class*=" wp-block-blockstrap-"] .block-editor-warning__actions .block-editor-warning__action .components-button.is-primary').not(":contains('Keep as HTML')");
2117 if ($bsRecoverBtn.length) {
2118 if(jQuery('.edit-site-layout.is-full-canvas').length || jQuery('.edit-site-layout.is-edit-mode').length){
2119 $bsRecoverBtn.removeAttr('disabled').trigger('click');
2120 }
2121 }
2122 }
2123
2124 <?php if( !isset( $_REQUEST['sd-block-recover-debug'] ) ){ ?>
2125 // Wait will window is loaded before calling.
2126 window.onload = function() {
2127 sd_auto_recover_blocks();
2128 // fire a second time incase of load delays.
2129 setTimeout(function() {
2130 sd_auto_recover_blocks();
2131 }, 5000);
2132
2133 setTimeout(function() {
2134 sd_auto_recover_blocks_fallback();
2135 }, 6000);
2136
2137 setTimeout(function() {
2138 sd_auto_recover_blocks_fallback();
2139 }, 10000);
2140
2141 setTimeout(function() {
2142 sd_auto_recover_blocks_fallback();
2143 }, 15000);
2144
2145 setTimeout(function() {
2146 sd_auto_recover_blocks_fallback();
2147 }, 20000);
2148
2149 setTimeout(function() {
2150 sd_auto_recover_blocks_fallback();
2151 }, 30000);
2152
2153 setTimeout(function() {
2154 sd_auto_recover_blocks_fallback();
2155 }, 60000);
2156
2157 jQuery('.edit-site-page-panels__edit-template-button, .edit-site-visual-editor__editor-canvas').on('click', function() {
2158 setTimeout(function() {
2159 sd_auto_recover_blocks_fallback(true);
2160 jQuery('.edit-site-page-panels__edit-template-button, .edit-site-visual-editor__editor-canvas').addClass('bs-edit-tmpl-clicked');
2161 }, 100);
2162 });
2163 };
2164 <?php } ?>
2165
2166 // fire when URL changes also.
2167 let lastUrl = location.href;
2168 new MutationObserver(() => {
2169 const url = location.href;
2170 if (url !== lastUrl) {
2171 lastUrl = url;
2172 sd_auto_recover_blocks();
2173 // fire a second time incase of load delays.
2174 setTimeout(function() {
2175 sd_auto_recover_blocks();
2176 sd_auto_recover_blocks_fallback();
2177 }, 2000);
2178
2179 setTimeout(function() {
2180 sd_auto_recover_blocks_fallback();
2181 }, 10000);
2182
2183 setTimeout(function() {
2184 sd_auto_recover_blocks_fallback();
2185 }, 15000);
2186
2187 setTimeout(function() {
2188 sd_auto_recover_blocks_fallback();
2189 }, 20000);
2190
2191 }
2192 }).observe(document, {
2193 subtree: true,
2194 childList: true
2195 });
2196
2197
2198 /**
2199 *
2200 * @param $args
2201 * @returns {*|{}}
2202 */
2203 function sd_build_aui_styles($args){
2204
2205 $styles = {};
2206 // background color
2207 if ( $args['bg'] !== undefined && $args['bg'] !== '' ) {
2208 if( $args['bg'] == 'custom-color' ){
2209 $styles['background-color']= $args['bg_color'];
2210 }else if( $args['bg'] == 'custom-gradient' ){
2211 $styles['background-image']= $args['bg_gradient'];
2212
2213 // use background on text
2214 if( $args['bg_on_text'] !== undefined && $args['bg_on_text'] ){
2215 $styles['backgroundClip'] = "text";
2216 $styles['WebkitBackgroundClip'] = "text";
2217 $styles['text-fill-color'] = "transparent";
2218 $styles['WebkitTextFillColor'] = "transparent";
2219 }
2220 }
2221
2222 }
2223
2224 let $bg_image = $args['bg_image'] !== undefined && $args['bg_image'] !== '' ? $args['bg_image'] : '';
2225
2226 // maybe use featured image.
2227 if( $args['bg_image_use_featured'] !== undefined && $args['bg_image_use_featured'] ){
2228 $bg_image = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxzdmcgYmFzZVByb2ZpbGU9InRpbnkiIGhlaWdodD0iNDAwIiB2ZXJzaW9uPSIxLjIiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6ZXY9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEveG1sLWV2ZW50cyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzIC8+PHJlY3QgZmlsbD0iI2QzZDNkMyIgaGVpZ2h0PSI0MDAiIHdpZHRoPSI0MDAiIHg9IjAiIHk9IjAiIC8+PGxpbmUgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIxMCIgeDE9IjAiIHgyPSI0MDAiIHkxPSIwIiB5Mj0iNDAwIiAvPjxsaW5lIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMTAiIHgxPSIwIiB4Mj0iNDAwIiB5MT0iNDAwIiB5Mj0iMCIgLz48cmVjdCBmaWxsPSIjZDNkM2QzIiBoZWlnaHQ9IjUwIiB3aWR0aD0iMjE4LjAiIHg9IjkxLjAiIHk9IjE3NS4wIiAvPjx0ZXh0IGZpbGw9IndoaXRlIiBmb250LXNpemU9IjMwIiBmb250LXdlaWdodD0iYm9sZCIgdGV4dC1hbmNob3I9Im1pZGRsZSIgeD0iMjAwLjAiIHk9IjIwNy41Ij5QTEFDRUhPTERFUjwvdGV4dD48L3N2Zz4=';
2229 }
2230
2231 if( $bg_image !== undefined && $bg_image !== '' ){
2232 var hasImage = true
2233 if($styles['background-color'] !== undefined && $args['bg'] == 'custom-color'){
2234 $styles['background-image'] = "url("+$bg_image+")";
2235 $styles['background-blend-mode'] = "overlay";
2236 }else if($styles['background-image'] !== undefined && $args['bg'] == 'custom-gradient'){
2237 $styles['background-image'] += ",url("+$bg_image+")";
2238 }else if($args['bg'] !== undefined && $args['bg'] != '' && $args['bg'] != 'transparent' ){
2239 // do nothing as we already have a preset
2240 hasImage = false;
2241 }else{
2242 $styles['background-image'] = "url("+$bg_image+")";
2243 }
2244
2245 if( hasImage){
2246 $styles['background-size'] = "cover";
2247
2248 if( $args['bg_image_fixed'] !== undefined && $args['bg_image_fixed'] ){
2249 $styles['background-attachment'] = "fixed";
2250 }
2251 }
2252
2253 if( hasImage && $args['bg_image_xy'].x !== undefined && $args['bg_image_xy'].x >=0 ){
2254 $styles['background-position'] = ($args['bg_image_xy'].x * 100 ) + "% " + ( $args['bg_image_xy'].y * 100) + "%";
2255 }
2256 }
2257
2258
2259
2260 // sticky offset top
2261 if( $args['sticky_offset_top'] !== undefined && $args['sticky_offset_top'] !== '' ){
2262 $styles['top'] = $args['sticky_offset_top'];
2263 }
2264
2265 // sticky offset bottom
2266 if( $args['sticky_offset_bottom'] !== undefined && $args['sticky_offset_bottom'] !== '' ){
2267 $styles['bottom'] = $args['sticky_offset_bottom'];
2268 }
2269
2270 // font size
2271 if( $args['font_size'] === undefined || $args['font_size'] === 'custom' ){
2272 if( $args['font_size_custom'] !== undefined && $args['font_size_custom'] !== '' ){
2273 $styles['fontSize'] = $args['font_size_custom'] + "rem";
2274 }
2275 }
2276
2277 // font color
2278 if( $args['text_color'] === undefined || $args['text_color'] === 'custom' ){
2279 if( $args['text_color_custom'] !== undefined && $args['text_color_custom'] !== '' ){
2280 $styles['color'] = $args['text_color_custom'];
2281 }
2282 }
2283
2284 // font line height
2285 if( $args['font_line_height'] !== undefined && $args['font_line_height'] !== '' ){
2286 $styles['lineHeight'] = $args['font_line_height'];
2287 }
2288
2289 // max height
2290 if( $args['max_height'] !== undefined && $args['max_height'] !== '' ){
2291 $styles['maxHeight'] = $args['max_height'];
2292 }
2293
2294 return $styles;
2295
2296 }
2297
2298 function sd_build_aui_class($args){
2299
2300 $classes = [];
2301
2302 <?php
2303 if($aui_bs5){
2304 ?>
2305 $aui_bs5 = true;
2306 $p_ml = 'ms-';
2307 $p_mr = 'me-';
2308
2309 $p_pl = 'ps-';
2310 $p_pr = 'pe-';
2311 <?php
2312 }else{
2313 ?>
2314 $aui_bs5 = false;
2315 $p_ml = 'ml-';
2316 $p_mr = 'mr-';
2317
2318 $p_pl = 'pl-';
2319 $p_pr = 'pr-';
2320 <?php
2321 }
2322 ?>
2323
2324 // margins
2325 if ( $args['mt'] !== undefined && $args['mt'] !== '' ) { $classes.push( "mt-" + $args['mt'] ); $mt = $args['mt']; }else{$mt = null;}
2326 if ( $args['mr'] !== undefined && $args['mr'] !== '' ) { $classes.push( $p_mr + $args['mr'] ); $mr = $args['mr']; }else{$mr = null;}
2327 if ( $args['mb'] !== undefined && $args['mb'] !== '' ) { $classes.push( "mb-" + $args['mb'] ); $mb = $args['mb']; }else{$mb = null;}
2328 if ( $args['ml'] !== undefined && $args['ml'] !== '' ) { $classes.push( $p_ml + $args['ml'] ); $ml = $args['ml']; }else{$ml = null;}
2329
2330 // margins tablet
2331 if ( $args['mt_md'] !== undefined && $args['mt_md'] !== '' ) { $classes.push( "mt-md-" + $args['mt_md'] ); $mt_md = $args['mt_md']; }else{$mt_md = null;}
2332 if ( $args['mr_md'] !== undefined && $args['mr_md'] !== '' ) { $classes.push( $p_mr + "md-" + $args['mr_md'] ); $mt_md = $args['mr_md']; }else{$mr_md = null;}
2333 if ( $args['mb_md'] !== undefined && $args['mb_md'] !== '' ) { $classes.push( "mb-md-" + $args['mb_md'] ); $mt_md = $args['mb_md']; }else{$mb_md = null;}
2334 if ( $args['ml_md'] !== undefined && $args['ml_md'] !== '' ) { $classes.push( $p_ml + "md-" + $args['ml_md'] ); $mt_md = $args['ml_md']; }else{$ml_md = null;}
2335
2336 // margins desktop
2337 if ( $args['mt_lg'] !== undefined && $args['mt_lg'] !== '' ) { if($mt == null && $mt_md == null){ $classes.push( "mt-" + $args['mt_lg'] ); }else{$classes.push( "mt-lg-" + $args['mt_lg'] ); } }
2338 if ( $args['mr_lg'] !== undefined && $args['mr_lg'] !== '' ) { if($mr == null && $mr_md == null){ $classes.push( $p_mr + $args['mr_lg'] ); }else{$classes.push( $p_mr + "lg-" + $args['mr_lg'] ); } }
2339 if ( $args['mb_lg'] !== undefined && $args['mb_lg'] !== '' ) { if($mb == null && $mb_md == null){ $classes.push( "mb-" + $args['mb_lg'] ); }else{$classes.push( "mb-lg-" + $args['mb_lg'] ); } }
2340 if ( $args['ml_lg'] !== undefined && $args['ml_lg'] !== '' ) { if($ml == null && $ml_md == null){ $classes.push( $p_ml + $args['ml_lg'] ); }else{$classes.push( $p_ml + "lg-" + $args['ml_lg'] ); } }
2341
2342 // padding
2343 if ( $args['pt'] !== undefined && $args['pt'] !== '' ) { $classes.push( "pt-" + $args['pt'] ); $pt = $args['pt']; }else{$pt = null;}
2344 if ( $args['pr'] !== undefined && $args['pr'] !== '' ) { $classes.push( $p_pr + $args['pr'] ); $pr = $args['pt']; }else{$pr = null;}
2345 if ( $args['pb'] !== undefined && $args['pb'] !== '' ) { $classes.push( "pb-" + $args['pb'] ); $pb = $args['pt']; }else{$pb = null;}
2346 if ( $args['pl'] !== undefined && $args['pl'] !== '' ) { $classes.push( $p_pl + $args['pl'] ); $pl = $args['pt']; }else{$pl = null;}
2347
2348 // padding tablet
2349 if ( $args['pt_md'] !== undefined && $args['pt_md'] !== '' ) { $classes.push( "pt-md-" + $args['pt_md'] ); $pt_md = $args['pt_md']; }else{$pt_md = null;}
2350 if ( $args['pr_md'] !== undefined && $args['pr_md'] !== '' ) { $classes.push( $p_pr + "md-" + $args['pr_md'] ); $pr_md = $args['pt_md']; }else{$pr_md = null;}
2351 if ( $args['pb_md'] !== undefined && $args['pb_md'] !== '' ) { $classes.push( "pb-md-" + $args['pb_md'] ); $pb_md = $args['pt_md']; }else{$pb_md = null;}
2352 if ( $args['pl_md'] !== undefined && $args['pl_md'] !== '' ) { $classes.push( $p_pl + "md-" + $args['pl_md'] ); $pl_md = $args['pt_md']; }else{$pl_md = null;}
2353
2354 // padding desktop
2355 if ( $args['pt_lg'] !== undefined && $args['pt_lg'] !== '' ) { if($pt == null && $pt_md == null){ $classes.push( "pt-" + $args['pt_lg'] ); }else{$classes.push( "pt-lg-" + $args['pt_lg'] ); } }
2356 if ( $args['pr_lg'] !== undefined && $args['pr_lg'] !== '' ) { if($pr == null && $pr_md == null){ $classes.push( $p_pr + $args['pr_lg'] ); }else{$classes.push( $p_pr + "lg-" + $args['pr_lg'] ); } }
2357 if ( $args['pb_lg'] !== undefined && $args['pb_lg'] !== '' ) { if($pb == null && $pb_md == null){ $classes.push( "pb-" + $args['pb_lg'] ); }else{$classes.push( "pb-lg-" + $args['pb_lg'] ); } }
2358 if ( $args['pl_lg'] !== undefined && $args['pl_lg'] !== '' ) { if($pl == null && $pl_md == null){ $classes.push( $p_pl + $args['pl_lg'] ); }else{$classes.push( $p_pl + "lg-" + $args['pl_lg'] ); } }
2359
2360 // row cols, mobile, tablet, desktop
2361 if ( $args['row_cols'] !== undefined && $args['row_cols'] !== '' ) { $classes.push( "row-cols-" + $args['row_cols'] ); $row_cols = $args['row_cols']; }else{$row_cols = null;}
2362 if ( $args['row_cols_md'] !== undefined && $args['row_cols_md'] !== '' ) { $classes.push( "row-cols-md-" + $args['row_cols_md'] ); $row_cols_md = $args['row_cols_md']; }else{$row_cols_md = null;}
2363 if ( $args['row_cols_lg'] !== undefined && $args['row_cols_lg'] !== '' ) { if($row_cols == null && $row_cols_md == null){ $classes.push( "row-cols-" + $args['row_cols_lg'] ); }else{$classes.push( "row-cols-lg-" + $args['row_cols_lg'] ); } }
2364
2365 // columns , mobile, tablet, desktop
2366 if ( $args['col'] !== undefined && $args['col'] !== '' ) { $classes.push( "col-" + $args['col'] ); $col = $args['col']; }else{$col = null;}
2367 if ( $args['col_md'] !== undefined && $args['col_md'] !== '' ) { $classes.push( "col-md-" + $args['col_md'] ); $col_md = $args['col_md']; }else{$col_md = null;}
2368 if ( $args['col_lg'] !== undefined && $args['col_lg'] !== '' ) { if($col == null && $col_md == null){ $classes.push( "col-" + $args['col_lg'] ); }else{$classes.push( "col-lg-" + $args['col_lg'] ); } }
2369
2370
2371 // border
2372 if ( $args['border'] === undefined || $args['border']=='') { }
2373 else if ( $args['border'] !== undefined && ( $args['border']=='none' || $args['border']==='0') ) { $classes.push( "border-0" ); }
2374 else if ( $args['border'] !== undefined ) {
2375 if($aui_bs5 && $args['border_type'] !== undefined){
2376 $args['border_type'] = $args['border_type'].replace('-left','-start').replace('-right','-end');
2377 }
2378 $border_class = 'border';
2379 if ( $args['border_type'] !== undefined && ! $args['border_type'].includes( '-0' ) ) {
2380 $border_class = '';
2381 }
2382 $classes.push( $border_class + " border-" + $args['border'] );
2383 }
2384
2385 // border radius type
2386 // if ( $args['rounded'] !== undefined && $args['rounded'] !== '' ) { $classes.push($args['rounded']); }
2387
2388 // border radius size
2389 if( $args['rounded_size'] !== undefined && ( $args['rounded_size']==='sm' || $args['rounded_size']==='lg' ) ){
2390 if ( $args['rounded_size'] !== undefined && $args['rounded_size'] !== '' ) {
2391 $classes.push("rounded-" + $args['rounded_size']);
2392 // if we set a size then we need to remove "rounded" if set
2393 var index = $classes.indexOf("rounded");
2394 if (index !== -1) {
2395 $classes.splice(index, 1);
2396 }
2397 }
2398 }else{
2399 // rounded_size , mobile, tablet, desktop
2400 if ( $args['rounded_size'] !== undefined && $args['rounded_size'] !== '' ) { $classes.push( "rounded-" + $args['rounded_size'] ); $rounded_size = $args['rounded_size']; }else{$rounded_size = null;}
2401 if ( $args['rounded_size_md'] !== undefined && $args['rounded_size_md'] !== '' ) { $classes.push( "rounded-md-" + $args['rounded_size_md'] ); $rounded_size_md = $args['rounded_size_md']; }else{$rounded_size_md = null;}
2402 if ( $args['rounded_size_lg'] !== undefined && $args['rounded_size_lg'] !== '' ) { if($rounded_size == null && $rounded_size_md == null){ $classes.push( "rounded-" + $args['rounded_size_lg'] ); }else{$classes.push( "rounded-lg-" + $args['rounded_size_lg'] ); } }
2403 }
2404
2405
2406 // shadow
2407 // if ( $args['shadow'] !== undefined && $args['shadow'] !== '' ) { $classes.push($args['shadow']); }
2408
2409 // background
2410 if ( $args['bg'] !== undefined && $args['bg'] !== '' ) { $classes.push("bg-" + $args['bg']); }
2411
2412 // background image fixed bg_image_fixed
2413 if ( $args['bg_image_fixed'] !== undefined && $args['bg_image_fixed'] !== '' ) { $classes.push("bg-image-fixed"); }
2414
2415 // text_color
2416 if ( $args['text_color'] !== undefined && $args['text_color'] !== '' ) { $classes.push( "text-" + $args['text_color']); }
2417
2418 // text_align
2419 if ( $args['text_justify'] !== undefined && $args['text_justify'] ) { $classes.push('text-justify'); }
2420 else{
2421 if ( $args['text_align'] !== undefined && $args['text_align'] !== '' ) {
2422 if($aui_bs5){ $args['text_align'] = $args['text_align'].replace('-left','-start').replace('-right','-end'); }
2423 $classes.push($args['text_align']); $text_align = $args['text_align'];
2424 }else{$text_align = null;}
2425 if ( $args['text_align_md'] !== undefined && $args['text_align_md'] !== '' ) {
2426 if($aui_bs5){ $args['text_align_md'] = $args['text_align_md'].replace('-left','-start').replace('-right','-end'); }
2427 $classes.push($args['text_align_md']); $text_align_md = $args['text_align_md'];
2428 }else{$text_align_md = null;}
2429 if ( $args['text_align_lg'] !== undefined && $args['text_align_lg'] !== '' ) {
2430 if($aui_bs5){ $args['text_align_lg'] = $args['text_align_lg'].replace('-left','-start').replace('-right','-end'); }
2431 if($text_align == null && $text_align_md == null){ $classes.push($args['text_align_lg'].replace("-lg", ""));
2432 }else{$classes.push($args['text_align_lg']);} }
2433 }
2434
2435 // display
2436 if ( $args['display'] !== undefined && $args['display'] !== '' ) { $classes.push($args['display']); $display = $args['display']; }else{$display = null;}
2437 if ( $args['display_md'] !== undefined && $args['display_md'] !== '' ) { $classes.push($args['display_md']); $display_md = $args['display_md']; }else{$display_md = null;}
2438 if ( $args['display_lg'] !== undefined && $args['display_lg'] !== '' ) { if($display == null && $display_md == null){ $classes.push($args['display_lg'].replace("-lg", "")); }else{$classes.push($args['display_lg']);} }
2439
2440 // bgtus - background transparent until scroll
2441 if ( $args['bgtus'] !== undefined && $args['bgtus'] ) { $classes.push("bg-transparent-until-scroll"); }
2442
2443 // cscos - change color scheme on scroll
2444 if ( $args['bgtus'] !== undefined && $args['bgtus'] && $args['cscos'] !== undefined && $args['cscos'] ) { $classes.push("color-scheme-flip-on-scroll"); }
2445
2446 // hover animations
2447 if ( $args['hover_animations'] !== undefined && $args['hover_animations'] ) { $classes.push($args['hover_animations'].toString().replace(',',' ')); }
2448
2449 // absolute_position
2450 if ( $args['absolute_position'] !== undefined ) {
2451 if ( 'top-left' === $args['absolute_position'] ) {
2452 $classes.push('start-0 top-0');
2453 } else if ( 'top-center' === $args['absolute_position'] ) {
2454 $classes.push('start-50 top-0 translate-middle');
2455 } else if ( 'top-right' === $args['absolute_position'] ) {
2456 $classes.push('end-0 top-0');
2457 } else if ( 'center-left' === $args['absolute_position'] ) {
2458 $classes.push('start-0 bottom-50');
2459 } else if ( 'center' === $args['absolute_position'] ) {
2460 $classes.push('start-50 top-50 translate-middle');
2461 } else if ( 'center-right' === $args['absolute_position'] ) {
2462 $classes.push('end-0 top-50');
2463 } else if ( 'bottom-left' === $args['absolute_position'] ) {
2464 $classes.push('start-0 bottom-0');
2465 } else if ( 'bottom-center' === $args['absolute_position'] ) {
2466 $classes.push('start-50 bottom-0 translate-middle');
2467 } else if ( 'bottom-right' === $args['absolute_position'] ) {
2468 $classes.push('end-0 bottom-0');
2469 }
2470 }
2471
2472 // build classes from build keys
2473 $build_keys = sd_get_class_build_keys();
2474 if ( $build_keys.length ) {
2475 $build_keys.forEach($key => {
2476
2477 if($key.endsWith("-MTD")){
2478
2479 $k = $key.replace("-MTD","");
2480
2481 // Mobile, Tablet, Desktop
2482 if ( $args[$k] !== undefined && $args[$k] !== '' ) { $classes.push( $args[$k] ); $v = $args[$k]; }else{$v = null;}
2483 if ( $args[$k + '_md'] !== undefined && $args[$k + '_md'] !== '' ) { $classes.push( $args[$k + '_md'] ); $v_md = $args[$k + '_md']; }else{$v_md = null;}
2484 if ( $args[$k + '_lg'] !== undefined && $args[$k + '_lg'] !== '' ) { if($v == null && $v_md == null){ $classes.push( $args[$k + '_lg'].replace('-lg','') ); }else{$classes.push( $args[$k + '_lg'] ); } }
2485
2486 }else{
2487 if ( $key == 'font_size' && ( $args[ $key ] == 'custom' || $args[ $key ] === '0' ) ) {
2488 return;
2489 }
2490 if ( $args[$key] !== undefined && $args[$key] !== '' ) { $classes.push($args[$key]); }
2491 }
2492
2493 });
2494 }
2495
2496 return $classes.join(" ");
2497 }
2498
2499 function sd_get_class_build_keys(){
2500 return <?php echo json_encode(sd_get_class_build_keys());?>;
2501 }
2502
2503 <?php
2504
2505
2506 }
2507
2508 if(method_exists($this,'block_global_js')){
2509 echo $this->block_global_js();
2510 }
2511 ?>
2512
2513 jQuery(function() {
2514
2515 /**
2516 * BLOCK: Basic
2517 *
2518 * Registering a basic block with Gutenberg.
2519 * Simple block, renders and saves the same content without any interactivity.
2520 *
2521 * Styles:
2522 * editor.css — Editor styles for the block.
2523 * style.css — Editor & Front end styles for the block.
2524 */
2525 (function (blocksx, elementx, blockEditor) {
2526 if (typeof blockEditor === 'undefined') {
2527 return;<?php /* Yoast SEO load blocks.js without block-editor.js on post edit pages */ ?>
2528 }
2529 var __ = wp.i18n.__; // The __() for internationalization.
2530 var el = wp.element.createElement; // The wp.element.createElement() function to create elements.
2531 var editable = wp.blocks.Editable;
2532 var blocks = wp.blocks;
2533 var registerBlockType = wp.blocks.registerBlockType; // The registerBlockType() to register blocks.
2534 var is_fetching = false;
2535 var prev_attributes = [];
2536
2537 var InnerBlocks = blockEditor.InnerBlocks;
2538
2539 var term_query_type = '';
2540 var post_type_rest_slugs = <?php if(! empty( $this->arguments ) && isset($this->arguments['post_type']['onchange_rest']['values'])){echo "[".json_encode($this->arguments['post_type']['onchange_rest']['values'])."]";}else{echo "[]";} ?>;
2541 const taxonomies_<?php echo str_replace("-","_", $this->id);?> = [{label: "Please wait", value: 0}];
2542 const sort_by_<?php echo str_replace("-","_", $this->id);?> = [{label: "Please wait", value: 0}];
2543 const MediaUpload = wp.blockEditor.MediaUpload;
2544
2545 /**
2546 * Register Basic Block.
2547 *
2548 * Registers a new block provided a unique name and an object defining its
2549 * behavior. Once registered, the block is made available as an option to any
2550 * editor interface where blocks are implemented.
2551 *
2552 * @param {string} name Block name.
2553 * @param {Object} settings Block settings.
2554 * @return {?WPBlock} The block, if it has been successfully
2555 * registered; otherwise `undefined`.
2556 */
2557 registerBlockType('<?php echo str_replace( "_", "-", sanitize_title_with_dashes( $this->options['textdomain'] ) . '/' . sanitize_title_with_dashes( $this->options['class_name'] ) ); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block.
2558 apiVersion: <?php echo isset($this->options['block-api-version']) ? absint($this->options['block-api-version']) : 2 ; ?>,
2559 title: '<?php echo addslashes( $this->options['name'] ); ?>', // Block title.
2560 description: '<?php echo addslashes( $this->options['widget_ops']['description'] )?>', // Block title.
2561 icon: <?php echo $this->get_block_icon( $this->options['block-icon'] );?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
2562 supports: {
2563 <?php
2564 if(!isset($this->options['block-supports']['renaming'])){
2565 $this->options['block-supports']['renaming'] = false;
2566 }
2567 if ( isset( $this->options['block-supports'] ) ) {
2568 echo $this->array_to_attributes( $this->options['block-supports'] );
2569 }
2570 ?>
2571 },
2572 __experimentalLabel( attributes, { context } ) {
2573 var visibility_html = attributes && attributes.visibility_conditions ? ' &#128065;' : '';
2574 var metadata_name = attributes && attributes.metadata && attributes.metadata.name ? attributes.metadata.name : '';
2575 var label_name = <?php echo !empty($this->options['block-label']) ? $this->options['block-label'] : "'" . esc_attr( addslashes( $this->options['name'] ) ) . "'"; ?>;
2576 return metadata_name ? metadata_name + visibility_html : label_name + visibility_html;
2577 },
2578 category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
2579 <?php if ( isset( $this->options['block-keywords'] ) ) {
2580 echo "keywords : " . $this->options['block-keywords'] . ",";
2581 }
2582
2583
2584 // block hover preview.
2585 $example_args = array();
2586 if(!empty($this->arguments)){
2587 foreach($this->arguments as $key => $a_args){
2588 if(isset($a_args['example'])){
2589 $example_args[$key] = $a_args['example'];
2590 }
2591 }
2592 }
2593 $viewport_width = isset($this->options['example']['viewportWidth']) ? 'viewportWidth: '.absint($this->options['example']['viewportWidth']) : '';
2594 $example_inner_blocks = !empty($this->options['example']['innerBlocks']) && is_array($this->options['example']['innerBlocks']) ? 'innerBlocks: ' . wp_json_encode($this->options['example']['innerBlocks']) : '';
2595 if( isset( $this->options['example'] ) && $this->options['example'] === false ){
2596 // no preview if set to false
2597 }elseif( !empty( $example_args ) ){
2598 echo "example : {attributes:{".$this->array_to_attributes( $example_args )."},$viewport_width},";
2599 }elseif( !empty( $this->options['example'] ) ){
2600 unset($this->options['example']['viewportWidth']);
2601 unset($this->options['example']['innerBlocks']);
2602 $example_atts = $this->array_to_attributes( $this->options['example'] );
2603 $example_parts = array();
2604 if($example_atts){
2605 $example_parts[] = rtrim($example_atts,",");
2606 }
2607 if($viewport_width){
2608 $example_parts[] = $viewport_width;
2609 }
2610 if($example_inner_blocks){
2611 $example_parts[] = $example_inner_blocks;
2612 }
2613 if(!empty($example_parts)){
2614 echo "example : {".implode(',', $example_parts)."},";
2615 }
2616 }else{
2617 echo 'example : {viewportWidth: 500},';
2618 }
2619
2620
2621
2622 // limit to parent
2623 if( !empty( $this->options['parent'] ) ){
2624 echo "parent : " . wp_json_encode( $this->options['parent'] ) . ",";
2625 }
2626
2627 // limit allowed blocks
2628 if( !empty( $this->options['allowed-blocks'] ) ){
2629 echo "allowedBlocks : " . wp_json_encode( $this->options['allowed-blocks'] ) . ",";
2630 }
2631
2632 // maybe set no_wrap
2633 $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
2634 if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) {
2635 $no_wrap = true;
2636 }
2637 if ( $no_wrap ) {
2638 $this->options['block-wrap'] = '';
2639 }
2640
2641 // Maybe load the drag/drop functions.
2642 $img_drag_drop = false;
2643 $show_alignment = false;
2644
2645 echo "attributes : {";
2646
2647 if ( $show_advanced ) {
2648 echo "show_advanced: {";
2649 echo " type: 'boolean',";
2650 echo " default: false";
2651 echo "},";
2652 }
2653
2654 // Block wrap element
2655 if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this?
2656 echo "block_wrap: {";
2657 echo " type: 'string',";
2658 echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "'";
2659 echo "},";
2660 }
2661
2662 if ( ! empty( $this->arguments ) ) {
2663 foreach ( $this->arguments as $key => $args ) {
2664 if ( $args['type'] == 'image' || $args['type'] == 'images' ) {
2665 $img_drag_drop = true;
2666 }
2667
2668 // Set if we should show alignment.
2669 if ( $key == 'alignment' ) {
2670 $show_alignment = true;
2671 }
2672
2673 $extra = '';
2674 $_default = isset( $args['default'] ) && ! is_null( $args['default'] ) ? $args['default'] : '';
2675
2676 if ( ! empty( $_default ) ) {
2677 $_default = wp_slash( $_default );
2678 }
2679
2680 if ( $args['type'] == 'notice' || $args['type'] == 'tab' ) {
2681 continue;
2682 } else if ( $args['type'] == 'checkbox' ) {
2683 $type = 'boolean';
2684 $default = $_default ? 'true' : 'false';
2685 } else if ( $args['type'] == 'number' ) {
2686 $type = 'number';
2687 $default = "'" . $_default . "'";
2688 } else if ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
2689 $type = 'array';
2690 if ( isset( $args['default'] ) && is_array( $args['default'] ) ) {
2691 $default = ! empty( $_default ) ? "['" . implode( "','", $_default ) . "']" : "[]";
2692 } else {
2693 $default = "'" . $_default . "'";
2694 }
2695 } else if ( $args['type'] == 'tagselect' ) {
2696 $type = 'array';
2697 $default = "'" . $_default . "'";
2698 } else if ( $args['type'] == 'multiselect' ) {
2699 $type = 'array';
2700 $default = "'" . $_default . "'";
2701 } else if ( $args['type'] == 'image_xy' ) {
2702 $type = 'object';
2703 $default = "'" . $_default . "'";
2704 } else if ( $args['type'] == 'image' ) {
2705 $type = 'string';
2706 $default = "'" . $_default . "'";
2707 } else {
2708 $type = ! empty( $args['hidden_type'] ) ? esc_attr( $args['hidden_type'] ) : 'string';
2709 $default = "'" . $_default . "'";
2710 }
2711
2712 echo $key . " : {";
2713 echo "type : '$type',";
2714 echo "default : $default";
2715 echo "},";
2716 }
2717 }
2718
2719 echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
2720 echo "sd_shortcode : {type : 'string',default: ''},";
2721
2722 if ( ! empty( $this->options['nested-block'] ) || ! empty( $this->arguments['html'] ) ) {
2723 echo "sd_shortcode_close : {type : 'string',default: ''},";
2724 }
2725
2726 echo "className: { type: 'string', default: '' }";
2727 echo "},";
2728 ?>
2729 // The "edit" property must be a valid function.
2730 edit: function (props) {
2731 const selectedBlock = wp.data.select('core/block-editor').getSelectedBlock();
2732 <?php
2733 // only include the drag/drop functions if required.
2734 if ( $img_drag_drop ) {
2735 ?>
2736
2737 function enableDragSort(listClass) {
2738 setTimeout(function(){
2739 const sortableLists = document.getElementsByClassName(listClass);
2740 Array.prototype.map.call(sortableLists, (list) => {enableDragList(list)});
2741 }, 300);
2742 }
2743
2744 function enableDragList(list) {
2745 Array.prototype.map.call(list.children, (item) => {enableDragItem(item)});
2746 }
2747
2748 function enableDragItem(item) {
2749 item.setAttribute('draggable', true)
2750 item.ondrag = handleDrag;
2751 item.ondragend = handleDrop;
2752 }
2753
2754 function handleDrag(item) {
2755 const selectedItem = item.target,
2756 list = selectedItem.parentNode,
2757 x = event.clientX,
2758 y = event.clientY;
2759
2760 selectedItem.classList.add('drag-sort-active');
2761 let swapItem = document.elementFromPoint(x, y) === null ? selectedItem : document.elementFromPoint(x, y);
2762
2763 if (list === swapItem.parentNode) {
2764 swapItem = swapItem !== selectedItem.nextSibling ? swapItem : swapItem.nextSibling;
2765 list.insertBefore(selectedItem, swapItem);
2766 }
2767 }
2768
2769 function handleDrop(item) {
2770
2771 item.target.classList.remove('drag-sort-active');
2772
2773 const newOrder = [];
2774 let $parent = item.target.parentNode;
2775 let $field = $parent.dataset.field;
2776 let $imgs = JSON.parse('[' + props.attributes[$field] + ']');
2777 item.target.parentNode.classList.add('xxx');
2778 $children = $parent.children;
2779
2780 Object.keys($children).forEach(function(key) {
2781 let $nKey = $children[key].dataset.index
2782 newOrder.push($imgs[$nKey]);
2783 });
2784
2785 // @todo find out why we need to empty the value first otherwise the order is wrong.
2786 props.setAttributes({ [$field]: '' });
2787 setTimeout(function(){
2788 props.setAttributes({ [$field]: JSON.stringify(newOrder).replace('[','').replace(']','') });
2789 }, 100);
2790
2791 }
2792 <?php } ?>
2793
2794 if (typeof(props.attributes.styleid) !== 'undefined') {
2795 var _styleId = props.attributes.styleid, setStyleId;
2796 if (!window.sdStyleId) {
2797 window.sdStyleId = [];
2798 }
2799 if (_styleId) {
2800 if (window.sdStyleId && window.sdStyleId[_styleId] && window.sdStyleId[_styleId] != props.clientId) {
2801 setStyleId = true;
2802 }
2803 } else {
2804 setStyleId = true;
2805 }
2806 if (setStyleId) {
2807 _styleId = 'block-' + (Math.random() + 1).toString(36).substring(2);
2808 }
2809 window.sdStyleId[_styleId] = props.clientId;
2810 if (setStyleId) {
2811 props.setAttributes({'styleid': _styleId});
2812 }
2813 }
2814
2815 <?php
2816 if(!empty($this->options['block-edit-raw'])) {
2817 echo $this->options['block-edit-raw']; // strings have to be in single quotes, may cause issues
2818 }else{
2819 ?>
2820
2821 function hasSelectedInnerBlock(props) {
2822 const select = wp.data.select('core/editor');
2823 const selected = select.getBlockSelectionStart();
2824 const inner = select.getBlock(props.clientId).innerBlocks;
2825 for (let i = 0; i < inner.length; i++) {
2826 if (inner[i].clientId === selected || inner[i].innerBlocks.length && hasSelectedInnerBlock(inner[i])) {
2827 return true;
2828 }
2829 }
2830 return false;
2831 };
2832
2833 const parentBlocksIDs = wp.data.select( 'core/block-editor' ).getBlockParents(props.clientId);
2834 const parentBlocks = wp.data.select('core/block-editor').getBlocksByClientId(parentBlocksIDs);
2835 // const isParentOfSelectedBlock = useSelect( ( select ) => wp.data.select( 'core/block-editor' ).hasSelectedInnerBlock( props.clientId, true ) ):
2836 const block = wp.data.select('core/block-editor').getBlocksByClientId(props.clientId);//.[0].innerBlocks;
2837 const childBlocks = block[0] == null ? '' : block[0].innerBlocks;
2838
2839 var $value = '';
2840 <?php
2841 // if we have a post_type and a category then link them
2842 if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){
2843 ?>
2844 if(typeof(prev_attributes[props.clientId]) != 'undefined' && selectedBlock && selectedBlock.clientId === props.clientId){
2845 $pt = props.attributes.post_type;
2846 if(post_type_rest_slugs.length){
2847 $value = post_type_rest_slugs[0][$pt];
2848 }
2849 var run = false;
2850
2851 if($pt != term_query_type){
2852 run = true;
2853 term_query_type = $pt;
2854 }
2855 <?php
2856 $cat_path = '';
2857 if ( ! empty( $this->arguments['post_type']['onchange_rest']['path'] ) ) {
2858 $cat_path = esc_js( strip_tags( $this->arguments['post_type']['onchange_rest']['path'] ) );
2859 $cat_path = str_replace( array( '&quot;', '&#039;' ), array( '"', "'" ), $cat_path );
2860 }
2861 ?>
2862 /* taxonomies */
2863 if($value && 'post_type' in prev_attributes[props.clientId] && 'category' in prev_attributes[props.clientId] && run){
2864 if (!window.gdCPTCats) {
2865 window.gdCPTCats = [];
2866 }
2867 var gdCatPath = "<?php echo ( ! empty( $cat_path ) ? $cat_path : "/wp/v2/" + $value + "/categories/?per_page=100" ); ?>";
2868 if (window.gdCPTCats[gdCatPath]) {
2869 terms = window.gdCPTCats[gdCatPath];
2870 while (taxonomies_<?php echo str_replace("-","_", $this->id);?>.length) {
2871 taxonomies_<?php echo str_replace("-","_", $this->id);?>.pop();
2872 }
2873 taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: "All", value: 0});
2874 jQuery.each( terms, function( key, val ) {
2875 taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: val.name, value: val.id});
2876 });
2877
2878 /* Setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. */
2879 var $old_cat_value = props.attributes.category
2880 props.setAttributes({category: [0] });
2881 props.setAttributes({category: $old_cat_value });
2882 } else {
2883 wp.apiFetch({path: gdCatPath}).then(terms => {
2884 window.gdCPTCats[gdCatPath] = terms;
2885 while (taxonomies_<?php echo str_replace("-","_", $this->id);?>.length) {
2886 taxonomies_<?php echo str_replace("-","_", $this->id);?>.pop();
2887 }
2888 taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: "All", value: 0});
2889 jQuery.each( terms, function( key, val ) {
2890 taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: val.name, value: val.id});
2891 });
2892
2893 /* Setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. */
2894 var $old_cat_value = props.attributes.category
2895 props.setAttributes({category: [0] });
2896 props.setAttributes({category: $old_cat_value });
2897
2898 return taxonomies_<?php echo str_replace("-","_", $this->id);?>;
2899 });
2900 }
2901 }
2902
2903 /* sort_by */
2904 if($value && 'post_type' in prev_attributes[props.clientId] && 'sort_by' in prev_attributes[props.clientId] && run){
2905 if (!window.gdCPTSort) {
2906 window.gdCPTSort = [];
2907 }
2908 if (window.gdCPTSort[$pt]) {
2909 response = window.gdCPTSort[$pt];
2910 while (sort_by_<?php echo str_replace("-","_", $this->id);?>.length) {
2911 sort_by_<?php echo str_replace("-","_", $this->id);?>.pop();
2912 }
2913
2914 jQuery.each( response, function( key, val ) {
2915 sort_by_<?php echo str_replace("-","_", $this->id);?>.push({label: val, value: key});
2916 });
2917
2918 // setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options.
2919 var $old_sort_by_value = props.attributes.sort_by
2920 props.setAttributes({sort_by: [0] });
2921 props.setAttributes({sort_by: $old_sort_by_value });
2922 } else {
2923 var data = {
2924 'action': 'geodir_get_sort_options',
2925 'post_type': $pt
2926 };
2927 jQuery.post(ajaxurl, data, function(response) {
2928 response = JSON.parse(response);
2929 window.gdCPTSort[$pt] = response;
2930 while (sort_by_<?php echo str_replace("-","_", $this->id);?>.length) {
2931 sort_by_<?php echo str_replace("-","_", $this->id);?>.pop();
2932 }
2933
2934 jQuery.each( response, function( key, val ) {
2935 sort_by_<?php echo str_replace("-","_", $this->id);?>.push({label: val, value: key});
2936 });
2937
2938 // setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options.
2939 var $old_sort_by_value = props.attributes.sort_by
2940 props.setAttributes({sort_by: [0] });
2941 props.setAttributes({sort_by: $old_sort_by_value });
2942
2943 return sort_by_<?php echo str_replace("-","_", $this->id);?>;
2944 });
2945 }
2946 }
2947 }
2948 <?php } ?>
2949 <?php
2950 $current_screen = function_exists('get_current_screen') ? get_current_screen() : '';
2951 if(!empty($current_screen->base) && $current_screen->base==='widgets'){
2952 echo 'const { deviceType } = "";';
2953 }else{
2954 ?>
2955 /** Get device type const. */
2956 const wpVersion = '<?php global $wp_version; echo esc_attr($wp_version); ?>';
2957 const { deviceType } = typeof wp.data.useSelect !== 'undefined' ? wp.data.useSelect(select => {
2958 if (parseFloat(wpVersion) < 6.5) {
2959 const { __experimentalGetPreviewDeviceType } = select('core/edit-site') ? select('core/edit-site') : select('core/edit-post') ? select('core/edit-post') : '';
2960 return {
2961 deviceType: __experimentalGetPreviewDeviceType(),
2962 };
2963 } else {
2964 const editorSelect = select('core/editor');
2965 if (editorSelect) {
2966 return {
2967 deviceType: editorSelect.getDeviceType(),
2968 };
2969 } else {
2970 return {
2971 deviceType: 'Desktop', // Default value if device type is not available
2972 };
2973 }
2974 }
2975 }, []) : '';
2976 <?php } ?>
2977 var content = props.attributes.content, shortcode = '';
2978
2979 function onChangeContent($type) {
2980 $refresh = false;
2981 // Set the old content the same as the new one so we only compare all other attributes
2982 if(typeof(prev_attributes[props.clientId]) != 'undefined'){
2983 prev_attributes[props.clientId].content = props.attributes.content;
2984
2985 // don't compare the sd_shortcode as it is changed later
2986 prev_attributes[props.clientId].sd_shortcode = props.attributes.sd_shortcode;
2987 }else if(props.attributes.content === ""){
2988 // if first load and content empty then refresh
2989 $refresh = true;
2990 } else {
2991 // if not new and has content then set it so we dont go fetch it
2992 if(props.attributes.content && props.attributes.content !== 'Please select the attributes in the block settings'){
2993 prev_attributes[props.clientId] = props.attributes;
2994 }
2995 }
2996
2997 if ( ( !is_fetching && JSON.stringify(prev_attributes[props.clientId]) != JSON.stringify(props.attributes) ) || $refresh ) {
2998 is_fetching = true;
2999
3000 var data = {
3001 'action': 'super_duper_output_shortcode',
3002 'shortcode': '<?php echo $this->options['base_id'];?>',
3003 'attributes': props.attributes,
3004 'block_parent_name': parentBlocks.length ? parentBlocks[parentBlocks.length - 1].name : '',
3005 'post_id': <?php global $post; if ( isset( $post->ID ) ) {
3006 echo $post->ID;
3007 }else{echo '0';}?>,
3008 '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
3009 };
3010
3011 jQuery.post(ajaxurl, data, function (response) {
3012 return response;
3013 }).then(function (env) {
3014 // if the content is empty then we place some placeholder text
3015 if (env == '') {
3016 env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for:', 'ayecode-connect' );?> " + props.name + "</div>";
3017 }
3018
3019 <?php
3020 if(!empty($this->options['nested-block'])){
3021 ?>
3022 // props.setAttributes({content: env});
3023 is_fetching = false;
3024 prev_attributes[props.clientId] = props.attributes;
3025 <?php
3026 }else{
3027 ?>
3028 props.setAttributes({content: env});
3029 is_fetching = false;
3030 prev_attributes[props.clientId] = props.attributes;
3031 <?php
3032 }
3033 ?>
3034
3035 // if AUI is active call the js init function
3036 if (typeof aui_init === "function") {
3037 aui_init();
3038 }
3039 });
3040 }
3041
3042 return props.attributes.content;
3043 }
3044
3045 <?php
3046 if(!empty($this->options['block-edit-js'])) {
3047 echo $this->options['block-edit-js'] ; // strings have to be in single quotes, may cause issues
3048 }
3049
3050 if(empty($this->options['block-save-return'])){
3051 ?>
3052 ///////////////////////////////////////////////////////////////////////
3053
3054 // build the shortcode.
3055 shortcode = "[<?php echo $this->options['base_id'];?>";
3056 <?php
3057
3058 if(! empty( $this->arguments )){
3059
3060 foreach($this->arguments as $key => $args){
3061 // if($args['type']=='tabs'){continue;}
3062
3063 // don't add metadata arguments
3064 if (substr($key, 0, 9 ) === 'metadata_') {
3065 continue;
3066 }
3067 ?>
3068 if (props.attributes.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
3069 if ('<?php echo esc_attr( $key );?>' == 'html') {
3070 } else if ('<?php echo esc_attr( $args['type'] );?>' == 'image_xy') {
3071 shortcode += props.attributes.<?php echo esc_attr( $key );?>.length && ( props.attributes.<?php echo esc_attr( $key );?>.x.length || props.attributes.<?php echo esc_attr( $key );?>.y.length ) ? " <?php echo esc_attr( $key );?>='{x:" + props.attributes.<?php echo esc_attr( $key );?>.x + ",y:"+props.attributes.<?php echo esc_attr( $key );?>.y +"}' " : "";
3072 } else {
3073 //shortcode += props.attributes.<?php echo esc_attr( $key );?>.length ? " <?php echo esc_attr( $key );?>='" + props.attributes.<?php echo esc_attr( $key );?>.toString().replace('\'','&#39;') + "' " : "";
3074 shortcode += " <?php echo esc_attr( $key );?>='" + props.attributes.<?php echo esc_attr( $key );?>.toString().replace('\'','&#39;') + "' ";
3075 }
3076 }
3077 <?php
3078 }
3079 }
3080
3081 ?>
3082 shortcode += "]";
3083
3084 if(shortcode){
3085
3086 // can cause a react exception when selecting multile blocks of the same type when the settings are not the same
3087 if (props.attributes.sd_shortcode !== shortcode) {
3088 props.setAttributes({ sd_shortcode: shortcode });
3089 }
3090
3091
3092 <?php
3093 if(!empty($this->options['nested-block']) || !empty($this->arguments['html']) ){
3094 echo "props.setAttributes({sd_shortcode_close: '[/".esc_attr( $this->options['base_id'] )."]'});";
3095 }
3096 ?>
3097 }
3098
3099
3100 ///////////////////////////////////////////////////////////////////////
3101 <?php
3102 } // end nested block check
3103 ?>
3104
3105 return [
3106
3107 el(wp.blockEditor.BlockControls, {key: 'controls'},
3108
3109 <?php if($show_alignment){?>
3110 el(
3111 wp.blockEditor.AlignmentToolbar,
3112 {
3113 value: props.attributes.alignment,
3114 onChange: function (alignment) {
3115 props.setAttributes({alignment: alignment})
3116 }
3117 }
3118 )
3119 <?php }?>
3120
3121 ),
3122
3123 el(wp.blockEditor.InspectorControls, {key: 'inspector'},
3124
3125 <?php
3126
3127 if(! empty( $this->arguments )){
3128
3129 if ( $show_advanced ) {
3130 ?>
3131 el('div', {
3132 style: {'padding-left': '16px','padding-right': '16px'}
3133 },
3134 el(
3135 wp.components.ToggleControl,
3136 {
3137 label: 'Show Advanced Settings?',
3138 checked: props.attributes.show_advanced,
3139 onChange: function (show_advanced) {
3140 props.setAttributes({show_advanced: !props.attributes.show_advanced})
3141 }
3142 }
3143 )
3144 )
3145 ,
3146 <?php
3147 }
3148
3149 $arguments = $this->group_arguments( $this->arguments );
3150 $block_group_tabs = ! empty( $this->options['block_group_tabs'] ) ? $this->group_block_tabs( $this->options['block_group_tabs'], $arguments ) : array();
3151
3152 // Do we have sections?
3153 $has_sections = $arguments == $this->arguments ? false : true;
3154
3155 if($has_sections){
3156 $panel_count = 0;
3157 $open_tab = '';
3158
3159 $open_tab_groups = array();
3160 $used_tabs = array();
3161
3162 foreach ( $arguments as $key => $args ) {
3163 $close_tab = false;
3164 $close_tabs = false;
3165
3166 if ( ! empty( $block_group_tabs ) ) {
3167 foreach ( $block_group_tabs as $tab_name => $tab_args ) {
3168 if ( in_array( $key, $tab_args['groups'] ) ) {
3169 $open_tab_groups[] = $key;
3170
3171 if ( $open_tab != $tab_name ) {
3172 $tab_args['tab']['tabs_open'] = $open_tab == '' ? true : false;
3173 $tab_args['tab']['open'] = true;
3174
3175 $this->block_tab_start( '', $tab_args );
3176 $open_tab = $tab_name;
3177 $used_tabs[] = $tab_name;
3178 }
3179
3180 if ( $open_tab_groups == $tab_args['groups'] ) {
3181 $close_tab = true;
3182 $open_tab_groups = array();
3183
3184 if ( $used_tabs == array_keys( $block_group_tabs ) ) {
3185 $close_tabs = true;
3186 }
3187 }
3188 }
3189 }
3190 }
3191 ?>
3192 el(wp.components.PanelBody, {
3193 title: '<?php esc_attr_e( $key ); ?>',
3194 initialOpen: <?php if ( $panel_count ) {
3195 echo "false";
3196 } else {
3197 echo "true";
3198 }?>
3199 },
3200 <?php
3201 foreach ( $args as $k => $a ) {
3202 $this->block_tab_start( $k, $a );
3203 $this->block_row_start( $k, $a );
3204 $this->build_block_arguments( $k, $a );
3205 $this->block_row_end( $k, $a );
3206 $this->block_tab_end( $k, $a );
3207 }
3208 ?>
3209 ),
3210 <?php
3211 $panel_count ++;
3212
3213 if($close_tab || $close_tabs){
3214 $tab_args = array(
3215 'tab' => array(
3216 'tabs_close' => $close_tabs,
3217 'close' => true,
3218 )
3219
3220 );
3221 $this->block_tab_end( '', $tab_args );
3222 // echo '###close'; print_r($tab_args);
3223 $panel_count = 0;
3224 }
3225 //
3226
3227 }
3228 }else {
3229 ?>
3230 el(wp.components.PanelBody, {
3231 title: '<?php esc_attr_e( "Settings", 'ayecode-connect' ); ?>',
3232 initialOpen: true
3233 },
3234 <?php
3235 foreach ( $this->arguments as $key => $args ) {
3236 $this->block_row_start( $key, $args );
3237 $this->build_block_arguments( $key, $args );
3238 $this->block_row_end( $key, $args );
3239 }
3240 ?>
3241 ),
3242 <?php
3243 }
3244
3245 }
3246 ?>
3247
3248 ),
3249
3250 <?php
3251 // If the user sets block-output array then build it
3252 if ( ! empty( $this->options['block-output'] ) ) {
3253 $this->block_element( $this->options['block-output'] );
3254 }elseif(!empty($this->options['block-edit-return'])){
3255 echo $this->options['block-edit-return'];
3256 }else{
3257 // if no block-output is set then we try and get the shortcode html output via ajax.
3258 $block_edit_wrap_tag = !empty($this->options['block_edit_wrap_tag']) ? esc_attr($this->options['block_edit_wrap_tag']) : 'div';
3259 ?>
3260 el('<?php echo esc_attr($block_edit_wrap_tag); ?>', wp.blockEditor.useBlockProps({
3261 dangerouslySetInnerHTML: {__html: onChangeContent()},
3262 className: props.className,
3263 <?php //if(isset($this->arguments['visibility_conditions'])){ echo 'dataVisibilityConditionSD: props.visibility_conditions ? true : false,';} //@todo we need to implement this in the other outputs also ?>
3264 style: {'minHeight': '30px'}
3265 }))
3266 <?php
3267 }
3268 ?>
3269 ]; // end return
3270
3271 <?php
3272 } // end block-edit-raw else
3273 ?>
3274 },
3275
3276 // The "save" property must be specified and must be a valid function.
3277 save: function (props) {
3278
3279 var attr = props.attributes;
3280 var align = '';
3281
3282 // build the shortcode.
3283 var content = "[<?php echo $this->options['base_id'];?>";
3284 $html = '';
3285 <?php
3286
3287 if(! empty( $this->arguments )){
3288
3289 foreach($this->arguments as $key => $args){
3290 // if($args['type']=='tabs'){continue;}
3291
3292 // don't add metadata arguments
3293 if (substr($key, 0, 9 ) === 'metadata_') {
3294 continue;
3295 }
3296 ?>
3297 if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
3298 if ('<?php echo esc_attr( $key );?>' == 'html') {
3299 $html = attr.<?php echo esc_attr( $key );?>;
3300 } else if ('<?php echo esc_attr( $args['type'] );?>' == 'image_xy') {
3301 content += " <?php echo esc_attr( $key );?>='{x:" + attr.<?php echo esc_attr( $key );?>.x + ",y:"+attr.<?php echo esc_attr( $key );?>.y +"}' ";
3302 } else {
3303 content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>.toString().replace('\'','&#39;') + "' ";
3304 }
3305 }
3306 <?php
3307 }
3308 }
3309
3310 ?>
3311 content += "]";
3312 content = '';
3313
3314 <?php
3315 // if(!empty($this->options['nested-block'])){
3316 // ?>
3317 // $html = 'el( InnerBlocks.Content )';
3318 // <?php
3319 // }
3320 ?>
3321 // if has html element
3322 if ($html) {
3323 //content += $html + "[/<?php echo $this->options['base_id'];?>]";
3324 }
3325
3326 // @todo should we add inline style here or just css classes?
3327 if (attr.alignment) {
3328 if (attr.alignment == 'left') {
3329 align = 'alignleft';
3330 }
3331 if (attr.alignment == 'center') {
3332 align = 'aligncenter';
3333 }
3334 if (attr.alignment == 'right') {
3335 align = 'alignright';
3336 }
3337 }
3338
3339 <?php
3340 // if(!empty($this->options['nested-block'])){
3341 // ?x>
3342 // return el(
3343 // 'div',
3344 // { className: props.className,
3345 // style: {'minHeight': '300px','position':'relative','overflow':'hidden','backgroundImage': 'url(https://s.w.org/images/core/5.5/don-quixote-06.jpg)'}
3346 // },
3347 // el( InnerBlocks.Content ),
3348 // el('div', {dangerouslySetInnerHTML: {__html: content}, className: align})
3349 // );
3350 // <x?php
3351 // }else
3352
3353 if(!empty($this->options['block-output'])){
3354 // echo "return";
3355 // $this->block_element( $this->options['block-output'], true );
3356 // echo ";";
3357
3358 ?>
3359 return el(
3360 '',
3361 {},
3362 // el('', {dangerouslySetInnerHTML: {__html: content}}),
3363 <?php $this->block_element( $this->options['block-output'], true ); ?>
3364 // el('', {dangerouslySetInnerHTML: {__html: "[/<?php echo $this->options['base_id'];?>]"}})
3365 );
3366 <?php
3367
3368 }elseif(!empty($this->options['block-save-return'])){
3369 echo 'return ' . $this->options['block-save-return'];
3370 }elseif(!empty($this->options['nested-block'])){
3371 ?>
3372 return el(
3373 '',
3374 {},
3375 el('', {dangerouslySetInnerHTML: {__html: content+"\n"}}),
3376 InnerBlocks.Content ? el( InnerBlocks.Content ) : '', // @todo i think we need a comma here
3377 // el('', {dangerouslySetInnerHTML: {__html: "[/<?php echo $this->options['base_id'];?>]"}})
3378 );
3379 <?php
3380 }elseif(!empty( $this->options['block-save-return'] ) ){
3381 echo "return ". $this->options['block-edit-return'].";";
3382 }elseif(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){
3383 ?>
3384 return content;
3385 <?php
3386 }else{
3387 ?>
3388 var block_wrap = 'div';
3389 if (attr.hasOwnProperty("block_wrap")) {
3390 block_wrap = attr.block_wrap;
3391 }
3392 return el(block_wrap, wp.blockEditor.useBlockProps.save( {dangerouslySetInnerHTML: {__html: content}, className: align} ));
3393 <?php
3394 }
3395 ?>
3396
3397
3398 }
3399 });
3400 })(
3401 window.wp.blocks,
3402 window.wp.element,
3403 window.wp.blockEditor
3404 );
3405
3406 });
3407 </script>
3408 <?php
3409 $output = ob_get_clean();
3410
3411 /*
3412 * We only add the <script> tags for code highlighting, so we strip them from the output.
3413 */
3414
3415 return str_replace( array(
3416 '<script>',
3417 '</script>'
3418 ), '', $output );
3419 }
3420
3421
3422
3423 public function block_row_start($key, $args){
3424
3425 // check for row
3426 if(!empty($args['row'])){
3427
3428 if(!empty($args['row']['open'])){
3429
3430 // element require
3431 $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
3432 $device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : '';
3433 $device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : '';
3434 $device_type_icon = '';
3435 if($device_type=='Desktop'){
3436 $device_type_icon = '<span class="dashicons dashicons-desktop" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
3437 }elseif($device_type=='Tablet'){
3438 $device_type_icon = '<span class="dashicons dashicons-tablet" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
3439 }elseif($device_type=='Mobile'){
3440 $device_type_icon = '<span class="dashicons dashicons-smartphone" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
3441 }
3442 echo $element_require;
3443 echo $device_type_require;
3444
3445 if(false){?><script><?php }?>
3446 el('div', {
3447 className: 'bsui components-base-control',
3448 },
3449 <?php if(!empty($args['row']['title'])){ ?>
3450 el('label', {
3451 className: 'components-base-control__label position-relative',
3452 style: {width:"100%"}
3453 },
3454 el('span',{dangerouslySetInnerHTML: {__html: '<?php echo addslashes( $args['row']['title'] ) ?>'}}),
3455 <?php if($device_type_icon){ ?>
3456 deviceType == '<?php echo $device_type;?>' && el('span',{dangerouslySetInnerHTML: {__html: '<?php echo $device_type_icon; ?>'},title: deviceType + ": Set preview mode to change",style: {right:"0",position:"absolute",color:"var(--wp-admin-theme-color)"}})
3457 <?php
3458 }
3459 ?>
3460
3461
3462 ),
3463 <?php }?>
3464 <?php if(!empty($args['row']['desc'])){ ?>
3465 el('p', {
3466 className: 'components-base-control__help mb-0',
3467 },
3468 '<?php echo addslashes( $args['row']['desc'] ); ?>'
3469 ),
3470 <?php }?>
3471 el(
3472 'div',
3473 {
3474 className: 'row mb-n2 <?php if(!empty($args['row']['class'])){ echo esc_attr($args['row']['class']);} ?>',
3475 },
3476 el(
3477 'div',
3478 {
3479 className: 'col pr-2 pe-2',
3480 },
3481
3482 <?php
3483 if(false){?></script><?php }
3484 }elseif(!empty($args['row']['close'])){
3485 if(false){?><script><?php }?>
3486 el(
3487 'div',
3488 {
3489 className: 'col pl-0 ps-0',
3490 },
3491 <?php
3492 if(false){?></script><?php }
3493 }else{
3494 if(false){?><script><?php }?>
3495 el(
3496 'div',
3497 {
3498 className: 'col pl-0 ps-0 pr-2 pe-2',
3499 },
3500 <?php
3501 if(false){?></script><?php }
3502 }
3503
3504 }
3505
3506 }
3507
3508 public function block_row_end($key, $args){
3509
3510 if(!empty($args['row'])){
3511 // maybe close
3512 if(!empty($args['row']['close'])){
3513 echo "))";
3514 }
3515
3516 echo "),";
3517 }
3518 }
3519
3520 public function block_tab_start($key, $args){
3521
3522 // check for row
3523 if(!empty($args['tab'])){
3524
3525 if(!empty($args['tab']['tabs_open'])){
3526
3527 if(false){?><script><?php }?>
3528
3529 el('div',{className: 'bsui'},
3530
3531 el('hr', {className: 'm-0'}), el(
3532 wp.components.TabPanel,
3533 {
3534 activeClass: 'is-active',
3535 className: 'btn-groupx',
3536 initialTabName: '<?php echo addslashes( esc_attr( $args['tab']['key']) ); ?>',
3537 tabs: [
3538
3539 <?php
3540 if(false){?></script><?php }
3541 }
3542
3543 if(!empty($args['tab']['open'])){
3544
3545 if(false){?><script><?php }?>
3546 {
3547 name: '<?php echo addslashes( esc_attr( $args['tab']['key']) ); ?>',
3548 title: el('div', {dangerouslySetInnerHTML: {__html: '<?php echo addslashes( esc_attr( $args['tab']['title']) ); ?>'}}),
3549 className: '<?php echo addslashes( esc_attr( $args['tab']['class']) ); ?>',
3550 content: el('div',{}, <?php if(!empty($args['tab']['desc'])){ ?>el('p', {
3551 className: 'components-base-control__help mb-0',
3552 dangerouslySetInnerHTML: {__html:'<?php echo addslashes( $args['tab']['desc'] ); ?>'}
3553 }),<?php }
3554 if(false){?></script><?php }
3555 }
3556
3557 }
3558
3559 }
3560
3561 public function block_tab_end($key, $args){
3562
3563 if(!empty($args['tab'])){
3564 // maybe close
3565 if(!empty($args['tab']['close'])){
3566 echo ")}, /* tab close */";
3567 }
3568
3569 if(!empty($args['tab']['tabs_close'])){
3570 if(false){?><script><?php }?>
3571 ]}, ( tab ) => {
3572 return tab.content;
3573 }
3574 )), /* tabs close */
3575 <?php if(false){ ?></script><?php }
3576 }
3577 }
3578 }
3579
3580 public function build_block_arguments( $key, $args ) {
3581 global $aui_bs5;
3582
3583 $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
3584 $options = '';
3585 $extra = '';
3586 $require = '';
3587 $inside_elements = '';
3588 $after_elements = '';
3589
3590 // `content` is a protected and special argument
3591 if ( $key == 'content' ) {
3592 return;
3593 }
3594
3595 $device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : '';
3596 $device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : '';
3597 $device_type_icon = '';
3598 if($device_type=='Desktop'){
3599 $device_type_icon = '<span class="dashicons dashicons-desktop" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
3600 }elseif($device_type=='Tablet'){
3601 $device_type_icon = '<span class="dashicons dashicons-tablet" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
3602 }elseif($device_type=='Mobile'){
3603 $device_type_icon = '<span class="dashicons dashicons-smartphone" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
3604 }
3605
3606 // icon
3607 $icon = '';
3608 if( !empty( $args['icon'] ) ){
3609 $icon .= "el('div', {";
3610 $icon .= "dangerouslySetInnerHTML: {__html: '".self::get_widget_icon( esc_attr($args['icon']))."'},";
3611 $icon .= "className: 'text-center',";
3612 $icon .= "title: '".addslashes( $args['title'] )."',";
3613 $icon .= "}),";
3614
3615 // blank title as its added to the icon.
3616 $args['title'] = '';
3617 }
3618
3619 // require advanced
3620 $require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : "";
3621
3622 // element require
3623 $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
3624
3625
3626 $onchange = "props.setAttributes({ $key: $key } )";
3627 $onchangecomplete = "";
3628 $value = "props.attributes.$key";
3629 $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx','range' );
3630 if ( in_array( $args['type'], $text_type ) ) {
3631 $type = 'TextControl';
3632 // Save numbers as numbers and not strings
3633 if ( $args['type'] == 'number' ) {
3634 $onchange = "props.setAttributes({ $key: $key ? Number($key) : '' } )";
3635 }
3636
3637 if (substr($key, 0, 9 ) === 'metadata_') {
3638 $real_key = str_replace('metadata_','', $key );
3639 $onchange = "props.setAttributes({ metadata: { $real_key: $key } } )";
3640 $value = "props.attributes.metadata && props.attributes.metadata.$real_key ? props.attributes.metadata.$real_key : ''";
3641 }
3642 }
3643 // else if ( $args['type'] == 'popup' ) {
3644 // $type = 'TextControl';
3645 // $args['type'] == 'text';
3646 // $after_elements .= "el( wp.components.Button, {
3647 // className: 'components-button components-circular-option-picker__clear is-primary is-smallx',
3648 // onClick: function(){
3649 // aui_modal('','<input id=\'zzz\' value= />');
3650 // const source = document.getElementById('zzz');
3651 // source.value = props.attributes.$key;
3652 // source.addEventListener('input', function(e){props.setAttributes({ $key: e.target.value });});
3653 // }
3654 // },
3655 // 'test'
3656 // ),";
3657 //
3658 // $value = "props.attributes.$key ? props.attributes.$key : ''";
3659 // }
3660 else if ( $args['type'] == 'styleid' ) {
3661 $type = 'TextControl';
3662 $args['type'] == 'text';
3663 // Save numbers as numbers and not strings
3664 $value = "props.attributes.$key ? props.attributes.$key : ''";
3665 }else if ( $args['type'] == 'notice' ) {
3666
3667 $notice_message = !empty($args['desc']) ? addslashes($args['desc']) : '';
3668 $notice_status = !empty($args['status']) ? esc_attr($args['status']) : 'info';
3669
3670 $notice = "el('div',{className:'bsui'},el(wp.components.Notice, {status: '$notice_status',isDismissible: false,className: 'm-0 pr-0 pe-0 mb-3'},el('div',{dangerouslySetInnerHTML: {__html: '$notice_message'}}))),";
3671 echo $notice_message ? $element_require . $notice : '';
3672 return;
3673 }
3674 /*
3675 * https://www.wptricks.com/question/set-current-tab-on-a-gutenberg-tabpanel-component-from-outside-that-component/ es5 layout
3676 elseif($args['type']=='tabs'){
3677 ?>
3678 el(
3679 wp.components.TabPanel,
3680 {
3681 activeClass: 'active-tab',
3682 initialTabName: deviceType,
3683 tabs: [
3684 {
3685 name: 'Desktop',
3686 title: el('div', {dangerouslySetInnerHTML: {__html: '<i class="fas fa-desktop"></i>'}}),
3687 className: 'tab-one' + deviceType == 'Desktop' ? ' active-tab' : '',
3688 content: el('div', {dangerouslySetInnerHTML: {__html: 'ddd'}})
3689 },
3690 {
3691 name: 'Tablet',
3692 title: el('div', {dangerouslySetInnerHTML: {__html: '<i class="fas fa-tablet-alt"></i>'}}),
3693 className: 'tab-two' + deviceType == 'Tablet' ? ' active-tab' : '',
3694 content: el('div', {dangerouslySetInnerHTML: {__html: 'ttt'}})
3695 },
3696 {
3697 name: 'Mobile',
3698 title: el('div', {dangerouslySetInnerHTML: {__html: '<i class="fas fa-mobile-alt"></i>'}}),
3699 className: 'tab-two' + deviceType == 'Mobile' ? ' active-tab' : '',
3700 content: el('div', {dangerouslySetInnerHTML: {__html: 'mmm'}})
3701 },
3702 ],
3703 },
3704 ( tab ) => {
3705
3706 // @todo https://github.com/WordPress/gutenberg/issues/39248
3707 if(tab.name=='Desktop'){
3708 wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Desktop');
3709 wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType();
3710 }else if(tab.name=='Tablet'){
3711 wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Tablet');
3712 wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType();
3713 }else if(tab.name=='Mobile'){
3714 wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Mobile');
3715 wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType();
3716 }
3717
3718 return tab.content;
3719
3720 }
3721 ),
3722
3723 <?php
3724 return;
3725 }
3726 */
3727 elseif ( $args['type'] == 'color' ) {
3728 $type = 'ColorPicker';
3729 $onchange = "";
3730 $extra = "color: $value,";
3731 if(!empty($args['disable_alpha'])){
3732 $extra .= "disableAlpha: true,";
3733 }
3734 $onchangecomplete = "onChangeComplete: function($key) {
3735 value = $key.rgb.a && $key.rgb.a < 1 ? \"rgba(\"+$key.rgb.r+\",\"+$key.rgb.g+\",\"+$key.rgb.b+\",\"+$key.rgb.a+\")\" : $key.hex;
3736 props.setAttributes({
3737 $key: value
3738 });
3739 },";
3740 }elseif ( $args['type'] == 'gradient' ) {
3741 $type = 'GradientPicker';
3742 $extra .= "gradients: [{
3743 name: 'Vivid cyan blue to vivid purple',
3744 gradient:
3745 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
3746 slug: 'vivid-cyan-blue-to-vivid-purple',
3747 },
3748 {
3749 name: 'Light green cyan to vivid green cyan',
3750 gradient:
3751 'linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%)',
3752 slug: 'light-green-cyan-to-vivid-green-cyan',
3753 },
3754 {
3755 name: 'Luminous vivid amber to luminous vivid orange',
3756 gradient:
3757 'linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%)',
3758 slug: 'luminous-vivid-amber-to-luminous-vivid-orange',
3759 },
3760 {
3761 name: 'Luminous vivid orange to vivid red',
3762 gradient:
3763 'linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%)',
3764 slug: 'luminous-vivid-orange-to-vivid-red',
3765 },
3766 {
3767 name: 'Very light gray to cyan bluish gray',
3768 gradient:
3769 'linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%)',
3770 slug: 'very-light-gray-to-cyan-bluish-gray',
3771 },
3772 {
3773 name: 'Cool to warm spectrum',
3774 gradient:
3775 'linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%)',
3776 slug: 'cool-to-warm-spectrum',
3777 }],";
3778
3779 }elseif ( $args['type'] == 'image' ) {
3780 // print_r($args);
3781
3782 $img_preview = isset($args['focalpoint']) && !$args['focalpoint'] ? " props.attributes.$key && el('img', { src: props.attributes.$key,style: {maxWidth:'100%',background: '#ccc'}})," : " ( props.attributes.$key || props.attributes.{$key}_use_featured ) && el(wp.components.FocalPointPicker,{
3783 url: props.attributes.{$key}_use_featured === true ? 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxzdmcgYmFzZVByb2ZpbGU9InRpbnkiIGhlaWdodD0iNDAwIiB2ZXJzaW9uPSIxLjIiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6ZXY9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEveG1sLWV2ZW50cyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzIC8+PHJlY3QgZmlsbD0iI2QzZDNkMyIgaGVpZ2h0PSI0MDAiIHdpZHRoPSI0MDAiIHg9IjAiIHk9IjAiIC8+PGxpbmUgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIxMCIgeDE9IjAiIHgyPSI0MDAiIHkxPSIwIiB5Mj0iNDAwIiAvPjxsaW5lIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMTAiIHgxPSIwIiB4Mj0iNDAwIiB5MT0iNDAwIiB5Mj0iMCIgLz48cmVjdCBmaWxsPSIjZDNkM2QzIiBoZWlnaHQ9IjUwIiB3aWR0aD0iMjE4LjAiIHg9IjkxLjAiIHk9IjE3NS4wIiAvPjx0ZXh0IGZpbGw9IndoaXRlIiBmb250LXNpemU9IjMwIiBmb250LXdlaWdodD0iYm9sZCIgdGV4dC1hbmNob3I9Im1pZGRsZSIgeD0iMjAwLjAiIHk9IjIwNy41Ij5QTEFDRUhPTERFUjwvdGV4dD48L3N2Zz4=' : props.attributes.$key,
3784 value: props.attributes.{$key}_xy.x !== undefined && props.attributes.{$key}_xy.x >= 0 ? props.attributes.{$key}_xy : {x: 0.5,y: 0.5,},
3785 // value: props.attributes.{$key}_xy,
3786 onChange: function(focalPoint){
3787 console.log(props.attributes);
3788 return props.setAttributes({
3789 {$key}_xy: focalPoint
3790 });
3791 },
3792 // @todo for some reason this does not work as expected.
3793 // onDrag: function(focalPointTemp){
3794 // return props.setAttributes({
3795 // {$key}_xy: focalPointTemp
3796 // });
3797 // }
3798
3799
3800 }), ";
3801
3802
3803 $value = '""';
3804 $type = 'MediaUpload';
3805 $extra .= "onSelect: function(media){
3806 return props.setAttributes({
3807 $key: media.url,
3808 {$key}_id: media.id
3809 });
3810 },";
3811 $extra .= "type: 'image',";
3812 $extra .= "render: function (obj) {
3813 return el( 'div',{},
3814 ( !props.attributes.$key && !props.attributes.{$key}_use_featured ) && el( wp.components.Button, {
3815 className: 'components-button components-circular-option-picker__clear is-primary is-smallx',
3816 onClick: obj.open
3817 },
3818 'Upload Image'
3819 ),
3820 $img_preview
3821 props.attributes.$key && el( wp.components.Button, {
3822 className: 'components-button components-circular-option-picker__clear is-secondary is-small',
3823 style: {margin:'8px 0',display: 'block'},
3824 onClick: function(){
3825 return props.setAttributes({
3826 $key: '',
3827 {$key}_id: ''
3828 });
3829 }
3830 },
3831 props.attributes.$key? 'Clear' : ''
3832 )
3833 )
3834
3835
3836
3837 }";
3838 $onchange = "";
3839
3840 //$inside_elements = ",el('div',{},'file upload')";
3841 } else if ( $args['type'] == 'images' ) {
3842 $img_preview = "props.attributes.$key && (function() {
3843 let uploads = JSON.parse('['+props.attributes.$key+']');
3844 let images = [];
3845 uploads.map((upload, index) => (
3846 images.push( el('div',{ className: 'col p-2', draggable: 'true', 'data-index': index },
3847 el('img', {
3848 src: (upload.sizes && upload.sizes.thumbnail ? upload.sizes.thumbnail.url : upload.url),
3849 style: { maxWidth:'100%', background: '#ccc', pointerEvents:'none' }
3850 }),
3851 el('i',{
3852 className: 'fas fa-times-circle text-danger position-absolute ml-n2 mt-n1 bg-white rounded-circle c-pointer',
3853 onClick: function() {
3854 aui_confirm('".esc_attr__('Are you sure?')."', '".esc_attr__('Delete')."', '".esc_attr__('Cancel')."', true).then(function(confirmed) {
3855 if (confirmed) {
3856 let new_uploads = JSON.parse('['+props.attributes.$key+']');
3857 new_uploads.splice(index, 1);
3858 return props.setAttributes({ {$key}: JSON.stringify( new_uploads ).replace('[','').replace(']','') });
3859 }
3860 });
3861 }},
3862 '')
3863 ))
3864 ));
3865 return images;
3866 })(),";
3867
3868
3869 $value = '""';
3870 $type = 'MediaUpload';
3871 $extra .= "onSelect: function(media){
3872 let slim_images = props.attributes.$key ? JSON.parse('['+props.attributes.$key+']') : [];
3873 if(media.length){
3874 for (var i=0; i < media.length; i++) {
3875 slim_images.push({id: media[i].id, caption: media[i].caption, description: media[i].description,title: media[i].title,alt: media[i].alt,sizes: media[i].sizes, url: media[i].url});
3876 }
3877 }
3878 var slimImagesV = JSON.stringify(slim_images);
3879 if (slimImagesV) {
3880 slimImagesV = slimImagesV.replace('[','').replace(']','').replace(/'/g, '&#39;');
3881 }
3882 return props.setAttributes({ $key: slimImagesV});
3883 },";
3884 $extra .= "type: 'image',";
3885 $extra .= "multiple: true,";
3886 $extra .= "render: function (obj) {
3887 /* Init the sort */
3888 enableDragSort('sd-sortable');
3889 return el( 'div',{},
3890 el( wp.components.Button, {
3891 className: 'components-button components-circular-option-picker__clear is-primary is-smallx',
3892 onClick: obj.open
3893 },
3894 'Upload Images'
3895 ),
3896 el('div',{
3897 className: 'row row-cols-3 px-2 sd-sortable',
3898 'data-field':'$key'
3899 },
3900 $img_preview
3901 ),
3902 props.attributes.$key && el( wp.components.Button, {
3903 className: 'components-button components-circular-option-picker__clear is-secondary is-small',
3904 style: {margin:'8px 0'},
3905 onClick: function(){
3906 return props.setAttributes({ $key: '' });
3907 }
3908 },
3909 props.attributes.$key ? 'Clear All' : ''
3910 )
3911 )
3912 }";
3913 $onchange = "";
3914
3915 //$inside_elements = ",el('div',{},'file upload')";
3916 }
3917 elseif ( $args['type'] == 'checkbox' ) {
3918 $type = 'CheckboxControl';
3919 $extra .= "checked: props.attributes.$key,";
3920 $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
3921 } elseif ( $args['type'] == 'textarea' ) {
3922 $type = 'TextareaControl';
3923
3924 } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
3925 $type = 'SelectControl';
3926
3927 if($args['name'] == 'category' && !empty($args['post_type_linked'])){
3928 $options .= "options: taxonomies_".str_replace("-","_", $this->id).",";
3929 }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){
3930 $options .= "options: sort_by_".str_replace("-","_", $this->id).",";
3931 }else {
3932
3933 if ( ! empty( $args['options'] ) ) {
3934 $options .= "options: [";
3935 foreach ( $args['options'] as $option_val => $option_label ) {
3936 $options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . esc_js( addslashes( $option_label ) ) . "' },";
3937 }
3938 $options .= "],";
3939 }
3940 }
3941 if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
3942 $extra .= ' multiple:true,style:{height:"auto",paddingRight:"8px","overflow-y":"auto"}, ';
3943 }
3944
3945 if($args['type'] == 'multiselect' || ( isset( $args['multiple'] ) && $args['multiple'] ) ){
3946 $after_elements .= "props.attributes.$key && el( wp.components.Button, {
3947 className: 'components-button components-circular-option-picker__clear is-secondary is-small',
3948 style: {margin:'-8px 0 8px 0',display: 'block'},
3949 onClick: function(){
3950 return props.setAttributes({
3951 $key: '',
3952 });
3953 }
3954 },
3955 'Clear'
3956 ),";
3957 }
3958 } elseif ( $args['type'] == 'tagselect' ) {
3959 // $type = 'FormTokenField';
3960 //
3961 // if ( ! empty( $args['options'] ) ) {
3962 // $options .= "suggestions: [";
3963 // foreach ( $args['options'] as $option_val => $option_label ) {
3964 // $options .= "{ value: '" . esc_attr( $option_val ) . "', title: '" . addslashes( $option_label ) . "' },";
3965 //// $options .= "'" . esc_attr( $option_val ) . "':'" . addslashes( $option_label ) . "',";
3966 // }
3967 // $options .= "],";
3968 // }
3969 //
3970 // $onchangex = "{ ( selectedItems ) => {
3971 // // Build array of selected posts.
3972 // let selectedPostsArray = [];
3973 // selectedPosts.map(
3974 // ( postName ) => {
3975 // const matchingPost = posts.find( ( post ) => {
3976 // return post.title.raw === postName;
3977 //
3978 // } );
3979 // if ( matchingPost !== undefined ) {
3980 // selectedPostsArray.push( matchingPost.id );
3981 // }
3982 // }
3983 // )
3984 //
3985 // setAttributes( { selectedPosts: selectedPostsArray } );
3986 // } } ";
3987 // $onchange = '';// "props.setAttributes({ $key: [ props.attributes.$key ] } )";
3988 //
3989 //// $options = "";
3990 // $value = "[]";
3991 // $extra .= ' __experimentalExpandOnFocus: true,';
3992
3993 } else if ( $args['type'] == 'alignment' ) {
3994 $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
3995 } else if ( $args['type'] == 'margins' ) {
3996
3997 } else if ( $args['type'] == 'visibility_conditions' && $this->supports_block_visibility() ) {
3998 $type = 'TextControl';
3999 $value = "(props.attributes.$key ? props.attributes.$key : '')";
4000 $args['type'] = 'text';
4001 $options .= 'disabled:true,';
4002 $bsvc_title = esc_attr( addslashes( $args['title'] ) );
4003 $bsvc_body = $this->block_visibility_fields( $args );
4004 // @TODO reset button
4005 $bsvc_footer = '<button type="button" class="btn btn-danger d-none">' . __( 'Reset', 'ayecode-connect' ) . '</button>' . ( $aui_bs5 ? '<button type="button" class="btn btn-secondary bs-vc-close text-white" data-bs-dismiss="modal">' . __( 'Close', 'ayecode-connect' ) . '</button>' : '<button type="button" class="close btn btn-secondary bs-vc-close text-white" data-dismiss="modal" aria-label="' . esc_attr__( 'Close', 'ayecode-connect' ) . '"><span aria-hidden="true">&times;</span></button>' ) . '<button type="button" class="btn btn-primary bs-vc-save">' . __( 'Save Rules', 'ayecode-connect' ) . '</button>';
4006 $after_elements .= "el('div', {className: 'components-base-control bs-vc-button-wrap'}, el(wp.components.Button, {
4007 className: 'components-button components-circular-option-picker__clear is-primary is-smallx',
4008 onClick: function() {
4009 var sValue = props.attributes." . $key . ";
4010 var oValue;
4011 try {oValue = JSON.parse(sValue);} catch(err) {}
4012 jQuery(document).off('show.bs.modal', '.bs-vc-modal').on('show.bs.modal', '.bs-vc-modal', function (e) {
4013 if (e.target && jQuery(e.target).hasClass('bs-vc-modal')) {
4014 sd_block_visibility_render_fields(oValue);
4015 if (!jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule').length) {
4016 jQuery('.bs-vc-modal-form .bs-vc-add-rule').trigger('click');
4017 }
4018 if(typeof aui_init_select2 == 'function') {
4019 aui_init_select2();
4020 }
4021 jQuery('.bs-vc-modal-form').trigger('change');
4022 }
4023 });
4024 aui_modal('" . $bsvc_title . "', '" . addslashes( $bsvc_body ) . "', '" . $bsvc_footer . "', true, 'bs-vc-modal', 'modal-lg', '');
4025 jQuery(document).off('change', '#bsvc_raw_value').on('change', '#bsvc_raw_value', function(e) {
4026 props.setAttributes({" . $key . ": e.target.value});
4027 });
4028 }
4029 },
4030 '" . addslashes( ! empty( $args['button_title'] ) ? $args['button_title'] : $args['title'] ) . "'
4031 ) ),";
4032 } else {
4033 return;// if we have not implemented the control then don't break the JS.
4034 }
4035
4036 // color input does not show the labels so we add them
4037 if($args['type']=='color'){
4038 // add show only if advanced
4039 echo $require_advanced;
4040 // add setting require if defined
4041 echo $element_require;
4042 echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),";
4043 }
4044
4045 // add show only if advanced
4046 echo $require_advanced;
4047 // add setting require if defined
4048 echo $element_require;
4049 echo $device_type_require;
4050
4051 // icon
4052 echo $icon;
4053 ?>
4054 el( <?php echo $args['type'] == 'image' || $args['type'] == 'images' ? $type : "wp.components.".$type; ?>, {
4055 label: <?php if ( empty( $args['title'] ) ) { echo "''"; } else if ( empty( $args['row'] ) && ! empty( $args['device_type'] ) ) { ?>el('label',{className:'components-base-control__label',style:{width:"100%"}},el('span',{dangerouslySetInnerHTML: {__html: '<?php echo addslashes( $args['title'] ) ?>'}}),<?php if ( $device_type_icon ) { ?>deviceType == '<?php echo $device_type;?>' && el('span',{dangerouslySetInnerHTML: {__html: '<?php echo $device_type_icon; ?>'},title: deviceType + ": Set preview mode to change",style: {right:"0",position:"absolute",color:"var(--wp-admin-theme-color)"}})<?php } ?>)<?php
4056 } else { ?>'<?php echo addslashes( trim( esc_html( $args['title'] ) ) ); ?>'<?php } ?>,
4057 help: <?php echo ( isset( $args['desc'] ) ? "el('span', {dangerouslySetInnerHTML: {__html: '" . trim( wp_kses_post( addslashes( $args['desc'] ) ) ) . "'}})" : "''" ); ?>,
4058 value: <?php echo $value; ?>,
4059 <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
4060 echo "type: '" . addslashes( $args['type'] ) . "',";
4061 } ?>
4062 <?php if ( ! empty( $args['placeholder'] ) ) {
4063 echo "placeholder: '" . esc_js( addslashes( trim( esc_html( $args['placeholder'] ) ) ) ) . "',";
4064 } ?>
4065 <?php echo $options; ?>
4066 <?php echo $extra; ?>
4067 <?php echo $custom_attributes; ?>
4068 <?php echo $onchangecomplete; ?>
4069 <?php if ( $onchange ) { ?>
4070 onChange: function ( <?php echo $key; ?> ) {
4071 <?php echo $onchange; ?>
4072 }
4073 <?php } ?>
4074 } <?php echo $inside_elements; ?> ),
4075 <?php
4076 echo $after_elements;
4077 }
4078
4079 /**
4080 * Convert an array of attributes to block string.
4081 *
4082 * @param $custom_attributes
4083 *
4084 * @return string
4085 *@todo there is prob a faster way to do this, also we could add some validation here.
4086 *
4087 */
4088 public function array_to_attributes( $custom_attributes, $html = false ) {
4089 $attributes = '';
4090 if ( ! empty( $custom_attributes ) ) {
4091
4092 foreach ( $custom_attributes as $key => $val ) {
4093 if(is_array($val)){
4094 $attributes .= $key.': {'.$this->array_to_attributes( $val, $html ).'},';
4095 }else{
4096 $attributes .= $html ? " $key='$val' " : "'$key': '$val',";
4097 }
4098 }
4099
4100 }
4101
4102 return $attributes;
4103 }
4104
4105
4106
4107 /**
4108 * A self looping function to create the output for JS block elements.
4109 *
4110 * This is what is output in the WP Editor visual view.
4111 *
4112 * @param $args
4113 */
4114 public function block_element( $args, $save = false ) {
4115
4116 // print_r($args);echo '###';exit;
4117
4118 if ( ! empty( $args ) ) {
4119 foreach ( $args as $element => $new_args ) {
4120
4121 if ( is_array( $new_args ) ) { // its an element
4122
4123
4124 if ( isset( $new_args['element'] ) ) {
4125
4126 if ( isset( $new_args['element_require'] ) ) {
4127 echo str_replace( array(
4128 "'+",
4129 "+'"
4130 ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && ";
4131 unset( $new_args['element_require'] );
4132 }
4133
4134 if($new_args['element']=='InnerBlocks'){
4135 echo "\n el( InnerBlocks, {";
4136 }elseif($new_args['element']=='innerBlocksProps'){
4137 $element = isset($new_args['inner_element']) ? esc_attr($new_args['inner_element']) : 'div';
4138 // echo "\n el( 'section', wp.blockEditor.useInnerBlocksProps( blockProps, {";
4139 // echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( ";
4140 echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( ";
4141 echo $save ? "wp.blockEditor.useBlockProps.save( {" : "wp.blockEditor.useBlockProps( {";
4142 echo !empty($new_args['blockProps']) ? $this->block_element( $new_args['blockProps'],$save ) : '';
4143
4144 echo "} ), {";
4145 echo !empty($new_args['innerBlocksProps']) && !$save ? $this->block_element( $new_args['innerBlocksProps'],$save ) : '';
4146 // echo '###';
4147
4148 // echo '###';
4149 }elseif($new_args['element']=='BlocksProps'){
4150
4151 if ( isset($new_args['if_inner_element']) ) {
4152 $element = $new_args['if_inner_element'];
4153 }else {
4154 $element = isset($new_args['inner_element']) ? "'".esc_attr($new_args['inner_element'])."'" : "'div'";
4155 }
4156
4157 unset($new_args['inner_element']);
4158 echo $save ? "\n el( $element, wp.blockEditor.useBlockProps.save( {" : "\n el( $element, wp.blockEditor.useBlockProps( {";
4159 echo !empty($new_args['blockProps']) ? $this->block_element( $new_args['blockProps'],$save ) : '';
4160
4161
4162 // echo "} ),";
4163
4164 }else{
4165 echo "\n el( '" . $new_args['element'] . "', {";
4166 }
4167
4168
4169 // get the attributes
4170 foreach ( $new_args as $new_key => $new_value ) {
4171
4172
4173 if ( $new_key == 'element' || $new_key == 'content'|| $new_key == 'if_content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
4174 // do nothing
4175 } else {
4176 echo $this->block_element( array( $new_key => $new_value ),$save );
4177 }
4178 }
4179
4180 echo $new_args['element']=='BlocksProps' ? '} ),' : "},";// end attributes
4181
4182 // get the content
4183 $first_item = 0;
4184 foreach ( $new_args as $new_key => $new_value ) {
4185 if ( $new_key === 'content' || $new_key === 'if_content' || is_array( $new_value ) ) {
4186
4187 if ( $new_key === 'content' ) {
4188 echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'";
4189 }else if ( $new_key === 'if_content' ) {
4190 echo $this->block_props_replace( $new_value );
4191 }
4192
4193 if ( is_array( $new_value ) ) {
4194
4195 if ( isset( $new_value['element_require'] ) ) {
4196 echo str_replace( array(
4197 "'+",
4198 "+'"
4199 ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && ";
4200 unset( $new_value['element_require'] );
4201 }
4202
4203 if ( isset( $new_value['element_repeat'] ) ) {
4204 $x = 1;
4205 while ( $x <= absint( $new_value['element_repeat'] ) ) {
4206 $this->block_element( array( '' => $new_value ),$save );
4207 $x ++;
4208 }
4209 } else {
4210 $this->block_element( array( '' => $new_value ),$save );
4211 }
4212 }
4213 $first_item ++;
4214 }
4215 }
4216
4217 if($new_args['element']=='innerBlocksProps' || $new_args['element']=='xBlocksProps'){
4218 echo "))";// end content
4219 }else{
4220 echo ")";// end content
4221 }
4222
4223
4224 echo ", \n";
4225
4226 }
4227 } else {
4228
4229 if ( substr( $element, 0, 3 ) === "if_" ) {
4230 $extra = '';
4231 if( strpos($new_args, '[%WrapClass%]') !== false ){
4232 $new_args = str_replace('[%WrapClass%]"','" + sd_build_aui_class(props.attributes)',$new_args);
4233 $new_args = str_replace('[%WrapClass%]','+ sd_build_aui_class(props.attributes)',$new_args);
4234 }
4235 echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
4236 } elseif ( $element == 'style' && strpos($new_args, '[%WrapStyle%]') !== false ) {
4237 $new_args = str_replace('[%WrapStyle%]','',$new_args);
4238 echo $element . ": {..." . $this->block_props_replace( $new_args ) . " , ...sd_build_aui_styles(props.attributes) },";
4239 // echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
4240 } elseif ( $element == 'style' ) {
4241 echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
4242 } elseif ( ( $element == 'class' || $element == 'className' ) && strpos($new_args, '[%WrapClass%]') !== false ) {
4243 $new_args = str_replace('[%WrapClass%]','',$new_args);
4244 echo $element . ": '" . $this->block_props_replace( $new_args ) . "' + sd_build_aui_class(props.attributes),";
4245 } elseif ( $element == 'template' && $new_args ) {
4246 echo $element . ": $new_args,";
4247 } else {
4248 echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
4249 }
4250
4251 }
4252 }
4253 }
4254 }
4255
4256 /**
4257 * Replace block attributes placeholders with the proper naming.
4258 *
4259 * @param $string
4260 *
4261 * @return mixed
4262 */
4263 public function block_props_replace( $string, $no_wrap = false ) {
4264 if ( $no_wrap ) {
4265 $string = str_replace( array( "[%", "%]", "%:checked]" ), array( "props.attributes.", "", "" ), $string );
4266 } else {
4267 $string = str_replace( array( "![%", "[%", "%]", "%:checked]" ), array( "'+!props.attributes.", "'+props.attributes.", "+'", "+'" ), $string );
4268 }
4269
4270 return $string;
4271 }
4272
4273 /**
4274 * Outputs the content of the widget
4275 *
4276 * @param array $args
4277 * @param array $instance
4278 */
4279 public function widget( $args, $instance ) {
4280 if ( ! is_array( $args ) ) {
4281 $args = array();
4282 }
4283
4284 // Get the filtered values
4285 $argument_values = $this->argument_values( $instance );
4286 $argument_values = $this->string_to_bool( $argument_values );
4287 $output = $this->output( $argument_values, $args );
4288
4289 $no_wrap = false;
4290 if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) {
4291 $no_wrap = true;
4292 }
4293
4294 ob_start();
4295 if ( $output && ! $no_wrap ) {
4296
4297 $class_original = $this->options['widget_ops']['classname'];
4298 $class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash();
4299
4300 // Before widget
4301 $before_widget = ! empty( $args['before_widget'] ) ? $args['before_widget'] : '';
4302 $before_widget = $before_widget ? str_replace( $class_original, $class, $before_widget ) : $before_widget;
4303 $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
4304 $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
4305
4306 // After widget
4307 $after_widget = ! empty( $args['after_widget'] ) ? $args['after_widget'] : '';
4308 $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
4309 $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
4310
4311 echo $before_widget;
4312 // elementor strips the widget wrapping div so we check for and add it back if needed
4313 if ( $this->is_elementor_widget_output() ) {
4314 // Filter class & attrs for elementor widget output.
4315 $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
4316 $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
4317
4318 $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
4319 $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
4320
4321 echo "<span class='" . esc_attr( $class ) . "' " . $attrs . ">";
4322 }
4323 echo $this->output_title( $args, $instance );
4324 echo $output;
4325 if ( $this->is_elementor_widget_output() ) {
4326 echo "</span>";
4327 }
4328 echo $after_widget;
4329 } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
4330 $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
4331 echo $output;
4332 } elseif ( $output && $no_wrap ) {
4333 echo $output;
4334 }
4335 $output = ob_get_clean();
4336
4337 $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this );
4338
4339 echo $output;
4340 }
4341
4342 /**
4343 * Tests if the current output is inside a elementor container.
4344 *
4345 * @return bool
4346 *@since 1.0.4
4347 */
4348 public function is_elementor_widget_output() {
4349 $result = false;
4350 if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
4351 $result = true;
4352 }
4353
4354 return $result;
4355 }
4356
4357 /**
4358 * Tests if the current output is inside a elementor preview.
4359 *
4360 * @return bool
4361 *@since 1.0.4
4362 */
4363 public function is_elementor_preview() {
4364 $result = false;
4365 if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
4366 $result = true;
4367 }
4368
4369 return $result;
4370 }
4371
4372 /**
4373 * Tests if the current output is inside a Divi preview.
4374 *
4375 * @return bool
4376 *@since 1.0.6
4377 */
4378 public function is_divi_preview() {
4379 $result = false;
4380 if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
4381 $result = true;
4382 }
4383
4384 return $result;
4385 }
4386
4387 /**
4388 * Tests if the current output is inside a Beaver builder preview.
4389 *
4390 * @return bool
4391 *@since 1.0.6
4392 */
4393 public function is_beaver_preview() {
4394 $result = false;
4395 if ( isset( $_REQUEST['fl_builder'] ) ) {
4396 $result = true;
4397 }
4398
4399 return $result;
4400 }
4401
4402 /**
4403 * Tests if the current output is inside a siteorigin builder preview.
4404 *
4405 * @return bool
4406 *@since 1.0.6
4407 */
4408 public function is_siteorigin_preview() {
4409 $result = false;
4410 if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
4411 $result = true;
4412 }
4413
4414 return $result;
4415 }
4416
4417 /**
4418 * Tests if the current output is inside a cornerstone builder preview.
4419 *
4420 * @return bool
4421 *@since 1.0.8
4422 */
4423 public function is_cornerstone_preview() {
4424 $result = false;
4425 if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
4426 $result = true;
4427 }
4428
4429 return $result;
4430 }
4431
4432 /**
4433 * Tests if the current output is inside a fusion builder preview.
4434 *
4435 * @return bool
4436 *@since 1.1.0
4437 */
4438 public function is_fusion_preview() {
4439 $result = false;
4440 if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) {
4441 $result = true;
4442 }
4443
4444 return $result;
4445 }
4446
4447 /**
4448 * Tests if the current output is inside a Oxygen builder preview.
4449 *
4450 * @return bool
4451 *@since 1.0.18
4452 */
4453 public function is_oxygen_preview() {
4454 $result = false;
4455 if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) {
4456 $result = true;
4457 }
4458
4459 return $result;
4460 }
4461
4462 /**
4463 * Check for Kallyas theme Zion builder preview.
4464 *
4465 * @since 1.1.22
4466 *
4467 * @return bool True when preview page otherwise false.
4468 */
4469 public function is_kallyas_zion_preview() {
4470 $result = false;
4471
4472 if ( function_exists( 'znhg_kallyas_theme_config' ) && ! empty( $_REQUEST['zn_pb_edit'] ) ) {
4473 $result = true;
4474 }
4475
4476 return $result;
4477 }
4478
4479 /**
4480 * Check for Bricks theme builder preview.
4481 *
4482 * @since 1.1.31
4483 *
4484 * @return bool True when preview page otherwise false.
4485 */
4486 public function is_bricks_preview() {
4487 $result = false;
4488
4489 if ( function_exists( 'bricks_is_builder' ) && ( bricks_is_builder() || bricks_is_builder_call() ) ) {
4490 $result = true;
4491 }
4492
4493 return $result;
4494 }
4495
4496 /**
4497 * Check for Breakdance builder preview.
4498 *
4499 * @since 1.2.28
4500 *
4501 * @return bool True when preview page otherwise false.
4502 */
4503 public function is_breakdance_preview() {
4504 return ( \function_exists( 'Breakdance\\isRequestFromBuilderIframe' ) && ( \Breakdance\isRequestFromBuilderIframe() || \Breakdance\isRequestFromBuilderSsr() ) );
4505 }
4506
4507 /**
4508 * General function to check if we are in a preview situation.
4509 *
4510 * @return bool
4511 *@since 1.0.6
4512 */
4513 public function is_preview() {
4514 $preview = false;
4515 if ( $this->is_divi_preview() ) {
4516 $preview = true;
4517 } elseif ( $this->is_elementor_preview() ) {
4518 $preview = true;
4519 } elseif ( $this->is_beaver_preview() ) {
4520 $preview = true;
4521 } elseif ( $this->is_siteorigin_preview() ) {
4522 $preview = true;
4523 } elseif ( $this->is_cornerstone_preview() ) {
4524 $preview = true;
4525 } elseif ( $this->is_fusion_preview() ) {
4526 $preview = true;
4527 } elseif ( $this->is_oxygen_preview() ) {
4528 $preview = true;
4529 } elseif( $this->is_kallyas_zion_preview() ) {
4530 $preview = true;
4531 } elseif( $this->is_block_content_call() ) {
4532 $preview = true;
4533 } elseif( $this->is_bricks_preview() ) {
4534 $preview = true;
4535 } elseif( $this->is_breakdance_preview() ) {
4536 $preview = true;
4537 }
4538
4539 return $preview;
4540 }
4541
4542 /**
4543 * Output the super title.
4544 *
4545 * @param $args
4546 * @param array $instance
4547 *
4548 * @return string
4549 */
4550 public function output_title( $args, $instance = array() ) {
4551 $output = '';
4552 if ( ! empty( $instance['title'] ) ) {
4553 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
4554 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
4555
4556 if ( empty( $instance['widget_title_tag'] ) ) {
4557 if ( ! isset( $args['before_title'] ) ) {
4558 $args['before_title'] = '';
4559 }
4560
4561 if ( ! isset( $args['after_title'] ) ) {
4562 $args['after_title'] = '';
4563 }
4564
4565 $output = $args['before_title'] . $title . $args['after_title'];
4566 } else {
4567 $tag = esc_attr( $instance['widget_title_tag'] );
4568 $allowed_tags = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'div', 'p' );
4569 $title_tag = in_array( $tag, $allowed_tags, true ) ? esc_attr( $tag ) : 'h2';
4570
4571 // classes
4572 $title_classes = array();
4573 $title_classes[] = !empty( $instance['widget_title_size_class'] ) ? sanitize_html_class( $instance['widget_title_size_class'] ) : '';
4574 $title_classes[] = !empty( $instance['widget_title_align_class'] ) ? sanitize_html_class( $instance['widget_title_align_class'] ) : '';
4575 $title_classes[] = !empty( $instance['widget_title_color_class'] ) ? "text-".sanitize_html_class( $instance['widget_title_color_class'] ) : '';
4576 $title_classes[] = !empty( $instance['widget_title_border_class'] ) ? sanitize_html_class( $instance['widget_title_border_class'] ) : '';
4577 $title_classes[] = !empty( $instance['widget_title_border_color_class'] ) ? "border-".sanitize_html_class( $instance['widget_title_border_color_class'] ) : '';
4578 $title_classes[] = !empty( $instance['widget_title_mt_class'] ) ? "mt-".absint( $instance['widget_title_mt_class'] ) : '';
4579 $title_classes[] = !empty( $instance['widget_title_mr_class'] ) ? "mr-".absint( $instance['widget_title_mr_class'] ) : '';
4580 $title_classes[] = !empty( $instance['widget_title_mb_class'] ) ? "mb-".absint( $instance['widget_title_mb_class'] ) : '';
4581 $title_classes[] = !empty( $instance['widget_title_ml_class'] ) ? "ml-".absint( $instance['widget_title_ml_class'] ) : '';
4582 $title_classes[] = !empty( $instance['widget_title_pt_class'] ) ? "pt-".absint( $instance['widget_title_pt_class'] ) : '';
4583 $title_classes[] = !empty( $instance['widget_title_pr_class'] ) ? "pr-".absint( $instance['widget_title_pr_class'] ) : '';
4584 $title_classes[] = !empty( $instance['widget_title_pb_class'] ) ? "pb-".absint( $instance['widget_title_pb_class'] ) : '';
4585 $title_classes[] = !empty( $instance['widget_title_pl_class'] ) ? "pl-".absint( $instance['widget_title_pl_class'] ) : '';
4586
4587 $class = !empty( $title_classes ) ? implode(" ",$title_classes) : '';
4588 $output = "<$title_tag class='$class' >$title</$title_tag>";
4589 }
4590
4591 }
4592
4593 return $output;
4594 }
4595
4596 /**
4597 * Outputs the options form inputs for the widget.
4598 *
4599 * @param array $instance The widget options.
4600 */
4601 public function form( $instance ) {
4602
4603 // set widget instance
4604 $this->instance = $instance;
4605
4606 // set it as a SD widget
4607 echo $this->widget_advanced_toggle();
4608
4609 echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
4610 $arguments_raw = $this->get_arguments();
4611
4612 if ( is_array( $arguments_raw ) ) {
4613
4614 $arguments = $this->group_arguments( $arguments_raw );
4615
4616 // Do we have sections?
4617 $has_sections = $arguments == $arguments_raw ? false : true;
4618
4619
4620 if ( $has_sections ) {
4621 $panel_count = 0;
4622 foreach ( $arguments as $key => $args ) {
4623
4624 ?>
4625 <script>
4626 // jQuery(this).find("i").toggleClass("fas fa-chevron-up fas fa-chevron-down");jQuery(this).next().toggle();
4627 </script>
4628 <?php
4629
4630 $hide = $panel_count ? ' style="display:none;" ' : '';
4631 $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down';
4632 echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes( $key ) . "'>" . esc_attr( $key ) . " <i style='float:right;' class='" . $icon_class . "'></i></button>";
4633 echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>";
4634
4635 foreach ( $args as $k => $a ) {
4636
4637 $this->widget_inputs_row_start($k, $a);
4638 $this->widget_inputs( $a, $instance );
4639 $this->widget_inputs_row_end($k, $a);
4640
4641 }
4642
4643 echo "</div>";
4644
4645 $panel_count ++;
4646
4647 }
4648 } else {
4649 foreach ( $arguments as $key => $args ) {
4650 $this->widget_inputs_row_start($key, $args);
4651 $this->widget_inputs( $args, $instance );
4652 $this->widget_inputs_row_end($key, $args);
4653 }
4654 }
4655
4656 }
4657 }
4658
4659 public function widget_inputs_row_start( $key, $args ) {
4660 if ( ! empty( $args['row'] ) ) {
4661 // Maybe open
4662 if ( ! empty( $args['row']['open'] ) ) {
4663 ?>
4664 <div class='bsui sd-argument' data-argument='<?php echo esc_attr( $args['row']['key'] ); ?>' data-element_require='<?php echo ( ! empty( $args['row']['element_require'] ) ? $this->convert_element_require( $args['row']['element_require'] ) : '' ); ?>'>
4665 <?php if ( ! empty( $args['row']['title'] ) ) { ?>
4666 <?php
4667 if ( isset( $args['row']['icon'] ) ) {
4668 $args['row']['icon'] = '';
4669 }
4670
4671 if ( ! isset( $args['row']['device_type'] ) && isset( $args['device_type'] ) ) {
4672 $args['row']['device_type'] = $args['device_type'];
4673 }
4674 ?>
4675 <label class="mb-0"><?php echo $this->widget_field_title( $args['row'] ); ?><?php echo $this->widget_field_desc( $args['row'] ); ?></label>
4676 <?php } ?>
4677 <div class='row<?php echo ( ! empty( $args['row']['class'] ) ? ' ' . esc_attr( $args['row']['class'] ) : '' ); ?>'>
4678 <div class='col pr-2'>
4679 <?php
4680 } else if ( ! empty( $args['row']['close'] ) ) {
4681 echo "<div class='col pl-0 ps-0'>";
4682 } else {
4683 echo "<div class='col pl-0 ps-0 pr-2 pe-2'>";
4684 }
4685 }
4686 }
4687
4688 public function widget_inputs_row_end( $key, $args ) {
4689 if ( ! empty( $args['row'] ) ) {
4690 // Maybe close
4691 if ( ! empty( $args['row']['close'] ) ) {
4692 echo "</div></div>";
4693 }
4694 echo "</div>";
4695 }
4696 }
4697
4698 /**
4699 * Get the hidden input that when added makes the advanced button show on widget settings.
4700 *
4701 * @return string
4702 */
4703 public function widget_advanced_toggle() {
4704
4705 $output = '';
4706 if ( $this->block_show_advanced() ) {
4707 $val = 1;
4708 } else {
4709 $val = 0;
4710 }
4711
4712 $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />";
4713
4714 return $output;
4715 }
4716
4717 /**
4718 * Convert require element.
4719 *
4720 * @param string $input Input element.
4721 *
4722 * @return string $output
4723 *@since 1.0.0
4724 *
4725 */
4726 public function convert_element_require( $input ) {
4727 $input = str_replace( "'", '"', $input );// we only want double quotes
4728
4729 $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
4730 "jQuery(form).find('[data-argument=\"",
4731 "\"]').find('input,select,textarea').val()",
4732 "\"]').find('input:checked').val()"
4733 ), $input ) );
4734
4735 return $output;
4736 }
4737
4738 /**
4739 * Builds the inputs for the widget options.
4740 *
4741 * @param $args
4742 * @param $instance
4743 */
4744 public function widget_inputs( $args, $instance ) {
4745
4746 $class = "";
4747 $element_require = "";
4748 $custom_attributes = "";
4749
4750 // get value
4751 if ( isset( $instance[ $args['name'] ] ) ) {
4752 $value = $instance[ $args['name'] ];
4753 } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
4754 $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
4755 } else {
4756 $value = '';
4757 }
4758
4759 // get placeholder
4760 if ( ! empty( $args['placeholder'] ) ) {
4761 $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
4762 } else {
4763 $placeholder = '';
4764 }
4765
4766 // get if advanced
4767 if ( isset( $args['advanced'] ) && $args['advanced'] ) {
4768 $class .= " sd-advanced-setting ";
4769 }
4770
4771 // element_require
4772 if ( isset( $args['element_require'] ) && $args['element_require'] ) {
4773 $element_require = $args['element_require'];
4774 }
4775
4776 // custom_attributes
4777 if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
4778 $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
4779 }
4780
4781 // before wrapper
4782 ?>
4783 <p class="sd-argument <?php echo esc_attr( $class ); ?>" data-argument='<?php echo esc_attr( $args['name'] ); ?>' data-element_require='<?php if ( $element_require ) { echo $this->convert_element_require( $element_require );} ?>'>
4784 <?php
4785 switch ( $args['type'] ) {
4786 //array('text','password','number','email','tel','url','color')
4787 case "text":
4788 case "password":
4789 case "number":
4790 case "email":
4791 case "tel":
4792 case "url":
4793 case "color":
4794 ?>
4795 <label for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args );?><?php echo $this->widget_field_desc( $args ); ?></label>
4796 <input <?php echo $placeholder; ?> class="widefat" <?php echo $custom_attributes; ?> id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="<?php echo esc_attr( $args['type'] ); ?>" value="<?php echo esc_attr( $value ); ?>">
4797 <?php
4798
4799 break;
4800 case "select":
4801 $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
4802 if ( $multiple ) {
4803 if ( empty( $value ) ) {
4804 $value = array();
4805 }
4806 }
4807 ?>
4808 <label for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args ); ?><?php echo $this->widget_field_desc( $args ); ?></label>
4809 <select <?php echo $placeholder; ?> class="widefat" <?php echo $custom_attributes; ?> id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); if ( $multiple ) { echo "[]"; } ?>"
4810 <?php if ( $multiple ) {
4811 echo "multiple";
4812 } //@todo not implemented yet due to gutenberg not supporting it
4813 ?>>
4814 <?php
4815
4816 if ( ! empty( $args['options'] ) ) {
4817 foreach ( $args['options'] as $val => $label ) {
4818 if ( $multiple ) {
4819 $selected = in_array( $val, $value ) ? 'selected="selected"' : '';
4820 } else {
4821 $selected = selected( $value, $val, false );
4822 }
4823 echo "<option value='$val' " . $selected . ">$label</option>";
4824 }
4825 }
4826 ?>
4827 </select>
4828 <?php
4829 break;
4830 case "checkbox":
4831 ?>
4832 <input <?php echo $placeholder; ?> <?php checked( 1, $value, true ) ?> <?php echo $custom_attributes; ?> class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" value="1">
4833 <label for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args );?><?php echo $this->widget_field_desc( $args ); ?></label>
4834 <?php
4835 break;
4836 case "textarea":
4837 ?>
4838 <label for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args ); ?><?php echo $this->widget_field_desc( $args ); ?></label>
4839 <textarea <?php echo $placeholder; ?> class="widefat" <?php echo $custom_attributes; ?> id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>"><?php echo esc_attr( $value ); ?></textarea>
4840 <?php
4841
4842 break;
4843 case "hidden":
4844 ?>
4845 <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" value="<?php echo esc_attr( $value ); ?>">
4846 <?php
4847 break;
4848 default:
4849 echo "No input type found!"; // @todo we need to add more input types.
4850 }
4851 // after wrapper
4852 ?></p><?php
4853 }
4854
4855 public function get_widget_icon($icon = 'box-top', $title = ''){
4856 if($icon=='box-top'){
4857 return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1.048" height="9.017" fill="#555D66"></rect><rect x="16.265" y="5.498" width="1.023" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.186" width="8.964" height="2.482" fill="#272B2F"></rect><rect x="5.487" y="16.261" width="9.026" height="1.037" fill="#555D66"></rect></svg>';
4858 }elseif($icon=='box-right'){
4859 return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1.046" height="9.017" fill="#555D66"></rect><rect x="15.244" y="5.498" width="2.518" height="9.003" fill="#272B2F"></rect><rect x="5.518" y="2.719" width="8.964" height="0.954" fill="#555D66"></rect><rect x="5.487" y="16.308" width="9.026" height="0.99" fill="#555D66"></rect></svg>';
4860 }elseif($icon=='box-bottom'){
4861 return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1" height="9.017" fill="#555D66"></rect><rect x="16.261" y="5.498" width="1.027" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.719" width="8.964" height="0.968" fill="#555D66"></rect><rect x="5.487" y="15.28" width="9.026" height="2.499" fill="#272B2F"></rect></svg>';
4862 }elseif($icon=='box-left'){
4863 return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.202" y="5.492" width="2.503" height="9.017" fill="#272B2F"></rect><rect x="16.276" y="5.498" width="1.012" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.719" width="8.964" height="0.966" fill="#555D66"></rect><rect x="5.487" y="16.303" width="9.026" height="0.995" fill="#555D66"></rect></svg>';
4864 }
4865 }
4866
4867 /**
4868 * Get the widget input description html.
4869 *
4870 * @param $args
4871 *
4872 * @return string
4873 * @todo, need to make its own tooltip script
4874 */
4875 public function widget_field_desc( $args ) {
4876
4877 $description = '';
4878 if ( isset( $args['desc'] ) && $args['desc'] ) {
4879 if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
4880 $description = $this->desc_tip( $args['desc'] );
4881 } else {
4882 $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
4883 }
4884 }
4885
4886 return $description;
4887 }
4888
4889 /**
4890 * Get the widget input title html.
4891 *
4892 * @param $args
4893 *
4894 * @return string
4895 */
4896 public function widget_field_title( $args ) {
4897 $title = '';
4898
4899 if ( isset( $args['title'] ) && $args['title'] ) {
4900 if ( ! empty( $args['device_type'] ) ) {
4901 $args['title'] .= ' (' . $args['device_type'] . ')'; // Append device type to title.
4902 }
4903
4904 if ( isset( $args['icon'] ) && $args['icon'] ) {
4905 $title = self::get_widget_icon( $args['icon'], $args['title'] );
4906 } else {
4907 $title = esc_attr( $args['title'] );
4908 }
4909 }
4910
4911 return $title;
4912 }
4913
4914 /**
4915 * Get the tool tip html.
4916 *
4917 * @param $tip
4918 * @param bool $allow_html
4919 *
4920 * @return string
4921 */
4922 function desc_tip( $tip, $allow_html = false ) {
4923 if ( $allow_html ) {
4924 $tip = $this->sanitize_tooltip( $tip );
4925 } else {
4926 $tip = esc_attr( $tip );
4927 }
4928
4929 return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
4930 }
4931
4932 /**
4933 * Sanitize a string destined to be a tooltip.
4934 *
4935 * @param string $var
4936 *
4937 * @return string
4938 */
4939 public function sanitize_tooltip( $var ) {
4940 return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
4941 'br' => array(),
4942 'em' => array(),
4943 'strong' => array(),
4944 'small' => array(),
4945 'span' => array(),
4946 'ul' => array(),
4947 'li' => array(),
4948 'ol' => array(),
4949 'p' => array(),
4950 ) ) );
4951 }
4952
4953 /**
4954 * Processing widget options on save
4955 *
4956 * @param array $new_instance The new options
4957 * @param array $old_instance The previous options
4958 *
4959 * @return array
4960 * @todo we should add some sanitation here.
4961 */
4962 public function update( $new_instance, $old_instance ) {
4963
4964 //save the widget
4965 $instance = array_merge( (array) $old_instance, (array) $new_instance );
4966
4967 // set widget instance
4968 $this->instance = $instance;
4969
4970 if ( empty( $this->arguments ) ) {
4971 $this->get_arguments();
4972 }
4973
4974 // check for checkboxes
4975 if ( ! empty( $this->arguments ) ) {
4976 foreach ( $this->arguments as $argument ) {
4977 if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
4978 $instance[ $argument['name'] ] = '0';
4979 }
4980 }
4981 }
4982
4983 // maybe sanitize widget title
4984 if(!empty($instance['title'])) {
4985 $instance['title'] = wp_kses_post( $instance['title'] );
4986 }
4987
4988 return $instance;
4989 }
4990
4991 /**
4992 * Checks if the current call is a ajax call to get the block content.
4993 *
4994 * This can be used in your widget to return different content as the block content.
4995 *
4996 * @return bool
4997 *@since 1.0.3
4998 */
4999 public function is_block_content_call() {
5000 $result = false;
5001 if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
5002 $result = true;
5003 }
5004
5005 return $result;
5006 }
5007
5008 /**
5009 * Get an instance hash that will be unique to the type and settings.
5010 *
5011 * @return string
5012 *@since 1.0.20
5013 */
5014 public function get_instance_hash(){
5015 $instance_string = $this->base_id.serialize($this->instance);
5016 return hash('crc32b',$instance_string);
5017 }
5018
5019 /**
5020 * Generate and return inline styles from CSS rules that will match the unique class of the instance.
5021 *
5022 * @param array $rules
5023 *
5024 * @return string
5025 *@since 1.0.20
5026 */
5027 public function get_instance_style($rules = array()){
5028 $css = '';
5029
5030 if(!empty($rules)){
5031 $rules = array_unique($rules);
5032 $instance_hash = $this->get_instance_hash();
5033 $css .= "<style>";
5034 foreach($rules as $rule){
5035 $css .= ".sdel-$instance_hash $rule";
5036 }
5037 $css .= "</style>";
5038 }
5039
5040 return $css;
5041 }
5042
5043 /**
5044 * Encode shortcodes tags.
5045 *
5046 * @param string $content Content to search for shortcode tags.
5047 *
5048 *@return string Content with shortcode tags removed.
5049 *@since 1.0.28
5050 *
5051 */
5052 public function encode_shortcodes( $content ) {
5053 // Avoids existing encoded tags.
5054 $trans = array(
5055 '&#91;' => '&#091;',
5056 '&#93;' => '&#093;',
5057 '&amp;#91;' => '&#091;',
5058 '&amp;#93;' => '&#093;',
5059 '&lt;' => '&0lt;',
5060 '&gt;' => '&0gt;',
5061 '&amp;lt;' => '&0lt;',
5062 '&amp;gt;' => '&0gt;',
5063 );
5064
5065 $content = strtr( $content, $trans );
5066
5067 $trans = array(
5068 '[' => '&#91;',
5069 ']' => '&#93;',
5070 '<' => '&lt;',
5071 '>' => '&gt;',
5072 '"' => '&quot;',
5073 "'" => '&#39;',
5074 );
5075
5076 $content = strtr( $content, $trans );
5077
5078 return $content;
5079 }
5080
5081 /**
5082 * Remove encoded shortcod tags.
5083 *
5084 * @param string $content Content to search for shortcode tags.
5085 *
5086 *@return string Content with decoded shortcode tags.
5087 *@since 1.0.28
5088 *
5089 */
5090 public function decode_shortcodes( $content ) {
5091 $trans = array(
5092 '&#91;' => '[',
5093 '&#93;' => ']',
5094 '&amp;#91;' => '[',
5095 '&amp;#93;' => ']',
5096 '&lt;' => '<',
5097 '&gt;' => '>',
5098 '&amp;lt;' => '<',
5099 '&amp;gt;' => '>',
5100 '&quot;' => '"',
5101 '&apos;' => "'",
5102 );
5103
5104 $content = strtr( $content, $trans );
5105
5106 $trans = array(
5107 '&#091;' => '&#91;',
5108 '&#093;' => '&#93;',
5109 '&amp;#091;' => '&#91;',
5110 '&amp;#093;' => '&#93;',
5111 '&0lt;' => '&lt;',
5112 '&0gt;' => '&gt;',
5113 '&amp;0lt;' => '&lt;',
5114 '&amp;0gt;' => '&gt;',
5115 );
5116
5117 $content = strtr( $content, $trans );
5118
5119 return $content;
5120 }
5121
5122 public function block_visibility_fields( $args ) {
5123 global $aui_bs5;
5124
5125 $value = ! empty( $args['value'] ) ? esc_attr( $args['value'] ) : '';
5126 $content = '<div class="bs-vc-rule-template d-none">';
5127 $content .= '<div class="px-3 pt-3 pb-0 mb-3 border border-1 rounded-1 position-relative bs-vc-rule" data-bs-index="BSVCINDEX" >';
5128 $content .= '<div class="row">';
5129 $content .= '<div class="col-sm-12">';
5130 $content .= '<div class="bs-rule-action position-absolute top-0 end-0 right-0 p-2 zindex-5"' . ( $aui_bs5 ? '' : ' style="top:0!important;right:0!important;z-index:5!important;"' ) . '><span class="text-danger c-pointer bs-vc-remove-rule" title="' . esc_attr__( 'Remove Rule', 'ayecode-connect' ) . '"><i class="fas fa-circle-minus fs-6"></i></span></div>';
5131 $content .= aui()->select(
5132 array(
5133 'id' => 'bsvc_rule_BSVCINDEX',
5134 'name' => 'bsvc_rule_BSVCINDEX',
5135 'label' => __( 'Rule', 'ayecode-connect' ),
5136 'placeholder' => __( 'Select Rule...', 'ayecode-connect' ),
5137 'class' => 'bsvc_rule ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5138 'options' => sd_visibility_rules_options(),
5139 'default' => '',
5140 'value' => '',
5141 'label_type' => '',
5142 'select2' => false,
5143 'input_group_left' => __( 'Rule:', 'ayecode-connect' ),
5144 'extra_attributes' => array(
5145 'data-minimum-results-for-search' => '-1'
5146 )
5147 )
5148 );
5149
5150 $content .= '</div>';
5151
5152 if ( ! $aui_bs5 ) {
5153 $content = str_replace( 'input-group"', 'input-group input-group-sm"', $content );
5154 }
5155
5156 if ( class_exists( 'GeoDirectory' ) ) {
5157 $content .= '<div class="col-md-7 col-sm-12">';
5158
5159 $content .= aui()->select(
5160 array(
5161 'id' => 'bsvc_gd_field_BSVCINDEX',
5162 'name' => 'bsvc_gd_field_BSVCINDEX',
5163 'label' => __( 'FIELD', 'ayecode-connect' ),
5164 'placeholder' => __( 'FIELD', 'ayecode-connect' ),
5165 'class' => 'bsvc_gd_field ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5166 'options' => sd_visibility_gd_field_options(),
5167 'default' => '',
5168 'value' => '',
5169 'label_type' => '',
5170 'select2' => false,
5171 'element_require' => '[%bsvc_rule_BSVCINDEX%]=="gd_field"',
5172 'extra_attributes' => array(
5173 'data-minimum-results-for-search' => '-1'
5174 )
5175 )
5176 );
5177
5178 $content .= '</div>';
5179 $content .= '<div class="col-md-5 col-sm-12">';
5180
5181 $content .= aui()->select(
5182 array(
5183 'id' => 'bsvc_gd_field_condition_BSVCINDEX',
5184 'name' => 'bsvc_gd_field_condition_BSVCINDEX',
5185 'label' => __( 'CONDITION', 'ayecode-connect' ),
5186 'placeholder' => __( 'CONDITION', 'ayecode-connect' ),
5187 'class' => 'bsvc_gd_field_condition ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5188 'options' => sd_visibility_field_condition_options(),
5189 'default' => '',
5190 'value' => '',
5191 'label_type' => '',
5192 'select2' => false,
5193 'element_require' => '[%bsvc_rule_BSVCINDEX%]=="gd_field"',
5194 'extra_attributes' => array(
5195 'data-minimum-results-for-search' => '-1'
5196 )
5197 )
5198 );
5199
5200 $content .= '</div>';
5201 $content .= '<div class="col-sm-12">';
5202
5203 $content .= aui()->input(
5204 array(
5205 'type' => 'text',
5206 'id' => 'bsvc_gd_field_search_BSVCINDEX',
5207 'name' => 'bsvc_gd_field_search_BSVCINDEX',
5208 'label' => __( 'VALUE TO MATCH', 'ayecode-connect' ),
5209 'class' => 'bsvc_gd_field_search form-control-sm',
5210 'placeholder' => __( 'VALUE TO MATCH', 'ayecode-connect' ),
5211 'label_type' => '',
5212 'value' => '',
5213 'element_require' => '([%bsvc_rule_BSVCINDEX%]=="gd_field" && [%bsvc_gd_field_condition_BSVCINDEX%] && [%bsvc_gd_field_condition_BSVCINDEX%]!="is_empty" && [%bsvc_gd_field_condition_BSVCINDEX%]!="is_not_empty")'
5214 )
5215 );
5216
5217 $content .= '</div>';
5218 }
5219
5220 $content .= apply_filters( 'sd_block_visibility_fields', '', $args );
5221
5222 $content .= '</div>';
5223
5224 $content .= '<div class="row aui-conditional-field" data-element-require="jQuery(form).find(\'[name=bsvc_rule_BSVCINDEX]\').val()==\'user_roles\'" data-argument="bsvc_user_roles_BSVCINDEX_1"><label for="bsvc_user_roles_BSVCINDEX_1" class="form-label mb-3' . ( $aui_bs5 ? '' : ' ml-3 w-100' ) . '">' . __( 'Select User Roles:', 'ayecode-connect' ) . '</label>';
5225 $role_options = sd_user_roles_options();
5226
5227 $role_option_i = 0;
5228 foreach ( $role_options as $role_option_key => $role_option_name ) {
5229 $role_option_i++;
5230
5231 $content .= '<div class="col-sm-6' . ( $aui_bs5 ? '' : ' mb-2' ) . '">';
5232 $content .= aui()->input(
5233 array(
5234 'id' => 'bsvc_user_roles_BSVCINDEX_' . $role_option_i,
5235 'name' => 'bsvc_user_roles_BSVCINDEX[]',
5236 'type' => 'checkbox',
5237 'label' => $role_option_name,
5238 'label_type' => 'hidden',
5239 'class' => 'bsvc_user_roles',
5240 'value' => $role_option_key,
5241 'switch' => 'md',
5242 'no_wrap' => true
5243 )
5244 );
5245 $content .= '</div>';
5246 }
5247 $content .= '</div>';
5248 $content .= '<div class="bs-vc-sep-wrap text-center position-absolute top-0 mt-n3"' . ( $aui_bs5 ? '' : ' style="top:0!important;"' ) . '><div class="bs-vc-sep-cond d-inline-block badge text-dark bg-gray mt-1">' . esc_html__( 'AND', 'ayecode-connect' ) . '</div></div>';
5249 $content .= '</div>';
5250 $content .= '</div>';
5251 $content .= '<form id="bs-vc-modal-form" class="bs-vc-modal-form">';
5252 $content .= '<div class="bs-vc-rule-sets"></div>';
5253 $content .= '<div class="row"><div class="col-sm-12 text-center pt-1 pb-4"><button type="button" class="btn btn-sm btn-primary d-block w-100 bs-vc-add-rule"><i class="fas fa-plus"></i> ' . __( 'Add Rule', 'ayecode-connect' ) . '</button></div></div>';
5254 $content .= '<div class="row"><div class="col-md-6 col-sm-12">';
5255 $content .= aui()->select(
5256 array(
5257 'id' => 'bsvc_output',
5258 'name' => 'bsvc_output',
5259 'label' => __( 'What should happen if rules met.', 'ayecode-connect' ),
5260 'placeholder' => __( 'Show Block', 'ayecode-connect' ),
5261 'class' => 'bsvc_output ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5262 'options' => sd_visibility_output_options(),
5263 'default' => '',
5264 'value' => '',
5265 'label_type' => 'top',
5266 'select2' => false,
5267 'extra_attributes' => array(
5268 'data-minimum-results-for-search' => '-1'
5269 )
5270 )
5271 );
5272
5273 $content .= '</div><div class="col-md-6 col-sm-12">';
5274
5275 $content .= aui()->select(
5276 array(
5277 'id' => 'bsvc_page',
5278 'name' => 'bsvc_page',
5279 'label' => __( 'Page Content', 'ayecode-connect' ),
5280 'placeholder' => __( 'Select Page ID...', 'ayecode-connect' ),
5281 'class' => 'bsvc_page ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5282 'options' => sd_template_page_options(),
5283 'default' => '',
5284 'value' => '',
5285 'label_type' => 'top',
5286 'select2' => false,
5287 'element_require' => '[%bsvc_output%]=="page"'
5288 )
5289 );
5290
5291 $content .= aui()->select(
5292 array(
5293 'id' => 'bsvc_tmpl_part',
5294 'name' => 'bsvc_tmpl_part',
5295 'label' => __( 'Template Part', 'ayecode-connect' ),
5296 'placeholder' => __( 'Select Template Part...', 'ayecode-connect' ),
5297 'class' => 'bsvc_tmpl_part ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5298 'options' => sd_template_part_options(),
5299 'default' => '',
5300 'value' => '',
5301 'label_type' => 'top',
5302 'select2' => false,
5303 'element_require' => '[%bsvc_output%]=="template_part"',
5304 'extra_attributes' => array(
5305 'data-minimum-results-for-search' => '-1'
5306 )
5307 )
5308 );
5309
5310 $content .= aui()->select(
5311 array(
5312 'id' => 'bsvc_message_type',
5313 'name' => 'bsvc_message_type',
5314 'label' => __( 'Custom Message Type', 'ayecode-connect' ),
5315 'placeholder' => __( 'Default (none)', 'ayecode-connect' ),
5316 'class' => 'bsvc_message_type ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5317 'options' => sd_aui_colors(),
5318 'default' => '',
5319 'value' => '',
5320 'label_type' => 'top',
5321 'select2' => false,
5322 'element_require' => '[%bsvc_output%]=="message"',
5323 'extra_attributes' => array(
5324 'data-minimum-results-for-search' => '-1'
5325 )
5326 )
5327 );
5328
5329 $content .= '</div><div class="col-sm-12">';
5330
5331 $content .= aui()->input(
5332 array(
5333 'type' => 'text',
5334 'id' => 'bsvc_message',
5335 'name' => 'bsvc_message',
5336 'label' => '',
5337 'class' => 'bsvc_message form-control-sm mb-3',
5338 'placeholder' => __( 'CUSTOM MESSAGE TO SHOW', 'ayecode-connect' ),
5339 'label_type' => '',
5340 'value' => '',
5341 'form_group_class' => ' ',
5342 'element_require' => '[%bsvc_output%]=="message"',
5343 )
5344 );
5345
5346 $content .= '</div></div><div class="row"><div class="col col-12"><div class="pt-3 mt-1 border-top"></div></div><div class="col-md-6 col-sm-12">';
5347 $content .= aui()->select(
5348 array(
5349 'id' => 'bsvc_output_n',
5350 'name' => 'bsvc_output_n',
5351 'label' => __( 'What should happen if rules NOT met.', 'ayecode-connect' ),
5352 'placeholder' => __( 'Show Block', 'ayecode-connect' ),
5353 'class' => 'bsvc_output_n ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5354 'options' => sd_visibility_output_options(),
5355 'default' => '',
5356 'value' => '',
5357 'label_type' => 'top',
5358 'select2' => false,
5359 'extra_attributes' => array(
5360 'data-minimum-results-for-search' => '-1'
5361 )
5362 )
5363 );
5364
5365 $content .= '</div><div class="col-md-6 col-sm-12">';
5366
5367 $content .= aui()->select(
5368 array(
5369 'id' => 'bsvc_page_n',
5370 'name' => 'bsvc_page_n',
5371 'label' => __( 'Page Content', 'ayecode-connect' ),
5372 'placeholder' => __( 'Select Page ID...', 'ayecode-connect' ),
5373 'class' => 'bsvc_page_n ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5374 'options' => sd_template_page_options(),
5375 'default' => '',
5376 'value' => '',
5377 'label_type' => 'top',
5378 'select2' => false,
5379 'element_require' => '[%bsvc_output_n%]=="page"'
5380 )
5381 );
5382
5383 $content .= aui()->select(
5384 array(
5385 'id' => 'bsvc_tmpl_part_n',
5386 'name' => 'bsvc_tmpl_part_n',
5387 'label' => __( 'Template Part', 'ayecode-connect' ),
5388 'placeholder' => __( 'Select Template Part...', 'ayecode-connect' ),
5389 'class' => 'bsvc_tmpl_part_n ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5390 'options' => sd_template_part_options(),
5391 'default' => '',
5392 'value' => '',
5393 'label_type' => 'top',
5394 'select2' => false,
5395 'element_require' => '[%bsvc_output_n%]=="template_part"',
5396 'extra_attributes' => array(
5397 'data-minimum-results-for-search' => '-1'
5398 )
5399 )
5400 );
5401
5402 $content .= aui()->select(
5403 array(
5404 'id' => 'bsvc_message_type_n',
5405 'name' => 'bsvc_message_type_n',
5406 'label' => __( 'Custom Message Type', 'ayecode-connect' ),
5407 'placeholder' => __( 'Default (none)', 'ayecode-connect' ),
5408 'class' => 'bsvc_message_type_n ' . ( $aui_bs5 ? 'form-select-sm' : 'custom-select-sm' ) . ' no-select2 mw-100',
5409 'options' => sd_aui_colors(),
5410 'default' => '',
5411 'value' => '',
5412 'label_type' => 'top',
5413 'select2' => false,
5414 'element_require' => '[%bsvc_output_n%]=="message"',
5415 'extra_attributes' => array(
5416 'data-minimum-results-for-search' => '-1'
5417 )
5418 )
5419 );
5420
5421 $content .= '</div><div class="col-sm-12">';
5422
5423 $content .= aui()->input(
5424 array(
5425 'type' => 'text',
5426 'id' => 'bsvc_message_n',
5427 'name' => 'bsvc_message_n',
5428 'label' => '',
5429 'class' => 'bsvc_message_n form-control-sm',
5430 'placeholder' => __( 'CUSTOM MESSAGE TO SHOW', 'ayecode-connect' ),
5431 'label_type' => '',
5432 'value' => '',
5433 'form_group_class' => ' ',
5434 'element_require' => '[%bsvc_output_n%]=="message"',
5435 )
5436 );
5437
5438 $content .= '</div></div></form><input type="hidden" id="bsvc_raw_value" name="bsvc_raw_value" value="' . $value . '">';
5439
5440 return $content;
5441 }
5442
5443 /**
5444 * Handle media_buttons hook.
5445 *
5446 * @since 1.2.7
5447 */
5448 public function wp_media_buttons() {
5449 global $shortcode_insert_button_once;
5450
5451 // Fix conflicts with UpSolution Core in header template edit element.
5452 if ( defined( 'US_CORE_DIR' ) && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'us_ajax_hb_get_ebuilder_html' ) {
5453 $shortcode_insert_button_once = true;
5454 }
5455 }
5456
5457 /**
5458 * Check if supports block visibility.
5459 *
5460 * @since 1.2.28
5461 * @return bool True if site supports block visibility else False.
5462 */
5463 public function supports_block_visibility() {
5464 // FSE Theme.
5465 if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
5466 return true;
5467 }
5468
5469 // BlockStrap Block Builder.
5470 if ( defined( 'BLOCKSTRAP_BLOCKS_VERSION' ) ) {
5471 return true;
5472 }
5473
5474 return $this->is_gutenberg();
5475 }
5476
5477 /**
5478 * Check if Gutenberg is in use.
5479 *
5480 * @since 1.2.28
5481 * @return bool True if site uses Gutenberg else False.
5482 */
5483 public function is_gutenberg() {
5484 global $wp_version;
5485
5486 $is_gutenberg = true;
5487
5488 // If less than v5.
5489 if ( version_compare( $wp_version, '5.0.0', '<' ) ) {
5490 $is_gutenberg = false;
5491 }
5492
5493 if ( class_exists( 'Classic_Editor' ) ) {
5494 $is_gutenberg = false; // Classic Editor plugin is active.
5495 } else if ( $this->is_classicpress() ) {
5496 $is_gutenberg = false; // Site is using ClassicPress.
5497 }
5498
5499 return $is_gutenberg;
5500 }
5501
5502 /**
5503 * Check if ClassicPress is in use.
5504 *
5505 * @since 1.2.29
5506 * @return bool True if site uses ClassicPress else False.
5507 */
5508 public function is_classicpress() {
5509 if ( function_exists( 'classicpress_version' ) ) {
5510 $is_classicpress = true;
5511 } else {
5512 $is_classicpress = false;
5513 }
5514
5515 return $is_classicpress;
5516 }
5517 }
5518 }
5519