PluginProbe ʕ •ᴥ•ʔ
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools / 3.0.1
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools v3.0.1
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
class-helper.php 3 years ago class-loader.php 3 years ago class-panel-options.php 3 years ago widgets-passing-lists.php 3 years ago
class-helper.php
410 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 $query_args = [
260 'post_type' => $settings['selectPostType'],
261 'post_status' => 'publish',
262 'posts_per_page' => !empty($onLoad) ? $settings['loadMorePost'] : $settings['numberOfPosts'],
263 'orderby' => $settings['postsOrderBy'],
264 'order' => $settings['postsOrder'],
265 'offset' => !empty($onLoad) ? $settings['offset'] : $settings['postsOffset'],
266 'post__in' => $include_posts,
267 'post__not_in' => $exclude_posts,
268 'ignore_sticky_posts' => true,
269 ];
270
271 $query_args['tax_query'] = [];
272
273 $setting_key = '';
274 if( $settings['selectPostType'] != 'post' ){
275 $setting_key = ($settings['taxonomyInclude']) ? explode(',', $settings['taxonomyInclude']) : [];
276 }else if( $settings['selectTaxonomy'] == 'category' ){
277 $setting_key = ($settings['postCategory']) ? $settings['postCategory'] : [];
278 }else if( $settings['selectTaxonomy']=='post_tag' ){
279 $setting_key = ($settings['postTags']) ? $settings['postTags'] : [];
280 }
281
282 if (!empty($setting_key)) {
283 $query_args['tax_query'][] = [
284 'taxonomy' => $settings['selectTaxonomy'],
285 'field' => 'term_id',
286 'terms' => $setting_key,
287 ];
288 }
289
290 if (!empty($query_args['tax_query'])) {
291 $query_args['tax_query']['relation'] = 'AND';
292 }
293
294 // if (!empty($settings['postAuthors'])) {
295 // $query_args['author__in'] = $settings['postAuthors'];
296 // }
297
298 return $query_args;
299 }
300
301 public static function getPostExcerpt($limit) {
302 if(method_exists('WPBMap', 'addAllMappedShortcodes')) {
303 WPBMap::addAllMappedShortcodes();
304 }
305 global $post;
306 $excerpt = explode(' ', get_the_excerpt(), $limit);
307 if (count($excerpt)>=$limit) {
308 array_pop($excerpt);
309 $excerpt = implode(" ",$excerpt).'...';
310 } else {
311 $excerpt = implode(" ",$excerpt);
312 }
313 $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
314
315 return $excerpt;
316 }
317
318
319 /*
320 * Post Pagination
321 */
322 public static function post_pagination($pages = '', $range = 4, $next ='Next', $prev = 'Prev') {
323 $showitems = ($range * 2)+1;
324
325 global $paged; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
326 if(empty($paged)) $paged = 1;
327
328 if( $pages == '' ) {
329 global $wp_query;
330 $pages = $wp_query->max_num_pages;
331 if (!$pages)
332 {
333 $pages = 1;
334 }
335 }
336
337 if( 1 != $pages ) {
338 $paginate ="<div class=\"eca-paginate\">";
339
340 if ($paged > 1) $paginate .= "<a class='prev' href='".get_pagenum_link($paged - 1)."'>".esc_html($prev)."</a>";
341 if ( get_previous_posts_link() ){
342 get_previous_posts_link('Prev');
343 }
344 for ( $i=1; $i <= $pages; $i++ ) {
345 if ( 1 != $pages && ( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ) ) {
346 $paginate .= ($paged == $i)? "<span class=\"current\">".esc_html($i)."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".esc_html($i)."</a>";
347 }
348 }
349 if ( get_next_posts_link() ) {
350 get_next_posts_link('Next',1);
351 }
352 if ( $paged < $pages ) $paginate .= "<a class='next' href='".get_pagenum_link($paged + 1)."'>".esc_html($next)."</a>";
353 $paginate .="</div>\n";
354 return $paginate;
355 }
356 }
357 }
358
359 function EcafeHelper() {
360 return EcafeHelper::instanceFetch();
361 }
362
363 function postsListingLoadMore() {
364 ob_start();
365 $settings = (!empty($_POST["settings"])) ? wp_unslash($_POST["settings"]) : '';
366 $settings = json_decode(str_replace ('\"','"', $settings));
367
368 $selectTaxonomy = isset( $settings->selectTaxonomy ) ? sanitize_text_field( wp_unslash($settings->selectTaxonomy) ) : '';
369 $style = isset( $settings->style ) ? sanitize_text_field( wp_unslash($settings->style) ) : '';
370 $showTitle = isset( $settings->showTitle ) ? wp_unslash($settings->showTitle) : '';
371 $titleTag = isset( $settings->titleTag ) ? wp_unslash($settings->titleTag) : '';
372 $titleLength = isset( $settings->titleLength ) ? wp_unslash($settings->titleLength) : '';
373 $showImage = isset( $settings->showImage ) ? wp_unslash($settings->showImage) : '';
374 $imageSize = isset( $settings->imageSize ) ? wp_unslash($settings->imageSize) : '';
375 $showExcerpt = isset( $settings->showExcerpt ) ? wp_unslash($settings->showExcerpt) : '';
376 $postExcerptLength = isset( $settings->postExcerptLength ) ? wp_unslash($settings->postExcerptLength) : '';
377 $showPostMeta = isset( $settings->showPostMeta ) ? wp_unslash($settings->showPostMeta) : '';
378 $postMetaStyle = isset( $settings->postMetaStyle ) ? wp_unslash($settings->postMetaStyle) : '';
379 $postDateMeta = isset( $settings->postDateMeta ) ? wp_unslash($settings->postDateMeta) : '';
380 $postUserMeta = isset( $settings->postUserMeta ) ? wp_unslash($settings->postUserMeta) : '';
381 $prefixTextPostUserMeta = isset( $settings->prefixTextPostUserMeta ) ? wp_unslash($settings->prefixTextPostUserMeta) : '';
382 $filterPost = isset( $settings->filterPost ) ? wp_unslash($settings->filterPost) : '';
383 $readMoreButton = isset( $settings->readMoreButton ) ? wp_unslash($settings->readMoreButton) : '';
384 $readButtonText = isset( $settings->readButtonText ) ? sanitize_text_field( wp_unslash($settings->readButtonText) ) : '';
385 $templateid = isset( $settings->templateid ) ? wp_unslash($settings->templateid) : '';
386 $selectPostType = isset( $settings->selectPostType ) ? sanitize_text_field( wp_unslash($settings->selectPostType) ) : '';
387 $loadMorePost = (isset( $settings->loadMorePost ) && intval($settings->loadMorePost) ) ? wp_unslash($settings->loadMorePost) : '';
388 $postCategory = isset( $settings->postCategory ) ? wp_unslash($settings->postCategory) : '';
389 $offset = (isset($settings->offset) && intval($settings->offset) ) ? wp_unslash( $settings->offset ) : '';
390 $postsOrderBy = isset( $settings->postsOrderBy ) ? sanitize_text_field( wp_unslash($settings->postsOrderBy) ) : '';
391 $postsOrder = isset( $settings->postsOrder ) ? sanitize_text_field( wp_unslash($settings->postsOrder) ) : '';
392
393 $itemClass = '';
394 $args = \EcafeHelper::getQueryArgs( (array) $settings, true );
395
396 $query = new WP_Query($args);
397
398 if ( $query->have_posts() ) {
399 while ($query->have_posts()) {
400 $query->the_post();
401 include ECAFE_PATH. "element/ajax-load/posts-listing.php";
402 }
403 }
404
405 wp_reset_postdata();
406 exit;
407 ob_end_clean();
408 }
409 add_action('wp_ajax_eca_load_more_posts', 'postsListingLoadMore' );
410 add_action('wp_ajax_nopriv_eca_load_more_posts', 'postsListingLoadMore' );