PluginProbe
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.3
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.3
4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 All 183 releases
elementskit-lite / helpers / utils.php
utils.php
484 lines 14.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ElementsKit_Lite;
3
4 defined( 'ABSPATH' ) || exit;
5
6 /**
7 * Global helper class.
8 *
9 * @since 1.0.0
10 */
11
12 class Utils {
13
14 /**
15 * Auto generate classname from path.
16 *
17 * @since 1.0.0
18 * @access public
19 */
20 public static function make_classname( $dirname ) {
21 $dirname = pathinfo( $dirname, PATHINFO_FILENAME );
22 $class_name = explode( '-', $dirname );
23 $class_name = array_map( 'ucfirst', $class_name );
24 $class_name = implode( '_', $class_name );
25
26 return $class_name;
27 }
28
29 public static function google_fonts( $font_families = array() ) {
30 $fonts_url = '';
31 if ( $font_families ) {
32 $query_args = array(
33 'family' => urlencode( implode( '|', $font_families ) ),
34 );
35
36 $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
37 }
38
39 return esc_url_raw( $fonts_url );
40 }
41
42 public static function get_kses_array(){
43 return array(
44 'a' => array(
45 'class' => array(),
46 'href' => array(),
47 'rel' => array(),
48 'title' => array(),
49 'target' => array(),
50 'style' => array(),
51 ),
52 'abbr' => array(
53 'title' => array(),
54 ),
55 'b' => array(
56 'class' => array(),
57 ),
58 'blockquote' => array(
59 'cite' => array(),
60 ),
61 'cite' => array(
62 'title' => array(),
63 ),
64 'code' => array(),
65 'pre' => array(),
66 'del' => array(
67 'datetime' => array(),
68 'title' => array(),
69 ),
70 'dd' => array(),
71 'div' => array(
72 'class' => array(),
73 'title' => array(),
74 'style' => array(),
75 ),
76 'dl' => array(),
77 'dt' => array(),
78 'em' => array(),
79 'strong' => array(),
80 'h1' => array(
81 'class' => array(),
82 ),
83 'h2' => array(
84 'class' => array(),
85 ),
86 'h3' => array(
87 'class' => array(),
88 ),
89 'h4' => array(
90 'class' => array(),
91 ),
92 'h5' => array(
93 'class' => array(),
94 ),
95 'h6' => array(
96 'class' => array(),
97 ),
98 'i' => array(
99 'class' => array(),
100 ),
101 'img' => array(
102 'alt' => array(),
103 'class' => array(),
104 'height' => array(),
105 'src' => array(),
106 'width' => array(),
107 'style' => array(),
108 'title' => array(),
109 'srcset' => array(),
110 'loading' => array(),
111 'sizes' => array(),
112 ),
113 'figure' => array(
114 'class' => array(),
115 ),
116 'li' => array(
117 'class' => array(),
118 ),
119 'ol' => array(
120 'class' => array(),
121 ),
122 'p' => array(
123 'class' => array(),
124 ),
125 'q' => array(
126 'cite' => array(),
127 'title' => array(),
128 ),
129 'span' => array(
130 'class' => array(),
131 'title' => array(),
132 'style' => array(),
133 ),
134 'iframe' => array(
135 'width' => array(),
136 'height' => array(),
137 'scrolling' => array(),
138 'frameborder' => array(),
139 'allow' => array(),
140 'src' => array(),
141 ),
142 'strike' => array(),
143 'br' => array(),
144 'table' => array(),
145 'thead' => array(),
146 'tbody' => array(),
147 'tfoot' => array(),
148 'tr' => array(),
149 'th' => array(
150 'class' => true,
151 'colspan' => true,
152 'rowspan' => true,
153 'style' => true,
154 'id' => true,
155 ),
156 'td' => array(
157 'class' => true,
158 'colspan' => true,
159 'rowspan' => true,
160 'style' => true,
161 'id' => true,
162 ),
163 'caption'=> array(),
164 'col' => array(
165 'span' => true,
166 'style' => true,
167 ),
168 'colgroup' => array(
169 'span' => true,
170 'style' => true,
171 ),
172 'strong' => array(),
173 'data-wow-duration' => array(),
174 'data-wow-delay' => array(),
175 'data-wallpaper-options' => array(),
176 'data-stellar-background-ratio' => array(),
177 'ul' => array(
178 'class' => array(),
179 ),
180 'svg' => array(
181 'class' => true,
182 'aria-hidden' => true,
183 'aria-labelledby' => true,
184 'role' => true,
185 'xmlns' => true,
186 'width' => true,
187 'height' => true,
188 'viewbox' => true, // <= Must be lower case!
189 'preserveaspectratio' => true,
190 ),
191 'g' => array( 'fill' => true ),
192 'title' => array( 'title' => true ),
193 'path' => array(
194 'd' => true,
195 'fill' => true,
196 ),
197 'input' => array(
198 'class' => array(),
199 'type' => array(),
200 'value' => array()
201 )
202 );
203 }
204
205 public static function kses( $raw ) {
206
207 $allowed_tags = self::get_kses_array();
208
209 if ( function_exists( 'wp_kses' ) ) { // WP is here
210 return wp_kses( $raw, $allowed_tags );
211 } else {
212 return $raw;
213 }
214 }
215
216 public static function kspan( $text ) {
217 // Collapse consecutive braces (e.g. "{{ }}") so they produce a single span instead of nested spans.
218 return preg_replace( array( '/\{+/', '/\}+/' ), array( '<span>', '</span>' ), $text );
219 }
220
221 public static function ekit_get__forms( $post_type ) {
222 $wpuf_form_list = get_posts(
223 array(
224 'post_type' => $post_type,
225 'showposts' => 999,
226 )
227 );
228
229 $options = array();
230
231 if ( ! empty( $wpuf_form_list ) && ! is_wp_error( $wpuf_form_list ) ) {
232 $options[0] = esc_html__( 'Select Form', 'elementskit-lite' );
233 foreach ( $wpuf_form_list as $post ) {
234 $options[ $post->ID ] = $post->post_title;
235 }
236 } else {
237 $options[0] = esc_html__( 'Create a form first', 'elementskit-lite' );
238 }
239
240 return $options;
241 }
242
243 public static function ekit_get_ninja_form() {
244 $options = array();
245
246 if ( class_exists( 'Ninja_Forms' ) ) {
247 $contact_forms = Ninja_Forms()->form()->get_forms();
248
249 if ( ! empty( $contact_forms ) && ! is_wp_error( $contact_forms ) ) {
250
251 $options[0] = esc_html__( 'Select Ninja Form', 'elementskit-lite' );
252
253 foreach ( $contact_forms as $form ) {
254 $options[ $form->get_id() ] = $form->get_setting( 'title' );
255 }
256 }
257 } else {
258 $options[0] = esc_html__( 'Create a Form First', 'elementskit-lite' );
259 }
260
261 return $options;
262 }
263
264 public static function tablepress_table_list() {
265 $table_options = array();
266
267 if ( class_exists( 'TablePress' ) ) {
268 $table_ids = \TablePress::$model_table->load_all( false );
269 $table_options[0] = esc_html__( 'Select Table', 'elementskit-lite' );
270
271 foreach ( $table_ids as $table_id ) {
272 // Load table, without table data, options, and visibility settings.
273 $table = \TablePress::$model_table->load( $table_id, false, false );
274
275 if ( '' === trim( $table['name'] ) ) {
276 $table['name'] = __( '(no name)', 'elementskit-lite' );
277 }
278
279 $table_options[ $table['id'] ] = $table['name'];
280 }
281 } else {
282 $table_options[0] = esc_html__( 'Create a Table First', 'elementskit-lite' );
283 }
284
285 return $table_options;
286 }
287
288 public static function ekit_do_shortcode( $tag, array $atts = array(), $content = null ) {
289 global $shortcode_tags;
290 if ( ! isset( $shortcode_tags[ $tag ] ) ) {
291 return false;
292 }
293 return call_user_func( $shortcode_tags[ $tag ], $atts, $content, $tag );
294 }
295
296 public static function trim_words( $text, $num_words ) {
297 return wp_trim_words( $text, $num_words, '' );
298 }
299
300 public static function array_push_assoc( $array, $key, $value ) {
301 $array[ $key ] = $value;
302 return $array;
303 }
304
305 public static function render_elementor_content_css( $content_id ) {
306 if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
307 $css_file = new \Elementor\Core\Files\CSS\Post( $content_id );
308 $css_file->enqueue();
309 }
310 }
311
312 public static function render_elementor_content( $content_id, $has_css = false ) {
313 $elementor_instance = \Elementor\Plugin::instance();
314
315 if (
316 \Elementor\Plugin::$instance->editor->is_edit_mode()
317 && ! wp_style_is( 'elementor-frontend', 'registered' )
318 ) {
319 wp_register_style( 'elementor-frontend', false );
320 }
321
322 /**
323 * CSS Print Method Internal and Exteral option support for Header and Footer Builder.
324 */
325 if ( ( 'internal' === get_option( 'elementor_css_print_method' ) ) || \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
326 $has_css = true;
327 }
328
329 return $elementor_instance->frontend->get_builder_content_for_display( $content_id, $has_css );
330 }
331
332 public static function render( $content ) {
333 if ( stripos( $content, 'elementskit-has-lisence' ) !== false ) {
334 return null;
335 }
336
337 return $content;
338 }
339
340 public static function render_tab_content( $content, $id ) {
341 return str_replace( '.elementor-' . $id . ' ', '#elementor .elementor-' . $id . ' ', $content );
342 }
343
344 public static function img_meta( $id ) {
345 $attachment = get_post( $id );
346 if ( $attachment == null || $attachment->post_type != 'attachment' ) {
347 return null;
348 }
349 return array(
350 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
351 'caption' => $attachment->post_excerpt,
352 'description' => $attachment->post_content,
353 'href' => get_permalink( $attachment->ID ),
354 'src' => $attachment->guid,
355 'title' => $attachment->post_title,
356 );
357 }
358
359 public static function esc_options( $str, $options = array(), $default = '' ) {
360 if ( ! in_array( $str, $options ) ) {
361 return $default;
362 }
363
364 return $str;
365 }
366
367 public static function get_attachment_image_html( $settings, $image_key, $image_size_key = null, $image_attr = array() ) {
368 if ( ! $image_key ) {
369 $image_key = $image_size_key;
370 }
371
372 $image = $settings[ $image_key ];
373
374 $size = $image_size_key;
375
376 $html = '';
377 if ( ! empty( $image['id'] ) && $image['id'] != '-1' && get_post($image['id'])) {
378 $html .= wp_get_attachment_image( $image['id'], $size, false, $image_attr );
379 } else {
380 $html .= sprintf(
381 '<img src="%s" title="%s" alt="%s" class="%s" />',
382 esc_attr($image['url']),
383 \Elementor\Control_Media::get_image_title($image),
384 \Elementor\Control_Media::get_image_alt($image),
385 (isset($image_attr['class']) ? esc_attr($image_attr['class']) : '')
386 );
387 }
388
389 $html = preg_replace( array( '/max-width:[^"]*;/', '/width:[^"]*;/', '/height:[^"]*;/' ), '', $html );
390
391 return $html;
392 }
393
394 public static function swiper_class() {
395 return 'ekit-main-swiper swiper';
396 }
397
398 /**
399 * Get a page/post by slug (new method).
400 *
401 * @since 3.6.1
402 *
403 * @param string $slug Post slug.
404 * @param string $post_type Post type. Default 'page'.
405 * @return WP_Post|null WP_Post object if found, null otherwise.
406 */
407 public static function get_page_by_title( $slug, $post_type = 'page' ) {
408 $posts = get_posts(
409 [
410 'name' => $slug,
411 'post_type' => $post_type,
412 'post_status' => 'publish',
413 'numberposts' => 1,
414 'no_found_rows' => true,
415 'ignore_sticky_posts' => true,
416 ]
417 );
418
419 if ( ! empty( $posts ) ) {
420 return $posts[0];
421 }
422
423 return null;
424 }
425
426 /**
427 * Check whether a specific plugin is active.
428 *
429 * Works for both single-site and multisite installations
430 * (including network-activated plugins).
431 *
432 * @since 3.7.8
433 *
434 * @param string $plugin_file Plugin file path relative to the plugins directory.
435 * Example: 'elementskit/elementskit.php'.
436 *
437 * @return bool True if the plugin is active, false otherwise.
438 */
439 public static function ekit_is_plugin_active( string $plugin_file ): bool {
440 $active_plugins = (array) apply_filters(
441 'active_plugins',
442 get_option( 'active_plugins', [] )
443 );
444
445 // Include network-activated plugins for multisite installs.
446 if ( is_multisite() ) {
447 $network_plugins = array_keys(
448 (array) get_site_option( 'active_sitewide_plugins', [] )
449 );
450
451 $active_plugins = array_merge( $active_plugins, $network_plugins );
452 }
453
454 return in_array( $plugin_file, $active_plugins, true );
455 }
456
457 /**
458 * Get the ElementsKit promo icon SVG markup.
459 *
460 * @since 3.8.1
461 * @access public
462 *
463 * @param string $fill Fill color for the SVG paths. Default '#13151D'.
464 * @param int $width Width of the SVG. Default 16.
465 * @param int $height Height of the SVG. Default 14.
466 *
467 * @return string SVG markup.
468 */
469 public static function get_promo_icon( string $fill = 'var(--e-a-color-txt-accent)', int $width = 16, int $height = 14 ): string {
470 return sprintf(
471 '<svg xmlns="http://www.w3.org/2000/svg" width="%1$d" height="%2$d" viewBox="0 0 16 14" fill="currentColor" style="margin-bottom:-2px;margin-right:5px;">
472 <path d="M0.51183 8.49042H4.93761C5.14836 8.49042 5.2989 8.36999 5.38922 8.21945C5.41933 8.15924 5.44944 8.06892 5.44944 7.97859V6.11192C5.44944 5.81085 5.20858 5.6001 4.93761 5.6001H2.37848H0.51183C0.210756 5.6001 0 5.84096 0 6.11192V7.97859C0 8.27967 0.240863 8.49042 0.51183 8.49042Z" fill="%3$s"/>
473 <path d="M11.3201 6.98495C11.3201 6.74409 11.4104 6.50322 11.5609 6.29247L14.8426 2.37849C14.9631 2.22796 15.0233 2.04731 14.9932 1.89677C14.9932 1.74623 14.933 1.62581 14.8125 1.50538L13.548 0.210752C13.4577 0.120429 13.3373 0.0602123 13.2168 0.0301048C13.1566 0.0301048 13.1265 0 13.0663 0C12.8857 0 12.705 0.0903189 12.5846 0.240857L11.4706 1.5957L10.4771 2.76989L8.24911 5.44946C7.97814 5.78064 7.82761 6.14193 7.7674 6.53333C7.67707 7.16559 7.8276 7.82795 8.24911 8.36989L9.30287 9.63441L9.99535 10.4774L11.4706 12.2538L12.2835 13.2473L12.705 13.7591C12.8255 13.9097 13.0061 13.9699 13.1867 14C13.2771 14 13.3674 13.9699 13.4577 13.9398C13.548 13.9097 13.6082 13.8495 13.6684 13.7892L13.7287 13.729L14.9029 12.5849C15.1437 12.3441 15.1738 11.9527 14.933 11.7118L14.5717 11.2602L13.3072 9.72473L11.5308 7.6172C11.4104 7.46666 11.3201 7.22581 11.3201 6.98495ZM10.4771 2.86022C10.4771 2.89032 10.4771 2.89032 10.4771 2.86022V2.86022Z" fill="%3$s"/>
474 <path d="M1.65511 13.6989H7.85723C8.15831 13.6989 8.36906 13.4581 8.36906 13.1871V13.0968V11.3204C8.36906 11.0193 8.1282 10.8086 7.85723 10.8086H7.46584H4.18412H0.571227C0.511012 10.8086 0.450805 10.8086 0.39059 10.8387C0.179838 10.8989 0.0292969 11.1097 0.0292969 11.3204V12.2538V13.1871C0.0292969 13.4882 0.27016 13.6989 0.541127 13.6989H0.571227H1.65511Z" fill="%3$s"/>
475 <path d="M6.71396 0.391602H0.51183C0.210756 0.391602 0 0.632465 0 0.903433V0.993752V2.7701C0 3.07117 0.240863 3.28193 0.51183 3.28193H0.903223H4.18492H7.79782C7.85803 3.28193 7.91826 3.28192 7.97847 3.25182C8.18923 3.1916 8.33977 2.98085 8.33977 2.7701V1.83676V0.903433C8.33977 0.602358 8.0989 0.391602 7.82794 0.391602H7.79782H6.71396Z" fill="%3$s"/>
476 </svg>',
477 $width,
478 $height,
479 esc_attr( $fill )
480 );
481 }
482
483 }
484