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