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

1,069 lines 39.8 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($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 = ''){
393 $alt = $alt ? ' alt="'.$alt.'" ' : '';
394 if( function_exists('ultimate_post_pro') ){
395 $addon_enable = ultimate_post()->get_setting('addons_imageloading');
396 if($addon_enable == 'true'){
397 $class = $class ? ' class="ultp-lazy '.$class.'" ' : ' class="ultp-lazy" ';
398 return '<img loading="lazy" loading="lazy" '.$class.$alt.' '.ultimate_post()->get_size($size).' src="'.ultimate_post()->img_placeholder($size).'" data-src="'.$url.'"/>';
399 }else{
400 $class = $class ? ' class="'.$class.'" ' : '';
401 return '<img loading="lazy" '.$class.$alt.' src="'.$url.'" />';
402 }
403 } else {
404 $class = $class ? ' class="'.$class.'" ' : '';
405 return '<img loading="lazy" '.$class.$alt.' src="'.$url.'" />';
406 }
407 }
408
409
410 /**
411 * Get Image HTML
412 *
413 * @since v.1.0.0
414 * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
415 * @return STRING
416 */
417 public function get_image($attach_id, $size = 'full', $class = '', $alt = ''){
418 $alt = $alt ? ' alt="'.$alt.'" ' : '';
419 $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
420 if( function_exists('ultimate_post_pro') ){
421 $addon_enable = ultimate_post()->get_setting('addons_imageloading');
422 if ($addon_enable == 'true') {
423 $class = $class ? ' class="ultp-lazy '.$class.'" ' : ' class="ultp-lazy" ';
424 return '<img loading="lazy" '.$class.$alt.' '.ultimate_post()->get_size($size).' src="'.ultimate_post()->img_placeholder($size).'" data-src="'.wp_get_attachment_image_url( $attach_id, $size ).'"/>';
425 } else {
426 $class = $class ? ' class="'.$class.'" ' : '';
427 return '<img loading="lazy" '.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
428 }
429 } else {
430 $class = $class ? ' class="'.$class.'" ' : '';
431 return '<img loading="lazy" '.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
432 }
433 }
434
435
436 /**
437 * Setup Initial Data Set
438 *
439 * @since v.1.0.0
440 * @return NULL
441 */
442 public function init_set_data(){
443 $data = get_option( 'ultp_options', array() );
444 $init_data = array(
445 'css_save_as' => 'wp_head',
446 'preloader_style' => 'style1',
447 'preloader_color' => '#037fff',
448 'container_width' => '1140',
449 'editor_container' => 'full_width',
450 'hide_import_btn' => '',
451 'disable_image_size'=> '',
452 'ultp_templates' => 'true',
453 'ultp_elementor' => 'true',
454 'ultp_table_of_content'=> 'true',
455 'post_grid_1' => 'yes',
456 'post_grid_2' => 'yes',
457 'post_grid_3' => 'yes',
458 'post_grid_4' => 'yes',
459 'post_grid_5' => 'yes',
460 'post_grid_6' => 'yes',
461 'post_grid_7' => 'yes',
462 'post_list_1' => 'yes',
463 'post_list_2' => 'yes',
464 'post_list_3' => 'yes',
465 'post_list_4' => 'yes',
466 'post_module_1' => 'yes',
467 'post_module_2' => 'yes',
468 'post_slider_1' => 'yes',
469 'heading' => 'yes',
470 'image' => 'yes',
471 'taxonomy' => 'yes',
472 'wrapper' => 'yes'
473 );
474 if (empty($data)) {
475 update_option('ultp_options', $init_data);
476 $GLOBALS['ultp_settings'] = $init_data;
477 } else {
478 foreach ($init_data as $key => $single) {
479 if (!isset($data[$key])) {
480 $data[$key] = $single;
481 }
482 }
483 update_option('ultp_options', $data);
484 $GLOBALS['ultp_settings'] = $data;
485 }
486 }
487
488
489 /**
490 * Get Excerpt Text
491 *
492 * @since v.1.0.0
493 * @param | Post ID (STRING) | Limit (NUMBER)
494 * @return STRING
495 */
496 public function excerpt( $post_id, $limit = 55 ) {
497 return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
498 }
499
500 public function get_builder_attr() {
501 $builder_data = '';
502 if (is_archive()) {
503 if (is_date()) {
504 if ( is_year() ) {
505 $builder_data = 'date###'.get_the_date('Y');
506 } else if ( is_month() ) {
507 $builder_data = 'date###'.get_the_date('Y-n');
508 } else if ( is_day() ) {
509 $builder_data = 'date###'.get_the_date('Y-n-j');
510 }
511 } else if (is_author()) {
512 $builder_data = 'author###'.get_the_author_meta('ID');
513 } else {
514 $obj = get_queried_object();
515 if (isset($obj->taxonomy)) {
516 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
517 }
518 }
519 } else if (is_search()) {
520 $builder_data = 'search###'.get_search_query(true);
521 }
522 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
523 }
524
525
526 public function is_builder($builder = '') {
527 $id = '';
528 if (function_exists('ultimate_post_pro')) {
529 if ($builder) {
530 return true;
531 }
532 $page_id = ultimate_post_pro()->conditions('return');
533 if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
534 $id = $page_id;
535 }
536 }
537 return $id;
538 }
539
540 /**
541 * Query Builder
542 *
543 * @since v.1.0.0
544 * @param ARRAY | Attribute of the Query
545 * @return ARRAY
546 */
547 public function get_query($attr) {
548 $archive_query = array();
549 $builder = isset($attr['builder']) ? $attr['builder'] : '';
550 if ($this->is_builder($builder)) {
551 if ($builder) {
552 $str = explode('###', $builder);
553 if (isset($str[0])) {
554 if ($str[0] == 'taxonomy') {
555 if (isset($str[1]) && isset($str[2])) {
556 $archive_query['tax_query'] = array(
557 array(
558 'taxonomy' => $str[1],
559 'field' => 'slug',
560 'terms' => $str[2]
561 )
562 );
563 }
564 } else if ($str[0] == 'author') {
565 if (isset($str[1])) {
566 $archive_query['author'] = $str[1];
567 }
568 } else if ($str[0] == 'search') {
569 if (isset($str[1])) {
570 $archive_query['s'] = $str[1];
571 }
572 } else if ($str[0] == 'date') {
573 if (isset($str[1])) {
574 $all_date = explode('-', $str[1]);
575 if (!empty($all_date)) {
576 $arg = array();
577 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
578 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
579 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
580 $archive_query['date_query'][] = $arg;
581 }
582 }
583 }
584 }
585 } else {
586 global $wp_query;
587 $archive_query = $wp_query->query_vars;
588 }
589 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
590 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
591 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
592 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
593 $archive_query = array_merge($archive_query, $offset);
594 }
595 $archive_query['post_status'] = 'publish';
596 return $archive_query;
597 }
598
599 $query_args = array(
600 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
601 'post_type' => isset($attr['queryType']) ? $attr['queryType'] : 'post',
602 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
603 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
604 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
605 'post_status' => 'publish'
606 );
607
608 if(isset($attr['queryOrderBy']) && isset($attr['metaKey'])){
609 if($attr['queryOrderBy'] == 'meta_value_num') {
610 $query_args['meta_key'] = $attr['metaKey'];
611 }
612 }
613
614 if(isset($attr['queryInclude']) && $attr['queryInclude']){
615 $query_args['post__in'] = explode(',', $attr['queryInclude']);
616 $query_args['ignore_sticky_posts'] = 1;
617 $query_args['orderby'] = 'post__in';
618 }
619
620 $exclude = '';
621 if (is_single()) {
622 $id = get_the_ID();
623 $exclude = $id ? $id : '';
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
635 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : ($attr['queryTax'] == 'category' ? $attr['queryCat'] : $attr['queryTag']);
636
637 if(strlen($tax_value) > 2){
638 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
639 $var = array('relation'=>$relation);
640 foreach (json_decode($tax_value) as $val) {
641 $tax_name = $attr['queryTax'] == 'tag' ? 'post_tag' : $attr['queryTax']; // for compatibility
642 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
643 }
644 if(count($var) > 1){
645 $query_args['tax_query'] = $var;
646 }
647 }
648 }
649 }
650
651 if(isset($attr['queryQuick'])){
652 if($attr['queryQuick'] != ''){
653 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
654 }
655 }
656
657 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
658 $offset = $this->get_offset($attr['queryOffset'], $query_args);
659 $query_args = array_merge($query_args, $offset);
660 }
661
662 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
663 $query_args['author'] = $attr['queryAuthor'];
664 }
665
666
667 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
668
669 return $query_args;
670 }
671
672 function get_offset($queryOffset, $query_args) {
673 $query = array();
674 if ($query_args['paged'] > 1) {
675 $offset_post = wp_get_recent_posts($query_args, OBJECT);
676 if ( count($offset_post) > 0 ) {
677 $offset = array();
678 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--){
679 $offset[] = $offset_post[$x-1]->ID;
680 }
681 $query['post__not_in'] = $offset;
682 }
683 } else {
684 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
685 }
686 return $query;
687 }
688
689
690 /**
691 * Get Page Number
692 *
693 * @since v.1.0.0
694 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
695 * @return ARRAY
696 */
697 public function get_page_number($attr, $post_number) {
698 if($post_number > 0){
699 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
700 $pages = ceil($post_number/$post_per_page);
701 return $pages ? $pages : 1;
702 }else{
703 return 1;
704 }
705 }
706
707
708 /**
709 * Get Image Size
710 *
711 * @since v.1.0.0
712 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
713 * @return ARRAY
714 */
715 public function get_image_size() {
716 $sizes = get_intermediate_image_sizes();
717 $filter = array('full' => 'Full');
718 foreach ($sizes as $value) {
719 $filter[$value] = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
720 }
721 return $filter;
722 }
723
724
725 /**
726 * Get All PostType Registered
727 *
728 * @since v.1.0.0
729 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
730 * @return ARRAY
731 */
732 public function get_post_type() {
733 $post_type = get_post_types( '', 'names' );
734 return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
735 }
736
737
738 /**
739 * Get Pagination HTML
740 *
741 * @since v.1.0.0
742 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
743 * @return STRING
744 */
745 public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
746 $html = '';
747 $showitems = 3;
748 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
749 $paged = $paged ? $paged : 1;
750 if($pages == '') {
751 global $wp_query;
752 $pages = $wp_query->max_num_pages;
753 if(!$pages) {
754 $pages = 1;
755 }
756 }
757 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
758
759 $paginationText = explode('|', $paginationText);
760
761 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
762 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
763
764 if(1 != $pages) {
765 $html .= '<ul class="ultp-pagination">';
766 $display_none = 'style="display:none"';
767 if($pages > 4) {
768 $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>';
769 }
770 if($pages > 4){
771 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
772 }
773 if($pages > 4){
774 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
775 }
776 foreach ($data as $i) {
777 if($pages >= $i){
778 $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>';
779 }
780 }
781 if($pages > 4){
782 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
783 }
784 if($pages > 4){
785 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
786 }
787 if ($paged != $pages) {
788 $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>';
789 }
790 $html .= '</ul>';
791 }
792 return $html;
793 }
794
795
796 /**
797 * Get Excerpt Word
798 *
799 * @since v.1.0.0
800 * @param NUMBER | Character Length
801 * @return STRING
802 */
803 public function excerpt_word($charlength = 200) {
804 $html = '';
805 $charlength++;
806 $excerpt = get_the_excerpt();
807 if ( mb_strlen( $excerpt ) > $charlength ) {
808 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
809 $exwords = explode( ' ', $subex );
810 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
811 if ( $excut < 0 ) {
812 $html = mb_substr( $subex, 0, $excut );
813 } else {
814 $html = $subex;
815 }
816 $html .= '...';
817 } else {
818 $html = $excerpt;
819 }
820 return $html;
821 }
822
823
824 /**
825 * Get Taxonomy Lists
826 *
827 * @since v.1.0.0
828 * @param STRING | Taxonomy Slug
829 * @return ARRAY
830 */
831 public function taxonomy( $prams = 'category' ) {
832 $data = array();
833 $terms = get_terms( $prams, array(
834 'hide_empty' => false,
835 ));
836 if( !is_wp_error($terms) ){
837 foreach ($terms as $val) {
838 $data[urldecode_deep($val->slug)] = $val->name;
839 }
840 }
841 return $data;
842 }
843
844
845 /**
846 * Get Taxonomy Data Lists
847 *
848 * @since v.1.0.0
849 * @param OBJECT | Taxonomy Object
850 * @return ARRAY
851 */
852 public function get_tax_data($terms) {
853 $temp = array();
854 $image = '';
855 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
856 if( $thumbnail_id ){
857 $image = wp_get_attachment_url( $thumbnail_id );
858 }
859 $temp['url'] = get_term_link($terms);
860 $temp['name'] = $terms->name;
861 $temp['desc'] = $terms->description;
862 $temp['count'] = $terms->count;
863 $temp['image'] = $image;
864 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
865 $temp['color'] = $color ? $color : '#037fff';
866 return $temp;
867 }
868
869 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
870 $data = array();
871 if($type == 'child'){
872 $image = '';
873 if (!empty($catSlug)) {
874 foreach ($catSlug as $cat) {
875 $parent_term = get_term_by('slug', $cat, $tax_slug);
876 if (!empty($parent_term)) {
877 $term_data = get_terms($tax_slug, array(
878 'hide_empty' => true,
879 'parent' => $parent_term->term_id
880 ));
881 if (!empty($term_data)) {
882 foreach ($term_data as $terms) {
883 $data[] = $this->get_tax_data($terms);
884 }
885 }
886 }
887 }
888 }
889 } else if ($type == 'parent') {
890 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
891 if (!empty($term_data)) {
892 foreach ($term_data as $terms) {
893 $data[] = $this->get_tax_data($terms);
894 }
895 }
896 } else if ($type == 'custom') {
897 foreach ($catSlug as $cat) {
898 $terms = get_term_by('slug', $cat, $tax_slug);
899 if (!empty($terms)) {
900 $data[] = $this->get_tax_data($terms);
901 }
902 }
903 } else {
904 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
905 if (!empty($term_data)) {
906 foreach ($term_data as $terms) {
907 $data[] = $this->get_tax_data($terms);
908 }
909 }
910 }
911 return $data;
912 }
913
914
915 /**
916 * Get Next Previous HTML
917 *
918 * @since v.1.0.0
919 * @param OBJECT | Taxonomy Object
920 * @return STRING
921 */
922 public function next_prev() {
923 $html = '';
924 $html .= '<ul>';
925 $html .= '<li>';
926 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
927 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
928 $html .= '</a>';
929 $html .= '</li>';
930 $html .= '<li>';
931 $html .= '<a class="ultp-next-action">';
932 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
933 $html .= '</a>';
934 $html .= '</li>';
935 $html .= '</ul>';
936 return $html;
937 }
938
939
940 /**
941 * Get Loading HTML
942 *
943 * @since v.1.0.0
944 * @param NULL
945 * @return STRING
946 */
947 public function loading(){
948 $html = '';
949 $style = ultimate_post()->get_setting('preloader_style');
950 if( $style == 'style2' ){
951 $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
952 } else {
953 $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>';
954 }
955 return '<div class="ultp-loading">'.$html.'</div>';
956 }
957
958
959 /**
960 * Get Filter HTML
961 *
962 * @since v.1.0.0
963 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
964 * @return STRING
965 */
966 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterCat = [], $filterTag = []){
967 $html = '';
968 $html .= '<ul class="ultp-flex-menu">';
969
970 $filterType = $filterType == 'tag' ? 'post_tag' : $filterType; // for compatibility
971
972 $cat = $this->taxonomy($filterType);
973 if($filterText){
974 $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
975 }
976
977 $filterValue = strlen($filterValue) > 2 ? $filterValue : ($filterType == 'category' ? $filterCat : $filterTag);
978
979 foreach (json_decode($filterValue) as $val) {
980 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
981 }
982 $html .= '</ul>';
983 return $html;
984 }
985
986
987 /**
988 * Check License Status
989 *
990 * @since v.2.4.2
991 * @return BOOLEAN | Is pro license active or not
992 */
993 public function is_lc_active() {
994 if (function_exists('ultimate_post_pro')) {
995 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
996 }
997 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
998 return true;
999 }
1000 return false;
1001 }
1002
1003
1004 /**
1005 * Get SVG Icon
1006 *
1007 * @since v.1.0.0
1008 * @param STRING | Icon Key
1009 * @return STRING | Icon SVG
1010 */
1011 public function svg_icon($icons = ''){
1012 $icon_lists = array(
1013 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
1014 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
1015 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
1016 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
1017 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
1018 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
1019 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
1020 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
1021 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
1022 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
1023 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
1024 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
1025 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
1026 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1027 );
1028 if($icons){
1029 return $icon_lists[ $icons ];
1030 }
1031 }
1032
1033 /**
1034 * Get SEO Meta
1035 *
1036 * @since v.2.4.3
1037 * @param NUMBER | Post ID
1038 * @return STRING | SEO Meta Description or Excerpt
1039 */
1040 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1041 $html = '';
1042 if ($showSeoMeta) {
1043 $str = '';
1044 if( function_exists('ultimate_post_pro') ) {
1045 if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1046 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1047 } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1048 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1049 } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1050 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1051 } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1052 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1053 } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1054 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1055 }
1056 }
1057 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1058 } else {
1059 if ( $showFullExcerpt == 0 ) {
1060 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1061 } else {
1062 $html = get_the_excerpt();
1063 }
1064 }
1065 return $html;
1066 }
1067
1068 }
1069