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

1,050 lines 38.3 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 : 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
616 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : ($attr['queryTax'] == 'category' ? $attr['queryCat'] : $attr['queryTag']);
617
618 if(strlen($tax_value) > 2){
619 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
620 $var = array('relation'=>$relation);
621 foreach (json_decode($tax_value) as $val) {
622 $tax_name = $attr['queryTax'] == 'tag' ? 'post_tag' : $attr['queryTax']; // for compatibility
623 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
624 }
625 if(count($var) > 1){
626 $query_args['tax_query'] = $var;
627 }
628 }
629 }
630 }
631
632 if(isset($attr['queryQuick'])){
633 if($attr['queryQuick'] != ''){
634 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
635 }
636 }
637
638 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
639 $offset = $this->get_offset($attr['queryOffset'], $query_args);
640 $query_args = array_merge($query_args, $offset);
641 }
642
643 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
644 $query_args['author'] = $attr['queryAuthor'];
645 }
646
647
648 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
649
650 return $query_args;
651 }
652
653 function get_offset($queryOffset, $query_args) {
654 $query = array();
655 if ($query_args['paged'] > 1) {
656 $offset_post = wp_get_recent_posts($query_args, OBJECT);
657 if ( count($offset_post) > 0 ) {
658 $offset = array();
659 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--){
660 $offset[] = $offset_post[$x-1]->ID;
661 }
662 $query['post__not_in'] = $offset;
663 }
664 } else {
665 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
666 }
667 return $query;
668 }
669
670
671 /**
672 * Get Page Number
673 *
674 * @since v.1.0.0
675 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
676 * @return ARRAY
677 */
678 public function get_page_number($attr, $post_number) {
679 if($post_number > 0){
680 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
681 $pages = ceil($post_number/$post_per_page);
682 return $pages ? $pages : 1;
683 }else{
684 return 1;
685 }
686 }
687
688
689 /**
690 * Get Image Size
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_image_size() {
697 $sizes = get_intermediate_image_sizes();
698 $filter = array('full' => 'Full');
699 foreach ($sizes as $value) {
700 $filter[$value] = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
701 }
702 return $filter;
703 }
704
705
706 /**
707 * Get All PostType Registered
708 *
709 * @since v.1.0.0
710 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
711 * @return ARRAY
712 */
713 public function get_post_type() {
714 $post_type = get_post_types( '', 'names' );
715 return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
716 }
717
718
719 /**
720 * Get Pagination HTML
721 *
722 * @since v.1.0.0
723 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
724 * @return STRING
725 */
726 public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
727 $html = '';
728 $showitems = 3;
729 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
730 $paged = $paged ? $paged : 1;
731 if($pages == '') {
732 global $wp_query;
733 $pages = $wp_query->max_num_pages;
734 if(!$pages) {
735 $pages = 1;
736 }
737 }
738 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
739
740 $paginationText = explode('|', $paginationText);
741
742 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
743 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
744
745 if(1 != $pages) {
746 $html .= '<ul class="ultp-pagination">';
747 $display_none = 'style="display:none"';
748 if($pages > 4) {
749 $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>';
750 }
751 if($pages > 4){
752 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
753 }
754 if($pages > 4){
755 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
756 }
757 foreach ($data as $i) {
758 if($pages >= $i){
759 $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>';
760 }
761 }
762 if($pages > 4){
763 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
764 }
765 if($pages > 4){
766 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
767 }
768 if ($paged != $pages) {
769 $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>';
770 }
771 $html .= '</ul>';
772 }
773 return $html;
774 }
775
776
777 /**
778 * Get Excerpt Word
779 *
780 * @since v.1.0.0
781 * @param NUMBER | Character Length
782 * @return STRING
783 */
784 public function excerpt_word($charlength = 200) {
785 $html = '';
786 $charlength++;
787 $excerpt = get_the_excerpt();
788 if ( mb_strlen( $excerpt ) > $charlength ) {
789 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
790 $exwords = explode( ' ', $subex );
791 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
792 if ( $excut < 0 ) {
793 $html = mb_substr( $subex, 0, $excut );
794 } else {
795 $html = $subex;
796 }
797 $html .= '...';
798 } else {
799 $html = $excerpt;
800 }
801 return $html;
802 }
803
804
805 /**
806 * Get Taxonomy Lists
807 *
808 * @since v.1.0.0
809 * @param STRING | Taxonomy Slug
810 * @return ARRAY
811 */
812 public function taxonomy( $prams = 'category' ) {
813 $data = array();
814 $terms = get_terms( $prams, array(
815 'hide_empty' => false,
816 ));
817 if( !is_wp_error($terms) ){
818 foreach ($terms as $val) {
819 $data[urldecode_deep($val->slug)] = $val->name;
820 }
821 }
822 return $data;
823 }
824
825
826 /**
827 * Get Taxonomy Data Lists
828 *
829 * @since v.1.0.0
830 * @param OBJECT | Taxonomy Object
831 * @return ARRAY
832 */
833 public function get_tax_data($terms) {
834 $temp = array();
835 $image = '';
836 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
837 if( $thumbnail_id ){
838 $image = wp_get_attachment_url( $thumbnail_id );
839 }
840 $temp['url'] = get_term_link($terms);
841 $temp['name'] = $terms->name;
842 $temp['desc'] = $terms->description;
843 $temp['count'] = $terms->count;
844 $temp['image'] = $image;
845 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
846 $temp['color'] = $color ? $color : '#037fff';
847 return $temp;
848 }
849
850 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
851 $data = array();
852 if($type == 'child'){
853 $image = '';
854 if (!empty($catSlug)) {
855 foreach ($catSlug as $cat) {
856 $parent_term = get_term_by('slug', $cat, $tax_slug);
857 if (!empty($parent_term)) {
858 $term_data = get_terms($tax_slug, array(
859 'hide_empty' => true,
860 'parent' => $parent_term->term_id
861 ));
862 if (!empty($term_data)) {
863 foreach ($term_data as $terms) {
864 $data[] = $this->get_tax_data($terms);
865 }
866 }
867 }
868 }
869 }
870 } else if ($type == 'parent') {
871 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
872 if (!empty($term_data)) {
873 foreach ($term_data as $terms) {
874 $data[] = $this->get_tax_data($terms);
875 }
876 }
877 } else if ($type == 'custom') {
878 foreach ($catSlug as $cat) {
879 $terms = get_term_by('slug', $cat, $tax_slug);
880 if (!empty($terms)) {
881 $data[] = $this->get_tax_data($terms);
882 }
883 }
884 } else {
885 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
886 if (!empty($term_data)) {
887 foreach ($term_data as $terms) {
888 $data[] = $this->get_tax_data($terms);
889 }
890 }
891 }
892 return $data;
893 }
894
895
896 /**
897 * Get Next Previous HTML
898 *
899 * @since v.1.0.0
900 * @param OBJECT | Taxonomy Object
901 * @return STRING
902 */
903 public function next_prev() {
904 $html = '';
905 $html .= '<ul>';
906 $html .= '<li>';
907 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
908 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
909 $html .= '</a>';
910 $html .= '</li>';
911 $html .= '<li>';
912 $html .= '<a class="ultp-next-action">';
913 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
914 $html .= '</a>';
915 $html .= '</li>';
916 $html .= '</ul>';
917 return $html;
918 }
919
920
921 /**
922 * Get Loading HTML
923 *
924 * @since v.1.0.0
925 * @param NULL
926 * @return STRING
927 */
928 public function loading(){
929 $html = '';
930 $style = ultimate_post()->get_setting('preloader_style');
931 if( $style == 'style2' ){
932 $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
933 } else {
934 $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>';
935 }
936 return '<div class="ultp-loading">'.$html.'</div>';
937 }
938
939
940 /**
941 * Get Filter HTML
942 *
943 * @since v.1.0.0
944 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
945 * @return STRING
946 */
947 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterCat = [], $filterTag = []){
948 $html = '';
949 $html .= '<ul class="ultp-flex-menu">';
950
951 $filterType = $filterType == 'tag' ? 'post_tag' : $filterType; // for compatibility
952
953 $cat = $this->taxonomy($filterType);
954 if($filterText){
955 $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
956 }
957
958 $filterValue = strlen($filterValue) > 2 ? $filterValue : ($filterType == 'category' ? $filterCat : $filterTag);
959
960 foreach (json_decode($filterValue) as $val) {
961 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
962 }
963 $html .= '</ul>';
964 return $html;
965 }
966
967
968 /**
969 * Check License Status
970 *
971 * @since v.2.4.2
972 * @return BOOLEAN | Is pro license active or not
973 */
974 public function is_lc_active() {
975 if (function_exists('ultimate_post_pro')) {
976 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
977 }
978 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
979 return true;
980 }
981 return false;
982 }
983
984
985 /**
986 * Get SVG Icon
987 *
988 * @since v.1.0.0
989 * @param STRING | Icon Key
990 * @return STRING | Icon SVG
991 */
992 public function svg_icon($icons = ''){
993 $icon_lists = array(
994 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
995 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
996 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
997 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
998 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
999 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
1000 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
1001 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
1002 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
1003 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
1004 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
1005 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
1006 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
1007 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1008 );
1009 if($icons){
1010 return $icon_lists[ $icons ];
1011 }
1012 }
1013
1014 /**
1015 * Get SEO Meta
1016 *
1017 * @since v.2.4.3
1018 * @param NUMBER | Post ID
1019 * @return STRING | SEO Meta Description or Excerpt
1020 */
1021 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1022 $html = '';
1023 if ($showSeoMeta) {
1024 $str = '';
1025 if( function_exists('ultimate_post_pro') ) {
1026 if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1027 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1028 } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1029 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1030 } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1031 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1032 } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1033 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1034 } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1035 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1036 }
1037 }
1038 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1039 } else {
1040 if ( $showFullExcerpt == 0 ) {
1041 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1042 } else {
1043 $html = get_the_excerpt();
1044 }
1045 }
1046 return $html;
1047 }
1048
1049 }
1050