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

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