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

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