PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.6.4
Post Grid Gutenberg Blocks – PostX v2.6.4
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Functions.php

Functions.php in Post Grid Gutenberg Blocks – PostX 2.6.4, at classes/Functions.php

1,362 lines 53.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common Functions.
4 *
5 * @package ULTP\Functions
6 * @since v.1.0.0
7 */
8 namespace ULTP;
9
10 defined('ABSPATH') || exit;
11
12 /**
13 * Functions class.
14 */
15
16 class Functions{
17
18 /**
19 * Setup class.
20 *
21 * @since v.1.0.0
22 */
23 public function __construct() {
24 if (!isset($GLOBALS['ultp_settings'])) {
25 $GLOBALS['ultp_settings'] = get_option('ultp_options');
26 }
27 }
28
29 /**
30 * ID for the Builder Post or Normal Post
31 *
32 * @since v.2.3.1
33 * @return NUMBER | is Builder or not
34 */
35 public function get_ID() {
36 $id = $this->is_builder();
37 return $id ? $id : (function_exists('is_shop') ? (is_shop() ? wc_get_page_id('shop') : get_the_ID()) : get_the_ID() );
38 }
39
40 /**
41 * Checking Statement of Archive Builder
42 *
43 * @since v.2.3.1
44 * @return BOOLEAN | is Builder or not
45 */
46 public function is_archive_builder() {
47 return get_post_type( get_the_ID() ) == 'ultp_builder' ? true : false;
48 }
49
50
51 /**
52 * Set Link with the Parameters
53 *
54 * @since v.1.1.0
55 * @return STRING | URL with Arg
56 */
57 public function get_premium_link( $url = '', $tag = 'go_premium' ) {
58 $url = $url ? $url : 'https://www.wpxpo.com/postx/pricing/';
59 $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
60 $arg = array( 'utm_source' => $tag );
61 if ( ! empty( $affiliate_id ) ) {
62 $arg[ 'ref' ] = esc_attr( $affiliate_id );
63 }
64 return add_query_arg( $arg, $url );
65 }
66
67
68 /**
69 * Get Width and Height of the Image
70 *
71 * @since v.1.1.0
72 * @return STRING | Image Size
73 */
74 public function get_size($name = ''){
75 global $_wp_additional_image_sizes;
76 $image_size = $name ? ( isset($_wp_additional_image_sizes[$name]) ? $_wp_additional_image_sizes[$name] : array_values($_wp_additional_image_sizes)[0] ) : array_values($_wp_additional_image_sizes)[0];
77
78 return ' width="'.$image_size['width'].'" height="'.$image_size['height'].'" ';
79 }
80
81
82 /**
83 * Image Placeholder
84 *
85 * @since v.1.1.0
86 * @return STRING | Image Placeholder
87 */
88 public function img_placeholder($type = 'small') {
89 switch ($type) {
90 case 'small':
91 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAABLAQMAAACr9CA9AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABZJREFUOI1jYMADmEe5o9xR7iiXQi4A4BsA388WUyMAAAAASUVORK5CYII=';
92 break;
93
94 case 'wide':
95 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAKCAYAAADVTVykAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB9JREFUeNpi/P//P8NAAiaGAQajDhh1wKgDRh0AEGAAQTcDEcKDrpMAAAAASUVORK5CYII=';
96 break;
97
98 case 'square':
99 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAApJREFUCJljYAAAAAIAAfRxZKYAAAAASUVORK5CYII=';
100 break;
101
102 case 'slider':
103 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAABkCAMAAAA7drv6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////AAAAVcLTfgAAAAF0Uk5TAEDm2GYAAAAqSURBVHja7MEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAH5NgAEAQTwAAWZtItYAAAAASUVORK5CYII=';
104 break;
105
106 default:
107 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYYAAADcAQMAAABOLJSDAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAACJJREFUaIHtwTEBAAAAwqD1T20ND6AAAAAAAAAAAAAA4N8AKvgAAUFIrrEAAAAASUVORK5CYII=';
108 break;
109 }
110 }
111
112
113 /**
114 * Quick Query
115 *
116 * @since v.1.1.0
117 * @return ARRAY | Query Arg
118 */
119 public function get_quick_query($prams, $args) {
120 switch ($prams['queryQuick']) {
121 case 'related_posts':
122 global $post;
123 if (isset($post->ID)) {
124 $args['post__not_in'] = array($post->ID);
125 }
126 break;
127 case 'related_tag':
128 global $post;
129 if (isset($post->ID)) {
130 $args['tax_query'] = array(
131 array(
132 'taxonomy' => 'post_tag',
133 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
134 'field' => 'term_id',
135 )
136 );
137 $args['post__not_in'] = array($post->ID);
138 }
139 break;
140 case 'related_category':
141 global $post;
142 if (isset($post->ID)) {
143 $args['tax_query'] = array(
144 array(
145 'taxonomy' => 'category',
146 'terms' => $this->get_terms_id($post->ID, 'category'),
147 'field' => 'term_id',
148 )
149 );
150 $args['post__not_in'] = array($post->ID);
151 }
152 break;
153 case 'related_cat_tag':
154 global $post;
155 if (isset($post->ID)) {
156 $args['tax_query'] = array(
157 array(
158 'taxonomy' => 'post_tag',
159 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
160 'field' => 'term_id',
161 ),
162 array(
163 'taxonomy' => 'category',
164 'terms' => $this->get_terms_id($post->ID, 'category'),
165 'field' => 'term_id',
166 )
167 );
168 $args['post__not_in'] = array($post->ID);
169 }
170 break;
171 case 'sticky_posts':
172 $sticky = get_option('sticky_posts');
173 if (is_array($sticky)) {
174 rsort($sticky);
175 $sticky = array_slice($sticky, 0, $args['posts_per_page']);
176 }
177 $args['ignore_sticky_posts'] = 1;
178 $args['post__in'] = $sticky;
179 break;
180 case 'latest_post_published':
181 $args['orderby'] = 'date';
182 $args['order'] = 'DESC';
183 $args['ignore_sticky_posts'] = 1;
184 break;
185 case 'latest_post_modified':
186 $args['orderby'] = 'modified';
187 $args['order'] = 'DESC';
188 $args['ignore_sticky_posts'] = 1;
189 break;
190 case 'oldest_post_published':
191 $args['orderby'] = 'date';
192 $args['order'] = 'ASC';
193 break;
194 case 'oldest_post_modified':
195 $args['orderby'] = 'modified';
196 $args['order'] = 'ASC';
197 break;
198 case 'alphabet_asc':
199 $args['orderby'] = 'title';
200 $args['order'] = 'ASC';
201 break;
202 case 'alphabet_desc':
203 $args['orderby'] = 'title';
204 $args['order'] = 'DESC';
205 break;
206 case 'random_post':
207 $args['orderby'] = 'rand';
208 $args['order'] = 'ASC';
209 break;
210 case 'random_post_7_days':
211 $args['orderby'] = 'rand';
212 $args['order'] = 'ASC';
213 $args['date_query'] = array( array( 'after' => '1 week ago') );
214 break;
215 case 'random_post_30_days':
216 $args['orderby'] = 'rand';
217 $args['order'] = 'ASC';
218 $args['date_query'] = array( array( 'after' => '1 month ago') );
219 break;
220 case 'most_comment':
221 $args['orderby'] = 'comment_count';
222 $args['order'] = 'DESC';
223 break;
224 case 'most_comment_1_day':
225 $args['orderby'] = 'comment_count';
226 $args['order'] = 'DESC';
227 $args['date_query'] = array( array( 'after' => '1 day ago') );
228 break;
229 case 'most_comment_7_days':
230 $args['orderby'] = 'comment_count';
231 $args['order'] = 'DESC';
232 $args['date_query'] = array( array( 'after' => '1 week ago') );
233 break;
234 case 'most_comment_30_days':
235 $args['orderby'] = 'comment_count';
236 $args['order'] = 'DESC';
237 $args['date_query'] = array( array( 'after' => '1 month ago') );
238 break;
239 case 'popular_post_1_day_view':
240 $args['meta_key'] = '__post_views_count';
241 $args['orderby'] = 'meta_value meta_value_num';
242 $args['order'] = 'DESC';
243 $args['date_query'] = array( array( 'after' => '1 day ago') );
244 break;
245 case 'popular_post_7_days_view':
246 $args['meta_key'] = '__post_views_count';
247 $args['orderby'] = 'meta_value meta_value_num';
248 $args['order'] = 'DESC';
249 $args['date_query'] = array( array( 'after' => '1 week ago') );
250 break;
251 case 'popular_post_30_days_view':
252 $args['meta_key'] = '__post_views_count';
253 $args['orderby'] = 'meta_value meta_value_num';
254 $args['order'] = 'DESC';
255 $args['date_query'] = array( array( 'after' => '1 month ago') );
256 break;
257 case 'popular_post_all_times_view':
258 $args['meta_key'] = '__post_views_count';
259 $args['orderby'] = 'meta_value meta_value_num';
260 $args['order'] = 'DESC';
261 break;
262 default:
263 # code...
264 break;
265 }
266 return $args;
267 }
268
269 /**
270 * Get All Term ID as Array
271 *
272 * @since v.2.4.12
273 * @return ARRAY | Query Arg
274 */
275 public function get_terms_id($id, $type) {
276 $data = array();
277 $arr = get_the_terms($id, $type);
278 if (is_array($arr)) {
279 foreach ($arr as $key => $val) {
280 $data[] = $val->term_id;
281 }
282 }
283 return $data;
284 }
285
286 /**
287 * Get All Reusable ID
288 *
289 * @since v.1.1.0
290 * @return ARRAY | Query Arg
291 */
292 public function reusable_id($post_id){
293 $reusable_id = array();
294 if($post_id){
295 $post = get_post($post_id);
296 if (has_blocks($post->post_content)) {
297 $blocks = parse_blocks($post->post_content);
298 foreach ($blocks as $key => $value) {
299 if(isset($value['attrs']['ref'])) {
300 $reusable_id[] = $value['attrs']['ref'];
301 }
302 }
303 }
304 }
305 return $reusable_id;
306 }
307
308
309 /**
310 * Set CSS Style
311 *
312 * @since v.1.1.0
313 * @return ARRAY | Query Arg
314 */
315 public function set_css_style($post_id, $shortcode = false){
316 if( $post_id ){
317 $upload_dir_url = wp_get_upload_dir();
318 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
319 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
320
321 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
322 if (is_ssl()) {
323 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
324 }
325
326 // Reusable CSS
327 $reusable_id = ultimate_post()->reusable_id($post_id);
328 foreach ( $reusable_id as $id ) {
329 $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
330 if (file_exists( $reusable_dir_path )) {
331 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
332 wp_enqueue_style( "ultp-post-{$id}", $css_url, array(), ultimate_post()->get_setting('save_version'), 'all' );
333 }else{
334 $css = get_post_meta($id, '_ultp_css', true);
335 if( $css ) {
336 wp_enqueue_style("ultp-post-{$id}", $css, false, ultimate_post()->get_setting('save_version'));
337 }
338 }
339 }
340
341 if (isset($_GET['et_fb']) || (isset($_GET['action']) && sanitize_key($_GET['action']) == 'elementor') || $shortcode) {
342 return ultimate_post()->set_inline(get_post_meta($post_id, '_ultp_css', true));
343 } else {
344 if ( file_exists( $css_dir_path ) ) {
345 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
346 wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ultimate_post()->get_setting('save_version'), 'all' );
347 } else {
348 $css = get_post_meta($post_id, '_ultp_css', true);
349 if( $css ) {
350 wp_enqueue_style("ultp-post-{$post_id}", $css, false, ultimate_post()->get_setting('save_version'));
351 }
352 }
353 }
354 }
355 }
356
357
358 /**
359 * Get Global Plugin Settings
360 *
361 * @since v.1.0.0
362 * @param STRING | Key of the Option
363 * @return ARRAY | STRING
364 */
365 public function get_setting($key = ''){
366 $data = $GLOBALS['ultp_settings'];
367 if ($key != '') {
368 return isset($data[$key]) ? $data[$key] : '';
369 } else {
370 return $data;
371 }
372 }
373
374
375 /**
376 * Set Option Settings
377 *
378 * @since v.1.0.0
379 * @param STRING | Key of the Option (STRING), Value (STRING)
380 * @return NULL
381 */
382 public function set_setting($key = '', $val = '') {
383 if($key != ''){
384 $data = $GLOBALS['ultp_settings'];
385 $data[$key] = $val;
386 update_option('ultp_options', $data);
387 $GLOBALS['ultp_settings'] = $data;
388 }
389 }
390
391
392 /**
393 * Get Image HTML
394 *
395 * @since v.1.0.0
396 * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
397 * @return STRING
398 */
399 public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = ''){
400 $alt = $alt ? ' alt="'.$alt.'" ' : '';
401 $lazy_data = $lazy ? ' loading="lazy"' : '';
402 $class = $class ? ' class="'.$class.'" ' : '';
403 return '<img '.$lazy_data.$class.$alt.' src="'.$url.'" />';
404 }
405
406
407 /**
408 * Get Image HTML
409 *
410 * @since v.1.0.0
411 * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
412 * @return STRING
413 */
414 public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = ''){
415 $alt = $alt ? ' alt="'.$alt.'" ' : '';
416 $class = $class ? ' class="'.$class.'" ' : '';
417 $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
418 $lazy_data = $lazy ? ' loading="lazy"' : '';
419 $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
420 return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
421 }
422
423
424 /**
425 * Setup Initial Data Set
426 *
427 * @since v.1.0.0
428 * @return NULL
429 */
430 public function init_set_data(){
431 $data = get_option( 'ultp_options', array() );
432 $init_data = array(
433 'css_save_as' => 'wp_head',
434 'preloader_style' => 'style1',
435 'preloader_color' => '#037fff',
436 'container_width' => '1140',
437 'hide_import_btn' => '',
438 'disable_image_size'=> '',
439 'disable_view_cookies' => '',
440 'ultp_templates' => 'true',
441 'ultp_elementor' => 'true',
442 'ultp_table_of_content'=> 'true',
443 'post_grid_1' => 'yes',
444 'post_grid_2' => 'yes',
445 'post_grid_3' => 'yes',
446 'post_grid_4' => 'yes',
447 'post_grid_5' => 'yes',
448 'post_grid_6' => 'yes',
449 'post_grid_7' => 'yes',
450 'post_list_1' => 'yes',
451 'post_list_2' => 'yes',
452 'post_list_3' => 'yes',
453 'post_list_4' => 'yes',
454 'post_module_1' => 'yes',
455 'post_module_2' => 'yes',
456 'post_slider_1' => 'yes',
457 'heading' => 'yes',
458 'image' => 'yes',
459 'taxonomy' => 'yes',
460 'wrapper' => 'yes',
461 'news_ticker' => 'yes',
462 'archive_title' => 'yes',
463 'save_version' => rand(1, 1000)
464 );
465 if (empty($data)) {
466 update_option('ultp_options', $init_data);
467 $GLOBALS['ultp_settings'] = $init_data;
468 } else {
469 foreach ($init_data as $key => $single) {
470 if (!isset($data[$key])) {
471 $data[$key] = $single;
472 }
473 }
474 update_option('ultp_options', $data);
475 $GLOBALS['ultp_settings'] = $data;
476 }
477 }
478
479
480 /**
481 * Get Excerpt Text
482 *
483 * @since v.1.0.0
484 * @param | Post ID (STRING) | Limit (NUMBER)
485 * @return STRING
486 */
487 public function excerpt( $post_id, $limit = 55 ) {
488 return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
489 }
490
491 public function get_builder_attr() {
492 $builder_data = '';
493 if (is_archive()) {
494 if (is_date()) {
495 if ( is_year() ) {
496 $builder_data = 'date###'.get_the_date('Y');
497 } else if ( is_month() ) {
498 $builder_data = 'date###'.get_the_date('Y-n');
499 } else if ( is_day() ) {
500 $builder_data = 'date###'.get_the_date('Y-n-j');
501 }
502 } else if (is_author()) {
503 $builder_data = 'author###'.get_the_author_meta('ID');
504 } else {
505 $obj = get_queried_object();
506 if (isset($obj->taxonomy)) {
507 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
508 }
509 }
510 } else if (is_search()) {
511 $builder_data = 'search###'.get_search_query(true);
512 }
513 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
514 }
515
516
517 public function is_builder($builder = '') {
518 $id = '';
519 if (function_exists('ultimate_post_pro')) {
520 if ($builder) {
521 return true;
522 }
523 $page_id = ultimate_post_pro()->conditions('return');
524 if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
525 $id = $page_id;
526 }
527 }
528 return $id;
529 }
530
531
532 /**
533 * Get Post Number Depending On Device
534 *
535 * @since v.2.5.4
536 * @param MULTIPLE | Attribute of Posts
537 * @return STRING
538 */
539 public function get_post_number($preDef, $prev, $current) {
540
541 $current = is_object($current)?json_decode(json_encode($current), true):$current;
542 if (['lg'=>$preDef,'sm'=>$preDef,'xs'=>$preDef] == $current) {
543 if ($preDef != $prev) {
544 return $prev;
545 }
546 }
547 if ($this->isDevice() == 'mobile') {
548 return $current['xs'];
549 } else if ($this->isDevice() == 'tablet') {
550 return $current['sm'];
551 } else {
552 return $current['lg'];
553 }
554 }
555
556
557 /**
558 * Get Post Number Depending On Device
559 *
560 * @since v.2.5.4
561 * @param NULL
562 * @return STRING | Device Type
563 */
564 public function isDevice(){
565 $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_key($_SERVER['HTTP_USER_AGENT']) : '';
566 if ($useragent) {
567 if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) {
568 return 'mobile';
569 } else if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent))) {
570 return 'tablet';
571 } else {
572 return 'desktop';
573 }
574 }
575 return 'desktop';
576 }
577
578
579 /**
580 * Get Raw Value from Objects
581 *
582 * @since v.2.5.3
583 * @param NULL
584 * @return STRING | Device Type
585 */
586 public function get_value($attr) {
587 $data = [];
588 if (is_array($attr)) {
589 foreach ($attr as $val) {
590 $data[] = $val->value;
591 }
592 }
593 return $data;
594 }
595
596
597 /**
598 * Query Builder
599 *
600 * @since v.1.0.0
601 * @param ARRAY | Attribute of the Query
602 * @return ARRAY
603 */
604 public function get_query($attr) {
605 $builder = isset($attr['builder']) ? $attr['builder'] : '';
606 if ($this->is_builder($builder)) {
607 $archive_query = array();
608 if ($builder) {
609 $str = explode('###', $builder);
610 if (isset($str[0])) {
611 if ($str[0] == 'taxonomy') {
612 if (isset($str[1]) && isset($str[2])) {
613 $archive_query['tax_query'] = array(
614 array(
615 'taxonomy' => $str[1],
616 'field' => 'slug',
617 'terms' => $str[2]
618 )
619 );
620 }
621 } else if ($str[0] == 'author') {
622 if (isset($str[1])) {
623 $archive_query['author'] = $str[1];
624 }
625 } else if ($str[0] == 'search') {
626 if (isset($str[1])) {
627 $archive_query['s'] = $str[1];
628 }
629 } else if ($str[0] == 'date') {
630 if (isset($str[1])) {
631 $all_date = explode('-', $str[1]);
632 if (!empty($all_date)) {
633 $arg = array();
634 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
635 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
636 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
637 $archive_query['date_query'][] = $arg;
638 }
639 }
640 }
641 }
642 } else {
643 global $wp_query;
644 $archive_query = $wp_query->query_vars;
645 }
646 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
647 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
648 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
649 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
650 $archive_query = array_merge($archive_query, $offset);
651 }
652
653 // Include Remove from Version 2.5.4
654 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
655 $_include = explode(',', $attr['queryInclude']);
656 if (is_array($_include) && count($_include)) {
657 $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
658 $archive_query['ignore_sticky_posts'] = 1;
659 $archive_query['orderby'] = 'post__in';
660 }
661 }
662
663 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
664 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
665 if (is_array($_exclude) && count($_exclude)) {
666 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $_exclude) : $_exclude;
667 }
668 }
669
670
671 if(isset($attr['querySticky']) && $attr['querySticky']) {
672 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
673 $sticky = get_option( 'sticky_posts', [] );
674 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $sticky) : $sticky;
675 }
676 }
677
678 $archive_query['post_status'] = 'publish';
679
680 if(!isset($archive_query['orderby'])) {
681 $archive_query['orderby'] = isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date';
682 }
683
684 // Quick Query Support for Builder
685 if (isset($attr['queryQuick'])) {
686 if ($attr['queryQuick'] != '') {
687 $archive_query = ultimate_post()->get_quick_query($attr, $archive_query);
688 }
689 }
690
691 if (!isset($attr['ajaxCall'])) {
692 if(isset($attr['filterShow']) && $attr['filterShow']) {
693 if(isset($attr['filterType']) && isset($attr['filterValue'])) {
694 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
695 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
696 if (count($filterValue) > 0 && $attr['filterType']) {
697 $final = array('relation' => 'OR');
698 foreach ($filterValue as $key => $val) {
699 $final[] = array(
700 'taxonomy' => $attr['filterType'],
701 'field' => 'slug',
702 'terms' => $val,
703 );
704 }
705 $archive_query['tax_query'] = $final;
706 }
707 }
708 }
709 }
710
711 return apply_filters('ultp_archive_query', $archive_query);
712 }
713
714 $query_args = array(
715 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
716 'post_type' => isset($attr['queryType']) ? $attr['queryType'] : 'post',
717 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
718 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
719 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
720 'post_status' => 'publish'
721 );
722
723
724 if ($attr['queryType'] == 'posts') {
725 if (isset($attr['queryPosts']) && $attr['queryPosts']) {
726 unset($query_args['post_type']);
727 $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
728 $final = $this->get_value($data);
729 if (count($final) > 0) {
730 $query_args['post__in'] = $final;
731 $query_args['posts_per_page'] = -1;
732 }
733 $query_args['ignore_sticky_posts'] = 1;
734 return $query_args;
735 }
736 } else if ($attr['queryType'] == 'customPosts') {
737 if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
738 $query_args['post_type'] = $this->get_post_type();
739 $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
740 $final = $this->get_value($data);
741 if (count($final) > 0) {
742 $query_args['post__in'] = $final;
743 $query_args['posts_per_page'] = -1;
744 }
745 $query_args['ignore_sticky_posts'] = 1;
746 return $query_args;
747 }
748 }
749
750 if(isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']){
751 $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
752 $final = $this->get_value($data);
753 if (count($final) > 0) {
754 $query_args['author__not_in'] = $final;
755 }
756 }
757
758
759 if(isset($attr['queryOrderBy']) && isset($attr['metaKey'])){
760 if($attr['queryOrderBy'] == 'meta_value_num') {
761 $query_args['meta_key'] = $attr['metaKey'];
762 }
763 }
764
765 // Include Remove from Version 2.5.4
766 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
767 $_include = explode(',', $attr['queryInclude']);
768 if (is_array($_include) && count($_include)) {
769 $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
770 $query_args['ignore_sticky_posts'] = 1;
771 $query_args['orderby'] = 'post__in';
772 }
773 }
774
775
776 if(isset($attr['queryTax'])){
777 if(isset($attr['queryTaxValue'])){
778 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
779 $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
780
781 $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
782
783 if(count($tax_value) > 0){
784 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
785 $var = array('relation'=>$relation);
786 foreach ($tax_value as $val) {
787 $tax_name = $attr['queryTax'];
788 // For Custom Terms
789 if ($attr['queryTax'] == 'multiTaxonomy') {
790 $temp = explode('###', $val);
791 if (isset($temp[1])) {
792 $val = $temp[1];
793 $tax_name = $temp[0];
794 }
795 }
796
797 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
798 }
799 if(count($var) > 1){
800 $query_args['tax_query'] = $var;
801 }
802 }
803 }
804 }
805
806
807 if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
808 $temp = json_decode($attr['queryExcludeTerm']);
809 $_term = [];
810 foreach ($temp as $val) {
811 $temp = explode('###', $val->value);
812 if (isset($temp[1])) {
813 if (array_key_exists($temp[0], $_term)) {
814 $_term[$temp[0]][] = $temp[1];
815 } else {
816 $_term[$temp[0]] = array($temp[1]);
817 }
818 }
819 }
820 if (count($_term) > 0) {
821 $final = array('relation' => 'AND');
822 foreach ($_term as $key => $val) {
823 $final[] = array(
824 'taxonomy' => $key,
825 'field' => 'slug',
826 'terms' => $val,
827 'operator' => 'NOT IN',
828 );
829 }
830
831 if (array_key_exists('tax_query', $query_args)) {
832 $query_args['tax_query'] = array(
833 'relation' => 'AND',
834 $query_args['tax_query']
835 );
836 $query_args['tax_query'][] = $final;
837 } else {
838 $query_args['tax_query'] = $final;
839 }
840 }
841 }
842
843 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
844 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
845 if (is_array($_exclude) && count($_exclude)) {
846 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
847 }
848 }
849
850 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
851 global $unique_ID;
852 if (isset($unique_ID[$attr['queryUnique']])) {
853 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $unique_ID[$attr['queryUnique']]) : $unique_ID[$attr['queryUnique']];
854 }
855 }
856
857 if (isset($attr['queryQuick'])) {
858 if ($attr['queryQuick'] != '') {
859 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
860 }
861 }
862
863 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
864 $offset = $this->get_offset($attr['queryOffset'], $query_args);
865 $query_args = array_merge($query_args, $offset);
866 }
867
868 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
869 $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
870 if (is_array($_include) && count($_include)) {
871 $query_args['author__in'] = $_include;
872 }
873 }
874
875 if(isset($attr['querySticky']) && $attr['querySticky']) {
876 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
877 $sticky = get_option( 'sticky_posts', [] );
878 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
879 }
880 }
881
882 if (!isset($attr['ajaxCall'])) {
883 if(isset($attr['filterShow']) && $attr['filterShow']) {
884 if(isset($attr['filterType']) && isset($attr['filterValue'])) {
885 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
886 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
887 if (count($filterValue) > 0 && $attr['filterType']) {
888 $final = array('relation' => 'OR');
889 foreach ($filterValue as $key => $val) {
890 $final[] = array(
891 'taxonomy' => $attr['filterType'],
892 'field' => 'slug',
893 'terms' => $val,
894 // 'operator' => '=',
895 );
896 }
897 $query_args['tax_query'] = $final;
898 }
899 }
900 }
901 }
902
903 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
904
905 return apply_filters('ultp_frontend_query', $query_args);
906 }
907
908 function get_offset($queryOffset, $query_args) {
909 $query = array();
910 if ($query_args['paged'] > 1) {
911 $offset_post = wp_get_recent_posts($query_args, OBJECT);
912 if ( count($offset_post) > 0 ) {
913 $offset = array();
914 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--){
915 $offset[] = $offset_post[$x-1]->ID;
916 }
917 $query['post__not_in'] = $offset;
918 }
919 } else {
920 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
921 }
922 return $query;
923 }
924
925
926 /**
927 * Get Page Number
928 *
929 * @since v.1.0.0
930 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
931 * @return ARRAY
932 */
933 public function get_page_number($attr, $post_number) {
934 if ($post_number > 0) {
935 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
936 $post_number = $post_number - (int)$attr['queryOffset'];
937 }
938 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
939 $pages = ceil($post_number/$post_per_page);
940 return $pages ? $pages : 1;
941 }else{
942 return 1;
943 }
944 }
945
946
947 /**
948 * Get Image Size
949 *
950 * @since v.1.0.0
951 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
952 * @return ARRAY
953 */
954 public function get_image_size() {
955 $sizes = get_intermediate_image_sizes();
956 $filter = array('full' => 'Full');
957 foreach ($sizes as $value) {
958 $title = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
959 switch ($value) {
960 case 'thumbnail':
961 $title = $title.' [150x150]';
962 break;
963 case 'medium':
964 $title = $title.' [300x300]';
965 break;
966 case 'large':
967 $title = $title.' [1024x1024]';
968 break;
969 case 'ultp_layout_landscape_large':
970 $title = $title.' [1200x800]';
971 break;
972 case 'ultp_layout_landscape':
973 $title = $title.' [870x570]';
974 break;
975 case 'ultp_layout_portrait':
976 $title = $title.' [600x900]';
977 break;
978 case 'ultp_layout_square':
979 $title = $title.' [600x600]';
980 break;
981 default:
982 break;
983 }
984 $filter[$value] = $title;
985 }
986 return $filter;
987 }
988
989
990 /**
991 * Get All PostType Registered
992 *
993 * @since v.1.0.0
994 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
995 * @return ARRAY
996 */
997 public function get_post_type() {
998 $post_type = get_post_types( ['public' => true], 'names' );
999 return array_diff($post_type, array( 'attachment' ));
1000 }
1001
1002
1003 /**
1004 * Get Pagination HTML
1005 *
1006 * @since v.1.0.0
1007 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1008 * @return STRING
1009 */
1010 public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
1011 $html = '';
1012 $showitems = 3;
1013 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
1014 $paged = $paged ? $paged : 1;
1015 if($pages == '') {
1016 global $wp_query;
1017 $pages = $wp_query->max_num_pages;
1018 if(!$pages) {
1019 $pages = 1;
1020 }
1021 }
1022 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1023
1024 $paginationText = explode('|', $paginationText);
1025
1026 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
1027 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
1028
1029 if(1 != $pages) {
1030 $html .= '<ul class="ultp-pagination">';
1031 $display_none = 'style="display:none"';
1032 if($pages > 4) {
1033 $html .= '<li class="ultp-prev-page-numbers" '.($paged==1?$display_none:"").'><a href="'.get_pagenum_link($paged-1).'">'.ultimate_post()->svg_icon('leftAngle2').' '.($paginationNav == 'textArrow' ? $prev_text : "").'</a></li>';
1034 }
1035 if($pages > 4){
1036 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
1037 }
1038 if($pages > 4){
1039 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
1040 }
1041 foreach ($data as $i) {
1042 if($pages >= $i){
1043 $html .= ($paged == $i) ? '<li class="ultp-center-item pagination-active" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>':'<li class="ultp-center-item" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
1044 }
1045 }
1046 if($pages > 4){
1047 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
1048 }
1049 if($pages > 4){
1050 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
1051 }
1052 if ($paged != $pages) {
1053 $html .= '<li class="ultp-next-page-numbers"><a href="'.get_pagenum_link($paged + 1).'">'.($paginationNav == 'textArrow' ? $next_text : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
1054 }
1055 $html .= '</ul>';
1056 }
1057 return $html;
1058 }
1059
1060
1061 /**
1062 * Get Excerpt Word
1063 *
1064 * @since v.1.0.0
1065 * @param NUMBER | Character Length
1066 * @return STRING
1067 */
1068 public function excerpt_word($charlength = 200) {
1069 $html = '';
1070 $charlength++;
1071 $excerpt = get_the_excerpt();
1072 if ( mb_strlen( $excerpt ) > $charlength ) {
1073 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
1074 $exwords = explode( ' ', $subex );
1075 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1076 if ( $excut < 0 ) {
1077 $html = mb_substr( $subex, 0, $excut );
1078 } else {
1079 $html = $subex;
1080 }
1081 $html .= '...';
1082 } else {
1083 $html = $excerpt;
1084 }
1085 return $html;
1086 }
1087
1088
1089 /**
1090 * Get Taxonomy Lists
1091 *
1092 * @since v.1.0.0
1093 * @param STRING | Taxonomy Slug
1094 * @return ARRAY
1095 */
1096 public function taxonomy( $prams = 'category' ) {
1097 $data = array();
1098 $terms = get_terms( $prams, array(
1099 'hide_empty' => false,
1100 ));
1101 if( !is_wp_error($terms) ){
1102 foreach ($terms as $val) {
1103 $data[urldecode_deep($val->slug)] = $val->name;
1104 }
1105 }
1106 return $data;
1107 }
1108
1109
1110 /**
1111 * Get Taxonomy Data Lists
1112 *
1113 * @since v.1.0.0
1114 * @param OBJECT | Taxonomy Object
1115 * @return ARRAY
1116 */
1117 public function get_tax_data($terms) {
1118 $temp = array();
1119 $image = '';
1120 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1121 if( $thumbnail_id ){
1122 $image = wp_get_attachment_url( $thumbnail_id );
1123 }
1124 $temp['url'] = get_term_link($terms);
1125 $temp['name'] = $terms->name;
1126 $temp['desc'] = $terms->description;
1127 $temp['count'] = $terms->count;
1128 $temp['image'] = $image;
1129 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1130 $temp['color'] = $color ? $color : '#037fff';
1131 return $temp;
1132 }
1133
1134 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
1135 $data = array();
1136 if($type == 'child'){
1137 $image = '';
1138 if (!empty($catSlug)) {
1139 foreach ($catSlug as $cat) {
1140 $parent_term = get_term_by('slug', $cat, $tax_slug);
1141 if (!empty($parent_term)) {
1142 $term_data = get_terms($tax_slug, array(
1143 'hide_empty' => true,
1144 'parent' => $parent_term->term_id
1145 ));
1146 if (!empty($term_data)) {
1147 foreach ($term_data as $terms) {
1148 $data[] = $this->get_tax_data($terms);
1149 }
1150 }
1151 }
1152 }
1153 }
1154 } else if ($type == 'parent') {
1155 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1156 if (!empty($term_data)) {
1157 foreach ($term_data as $terms) {
1158 $data[] = $this->get_tax_data($terms);
1159 }
1160 }
1161 } else if ($type == 'custom') {
1162 foreach ($catSlug as $cat) {
1163 $terms = get_term_by('slug', $cat, $tax_slug);
1164 if (!empty($terms)) {
1165 $data[] = $this->get_tax_data($terms);
1166 }
1167 }
1168 } else {
1169 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
1170 if (!empty($term_data)) {
1171 foreach ($term_data as $terms) {
1172 $data[] = $this->get_tax_data($terms);
1173 }
1174 }
1175 }
1176 return $data;
1177 }
1178
1179
1180 /**
1181 * Get Next Previous HTML
1182 *
1183 * @since v.1.0.0
1184 * @param OBJECT | Taxonomy Object
1185 * @return STRING
1186 */
1187 public function next_prev() {
1188 $html = '';
1189 $html .= '<ul>';
1190 $html .= '<li>';
1191 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1192 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.esc_html__("Previous", "ultimate-post").'</span>';
1193 $html .= '</a>';
1194 $html .= '</li>';
1195 $html .= '<li>';
1196 $html .= '<a class="ultp-next-action">';
1197 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.esc_html__("Next", "ultimate-post").'</span>';
1198 $html .= '</a>';
1199 $html .= '</li>';
1200 $html .= '</ul>';
1201 return $html;
1202 }
1203
1204
1205 /**
1206 * Get Loading HTML
1207 *
1208 * @since v.1.0.0
1209 * @param NULL
1210 * @return STRING
1211 */
1212 public function loading(){
1213 $html = '';
1214 $style = ultimate_post()->get_setting('preloader_style');
1215 if( $style == 'style2' ){
1216 $html .= '<div class="ultp-loading-spinner" style="width:100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>';//ultp-block-items-wrap
1217 } else {
1218 $html .= '<div class="ultp-loading-blocks" style="width:100%;height:100%;"><div style="left: 0;top: 0;animation-delay:0s;"></div><div style="left: 21px;top: 0;animation-delay:0.125s;"></div><div style="left: 42px;top: 0;animation-delay:0.25s;"></div><div style="left: 0;top: 21px;animation-delay:0.875s;"></div><div style="left: 42px;top: 21px;animation-delay:0.375s;"></div><div style="left: 0;top: 42px;animation-delay:0.75s;"></div><div style="left: 42px;top: 42px;animation-delay:0.625s;"></div><div style="left: 21px;top: 42px;animation-delay:0.5s;"></div></div>';
1219 }
1220 return '<div class="ultp-loading">'.$html.'</div>';
1221 }
1222
1223
1224 /**
1225 * Get Filter HTML
1226 *
1227 * @since v.1.0.0
1228 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1229 * @return STRING
1230 */
1231 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true){
1232 $html = '';
1233 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1234 $cat = $this->taxonomy($filterType);
1235 if($filterText){
1236 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1237 }
1238
1239 if ($filterValue) {
1240 $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1241 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1242 foreach ($filterValue as $val) {
1243 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1244 }
1245 }
1246 $html .= '</ul>';
1247 return $html;
1248 }
1249
1250
1251 /**
1252 * Check License Status
1253 *
1254 * @since v.2.4.2
1255 * @return BOOLEAN | Is pro license active or not
1256 */
1257 public function is_lc_active() {
1258 if (function_exists('ultimate_post_pro')) {
1259 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1260 }
1261 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
1262 return true;
1263 }
1264 return false;
1265 }
1266
1267
1268 /**
1269 * Get SVG Icon
1270 *
1271 * @since v.1.0.0
1272 * @param STRING | Icon Key
1273 * @return STRING | Icon SVG
1274 */
1275 public function svg_icon($icons = ''){
1276 $icon_lists = array(
1277 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
1278 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
1279 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
1280 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
1281 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
1282 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
1283 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
1284 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
1285 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
1286 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
1287 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
1288 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
1289 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
1290 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1291 );
1292 if($icons){
1293 return $icon_lists[ $icons ];
1294 }
1295 }
1296
1297 /**
1298 * Get SEO Meta
1299 *
1300 * @since v.2.4.3
1301 * @param NUMBER | Post ID
1302 * @return STRING | SEO Meta Description or Excerpt
1303 */
1304 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1305 $html = '';
1306 if ($showSeoMeta) {
1307 $str = '';
1308 if( function_exists('ultimate_post_pro') ) {
1309 if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1310 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1311 } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1312 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1313 } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1314 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1315 } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1316 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1317 } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1318 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1319 }
1320 }
1321 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1322 } else {
1323 if ( $showFullExcerpt == 0 ) {
1324 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1325 } else {
1326 $html = get_the_excerpt();
1327 }
1328 }
1329 return $html;
1330 }
1331
1332 /**
1333 * Set Inline CSS
1334 *
1335 * @since v.2.5.8
1336 * @param STRING | CSS
1337 * @return STRING | CSS with Style
1338 */
1339 public function set_inline($css) {
1340 return '<style type="text/css">'.wp_strip_all_tags($css).'</style>';
1341 }
1342
1343 /**
1344 * Array Sanitize Function
1345 *
1346 * @since v.2.6.0
1347 * @param ARRAY
1348 * @return ARRAY | Array of Sanitize
1349 */
1350 public function recursive_sanitize_text_field($array) {
1351 foreach ($array as $key => &$value) {
1352 if (is_array($value)) {
1353 $value = $this->recursive_sanitize_text_field($value);
1354 } else {
1355 $value = sanitize_text_field($value);
1356 }
1357 }
1358 return $array;
1359 }
1360
1361 }
1362