Total Complexity | 659 |
Total Lines | 5397 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like WP_Super_Duper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WP_Super_Duper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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() { |
||
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() { |
||
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() { |
||
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("'", "'"); // replace single quotes |
||
1165 | $element_require = $element_require.replace(""", '"'); // 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 ? ' 👁' : ''; |
||
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 | if(props.attributes.styleid==''){ props.setAttributes({ 'styleid': 'block-'+(Math.random() + 1).toString(36).substring(2) } ); } |
||
2796 | } |
||
2797 | |||
2798 | <?php |
||
2799 | if(!empty($this->options['block-edit-raw'])) { |
||
2800 | echo $this->options['block-edit-raw']; // strings have to be in single quotes, may cause issues |
||
2801 | }else{ |
||
2802 | ?> |
||
2803 | |||
2804 | function hasSelectedInnerBlock(props) { |
||
2805 | const select = wp.data.select('core/editor'); |
||
2806 | const selected = select.getBlockSelectionStart(); |
||
2807 | const inner = select.getBlock(props.clientId).innerBlocks; |
||
2808 | for (let i = 0; i < inner.length; i++) { |
||
2809 | if (inner[i].clientId === selected || inner[i].innerBlocks.length && hasSelectedInnerBlock(inner[i])) { |
||
2810 | return true; |
||
2811 | } |
||
2812 | } |
||
2813 | return false; |
||
2814 | }; |
||
2815 | |||
2816 | const parentBlocksIDs = wp.data.select( 'core/block-editor' ).getBlockParents(props.clientId); |
||
2817 | const parentBlocks = wp.data.select('core/block-editor').getBlocksByClientId(parentBlocksIDs); |
||
2818 | // const isParentOfSelectedBlock = useSelect( ( select ) => wp.data.select( 'core/block-editor' ).hasSelectedInnerBlock( props.clientId, true ) ): |
||
2819 | const block = wp.data.select('core/block-editor').getBlocksByClientId(props.clientId);//.[0].innerBlocks; |
||
2820 | const childBlocks = block[0] == null ? '' : block[0].innerBlocks; |
||
2821 | |||
2822 | var $value = ''; |
||
2823 | <?php |
||
2824 | // if we have a post_type and a category then link them |
||
2825 | if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){ |
||
2826 | ?> |
||
2827 | if(typeof(prev_attributes[props.clientId]) != 'undefined' && selectedBlock && selectedBlock.clientId === props.clientId){ |
||
2828 | $pt = props.attributes.post_type; |
||
2829 | if(post_type_rest_slugs.length){ |
||
2830 | $value = post_type_rest_slugs[0][$pt]; |
||
2831 | } |
||
2832 | var run = false; |
||
2833 | |||
2834 | if($pt != term_query_type){ |
||
2835 | run = true; |
||
2836 | term_query_type = $pt; |
||
2837 | } |
||
2838 | <?php |
||
2839 | $cat_path = ''; |
||
2840 | if ( ! empty( $this->arguments['post_type']['onchange_rest']['path'] ) ) { |
||
2841 | $cat_path = esc_js( strip_tags( $this->arguments['post_type']['onchange_rest']['path'] ) ); |
||
2842 | $cat_path = str_replace( array( '"', ''' ), array( '"', "'" ), $cat_path ); |
||
2843 | } |
||
2844 | ?> |
||
2845 | /* taxonomies */ |
||
2846 | if($value && 'post_type' in prev_attributes[props.clientId] && 'category' in prev_attributes[props.clientId] && run){ |
||
2847 | if (!window.gdCPTCats) { |
||
2848 | window.gdCPTCats = []; |
||
2849 | } |
||
2850 | var gdCatPath = "<?php echo ( ! empty( $cat_path ) ? $cat_path : "/wp/v2/" + $value + "/categories/?per_page=100" ); ?>"; |
||
2851 | if (window.gdCPTCats[gdCatPath]) { |
||
2852 | terms = window.gdCPTCats[gdCatPath]; |
||
2853 | while (taxonomies_<?php echo str_replace("-","_", $this->id);?>.length) { |
||
2854 | taxonomies_<?php echo str_replace("-","_", $this->id);?>.pop(); |
||
2855 | } |
||
2856 | taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: "All", value: 0}); |
||
2857 | jQuery.each( terms, function( key, val ) { |
||
2858 | taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: val.name, value: val.id}); |
||
2859 | }); |
||
2860 | |||
2861 | /* Setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. */ |
||
2862 | var $old_cat_value = props.attributes.category |
||
2863 | props.setAttributes({category: [0] }); |
||
2864 | props.setAttributes({category: $old_cat_value }); |
||
2865 | } else { |
||
2866 | wp.apiFetch({path: gdCatPath}).then(terms => { |
||
2867 | window.gdCPTCats[gdCatPath] = terms; |
||
2868 | while (taxonomies_<?php echo str_replace("-","_", $this->id);?>.length) { |
||
2869 | taxonomies_<?php echo str_replace("-","_", $this->id);?>.pop(); |
||
2870 | } |
||
2871 | taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: "All", value: 0}); |
||
2872 | jQuery.each( terms, function( key, val ) { |
||
2873 | taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: val.name, value: val.id}); |
||
2874 | }); |
||
2875 | |||
2876 | /* Setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. */ |
||
2877 | var $old_cat_value = props.attributes.category |
||
2878 | props.setAttributes({category: [0] }); |
||
2879 | props.setAttributes({category: $old_cat_value }); |
||
2880 | |||
2881 | return taxonomies_<?php echo str_replace("-","_", $this->id);?>; |
||
2882 | }); |
||
2883 | } |
||
2884 | } |
||
2885 | |||
2886 | /* sort_by */ |
||
2887 | if($value && 'post_type' in prev_attributes[props.clientId] && 'sort_by' in prev_attributes[props.clientId] && run){ |
||
2888 | if (!window.gdCPTSort) { |
||
2889 | window.gdCPTSort = []; |
||
2890 | } |
||
2891 | if (window.gdCPTSort[$pt]) { |
||
2892 | response = window.gdCPTSort[$pt]; |
||
2893 | while (sort_by_<?php echo str_replace("-","_", $this->id);?>.length) { |
||
2894 | sort_by_<?php echo str_replace("-","_", $this->id);?>.pop(); |
||
2895 | } |
||
2896 | |||
2897 | jQuery.each( response, function( key, val ) { |
||
2898 | sort_by_<?php echo str_replace("-","_", $this->id);?>.push({label: val, value: key}); |
||
2899 | }); |
||
2900 | |||
2901 | // setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. |
||
2902 | var $old_sort_by_value = props.attributes.sort_by |
||
2903 | props.setAttributes({sort_by: [0] }); |
||
2904 | props.setAttributes({sort_by: $old_sort_by_value }); |
||
2905 | } else { |
||
2906 | var data = { |
||
2907 | 'action': 'geodir_get_sort_options', |
||
2908 | 'post_type': $pt |
||
2909 | }; |
||
2910 | jQuery.post(ajaxurl, data, function(response) { |
||
2911 | response = JSON.parse(response); |
||
2912 | window.gdCPTSort[$pt] = response; |
||
2913 | while (sort_by_<?php echo str_replace("-","_", $this->id);?>.length) { |
||
2914 | sort_by_<?php echo str_replace("-","_", $this->id);?>.pop(); |
||
2915 | } |
||
2916 | |||
2917 | jQuery.each( response, function( key, val ) { |
||
2918 | sort_by_<?php echo str_replace("-","_", $this->id);?>.push({label: val, value: key}); |
||
2919 | }); |
||
2920 | |||
2921 | // setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. |
||
2922 | var $old_sort_by_value = props.attributes.sort_by |
||
2923 | props.setAttributes({sort_by: [0] }); |
||
2924 | props.setAttributes({sort_by: $old_sort_by_value }); |
||
2925 | |||
2926 | return sort_by_<?php echo str_replace("-","_", $this->id);?>; |
||
2927 | }); |
||
2928 | } |
||
2929 | } |
||
2930 | } |
||
2931 | <?php } ?> |
||
2932 | <?php |
||
2933 | $current_screen = function_exists('get_current_screen') ? get_current_screen() : ''; |
||
2934 | if(!empty($current_screen->base) && $current_screen->base==='widgets'){ |
||
2935 | echo 'const { deviceType } = "";'; |
||
2936 | }else{ |
||
2937 | ?> |
||
2938 | /** Get device type const. */ |
||
2939 | const wpVersion = '<?php global $wp_version; echo esc_attr($wp_version); ?>'; |
||
2940 | const { deviceType } = typeof wp.data.useSelect !== 'undefined' ? wp.data.useSelect(select => { |
||
2941 | if (parseFloat(wpVersion) < 6.5) { |
||
2942 | const { __experimentalGetPreviewDeviceType } = select('core/edit-site') ? select('core/edit-site') : select('core/edit-post') ? select('core/edit-post') : ''; |
||
2943 | return { |
||
2944 | deviceType: __experimentalGetPreviewDeviceType(), |
||
2945 | }; |
||
2946 | } else { |
||
2947 | const editorSelect = select('core/editor'); |
||
2948 | if (editorSelect) { |
||
2949 | return { |
||
2950 | deviceType: editorSelect.getDeviceType(), |
||
2951 | }; |
||
2952 | } else { |
||
2953 | return { |
||
2954 | deviceType: 'Desktop', // Default value if device type is not available |
||
2955 | }; |
||
2956 | } |
||
2957 | } |
||
2958 | }, []) : ''; |
||
2959 | <?php } ?> |
||
2960 | var content = props.attributes.content, shortcode = ''; |
||
2961 | |||
2962 | function onChangeContent($type) { |
||
2963 | $refresh = false; |
||
2964 | // Set the old content the same as the new one so we only compare all other attributes |
||
2965 | if(typeof(prev_attributes[props.clientId]) != 'undefined'){ |
||
2966 | prev_attributes[props.clientId].content = props.attributes.content; |
||
2967 | |||
2968 | // don't compare the sd_shortcode as it is changed later |
||
2969 | prev_attributes[props.clientId].sd_shortcode = props.attributes.sd_shortcode; |
||
2970 | }else if(props.attributes.content === ""){ |
||
2971 | // if first load and content empty then refresh |
||
2972 | $refresh = true; |
||
2973 | } else { |
||
2974 | // if not new and has content then set it so we dont go fetch it |
||
2975 | if(props.attributes.content && props.attributes.content !== 'Please select the attributes in the block settings'){ |
||
2976 | prev_attributes[props.clientId] = props.attributes; |
||
2977 | } |
||
2978 | } |
||
2979 | |||
2980 | if ( ( !is_fetching && JSON.stringify(prev_attributes[props.clientId]) != JSON.stringify(props.attributes) ) || $refresh ) { |
||
2981 | is_fetching = true; |
||
2982 | |||
2983 | var data = { |
||
2984 | 'action': 'super_duper_output_shortcode', |
||
2985 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
||
2986 | 'attributes': props.attributes, |
||
2987 | 'block_parent_name': parentBlocks.length ? parentBlocks[parentBlocks.length - 1].name : '', |
||
2988 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
||
2989 | echo $post->ID; |
||
2990 | }else{echo '0';}?>, |
||
2991 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
||
2992 | }; |
||
2993 | |||
2994 | jQuery.post(ajaxurl, data, function (response) { |
||
2995 | return response; |
||
2996 | }).then(function (env) { |
||
2997 | // if the content is empty then we place some placeholder text |
||
2998 | if (env == '') { |
||
2999 | env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for:', 'ayecode-connect' );?> " + props.name + "</div>"; |
||
3000 | } |
||
3001 | |||
3002 | <?php |
||
3003 | if(!empty($this->options['nested-block'])){ |
||
3004 | ?> |
||
3005 | // props.setAttributes({content: env}); |
||
3006 | is_fetching = false; |
||
3007 | prev_attributes[props.clientId] = props.attributes; |
||
3008 | <?php |
||
3009 | }else{ |
||
3010 | ?> |
||
3011 | props.setAttributes({content: env}); |
||
3012 | is_fetching = false; |
||
3013 | prev_attributes[props.clientId] = props.attributes; |
||
3014 | <?php |
||
3015 | } |
||
3016 | ?> |
||
3017 | |||
3018 | // if AUI is active call the js init function |
||
3019 | if (typeof aui_init === "function") { |
||
3020 | aui_init(); |
||
3021 | } |
||
3022 | }); |
||
3023 | } |
||
3024 | |||
3025 | return props.attributes.content; |
||
3026 | } |
||
3027 | |||
3028 | <?php |
||
3029 | if(!empty($this->options['block-edit-js'])) { |
||
3030 | echo $this->options['block-edit-js'] ; // strings have to be in single quotes, may cause issues |
||
3031 | } |
||
3032 | |||
3033 | if(empty($this->options['block-save-return'])){ |
||
3034 | ?> |
||
3035 | /////////////////////////////////////////////////////////////////////// |
||
3036 | |||
3037 | // build the shortcode. |
||
3038 | shortcode = "[<?php echo $this->options['base_id'];?>"; |
||
3039 | <?php |
||
3040 | |||
3041 | if(! empty( $this->arguments )){ |
||
3042 | |||
3043 | foreach($this->arguments as $key => $args){ |
||
3044 | // if($args['type']=='tabs'){continue;} |
||
3045 | |||
3046 | // don't add metadata arguments |
||
3047 | if (substr($key, 0, 9 ) === 'metadata_') { |
||
3048 | continue; |
||
3049 | } |
||
3050 | ?> |
||
3051 | if (props.attributes.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
||
3052 | if ('<?php echo esc_attr( $key );?>' == 'html') { |
||
3053 | } else if ('<?php echo esc_attr( $args['type'] );?>' == 'image_xy') { |
||
3054 | 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 +"}' " : ""; |
||
3055 | } else { |
||
3056 | //shortcode += props.attributes.<?php echo esc_attr( $key );?>.length ? " <?php echo esc_attr( $key );?>='" + props.attributes.<?php echo esc_attr( $key );?>.toString().replace('\'',''') + "' " : ""; |
||
3057 | shortcode += " <?php echo esc_attr( $key );?>='" + props.attributes.<?php echo esc_attr( $key );?>.toString().replace('\'',''') + "' "; |
||
3058 | } |
||
3059 | } |
||
3060 | <?php |
||
3061 | } |
||
3062 | } |
||
3063 | |||
3064 | ?> |
||
3065 | shortcode += "]"; |
||
3066 | |||
3067 | if(shortcode){ |
||
3068 | |||
3069 | // can cause a react exception when selecting multile blocks of the same type when the settings are not the same |
||
3070 | if (props.attributes.sd_shortcode !== shortcode) { |
||
3071 | props.setAttributes({ sd_shortcode: shortcode }); |
||
3072 | } |
||
3073 | |||
3074 | |||
3075 | <?php |
||
3076 | if(!empty($this->options['nested-block']) || !empty($this->arguments['html']) ){ |
||
3077 | echo "props.setAttributes({sd_shortcode_close: '[/".esc_attr( $this->options['base_id'] )."]'});"; |
||
3078 | } |
||
3079 | ?> |
||
3080 | } |
||
3081 | |||
3082 | |||
3083 | /////////////////////////////////////////////////////////////////////// |
||
3084 | <?php |
||
3085 | } // end nested block check |
||
3086 | ?> |
||
3087 | |||
3088 | return [ |
||
3089 | |||
3090 | el(wp.blockEditor.BlockControls, {key: 'controls'}, |
||
3091 | |||
3092 | <?php if($show_alignment){?> |
||
3093 | el( |
||
3094 | wp.blockEditor.AlignmentToolbar, |
||
3095 | { |
||
3096 | value: props.attributes.alignment, |
||
3097 | onChange: function (alignment) { |
||
3098 | props.setAttributes({alignment: alignment}) |
||
3099 | } |
||
3100 | } |
||
3101 | ) |
||
3102 | <?php }?> |
||
3103 | |||
3104 | ), |
||
3105 | |||
3106 | el(wp.blockEditor.InspectorControls, {key: 'inspector'}, |
||
3107 | |||
3108 | <?php |
||
3109 | |||
3110 | if(! empty( $this->arguments )){ |
||
3111 | |||
3112 | if ( $show_advanced ) { |
||
3113 | ?> |
||
3114 | el('div', { |
||
3115 | style: {'padding-left': '16px','padding-right': '16px'} |
||
3116 | }, |
||
3117 | el( |
||
3118 | wp.components.ToggleControl, |
||
3119 | { |
||
3120 | label: 'Show Advanced Settings?', |
||
3121 | checked: props.attributes.show_advanced, |
||
3122 | onChange: function (show_advanced) { |
||
3123 | props.setAttributes({show_advanced: !props.attributes.show_advanced}) |
||
3124 | } |
||
3125 | } |
||
3126 | ) |
||
3127 | ) |
||
3128 | , |
||
3129 | <?php |
||
3130 | } |
||
3131 | |||
3132 | $arguments = $this->group_arguments( $this->arguments ); |
||
3133 | $block_group_tabs = ! empty( $this->options['block_group_tabs'] ) ? $this->group_block_tabs( $this->options['block_group_tabs'], $arguments ) : array(); |
||
3134 | |||
3135 | // Do we have sections? |
||
3136 | $has_sections = $arguments == $this->arguments ? false : true; |
||
3137 | |||
3138 | if($has_sections){ |
||
3139 | $panel_count = 0; |
||
3140 | $open_tab = ''; |
||
3141 | |||
3142 | $open_tab_groups = array(); |
||
3143 | $used_tabs = array(); |
||
3144 | |||
3145 | foreach ( $arguments as $key => $args ) { |
||
3146 | $close_tab = false; |
||
3147 | $close_tabs = false; |
||
3148 | |||
3149 | if ( ! empty( $block_group_tabs ) ) { |
||
3150 | foreach ( $block_group_tabs as $tab_name => $tab_args ) { |
||
3151 | if ( in_array( $key, $tab_args['groups'] ) ) { |
||
3152 | $open_tab_groups[] = $key; |
||
3153 | |||
3154 | if ( $open_tab != $tab_name ) { |
||
3155 | $tab_args['tab']['tabs_open'] = $open_tab == '' ? true : false; |
||
3156 | $tab_args['tab']['open'] = true; |
||
3157 | |||
3158 | $this->block_tab_start( '', $tab_args ); |
||
3159 | $open_tab = $tab_name; |
||
3160 | $used_tabs[] = $tab_name; |
||
3161 | } |
||
3162 | |||
3163 | if ( $open_tab_groups == $tab_args['groups'] ) { |
||
3164 | $close_tab = true; |
||
3165 | $open_tab_groups = array(); |
||
3166 | |||
3167 | if ( $used_tabs == array_keys( $block_group_tabs ) ) { |
||
3168 | $close_tabs = true; |
||
3169 | } |
||
3170 | } |
||
3171 | } |
||
3172 | } |
||
3173 | } |
||
3174 | ?> |
||
3175 | el(wp.components.PanelBody, { |
||
3176 | title: '<?php esc_attr_e( $key ); ?>', |
||
3177 | initialOpen: <?php if ( $panel_count ) { |
||
3178 | echo "false"; |
||
3179 | } else { |
||
3180 | echo "true"; |
||
3181 | }?> |
||
3182 | }, |
||
3183 | <?php |
||
3184 | foreach ( $args as $k => $a ) { |
||
3185 | $this->block_tab_start( $k, $a ); |
||
3186 | $this->block_row_start( $k, $a ); |
||
3187 | $this->build_block_arguments( $k, $a ); |
||
3188 | $this->block_row_end( $k, $a ); |
||
3189 | $this->block_tab_end( $k, $a ); |
||
3190 | } |
||
3191 | ?> |
||
3192 | ), |
||
3193 | <?php |
||
3194 | $panel_count ++; |
||
3195 | |||
3196 | if($close_tab || $close_tabs){ |
||
3197 | $tab_args = array( |
||
3198 | 'tab' => array( |
||
3199 | 'tabs_close' => $close_tabs, |
||
3200 | 'close' => true, |
||
3201 | ) |
||
3202 | |||
3203 | ); |
||
3204 | $this->block_tab_end( '', $tab_args ); |
||
3205 | // echo '###close'; print_r($tab_args); |
||
3206 | $panel_count = 0; |
||
3207 | } |
||
3208 | // |
||
3209 | |||
3210 | } |
||
3211 | }else { |
||
3212 | ?> |
||
3213 | el(wp.components.PanelBody, { |
||
3214 | title: '<?php esc_attr_e( "Settings", 'ayecode-connect' ); ?>', |
||
3215 | initialOpen: true |
||
3216 | }, |
||
3217 | <?php |
||
3218 | foreach ( $this->arguments as $key => $args ) { |
||
3219 | $this->block_row_start( $key, $args ); |
||
3220 | $this->build_block_arguments( $key, $args ); |
||
3221 | $this->block_row_end( $key, $args ); |
||
3222 | } |
||
3223 | ?> |
||
3224 | ), |
||
3225 | <?php |
||
3226 | } |
||
3227 | |||
3228 | } |
||
3229 | ?> |
||
3230 | |||
3231 | ), |
||
3232 | |||
3233 | <?php |
||
3234 | // If the user sets block-output array then build it |
||
3235 | if ( ! empty( $this->options['block-output'] ) ) { |
||
3236 | $this->block_element( $this->options['block-output'] ); |
||
3237 | }elseif(!empty($this->options['block-edit-return'])){ |
||
3238 | echo $this->options['block-edit-return']; |
||
3239 | }else{ |
||
3240 | // if no block-output is set then we try and get the shortcode html output via ajax. |
||
3241 | $block_edit_wrap_tag = !empty($this->options['block_edit_wrap_tag']) ? esc_attr($this->options['block_edit_wrap_tag']) : 'div'; |
||
3242 | ?> |
||
3243 | el('<?php echo esc_attr($block_edit_wrap_tag); ?>', wp.blockEditor.useBlockProps({ |
||
3244 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
||
3245 | className: props.className, |
||
3246 | <?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 ?> |
||
3247 | style: {'minHeight': '30px'} |
||
3248 | })) |
||
3249 | <?php |
||
3250 | } |
||
3251 | ?> |
||
3252 | ]; // end return |
||
3253 | |||
3254 | <?php |
||
3255 | } // end block-edit-raw else |
||
3256 | ?> |
||
3257 | }, |
||
3258 | |||
3259 | // The "save" property must be specified and must be a valid function. |
||
3260 | save: function (props) { |
||
3261 | |||
3262 | var attr = props.attributes; |
||
3263 | var align = ''; |
||
3264 | |||
3265 | // build the shortcode. |
||
3266 | var content = "[<?php echo $this->options['base_id'];?>"; |
||
3267 | $html = ''; |
||
3268 | <?php |
||
3269 | |||
3270 | if(! empty( $this->arguments )){ |
||
3271 | |||
3272 | foreach($this->arguments as $key => $args){ |
||
3273 | // if($args['type']=='tabs'){continue;} |
||
3274 | |||
3275 | // don't add metadata arguments |
||
3276 | if (substr($key, 0, 9 ) === 'metadata_') { |
||
3277 | continue; |
||
3278 | } |
||
3279 | ?> |
||
3280 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
||
3281 | if ('<?php echo esc_attr( $key );?>' == 'html') { |
||
3282 | $html = attr.<?php echo esc_attr( $key );?>; |
||
3283 | } else if ('<?php echo esc_attr( $args['type'] );?>' == 'image_xy') { |
||
3284 | content += " <?php echo esc_attr( $key );?>='{x:" + attr.<?php echo esc_attr( $key );?>.x + ",y:"+attr.<?php echo esc_attr( $key );?>.y +"}' "; |
||
3285 | } else { |
||
3286 | content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>.toString().replace('\'',''') + "' "; |
||
3287 | } |
||
3288 | } |
||
3289 | <?php |
||
3290 | } |
||
3291 | } |
||
3292 | |||
3293 | ?> |
||
3294 | content += "]"; |
||
3295 | content = ''; |
||
3296 | |||
3297 | <?php |
||
3298 | // if(!empty($this->options['nested-block'])){ |
||
3299 | // ?> |
||
3300 | // $html = 'el( InnerBlocks.Content )'; |
||
3301 | // <?php |
||
3302 | // } |
||
3303 | ?> |
||
3304 | // if has html element |
||
3305 | if ($html) { |
||
3306 | //content += $html + "[/<?php echo $this->options['base_id'];?>]"; |
||
3307 | } |
||
3308 | |||
3309 | // @todo should we add inline style here or just css classes? |
||
3310 | if (attr.alignment) { |
||
3311 | if (attr.alignment == 'left') { |
||
3312 | align = 'alignleft'; |
||
3313 | } |
||
3314 | if (attr.alignment == 'center') { |
||
3315 | align = 'aligncenter'; |
||
3316 | } |
||
3317 | if (attr.alignment == 'right') { |
||
3318 | align = 'alignright'; |
||
3319 | } |
||
3320 | } |
||
3321 | |||
3322 | <?php |
||
3323 | // if(!empty($this->options['nested-block'])){ |
||
3324 | // ?x> |
||
3325 | // return el( |
||
3326 | // 'div', |
||
3327 | // { className: props.className, |
||
3328 | // style: {'minHeight': '300px','position':'relative','overflow':'hidden','backgroundImage': 'url(https://s.w.org/images/core/5.5/don-quixote-06.jpg)'} |
||
3329 | // }, |
||
3330 | // el( InnerBlocks.Content ), |
||
3331 | // el('div', {dangerouslySetInnerHTML: {__html: content}, className: align}) |
||
3332 | // ); |
||
3333 | // <x?php |
||
3334 | // }else |
||
3335 | |||
3336 | if(!empty($this->options['block-output'])){ |
||
3337 | // echo "return"; |
||
3338 | // $this->block_element( $this->options['block-output'], true ); |
||
3339 | // echo ";"; |
||
3340 | |||
3341 | ?> |
||
3342 | return el( |
||
3343 | '', |
||
3344 | {}, |
||
3345 | // el('', {dangerouslySetInnerHTML: {__html: content}}), |
||
3346 | <?php $this->block_element( $this->options['block-output'], true ); ?> |
||
3347 | // el('', {dangerouslySetInnerHTML: {__html: "[/<?php echo $this->options['base_id'];?>]"}}) |
||
3348 | ); |
||
3349 | <?php |
||
3350 | |||
3351 | }elseif(!empty($this->options['block-save-return'])){ |
||
3352 | echo 'return ' . $this->options['block-save-return']; |
||
3353 | }elseif(!empty($this->options['nested-block'])){ |
||
3354 | ?> |
||
3355 | return el( |
||
3356 | '', |
||
3357 | {}, |
||
3358 | el('', {dangerouslySetInnerHTML: {__html: content+"\n"}}), |
||
3359 | InnerBlocks.Content ? el( InnerBlocks.Content ) : '', // @todo i think we need a comma here |
||
3360 | // el('', {dangerouslySetInnerHTML: {__html: "[/<?php echo $this->options['base_id'];?>]"}}) |
||
3361 | ); |
||
3362 | <?php |
||
3363 | }elseif(!empty( $this->options['block-save-return'] ) ){ |
||
3364 | echo "return ". $this->options['block-edit-return'].";"; |
||
3365 | }elseif(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){ |
||
3366 | ?> |
||
3367 | return content; |
||
3368 | <?php |
||
3369 | }else{ |
||
3370 | ?> |
||
3371 | var block_wrap = 'div'; |
||
3372 | if (attr.hasOwnProperty("block_wrap")) { |
||
3373 | block_wrap = attr.block_wrap; |
||
3374 | } |
||
3375 | return el(block_wrap, wp.blockEditor.useBlockProps.save( {dangerouslySetInnerHTML: {__html: content}, className: align} )); |
||
3376 | <?php |
||
3377 | } |
||
3378 | ?> |
||
3379 | |||
3380 | |||
3381 | } |
||
3382 | }); |
||
3383 | })( |
||
3384 | window.wp.blocks, |
||
3385 | window.wp.element, |
||
3386 | window.wp.blockEditor |
||
3387 | ); |
||
3388 | |||
3389 | }); |
||
3390 | </script> |
||
3391 | <?php |
||
3392 | $output = ob_get_clean(); |
||
3393 | |||
3394 | /* |
||
3395 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
||
3396 | */ |
||
3397 | |||
3398 | return str_replace( array( |
||
3399 | '<script>', |
||
3400 | '</script>' |
||
3401 | ), '', $output ); |
||
3402 | } |
||
3403 | |||
3404 | |||
3405 | |||
3406 | public function block_row_start($key, $args){ |
||
3407 | |||
3408 | // check for row |
||
3409 | if(!empty($args['row'])){ |
||
3410 | |||
3411 | if(!empty($args['row']['open'])){ |
||
3412 | |||
3413 | // element require |
||
3414 | $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : ""; |
||
3415 | $device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : ''; |
||
3416 | $device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : ''; |
||
3417 | $device_type_icon = ''; |
||
3418 | if($device_type=='Desktop'){ |
||
3419 | $device_type_icon = '<span class="dashicons dashicons-desktop" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>'; |
||
3420 | }elseif($device_type=='Tablet'){ |
||
3421 | $device_type_icon = '<span class="dashicons dashicons-tablet" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>'; |
||
3422 | }elseif($device_type=='Mobile'){ |
||
3423 | $device_type_icon = '<span class="dashicons dashicons-smartphone" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>'; |
||
3424 | } |
||
3425 | echo $element_require; |
||
3426 | echo $device_type_require; |
||
3427 | |||
3428 | if(false){?><script><?php }?> |
||
3429 | el('div', { |
||
3430 | className: 'bsui components-base-control', |
||
3431 | }, |
||
3432 | <?php if(!empty($args['row']['title'])){ ?> |
||
3433 | el('label', { |
||
3434 | className: 'components-base-control__label position-relative', |
||
3435 | style: {width:"100%"} |
||
3436 | }, |
||
3437 | el('span',{dangerouslySetInnerHTML: {__html: '<?php echo addslashes( $args['row']['title'] ) ?>'}}), |
||
3438 | <?php if($device_type_icon){ ?> |
||
3439 | 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)"}}) |
||
3440 | <?php |
||
3441 | } |
||
3442 | ?> |
||
3443 | |||
3444 | |||
3445 | ), |
||
3446 | <?php }?> |
||
3447 | <?php if(!empty($args['row']['desc'])){ ?> |
||
3448 | el('p', { |
||
3449 | className: 'components-base-control__help mb-0', |
||
3450 | }, |
||
3451 | '<?php echo addslashes( $args['row']['desc'] ); ?>' |
||
3452 | ), |
||
3453 | <?php }?> |
||
3454 | el( |
||
3455 | 'div', |
||
3456 | { |
||
3457 | className: 'row mb-n2 <?php if(!empty($args['row']['class'])){ echo esc_attr($args['row']['class']);} ?>', |
||
3458 | }, |
||
3459 | el( |
||
3460 | 'div', |
||
3461 | { |
||
3462 | className: 'col pr-2 pe-2', |
||
3463 | }, |
||
3464 | |||
3465 | <?php |
||
3466 | if(false){?></script><?php } |
||
3467 | }elseif(!empty($args['row']['close'])){ |
||
3468 | if(false){?><script><?php }?> |
||
3469 | el( |
||
3470 | 'div', |
||
3471 | { |
||
3472 | className: 'col pl-0 ps-0', |
||
3473 | }, |
||
3474 | <?php |
||
3475 | if(false){?></script><?php } |
||
3476 | }else{ |
||
3477 | if(false){?><script><?php }?> |
||
3478 | el( |
||
3479 | 'div', |
||
3480 | { |
||
3481 | className: 'col pl-0 ps-0 pr-2 pe-2', |
||
3482 | }, |
||
3483 | <?php |
||
3484 | if(false){?></script><?php } |
||
3485 | } |
||
3486 | |||
3487 | } |
||
3488 | |||
3489 | } |
||
3490 | |||
3491 | public function block_row_end($key, $args){ |
||
3492 | |||
3493 | if(!empty($args['row'])){ |
||
3494 | // maybe close |
||
3495 | if(!empty($args['row']['close'])){ |
||
3496 | echo "))"; |
||
3497 | } |
||
3498 | |||
3499 | echo "),"; |
||
3500 | } |
||
3501 | } |
||
3502 | |||
3503 | public function block_tab_start($key, $args){ |
||
3504 | |||
3505 | // check for row |
||
3506 | if(!empty($args['tab'])){ |
||
3507 | |||
3508 | if(!empty($args['tab']['tabs_open'])){ |
||
3509 | |||
3510 | if(false){?><script><?php }?> |
||
3511 | |||
3512 | el('div',{className: 'bsui'}, |
||
3513 | |||
3514 | el('hr', {className: 'm-0'}), el( |
||
3515 | wp.components.TabPanel, |
||
3516 | { |
||
3517 | activeClass: 'is-active', |
||
3518 | className: 'btn-groupx', |
||
3519 | initialTabName: '<?php echo addslashes( esc_attr( $args['tab']['key']) ); ?>', |
||
3520 | tabs: [ |
||
3521 | |||
3522 | <?php |
||
3523 | if(false){?></script><?php } |
||
3524 | } |
||
3525 | |||
3526 | if(!empty($args['tab']['open'])){ |
||
3527 | |||
3528 | if(false){?><script><?php }?> |
||
3529 | { |
||
3530 | name: '<?php echo addslashes( esc_attr( $args['tab']['key']) ); ?>', |
||
3531 | title: el('div', {dangerouslySetInnerHTML: {__html: '<?php echo addslashes( esc_attr( $args['tab']['title']) ); ?>'}}), |
||
3532 | className: '<?php echo addslashes( esc_attr( $args['tab']['class']) ); ?>', |
||
3533 | content: el('div',{}, <?php if(!empty($args['tab']['desc'])){ ?>el('p', { |
||
3534 | className: 'components-base-control__help mb-0', |
||
3535 | dangerouslySetInnerHTML: {__html:'<?php echo addslashes( $args['tab']['desc'] ); ?>'} |
||
3536 | }),<?php } |
||
3537 | if(false){?></script><?php } |
||
3538 | } |
||
3539 | |||
3540 | } |
||
3541 | |||
3542 | } |
||
3543 | |||
3544 | public function block_tab_end($key, $args){ |
||
3545 | |||
3546 | if(!empty($args['tab'])){ |
||
3547 | // maybe close |
||
3548 | if(!empty($args['tab']['close'])){ |
||
3549 | echo ")}, /* tab close */"; |
||
3550 | } |
||
3551 | |||
3552 | if(!empty($args['tab']['tabs_close'])){ |
||
3553 | if(false){?><script><?php }?> |
||
3554 | ]}, ( tab ) => { |
||
3555 | return tab.content; |
||
3556 | } |
||
3557 | )), /* tabs close */ |
||
3558 | <?php if(false){ ?></script><?php } |
||
3559 | } |
||
3560 | } |
||
3561 | } |
||
3562 | |||
3563 | public function build_block_arguments( $key, $args ) { |
||
3564 | $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
||
3565 | $options = ''; |
||
3566 | $extra = ''; |
||
3567 | $require = ''; |
||
3568 | $inside_elements = ''; |
||
3569 | $after_elements = ''; |
||
3570 | |||
3571 | // `content` is a protected and special argument |
||
3572 | if ( $key == 'content' ) { |
||
3573 | return; |
||
3574 | } |
||
3575 | |||
3576 | $device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : ''; |
||
3577 | $device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : ''; |
||
3578 | $device_type_icon = ''; |
||
3579 | if($device_type=='Desktop'){ |
||
3580 | $device_type_icon = '<span class="dashicons dashicons-desktop" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>'; |
||
3581 | }elseif($device_type=='Tablet'){ |
||
3582 | $device_type_icon = '<span class="dashicons dashicons-tablet" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>'; |
||
3583 | }elseif($device_type=='Mobile'){ |
||
3584 | $device_type_icon = '<span class="dashicons dashicons-smartphone" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>'; |
||
3585 | } |
||
3586 | |||
3587 | // icon |
||
3588 | $icon = ''; |
||
3589 | if( !empty( $args['icon'] ) ){ |
||
3590 | $icon .= "el('div', {"; |
||
3591 | $icon .= "dangerouslySetInnerHTML: {__html: '".self::get_widget_icon( esc_attr($args['icon']))."'},"; |
||
3592 | $icon .= "className: 'text-center',"; |
||
3593 | $icon .= "title: '".addslashes( $args['title'] )."',"; |
||
3594 | $icon .= "}),"; |
||
3595 | |||
3596 | // blank title as its added to the icon. |
||
3597 | $args['title'] = ''; |
||
3598 | } |
||
3599 | |||
3600 | // require advanced |
||
3601 | $require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : ""; |
||
3602 | |||
3603 | // element require |
||
3604 | $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : ""; |
||
3605 | |||
3606 | |||
3607 | $onchange = "props.setAttributes({ $key: $key } )"; |
||
3608 | $onchangecomplete = ""; |
||
3609 | $value = "props.attributes.$key"; |
||
3610 | $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx','range' ); |
||
3611 | if ( in_array( $args['type'], $text_type ) ) { |
||
3612 | $type = 'TextControl'; |
||
3613 | // Save numbers as numbers and not strings |
||
3614 | if ( $args['type'] == 'number' ) { |
||
3615 | $onchange = "props.setAttributes({ $key: $key ? Number($key) : '' } )"; |
||
3616 | } |
||
3617 | |||
3618 | if (substr($key, 0, 9 ) === 'metadata_') { |
||
3619 | $real_key = str_replace('metadata_','', $key ); |
||
3620 | $onchange = "props.setAttributes({ metadata: { $real_key: $key } } )"; |
||
3621 | $value = "props.attributes.metadata && props.attributes.metadata.$real_key ? props.attributes.metadata.$real_key : ''"; |
||
3622 | } |
||
3623 | } |
||
3624 | // else if ( $args['type'] == 'popup' ) { |
||
3625 | // $type = 'TextControl'; |
||
3626 | // $args['type'] == 'text'; |
||
3627 | // $after_elements .= "el( wp.components.Button, { |
||
3628 | // className: 'components-button components-circular-option-picker__clear is-primary is-smallx', |
||
3629 | // onClick: function(){ |
||
3630 | // aui_modal('','<input id=\'zzz\' value= />'); |
||
3631 | // const source = document.getElementById('zzz'); |
||
3632 | // source.value = props.attributes.$key; |
||
3633 | // source.addEventListener('input', function(e){props.setAttributes({ $key: e.target.value });}); |
||
3634 | // } |
||
3635 | // }, |
||
3636 | // 'test' |
||
3637 | // ),"; |
||
3638 | // |
||
3639 | // $value = "props.attributes.$key ? props.attributes.$key : ''"; |
||
3640 | // } |
||
3641 | else if ( $args['type'] == 'styleid' ) { |
||
3642 | $type = 'TextControl'; |
||
3643 | $args['type'] == 'text'; |
||
3644 | // Save numbers as numbers and not strings |
||
3645 | $value = "props.attributes.$key ? props.attributes.$key : ''"; |
||
3646 | }else if ( $args['type'] == 'notice' ) { |
||
3647 | |||
3648 | $notice_message = !empty($args['desc']) ? addslashes($args['desc']) : ''; |
||
3649 | $notice_status = !empty($args['status']) ? esc_attr($args['status']) : 'info'; |
||
3650 | |||
3651 | $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'}}))),"; |
||
3652 | echo $notice_message ? $element_require . $notice : ''; |
||
3653 | return; |
||
3654 | } |
||
3655 | /* |
||
3656 | * https://www.wptricks.com/question/set-current-tab-on-a-gutenberg-tabpanel-component-from-outside-that-component/ es5 layout |
||
3657 | elseif($args['type']=='tabs'){ |
||
3658 | ?> |
||
3659 | el( |
||
3660 | wp.components.TabPanel, |
||
3661 | { |
||
3662 | activeClass: 'active-tab', |
||
3663 | initialTabName: deviceType, |
||
3664 | tabs: [ |
||
3665 | { |
||
3666 | name: 'Desktop', |
||
3667 | title: el('div', {dangerouslySetInnerHTML: {__html: '<i class="fas fa-desktop"></i>'}}), |
||
3668 | className: 'tab-one' + deviceType == 'Desktop' ? ' active-tab' : '', |
||
3669 | content: el('div', {dangerouslySetInnerHTML: {__html: 'ddd'}}) |
||
3670 | }, |
||
3671 | { |
||
3672 | name: 'Tablet', |
||
3673 | title: el('div', {dangerouslySetInnerHTML: {__html: '<i class="fas fa-tablet-alt"></i>'}}), |
||
3674 | className: 'tab-two' + deviceType == 'Tablet' ? ' active-tab' : '', |
||
3675 | content: el('div', {dangerouslySetInnerHTML: {__html: 'ttt'}}) |
||
3676 | }, |
||
3677 | { |
||
3678 | name: 'Mobile', |
||
3679 | title: el('div', {dangerouslySetInnerHTML: {__html: '<i class="fas fa-mobile-alt"></i>'}}), |
||
3680 | className: 'tab-two' + deviceType == 'Mobile' ? ' active-tab' : '', |
||
3681 | content: el('div', {dangerouslySetInnerHTML: {__html: 'mmm'}}) |
||
3682 | }, |
||
3683 | ], |
||
3684 | }, |
||
3685 | ( tab ) => { |
||
3686 | |||
3687 | // @todo https://github.com/WordPress/gutenberg/issues/39248 |
||
3688 | if(tab.name=='Desktop'){ |
||
3689 | wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Desktop'); |
||
3690 | wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType(); |
||
3691 | }else if(tab.name=='Tablet'){ |
||
3692 | wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Tablet'); |
||
3693 | wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType(); |
||
3694 | }else if(tab.name=='Mobile'){ |
||
3695 | wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Mobile'); |
||
3696 | wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType(); |
||
3697 | } |
||
3698 | |||
3699 | return tab.content; |
||
3700 | |||
3701 | } |
||
3702 | ), |
||
3703 | |||
3704 | <?php |
||
3705 | return; |
||
3706 | } |
||
3707 | */ |
||
3708 | elseif ( $args['type'] == 'color' ) { |
||
3709 | $type = 'ColorPicker'; |
||
3710 | $onchange = ""; |
||
3711 | $extra = "color: $value,"; |
||
3712 | if(!empty($args['disable_alpha'])){ |
||
3713 | $extra .= "disableAlpha: true,"; |
||
3714 | } |
||
3715 | $onchangecomplete = "onChangeComplete: function($key) { |
||
3716 | value = $key.rgb.a && $key.rgb.a < 1 ? \"rgba(\"+$key.rgb.r+\",\"+$key.rgb.g+\",\"+$key.rgb.b+\",\"+$key.rgb.a+\")\" : $key.hex; |
||
3717 | props.setAttributes({ |
||
3718 | $key: value |
||
3719 | }); |
||
3720 | },"; |
||
3721 | }elseif ( $args['type'] == 'gradient' ) { |
||
3722 | $type = 'GradientPicker'; |
||
3723 | $extra .= "gradients: [{ |
||
3724 | name: 'Vivid cyan blue to vivid purple', |
||
3725 | gradient: |
||
3726 | 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)', |
||
3727 | slug: 'vivid-cyan-blue-to-vivid-purple', |
||
3728 | }, |
||
3729 | { |
||
3730 | name: 'Light green cyan to vivid green cyan', |
||
3731 | gradient: |
||
3732 | 'linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%)', |
||
3733 | slug: 'light-green-cyan-to-vivid-green-cyan', |
||
3734 | }, |
||
3735 | { |
||
3736 | name: 'Luminous vivid amber to luminous vivid orange', |
||
3737 | gradient: |
||
3738 | 'linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%)', |
||
3739 | slug: 'luminous-vivid-amber-to-luminous-vivid-orange', |
||
3740 | }, |
||
3741 | { |
||
3742 | name: 'Luminous vivid orange to vivid red', |
||
3743 | gradient: |
||
3744 | 'linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%)', |
||
3745 | slug: 'luminous-vivid-orange-to-vivid-red', |
||
3746 | }, |
||
3747 | { |
||
3748 | name: 'Very light gray to cyan bluish gray', |
||
3749 | gradient: |
||
3750 | 'linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%)', |
||
3751 | slug: 'very-light-gray-to-cyan-bluish-gray', |
||
3752 | }, |
||
3753 | { |
||
3754 | name: 'Cool to warm spectrum', |
||
3755 | gradient: |
||
3756 | '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%)', |
||
3757 | slug: 'cool-to-warm-spectrum', |
||
3758 | }],"; |
||
3759 | |||
3760 | }elseif ( $args['type'] == 'image' ) { |
||
3761 | // print_r($args); |
||
3762 | |||
3763 | $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,{ |
||
3764 | url: props.attributes.{$key}_use_featured === true ? 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxzdmcgYmFzZVByb2ZpbGU9InRpbnkiIGhlaWdodD0iNDAwIiB2ZXJzaW9uPSIxLjIiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6ZXY9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEveG1sLWV2ZW50cyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzIC8+PHJlY3QgZmlsbD0iI2QzZDNkMyIgaGVpZ2h0PSI0MDAiIHdpZHRoPSI0MDAiIHg9IjAiIHk9IjAiIC8+PGxpbmUgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIxMCIgeDE9IjAiIHgyPSI0MDAiIHkxPSIwIiB5Mj0iNDAwIiAvPjxsaW5lIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMTAiIHgxPSIwIiB4Mj0iNDAwIiB5MT0iNDAwIiB5Mj0iMCIgLz48cmVjdCBmaWxsPSIjZDNkM2QzIiBoZWlnaHQ9IjUwIiB3aWR0aD0iMjE4LjAiIHg9IjkxLjAiIHk9IjE3NS4wIiAvPjx0ZXh0IGZpbGw9IndoaXRlIiBmb250LXNpemU9IjMwIiBmb250LXdlaWdodD0iYm9sZCIgdGV4dC1hbmNob3I9Im1pZGRsZSIgeD0iMjAwLjAiIHk9IjIwNy41Ij5QTEFDRUhPTERFUjwvdGV4dD48L3N2Zz4=' : props.attributes.$key, |
||
3765 | value: props.attributes.{$key}_xy.x !== undefined && props.attributes.{$key}_xy.x >= 0 ? props.attributes.{$key}_xy : {x: 0.5,y: 0.5,}, |
||
3766 | // value: props.attributes.{$key}_xy, |
||
3767 | onChange: function(focalPoint){ |
||
3768 | console.log(props.attributes); |
||
3769 | return props.setAttributes({ |
||
3770 | {$key}_xy: focalPoint |
||
3771 | }); |
||
3772 | }, |
||
3773 | // @todo for some reason this does not work as expected. |
||
3774 | // onDrag: function(focalPointTemp){ |
||
3775 | // return props.setAttributes({ |
||
3776 | // {$key}_xy: focalPointTemp |
||
3777 | // }); |
||
3778 | // } |
||
3779 | |||
3780 | |||
3781 | }), "; |
||
3782 | |||
3783 | |||
3784 | $value = '""'; |
||
3785 | $type = 'MediaUpload'; |
||
3786 | $extra .= "onSelect: function(media){ |
||
3787 | return props.setAttributes({ |
||
3788 | $key: media.url, |
||
3789 | {$key}_id: media.id |
||
3790 | }); |
||
3791 | },"; |
||
3792 | $extra .= "type: 'image',"; |
||
3793 | $extra .= "render: function (obj) { |
||
3794 | return el( 'div',{}, |
||
3795 | ( !props.attributes.$key && !props.attributes.{$key}_use_featured ) && el( wp.components.Button, { |
||
3796 | className: 'components-button components-circular-option-picker__clear is-primary is-smallx', |
||
3797 | onClick: obj.open |
||
3798 | }, |
||
3799 | 'Upload Image' |
||
3800 | ), |
||
3801 | $img_preview |
||
3802 | props.attributes.$key && el( wp.components.Button, { |
||
3803 | className: 'components-button components-circular-option-picker__clear is-secondary is-small', |
||
3804 | style: {margin:'8px 0',display: 'block'}, |
||
3805 | onClick: function(){ |
||
3806 | return props.setAttributes({ |
||
3807 | $key: '', |
||
3808 | {$key}_id: '' |
||
3809 | }); |
||
3810 | } |
||
3811 | }, |
||
3812 | props.attributes.$key? 'Clear' : '' |
||
3813 | ) |
||
3814 | ) |
||
3815 | |||
3816 | |||
3817 | |||
3818 | }"; |
||
3819 | $onchange = ""; |
||
3820 | |||
3821 | //$inside_elements = ",el('div',{},'file upload')"; |
||
3822 | } else if ( $args['type'] == 'images' ) { |
||
3823 | $img_preview = "props.attributes.$key && (function() { |
||
3824 | let uploads = JSON.parse('['+props.attributes.$key+']'); |
||
3825 | let images = []; |
||
3826 | uploads.map((upload, index) => ( |
||
3827 | images.push( el('div',{ className: 'col p-2', draggable: 'true', 'data-index': index }, |
||
3828 | el('img', { |
||
3829 | src: (upload.sizes && upload.sizes.thumbnail ? upload.sizes.thumbnail.url : upload.url), |
||
3830 | style: { maxWidth:'100%', background: '#ccc', pointerEvents:'none' } |
||
3831 | }), |
||
3832 | el('i',{ |
||
3833 | className: 'fas fa-times-circle text-danger position-absolute ml-n2 mt-n1 bg-white rounded-circle c-pointer', |
||
3834 | onClick: function() { |
||
3835 | aui_confirm('".esc_attr__('Are you sure?')."', '".esc_attr__('Delete')."', '".esc_attr__('Cancel')."', true).then(function(confirmed) { |
||
3836 | if (confirmed) { |
||
3837 | let new_uploads = JSON.parse('['+props.attributes.$key+']'); |
||
3838 | new_uploads.splice(index, 1); |
||
3839 | return props.setAttributes({ {$key}: JSON.stringify( new_uploads ).replace('[','').replace(']','') }); |
||
3840 | } |
||
3841 | }); |
||
3842 | }}, |
||
3843 | '') |
||
3844 | )) |
||
3845 | )); |
||
3846 | return images; |
||
3847 | })(),"; |
||
3848 | |||
3849 | |||
3850 | $value = '""'; |
||
3851 | $type = 'MediaUpload'; |
||
3852 | $extra .= "onSelect: function(media){ |
||
3853 | let slim_images = props.attributes.$key ? JSON.parse('['+props.attributes.$key+']') : []; |
||
3854 | if(media.length){ |
||
3855 | for (var i=0; i < media.length; i++) { |
||
3856 | 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}); |
||
3857 | } |
||
3858 | } |
||
3859 | var slimImagesV = JSON.stringify(slim_images); |
||
3860 | if (slimImagesV) { |
||
3861 | slimImagesV = slimImagesV.replace('[','').replace(']','').replace(/'/g, '''); |
||
3862 | } |
||
3863 | return props.setAttributes({ $key: slimImagesV}); |
||
3864 | },"; |
||
3865 | $extra .= "type: 'image',"; |
||
3866 | $extra .= "multiple: true,"; |
||
3867 | $extra .= "render: function (obj) { |
||
3868 | /* Init the sort */ |
||
3869 | enableDragSort('sd-sortable'); |
||
3870 | return el( 'div',{}, |
||
3871 | el( wp.components.Button, { |
||
3872 | className: 'components-button components-circular-option-picker__clear is-primary is-smallx', |
||
3873 | onClick: obj.open |
||
3874 | }, |
||
3875 | 'Upload Images' |
||
3876 | ), |
||
3877 | el('div',{ |
||
3878 | className: 'row row-cols-3 px-2 sd-sortable', |
||
3879 | 'data-field':'$key' |
||
3880 | }, |
||
3881 | $img_preview |
||
3882 | ), |
||
3883 | props.attributes.$key && el( wp.components.Button, { |
||
3884 | className: 'components-button components-circular-option-picker__clear is-secondary is-small', |
||
3885 | style: {margin:'8px 0'}, |
||
3886 | onClick: function(){ |
||
3887 | return props.setAttributes({ $key: '' }); |
||
3888 | } |
||
3889 | }, |
||
3890 | props.attributes.$key ? 'Clear All' : '' |
||
3891 | ) |
||
3892 | ) |
||
3893 | }"; |
||
3894 | $onchange = ""; |
||
3895 | |||
3896 | //$inside_elements = ",el('div',{},'file upload')"; |
||
3897 | } |
||
3898 | elseif ( $args['type'] == 'checkbox' ) { |
||
3899 | $type = 'CheckboxControl'; |
||
3900 | $extra .= "checked: props.attributes.$key,"; |
||
3901 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
||
3902 | } elseif ( $args['type'] == 'textarea' ) { |
||
3903 | $type = 'TextareaControl'; |
||
3904 | |||
3905 | } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
||
3906 | $type = 'SelectControl'; |
||
3907 | |||
3908 | if($args['name'] == 'category' && !empty($args['post_type_linked'])){ |
||
3909 | $options .= "options: taxonomies_".str_replace("-","_", $this->id).","; |
||
3910 | }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){ |
||
3911 | $options .= "options: sort_by_".str_replace("-","_", $this->id).","; |
||
3912 | }else { |
||
3913 | |||
3914 | if ( ! empty( $args['options'] ) ) { |
||
3915 | $options .= "options: ["; |
||
3916 | foreach ( $args['options'] as $option_val => $option_label ) { |
||
3917 | $options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . esc_js( addslashes( $option_label ) ) . "' },"; |
||
3918 | } |
||
3919 | $options .= "],"; |
||
3920 | } |
||
3921 | } |
||
3922 | if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
||
3923 | $extra .= ' multiple:true,style:{height:"auto",paddingRight:"8px","overflow-y":"auto"}, '; |
||
3924 | } |
||
3925 | |||
3926 | if($args['type'] == 'multiselect' || ( isset( $args['multiple'] ) && $args['multiple'] ) ){ |
||
3927 | $after_elements .= "props.attributes.$key && el( wp.components.Button, { |
||
3928 | className: 'components-button components-circular-option-picker__clear is-secondary is-small', |
||
3929 | style: {margin:'-8px 0 8px 0',display: 'block'}, |
||
3930 | onClick: function(){ |
||
3931 | return props.setAttributes({ |
||
3932 | $key: '', |
||
3933 | }); |
||
3934 | } |
||
3935 | }, |
||
3936 | 'Clear' |
||
3937 | ),"; |
||
3938 | } |
||
3939 | } elseif ( $args['type'] == 'tagselect' ) { |
||
3940 | // $type = 'FormTokenField'; |
||
3941 | // |
||
3942 | // if ( ! empty( $args['options'] ) ) { |
||
3943 | // $options .= "suggestions: ["; |
||
3944 | // foreach ( $args['options'] as $option_val => $option_label ) { |
||
3945 | // $options .= "{ value: '" . esc_attr( $option_val ) . "', title: '" . addslashes( $option_label ) . "' },"; |
||
3946 | //// $options .= "'" . esc_attr( $option_val ) . "':'" . addslashes( $option_label ) . "',"; |
||
3947 | // } |
||
3948 | // $options .= "],"; |
||
3949 | // } |
||
3950 | // |
||
3951 | // $onchangex = "{ ( selectedItems ) => { |
||
3952 | // // Build array of selected posts. |
||
3953 | // let selectedPostsArray = []; |
||
3954 | // selectedPosts.map( |
||
3955 | // ( postName ) => { |
||
3956 | // const matchingPost = posts.find( ( post ) => { |
||
3957 | // return post.title.raw === postName; |
||
3958 | // |
||
3959 | // } ); |
||
3960 | // if ( matchingPost !== undefined ) { |
||
3961 | // selectedPostsArray.push( matchingPost.id ); |
||
3962 | // } |
||
3963 | // } |
||
3964 | // ) |
||
3965 | // |
||
3966 | // setAttributes( { selectedPosts: selectedPostsArray } ); |
||
3967 | // } } "; |
||
3968 | // $onchange = '';// "props.setAttributes({ $key: [ props.attributes.$key ] } )"; |
||
3969 | // |
||
3970 | //// $options = ""; |
||
3971 | // $value = "[]"; |
||
3972 | // $extra .= ' __experimentalExpandOnFocus: true,'; |
||
3973 | |||
3974 | } else if ( $args['type'] == 'alignment' ) { |
||
3975 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
||
3976 | } else if ( $args['type'] == 'margins' ) { |
||
3977 | |||
3978 | } else if ( $args['type'] == 'visibility_conditions' && ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) ) { |
||
3979 | $type = 'TextControl'; |
||
3980 | $value = "(props.attributes.$key ? props.attributes.$key : '')"; |
||
3981 | $args['type'] = 'text'; |
||
3982 | $options .= 'disabled:true,'; |
||
3983 | $bsvc_title = esc_attr( addslashes( $args['title'] ) ); |
||
3984 | $bsvc_body = $this->block_visibility_fields( $args ); |
||
3985 | // @TODO reset button |
||
3986 | $bsvc_footer = '<button type="button" class="btn btn-danger d-none">' . __( 'Reset', 'ayecode-connect' ) . '</button><button type="button" class="btn btn-secondary bs-vc-close text-white" data-bs-dismiss="modal">' . __( 'Close', 'ayecode-connect' ) . '</button><button type="button" class="btn btn-primary bs-vc-save">' . __( 'Save Rules', 'ayecode-connect' ) . '</button>'; |
||
3987 | $after_elements .= "el('div', {className: 'components-base-control bs-vc-button-wrap'}, el(wp.components.Button, { |
||
3988 | className: 'components-button components-circular-option-picker__clear is-primary is-smallx', |
||
3989 | onClick: function() { |
||
3990 | var sValue = props.attributes." . $key . "; |
||
3991 | var oValue; |
||
3992 | try {oValue = JSON.parse(sValue);} catch(err) {} |
||
3993 | jQuery(document).off('show.bs.modal', '.bs-vc-modal').on('show.bs.modal', '.bs-vc-modal', function (e) { |
||
3994 | if (e.target && jQuery(e.target).hasClass('bs-vc-modal')) { |
||
3995 | sd_block_visibility_render_fields(oValue); |
||
3996 | if (!jQuery('.bs-vc-modal-form .bs-vc-rule-sets .bs-vc-rule').length) { |
||
3997 | jQuery('.bs-vc-modal-form .bs-vc-add-rule').trigger('click'); |
||
3998 | } |
||
3999 | if(typeof aui_init_select2 == 'function') { |
||
4000 | aui_init_select2(); |
||
4001 | } |
||
4002 | jQuery('.bs-vc-modal-form').trigger('change'); |
||
4003 | } |
||
4004 | }); |
||
4005 | aui_modal('" . $bsvc_title . "', '" . addslashes( $bsvc_body ) . "', '" . $bsvc_footer . "', true, 'bs-vc-modal', 'modal-lg', ''); |
||
4006 | jQuery(document).off('change', '#bsvc_raw_value').on('change', '#bsvc_raw_value', function(e) { |
||
4007 | props.setAttributes({" . $key . ": e.target.value}); |
||
4008 | }); |
||
4009 | } |
||
4010 | }, |
||
4011 | '" . addslashes( ! empty( $args['button_title'] ) ? $args['button_title'] : $args['title'] ) . "' |
||
4012 | ) ),"; |
||
4013 | } else { |
||
4014 | return;// if we have not implemented the control then don't break the JS. |
||
4015 | } |
||
4016 | |||
4017 | // color input does not show the labels so we add them |
||
4018 | if($args['type']=='color'){ |
||
4019 | // add show only if advanced |
||
4020 | echo $require_advanced; |
||
4021 | // add setting require if defined |
||
4022 | echo $element_require; |
||
4023 | echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),"; |
||
4024 | } |
||
4025 | |||
4026 | // add show only if advanced |
||
4027 | echo $require_advanced; |
||
4028 | // add setting require if defined |
||
4029 | echo $element_require; |
||
4030 | echo $device_type_require; |
||
4031 | |||
4032 | // icon |
||
4033 | echo $icon; |
||
4034 | ?> |
||
4035 | el( <?php echo $args['type'] == 'image' || $args['type'] == 'images' ? $type : "wp.components.".$type; ?>, { |
||
4036 | 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 |
||
4037 | } else { ?>'<?php echo addslashes( trim( esc_html( $args['title'] ) ) ); ?>'<?php } ?>, |
||
4038 | help: <?php echo ( isset( $args['desc'] ) ? "el('span', {dangerouslySetInnerHTML: {__html: '" . trim( wp_kses_post( addslashes( $args['desc'] ) ) ) . "'}})" : "''" ); ?>, |
||
4039 | value: <?php echo $value; ?>, |
||
4040 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
||
4041 | echo "type: '" . addslashes( $args['type'] ) . "',"; |
||
4042 | } ?> |
||
4043 | <?php if ( ! empty( $args['placeholder'] ) ) { |
||
4044 | echo "placeholder: '" . esc_js( addslashes( trim( esc_html( $args['placeholder'] ) ) ) ) . "',"; |
||
4045 | } ?> |
||
4046 | <?php echo $options; ?> |
||
4047 | <?php echo $extra; ?> |
||
4048 | <?php echo $custom_attributes; ?> |
||
4049 | <?php echo $onchangecomplete; ?> |
||
4050 | <?php if ( $onchange ) { ?> |
||
4051 | onChange: function ( <?php echo $key; ?> ) { |
||
4052 | <?php echo $onchange; ?> |
||
4053 | } |
||
4054 | <?php } ?> |
||
4055 | } <?php echo $inside_elements; ?> ), |
||
4056 | <?php |
||
4057 | echo $after_elements; |
||
4058 | } |
||
4059 | |||
4060 | /** |
||
4061 | * Convert an array of attributes to block string. |
||
4062 | * |
||
4063 | * @param $custom_attributes |
||
4064 | * |
||
4065 | * @return string |
||
4066 | *@todo there is prob a faster way to do this, also we could add some validation here. |
||
4067 | * |
||
4068 | */ |
||
4069 | public function array_to_attributes( $custom_attributes, $html = false ) { |
||
4070 | $attributes = ''; |
||
4071 | if ( ! empty( $custom_attributes ) ) { |
||
4072 | |||
4073 | foreach ( $custom_attributes as $key => $val ) { |
||
4074 | if(is_array($val)){ |
||
4075 | $attributes .= $key.': {'.$this->array_to_attributes( $val, $html ).'},'; |
||
4076 | }else{ |
||
4077 | $attributes .= $html ? " $key='$val' " : "'$key': '$val',"; |
||
4078 | } |
||
4079 | } |
||
4080 | |||
4081 | } |
||
4082 | |||
4083 | return $attributes; |
||
4084 | } |
||
4085 | |||
4086 | |||
4087 | |||
4088 | /** |
||
4089 | * A self looping function to create the output for JS block elements. |
||
4090 | * |
||
4091 | * This is what is output in the WP Editor visual view. |
||
4092 | * |
||
4093 | * @param $args |
||
4094 | */ |
||
4095 | public function block_element( $args, $save = false ) { |
||
4096 | |||
4097 | // print_r($args);echo '###';exit; |
||
4098 | |||
4099 | if ( ! empty( $args ) ) { |
||
4100 | foreach ( $args as $element => $new_args ) { |
||
4101 | |||
4102 | if ( is_array( $new_args ) ) { // its an element |
||
4103 | |||
4104 | |||
4105 | if ( isset( $new_args['element'] ) ) { |
||
4106 | |||
4107 | if ( isset( $new_args['element_require'] ) ) { |
||
4108 | echo str_replace( array( |
||
4109 | "'+", |
||
4110 | "+'" |
||
4111 | ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
||
4112 | unset( $new_args['element_require'] ); |
||
4113 | } |
||
4114 | |||
4115 | if($new_args['element']=='InnerBlocks'){ |
||
4116 | echo "\n el( InnerBlocks, {"; |
||
4117 | }elseif($new_args['element']=='innerBlocksProps'){ |
||
4118 | $element = isset($new_args['inner_element']) ? esc_attr($new_args['inner_element']) : 'div'; |
||
4119 | // echo "\n el( 'section', wp.blockEditor.useInnerBlocksProps( blockProps, {"; |
||
4120 | // echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( "; |
||
4121 | echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( "; |
||
4122 | echo $save ? "wp.blockEditor.useBlockProps.save( {" : "wp.blockEditor.useBlockProps( {"; |
||
4123 | echo !empty($new_args['blockProps']) ? $this->block_element( $new_args['blockProps'],$save ) : ''; |
||
4124 | |||
4125 | echo "} ), {"; |
||
4126 | echo !empty($new_args['innerBlocksProps']) && !$save ? $this->block_element( $new_args['innerBlocksProps'],$save ) : ''; |
||
4127 | // echo '###'; |
||
4128 | |||
4129 | // echo '###'; |
||
4130 | }elseif($new_args['element']=='BlocksProps'){ |
||
4131 | |||
4132 | if ( isset($new_args['if_inner_element']) ) { |
||
4133 | $element = $new_args['if_inner_element']; |
||
4134 | }else { |
||
4135 | $element = isset($new_args['inner_element']) ? "'".esc_attr($new_args['inner_element'])."'" : "'div'"; |
||
4136 | } |
||
4137 | |||
4138 | unset($new_args['inner_element']); |
||
4139 | echo $save ? "\n el( $element, wp.blockEditor.useBlockProps.save( {" : "\n el( $element, wp.blockEditor.useBlockProps( {"; |
||
4140 | echo !empty($new_args['blockProps']) ? $this->block_element( $new_args['blockProps'],$save ) : ''; |
||
4141 | |||
4142 | |||
4143 | // echo "} ),"; |
||
4144 | |||
4145 | }else{ |
||
4146 | echo "\n el( '" . $new_args['element'] . "', {"; |
||
4147 | } |
||
4148 | |||
4149 | |||
4150 | // get the attributes |
||
4151 | foreach ( $new_args as $new_key => $new_value ) { |
||
4152 | |||
4153 | |||
4154 | if ( $new_key == 'element' || $new_key == 'content'|| $new_key == 'if_content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
||
4155 | // do nothing |
||
4156 | } else { |
||
4157 | echo $this->block_element( array( $new_key => $new_value ),$save ); |
||
4158 | } |
||
4159 | } |
||
4160 | |||
4161 | echo $new_args['element']=='BlocksProps' ? '} ),' : "},";// end attributes |
||
4162 | |||
4163 | // get the content |
||
4164 | $first_item = 0; |
||
4165 | foreach ( $new_args as $new_key => $new_value ) { |
||
4166 | if ( $new_key === 'content' || $new_key === 'if_content' || is_array( $new_value ) ) { |
||
4167 | |||
4168 | if ( $new_key === 'content' ) { |
||
4169 | echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
||
4170 | }else if ( $new_key === 'if_content' ) { |
||
4171 | echo $this->block_props_replace( $new_value ); |
||
4172 | } |
||
4173 | |||
4174 | if ( is_array( $new_value ) ) { |
||
4175 | |||
4176 | if ( isset( $new_value['element_require'] ) ) { |
||
4177 | echo str_replace( array( |
||
4178 | "'+", |
||
4179 | "+'" |
||
4180 | ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
||
4181 | unset( $new_value['element_require'] ); |
||
4182 | } |
||
4183 | |||
4184 | if ( isset( $new_value['element_repeat'] ) ) { |
||
4185 | $x = 1; |
||
4186 | while ( $x <= absint( $new_value['element_repeat'] ) ) { |
||
4187 | $this->block_element( array( '' => $new_value ),$save ); |
||
4188 | $x ++; |
||
4189 | } |
||
4190 | } else { |
||
4191 | $this->block_element( array( '' => $new_value ),$save ); |
||
4192 | } |
||
4193 | } |
||
4194 | $first_item ++; |
||
4195 | } |
||
4196 | } |
||
4197 | |||
4198 | if($new_args['element']=='innerBlocksProps' || $new_args['element']=='xBlocksProps'){ |
||
4199 | echo "))";// end content |
||
4200 | }else{ |
||
4201 | echo ")";// end content |
||
4202 | } |
||
4203 | |||
4204 | |||
4205 | echo ", \n"; |
||
4206 | |||
4207 | } |
||
4208 | } else { |
||
4209 | |||
4210 | if ( substr( $element, 0, 3 ) === "if_" ) { |
||
4211 | $extra = ''; |
||
4212 | if( strpos($new_args, '[%WrapClass%]') !== false ){ |
||
4213 | $new_args = str_replace('[%WrapClass%]"','" + sd_build_aui_class(props.attributes)',$new_args); |
||
4214 | $new_args = str_replace('[%WrapClass%]','+ sd_build_aui_class(props.attributes)',$new_args); |
||
4215 | } |
||
4216 | echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
||
4217 | } elseif ( $element == 'style' && strpos($new_args, '[%WrapStyle%]') !== false ) { |
||
4218 | $new_args = str_replace('[%WrapStyle%]','',$new_args); |
||
4219 | echo $element . ": {..." . $this->block_props_replace( $new_args ) . " , ...sd_build_aui_styles(props.attributes) },"; |
||
4220 | // echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
||
4221 | } elseif ( $element == 'style' ) { |
||
4222 | echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
||
4223 | } elseif ( ( $element == 'class' || $element == 'className' ) && strpos($new_args, '[%WrapClass%]') !== false ) { |
||
4224 | $new_args = str_replace('[%WrapClass%]','',$new_args); |
||
4225 | echo $element . ": '" . $this->block_props_replace( $new_args ) . "' + sd_build_aui_class(props.attributes),"; |
||
4226 | } elseif ( $element == 'template' && $new_args ) { |
||
4227 | echo $element . ": $new_args,"; |
||
4228 | } else { |
||
4229 | echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
||
4230 | } |
||
4231 | |||
4232 | } |
||
4233 | } |
||
4234 | } |
||
4235 | } |
||
4236 | |||
4237 | /** |
||
4238 | * Replace block attributes placeholders with the proper naming. |
||
4239 | * |
||
4240 | * @param $string |
||
4241 | * |
||
4242 | * @return mixed |
||
4243 | */ |
||
4244 | public function block_props_replace( $string, $no_wrap = false ) { |
||
4245 | if ( $no_wrap ) { |
||
4246 | $string = str_replace( array( "[%", "%]", "%:checked]" ), array( "props.attributes.", "", "" ), $string ); |
||
4247 | } else { |
||
4248 | $string = str_replace( array( "![%", "[%", "%]", "%:checked]" ), array( "'+!props.attributes.", "'+props.attributes.", "+'", "+'" ), $string ); |
||
4249 | } |
||
4250 | |||
4251 | return $string; |
||
4252 | } |
||
4253 | |||
4254 | /** |
||
4255 | * Outputs the content of the widget |
||
4256 | * |
||
4257 | * @param array $args |
||
4258 | * @param array $instance |
||
4259 | */ |
||
4260 | public function widget( $args, $instance ) { |
||
4261 | if ( ! is_array( $args ) ) { |
||
4262 | $args = array(); |
||
4263 | } |
||
4264 | |||
4265 | // Get the filtered values |
||
4266 | $argument_values = $this->argument_values( $instance ); |
||
4267 | $argument_values = $this->string_to_bool( $argument_values ); |
||
4268 | $output = $this->output( $argument_values, $args ); |
||
4269 | |||
4270 | $no_wrap = false; |
||
4271 | if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) { |
||
4272 | $no_wrap = true; |
||
4273 | } |
||
4274 | |||
4275 | ob_start(); |
||
4276 | if ( $output && ! $no_wrap ) { |
||
4277 | |||
4278 | $class_original = $this->options['widget_ops']['classname']; |
||
4279 | $class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash(); |
||
4280 | |||
4281 | // Before widget |
||
4282 | $before_widget = ! empty( $args['before_widget'] ) ? $args['before_widget'] : ''; |
||
4283 | $before_widget = $before_widget ? str_replace( $class_original, $class, $before_widget ) : $before_widget; |
||
4284 | $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
||
4285 | $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
||
4286 | |||
4287 | // After widget |
||
4288 | $after_widget = ! empty( $args['after_widget'] ) ? $args['after_widget'] : ''; |
||
4289 | $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
||
4290 | $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
||
4291 | |||
4292 | echo $before_widget; |
||
4293 | // elementor strips the widget wrapping div so we check for and add it back if needed |
||
4294 | if ( $this->is_elementor_widget_output() ) { |
||
4295 | // Filter class & attrs for elementor widget output. |
||
4296 | $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this ); |
||
4297 | $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this ); |
||
4298 | |||
4299 | $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
||
4300 | $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
||
4301 | |||
4302 | echo "<span class='" . esc_attr( $class ) . "' " . $attrs . ">"; |
||
4303 | } |
||
4304 | echo $this->output_title( $args, $instance ); |
||
4305 | echo $output; |
||
4306 | if ( $this->is_elementor_widget_output() ) { |
||
4307 | echo "</span>"; |
||
4308 | } |
||
4309 | echo $after_widget; |
||
4310 | } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
||
4311 | $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
||
4312 | echo $output; |
||
4313 | } elseif ( $output && $no_wrap ) { |
||
4314 | echo $output; |
||
4315 | } |
||
4316 | $output = ob_get_clean(); |
||
4317 | |||
4318 | $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
||
4319 | |||
4320 | echo $output; |
||
4321 | } |
||
4322 | |||
4323 | /** |
||
4324 | * Tests if the current output is inside a elementor container. |
||
4325 | * |
||
4326 | * @return bool |
||
4327 | *@since 1.0.4 |
||
4328 | */ |
||
4329 | public function is_elementor_widget_output() { |
||
4330 | $result = false; |
||
4331 | if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
||
4332 | $result = true; |
||
4333 | } |
||
4334 | |||
4335 | return $result; |
||
4336 | } |
||
4337 | |||
4338 | /** |
||
4339 | * Tests if the current output is inside a elementor preview. |
||
4340 | * |
||
4341 | * @return bool |
||
4342 | *@since 1.0.4 |
||
4343 | */ |
||
4344 | public function is_elementor_preview() { |
||
4345 | $result = false; |
||
4346 | if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
||
4347 | $result = true; |
||
4348 | } |
||
4349 | |||
4350 | return $result; |
||
4351 | } |
||
4352 | |||
4353 | /** |
||
4354 | * Tests if the current output is inside a Divi preview. |
||
4355 | * |
||
4356 | * @return bool |
||
4357 | *@since 1.0.6 |
||
4358 | */ |
||
4359 | public function is_divi_preview() { |
||
4360 | $result = false; |
||
4361 | if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
||
4362 | $result = true; |
||
4363 | } |
||
4364 | |||
4365 | return $result; |
||
4366 | } |
||
4367 | |||
4368 | /** |
||
4369 | * Tests if the current output is inside a Beaver builder preview. |
||
4370 | * |
||
4371 | * @return bool |
||
4372 | *@since 1.0.6 |
||
4373 | */ |
||
4374 | public function is_beaver_preview() { |
||
4375 | $result = false; |
||
4376 | if ( isset( $_REQUEST['fl_builder'] ) ) { |
||
4377 | $result = true; |
||
4378 | } |
||
4379 | |||
4380 | return $result; |
||
4381 | } |
||
4382 | |||
4383 | /** |
||
4384 | * Tests if the current output is inside a siteorigin builder preview. |
||
4385 | * |
||
4386 | * @return bool |
||
4387 | *@since 1.0.6 |
||
4388 | */ |
||
4389 | public function is_siteorigin_preview() { |
||
4390 | $result = false; |
||
4391 | if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
||
4392 | $result = true; |
||
4393 | } |
||
4394 | |||
4395 | return $result; |
||
4396 | } |
||
4397 | |||
4398 | /** |
||
4399 | * Tests if the current output is inside a cornerstone builder preview. |
||
4400 | * |
||
4401 | * @return bool |
||
4402 | *@since 1.0.8 |
||
4403 | */ |
||
4404 | public function is_cornerstone_preview() { |
||
4405 | $result = false; |
||
4406 | if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
||
4407 | $result = true; |
||
4408 | } |
||
4409 | |||
4410 | return $result; |
||
4411 | } |
||
4412 | |||
4413 | /** |
||
4414 | * Tests if the current output is inside a fusion builder preview. |
||
4415 | * |
||
4416 | * @return bool |
||
4417 | *@since 1.1.0 |
||
4418 | */ |
||
4419 | public function is_fusion_preview() { |
||
4420 | $result = false; |
||
4421 | if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
||
4422 | $result = true; |
||
4423 | } |
||
4424 | |||
4425 | return $result; |
||
4426 | } |
||
4427 | |||
4428 | /** |
||
4429 | * Tests if the current output is inside a Oxygen builder preview. |
||
4430 | * |
||
4431 | * @return bool |
||
4432 | *@since 1.0.18 |
||
4433 | */ |
||
4434 | public function is_oxygen_preview() { |
||
4435 | $result = false; |
||
4436 | if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) { |
||
4437 | $result = true; |
||
4438 | } |
||
4439 | |||
4440 | return $result; |
||
4441 | } |
||
4442 | |||
4443 | /** |
||
4444 | * Check for Kallyas theme Zion builder preview. |
||
4445 | * |
||
4446 | * @since 1.1.22 |
||
4447 | * |
||
4448 | * @return bool True when preview page otherwise false. |
||
4449 | */ |
||
4450 | public function is_kallyas_zion_preview() { |
||
4451 | $result = false; |
||
4452 | |||
4453 | if ( function_exists( 'znhg_kallyas_theme_config' ) && ! empty( $_REQUEST['zn_pb_edit'] ) ) { |
||
4454 | $result = true; |
||
4455 | } |
||
4456 | |||
4457 | return $result; |
||
4458 | } |
||
4459 | |||
4460 | /** |
||
4461 | * Check for Bricks theme builder preview. |
||
4462 | * |
||
4463 | * @since 1.1.31 |
||
4464 | * |
||
4465 | * @return bool True when preview page otherwise false. |
||
4466 | */ |
||
4467 | public function is_bricks_preview() { |
||
4468 | $result = false; |
||
4469 | |||
4470 | if ( function_exists( 'bricks_is_builder' ) && ( bricks_is_builder() || bricks_is_builder_call() ) ) { |
||
4471 | $result = true; |
||
4472 | } |
||
4473 | |||
4474 | return $result; |
||
4475 | } |
||
4476 | |||
4477 | /** |
||
4478 | * General function to check if we are in a preview situation. |
||
4479 | * |
||
4480 | * @return bool |
||
4481 | *@since 1.0.6 |
||
4482 | */ |
||
4483 | public function is_preview() { |
||
4484 | $preview = false; |
||
4485 | if ( $this->is_divi_preview() ) { |
||
4486 | $preview = true; |
||
4487 | } elseif ( $this->is_elementor_preview() ) { |
||
4488 | $preview = true; |
||
4489 | } elseif ( $this->is_beaver_preview() ) { |
||
4490 | $preview = true; |
||
4491 | } elseif ( $this->is_siteorigin_preview() ) { |
||
4492 | $preview = true; |
||
4493 | } elseif ( $this->is_cornerstone_preview() ) { |
||
4494 | $preview = true; |
||
4495 | } elseif ( $this->is_fusion_preview() ) { |
||
4496 | $preview = true; |
||
4497 | } elseif ( $this->is_oxygen_preview() ) { |
||
4498 | $preview = true; |
||
4499 | } elseif( $this->is_kallyas_zion_preview() ) { |
||
4500 | $preview = true; |
||
4501 | } elseif( $this->is_block_content_call() ) { |
||
4502 | $preview = true; |
||
4503 | } elseif( $this->is_bricks_preview() ) { |
||
4504 | $preview = true; |
||
4505 | } |
||
4506 | |||
4507 | return $preview; |
||
4508 | } |
||
4509 | |||
4510 | /** |
||
4511 | * Output the super title. |
||
4512 | * |
||
4513 | * @param $args |
||
4514 | * @param array $instance |
||
4515 | * |
||
4516 | * @return string |
||
4517 | */ |
||
4518 | public function output_title( $args, $instance = array() ) { |
||
4519 | $output = ''; |
||
4520 | if ( ! empty( $instance['title'] ) ) { |
||
4521 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
||
4522 | $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
||
4523 | |||
4524 | if ( empty( $instance['widget_title_tag'] ) ) { |
||
4525 | if ( ! isset( $args['before_title'] ) ) { |
||
4526 | $args['before_title'] = ''; |
||
4527 | } |
||
4528 | |||
4529 | if ( ! isset( $args['after_title'] ) ) { |
||
4530 | $args['after_title'] = ''; |
||
4531 | } |
||
4532 | |||
4533 | $output = $args['before_title'] . $title . $args['after_title']; |
||
4534 | } else { |
||
4535 | $tag = esc_attr( $instance['widget_title_tag'] ); |
||
4536 | $allowed_tags = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'div', 'p' ); |
||
4537 | $title_tag = in_array( $tag, $allowed_tags, true ) ? esc_attr( $tag ) : 'h2'; |
||
4538 | |||
4539 | // classes |
||
4540 | $title_classes = array(); |
||
4541 | $title_classes[] = !empty( $instance['widget_title_size_class'] ) ? sanitize_html_class( $instance['widget_title_size_class'] ) : ''; |
||
4542 | $title_classes[] = !empty( $instance['widget_title_align_class'] ) ? sanitize_html_class( $instance['widget_title_align_class'] ) : ''; |
||
4543 | $title_classes[] = !empty( $instance['widget_title_color_class'] ) ? "text-".sanitize_html_class( $instance['widget_title_color_class'] ) : ''; |
||
4544 | $title_classes[] = !empty( $instance['widget_title_border_class'] ) ? sanitize_html_class( $instance['widget_title_border_class'] ) : ''; |
||
4545 | $title_classes[] = !empty( $instance['widget_title_border_color_class'] ) ? "border-".sanitize_html_class( $instance['widget_title_border_color_class'] ) : ''; |
||
4546 | $title_classes[] = !empty( $instance['widget_title_mt_class'] ) ? "mt-".absint( $instance['widget_title_mt_class'] ) : ''; |
||
4547 | $title_classes[] = !empty( $instance['widget_title_mr_class'] ) ? "mr-".absint( $instance['widget_title_mr_class'] ) : ''; |
||
4548 | $title_classes[] = !empty( $instance['widget_title_mb_class'] ) ? "mb-".absint( $instance['widget_title_mb_class'] ) : ''; |
||
4549 | $title_classes[] = !empty( $instance['widget_title_ml_class'] ) ? "ml-".absint( $instance['widget_title_ml_class'] ) : ''; |
||
4550 | $title_classes[] = !empty( $instance['widget_title_pt_class'] ) ? "pt-".absint( $instance['widget_title_pt_class'] ) : ''; |
||
4551 | $title_classes[] = !empty( $instance['widget_title_pr_class'] ) ? "pr-".absint( $instance['widget_title_pr_class'] ) : ''; |
||
4552 | $title_classes[] = !empty( $instance['widget_title_pb_class'] ) ? "pb-".absint( $instance['widget_title_pb_class'] ) : ''; |
||
4553 | $title_classes[] = !empty( $instance['widget_title_pl_class'] ) ? "pl-".absint( $instance['widget_title_pl_class'] ) : ''; |
||
4554 | |||
4555 | $class = !empty( $title_classes ) ? implode(" ",$title_classes) : ''; |
||
4556 | $output = "<$title_tag class='$class' >$title</$title_tag>"; |
||
4557 | } |
||
4558 | |||
4559 | } |
||
4560 | |||
4561 | return $output; |
||
4562 | } |
||
4563 | |||
4564 | /** |
||
4565 | * Outputs the options form inputs for the widget. |
||
4566 | * |
||
4567 | * @param array $instance The widget options. |
||
4568 | */ |
||
4569 | public function form( $instance ) { |
||
4570 | |||
4571 | // set widget instance |
||
4572 | $this->instance = $instance; |
||
4573 | |||
4574 | // set it as a SD widget |
||
4575 | echo $this->widget_advanced_toggle(); |
||
4576 | |||
4577 | echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
||
4578 | $arguments_raw = $this->get_arguments(); |
||
4579 | |||
4580 | if ( is_array( $arguments_raw ) ) { |
||
4581 | |||
4582 | $arguments = $this->group_arguments( $arguments_raw ); |
||
4583 | |||
4584 | // Do we have sections? |
||
4585 | $has_sections = $arguments == $arguments_raw ? false : true; |
||
4586 | |||
4587 | |||
4588 | if ( $has_sections ) { |
||
4589 | $panel_count = 0; |
||
4590 | foreach ( $arguments as $key => $args ) { |
||
4591 | |||
4592 | ?> |
||
4593 | <script> |
||
4594 | // jQuery(this).find("i").toggleClass("fas fa-chevron-up fas fa-chevron-down");jQuery(this).next().toggle(); |
||
4595 | </script> |
||
4596 | <?php |
||
4597 | |||
4598 | $hide = $panel_count ? ' style="display:none;" ' : ''; |
||
4599 | $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
||
4600 | 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>"; |
||
4601 | echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>"; |
||
4602 | |||
4603 | foreach ( $args as $k => $a ) { |
||
4604 | |||
4605 | $this->widget_inputs_row_start($k, $a); |
||
4606 | $this->widget_inputs( $a, $instance ); |
||
4607 | $this->widget_inputs_row_end($k, $a); |
||
4608 | |||
4609 | } |
||
4610 | |||
4611 | echo "</div>"; |
||
4612 | |||
4613 | $panel_count ++; |
||
4614 | |||
4615 | } |
||
4616 | } else { |
||
4617 | foreach ( $arguments as $key => $args ) { |
||
4618 | $this->widget_inputs_row_start($key, $args); |
||
4619 | $this->widget_inputs( $args, $instance ); |
||
4620 | $this->widget_inputs_row_end($key, $args); |
||
4621 | } |
||
4622 | } |
||
4623 | |||
4624 | } |
||
4625 | } |
||
4626 | |||
4627 | public function widget_inputs_row_start( $key, $args ) { |
||
4628 | if ( ! empty( $args['row'] ) ) { |
||
4629 | // Maybe open |
||
4630 | if ( ! empty( $args['row']['open'] ) ) { |
||
4631 | ?> |
||
4632 | <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'] ) : '' ); ?>'> |
||
4633 | <?php if ( ! empty( $args['row']['title'] ) ) { ?> |
||
4634 | <?php |
||
4635 | if ( isset( $args['row']['icon'] ) ) { |
||
4636 | $args['row']['icon'] = ''; |
||
4637 | } |
||
4638 | |||
4639 | if ( ! isset( $args['row']['device_type'] ) && isset( $args['device_type'] ) ) { |
||
4640 | $args['row']['device_type'] = $args['device_type']; |
||
4641 | } |
||
4642 | ?> |
||
4643 | <label class="mb-0"><?php echo $this->widget_field_title( $args['row'] ); ?><?php echo $this->widget_field_desc( $args['row'] ); ?></label> |
||
4644 | <?php } ?> |
||
4645 | <div class='row<?php echo ( ! empty( $args['row']['class'] ) ? ' ' . esc_attr( $args['row']['class'] ) : '' ); ?>'> |
||
4646 | <div class='col pr-2'> |
||
4647 | <?php |
||
4648 | } else if ( ! empty( $args['row']['close'] ) ) { |
||
4649 | echo "<div class='col pl-0 ps-0'>"; |
||
4650 | } else { |
||
4651 | echo "<div class='col pl-0 ps-0 pr-2 pe-2'>"; |
||
4652 | } |
||
4653 | } |
||
4654 | } |
||
4655 | |||
4656 | public function widget_inputs_row_end( $key, $args ) { |
||
4657 | if ( ! empty( $args['row'] ) ) { |
||
4658 | // Maybe close |
||
4659 | if ( ! empty( $args['row']['close'] ) ) { |
||
4660 | echo "</div></div>"; |
||
4661 | } |
||
4662 | echo "</div>"; |
||
4663 | } |
||
4664 | } |
||
4665 | |||
4666 | /** |
||
4667 | * Get the hidden input that when added makes the advanced button show on widget settings. |
||
4668 | * |
||
4669 | * @return string |
||
4670 | */ |
||
4671 | public function widget_advanced_toggle() { |
||
4672 | |||
4673 | $output = ''; |
||
4674 | if ( $this->block_show_advanced() ) { |
||
4675 | $val = 1; |
||
4676 | } else { |
||
4677 | $val = 0; |
||
4678 | } |
||
4679 | |||
4680 | $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
||
4681 | |||
4682 | return $output; |
||
4683 | } |
||
4684 | |||
4685 | /** |
||
4686 | * Convert require element. |
||
4687 | * |
||
4688 | * @param string $input Input element. |
||
4689 | * |
||
4690 | * @return string $output |
||
4691 | *@since 1.0.0 |
||
4692 | * |
||
4693 | */ |
||
4694 | public function convert_element_require( $input ) { |
||
4695 | $input = str_replace( "'", '"', $input );// we only want double quotes |
||
4696 | |||
4697 | $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
||
4698 | "jQuery(form).find('[data-argument=\"", |
||
4699 | "\"]').find('input,select,textarea').val()", |
||
4700 | "\"]').find('input:checked').val()" |
||
4701 | ), $input ) ); |
||
4702 | |||
4703 | return $output; |
||
4704 | } |
||
4705 | |||
4706 | /** |
||
4707 | * Builds the inputs for the widget options. |
||
4708 | * |
||
4709 | * @param $args |
||
4710 | * @param $instance |
||
4711 | */ |
||
4712 | public function widget_inputs( $args, $instance ) { |
||
4713 | |||
4714 | $class = ""; |
||
4715 | $element_require = ""; |
||
4716 | $custom_attributes = ""; |
||
4717 | |||
4718 | // get value |
||
4719 | if ( isset( $instance[ $args['name'] ] ) ) { |
||
4720 | $value = $instance[ $args['name'] ]; |
||
4721 | } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
||
4722 | $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
||
4723 | } else { |
||
4724 | $value = ''; |
||
4725 | } |
||
4726 | |||
4727 | // get placeholder |
||
4728 | if ( ! empty( $args['placeholder'] ) ) { |
||
4729 | $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
||
4730 | } else { |
||
4731 | $placeholder = ''; |
||
4732 | } |
||
4733 | |||
4734 | // get if advanced |
||
4735 | if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
||
4736 | $class .= " sd-advanced-setting "; |
||
4737 | } |
||
4738 | |||
4739 | // element_require |
||
4740 | if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
||
4741 | $element_require = $args['element_require']; |
||
4742 | } |
||
4743 | |||
4744 | // custom_attributes |
||
4745 | if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
||
4746 | $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
||
4747 | } |
||
4748 | |||
4749 | // before wrapper |
||
4750 | ?> |
||
4751 | <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 );} ?>'> |
||
4752 | <?php |
||
4753 | switch ( $args['type'] ) { |
||
4754 | //array('text','password','number','email','tel','url','color') |
||
4755 | case "text": |
||
4756 | case "password": |
||
4757 | case "number": |
||
4758 | case "email": |
||
4759 | case "tel": |
||
4760 | case "url": |
||
4761 | case "color": |
||
4762 | ?> |
||
4763 | <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> |
||
4764 | <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 ); ?>"> |
||
4765 | <?php |
||
4766 | |||
4767 | break; |
||
4768 | case "select": |
||
4769 | $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
||
4770 | if ( $multiple ) { |
||
4771 | if ( empty( $value ) ) { |
||
4772 | $value = array(); |
||
4773 | } |
||
4774 | } |
||
4775 | ?> |
||
4776 | <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> |
||
4777 | <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 "[]"; } ?>" |
||
4778 | <?php if ( $multiple ) { |
||
4779 | echo "multiple"; |
||
4780 | } //@todo not implemented yet due to gutenberg not supporting it |
||
4781 | ?>> |
||
4782 | <?php |
||
4783 | |||
4784 | if ( ! empty( $args['options'] ) ) { |
||
4785 | foreach ( $args['options'] as $val => $label ) { |
||
4786 | if ( $multiple ) { |
||
4787 | $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
||
4788 | } else { |
||
4789 | $selected = selected( $value, $val, false ); |
||
4790 | } |
||
4791 | echo "<option value='$val' " . $selected . ">$label</option>"; |
||
4792 | } |
||
4793 | } |
||
4794 | ?> |
||
4795 | </select> |
||
4796 | <?php |
||
4797 | break; |
||
4798 | case "checkbox": |
||
4799 | ?> |
||
4800 | <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"> |
||
4801 | <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> |
||
4802 | <?php |
||
4803 | break; |
||
4804 | case "textarea": |
||
4805 | ?> |
||
4806 | <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> |
||
4807 | <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> |
||
4808 | <?php |
||
4809 | |||
4810 | break; |
||
4811 | case "hidden": |
||
4812 | ?> |
||
4813 | <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 ); ?>"> |
||
4814 | <?php |
||
4815 | break; |
||
4816 | default: |
||
4817 | echo "No input type found!"; // @todo we need to add more input types. |
||
4818 | } |
||
4819 | // after wrapper |
||
4820 | ?></p><?php |
||
4821 | } |
||
4822 | |||
4823 | public function get_widget_icon($icon = 'box-top', $title = ''){ |
||
4832 | } |
||
4833 | } |
||
4834 | |||
4835 | /** |
||
4836 | * Get the widget input description html. |
||
4837 | * |
||
4838 | * @param $args |
||
4839 | * |
||
4840 | * @return string |
||
4841 | * @todo, need to make its own tooltip script |
||
4842 | */ |
||
4843 | public function widget_field_desc( $args ) { |
||
4844 | |||
4845 | $description = ''; |
||
4846 | if ( isset( $args['desc'] ) && $args['desc'] ) { |
||
4847 | if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
||
4848 | $description = $this->desc_tip( $args['desc'] ); |
||
4849 | } else { |
||
4850 | $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
||
4851 | } |
||
4852 | } |
||
4853 | |||
4854 | return $description; |
||
4855 | } |
||
4856 | |||
4857 | /** |
||
4858 | * Get the widget input title html. |
||
4859 | * |
||
4860 | * @param $args |
||
4861 | * |
||
4862 | * @return string |
||
4863 | */ |
||
4864 | public function widget_field_title( $args ) { |
||
4865 | $title = ''; |
||
4866 | |||
4867 | if ( isset( $args['title'] ) && $args['title'] ) { |
||
4868 | if ( ! empty( $args['device_type'] ) ) { |
||
4869 | $args['title'] .= ' (' . $args['device_type'] . ')'; // Append device type to title. |
||
4870 | } |
||
4871 | |||
4872 | if ( isset( $args['icon'] ) && $args['icon'] ) { |
||
4873 | $title = self::get_widget_icon( $args['icon'], $args['title'] ); |
||
4874 | } else { |
||
4875 | $title = esc_attr( $args['title'] ); |
||
4876 | } |
||
4877 | } |
||
4878 | |||
4879 | return $title; |
||
4880 | } |
||
4881 | |||
4882 | /** |
||
4883 | * Get the tool tip html. |
||
4884 | * |
||
4885 | * @param $tip |
||
4886 | * @param bool $allow_html |
||
4887 | * |
||
4888 | * @return string |
||
4889 | */ |
||
4890 | function desc_tip( $tip, $allow_html = false ) { |
||
4891 | if ( $allow_html ) { |
||
4892 | $tip = $this->sanitize_tooltip( $tip ); |
||
4893 | } else { |
||
4894 | $tip = esc_attr( $tip ); |
||
4895 | } |
||
4896 | |||
4897 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
||
4898 | } |
||
4899 | |||
4900 | /** |
||
4901 | * Sanitize a string destined to be a tooltip. |
||
4902 | * |
||
4903 | * @param string $var |
||
4904 | * |
||
4905 | * @return string |
||
4906 | */ |
||
4907 | public function sanitize_tooltip( $var ) { |
||
4908 | return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
||
4909 | 'br' => array(), |
||
4910 | 'em' => array(), |
||
4911 | 'strong' => array(), |
||
4912 | 'small' => array(), |
||
4913 | 'span' => array(), |
||
4914 | 'ul' => array(), |
||
4915 | 'li' => array(), |
||
4916 | 'ol' => array(), |
||
4917 | 'p' => array(), |
||
4918 | ) ) ); |
||
4919 | } |
||
4920 | |||
4921 | /** |
||
4922 | * Processing widget options on save |
||
4923 | * |
||
4924 | * @param array $new_instance The new options |
||
4925 | * @param array $old_instance The previous options |
||
4926 | * |
||
4927 | * @return array |
||
4928 | * @todo we should add some sanitation here. |
||
4929 | */ |
||
4930 | public function update( $new_instance, $old_instance ) { |
||
4931 | |||
4932 | //save the widget |
||
4933 | $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
||
4934 | |||
4935 | // set widget instance |
||
4936 | $this->instance = $instance; |
||
4937 | |||
4938 | if ( empty( $this->arguments ) ) { |
||
4939 | $this->get_arguments(); |
||
4940 | } |
||
4941 | |||
4942 | // check for checkboxes |
||
4943 | if ( ! empty( $this->arguments ) ) { |
||
4944 | foreach ( $this->arguments as $argument ) { |
||
4945 | if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
||
4946 | $instance[ $argument['name'] ] = '0'; |
||
4947 | } |
||
4948 | } |
||
4949 | } |
||
4950 | |||
4951 | // maybe sanitize widget title |
||
4952 | if(!empty($instance['title'])) { |
||
4953 | $instance['title'] = wp_kses_post( $instance['title'] ); |
||
4954 | } |
||
4955 | |||
4956 | return $instance; |
||
4957 | } |
||
4958 | |||
4959 | /** |
||
4960 | * Checks if the current call is a ajax call to get the block content. |
||
4961 | * |
||
4962 | * This can be used in your widget to return different content as the block content. |
||
4963 | * |
||
4964 | * @return bool |
||
4965 | *@since 1.0.3 |
||
4966 | */ |
||
4967 | public function is_block_content_call() { |
||
4968 | $result = false; |
||
4969 | if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
||
4970 | $result = true; |
||
4971 | } |
||
4972 | |||
4973 | return $result; |
||
4974 | } |
||
4975 | |||
4976 | /** |
||
4977 | * Get an instance hash that will be unique to the type and settings. |
||
4978 | * |
||
4979 | * @return string |
||
4980 | *@since 1.0.20 |
||
4981 | */ |
||
4982 | public function get_instance_hash(){ |
||
4983 | $instance_string = $this->base_id.serialize($this->instance); |
||
4984 | return hash('crc32b',$instance_string); |
||
4985 | } |
||
4986 | |||
4987 | /** |
||
4988 | * Generate and return inline styles from CSS rules that will match the unique class of the instance. |
||
4989 | * |
||
4990 | * @param array $rules |
||
4991 | * |
||
4992 | * @return string |
||
4993 | *@since 1.0.20 |
||
4994 | */ |
||
4995 | public function get_instance_style($rules = array()){ |
||
4996 | $css = ''; |
||
4997 | |||
4998 | if(!empty($rules)){ |
||
4999 | $rules = array_unique($rules); |
||
5000 | $instance_hash = $this->get_instance_hash(); |
||
5001 | $css .= "<style>"; |
||
5002 | foreach($rules as $rule){ |
||
5003 | $css .= ".sdel-$instance_hash $rule"; |
||
5004 | } |
||
5005 | $css .= "</style>"; |
||
5006 | } |
||
5007 | |||
5008 | return $css; |
||
5009 | } |
||
5010 | |||
5011 | /** |
||
5012 | * Encode shortcodes tags. |
||
5013 | * |
||
5014 | * @param string $content Content to search for shortcode tags. |
||
5015 | * |
||
5016 | *@return string Content with shortcode tags removed. |
||
5017 | *@since 1.0.28 |
||
5018 | * |
||
5019 | */ |
||
5020 | public function encode_shortcodes( $content ) { |
||
5047 | } |
||
5048 | |||
5049 | /** |
||
5050 | * Remove encoded shortcod tags. |
||
5051 | * |
||
5052 | * @param string $content Content to search for shortcode tags. |
||
5053 | * |
||
5054 | *@return string Content with decoded shortcode tags. |
||
5055 | *@since 1.0.28 |
||
5056 | * |
||
5057 | */ |
||
5058 | public function decode_shortcodes( $content ) { |
||
5059 | $trans = array( |
||
5060 | '[' => '[', |
||
5061 | ']' => ']', |
||
5062 | '&#91;' => '[', |
||
5063 | '&#93;' => ']', |
||
5064 | '<' => '<', |
||
5065 | '>' => '>', |
||
5066 | '&lt;' => '<', |
||
5067 | '&gt;' => '>', |
||
5068 | '"' => '"', |
||
5069 | ''' => "'", |
||
5070 | ); |
||
5071 | |||
5072 | $content = strtr( $content, $trans ); |
||
5073 | |||
5074 | $trans = array( |
||
5075 | '[' => '[', |
||
5076 | ']' => ']', |
||
5077 | '&#091;' => '[', |
||
5078 | '&#093;' => ']', |
||
5079 | '&0lt;' => '<', |
||
5080 | '&0gt;' => '>', |
||
5081 | '&0lt;' => '<', |
||
5082 | '&0gt;' => '>', |
||
5083 | ); |
||
5084 | |||
5085 | $content = strtr( $content, $trans ); |
||
5086 | |||
5087 | return $content; |
||
5088 | } |
||
5089 | |||
5090 | public function block_visibility_fields( $args ) { |
||
5091 | $value = ! empty( $args['value'] ) ? esc_attr( $args['value'] ) : ''; |
||
5092 | $content = '<div class="bs-vc-rule-template d-none">'; |
||
5093 | $content .= '<div class="p-3 pb-0 mb-3 border border-1 rounded-1 position-relative bs-vc-rule" data-bs-index="BSVCINDEX" >'; |
||
5094 | $content .= '<div class="row">'; |
||
5095 | $content .= '<div class="col-sm-12">'; |
||
5096 | $content .= '<div class="bs-rule-action position-absolute top-0 end-0 p-2 zindex-5"><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>'; |
||
5097 | $content .= aui()->select( |
||
5098 | array( |
||
5099 | 'id' => 'bsvc_rule_BSVCINDEX', |
||
5100 | 'name' => 'bsvc_rule_BSVCINDEX', |
||
5101 | 'label' => __( 'Rule', 'ayecode-connect' ), |
||
5102 | 'placeholder' => __( 'Select Rule...', 'ayecode-connect' ), |
||
5103 | 'class' => 'bsvc_rule form-select-sm no-select2 mw-100', |
||
5104 | 'options' => sd_visibility_rules_options(), |
||
5105 | 'default' => '', |
||
5106 | 'value' => '', |
||
5107 | 'label_type' => '', |
||
5108 | 'select2' => false, |
||
5109 | 'input_group_left' => __( 'Rule:', 'ayecode-connect' ), |
||
5110 | 'extra_attributes' => array( |
||
5111 | 'data-minimum-results-for-search' => '-1' |
||
5112 | ) |
||
5113 | ) |
||
5114 | ); |
||
5115 | |||
5116 | $content .= '</div>'; |
||
5117 | |||
5118 | if ( class_exists( 'GeoDirectory' ) ) { |
||
5119 | $content .= '<div class="col-md-7 col-sm-12">'; |
||
5120 | |||
5121 | $content .= aui()->select( |
||
5122 | array( |
||
5123 | 'id' => 'bsvc_gd_field_BSVCINDEX', |
||
5124 | 'name' => 'bsvc_gd_field_BSVCINDEX', |
||
5125 | 'label' => __( 'FIELD', 'ayecode-connect' ), |
||
5126 | 'placeholder' => __( 'FIELD', 'ayecode-connect' ), |
||
5127 | 'class' => 'bsvc_gd_field form-select-sm no-select2 mw-100', |
||
5128 | 'options' => sd_visibility_gd_field_options(), |
||
5129 | 'default' => '', |
||
5130 | 'value' => '', |
||
5131 | 'label_type' => '', |
||
5132 | 'select2' => false, |
||
5133 | 'element_require' => '[%bsvc_rule_BSVCINDEX%]=="gd_field"', |
||
5134 | 'extra_attributes' => array( |
||
5135 | 'data-minimum-results-for-search' => '-1' |
||
5136 | ) |
||
5137 | ) |
||
5138 | ); |
||
5139 | |||
5140 | $content .= '</div>'; |
||
5141 | $content .= '<div class="col-md-5 col-sm-12">'; |
||
5142 | |||
5143 | $content .= aui()->select( |
||
5144 | array( |
||
5145 | 'id' => 'bsvc_gd_field_condition_BSVCINDEX', |
||
5146 | 'name' => 'bsvc_gd_field_condition_BSVCINDEX', |
||
5147 | 'label' => __( 'CONDITION', 'ayecode-connect' ), |
||
5148 | 'placeholder' => __( 'CONDITION', 'ayecode-connect' ), |
||
5149 | 'class' => 'bsvc_gd_field_condition form-select-sm no-select2 mw-100', |
||
5150 | 'options' => sd_visibility_field_condition_options(), |
||
5151 | 'default' => '', |
||
5152 | 'value' => '', |
||
5153 | 'label_type' => '', |
||
5154 | 'select2' => false, |
||
5155 | 'element_require' => '[%bsvc_rule_BSVCINDEX%]=="gd_field"', |
||
5156 | 'extra_attributes' => array( |
||
5157 | 'data-minimum-results-for-search' => '-1' |
||
5158 | ) |
||
5159 | ) |
||
5160 | ); |
||
5161 | |||
5162 | $content .= '</div>'; |
||
5163 | $content .= '<div class="col-sm-12">'; |
||
5164 | |||
5165 | $content .= aui()->input( |
||
5166 | array( |
||
5167 | 'type' => 'text', |
||
5168 | 'id' => 'bsvc_gd_field_search_BSVCINDEX', |
||
5169 | 'name' => 'bsvc_gd_field_search_BSVCINDEX', |
||
5170 | 'label' => __( 'VALUE TO MATCH', 'ayecode-connect' ), |
||
5171 | 'class' => 'bsvc_gd_field_search form-control-sm', |
||
5172 | 'placeholder' => __( 'VALUE TO MATCH', 'ayecode-connect' ), |
||
5173 | 'label_type' => '', |
||
5174 | 'value' => '', |
||
5175 | '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")' |
||
5176 | ) |
||
5177 | ); |
||
5178 | |||
5179 | $content .= '</div>'; |
||
5180 | } |
||
5181 | |||
5182 | $content .= apply_filters( 'sd_block_visibility_fields', '', $args ); |
||
5183 | |||
5184 | $content .= '</div>'; |
||
5185 | |||
5186 | $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">' . __( 'Select User Roles:', 'ayecode-connect' ) . '</label>'; |
||
5187 | $role_options = sd_user_roles_options(); |
||
5188 | |||
5189 | $role_option_i = 0; |
||
5190 | foreach ( $role_options as $role_option_key => $role_option_name ) { |
||
5191 | $role_option_i++; |
||
5192 | |||
5193 | $content .= '<div class="col-sm-6">'; |
||
5194 | $content .= aui()->input( |
||
5195 | array( |
||
5196 | 'id' => 'bsvc_user_roles_BSVCINDEX_' . $role_option_i, |
||
5197 | 'name' => 'bsvc_user_roles_BSVCINDEX[]', |
||
5198 | 'type' => 'checkbox', |
||
5199 | 'label' => $role_option_name, |
||
5200 | 'label_type' => 'hidden', |
||
5201 | 'class' => 'bsvc_user_roles', |
||
5202 | 'value' => $role_option_key, |
||
5203 | 'switch' => 'md', |
||
5204 | 'no_wrap' => true |
||
5205 | ) |
||
5206 | ); |
||
5207 | $content .= '</div>'; |
||
5208 | } |
||
5209 | $content .= '</div>'; |
||
5210 | $content .= '<div class="bs-vc-sep-wrap text-center position-absolute top-0 mt-n3"><div class="bs-vc-sep-cond d-inline-block badge text-dark bg-gray mt-1">' . esc_html__( 'AND', 'ayecode-connect' ) . '</div></div>'; |
||
5211 | $content .= '</div>'; |
||
5212 | $content .= '</div>'; |
||
5213 | $content .= '<form id="bs-vc-modal-form" class="bs-vc-modal-form">'; |
||
5214 | $content .= '<div class="bs-vc-rule-sets"></div>'; |
||
5215 | $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>'; |
||
5216 | $content .= '<div class="row"><div class="col-md-6 col-sm-12">'; |
||
5217 | $content .= aui()->select( |
||
5218 | array( |
||
5219 | 'id' => 'bsvc_output', |
||
5220 | 'name' => 'bsvc_output', |
||
5221 | 'label' => __( 'What should happen if rules met.', 'ayecode-connect' ), |
||
5222 | 'placeholder' => __( 'Show Block', 'ayecode-connect' ), |
||
5223 | 'class' => 'bsvc_output form-select-sm no-select2 mw-100', |
||
5224 | 'options' => sd_visibility_output_options(), |
||
5225 | 'default' => '', |
||
5226 | 'value' => '', |
||
5227 | 'label_type' => 'top', |
||
5228 | 'select2' => false, |
||
5229 | 'extra_attributes' => array( |
||
5230 | 'data-minimum-results-for-search' => '-1' |
||
5231 | ) |
||
5232 | ) |
||
5233 | ); |
||
5234 | |||
5235 | $content .= '</div><div class="col-md-6 col-sm-12">'; |
||
5236 | |||
5237 | $content .= aui()->select( |
||
5238 | array( |
||
5239 | 'id' => 'bsvc_page', |
||
5240 | 'name' => 'bsvc_page', |
||
5241 | 'label' => __( 'Page Content', 'ayecode-connect' ), |
||
5242 | 'placeholder' => __( 'Select Page ID...', 'ayecode-connect' ), |
||
5243 | 'class' => 'bsvc_page form-select-sm no-select2 mw-100', |
||
5244 | 'options' => sd_template_page_options(), |
||
5245 | 'default' => '', |
||
5246 | 'value' => '', |
||
5247 | 'label_type' => 'top', |
||
5248 | 'select2' => false, |
||
5249 | 'element_require' => '[%bsvc_output%]=="page"' |
||
5250 | ) |
||
5251 | ); |
||
5252 | |||
5253 | $content .= aui()->select( |
||
5254 | array( |
||
5255 | 'id' => 'bsvc_tmpl_part', |
||
5256 | 'name' => 'bsvc_tmpl_part', |
||
5257 | 'label' => __( 'Template Part', 'ayecode-connect' ), |
||
5258 | 'placeholder' => __( 'Select Template Part...', 'ayecode-connect' ), |
||
5259 | 'class' => 'bsvc_tmpl_part form-select-sm no-select2 mw-100', |
||
5260 | 'options' => sd_template_part_options(), |
||
5261 | 'default' => '', |
||
5262 | 'value' => '', |
||
5263 | 'label_type' => 'top', |
||
5264 | 'select2' => false, |
||
5265 | 'element_require' => '[%bsvc_output%]=="template_part"', |
||
5266 | 'extra_attributes' => array( |
||
5267 | 'data-minimum-results-for-search' => '-1' |
||
5268 | ) |
||
5269 | ) |
||
5270 | ); |
||
5271 | |||
5272 | $content .= aui()->select( |
||
5273 | array( |
||
5274 | 'id' => 'bsvc_message_type', |
||
5275 | 'name' => 'bsvc_message_type', |
||
5276 | 'label' => __( 'Custom Message Type', 'ayecode-connect' ), |
||
5277 | 'placeholder' => __( 'Default (none)', 'ayecode-connect' ), |
||
5278 | 'class' => 'bsvc_message_type form-select-sm no-select2 mw-100', |
||
5279 | 'options' => sd_aui_colors(), |
||
5280 | 'default' => '', |
||
5281 | 'value' => '', |
||
5282 | 'label_type' => 'top', |
||
5283 | 'select2' => false, |
||
5284 | 'element_require' => '[%bsvc_output%]=="message"', |
||
5285 | 'extra_attributes' => array( |
||
5286 | 'data-minimum-results-for-search' => '-1' |
||
5287 | ) |
||
5288 | ) |
||
5289 | ); |
||
5290 | |||
5291 | $content .= '</div><div class="col-sm-12">'; |
||
5292 | |||
5293 | $content .= aui()->input( |
||
5294 | array( |
||
5295 | 'type' => 'text', |
||
5296 | 'id' => 'bsvc_message', |
||
5297 | 'name' => 'bsvc_message', |
||
5298 | 'label' => '', |
||
5299 | 'class' => 'bsvc_message form-control-sm mb-3', |
||
5300 | 'placeholder' => __( 'CUSTOM MESSAGE TO SHOW', 'ayecode-connect' ), |
||
5301 | 'label_type' => '', |
||
5302 | 'value' => '', |
||
5303 | 'form_group_class' => ' ', |
||
5304 | 'element_require' => '[%bsvc_output%]=="message"', |
||
5305 | ) |
||
5306 | ); |
||
5307 | |||
5308 | $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">'; |
||
5309 | $content .= aui()->select( |
||
5310 | array( |
||
5311 | 'id' => 'bsvc_output_n', |
||
5312 | 'name' => 'bsvc_output_n', |
||
5313 | 'label' => __( 'What should happen if rules NOT met.', 'ayecode-connect' ), |
||
5314 | 'placeholder' => __( 'Show Block', 'ayecode-connect' ), |
||
5315 | 'class' => 'bsvc_output_n form-select-sm no-select2 mw-100', |
||
5316 | 'options' => sd_visibility_output_options(), |
||
5317 | 'default' => '', |
||
5318 | 'value' => '', |
||
5319 | 'label_type' => 'top', |
||
5320 | 'select2' => false, |
||
5321 | 'extra_attributes' => array( |
||
5322 | 'data-minimum-results-for-search' => '-1' |
||
5323 | ) |
||
5324 | ) |
||
5325 | ); |
||
5326 | |||
5327 | $content .= '</div><div class="col-md-6 col-sm-12">'; |
||
5328 | |||
5329 | $content .= aui()->select( |
||
5330 | array( |
||
5331 | 'id' => 'bsvc_page_n', |
||
5332 | 'name' => 'bsvc_page_n', |
||
5333 | 'label' => __( 'Page Content', 'ayecode-connect' ), |
||
5334 | 'placeholder' => __( 'Select Page ID...', 'ayecode-connect' ), |
||
5335 | 'class' => 'bsvc_page_n form-select-sm no-select2 mw-100', |
||
5336 | 'options' => sd_template_page_options(), |
||
5337 | 'default' => '', |
||
5338 | 'value' => '', |
||
5339 | 'label_type' => 'top', |
||
5340 | 'select2' => false, |
||
5341 | 'element_require' => '[%bsvc_output_n%]=="page"' |
||
5342 | ) |
||
5343 | ); |
||
5344 | |||
5345 | $content .= aui()->select( |
||
5346 | array( |
||
5347 | 'id' => 'bsvc_tmpl_part_n', |
||
5348 | 'name' => 'bsvc_tmpl_part_n', |
||
5349 | 'label' => __( 'Template Part', 'ayecode-connect' ), |
||
5350 | 'placeholder' => __( 'Select Template Part...', 'ayecode-connect' ), |
||
5351 | 'class' => 'bsvc_tmpl_part_n form-select-sm no-select2 mw-100', |
||
5352 | 'options' => sd_template_part_options(), |
||
5353 | 'default' => '', |
||
5354 | 'value' => '', |
||
5355 | 'label_type' => 'top', |
||
5356 | 'select2' => false, |
||
5357 | 'element_require' => '[%bsvc_output_n%]=="template_part"', |
||
5358 | 'extra_attributes' => array( |
||
5359 | 'data-minimum-results-for-search' => '-1' |
||
5360 | ) |
||
5361 | ) |
||
5362 | ); |
||
5363 | |||
5364 | $content .= aui()->select( |
||
5365 | array( |
||
5366 | 'id' => 'bsvc_message_type_n', |
||
5367 | 'name' => 'bsvc_message_type_n', |
||
5368 | 'label' => __( 'Custom Message Type', 'ayecode-connect' ), |
||
5369 | 'placeholder' => __( 'Default (none)', 'ayecode-connect' ), |
||
5370 | 'class' => 'bsvc_message_type_n form-select-sm no-select2 mw-100', |
||
5371 | 'options' => sd_aui_colors(), |
||
5372 | 'default' => '', |
||
5373 | 'value' => '', |
||
5374 | 'label_type' => 'top', |
||
5375 | 'select2' => false, |
||
5376 | 'element_require' => '[%bsvc_output_n%]=="message"', |
||
5377 | 'extra_attributes' => array( |
||
5378 | 'data-minimum-results-for-search' => '-1' |
||
5379 | ) |
||
5380 | ) |
||
5381 | ); |
||
5382 | |||
5383 | $content .= '</div><div class="col-sm-12">'; |
||
5384 | |||
5385 | $content .= aui()->input( |
||
5386 | array( |
||
5387 | 'type' => 'text', |
||
5388 | 'id' => 'bsvc_message_n', |
||
5389 | 'name' => 'bsvc_message_n', |
||
5390 | 'label' => '', |
||
5391 | 'class' => 'bsvc_message_n form-control-sm', |
||
5392 | 'placeholder' => __( 'CUSTOM MESSAGE TO SHOW', 'ayecode-connect' ), |
||
5393 | 'label_type' => '', |
||
5394 | 'value' => '', |
||
5395 | 'form_group_class' => ' ', |
||
5396 | 'element_require' => '[%bsvc_output_n%]=="message"', |
||
5397 | ) |
||
5398 | ); |
||
5399 | |||
5400 | $content .= '</div></div></form><input type="hidden" id="bsvc_raw_value" name="bsvc_raw_value" value="' . $value . '">'; |
||
5401 | |||
5402 | return $content; |
||
5403 | } |
||
5404 | |||
5405 | /** |
||
5406 | * Handle media_buttons hook. |
||
5407 | * |
||
5408 | * @since 1.2.7 |
||
5409 | */ |
||
5410 | public function wp_media_buttons() { |
||
5416 | } |
||
5417 | } |
||
5418 | } |
||
5419 | } |
||
5420 |