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

958 lines 34.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 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
592
593 return $query_args;
594 }
595
596 function get_offset($queryOffset, $query_args) {
597 $query = array();
598 if ($query_args['paged'] > 1) {
599 $offset_post = wp_get_recent_posts($query_args, OBJECT);
600 if ( count($offset_post) > 0 ) {
601 $offset = array();
602 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--){
603 $offset[] = $offset_post[$x-1]->ID;
604 }
605 $query['post__not_in'] = $offset;
606 }
607 } else {
608 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
609 }
610 return $query;
611 }
612
613
614 /**
615 * Get Page Number
616 *
617 * @since v.1.0.0
618 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
619 * @return ARRAY
620 */
621 public function get_page_number($attr, $post_number) {
622 if($post_number > 0){
623 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
624 $pages = ceil($post_number/$post_per_page);
625 return $pages ? $pages : 1;
626 }else{
627 return 1;
628 }
629 }
630
631
632 /**
633 * Get Image Size
634 *
635 * @since v.1.0.0
636 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
637 * @return ARRAY
638 */
639 public function get_image_size() {
640 $sizes = get_intermediate_image_sizes();
641 $filter = array('full' => 'Full');
642 foreach ($sizes as $value) {
643 $filter[$value] = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
644 }
645 return $filter;
646 }
647
648
649 /**
650 * Get All PostType Registered
651 *
652 * @since v.1.0.0
653 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
654 * @return ARRAY
655 */
656 public function get_post_type() {
657 $post_type = get_post_types( '', 'names' );
658 return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
659 }
660
661
662 /**
663 * Get Pagination HTML
664 *
665 * @since v.1.0.0
666 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
667 * @return STRING
668 */
669 public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
670 $html = '';
671 $showitems = 3;
672 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
673 $paged = $paged ? $paged : 1;
674 if($pages == '') {
675 global $wp_query;
676 $pages = $wp_query->max_num_pages;
677 if(!$pages) {
678 $pages = 1;
679 }
680 }
681 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
682
683 $paginationText = explode('|', $paginationText);
684
685 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
686 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
687
688 if(1 != $pages) {
689 $html .= '<ul class="ultp-pagination">';
690 $display_none = 'style="display:none"';
691 if($pages > 4) {
692 $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>';
693 }
694 if($pages > 4){
695 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
696 }
697 if($pages > 4){
698 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
699 }
700 foreach ($data as $i) {
701 if($pages >= $i){
702 $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>';
703 }
704 }
705 if($pages > 4){
706 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
707 }
708 if($pages > 4){
709 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
710 }
711 if ($paged != $pages) {
712 $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>';
713 }
714 $html .= '</ul>';
715 }
716 return $html;
717 }
718
719
720 /**
721 * Get Excerpt Word
722 *
723 * @since v.1.0.0
724 * @param NUMBER | Character Length
725 * @return STRING
726 */
727 public function excerpt_word($charlength = 200) {
728 $html = '';
729 $charlength++;
730 $excerpt = get_the_excerpt();
731 if ( mb_strlen( $excerpt ) > $charlength ) {
732 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
733 $exwords = explode( ' ', $subex );
734 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
735 if ( $excut < 0 ) {
736 $html = mb_substr( $subex, 0, $excut );
737 } else {
738 $html = $subex;
739 }
740 $html .= '...';
741 } else {
742 $html = $excerpt;
743 }
744 return $html;
745 }
746
747
748 /**
749 * Get Taxonomy Lists
750 *
751 * @since v.1.0.0
752 * @param STRING | Taxonomy Slug
753 * @return ARRAY
754 */
755 public function taxonomy( $prams = 'category' ) {
756 $data = array();
757 $terms = get_terms( $prams, array(
758 'hide_empty' => false,
759 ));
760 if( !is_wp_error($terms) ){
761 foreach ($terms as $val) {
762 $data[urldecode_deep($val->slug)] = $val->name;
763 }
764 }
765 return $data;
766 }
767
768
769 /**
770 * Get Taxonomy Data Lists
771 *
772 * @since v.1.0.0
773 * @param OBJECT | Taxonomy Object
774 * @return ARRAY
775 */
776 public function get_tax_data($terms) {
777 $temp = array();
778 $image = '';
779 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
780 if( $thumbnail_id ){
781 $image = wp_get_attachment_url( $thumbnail_id );
782 }
783 $temp['url'] = get_term_link($terms);
784 $temp['name'] = $terms->name;
785 $temp['desc'] = $terms->description;
786 $temp['count'] = $terms->count;
787 $temp['image'] = $image;
788 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
789 $temp['color'] = $color == 1 ? '#037fff' : $color;
790 return $temp;
791 }
792
793 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
794 $data = array();
795 if($type == 'child'){
796 $image = '';
797 if (!empty($catSlug)) {
798 foreach ($catSlug as $cat) {
799 $parent_term = get_term_by('slug', $cat, $tax_slug);
800 if (!empty($parent_term)) {
801 $term_data = get_terms($tax_slug, array(
802 'hide_empty' => true,
803 'parent' => $parent_term->term_id
804 ));
805 if (!empty($term_data)) {
806 foreach ($term_data as $terms) {
807 $data[] = $this->get_tax_data($terms);
808 }
809 }
810 }
811 }
812 }
813 } else if ($type == 'parent') {
814 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
815 if (!empty($term_data)) {
816 foreach ($term_data as $terms) {
817 $data[] = $this->get_tax_data($terms);
818 }
819 }
820 } else if ($type == 'custom') {
821 foreach ($catSlug as $cat) {
822 $terms = get_term_by('slug', $cat, $tax_slug);
823 if (!empty($terms)) {
824 $data[] = $this->get_tax_data($terms);
825 }
826 }
827 } else {
828 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
829 if (!empty($term_data)) {
830 foreach ($term_data as $terms) {
831 $data[] = $this->get_tax_data($terms);
832 }
833 }
834 }
835 return $data;
836 }
837
838
839 /**
840 * Get Next Previous HTML
841 *
842 * @since v.1.0.0
843 * @param OBJECT | Taxonomy Object
844 * @return STRING
845 */
846 public function next_prev() {
847 $html = '';
848 $html .= '<ul>';
849 $html .= '<li>';
850 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
851 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
852 $html .= '</a>';
853 $html .= '</li>';
854 $html .= '<li>';
855 $html .= '<a class="ultp-next-action">';
856 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
857 $html .= '</a>';
858 $html .= '</li>';
859 $html .= '</ul>';
860 return $html;
861 }
862
863
864 /**
865 * Get Loading HTML
866 *
867 * @since v.1.0.0
868 * @param NULL
869 * @return STRING
870 */
871 public function loading(){
872 $html = '';
873 $style = ultimate_post()->get_setting('preloader_style');
874 if( $style == 'style2' ){
875 $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
876 } else {
877 $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>';
878 }
879 return '<div class="ultp-loading">'.$html.'</div>';
880 }
881
882
883 /**
884 * Get Filter HTML
885 *
886 * @since v.1.0.0
887 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
888 * @return STRING
889 */
890 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterCat = [], $filterTag = []){
891 $html = '';
892 $html .= '<ul class="ultp-flex-menu">';
893
894 $filterType = $filterType == 'tag' ? 'post_tag' : $filterType; // for compatibility
895
896 $cat = $this->taxonomy($filterType);
897 if($filterText){
898 $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
899 }
900
901 $filterValue = strlen($filterValue) > 2 ? $filterValue : ($filterType == 'category' ? $filterCat : $filterTag);
902
903 foreach (json_decode($filterValue) as $val) {
904 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
905 }
906 $html .= '</ul>';
907 return $html;
908 }
909
910
911 /**
912 * Check License Status
913 *
914 * @since v.2.4.2
915 * @return BOOLEAN | Is pro license active or not
916 */
917 public function is_lc_active() {
918 if (function_exists('ultimate_post_pro')) {
919 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
920 }
921 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
922 return true;
923 }
924 return false;
925 }
926
927
928 /**
929 * Get SVG Icon
930 *
931 * @since v.1.0.0
932 * @param STRING | Icon Key
933 * @return STRING | Icon SVG
934 */
935 public function svg_icon($icons = ''){
936 $icon_lists = array(
937 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
938 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
939 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
940 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
941 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
942 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
943 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
944 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
945 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
946 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
947 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
948 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
949 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
950 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
951 );
952 if($icons){
953 return $icon_lists[ $icons ];
954 }
955 }
956
957 }
958