PluginProbe ʕ •ᴥ•ʔ
Essential Addons for Elementor – Popular Elementor Templates & Widgets / 5.1.4
Essential Addons for Elementor – Popular Elementor Templates & Widgets v5.1.4
6.6.5 6.6.4 6.6.3 5.7.3 5.7.4 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.15 5.8.16 5.8.18 5.8.2 5.8.3 5.8.4 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.10 5.9.11 5.9.12 5.9.13 5.9.14 5.9.15 5.9.16 5.9.17 5.9.18 5.9.19 5.9.2 5.9.20 5.9.21 5.9.22 5.9.23 5.9.24 5.9.25 5.9.26 5.9.27 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.14 6.0.15 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.0 6.1.1 6.1.10 6.1.11 trunk 6.1.12 1.0.0 6.1.13 1.0.1 6.1.14 1.1.0 6.1.15 2.0 6.1.17 2.1 6.1.18 2.10.0 6.1.19 2.10.1 6.1.2 2.10.2 6.1.20 2.10.3 6.1.3 2.10.4 6.1.4 2.10.5 6.1.5 2.2.0 6.1.6 2.2.1 6.1.7 2.2.2 6.1.8 2.2.3 6.1.9 2.2.4 6.2.0 2.2.5 6.2.1 2.3.0 6.2.2 2.3.1 6.2.3 2.4.0 6.2.4 2.4.1 6.3.0 2.4.2 6.3.1 2.4.3 6.3.2 2.5.0 6.3.3 2.6.0 6.4.0 2.7.0 6.5.0 2.7.1 6.5.1 2.7.10 6.5.10 2.7.11 6.5.11 2.7.2 6.5.12 2.7.3 6.5.13 2.7.4 6.5.2 2.7.5 6.5.3 2.7.6 6.5.4 2.7.7 6.5.5 2.7.8 6.5.6 2.7.9 6.5.7 2.8.0 6.5.8 2.8.1 6.5.9 2.8.2 6.6.0 2.8.3 6.6.1 2.8.4 6.6.2 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.4.1 3.1.5 3.2.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 5.0.0 5.0.1 5.0.10 5.0.11 5.0.12 5.0.13 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.4.6 5.5.5 5.6.5 5.7.2
essential-addons-for-elementor-lite / includes / Classes / Helper.php
essential-addons-for-elementor-lite / includes / Classes Last commit date
Bootstrap.php 4 years ago Helper.php 4 years ago Migration.php 4 years ago Plugin_Usage_Tracker.php 4 years ago WPDeveloper_Core_Installer.php 4 years ago WPDeveloper_Notice.php 4 years ago WPDeveloper_Plugin_Installer.php 4 years ago WPDeveloper_Setup_Wizard.php 4 years ago
Helper.php
1198 lines
1 <?php
2
3 namespace Essential_Addons_Elementor\Classes;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 } // Exit if accessed directly
8
9 use \Elementor\Controls_Manager;
10 use \Elementor\Utils;
11 use Elementor\Plugin;
12
13 class Helper
14 {
15
16
17 const EAEL_ALLOWED_HTML_TAGS = [
18 'article',
19 'aside',
20 'div',
21 'footer',
22 'h1',
23 'h2',
24 'h3',
25 'h4',
26 'h5',
27 'h6',
28 'header',
29 'main',
30 'nav',
31 'p',
32 'section',
33 'span',
34 ];
35
36 /**
37 * Include a file with variables
38 *
39 * @param $file_path
40 * @param $variables
41 *
42 * @return string
43 * @since 4.2.2
44 */
45 public static function include_with_variable( $file_path, $variables = [])
46 {
47 if (file_exists($file_path)) {
48 extract($variables);
49
50 ob_start();
51
52 include $file_path;
53
54 return ob_get_clean();
55 }
56
57 return '';
58 }
59
60 /**
61 * check EAEL extension can load this page or post
62 *
63 * @param $id page or post id
64 *
65 * @return bool
66 * @since 4.0.4
67 */
68 public static function prevent_extension_loading($post_id)
69 {
70 $template_name = get_post_meta($post_id, '_elementor_template_type', true);
71 $template_list = [
72 'header',
73 'footer',
74 'single',
75 'post',
76 'page',
77 'archive',
78 'search-results',
79 'error-404',
80 'product',
81 'product-archive',
82 'section',
83 ];
84
85 return in_array($template_name, $template_list);
86 }
87
88 public static function str_to_css_id( $str ) {
89 $str = strtolower( $str );
90
91 //Make alphanumeric (removes all other characters)
92 $str = preg_replace( "/[^a-z0-9_\s-]/", "", $str );
93
94 //Clean up multiple dashes or whitespaces
95 $str = preg_replace( "/[\s-]+/", " ", $str );
96
97 //Convert whitespaces and underscore to dash
98 $str = preg_replace( "/[\s_]/", "-", $str );
99
100 return $str;
101 }
102
103 public static function fix_old_query($settings)
104 {
105 $update_query = false;
106
107 foreach ($settings as $key => $value) {
108 if (strpos($key, 'eaeposts_') !== false) {
109 $settings[str_replace('eaeposts_', '', $key)] = $value;
110 $update_query = true;
111 }
112 }
113
114 if ($update_query) {
115 global $wpdb;
116
117 $post_id = get_the_ID();
118 $data = get_post_meta($post_id, '_elementor_data', true);
119 $data = str_replace('eaeposts_', '', $data);
120 $wpdb->update(
121 $wpdb->postmeta,
122 [
123 'meta_value' => $data,
124 ],
125 [
126 'post_id' => $post_id,
127 'meta_key' => '_elementor_data',
128 ]
129 );
130 }
131
132 return $settings;
133 }
134
135 public static function get_query_args($settings = [], $post_type = 'post')
136 {
137 $settings = wp_parse_args($settings, [
138 'post_type' => $post_type,
139 'posts_ids' => [],
140 'orderby' => 'date',
141 'order' => 'desc',
142 'posts_per_page' => 3,
143 'offset' => 0,
144 'post__not_in' => [],
145 ]);
146
147 $args = [
148 'orderby' => $settings['orderby'],
149 'order' => $settings['order'],
150 'ignore_sticky_posts' => 1,
151 'post_status' => 'publish',
152 'posts_per_page' => $settings['posts_per_page'],
153 'offset' => $settings['offset'],
154 ];
155
156 if ('by_id' === $settings['post_type']) {
157 $args['post_type'] = 'any';
158 $args['post__in'] = empty($settings['posts_ids']) ? [0] : $settings['posts_ids'];
159 } else {
160 $args['post_type'] = $settings['post_type'];
161
162 //if ($args['post_type'] !== 'page') {
163 $args['tax_query'] = [];
164
165 $taxonomies = get_object_taxonomies($settings['post_type'], 'objects');
166
167 foreach ($taxonomies as $object) {
168 $setting_key = $object->name . '_ids';
169
170 if (!empty($settings[$setting_key])) {
171 $args['tax_query'][] = [
172 'taxonomy' => $object->name,
173 'field' => 'term_id',
174 'terms' => $settings[$setting_key],
175 ];
176 }
177 }
178
179 if (!empty($args['tax_query'])) {
180 $args['tax_query']['relation'] = 'AND';
181 }
182 //}
183 }
184
185 if (!empty($settings['authors'])) {
186 $args['author__in'] = $settings['authors'];
187 }
188
189 if (!empty($settings['post__not_in'])) {
190 $args['post__not_in'] = $settings['post__not_in'];
191 }
192
193 return $args;
194 }
195
196 /**
197 * Go Premium
198 *
199 */
200 public static function go_premium($wb)
201 {
202 $wb->start_controls_section(
203 'eael_section_pro',
204 [
205 'label' => __('Go Premium for More Features', 'essential-addons-for-elementor-lite'),
206 ]
207 );
208
209 $wb->add_control(
210 'eael_control_get_pro',
211 [
212 'label' => __('Unlock more possibilities', 'essential-addons-for-elementor-lite'),
213 'type' => Controls_Manager::CHOOSE,
214 'options' => [
215 '1' => [
216 'title' => '',
217 'icon' => 'fa fa-unlock-alt',
218 ],
219 ],
220 'default' => '1',
221 'description' => '<span class="pro-feature"> Get the <a href="https://wpdeveloper.com/upgrade/ea-pro" target="_blank">Pro version</a> for more stunning elements and customization options.</span>',
222 ]
223 );
224
225 $wb->end_controls_section();
226 }
227
228 /**
229 * Get All POst Types
230 * @return array
231 */
232 public static function get_post_types()
233 {
234 $post_types = get_post_types(['public' => true, 'show_in_nav_menus' => true], 'objects');
235 $post_types = wp_list_pluck($post_types, 'label', 'name');
236
237 return array_diff_key($post_types, ['elementor_library', 'attachment']);
238 }
239
240 /**
241 * Get all types of post.
242 *
243 * @param string $post_type
244 *
245 * @return array
246 */
247 public static function get_post_list($post_type = 'any')
248 {
249 return self::get_query_post_list($post_type);
250 }
251
252 /**
253 * POst Orderby Options
254 *
255 * @return array
256 */
257 public static function get_post_orderby_options()
258 {
259 $orderby = array(
260 'ID' => 'Post ID',
261 'author' => 'Post Author',
262 'title' => 'Title',
263 'date' => 'Date',
264 'modified' => 'Last Modified Date',
265 'parent' => 'Parent Id',
266 'rand' => 'Random',
267 'comment_count' => 'Comment Count',
268 'menu_order' => 'Menu Order',
269 );
270
271 return $orderby;
272 }
273
274 /**
275 * Get Post Categories
276 *
277 * @return array
278 */
279 public static function get_terms_list($taxonomy = 'category', $key = 'term_id')
280 {
281 $options = [];
282 $terms = get_terms([
283 'taxonomy' => $taxonomy,
284 'hide_empty' => true,
285 ]);
286
287 if (!empty($terms) && !is_wp_error($terms)) {
288 foreach ($terms as $term) {
289 $options[$term->{$key}] = $term->name;
290 }
291 }
292
293 return $options;
294 }
295
296 /**
297 * Get all elementor page templates
298 *
299 * @param null $type
300 *
301 * @return array
302 */
303 public static function get_elementor_templates($type = null)
304 {
305 $options = [];
306
307 if ($type) {
308 $args = [
309 'post_type' => 'elementor_library',
310 'posts_per_page' => -1,
311 ];
312 $args['tax_query'] = [
313 [
314 'taxonomy' => 'elementor_library_type',
315 'field' => 'slug',
316 'terms' => $type,
317 ],
318 ];
319
320 $page_templates = get_posts($args);
321
322 if (!empty($page_templates) && !is_wp_error($page_templates)) {
323 foreach ($page_templates as $post) {
324 $options[$post->ID] = $post->post_title;
325 }
326 }
327 } else {
328 $options = self::get_query_post_list('elementor_library');
329 }
330
331 return $options;
332 }
333
334 /**
335 * Get all Authors
336 *
337 * @return array
338 */
339 public static function get_authors_list() {
340 $args = [
341 'capability' => [ 'edit_posts' ],
342 'has_published_posts' => true,
343 'fields' => [
344 'ID',
345 'display_name',
346 ],
347 ];
348
349 // Capability queries were only introduced in WP 5.9.
350 if ( version_compare( $GLOBALS['wp_version'], '5.9-alpha', '<' ) ) {
351 $args['who'] = 'authors';
352 unset( $args['capability'] );
353 }
354
355 $users = get_users( $args );
356
357 if ( ! empty( $users ) ) {
358 return wp_list_pluck( $users, 'display_name', 'ID' );
359 }
360
361 return [];
362 }
363
364 /**
365 * Get all Tags
366 *
367 * @param array $args
368 *
369 * @return array
370 */
371 public static function get_tags_list($args = array())
372 {
373 $options = [];
374 $tags = get_tags($args);
375
376 if (!is_wp_error($tags) && !empty($tags)) {
377 foreach ($tags as $tag) {
378 $options[$tag->term_id] = $tag->name;
379 }
380 }
381
382 return $options;
383 }
384
385 /**
386 * Get all taxonomies by post
387 *
388 * @param array $args
389 *
390 * @param string $output
391 * @param string $operator
392 *
393 * @return array
394 */
395 public static function get_taxonomies_by_post($args = [], $output = 'names', $operator = 'and')
396 {
397 global $wp_taxonomies;
398
399 $field = ('names' === $output) ? 'name' : false;
400
401 // Handle 'object_type' separately.
402 if (isset($args['object_type'])) {
403 $object_type = (array) $args['object_type'];
404 unset($args['object_type']);
405 }
406
407 $taxonomies = wp_filter_object_list($wp_taxonomies, $args, $operator);
408
409 if (isset($object_type)) {
410 foreach ($taxonomies as $tax => $tax_data) {
411 if (!array_intersect($object_type, $tax_data->object_type)) {
412 unset($taxonomies[$tax]);
413 }
414 }
415 }
416
417 if ($field) {
418 $taxonomies = wp_list_pluck($taxonomies, $field);
419 }
420
421 return $taxonomies;
422 }
423
424 /**
425 * Get Contact Form 7 [ if exists ]
426 */
427 public static function get_wpcf7_list()
428 {
429 $options = array();
430
431 if (function_exists('wpcf7')) {
432 $wpcf7_form_list = get_posts(array(
433 'post_type' => 'wpcf7_contact_form',
434 'showposts' => 999,
435 ));
436 $options[0] = esc_html__('Select a Contact Form', 'essential-addons-for-elementor-lite');
437 if (!empty($wpcf7_form_list) && !is_wp_error($wpcf7_form_list)) {
438 foreach ($wpcf7_form_list as $post) {
439 $options[$post->ID] = $post->post_title;
440 }
441 } else {
442 $options[0] = esc_html__('Create a Form First', 'essential-addons-for-elementor-lite');
443 }
444 }
445 return $options;
446 }
447
448 /**
449 * Get Gravity Form [ if exists ]
450 *
451 * @return array
452 */
453 public static function get_gravity_form_list()
454 {
455 $options = array();
456
457 if (class_exists('GFCommon')) {
458 $gravity_forms = \RGFormsModel::get_forms(null, 'title');
459
460 if (!empty($gravity_forms) && !is_wp_error($gravity_forms)) {
461
462 $options[0] = esc_html__('Select Gravity Form', 'essential-addons-for-elementor-lite');
463 foreach ($gravity_forms as $form) {
464 $options[$form->id] = $form->title;
465 }
466
467 } else {
468 $options[0] = esc_html__('Create a Form First', 'essential-addons-for-elementor-lite');
469 }
470 }
471
472 return $options;
473 }
474
475 /**
476 * Get WeForms Form List
477 *
478 * @return array
479 */
480 public static function get_weform_list()
481 {
482 $wpuf_form_list = get_posts(array(
483 'post_type' => 'wpuf_contact_form',
484 'showposts' => 999,
485 ));
486
487 $options = array();
488
489 if (!empty($wpuf_form_list) && !is_wp_error($wpuf_form_list)) {
490 $options[0] = esc_html__('Select weForm', 'essential-addons-for-elementor-lite');
491 foreach ($wpuf_form_list as $post) {
492 $options[$post->ID] = $post->post_title;
493 }
494 } else {
495 $options[0] = esc_html__('Create a Form First', 'essential-addons-for-elementor-lite');
496 }
497
498 return $options;
499 }
500
501 /**
502 * Get Ninja Form List
503 *
504 * @return array
505 */
506 public static function get_ninja_form_list()
507 {
508 $options = array();
509
510 if (class_exists('Ninja_Forms')) {
511 $contact_forms = Ninja_Forms()->form()->get_forms();
512
513 if (!empty($contact_forms) && !is_wp_error($contact_forms)) {
514
515 $options[0] = esc_html__('Select Ninja Form', 'essential-addons-for-elementor-lite');
516
517 foreach ($contact_forms as $form) {
518 $options[$form->get_id()] = $form->get_setting('title');
519 }
520 }
521 } else {
522 $options[0] = esc_html__('Create a Form First', 'essential-addons-for-elementor-lite');
523 }
524
525 return $options;
526 }
527
528 /**
529 * Get Caldera Form List
530 *
531 * @return array
532 */
533 public static function get_caldera_form_list()
534 {
535 $options = array();
536
537 if (class_exists('Caldera_Forms')) {
538 $contact_forms = \Caldera_Forms_Forms::get_forms(true, true);
539
540 if (!empty($contact_forms) && !is_wp_error($contact_forms)) {
541 $options[0] = esc_html__('Select Caldera Form', 'essential-addons-for-elementor-lite');
542 foreach ($contact_forms as $form) {
543 $options[$form['ID']] = $form['name'];
544 }
545 }
546 } else {
547 $options[0] = esc_html__('Create a Form First', 'essential-addons-for-elementor-lite');
548 }
549
550 return $options;
551 }
552
553 /**
554 * Get WPForms List
555 *
556 * @return array
557 */
558 public static function get_wpforms_list()
559 {
560 $options = array();
561
562 if (class_exists('\WPForms\WPForms')) {
563 $args = array(
564 'post_type' => 'wpforms',
565 'posts_per_page' => -1,
566 );
567
568 $contact_forms = get_posts($args);
569
570 if (!empty($contact_forms) && !is_wp_error($contact_forms)) {
571 $options[0] = esc_html__('Select a WPForm', 'essential-addons-for-elementor-lite');
572 foreach ($contact_forms as $post) {
573 $options[$post->ID] = $post->post_title;
574 }
575 }
576 } else {
577 $options[0] = esc_html__('Create a Form First', 'essential-addons-for-elementor-lite');
578 }
579
580 return $options;
581 }
582
583
584
585 public static function get_ninja_tables_list()
586 {
587 $tables = get_posts([
588 'post_type' => 'ninja-table',
589 'post_status' => 'publish',
590 'posts_per_page' => '-1',
591 ]);
592
593 if (!empty($tables)) {
594 return wp_list_pluck($tables, 'post_title', 'ID');
595 }
596
597 return [];
598 }
599
600 public static function get_terms_as_list($term_type = 'category', $length = 1)
601 {
602 $terms = get_the_terms( get_the_ID(), $term_type );
603
604 if ($term_type === 'category') {
605 $terms = get_the_category();
606 }
607
608 if ($term_type === 'tags') {
609 $terms = get_the_tags();
610 }
611
612 if (empty($terms)) {
613 return;
614 }
615
616 $count = 0;
617
618 $html = '<ul class="post-carousel-categories">';
619 foreach ($terms as $term) {
620 if ( $count === absint( $length ) ) {
621 break;
622 }
623 $link = ($term_type === 'category') ? get_category_link($term->term_id) : get_tag_link($term->term_id);
624 $html .= '<li>';
625 $html .= '<a href="' . esc_url($link) . '">';
626 $html .= $term->name;
627 $html .= '</a>';
628 $html .= '</li>';
629 $count++;
630 }
631 $html .= '</ul>';
632
633 return $html;
634
635 }
636
637 /**
638 * Returns product categories list
639 *
640 * @return string
641 */
642 public static function get_product_categories_list($terms_name) {
643 global $product;
644
645 if ( ! is_a( $product, 'WC_Product' ) ) {
646 return;
647 }
648
649 $separator = '';
650 $before = '<ul class="eael-product-cats"><li>';
651 $after = '</li></ul>';
652
653 return get_the_term_list( $product->get_id(), $terms_name, $before, $separator, $after );
654 }
655
656 /**
657 * This function is responsible for counting doc post under a category.
658 *
659 * @param int $term_count
660 * @param int $term_id
661 * @return int $term_count;
662 */
663 public static function get_doc_post_count($term_count = 0, $term_id = 0)
664 {
665 $tax_terms = get_terms('doc_category', ['child_of' => $term_id]);
666
667 foreach ($tax_terms as $tax_term) {
668 $term_count += $tax_term->count;
669 }
670
671 return $term_count;
672 }
673
674 public static function get_dynamic_args(array $settings, array $args)
675 {
676 if ($settings['post_type'] === 'source_dynamic' && is_archive()) {
677 $data = get_queried_object();
678
679 if (isset($data->post_type)) {
680 $args['post_type'] = $data->post_type;
681 $args['tax_query'] = [];
682 } else {
683 global $wp_query;
684 $args['post_type'] = $wp_query->query_vars['post_type'];
685 if(!empty($wp_query->query_vars['s'])){
686 $args['s'] = $wp_query->query_vars['s'];
687 $args['offset'] = 0;
688 }
689 }
690
691 if ( isset( $data->taxonomy ) ) {
692 $args[ 'tax_query' ][] = [
693 'taxonomy' => $data->taxonomy,
694 'field' => 'term_id',
695 'terms' => $data->term_id,
696 ];
697 }
698
699 if ( isset($data->taxonomy) ) {
700 $args[ 'tax_query' ][] = [
701 'taxonomy' => $data->taxonomy,
702 'field' => 'term_id',
703 'terms' => $data->term_id,
704 ];
705 }
706
707 if (get_query_var('author') > 0) {
708 $args['author__in'] = get_query_var('author');
709 }
710
711 if (get_query_var('s')!='') {
712 $args['s'] = get_query_var('s');
713 }
714
715 if (get_query_var('year') || get_query_var('monthnum') || get_query_var('day')) {
716 $args['date_query'] = [
717 'year' => get_query_var('year'),
718 'month' => get_query_var('monthnum'),
719 'day' => get_query_var('day'),
720 ];
721 }
722
723 if (!empty($args['tax_query'])) {
724 $args['tax_query']['relation'] = 'AND';
725 }
726 }
727
728 return $args;
729 }
730
731 public static function get_multiple_kb_terms($prettify = false, $term_id = true)
732 {
733 $args = [
734 'taxonomy' => 'knowledge_base',
735 'hide_empty' => true,
736 'parent' => 0,
737 ];
738
739 $terms = get_terms($args);
740
741 if (is_wp_error($terms)) {
742 return [];
743 }
744
745 if ($prettify) {
746 $pretty_taxonomies = [];
747
748 foreach ($terms as $term) {
749 $pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = $term->name;
750 }
751
752 return $pretty_taxonomies;
753 }
754
755 return $terms;
756 }
757
758 public static function get_betterdocs_multiple_kb_status()
759 {
760 if (\BetterDocs_DB::get_settings('multiple_kb') == 1) {
761 return 'true';
762 }
763
764 return '';
765 }
766
767 public static function get_query_post_list($post_type = 'any', $limit = -1, $search = '')
768 {
769 global $wpdb;
770 $where = '';
771 $data = [];
772
773 if (-1 == $limit) {
774 $limit = '';
775 } elseif (0 == $limit) {
776 $limit = "limit 0,1";
777 } else {
778 $limit = $wpdb->prepare(" limit 0,%d", esc_sql($limit));
779 }
780
781 if ('any' === $post_type) {
782 $in_search_post_types = get_post_types(['exclude_from_search' => false]);
783 if (empty($in_search_post_types)) {
784 $where .= ' AND 1=0 ';
785 } else {
786 $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '",
787 array_map('esc_sql', $in_search_post_types)) . "')";
788 }
789 } elseif (!empty($post_type)) {
790 $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_type = %s", esc_sql($post_type));
791 }
792
793 if (!empty($search)) {
794 $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql($search) . '%');
795 }
796
797 $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' $where $limit";
798 $results = $wpdb->get_results($query);
799 if (!empty($results)) {
800 foreach ($results as $row) {
801 $data[$row->ID] = $row->post_title;
802 }
803 }
804 return $data;
805 }
806
807 public static function eael_get_widget_settings( $page_id, $widget_id ) {
808 $document = Plugin::$instance->documents->get( $page_id );
809 $settings = [];
810 if ( $document ) {
811 $elements = Plugin::instance()->documents->get( $page_id )->get_elements_data();
812 $widget_data = self::find_element_recursive( $elements, $widget_id );
813 if (!empty($widget_data) && is_array($widget_data)) {
814 $widget = Plugin::instance()->elements_manager->create_element_instance( $widget_data );
815 }
816 if ( !empty($widget) ) {
817 $settings = $widget->get_settings_for_display();
818 }
819 }
820 return $settings;
821 }
822
823 /**
824 * Get Widget data.
825 *
826 * @param array $elements Element array.
827 * @param string $form_id Element ID.
828 *
829 * @return bool|array
830 */
831 public static function find_element_recursive( $elements, $form_id ) {
832
833 foreach ( $elements as $element ) {
834 if ( $form_id === $element['id'] ) {
835 return $element;
836 }
837
838 if ( ! empty( $element['elements'] ) ) {
839 $element = self::find_element_recursive( $element['elements'], $form_id );
840
841 if ( $element ) {
842 return $element;
843 }
844 }
845 }
846
847 return false;
848 }
849
850 /**
851 * eael_pagination
852 * Generate post pagination
853 *
854 * @param $args array wp_query param
855 * @param $settings array Elementor widget setting data
856 *
857 * @access public
858 * @return string|void
859 * @since 3.3.0
860 */
861 public static function eael_pagination ($args, $settings) {
862
863 $pagination_Count = intval( $args['total_post'] );
864 $paginationLimit = intval( $settings['eael_product_grid_products_count'] ) ?: 4;
865 $pagination_Paginationlist = ceil( $pagination_Count / $paginationLimit );
866 $widget_id = sanitize_key( $settings['eael_widget_id'] );
867 $page_id = intval( $settings['eael_page_id'] );
868 $next_label = $settings['pagination_next_label'];
869 $adjacents = "2";
870 $setPagination = "";
871 $template_info = [
872 'dir' => 'free',
873 'file_name' => $settings['eael_dynamic_template_Layout'],
874 'name' => $settings['eael_widget_name']
875 ];
876
877 if( $pagination_Paginationlist > 0 ){
878
879 $setPagination .="<nav id='{$widget_id}-eael-pagination' class='eael-woo-pagination' data-plimit='$paginationLimit' data-totalpage ='{$args['total_post']}' data-widgetid='{$widget_id}' data-pageid='$page_id' data-args='".http_build_query( $args )."' data-template='".json_encode( $template_info, 1 )."'>";
880 $setPagination .="<ul class='page-numbers'>";
881
882 if ( $pagination_Paginationlist < 7 + ($adjacents * 2) ){
883 for ( $pagination = 1; $pagination <= $pagination_Paginationlist; $pagination ++ ) {
884 $active = ( $pagination == 0 || $pagination == 1 ) ? 'current' : '';
885 $setPagination .= sprintf("<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>" ,$active ,$pagination);
886 }
887
888 } else if ( $pagination_Paginationlist >= 5 + ($adjacents * 2) ){
889 for ( $pagination = 1; $pagination <= 4 + ( $adjacents * 2 ); $pagination ++ ) {
890 $active = ( $pagination == 0 || $pagination == 1 ) ? 'current' : '';
891 $setPagination .= sprintf("<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>" ,$active ,$pagination);
892 }
893
894 $setPagination .="<li class='pagitext dots'>...</li>";
895 $setPagination .= sprintf("<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>" ,$active ,$pagination);
896 }
897
898 if ($pagination_Paginationlist > 1) {
899 $setPagination .= "<li class='pagitext'><a href='javascript:void(0);' class='page-numbers' data-pnumber='2'>".esc_html( $next_label )."</a></li>";
900 }
901
902 $setPagination .="</ul>";
903 $setPagination .="</nav>";
904
905 return $setPagination;
906 }
907 }
908
909 public static function eael_product_quick_view ($product, $settings, $widget_id) {
910
911 $sale_badge_align = isset( $settings['eael_product_sale_badge_alignment'] ) ? $settings['eael_product_sale_badge_alignment'] : '';
912 $sale_badge_preset = isset( $settings['eael_product_sale_badge_preset'] ) ? $settings['eael_product_sale_badge_preset'] : '';
913 $sale_text = ! empty( $settings['eael_product_carousel_sale_text'] ) ? $settings['eael_product_carousel_sale_text'] : (! empty( $settings['eael_product_sale_text'] ) ? $settings['eael_product_sale_text'] :'Sale!');
914 $stockout_text = ! empty( $settings['eael_product_carousel_stockout_text'] ) ? $settings['eael_product_carousel_stockout_text'] : (! empty( $settings['eael_product_stockout_text'] ) ? $settings['eael_product_stockout_text'] :'Stock Out');
915 $tag = ! empty( $settings['eael_product_quick_view_title_tag'] ) ? self::eael_validate_html_tag( $settings['eael_product_quick_view_title_tag'] ) : 'h1';
916
917 remove_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_title', 5 );
918 add_action( 'eael_woo_single_product_summary', function () use ( $tag ) {
919 printf('<%1$s class="eael-product-quick-view-title product_title entry-title">%2$s</%1$s>',$tag,Helper::eael_wp_kses( get_the_title() ));
920 }, 5 );
921
922 ?>
923
924 <div id="eaproduct<?php echo esc_attr( $widget_id . $product->get_id() ); ?>" class="eael-product-popup
925 eael-product-zoom-in woocommerce">
926 <div class="eael-product-modal-bg"></div>
927 <div class="eael-product-popup-details">
928 <div id="product-<?php esc_attr( get_the_ID() ); ?>" <?php post_class( 'product' ); ?>>
929 <div class="eael-product-image-wrap">
930 <?php
931 echo ( ! $product->is_in_stock() ? '<span class="eael-onsale outofstock '.esc_attr( $sale_badge_preset ).' '.esc_attr( $sale_badge_align ).'">'. esc_html( $stockout_text ) .'</span>' : ($product->is_on_sale() ? '<span class="eael-onsale '.esc_attr( $sale_badge_preset ).' '.esc_attr( $sale_badge_align ).'">' . esc_html( $sale_text ) . '</span>' : '') );
932 do_action( 'eael_woo_single_product_image' );
933 ?>
934 </div>
935 <div class="eael-product-details-wrap">
936 <?php do_action( 'eael_woo_single_product_summary' ); ?>
937 </div>
938 </div>
939 <button class="eael-product-popup-close"><i class="fas fa-times"></i></button>
940 </div>
941
942 </div>
943 <?php
944 }
945
946 public static function eael_avoid_redirect_to_single_page() {
947 return '';
948 }
949
950 public static function eael_woo_product_grid_actions() {
951
952 add_filter( 'woocommerce_add_to_cart_form_action', self::eael_avoid_redirect_to_single_page(), 10 );
953 add_action( 'eael_woo_before_product_loop', 'woocommerce_output_all_notices', 30 );
954
955 }
956
957 public static function get_local_plugin_data( $basename = '' ) {
958 if ( empty( $basename ) ) {
959 return false;
960 }
961
962 if ( !function_exists( 'get_plugins' ) ) {
963 include_once ABSPATH . 'wp-admin/includes/plugin.php';
964 }
965
966 $plugins = get_plugins();
967
968 if ( !isset( $plugins[ $basename ] ) ) {
969 return false;
970 }
971
972 return $plugins[ $basename ];
973 }
974
975 /**
976 * eael_validate_html_tag
977 * @param $tag
978 * @return mixed|string
979 */
980 public static function eael_validate_html_tag( $tag ){
981 return in_array( strtolower( $tag ), self::EAEL_ALLOWED_HTML_TAGS ) ? $tag : 'div';
982 }
983
984 /**
985 *
986 * Strip tag based on allowed html tag
987 * eael_wp_kses
988 * @param $text
989 * @return string
990 */
991 public static function eael_wp_kses($text){
992 return wp_kses($text,self::eael_allowed_tags());
993 }
994
995 /**
996 * List of allowed html tag for wp_kses
997 *
998 * eael_allowed_tags
999 * @return array
1000 */
1001 public static function eael_allowed_tags(){
1002 return [
1003 'a' => [
1004 'href' => [],
1005 'title' => [],
1006 'class' => [],
1007 'rel' => [],
1008 'id' => [],
1009 'style' => []
1010 ],
1011 'q' => [
1012 'cite' => [],
1013 'class' => [],
1014 'id' => [],
1015 ],
1016 'img' => [
1017 'src' => [],
1018 'alt' => [],
1019 'height' => [],
1020 'width' => [],
1021 'class' => [],
1022 'id' => [],
1023 'style' => []
1024 ],
1025 'span' => [
1026 'class' => [],
1027 'id' => [],
1028 'style' => []
1029 ],
1030 'dfn' => [
1031 'class' => [],
1032 'id' => [],
1033 'style' => []
1034 ],
1035 'time' => [
1036 'datetime' => [],
1037 'class' => [],
1038 'id' => [],
1039 'style' => [],
1040 ],
1041 'cite' => [
1042 'title' => [],
1043 'class' => [],
1044 'id' => [],
1045 'style' => [],
1046 ],
1047 'hr' => [
1048 'class' => [],
1049 'id' => [],
1050 'style' => [],
1051 ],
1052 'b' => [
1053 'class' => [],
1054 'id' => [],
1055 'style' => [],
1056 ],
1057 'p' => [
1058 'class' => [],
1059 'id' => [],
1060 'style' => []
1061 ],
1062 'i' => [
1063 'class' => [],
1064 'id' => [],
1065 'style' => []
1066 ],
1067 'u' => [
1068 'class' => [],
1069 'id' => [],
1070 'style' => []
1071 ],
1072 's' => [
1073 'class' => [],
1074 'id' => [],
1075 'style' => [],
1076 ],
1077 'br' => [],
1078 'em' => [
1079 'class' => [],
1080 'id' => [],
1081 'style' => []
1082 ],
1083 'code' => [
1084 'class' => [],
1085 'id' => [],
1086 'style' => [],
1087 ],
1088 'mark' => [
1089 'class' => [],
1090 'id' => [],
1091 'style' => [],
1092 ],
1093 'small' => [
1094 'class' => [],
1095 'id' => [],
1096 'style' => []
1097 ],
1098 'abbr' => [
1099 'title' => [],
1100 'class' => [],
1101 'id' => [],
1102 'style' => [],
1103 ],
1104 'strong' => [
1105 'class' => [],
1106 'id' => [],
1107 'style' => []
1108 ],
1109 'del' => [
1110 'class' => [],
1111 'id' => [],
1112 'style' => []
1113 ],
1114 'ins' => [
1115 'class' => [],
1116 'id' => [],
1117 'style' => []
1118 ],
1119 'sub' => [
1120 'class' => [],
1121 'id' => [],
1122 'style' => [],
1123 ],
1124 'sup' => [
1125 'class' => [],
1126 'id' => [],
1127 'style' => [],
1128 ],
1129 'div' => [
1130 'class' => [],
1131 'id' => [],
1132 'style' => []
1133 ],
1134 'strike' => [
1135 'class' => [],
1136 'id' => [],
1137 'style' => [],
1138 ],
1139 'acronym' => [],
1140 'h1' => [
1141 'class' => [],
1142 'id' => [],
1143 'style' => [],
1144 ],
1145 'h2' => [
1146 'class' => [],
1147 'id' => [],
1148 'style' => [],
1149 ],
1150 'h3' => [
1151 'class' => [],
1152 'id' => [],
1153 'style' => [],
1154 ],
1155 'h4' => [
1156 'class' => [],
1157 'id' => [],
1158 'style' => [],
1159 ],
1160 'h5' => [
1161 'class' => [],
1162 'id' => [],
1163 'style' => [],
1164 ],
1165 'h6' => [
1166 'class' => [],
1167 'id' => [],
1168 'style' => [],
1169 ],
1170 'button' => [
1171 'class' => [],
1172 'id' => [],
1173 'style' => [],
1174 ],
1175 ];
1176 }
1177
1178 public static function eael_fetch_color_or_global_color($settings, $control_name=''){
1179 if( !isset($settings[$control_name])) {
1180 return '';
1181 }
1182
1183 $color = $settings[$control_name];
1184
1185 if(!empty($settings['__globals__']) && !empty($settings['__globals__'][$control_name])){
1186 $color = $settings['__globals__'][$control_name];
1187 $color_arr = explode('?id=', $color); //E.x. 'globals/colors/?id=primary'
1188
1189 $color_name = count($color_arr) > 1 ? $color_arr[1] : '';
1190 if( !empty($color_name) ) {
1191 $color = "var( --e-global-color-$color_name )";
1192 }
1193 }
1194
1195 return $color;
1196 }
1197 }
1198