PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.5.0
Post Grid Gutenberg Blocks – PostX v2.5.0
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.5.0, at classes/Functions.php

1,099 lines 40.9 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 = 'https://www.wpxpo.com/postx/pricing/' ) {
58 $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
59 $arg = array( 'utm_source' => 'go_premium' );
60 if ( ! empty( $affiliate_id ) ) {
61 $arg[ 'ref' ] = esc_attr( $affiliate_id );
62 }
63 return add_query_arg( $arg, $url );
64 }
65
66
67 /**
68 * Get Width and Height of the Image
69 *
70 * @since v.1.1.0
71 * @return STRING | Image Size
72 */
73 public function get_size($name = ''){
74 global $_wp_additional_image_sizes;
75 $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];
76
77 return ' width="'.$image_size['width'].'" height="'.$image_size['height'].'" ';
78 }
79
80
81 /**
82 * Image Placeholder
83 *
84 * @since v.1.1.0
85 * @return STRING | Image Placeholder
86 */
87 public function img_placeholder($type = 'small') {
88 switch ($type) {
89 case 'small':
90 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAABLAQMAAACr9CA9AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABZJREFUOI1jYMADmEe5o9xR7iiXQi4A4BsA388WUyMAAAAASUVORK5CYII=';
91 break;
92
93 case 'wide':
94 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAKCAYAAADVTVykAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB9JREFUeNpi/P//P8NAAiaGAQajDhh1wKgDRh0AEGAAQTcDEcKDrpMAAAAASUVORK5CYII=';
95 break;
96
97 case 'square':
98 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAApJREFUCJljYAAAAAIAAfRxZKYAAAAASUVORK5CYII=';
99 break;
100
101 case 'slider':
102 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAABkCAMAAAA7drv6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////AAAAVcLTfgAAAAF0Uk5TAEDm2GYAAAAqSURBVHja7MEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAH5NgAEAQTwAAWZtItYAAAAASUVORK5CYII=';
103 break;
104
105 default:
106 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYYAAADcAQMAAABOLJSDAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAACJJREFUaIHtwTEBAAAAwqD1T20ND6AAAAAAAAAAAAAA4N8AKvgAAUFIrrEAAAAASUVORK5CYII=';
107 break;
108 }
109 }
110
111
112 /**
113 * Quick Query
114 *
115 * @since v.1.1.0
116 * @return ARRAY | Query Arg
117 */
118 public function get_quick_query($prams, $args) {
119 switch ($prams['queryQuick']) {
120 case 'related_posts':
121 global $post;
122 if (isset($post->ID)) {
123 $args['post__not_in'] = array($post->ID);
124 }
125 break;
126 case 'related_tag':
127 global $post;
128 if (isset($post->ID)) {
129 $args['tax_query'] = array(
130 array(
131 'taxonomy' => 'post_tag',
132 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
133 'field' => 'term_id',
134 )
135 );
136 $args['post__not_in'] = array($post->ID);
137 }
138 break;
139 case 'related_category':
140 global $post;
141 if (isset($post->ID)) {
142 $args['tax_query'] = array(
143 array(
144 'taxonomy' => 'category',
145 'terms' => $this->get_terms_id($post->ID, 'category'),
146 'field' => 'term_id',
147 )
148 );
149 $args['post__not_in'] = array($post->ID);
150 }
151 break;
152 case 'related_cat_tag':
153 global $post;
154 if (isset($post->ID)) {
155 $args['tax_query'] = array(
156 array(
157 'taxonomy' => 'post_tag',
158 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
159 'field' => 'term_id',
160 ),
161 array(
162 'taxonomy' => 'category',
163 'terms' => $this->get_terms_id($post->ID, 'category'),
164 'field' => 'term_id',
165 )
166 );
167 $args['post__not_in'] = array($post->ID);
168 }
169 break;
170 case 'sticky_posts':
171 $sticky = get_option('sticky_posts');
172 if (is_array($sticky)) {
173 rsort($sticky);
174 $sticky = array_slice($sticky, 0, $args['posts_per_page']);
175 }
176 $args['ignore_sticky_posts'] = 1;
177 $args['post__in'] = $sticky;
178 break;
179 case 'latest_post_published':
180 $args['orderby'] = 'date';
181 $args['order'] = 'DESC';
182 $args['ignore_sticky_posts'] = 1;
183 break;
184 case 'latest_post_modified':
185 $args['orderby'] = 'modified';
186 $args['order'] = 'DESC';
187 $args['ignore_sticky_posts'] = 1;
188 break;
189 case 'oldest_post_published':
190 $args['orderby'] = 'date';
191 $args['order'] = 'ASC';
192 break;
193 case 'oldest_post_modified':
194 $args['orderby'] = 'modified';
195 $args['order'] = 'ASC';
196 break;
197 case 'alphabet_asc':
198 $args['orderby'] = 'title';
199 $args['order'] = 'ASC';
200 break;
201 case 'alphabet_desc':
202 $args['orderby'] = 'title';
203 $args['order'] = 'DESC';
204 break;
205 case 'random_post':
206 $args['orderby'] = 'rand';
207 $args['order'] = 'ASC';
208 break;
209 case 'random_post_7_days':
210 $args['orderby'] = 'rand';
211 $args['order'] = 'ASC';
212 $args['date_query'] = array( array( 'after' => '1 week ago') );
213 break;
214 case 'random_post_30_days':
215 $args['orderby'] = 'rand';
216 $args['order'] = 'ASC';
217 $args['date_query'] = array( array( 'after' => '1 month ago') );
218 break;
219 case 'most_comment':
220 $args['orderby'] = 'comment_count';
221 $args['order'] = 'DESC';
222 break;
223 case 'most_comment_1_day':
224 $args['orderby'] = 'comment_count';
225 $args['order'] = 'DESC';
226 $args['date_query'] = array( array( 'after' => '1 day ago') );
227 break;
228 case 'most_comment_7_days':
229 $args['orderby'] = 'comment_count';
230 $args['order'] = 'DESC';
231 $args['date_query'] = array( array( 'after' => '1 week ago') );
232 break;
233 case 'most_comment_30_days':
234 $args['orderby'] = 'comment_count';
235 $args['order'] = 'DESC';
236 $args['date_query'] = array( array( 'after' => '1 month ago') );
237 break;
238 case 'popular_post_1_day_view':
239 $args['meta_key'] = '__post_views_count';
240 $args['orderby'] = 'meta_value meta_value_num';
241 $args['order'] = 'DESC';
242 $args['date_query'] = array( array( 'after' => '1 day ago') );
243 break;
244 case 'popular_post_7_days_view':
245 $args['meta_key'] = '__post_views_count';
246 $args['orderby'] = 'meta_value meta_value_num';
247 $args['order'] = 'DESC';
248 $args['date_query'] = array( array( 'after' => '1 week ago') );
249 break;
250 case 'popular_post_30_days_view':
251 $args['meta_key'] = '__post_views_count';
252 $args['orderby'] = 'meta_value meta_value_num';
253 $args['order'] = 'DESC';
254 $args['date_query'] = array( array( 'after' => '1 month ago') );
255 break;
256 case 'popular_post_all_times_view':
257 $args['meta_key'] = '__post_views_count';
258 $args['orderby'] = 'meta_value meta_value_num';
259 $args['order'] = 'DESC';
260 break;
261 default:
262 # code...
263 break;
264 }
265 return $args;
266 }
267
268 /**
269 * Get All Term ID as Array
270 *
271 * @since v.2.4.12
272 * @return ARRAY | Query Arg
273 */
274 public function get_terms_id($id, $type) {
275 $data = array();
276 $arr = get_the_terms($id, $type);
277 if (is_array($arr)) {
278 foreach ($arr as $key => $val) {
279 $data[] = $val->term_id;
280 }
281 }
282 return $data;
283 }
284
285 /**
286 * Get All Reusable ID
287 *
288 * @since v.1.1.0
289 * @return ARRAY | Query Arg
290 */
291 public function reusable_id($post_id){
292 $reusable_id = array();
293 if($post_id){
294 $post = get_post($post_id);
295 if (has_blocks($post->post_content)) {
296 $blocks = parse_blocks($post->post_content);
297 foreach ($blocks as $key => $value) {
298 if(isset($value['attrs']['ref'])) {
299 $reusable_id[] = $value['attrs']['ref'];
300 }
301 }
302 }
303 }
304 return $reusable_id;
305 }
306
307
308 /**
309 * Set CSS Style
310 *
311 * @since v.1.1.0
312 * @return ARRAY | Query Arg
313 */
314 public function set_css_style($post_id, $shortcode = false){
315 if( $post_id ){
316 $upload_dir_url = wp_get_upload_dir();
317 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
318 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
319
320 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
321 if (is_ssl()) {
322 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
323 }
324
325 // Reusable CSS
326 $reusable_id = ultimate_post()->reusable_id($post_id);
327 foreach ( $reusable_id as $id ) {
328 $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
329 if (file_exists( $reusable_dir_path )) {
330 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
331 wp_enqueue_style( "ultp-post-{$id}", $css_url, array(), ULTP_VER, 'all' );
332 }else{
333 $css = get_post_meta($id, '_ultp_css', true);
334 if( $css ) {
335 wp_enqueue_style("ultp-post-{$id}", $css, false, ULTP_VER);
336 }
337 }
338 }
339
340 if (isset($_GET['et_fb']) || (isset($_GET['action']) && $_GET['action'] =='elementor') || $shortcode) {
341 echo '<style type="text/css">'.get_post_meta($post_id, '_ultp_css', true).'</style>';
342 } else {
343 if ( file_exists( $css_dir_path ) ) {
344 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
345 wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ULTP_VER, 'all' );
346 } else {
347 $css = get_post_meta($post_id, '_ultp_css', true);
348 if( $css ) {
349 wp_enqueue_style("ultp-post-{$post_id}", $css, false, ULTP_VER);
350 }
351 }
352 }
353 }
354 }
355
356
357 /**
358 * Get Global Plugin Settings
359 *
360 * @since v.1.0.0
361 * @param STRING | Key of the Option
362 * @return ARRAY | STRING
363 */
364 public function get_setting($key = ''){
365 $data = $GLOBALS['ultp_settings'];
366 if ($key != '') {
367 return isset($data[$key]) ? $data[$key] : '';
368 } else {
369 return $data;
370 }
371 }
372
373
374 /**
375 * Set Option Settings
376 *
377 * @since v.1.0.0
378 * @param STRING | Key of the Option (STRING), Value (STRING)
379 * @return NULL
380 */
381 public function set_setting($key = '', $val = '') {
382 if($key != ''){
383 $data = $GLOBALS['ultp_settings'];
384 $data[$key] = $val;
385 update_option('ultp_options', $data);
386 $GLOBALS['ultp_settings'] = $data;
387 }
388 }
389
390
391 /**
392 * Get Image HTML
393 *
394 * @since v.1.0.0
395 * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
396 * @return STRING
397 */
398 public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = ''){
399 $alt = $alt ? ' alt="'.$alt.'" ' : '';
400 $lazy_data = $lazy ? ' loading="lazy"' : '';
401 $class = $class ? ' class="'.$class.'" ' : '';
402 return '<img '.$lazy_data.$class.$alt.' src="'.$url.'" />';
403 }
404
405
406 /**
407 * Get Image HTML
408 *
409 * @since v.1.0.0
410 * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
411 * @return STRING
412 */
413 public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = ''){
414 $alt = $alt ? ' alt="'.$alt.'" ' : '';
415 $class = $class ? ' class="'.$class.'" ' : '';
416 $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
417 $lazy_data = $lazy ? ' loading="lazy"' : '';
418 $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
419 return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
420 }
421
422
423 /**
424 * Setup Initial Data Set
425 *
426 * @since v.1.0.0
427 * @return NULL
428 */
429 public function init_set_data(){
430 $data = get_option( 'ultp_options', array() );
431 $init_data = array(
432 'css_save_as' => 'wp_head',
433 'preloader_style' => 'style1',
434 'preloader_color' => '#037fff',
435 'container_width' => '1140',
436 'hide_import_btn' => '',
437 'disable_image_size'=> '',
438 'ultp_templates' => 'true',
439 'ultp_elementor' => 'true',
440 'ultp_table_of_content'=> 'true',
441 'post_grid_1' => 'yes',
442 'post_grid_2' => 'yes',
443 'post_grid_3' => 'yes',
444 'post_grid_4' => 'yes',
445 'post_grid_5' => 'yes',
446 'post_grid_6' => 'yes',
447 'post_grid_7' => 'yes',
448 'post_list_1' => 'yes',
449 'post_list_2' => 'yes',
450 'post_list_3' => 'yes',
451 'post_list_4' => 'yes',
452 'post_module_1' => 'yes',
453 'post_module_2' => 'yes',
454 'post_slider_1' => 'yes',
455 'heading' => 'yes',
456 'image' => 'yes',
457 'taxonomy' => 'yes',
458 'wrapper' => 'yes'
459 );
460 if (empty($data)) {
461 update_option('ultp_options', $init_data);
462 $GLOBALS['ultp_settings'] = $init_data;
463 } else {
464 foreach ($init_data as $key => $single) {
465 if (!isset($data[$key])) {
466 $data[$key] = $single;
467 }
468 }
469 update_option('ultp_options', $data);
470 $GLOBALS['ultp_settings'] = $data;
471 }
472 }
473
474
475 /**
476 * Get Excerpt Text
477 *
478 * @since v.1.0.0
479 * @param | Post ID (STRING) | Limit (NUMBER)
480 * @return STRING
481 */
482 public function excerpt( $post_id, $limit = 55 ) {
483 return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
484 }
485
486 public function get_builder_attr() {
487 $builder_data = '';
488 if (is_archive()) {
489 if (is_date()) {
490 if ( is_year() ) {
491 $builder_data = 'date###'.get_the_date('Y');
492 } else if ( is_month() ) {
493 $builder_data = 'date###'.get_the_date('Y-n');
494 } else if ( is_day() ) {
495 $builder_data = 'date###'.get_the_date('Y-n-j');
496 }
497 } else if (is_author()) {
498 $builder_data = 'author###'.get_the_author_meta('ID');
499 } else {
500 $obj = get_queried_object();
501 if (isset($obj->taxonomy)) {
502 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
503 }
504 }
505 } else if (is_search()) {
506 $builder_data = 'search###'.get_search_query(true);
507 }
508 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
509 }
510
511
512 public function is_builder($builder = '') {
513 $id = '';
514 if (function_exists('ultimate_post_pro')) {
515 if ($builder) {
516 return true;
517 }
518 $page_id = ultimate_post_pro()->conditions('return');
519 if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
520 $id = $page_id;
521 }
522 }
523 return $id;
524 }
525
526 /**
527 * Query Builder
528 *
529 * @since v.1.0.0
530 * @param ARRAY | Attribute of the Query
531 * @return ARRAY
532 */
533 public function get_query($attr) {
534 $builder = isset($attr['builder']) ? $attr['builder'] : '';
535 if ($this->is_builder($builder)) {
536 $archive_query = array();
537 if ($builder) {
538 $str = explode('###', $builder);
539 if (isset($str[0])) {
540 if ($str[0] == 'taxonomy') {
541 if (isset($str[1]) && isset($str[2])) {
542 $archive_query['tax_query'] = array(
543 array(
544 'taxonomy' => $str[1],
545 'field' => 'slug',
546 'terms' => $str[2]
547 )
548 );
549 }
550 } else if ($str[0] == 'author') {
551 if (isset($str[1])) {
552 $archive_query['author'] = $str[1];
553 }
554 } else if ($str[0] == 'search') {
555 if (isset($str[1])) {
556 $archive_query['s'] = $str[1];
557 }
558 } else if ($str[0] == 'date') {
559 if (isset($str[1])) {
560 $all_date = explode('-', $str[1]);
561 if (!empty($all_date)) {
562 $arg = array();
563 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
564 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
565 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
566 $archive_query['date_query'][] = $arg;
567 }
568 }
569 }
570 }
571 } else {
572 global $wp_query;
573 $archive_query = $wp_query->query_vars;
574 }
575 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
576 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
577 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
578 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
579 $archive_query = array_merge($archive_query, $offset);
580 }
581
582 if(isset($attr['queryInclude']) && $attr['queryInclude']){
583 $archive_query['post__in'] = explode(',', $attr['queryInclude']);
584 $archive_query['ignore_sticky_posts'] = 1;
585 $archive_query['orderby'] = 'post__in';
586 }
587 if(isset($attr['queryExclude']) && $attr['queryExclude']) {
588 $archive_query['post__not_in'] = explode(',', $attr['queryExclude']);
589 }
590
591 $archive_query['post_status'] = 'publish';
592 return $archive_query;
593 }
594
595 $query_args = array(
596 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
597 'post_type' => isset($attr['queryType']) ? $attr['queryType'] : 'post',
598 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
599 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
600 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
601 'post_status' => 'publish'
602 );
603
604 if(isset($attr['queryOrderBy']) && isset($attr['metaKey'])){
605 if($attr['queryOrderBy'] == 'meta_value_num') {
606 $query_args['meta_key'] = $attr['metaKey'];
607 }
608 }
609
610 if(isset($attr['queryInclude']) && $attr['queryInclude']){
611 $query_args['post__in'] = explode(',', $attr['queryInclude']);
612 $query_args['ignore_sticky_posts'] = 1;
613 $query_args['orderby'] = 'post__in';
614 }
615
616 $exclude = '';
617 if (is_singular()) {
618 $id = get_the_ID();
619 $exclude = $id ? $id : '';
620 }
621 if (isset($attr['current_post']) && $attr['current_post']) {
622 $exclude = $attr['current_post'];
623 }
624
625 if(isset($attr['queryExclude']) && $attr['queryExclude']) {
626 $exclude = ($exclude ? $exclude.',' : '') . $attr['queryExclude'];
627 }
628 if ($exclude) {
629 $query_args['post__not_in'] = explode(',', $exclude);
630 }
631
632 if(isset($attr['queryTax'])){
633 if(isset($attr['queryTaxValue'])){
634 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : ($attr['queryTax'] == 'category' ? $attr['queryCat'] : $attr['queryTag']);
635 $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
636 if(count($tax_value) > 0){
637 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
638 $var = array('relation'=>$relation);
639 foreach ($tax_value as $val) {
640 $tax_name = $attr['queryTax'] == 'tag' ? 'post_tag' : $attr['queryTax']; // for compatibility
641 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
642 }
643 if(count($var) > 1){
644 $query_args['tax_query'] = $var;
645 }
646 }
647 }
648 }
649
650 if(isset($attr['queryQuick'])){
651 if($attr['queryQuick'] != ''){
652 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
653 }
654 }
655
656 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
657 $offset = $this->get_offset($attr['queryOffset'], $query_args);
658 $query_args = array_merge($query_args, $offset);
659 }
660
661 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
662 $query_args['author'] = $attr['queryAuthor'];
663 }
664
665
666 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
667
668 return $query_args;
669 }
670
671 function get_offset($queryOffset, $query_args) {
672 $query = array();
673 if ($query_args['paged'] > 1) {
674 $offset_post = wp_get_recent_posts($query_args, OBJECT);
675 if ( count($offset_post) > 0 ) {
676 $offset = array();
677 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--){
678 $offset[] = $offset_post[$x-1]->ID;
679 }
680 $query['post__not_in'] = $offset;
681 }
682 } else {
683 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
684 }
685 return $query;
686 }
687
688
689 /**
690 * Get Page Number
691 *
692 * @since v.1.0.0
693 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
694 * @return ARRAY
695 */
696 public function get_page_number($attr, $post_number) {
697 if ($post_number > 0) {
698 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
699 $post_number = $post_number - (int)$attr['queryOffset'];
700 }
701 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
702 $pages = ceil($post_number/$post_per_page);
703 return $pages ? $pages : 1;
704 }else{
705 return 1;
706 }
707 }
708
709
710 /**
711 * Get Image Size
712 *
713 * @since v.1.0.0
714 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
715 * @return ARRAY
716 */
717 public function get_image_size() {
718 $sizes = get_intermediate_image_sizes();
719 $filter = array('full' => 'Full');
720 foreach ($sizes as $value) {
721 $title = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
722 switch ($value) {
723 case 'thumbnail':
724 $title = $title.' [150x150]';
725 break;
726 case 'medium':
727 $title = $title.' [300x300]';
728 break;
729 case 'large':
730 $title = $title.' [1024x1024]';
731 break;
732 case 'ultp_layout_landscape_large':
733 $title = $title.' [1200x800]';
734 break;
735 case 'ultp_layout_landscape':
736 $title = $title.' [870x570]';
737 break;
738 case 'ultp_layout_portrait':
739 $title = $title.' [600x900]';
740 break;
741 case 'ultp_layout_square':
742 $title = $title.' [600x600]';
743 break;
744 default:
745 break;
746 }
747 $filter[$value] = $title;
748 }
749 return $filter;
750 }
751
752
753 /**
754 * Get All PostType Registered
755 *
756 * @since v.1.0.0
757 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
758 * @return ARRAY
759 */
760 public function get_post_type() {
761 $post_type = get_post_types( '', 'names' );
762 return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
763 }
764
765
766 /**
767 * Get Pagination HTML
768 *
769 * @since v.1.0.0
770 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
771 * @return STRING
772 */
773 public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
774 $html = '';
775 $showitems = 3;
776 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
777 $paged = $paged ? $paged : 1;
778 if($pages == '') {
779 global $wp_query;
780 $pages = $wp_query->max_num_pages;
781 if(!$pages) {
782 $pages = 1;
783 }
784 }
785 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
786
787 $paginationText = explode('|', $paginationText);
788
789 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
790 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
791
792 if(1 != $pages) {
793 $html .= '<ul class="ultp-pagination">';
794 $display_none = 'style="display:none"';
795 if($pages > 4) {
796 $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>';
797 }
798 if($pages > 4){
799 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
800 }
801 if($pages > 4){
802 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
803 }
804 foreach ($data as $i) {
805 if($pages >= $i){
806 $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>';
807 }
808 }
809 if($pages > 4){
810 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
811 }
812 if($pages > 4){
813 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
814 }
815 if ($paged != $pages) {
816 $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>';
817 }
818 $html .= '</ul>';
819 }
820 return $html;
821 }
822
823
824 /**
825 * Get Excerpt Word
826 *
827 * @since v.1.0.0
828 * @param NUMBER | Character Length
829 * @return STRING
830 */
831 public function excerpt_word($charlength = 200) {
832 $html = '';
833 $charlength++;
834 $excerpt = get_the_excerpt();
835 if ( mb_strlen( $excerpt ) > $charlength ) {
836 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
837 $exwords = explode( ' ', $subex );
838 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
839 if ( $excut < 0 ) {
840 $html = mb_substr( $subex, 0, $excut );
841 } else {
842 $html = $subex;
843 }
844 $html .= '...';
845 } else {
846 $html = $excerpt;
847 }
848 return $html;
849 }
850
851
852 /**
853 * Get Taxonomy Lists
854 *
855 * @since v.1.0.0
856 * @param STRING | Taxonomy Slug
857 * @return ARRAY
858 */
859 public function taxonomy( $prams = 'category' ) {
860 $data = array();
861 $terms = get_terms( $prams, array(
862 'hide_empty' => false,
863 ));
864 if( !is_wp_error($terms) ){
865 foreach ($terms as $val) {
866 $data[urldecode_deep($val->slug)] = $val->name;
867 }
868 }
869 return $data;
870 }
871
872
873 /**
874 * Get Taxonomy Data Lists
875 *
876 * @since v.1.0.0
877 * @param OBJECT | Taxonomy Object
878 * @return ARRAY
879 */
880 public function get_tax_data($terms) {
881 $temp = array();
882 $image = '';
883 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
884 if( $thumbnail_id ){
885 $image = wp_get_attachment_url( $thumbnail_id );
886 }
887 $temp['url'] = get_term_link($terms);
888 $temp['name'] = $terms->name;
889 $temp['desc'] = $terms->description;
890 $temp['count'] = $terms->count;
891 $temp['image'] = $image;
892 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
893 $temp['color'] = $color ? $color : '#037fff';
894 return $temp;
895 }
896
897 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
898 $data = array();
899 if($type == 'child'){
900 $image = '';
901 if (!empty($catSlug)) {
902 foreach ($catSlug as $cat) {
903 $parent_term = get_term_by('slug', $cat, $tax_slug);
904 if (!empty($parent_term)) {
905 $term_data = get_terms($tax_slug, array(
906 'hide_empty' => true,
907 'parent' => $parent_term->term_id
908 ));
909 if (!empty($term_data)) {
910 foreach ($term_data as $terms) {
911 $data[] = $this->get_tax_data($terms);
912 }
913 }
914 }
915 }
916 }
917 } else if ($type == 'parent') {
918 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
919 if (!empty($term_data)) {
920 foreach ($term_data as $terms) {
921 $data[] = $this->get_tax_data($terms);
922 }
923 }
924 } else if ($type == 'custom') {
925 foreach ($catSlug as $cat) {
926 $terms = get_term_by('slug', $cat, $tax_slug);
927 if (!empty($terms)) {
928 $data[] = $this->get_tax_data($terms);
929 }
930 }
931 } else {
932 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
933 if (!empty($term_data)) {
934 foreach ($term_data as $terms) {
935 $data[] = $this->get_tax_data($terms);
936 }
937 }
938 }
939 return $data;
940 }
941
942
943 /**
944 * Get Next Previous HTML
945 *
946 * @since v.1.0.0
947 * @param OBJECT | Taxonomy Object
948 * @return STRING
949 */
950 public function next_prev() {
951 $html = '';
952 $html .= '<ul>';
953 $html .= '<li>';
954 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
955 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
956 $html .= '</a>';
957 $html .= '</li>';
958 $html .= '<li>';
959 $html .= '<a class="ultp-next-action">';
960 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
961 $html .= '</a>';
962 $html .= '</li>';
963 $html .= '</ul>';
964 return $html;
965 }
966
967
968 /**
969 * Get Loading HTML
970 *
971 * @since v.1.0.0
972 * @param NULL
973 * @return STRING
974 */
975 public function loading(){
976 $html = '';
977 $style = ultimate_post()->get_setting('preloader_style');
978 if( $style == 'style2' ){
979 $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
980 } else {
981 $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>';
982 }
983 return '<div class="ultp-loading">'.$html.'</div>';
984 }
985
986
987 /**
988 * Get Filter HTML
989 *
990 * @since v.1.0.0
991 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
992 * @return STRING
993 */
994 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterCat = [], $filterTag = [], $filterMobileText = '...', $filterMobile = true){
995 $html = '';
996 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
997
998 $filterType = $filterType == 'tag' ? 'post_tag' : $filterType; // for compatibility
999
1000 $cat = $this->taxonomy($filterType);
1001 if($filterText){
1002 $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
1003 }
1004
1005 if ($filterValue) {
1006 $filterValue = strlen($filterValue) > 2 ? $filterValue : ($filterType == 'category' ? $filterCat : $filterTag);
1007 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1008 foreach ($filterValue as $val) {
1009 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1010 }
1011 }
1012 $html .= '</ul>';
1013 return $html;
1014 }
1015
1016
1017 /**
1018 * Check License Status
1019 *
1020 * @since v.2.4.2
1021 * @return BOOLEAN | Is pro license active or not
1022 */
1023 public function is_lc_active() {
1024 if (function_exists('ultimate_post_pro')) {
1025 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1026 }
1027 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
1028 return true;
1029 }
1030 return false;
1031 }
1032
1033
1034 /**
1035 * Get SVG Icon
1036 *
1037 * @since v.1.0.0
1038 * @param STRING | Icon Key
1039 * @return STRING | Icon SVG
1040 */
1041 public function svg_icon($icons = ''){
1042 $icon_lists = array(
1043 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
1044 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
1045 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
1046 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
1047 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
1048 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
1049 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
1050 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
1051 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
1052 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
1053 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
1054 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
1055 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
1056 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1057 );
1058 if($icons){
1059 return $icon_lists[ $icons ];
1060 }
1061 }
1062
1063 /**
1064 * Get SEO Meta
1065 *
1066 * @since v.2.4.3
1067 * @param NUMBER | Post ID
1068 * @return STRING | SEO Meta Description or Excerpt
1069 */
1070 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1071 $html = '';
1072 if ($showSeoMeta) {
1073 $str = '';
1074 if( function_exists('ultimate_post_pro') ) {
1075 if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1076 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1077 } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1078 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1079 } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1080 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1081 } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1082 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1083 } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1084 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1085 }
1086 }
1087 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1088 } else {
1089 if ( $showFullExcerpt == 0 ) {
1090 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1091 } else {
1092 $html = get_the_excerpt();
1093 }
1094 }
1095 return $html;
1096 }
1097
1098 }
1099