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

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