PluginProbe ʕ •ᴥ•ʔ
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools / 1.0.4
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools v1.0.4
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 4 years ago class-loader.php 4 years ago class-panel-options.php 4 years ago widgets-passing-lists.php 4 years ago
class-helper.php
419 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='' ) {
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
113 return $style;
114 }
115
116 public static function getListLayout() {
117 return array(
118 'grid' => esc_html__( 'Grid', 'essential-classy-addons-for-elementor' ),
119 'masonry' => esc_html__( 'Masonry', 'essential-classy-addons-for-elementor' ),
120 );
121 }
122
123 public static function getResponsiveColumn() {
124 return array(
125 '100' => esc_html__( '1', 'essential-classy-addons-for-elementor' ),
126 '50' => esc_html__( '2', 'essential-classy-addons-for-elementor' ),
127 '33.3333' => esc_html__( '3', 'essential-classy-addons-for-elementor' ),
128 '25' => esc_html__( '4', 'essential-classy-addons-for-elementor' ),
129 '20' => esc_html__( '5', 'essential-classy-addons-for-elementor' ),
130 '16.666667' => esc_html__( '6', 'essential-classy-addons-for-elementor' ),
131 );
132 }
133
134 public static function getHtmlTag($linktag='') {
135 $tag = array(
136 'h1' => esc_html__('H1', 'essential-classy-addons-for-elementor'),
137 'h2' => esc_html__('H2', 'essential-classy-addons-for-elementor'),
138 'h3' => esc_html__('H3', 'essential-classy-addons-for-elementor'),
139 'h4' => esc_html__('H4', 'essential-classy-addons-for-elementor'),
140 'h5' => esc_html__('H5', 'essential-classy-addons-for-elementor'),
141 'h6' => esc_html__('H6', 'essential-classy-addons-for-elementor'),
142 'span' => esc_html__('Span', 'essential-classy-addons-for-elementor'),
143 'p' => esc_html__('P', 'essential-classy-addons-for-elementor'),
144 'div' => esc_html__('Div', 'essential-classy-addons-for-elementor'),
145 );
146 if(!empty($linktag)){
147 $tag['a'] = esc_html__( 'a', 'essential-classy-addons-for-elementor' );
148 }
149 return $tag;
150 }
151
152 /* get Post Tyles List*/
153 public static function getPostTypes() {
154 $options = [];
155 $postTypes = get_post_types( [ 'public' => true, 'show_ui' => true ], 'objects' );
156
157 $exclude = [ 'attachment', 'elementor_library' ];
158
159 foreach ( $postTypes as $postType ) {
160
161 if( TRUE === in_array( $postType->name, $exclude ) )
162 continue;
163
164 $options[$postType->name] = $postType->label;
165 }
166
167 return $options;
168 }
169
170 /* get Taxonomy List*/
171 public static function getTaxonomiesList() {
172 $options = [];
173 $output = 'objects'; // or names
174 $operator = 'and'; // 'and' or 'or'
175
176 $taxonomies = get_taxonomies( [ 'public' => true, 'show_ui' => true ], $output, $operator );
177 if ( $taxonomies ) {
178 foreach ( $taxonomies as $taxonomy ) {
179 $options[$taxonomy->name] = $taxonomy->label;
180 }
181 return $options;
182 }
183 }
184
185 /* Get Post Categories */
186 public static function getTermsList($taxonomy = 'category', $key = 'term_id') {
187 $options = [];
188 $terms = get_terms([ 'taxonomy' => $taxonomy, 'hide_empty' => true ]);
189
190 if (!empty($terms) && !is_wp_error($terms)) {
191 foreach ($terms as $term) {
192 $options[$term->{$key}] = $term->name;
193 }
194 }
195
196 return $options;
197 }
198
199 /* Get all Authors*/
200 // public static function getAuthorsList() {
201 // $users = get_users([
202 // 'capability' => 'authors',
203 // 'has_published_posts' => true,
204 // 'fields' => [
205 // 'ID',
206 // 'display_name',
207 // ],
208 // ]);
209
210 // if (!empty($users)) {
211 // return wp_list_pluck($users, 'display_name', 'ID');
212 // }
213
214 // return [];
215 // }
216
217 public static function getOrderByArray() {
218 $options = array(
219 'none' => esc_html__( 'None', 'essential-classy-addons-for-elementor' ),
220 'menu_order' => esc_html__( 'Default', 'essential-classy-addons-for-elementor' ),
221 'ID' => esc_html__( 'ID', 'essential-classy-addons-for-elementor' ),
222 'author' => esc_html__( 'Author', 'essential-classy-addons-for-elementor' ),
223 'title' => esc_html__( 'Title', 'essential-classy-addons-for-elementor' ),
224 'name' => esc_html__( 'Name (slug)', 'essential-classy-addons-for-elementor' ),
225 'date' => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
226 'modified' => esc_html__( 'Modified', 'essential-classy-addons-for-elementor' ),
227 'rand' => esc_html__( 'Random', 'essential-classy-addons-for-elementor' ),
228 'parent' => esc_html__( 'Parent Id', 'essential-classy-addons-for-elementor' ),
229 'comment_count' => esc_html__( 'Comment Count', 'essential-classy-addons-for-elementor' ),
230 );
231 ksort($options);
232 return $options;
233 }
234 public static function getOrderArray() {
235 return array(
236 'ASC' => esc_html__( 'Ascending', 'essential-classy-addons-for-elementor' ),
237 'DESC' => esc_html__( 'Descending', 'essential-classy-addons-for-elementor' ),
238 );
239 }
240
241 public static function getLoadingOptions() {
242 return array(
243 'none' => esc_html__( 'Select Options', 'essential-classy-addons-for-elementor' ),
244 'pagination' => esc_html__( 'Pagination', 'essential-classy-addons-for-elementor' ),
245 'load_more' => esc_html__( 'Load More', 'essential-classy-addons-for-elementor' ),
246 'lazy_load' => esc_html__( 'Lazy Load', 'essential-classy-addons-for-elementor' ),
247 );
248 }
249
250 public static function getQueryArgs( $settings =[]){
251
252 $include_posts = ($settings['postsInclude']) ? explode(',', $settings['postsInclude']) : [];
253 $exclude_posts = ($settings['postsExclude']) ? explode(',', $settings['postsExclude']) : [];
254
255 $query_args = [
256 'post_type' => $settings['selectPostType'],
257 'post_status' => 'publish',
258 'posts_per_page' => $settings['numberOfPosts'],
259 'orderby' => $settings['postsOrderBy'],
260 'order' => $settings['postsOrder'],
261 'offset' => $settings['postsOffset'],
262 'post__in' => $include_posts,
263 'post__not_in' => $exclude_posts,
264 'ignore_sticky_posts' => true,
265 ];
266
267 if(!empty($settings['selectPostType']) && $settings['selectPostType']=='post'){
268 $query_args['tax_query'] = [];
269
270 $taxonomies = get_object_taxonomies($settings['selectPostType'], 'objects');
271
272 foreach ($taxonomies as $object) {
273 $setting_key = '';
274 if($settings['selectPostType'] != 'post' && $object->name!='category' && $object->name != 'post_tag'){
275 $setting_key = ($settings['taxonomyInclude']) ? explode(',', $settings['taxonomyInclude']) : [];
276 }else if( $object->name == 'category' ){
277 $setting_key = ($settings['postCategory']) ? $settings['postCategory'] : [];
278 }else if( $object->name=='post_tag' ){
279 $setting_key = ($settings['postTags']) ? $settings['postTags'] : [];
280 }
281
282 if (!empty($setting_key)) {
283 $query_args['tax_query'][] = [
284 'taxonomy' => $object->name,
285 'field' => 'term_id',
286 'terms' => $setting_key,
287 ];
288 }
289 }
290
291 if (!empty($query_args['tax_query'])) {
292 $query_args['tax_query']['relation'] = 'AND';
293 }
294 }
295
296 // if (!empty($settings['postAuthors'])) {
297 // $query_args['author__in'] = $settings['postAuthors'];
298 // }
299
300 return $query_args;
301 }
302
303 public static function getPostExcerpt($limit) {
304 if(method_exists('WPBMap', 'addAllMappedShortcodes')) {
305 WPBMap::addAllMappedShortcodes();
306 }
307 global $post;
308 $excerpt = explode(' ', get_the_excerpt(), $limit);
309 if (count($excerpt)>=$limit) {
310 array_pop($excerpt);
311 $excerpt = implode(" ",$excerpt).'...';
312 } else {
313 $excerpt = implode(" ",$excerpt);
314 }
315 $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
316
317 return $excerpt;
318 }
319
320
321 /*
322 * Post Pagination
323 */
324 public static function post_pagination($pages = '', $range = 4, $next ='Next', $prev = 'Prev') {
325 $showitems = ($range * 2)+1;
326
327 global $paged; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
328 if(empty($paged)) $paged = 1;
329
330 if( $pages == '' ) {
331 global $wp_query;
332 $pages = $wp_query->max_num_pages;
333 if (!$pages)
334 {
335 $pages = 1;
336 }
337 }
338
339 if( 1 != $pages ) {
340 $paginate ="<div class=\"eca-paginate\">";
341
342 if ($paged > 1) $paginate .= "<a class='prev' href='".get_pagenum_link($paged - 1)."'>".esc_html($prev)."</a>";
343 if ( get_previous_posts_link() ){
344 get_previous_posts_link('Prev');
345 }
346 for ( $i=1; $i <= $pages; $i++ ) {
347 if ( 1 != $pages && ( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ) ) {
348 $paginate .= ($paged == $i)? "<span class=\"current\">".esc_html($i)."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".esc_html($i)."</a>";
349 }
350 }
351 if ( get_next_posts_link() ) {
352 get_next_posts_link('Next',1);
353 }
354 if ( $paged < $pages ) $paginate .= "<a class='next' href='".get_pagenum_link($paged + 1)."'>".esc_html($next)."</a>";
355 $paginate .="</div>\n";
356 return $paginate;
357 }
358 }
359 }
360 function EcafeHelper() {
361 return EcafeHelper::instanceFetch();
362 }
363 function posts_listing_load_more() {
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 $selectPostType = isset( $settings->selectPostType ) ? sanitize_text_field( wp_unslash($settings->selectPostType) ) : '';
386 $loadMorePost = (isset( $settings->loadMorePost ) && intval($settings->loadMorePost) ) ? wp_unslash($settings->loadMorePost) : '';
387 $postCategory = isset( $settings->postCategory ) ? wp_unslash($settings->postCategory) : '';
388 $offset = (isset($settings->offset) && intval($settings->offset) ) ? wp_unslash( $settings->offset ) : '';
389 $postsOrderBy = isset( $settings->postsOrderBy ) ? sanitize_text_field( wp_unslash($settings->postsOrderBy) ) : '';
390 $postsOrder = isset( $settings->postsOrder ) ? sanitize_text_field( wp_unslash($settings->postsOrder) ) : '';
391
392 $itemClass = '';
393
394 $args = array(
395 'post_type' => $selectPostType,
396 'posts_per_page' => $loadMorePost,
397 $selectTaxonomy => $postCategory,
398 'offset' => $offset,
399 'orderby' => $postsOrderBy,
400 'post_status' => 'publish',
401 'order' => $postsOrder
402 );
403
404 $query = new WP_Query($args);
405
406 if ( $query->have_posts() ) {
407 while ($query->have_posts()) {
408 $query->the_post();
409 include ECAFE_PATH. "element/ajax-load/posts-listing.php";
410 }
411 }
412
413 wp_reset_postdata();
414 exit;
415 ob_end_clean();
416 }
417
418 add_action('wp_ajax_eca_load_more_posts', 'posts_listing_load_more' );
419 add_action('wp_ajax_nopriv_eca_load_more_posts', 'posts_listing_load_more' );