PluginProbe ʕ •ᴥ•ʔ
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools / 3.0.38
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools v3.0.38
3.0.59 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 3.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.18 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 3.0.35 3.0.36 3.0.37 3.0.38 3.0.39 3.0.4 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.5 3.0.50 3.0.51 3.0.52 3.0.53 3.0.54 3.0.55 3.0.56 3.0.57 3.0.58 3.0.6 3.0.7 3.0.8 3.0.9
essential-classy-addons-for-elementor / classes / class-helper.php
essential-classy-addons-for-elementor / classes Last commit date
builders 1 year ago documents 1 year ago builder-content.php 1 year ago class-helper.php 1 year ago class-loader.php 1 year ago class-panel-options.php 1 year ago conditions-file.php 1 year ago conditions-rules.php 1 year ago elementor-document.php 1 year ago theme-builder.php 1 year ago widgets-passing-lists.php 1 year ago
class-helper.php
570 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6 class EcafeHelper {
7
8 private static $instance;
9
10 public static function instanceFetch() {
11 if ( ! isset( self::$instance ) ) {
12 self::$instance = new self;
13 }
14 return self::$instance;
15 }
16
17 /**
18 * Constructor
19 */
20 public function __construct() {}
21
22 /**
23 * Get Number
24 */
25 public static function getNumbers($start=0,$end=10,$none=''){
26 $options = [];
27 if(!empty($none)){
28 $options[ 0 ] = esc_html__( 'None', 'essential-classy-addons-for-elementor' );
29 }
30 for( $start;$start<=$end;$start++) {
31 $options[ $start ] = $start;
32 }
33 return $options;
34 }
35
36 /**
37 * Get Template
38 */
39 public static function getTemplates() {
40 $EleTemplates = Elementor\Plugin::instance()->templates_manager->get_source( 'local' )->get_items();
41 $types = [];
42
43 if ( empty( $EleTemplates ) ) {
44 $options = [ '0' => esc_html__( 'No Templates Found.', 'essential-classy-addons-for-elementor' ) ];
45 } else {
46 $options = [ '0' => esc_html__( 'Select Template', 'essential-classy-addons-for-elementor' ) ];
47
48 foreach ( $EleTemplates as $template ) {
49 $options[ $template['template_id'] ] = $template['title'] . ' (' . $template['type'] . ')';
50 $types[ $template['template_id'] ] = $template['type'];
51 }
52 }
53
54 return $options;
55 }
56
57 /**
58 * Get option
59 */
60 public static function ecafeGetOption($optionsType,$field){
61 $ecafewidgetsPage=get_option('ecafe_widgets');
62 $postTypeOptions=get_option('post_type_options');
63 $values='';
64 if($optionsType=='general'){
65 if(isset($ecafewidgetsPage[$field]) && !empty($ecafewidgetsPage[$field])){
66 $values=$ecafewidgetsPage[$field];
67 }
68 }
69 if($optionsType=='post_type'){
70 if(isset($postTypeOptions[$field]) && !empty($postTypeOptions[$field])){
71 $values=$postTypeOptions[$field];
72 }
73 }
74 return $values;
75 }
76
77 /*html tag validate*/
78 public static function html_tag_check_and_verify(){
79 return [ 'h1',
80 'h2',
81 'h3',
82 'h4',
83 'h5',
84 'h6',
85 'div',
86 'a',
87 'span',
88 'p',
89 'main',
90 'nav',
91 'section',
92 'header',
93 'footer',
94 'article',
95 'aside',
96 ];
97 }
98
99 public static function check_and_validate_html_tag( $chk_tag ) {
100 return in_array( strtolower( $chk_tag ), \EcafeHelper::html_tag_check_and_verify() ) ? $chk_tag : 'div';
101 }
102
103 /*get Style Loop List*/
104 public static function getStyleLoop( $max = 5, $none='',$loop='' ) {
105 $style = [];
106 if($none=='yes'){
107 $style[ 'none' ] = esc_html__('None','essential-classy-addons-for-elementor');
108 }
109 for( $i=1;$i<=$max;$i++) {
110 $style[ 'style-'.$i ] = esc_html__('Style ','essential-classy-addons-for-elementor').$i;
111 }
112 if($loop=='yes'){
113 $style[ 'custom-template' ] = esc_html__('Custom Template','essential-classy-addons-for-elementor');
114 }
115
116 return $style;
117 }
118
119 public static function getListLayout() {
120 return array(
121 'grid' => esc_html__( 'Grid', 'essential-classy-addons-for-elementor' ),
122 'masonry' => esc_html__( 'Masonry', 'essential-classy-addons-for-elementor' ),
123 );
124 }
125
126 public static function getResponsiveColumn() {
127 return array(
128 '100' => esc_html__( '1', 'essential-classy-addons-for-elementor' ),
129 '50' => esc_html__( '2', 'essential-classy-addons-for-elementor' ),
130 '33.3333' => esc_html__( '3', 'essential-classy-addons-for-elementor' ),
131 '25' => esc_html__( '4', 'essential-classy-addons-for-elementor' ),
132 '20' => esc_html__( '5', 'essential-classy-addons-for-elementor' ),
133 '16.666667' => esc_html__( '6', 'essential-classy-addons-for-elementor' ),
134 );
135 }
136
137 public static function getHtmlTag($linktag='') {
138 $tag = array(
139 'h1' => esc_html__('H1', 'essential-classy-addons-for-elementor'),
140 'h2' => esc_html__('H2', 'essential-classy-addons-for-elementor'),
141 'h3' => esc_html__('H3', 'essential-classy-addons-for-elementor'),
142 'h4' => esc_html__('H4', 'essential-classy-addons-for-elementor'),
143 'h5' => esc_html__('H5', 'essential-classy-addons-for-elementor'),
144 'h6' => esc_html__('H6', 'essential-classy-addons-for-elementor'),
145 'span' => esc_html__('Span', 'essential-classy-addons-for-elementor'),
146 'p' => esc_html__('P', 'essential-classy-addons-for-elementor'),
147 'div' => esc_html__('Div', 'essential-classy-addons-for-elementor'),
148 );
149 if(!empty($linktag)){
150 $tag['a'] = esc_html__( 'a', 'essential-classy-addons-for-elementor' );
151 }
152 return $tag;
153 }
154
155 /* get Post Tyles List*/
156 public static function getPostTypes() {
157 $options = [];
158 $postTypes = get_post_types( [ 'public' => true, 'show_ui' => true ], 'objects' );
159
160 $exclude = [ 'attachment', 'elementor_library' ];
161
162 foreach ( $postTypes as $postType ) {
163
164 if( TRUE === in_array( $postType->name, $exclude ) )
165 continue;
166
167 $options[$postType->name] = $postType->label;
168 }
169
170 return $options;
171 }
172
173 /* get Taxonomy List*/
174 public static function getTaxonomiesList() {
175 $options = [];
176 $output = 'objects'; // or names
177 $operator = 'and'; // 'and' or 'or'
178
179 $taxonomies = get_taxonomies( [ 'public' => true, 'show_ui' => true ], $output, $operator );
180 if ( $taxonomies ) {
181 foreach ( $taxonomies as $taxonomy ) {
182 $options[$taxonomy->name] = $taxonomy->label;
183 }
184 return $options;
185 }
186 }
187
188 /* Get Post Categories */
189 public static function getTermsList($taxonomy = 'category', $key = 'term_id') {
190 $options = [];
191 $terms = get_terms([ 'taxonomy' => $taxonomy, 'hide_empty' => true ]);
192
193 if (!empty($terms) && !is_wp_error($terms)) {
194 foreach ($terms as $term) {
195 $options[$term->{$key}] = $term->name;
196 }
197 }
198
199 return $options;
200 }
201
202 /* Get all Authors*/
203 // public static function getAuthorsList() {
204 // $users = get_users([
205 // 'capability' => 'authors',
206 // 'has_published_posts' => true,
207 // 'fields' => [
208 // 'ID',
209 // 'display_name',
210 // ],
211 // ]);
212
213 // if (!empty($users)) {
214 // return wp_list_pluck($users, 'display_name', 'ID');
215 // }
216
217 // return [];
218 // }
219
220 public static function getOrderByArray() {
221 $options = array(
222 'none' => esc_html__( 'None', 'essential-classy-addons-for-elementor' ),
223 'menu_order' => esc_html__( 'Default', 'essential-classy-addons-for-elementor' ),
224 'ID' => esc_html__( 'ID', 'essential-classy-addons-for-elementor' ),
225 'author' => esc_html__( 'Author', 'essential-classy-addons-for-elementor' ),
226 'title' => esc_html__( 'Title', 'essential-classy-addons-for-elementor' ),
227 'name' => esc_html__( 'Name (slug)', 'essential-classy-addons-for-elementor' ),
228 'date' => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
229 'modified' => esc_html__( 'Modified', 'essential-classy-addons-for-elementor' ),
230 'rand' => esc_html__( 'Random', 'essential-classy-addons-for-elementor' ),
231 'parent' => esc_html__( 'Parent Id', 'essential-classy-addons-for-elementor' ),
232 'comment_count' => esc_html__( 'Comment Count', 'essential-classy-addons-for-elementor' ),
233 );
234 ksort($options);
235 return $options;
236 }
237
238 public static function getOrderArray() {
239 return array(
240 'ASC' => esc_html__( 'Ascending', 'essential-classy-addons-for-elementor' ),
241 'DESC' => esc_html__( 'Descending', 'essential-classy-addons-for-elementor' ),
242 );
243 }
244
245 public static function getLoadingOptions() {
246 return array(
247 'none' => esc_html__( 'Select Options', 'essential-classy-addons-for-elementor' ),
248 'pagination' => esc_html__( 'Pagination', 'essential-classy-addons-for-elementor' ),
249 'load_more' => esc_html__( 'Load More', 'essential-classy-addons-for-elementor' ),
250 'lazy_load' => esc_html__( 'Lazy Load', 'essential-classy-addons-for-elementor' ),
251 );
252 }
253
254 public static function getQueryArgs( $settings =[], $onLoad = false){
255
256 $include_posts = ($settings['postsInclude']) ? explode(',', $settings['postsInclude']) : [];
257 $exclude_posts = ($settings['postsExclude']) ? explode(',', $settings['postsExclude']) : [];
258
259 if(is_single()){
260 $exclude_posts = array( get_the_ID());
261 }
262 $query_args = [
263 'post_type' => $settings['selectPostType'],
264 'post_status' => 'publish',
265 'posts_per_page' => !empty($onLoad) ? $settings['loadMorePost'] : $settings['numberOfPosts'],
266 'orderby' => $settings['postsOrderBy'],
267 'order' => $settings['postsOrder'],
268 'offset' => !empty($onLoad) ? $settings['offset'] : $settings['postsOffset'],
269 'post__in' => $include_posts,
270 'post__not_in' => $exclude_posts,
271 'ignore_sticky_posts' => true,
272 ];
273
274 $query_args['tax_query'] = [];
275
276 if (is_archive()) {
277 if (is_category()) {
278 $query_args['tax_query'][] = [
279 'taxonomy' => 'category',
280 'field' => 'term_id',
281 'terms' => get_queried_object_id(),
282 ];
283 } elseif (is_tag()) {
284 $query_args['tax_query'][] = [
285 'taxonomy' => 'post_tag',
286 'field' => 'term_id',
287 'terms' => get_queried_object_id(),
288 ];
289 } elseif (is_tax()) {
290 $queried_object = get_queried_object();
291 $query_args['tax_query'][] = [
292 'taxonomy' => $queried_object->taxonomy,
293 'field' => 'term_id',
294 'terms' => $queried_object->term_id,
295 ];
296 }
297 } else {
298 $setting_key = '';
299 if ($settings['selectPostType'] != 'post') {
300 $setting_key = !empty($settings['taxonomyInclude']) ? explode(',', $settings['taxonomyInclude']) : [];
301 } elseif ($settings['selectTaxonomy'] == 'category') {
302 $setting_key = !empty($settings['postCategory']) ? $settings['postCategory'] : [];
303 } elseif ($settings['selectTaxonomy'] == 'post_tag') {
304 $setting_key = !empty($settings['postTags']) ? $settings['postTags'] : [];
305 }
306
307 if (!empty($setting_key)) {
308 $query_args['tax_query'][] = [
309 'taxonomy' => $settings['selectTaxonomy'],
310 'field' => 'term_id',
311 'terms' => $setting_key,
312 ];
313 }
314 }
315
316 if (!empty($query_args['tax_query'])) {
317 $query_args['tax_query']['relation'] = 'AND';
318 }
319
320 return $query_args;
321 }
322
323 public static function getPostExcerpt($limit) {
324 if(method_exists('WPBMap', 'addAllMappedShortcodes')) {
325 WPBMap::addAllMappedShortcodes();
326 }
327 global $post;
328 $excerpt = explode(' ', get_the_excerpt(), $limit);
329 if (count($excerpt)>=$limit) {
330 array_pop($excerpt);
331 $excerpt = implode(" ",$excerpt).'...';
332 } else {
333 $excerpt = implode(" ",$excerpt);
334 }
335 $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
336
337 return $excerpt;
338 }
339
340
341 /*
342 * Post Pagination
343 */
344 public static function post_pagination($pages = '', $range = 4, $next ='Next', $prev = 'Prev') {
345 $showitems = ($range * 2)+1;
346
347 global $paged; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
348 if(empty($paged)) $paged = 1;
349
350 if( $pages == '' ) {
351 global $wp_query;
352 $pages = $wp_query->max_num_pages;
353 if (!$pages)
354 {
355 $pages = 1;
356 }
357 }
358
359 if( 1 != $pages ) {
360 $paginate ="<div class=\"eca-paginate\">";
361
362 if ($paged > 1) $paginate .= "<a class='prev' href='".get_pagenum_link($paged - 1)."'>".esc_html($prev)."</a>";
363 if ( get_previous_posts_link() ){
364 get_previous_posts_link('Prev');
365 }
366 for ( $i=1; $i <= $pages; $i++ ) {
367 if ( 1 != $pages && ( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ) ) {
368 $paginate .= ($paged == $i)? "<span class=\"current\">".esc_html($i)."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".esc_html($i)."</a>";
369 }
370 }
371 if ( get_next_posts_link() ) {
372 get_next_posts_link('Next',1);
373 }
374 if ( $paged < $pages ) $paginate .= "<a class='next' href='".get_pagenum_link($paged + 1)."'>".esc_html($next)."</a>";
375 $paginate .="</div>\n";
376 return $paginate;
377 }
378 }
379
380 public static function ecGetAcfFields( $type = 'text') {
381 $acfGet = [];
382 if( class_exists( 'ACF' )){
383 if ( function_exists( 'acf_get_field_groups' ) ) {
384 $acfField = acf_get_field_groups();
385 } else {
386 $acfField = apply_filters( 'acf/get_field_groups', [] );
387 }
388
389 foreach ( $acfField as $fieldGroup ) {
390 $key = $fieldGroup['key'];
391 $title = $fieldGroup['title'];
392 $ecAcfFields = [];
393 if ( function_exists( 'acf_get_fields' ) ) {
394 if ( isset( $fieldGroup['ID'] ) && ! empty( $fieldGroup['ID'] ) ) {
395 $fields = acf_get_fields( $fieldGroup['ID'] );
396 } else {
397 $fields = acf_get_fields( $fieldGroup );
398 }
399 } else {
400 $fields = apply_filters( 'acf/field_group/get_fields', [], $fieldGroup['id'] );
401 }
402
403 foreach( $fields as $acfField ) {
404 if ( !empty( $acfField['name'] ) && $acfField['type'] === $type) {
405 $ecAcfFields[$acfField['name']] = $acfField['label'];
406 }
407 }
408 $acfGet[] = [
409 'label' => $title,
410 'options' => $ecAcfFields
411 ];
412 }
413 }
414 return $acfGet;
415 }
416
417 public static function ecGetJetEngineFields( $type = 'text') {
418 $jetEngineGet = [];
419 if ( class_exists( 'Jet_Engine' ) ) {
420 $ecJetRaw = jet_engine()->meta_boxes->data->raw;
421 foreach ( $ecJetRaw as $field_group ) {
422 $ecJetEngineGroup = [];
423 foreach ( $field_group['meta_fields'] as $field ) {
424 if( !empty( $field['name'] ) && $field['type'] == $type){
425 $ecJetEngineGroup[$field['name']] = $field['title'];
426 }
427 }
428 if(!empty($ecJetEngineGroup)){
429 $jetEngineGet[] = [
430 'label' => $field_group['args']['name'],
431 'options' => $ecJetEngineGroup,
432 ];
433 }
434 }
435 }
436 return $jetEngineGet;
437 }
438
439 public static function ecGetMetaBoxFields( $type = 'text') {
440 $metaBoxGet = [];
441 if( class_exists( 'RWMB_Field' ) ){
442 $mbRegistry = (array) rwmb_get_registry( 'meta_box' )->all();
443 foreach($mbRegistry as $metaField){
444 $ecMetaFields = [];
445 $metaBox = (array) $metaField;
446 $metaTitle = $metaBox['meta_box']['title'];
447 $metaField = $metaBox['meta_box']['fields'];
448
449 foreach($metaField as $field){
450 if ( ! empty( $field['name'] ) && $field['type'] == $type) {
451 $ecMetaFields[$field['id']] = $field['name'];
452 }
453 }
454 $metaBoxGet[] = [
455 'label' => $metaTitle,
456 'options' => $ecMetaFields
457 ];
458 }
459 }
460
461 return $metaBoxGet;
462 }
463
464 public static function ecGetPodsFields( $type = 'text') {
465 $podsGet = [];
466 if(class_exists('PodsInit')){
467 $podsLoad = pods_api()->load_pods( [
468 'table_info' => true,
469 'fields' => true,
470 ]);
471 if (!empty($podsLoad)) {
472 foreach ( $podsLoad as $group ) {
473 $ecPodsField = [];
474 if (!empty($group['fields'])) {
475 foreach ( $group['fields'] as $field ) {
476 if( !empty( $field['name'] ) && $field['type'] == $type ){
477 $ecPodsField[$field['name']] = $field['label'];
478 }
479 }
480 }
481
482 if(!empty($ecPodsField)){
483 $podsGet[] = [
484 'label' => $group['label'],
485 'options' => $ecPodsField,
486 ];
487 }
488 }
489 }
490 }
491 return $podsGet;
492 }
493
494 public static function ecGetToolsetFields( $type = 'textfield') {
495 $toolsetGet = [];
496 if( defined('WPCF_VERSION') ) {
497 $groups = wpcf_admin_fields_get_groups();
498 foreach($groups AS $group){
499 $ecToolsetField = [];
500 if($group['slug'] !== 'toolset-woocommerce-fields'){
501 $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
502 $tooltitle = $group['name'];
503 foreach($fields as $key=>$value){
504 if ( ! empty( $value['name'] ) && $value['type'] == $type ) {
505 $ecToolsetField[$value['id']] = $value['name'];
506 }
507 }
508 }
509 if(!empty($ecToolsetField)){
510 $toolsetGet[] = [
511 'label' => $tooltitle,
512 'options' => $ecToolsetField
513 ];
514 }
515 }
516 }
517 return $toolsetGet;
518 }
519 }
520
521 EcafeHelper::instanceFetch();
522
523 function postsListingLoadMore() {
524 ob_start();
525 $settings = (!empty($_POST["settings"])) ? wp_unslash($_POST["settings"]) : '';
526 $settings = json_decode(str_replace ('\"','"', $settings));
527
528 $selectTaxonomy = isset( $settings->selectTaxonomy ) ? sanitize_text_field( wp_unslash($settings->selectTaxonomy) ) : '';
529 $style = isset( $settings->style ) ? sanitize_text_field( wp_unslash($settings->style) ) : '';
530 $showTitle = isset( $settings->showTitle ) ? wp_unslash($settings->showTitle) : '';
531 $titleTag = isset( $settings->titleTag ) ? wp_unslash($settings->titleTag) : '';
532 $titleLength = isset( $settings->titleLength ) ? wp_unslash($settings->titleLength) : '';
533 $showImage = isset( $settings->showImage ) ? wp_unslash($settings->showImage) : '';
534 $imageSize = isset( $settings->imageSize ) ? wp_unslash($settings->imageSize) : '';
535 $showExcerpt = isset( $settings->showExcerpt ) ? wp_unslash($settings->showExcerpt) : '';
536 $postExcerptLength = isset( $settings->postExcerptLength ) ? wp_unslash($settings->postExcerptLength) : '';
537 $showPostMeta = isset( $settings->showPostMeta ) ? wp_unslash($settings->showPostMeta) : '';
538 $postMetaStyle = isset( $settings->postMetaStyle ) ? wp_unslash($settings->postMetaStyle) : '';
539 $postDateMeta = isset( $settings->postDateMeta ) ? wp_unslash($settings->postDateMeta) : '';
540 $postUserMeta = isset( $settings->postUserMeta ) ? wp_unslash($settings->postUserMeta) : '';
541 $prefixTextPostUserMeta = isset( $settings->prefixTextPostUserMeta ) ? wp_unslash($settings->prefixTextPostUserMeta) : '';
542 $filterPost = isset( $settings->filterPost ) ? wp_unslash($settings->filterPost) : '';
543 $readMoreButton = isset( $settings->readMoreButton ) ? wp_unslash($settings->readMoreButton) : '';
544 $readButtonText = isset( $settings->readButtonText ) ? sanitize_text_field( wp_unslash($settings->readButtonText) ) : '';
545 $templateid = isset( $settings->templateid ) ? wp_unslash($settings->templateid) : '';
546 $selectPostType = isset( $settings->selectPostType ) ? sanitize_text_field( wp_unslash($settings->selectPostType) ) : '';
547 $loadMorePost = (isset( $settings->loadMorePost ) && intval($settings->loadMorePost) ) ? wp_unslash($settings->loadMorePost) : '';
548 $postCategory = isset( $settings->postCategory ) ? wp_unslash($settings->postCategory) : '';
549 $offset = (isset($settings->offset) && intval($settings->offset) ) ? wp_unslash( $settings->offset ) : '';
550 $postsOrderBy = isset( $settings->postsOrderBy ) ? sanitize_text_field( wp_unslash($settings->postsOrderBy) ) : '';
551 $postsOrder = isset( $settings->postsOrder ) ? sanitize_text_field( wp_unslash($settings->postsOrder) ) : '';
552
553 $itemClass = '';
554 $args = \EcafeHelper::getQueryArgs( (array) $settings, true );
555
556 $query = new WP_Query($args);
557
558 if ( $query->have_posts() ) {
559 while ($query->have_posts()) {
560 $query->the_post();
561 include ECAFE_PATH. "element/ajax-load/posts-listing.php";
562 }
563 }
564
565 wp_reset_postdata();
566 exit;
567 ob_end_clean();
568 }
569 add_action('wp_ajax_eca_load_more_posts', 'postsListingLoadMore' );
570 add_action('wp_ajax_nopriv_eca_load_more_posts', 'postsListingLoadMore' );