PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.2.7
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.2.7
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Helpers / Fns.php
the-post-grid / app / Helpers Last commit date
Fns.php 3 years ago Install.php 3 years ago Options.php 3 years ago
Fns.php
4030 lines
1 <?php
2 /**
3 * Helper class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Helpers;
9
10 use RT\ThePostGrid\Models\Field;
11 use RT\ThePostGrid\Models\ReSizer;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Helper class.
20 */
21 class Fns {
22
23 /**
24 * Get Ajax URL.
25 *
26 * @return string
27 */
28 public function ajax_url() {
29 return admin_url( 'admin-ajax.php', 'relative' );
30 }
31
32
33 /**
34 * Render view
35 *
36 * @param string $viewName View name.
37 * @param array $args Args.
38 * @param boolean $return Include/return.
39 *
40 * @return string
41 */
42 public static function view( $viewName, $args = [], $return = false ) {
43 $file = str_replace( '.', '/', $viewName );
44 $file = ltrim( $file, '/' );
45 $viewFile = trailingslashit( RT_THE_POST_GRID_PLUGIN_PATH . '/resources' ) . $file . '.php';
46
47 if ( ! file_exists( $viewFile ) ) {
48 return new \WP_Error(
49 'brock',
50 sprintf(
51 /* translators: %s File name */
52 esc_html__( '%s file not found', 'the-post-grid' ),
53 $viewFile
54 )
55 );
56 }
57
58 if ( $args ) {
59 extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
60 }
61
62 if ( $return ) {
63 ob_start();
64 include $viewFile;
65
66 return ob_get_clean();
67 }
68
69 include $viewFile;
70 }
71
72 /**
73 * Update post view
74 *
75 * @param integer $post_id Listing ID.
76 *
77 * @return void
78 */
79 public static function update_post_views_count( $post_id ) {
80
81 if ( ! $post_id && is_admin() ) {
82 return;
83 }
84
85 $user_ip = sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // retrieve the current IP address of the visitor.
86 $key = 'tpg_cache_' . $user_ip . '_' . $post_id;
87 $value = [ $user_ip, $post_id ];
88 $visited = get_transient( $key );
89
90
91 if ( false === ( $visited ) ) {
92 //set_transient( $key, $value, HOUR_IN_SECONDS * 12 ); // store the unique key, Post ID & IP address for 12 hours if it does not exist.
93 set_transient( $key, $value, HOUR_IN_SECONDS * 12 ); // store the unique key, Post ID & IP address for 12 hours if it does not exist.
94
95 // now run post views function.
96 $count_key = self::get_post_view_count_meta_key();
97 $count = get_post_meta( $post_id, $count_key, true );
98
99 if ( '' == $count ) {
100 update_post_meta( $post_id, $count_key, 1 );
101 } else {
102 $count = absint( $count );
103 $count ++;
104
105 update_post_meta( $post_id, $count_key, $count );
106 }
107 }
108 }
109
110 /**
111 * Template Content
112 *
113 * @param string $template_name Template name.
114 * @param array $args Arguments. (default: array).
115 * @param string $template_path Template path. (default: '').
116 * @param string $default_path Default path. (default: '').
117 */
118 public static function get_template( $template_name, $args = null, $template_path = '', $default_path = '' ) {
119 if ( ! empty( $args ) && is_array( $args ) ) {
120 extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
121 }
122
123 $located = self::locate_template( $template_name, $template_path, $default_path );
124
125 if ( ! file_exists( $located ) ) {
126 /* translators: %s template */
127 self::doing_it_wrong( __FUNCTION__, sprintf( esc_html__( '%s does not exist.', 'the-post-grid' ), '<code>' . $located . '</code>' ), '1.0' );
128
129 return;
130 }
131
132 // Allow 3rd party plugin filter template file from their plugin.
133 $located = apply_filters( 'rttpg_get_template', $located, $template_name, $args );
134
135 do_action( 'rttpg_before_template_part', $template_name, $located, $args );
136
137 include $located;
138
139 do_action( 'rttpg_after_template_part', $template_name, $located, $args );
140 }
141
142 /**
143 * Get template content and return
144 *
145 * @param string $template_name Template name.
146 * @param array $args Arguments. (default: array).
147 * @param string $template_path Template path. (default: '').
148 * @param string $default_path Default path. (default: '').
149 *
150 * @return string
151 */
152 public static function get_template_html( $template_name, $args = [], $template_path = '', $default_path = '' ) {
153 ob_start();
154 self::get_template( $template_name, $args, $template_path, $default_path );
155
156 return ob_get_clean();
157 }
158
159 /**
160 * Locate template.
161 *
162 * @param string $template_name Template.
163 * @param string $template_path Path.
164 * @param string $default_path Default path.
165 *
166 * @return mixed|void
167 */
168 public static function locate_template( $template_name, $template_path = '', $default_path = '' ) {
169 $template_name = $template_name . '.php';
170
171 if ( ! $template_path ) {
172 $template_path = rtTPG()->get_template_path();
173 }
174
175 if ( ! $default_path ) {
176 $default_path = rtTPG()->default_template_path() . '/templates/';
177 }
178
179 // Look within passed path within the theme - this is priority.
180 $template_files = [];
181 $template_files[] = trailingslashit( $template_path ) . $template_name;
182
183 $template = locate_template( apply_filters( 'rttpg_locate_template_files', $template_files, $template_name, $template_path, $default_path ) );
184
185 // Get default template/.
186 if ( ! $template ) {
187 $template = trailingslashit( $default_path ) . $template_name;
188 }
189
190 return apply_filters( 'rttpg_locate_template', $template, $template_name );
191 }
192
193 /**
194 * Mark something as being incorrectly called.
195 *
196 * @param string $function — The function that was called.
197 * @param string $message — A message explaining what has been done incorrectly.
198 * @param string $version — The version of WordPress where the message was added.
199 *
200 * @return void
201 */
202 public static function doing_it_wrong( $function, $message, $version ) {
203 // phpcs:disable
204 $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
205 _doing_it_wrong( $function, $message, $version );
206 // phpcs:enable
207 }
208
209 /**
210 * Verify nonce.
211 *
212 * @return bool
213 */
214 public static function verifyNonce() {
215 $nonce = isset( $_REQUEST[ rtTPG()->nonceId() ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ rtTPG()->nonceId() ] ) ) : null;
216 $nonceText = rtTPG()->nonceText();
217
218 if ( ! wp_verify_nonce( $nonce, $nonceText ) ) {
219 return false;
220 }
221
222 return true;
223 }
224
225 /**
226 * @param $data
227 * @param $temp_path
228 *
229 * @return void
230 */
231 public static function tpg_template( $data, $temp_path = 'elementor' ) {
232 $layout = str_replace( '-2', '', $data['layout'] );
233
234 $template_name = '/the-post-grid/' . $temp_path . '/' . $layout . '.php';
235 if ( file_exists( STYLESHEETPATH . $template_name ) ) {
236 $file = STYLESHEETPATH . $template_name;
237 } else if ( file_exists( TEMPLATEPATH . $template_name ) ) {
238 $file = TEMPLATEPATH . $template_name;
239 } else {
240 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php';
241 if ( ! file_exists( $file ) ) {
242 if ( rtTPG()->hasPro() ) {
243 $file = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php';
244 } else {
245 $layout = substr( $layout, 0, - 1 );
246 $layout = strpos( $layout, '1' ) ? str_replace( '1', '', $layout ) : $layout;
247 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '1.php';
248 }
249 }
250 }
251
252 ob_start();
253 include $file;
254 echo ob_get_clean();
255 }
256
257 /**
258 * @param $data
259 *
260 * @return string
261 */
262 public static function tpg_template_path( $data, $temp_path = 'elementor' ) {
263 $layout = str_replace( '-2', '', $data['layout'] );
264 $template_name = '/the-post-grid/' . $temp_path . '/' . $layout . '.php';
265 $path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/';
266 if ( file_exists( STYLESHEETPATH . $template_name ) ) {
267 $path = STYLESHEETPATH . '/the-post-grid/' . $temp_path . '/';
268 } else if ( file_exists( TEMPLATEPATH . $template_name ) ) {
269 $path = TEMPLATEPATH . '/the-post-grid/' . $temp_path . '/';
270 } else {
271 $template_path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php';
272
273 if ( ! file_exists( $template_path ) && rtTPG()->hasPro() ) {
274 $path = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/' . $temp_path . '/';
275 }
276 }
277
278 return $path;
279 }
280
281 /**
282 * Get Post Pagination, Load more & Scroll markup
283 *
284 * @param $query
285 * @param $data
286 *
287 * @return false|string|void
288 */
289 public static function get_pagination_markup( $query, $data ) {
290 if ( 'show' !== $data['show_pagination'] ) {
291 return;
292 }
293
294 $htmlUtility = null;
295
296 $posts_loading_type = $data['pagination_type'];
297
298 $posts_per_page = ( isset( $data['display_per_page'] ) && $data['display_per_page'] ) ? $data['display_per_page']
299 : ( $data['post_limit'] ? $data['post_limit'] : get_option( 'posts_per_page' ) );
300 $hide = ( $query->max_num_pages < 2 ? " rt-hidden-elm" : null );
301
302 if ( $posts_loading_type == "pagination" ) {
303 $htmlUtility .= Fns::rt_pagination( $query, $posts_per_page );
304 } else if ( rtTPG()->hasPro() && $posts_loading_type == "pagination_ajax" ) { //&& ! $isIsotope
305 $htmlUtility .= "<div class='rt-page-numbers'></div>";
306 } else if ( rtTPG()->hasPro() && $posts_loading_type == "load_more" ) {
307 $load_more_button_text = $data['load_more_button_text'] ? $data['load_more_button_text'] : __( "Load More", 'the-post-grid' );
308 $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style{$hide}'>
309 <span class='rt-loadmore-text'>" . $load_more_button_text . "</span>
310 <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div>
311 </div>";
312 } else if ( rtTPG()->hasPro() && $posts_loading_type == "load_on_scroll" ) {
313 $htmlUtility .= "<div class='rt-infinite-action'>
314 <div class='rt-infinite-loading la-fire la-2x'>
315 <div></div><div></div><div></div>
316 </div>
317 </div>";
318 }
319
320 if ( $htmlUtility ) {
321 $html = "<div class='rt-pagination-wrap' data-total-pages='{$query->max_num_pages}' data-posts-per-page='{$posts_per_page}' data-type='{$posts_loading_type}' >"
322 . $htmlUtility . "</div>";
323
324 return $html;
325 }
326
327 return false;
328 }
329
330 /**
331 * @param $data
332 * @param $total_pages
333 * @param $posts_per_page
334 * @param $_prefix
335 * @param $is_gutenberg
336 *
337 * @return array
338 */
339 public static function get_render_data_set( $data, $total_pages, $posts_per_page, $_prefix, $is_gutenberg = '' ) {
340
341 $data_set = [
342 'block_type' => 'elementor',
343 'is_gutenberg' => $is_gutenberg,
344 'prefix' => $_prefix,
345 'grid_column' => $data[ $_prefix . '_column' ] ?? '0',
346 'grid_column_tablet' => $data[ $_prefix . '_column_tablet' ] ?? '0',
347 'grid_column_mobile' => $data[ $_prefix . '_column_mobile' ] ?? '0',
348 'layout' => $data[ $_prefix . '_layout' ],
349 'pagination_type' => 'slider' === $_prefix ? 'slider' : $data['pagination_type'],
350 'total_pages' => $total_pages,
351 'posts_per_page' => $posts_per_page,
352 'layout_style' => $data[ $_prefix . '_layout_style' ] ?? '',
353 'show_title' => $data['show_title'],
354 'excerpt_type' => $data['excerpt_type'],
355 'excerpt_limit' => $data['excerpt_limit'],
356 'excerpt_more_text' => $data['excerpt_more_text'],
357 'title_limit' => $data['title_limit'],
358 'title_limit_type' => $data['title_limit_type'],
359 'title_visibility_style' => $data['title_visibility_style'],
360 'post_link_type' => $data['post_link_type'],
361 'link_target' => $data['link_target'],
362 'hover_animation' => $data['hover_animation'] ?? '',
363 'show_thumb' => $data['show_thumb'],
364 'show_meta' => $data['show_meta'],
365 'show_author' => $data['show_author'],
366 'show_author_image' => $data['show_author_image'],
367 'author_icon_visibility' => $data['author_icon_visibility'],
368 'show_meta_icon' => $data['show_meta_icon'],
369 'show_category' => $data['show_category'],
370 'show_date' => $data['show_date'],
371 'show_tags' => $data['show_tags'],
372 'show_comment_count' => $data['show_comment_count'],
373 'show_comment_count_label' => $data['show_comment_count_label'] ?? '',
374 'comment_count_label_singular' => $data['comment_count_label_singular'] ?? '',
375 'comment_count_label_plural' => $data['comment_count_label_plural'] ?? '',
376 'show_post_count' => $data['show_post_count'],
377 'post_count_icon' => $data['post_count_icon'] ?? '',
378 'show_excerpt' => $data['show_excerpt'],
379 'show_read_more' => $data['show_read_more'],
380 'show_btn_icon' => $data['show_btn_icon'],
381 'show_social_share' => $data['show_social_share'],
382 'show_cat_icon' => $data['show_cat_icon'] ?? '',
383 'is_thumb_linked' => $data['is_thumb_linked'],
384 'media_source' => $data['media_source'],
385 'no_posts_found_text' => isset( $data['no_posts_found_text'] ) ? esc_html( $data['no_posts_found_text'] ) : '',
386 'image_size' => $data['image_size'],
387 'image_offset' => $data['image_offset_size'],
388 'is_default_img' => $data['is_default_img'],
389 'default_image' => $data['default_image'],
390 'thumb_overlay_visibility' => $data['thumb_overlay_visibility'] ?? '',
391 'overlay_type' => $data['overlay_type'] ?? '',
392 'title_tag' => $data['title_tag'],
393 'post_type' => $data['post_type'],
394 'meta_separator' => $data['meta_separator'],
395 'readmore_icon_position' => $data['readmore_icon_position'],
396 'read_more_label' => $data['read_more_label'],
397 'readmore_btn_icon' => $data['readmore_btn_icon'],
398 'category_position' => $data['category_position'],
399 'title_position' => $data['title_position'] ?? 'default',
400 'category_style' => $data['category_style'] ?? '',
401 'is_thumb_lightbox' => $data['is_thumb_lightbox'],
402 'author_prefix' => $data['author_prefix'],
403 'cat_icon' => $data['cat_icon'] ?? '',
404 'tag_icon' => $data['tag_icon'] ?? '',
405 'date_icon' => $data['date_icon'] ?? '',
406 'user_icon' => $data['user_icon'] ?? '',
407 'meta_ordering' => $data['meta_ordering'],
408 'comment_icon' => $data['comment_icon'] ?? '',
409 'image_custom_dimension' => ( $data['image_size'] == 'custom' && isset( $data['image_custom_dimension'] ) ) ? $data['image_custom_dimension'] : [],
410 'img_crop_style' => ( $data['image_size'] == 'custom' && isset( $data['img_crop_style'] ) ) ? $data['img_crop_style'] : '',
411 'show_acf' => $data['show_acf'] ?? '',
412 'search_by' => $data['search_by'] ?? '',
413 ];
414
415 $cf = Fns::is_acf();
416 if ( $cf && rtTPG()->hasPro() ) {
417 $post_type = $data['post_type'];
418 if ( $is_gutenberg && isset( $data['acf_data_lists'][ $post_type . '_cf_group' ] ) ) {
419 $cf_group = $data['acf_data_lists'][ $post_type . '_cf_group' ]['options'];
420 $data_set['cf_group'] = wp_list_pluck( $cf_group, 'value' );
421 } else {
422 $data_set['cf_group'] = $data[ $post_type . '_cf_group' ];
423 }
424 $data_set['cf_hide_empty_value'] = $data['cf_hide_empty_value'];
425 $data_set['cf_show_only_value'] = $data['cf_show_only_value'];
426 $data_set['cf_hide_group_title'] = $data['cf_hide_group_title'];
427 }
428 if ( $is_gutenberg ) {
429 unset( $data_set['grid_column'] );
430 unset( $data_set['grid_column_mobile'] );
431 unset( $data_set['grid_column_mobile'] );
432 unset( $data_set['layout_style'] );
433 $data_set['c_image_width'] = $data['c_image_width'] ?? '';
434 $data_set['c_image_height'] = $data['c_image_height'] ?? '';
435 $data_set['grid_column'] = (array) $data['grid_column'];
436 $data_set['layout_style'] = $data['grid_layout_style'];
437 }
438
439 return $data_set;
440 }
441
442
443 /**
444 * Get Filter markup
445 *
446 * @param $data
447 *
448 * @return string
449 */
450 public static function get_frontend_filter_markup( $data, $is_guten = false ) {
451 if ( ! rtTPG()->hasPro()
452 || ! ( $data['show_taxonomy_filter'] == 'show' || $data['show_author_filter'] == 'show' || $data['show_order_by'] == 'show'
453 || $data['show_sort_order'] == 'show'
454 || $data['show_search'] == 'show' )
455 ) {
456 return;
457 }
458
459 $html = null;
460 $wrapperContainer = $wrapperClass = $itemClass = $filter_btn_item_per_page = '';
461
462 if ( 'carousel' === $data['filter_btn_style'] ) {
463 $wrapperContainer = 'swiper';
464 $wrapperClass = 'swiper-wrapper';
465 $itemClass = 'swiper-slide';
466 $filter_btn_mobile = isset( $data['filter_btn_item_per_page_mobile'] ) ? $data['filter_btn_item_per_page_mobile'] : 'auto';
467 $filter_btn_tablet = isset( $data['filter_btn_item_per_page_tablet'] ) ? $data['filter_btn_item_per_page_tablet'] : 'auto';
468 $filter_btn_item_per_page
469 = "data-per-page = '{$data['filter_btn_item_per_page']}' data-per-page-mobile = '{$filter_btn_mobile}' data-per-tablet = '{$filter_btn_tablet}'";
470 }
471
472 $html .= "<div class='rt-layout-filter-container rt-clear'><div class='rt-filter-wrap'>";
473
474 if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) {
475 $html .= "<div class='filter-left-wrapper {$wrapperContainer}' {$filter_btn_item_per_page}>";
476 }
477 // if($data['filter_btn_style'] == 'carousel') {
478 // $html .= "<div class='swiper-pagination'></div>";
479 // }
480 $selectedSubTermsForButton = null;
481
482 $filterType = $data['filter_type'];
483 $post_count = ( 'yes' == $data['filter_post_count'] ) ? true : false;
484
485
486 if ( 'show' == $data['show_taxonomy_filter'] ) {
487 $postCountClass = ( $post_count ? " has-post-count" : null );
488 $allSelect = " selected";
489 $isTermSelected = false;
490
491 $taxFilterOperator = $data['relation'];
492
493 $taxonomy_label = $default_term = '';
494 if ( $is_guten ) {
495 $taxFilter = $data['filter_taxonomy'];
496 } else {
497 $section_term_key = $data['post_type'] . '_filter_taxonomy';
498 $taxFilter = $data[ $section_term_key ];
499 }
500
501 if ( $taxFilter ) {
502 $taxonomy_details = get_taxonomy( $taxFilter );
503 $taxonomy_label = $taxonomy_details->label;
504 $default_term_key = $taxFilter . '_default_terms';
505 $default_term = isset( $data[ $default_term_key ] ) ? $data[ $default_term_key ] : '';
506 }
507
508 $allText = $data['tax_filter_all_text'] ? $data['tax_filter_all_text'] : __( "All ", "the-post-grid" ) . $taxonomy_label;
509
510
511 $_taxonomies = get_object_taxonomies( $data['post_type'], 'objects' );
512 $terms = [];
513
514 foreach ( $_taxonomies as $index => $object ) {
515 if ( $object->name != $taxFilter ) {
516 continue;
517 }
518 $setting_key = $object->name . '_ids';
519
520 if ( $is_guten && ! empty( $data['taxonomy_lists'][ $object->name ]['options'] ) ) {
521 //This block execute if gutenberg editor has taxonomy query
522 $terms = wp_list_pluck( $data['taxonomy_lists'][ $object->name ]['options'], 'value' );
523 } else if ( ! empty( $data[ $setting_key ] ) ) {
524 //This block execute for Elementor editor has taxonomy query
525 $terms = $data[ $setting_key ];
526 } else {
527 //Execute if there is no taxonomy query
528 $terms = get_terms( [
529 'taxonomy' => $taxFilter,
530 'fields' => 'ids',
531 ] );
532 }
533 }
534
535 $taxFilterTerms = $terms;
536
537 if ( $default_term && $taxFilter ) {
538 $isTermSelected = true;
539 $allSelect = null;
540 }
541
542 if ( $filterType == 'dropdown' ) {
543 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>";
544 $termDefaultText = $allText;
545 $dataTerm = 'all';
546 $htmlButton = "";
547 $selectedSubTerms = null;
548 $pCount = 0;
549
550
551 if ( ! empty( $terms ) ) {
552 $i = 0;
553 foreach ( $terms as $term_id ) {
554 $term = get_term( $term_id, $taxFilter, ARRAY_A );
555 $id = $term['term_id'];
556 $pCount = $pCount + $term['count'];
557 $sT = null;
558 if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' ) {
559 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
560 if ( ! empty( $subTerms ) ) {
561 $count = 0;
562 $item = $allCount = null;
563 foreach ( $subTerms as $stId => $t ) {
564 $count = $count + absint( $t['count'] );
565 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
566 $item .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$stId}'><span class='rt-text'>{$t['name']}{$sTPostCount}</span></span>";
567 }
568 if ( $post_count ) {
569 $allCount = " (<span class='rt-post-count'>{$count}</span>)";
570 }
571 $sT .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap sub-dropdown-wrap{$postCountClass}'>";
572 $sT .= "<span class='term-default rt-filter-dropdown-default' data-term='{$id}'>
573 <span class='rt-text'>" . $allText . "</span>
574 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
575 </span>";
576 $sT .= '<span class="term-dropdown rt-filter-dropdown">';
577 $sT .= $item;
578 $sT .= '</span>';
579 $sT .= "</div>";
580 }
581 if ( $default_term === $id ) {
582 $selectedSubTerms = $sT;
583 }
584 }
585 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
586 if ( $default_term && $default_term == $id ) {
587 $termDefaultText = $term['name'] . $postCount;
588 $dataTerm = $id;
589 }
590 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
591 if ( in_array( $id, $taxFilterTerms ) ) {
592 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
593 }
594 } else {
595 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
596 }
597 $i ++;
598 }
599 }
600 $pAllCount = null;
601 if ( $post_count ) {
602 $pAllCount = " (<span class='rt-post-count'>{$pCount}</span>)";
603 if ( ! $default_term ) {
604 $termDefaultText = $termDefaultText;
605 }
606 }
607
608 if ( 'yes' == $data['tpg_hide_all_button'] ) {
609 $htmlButton = "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'><span class='rt-text'>" . $allText . "</span></span>"
610 . $htmlButton;
611 }
612 $htmlButton = sprintf( '<span class="term-dropdown rt-filter-dropdown">%s</span>', $htmlButton );
613
614 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataTerm . '">
615 <span class="rt-text">' . $termDefaultText . '</span>
616 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
617 </span>';
618
619 $html .= $showAllhtml . $htmlButton;
620 $html .= '</div>' . $selectedSubTerms;
621 } else {
622 //if Button the execute
623 //$termDefaultText = $allText;
624
625 $bCount = 0;
626 $bItems = null;
627
628 if ( ! empty( $terms ) ) {
629 foreach ( $terms as $term_id ) {
630 $term = get_term( $term_id, $taxFilter, ARRAY_A );
631 if ( ! isset( $term['term_id'] ) ) {
632 continue;
633 }
634 $id = $term['term_id'];
635 $bCount = $bCount + absint( $term['count'] );
636 $sT = null;
637 if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' && $data['filter_btn_style'] === 'default' && $data['filter_type'] == 'button' ) {
638 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
639 if ( ! empty( $subTerms ) ) {
640 $sT .= "<div class='rt-filter-sub-tax sub-button-group '>";
641 foreach ( $subTerms as $stId => $t ) {
642 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
643 $sT .= "<span class='term-button-item rt-filter-button-item ' data-term='{$stId}'>{$t['name']}{$sTPostCount}</span>";
644 }
645 $sT .= "</div>";
646 if ( $default_term === $id ) {
647 $selectedSubTermsForButton = $sT;
648 }
649 }
650 }
651 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
652 $termSelected = null;
653 if ( $isTermSelected && $id == $default_term ) {
654 $termSelected = " selected";
655 }
656 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
657 if ( in_array( $id, $taxFilterTerms ) ) {
658 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
659 }
660 } else {
661 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
662 }
663 }
664 }
665 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-button-wrap{$postCountClass} {$wrapperClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>";
666
667 //$pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
668 if ( 'yes' == $data['tpg_hide_all_button'] ) {
669 $html .= "<span class='term-button-item rt-filter-button-item {$allSelect} {$itemClass}' data-term='all'>" . $allText . "</span>";
670 }
671
672 $html .= $bItems;
673
674 $html .= "</div>";
675 if ( 'carousel' === $data['filter_btn_style'] ) {
676 $html .= '<div class="swiper-navigation"><div class="swiper-button-prev slider-btn"></div><div class="swiper-button-next slider-btn"></div></div>';
677 }
678 }
679 }
680
681 // TODO: Author filter
682 if ( 'show' == $data['show_author_filter'] ) {
683 $user_el = $data['author'];
684
685 $filterAuthors = $user_el;
686
687 if ( ! empty( $user_el ) ) {
688 $users = get_users( apply_filters( 'tpg_author_arg', [ 'include' => $user_el ] ) );
689 } else {
690 $users = get_users( apply_filters( 'tpg_author_arg', [] ) );
691 }
692 $allText = $allText = $data['author_filter_all_text'] ? $data['author_filter_all_text'] : __( "All Users", "the-post-grid" );
693 $allSelect = " selected";
694 //$isTermSelected = false;
695 // if ( $default_term && $taxFilter ) {
696 $isTermSelected = true;
697 // $allSelect = null;
698 // }
699 if ( $filterType == 'dropdown' ) {
700 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-filter='author'>";
701 $termDefaultText = $allText;
702 $dataAuthor = 'all';
703 $htmlButton = "";
704 $htmlButton .= '<span class="author-dropdown rt-filter-dropdown">';
705 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'>" . $allText . "</span>";
706
707 if ( ! empty( $users ) ) {
708 foreach ( $users as $user ) {
709 $user_post_count = false;
710 $post_count ? "(" . count_user_posts( $user->ID, $data['post_type'] ) . ")" : null;
711 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
712 if ( in_array( $user->ID, $filterAuthors ) ) {
713 if ( $default_term == $user->ID ) {
714 $termDefaultText = $user->display_name;
715 $dataTerm = $user->ID;
716 } else {
717 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name} <span class='rt-text'>{$user_post_count}</span></span>";
718 }
719 }
720 } else {
721 if ( $default_term == $user->ID ) {
722 $termDefaultText = $user->display_name;
723 $dataTerm = $user->ID;
724 } else {
725 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'><span class='rt-text'>{$user->display_name} {$user_post_count}</span></span>";
726 }
727 }
728 }
729 }
730
731
732 $htmlButton .= '</span>';
733
734 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataAuthor . '">
735 <span class="rt-text">' . $termDefaultText . '</span>
736 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
737 </span>';
738
739 $html .= $showAllhtml . $htmlButton;
740 $html .= '</div>';
741 } else {
742 $bCount = 0;
743 $bItems = null;
744
745 if ( ! empty( $users ) ) {
746 foreach ( $users as $user ) {
747 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
748 if ( in_array( $user->ID, $filterAuthors ) ) {
749 $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>";
750 }
751 } else {
752 $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>";
753 }
754 }
755 }
756
757 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-button-wrap{$postCountClass}' data-filter='author'>";
758 // if ( 'yes' == $data['tax_filter_all_text'] ) {
759 //$pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
760 $html .= "<span class='author-button-item rt-filter-button-item {$allSelect}' data-author='all'>" . $allText . "</span>";
761 // }
762 $html .= $bItems;
763 $html .= "</div>";
764 }
765 }
766
767
768 if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) {
769 $html .= "</div>";
770 }
771
772
773 if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) {
774 $html .= "<div class='filter-right-wrapper'>";
775 }
776
777
778 // TODO: Order Filter
779 if ( 'show' == $data['show_sort_order'] ) {
780 $action_order = ( $data['order'] ? strtoupper( $data['order'] ) : "DESC" );
781 $html .= '<div class="rt-filter-item-wrap rt-sort-order-action" data-filter="order">';
782 $html .= "<span class='rt-sort-order-action-arrow' data-sort-order='{$action_order}'>&nbsp;<span></span></span>";
783 $html .= '</div>';
784 }
785
786 //TODO: Orderby Filter
787 if ( 'show' == $data['show_order_by'] ) {
788 $wooFeature = ( $data['post_type'] == "product" ? true : false );
789 $orders = Options::rtPostOrderBy( $wooFeature );
790 $action_orderby = ( ! empty( $data['orderby'] ) ? $data['orderby'] : "none" );
791 if ( $action_orderby == 'none' ) {
792 $action_orderby_label = __( "Sort By", "the-post-grid" );
793 } else if ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) {
794 $action_orderby_label = __( "Meta value", "the-post-grid" );
795 } else {
796 $action_orderby_label = __( "By ", "the-post-grid" ) . $action_orderby;
797 }
798 if ( $action_orderby !== 'none' ) {
799 $orders['none'] = __( "Sort By", "the-post-grid" );
800 }
801 $html .= '<div class="rt-filter-item-wrap rt-order-by-action rt-filter-dropdown-wrap" data-filter="orderby">';
802 $html .= "<span class='order-by-default rt-filter-dropdown-default' data-order-by='{$action_orderby}'>
803 <span class='rt-text-order-by'>{$action_orderby_label}</span>
804 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
805 </span>";
806 $html .= '<span class="order-by-dropdown rt-filter-dropdown">';
807
808 foreach ( $orders as $orderKey => $order ) {
809 $html .= '<span class="order-by-dropdown-item rt-filter-dropdown-item" data-order-by="' . $orderKey . '">' . $order . '</span>';
810 }
811 $html .= '</span>';
812 $html .= '</div>';
813 }
814
815 //TODO: Search Filter
816 if ( 'show' == $data['show_search'] ) {
817 $html .= '<div class="rt-filter-item-wrap rt-search-filter-wrap" data-filter="search">';
818 $html .= sprintf( '<input type="text" class="rt-search-input" placeholder="%s">', esc_html__( "Search...", 'the-post-grid' ) );
819 $html .= "<span class='rt-action'>&#128269;</span>";
820 $html .= "<span class='rt-loading'></span>";
821 $html .= '</div>';
822 }
823
824 if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) {
825 $html .= "</div>";
826 }
827
828 $html .= "</div>$selectedSubTermsForButton</div>";
829
830 return $html;
831 }
832
833
834 /**
835 * Get Excluded Taxonomy
836 *
837 * @return string[]
838 */
839 public static function get_excluded_taxonomy() {
840 return [
841 'post_format',
842 'nav_menu',
843 'link_category',
844 'wp_theme',
845 'elementor_library_type',
846 'elementor_library_type',
847 'elementor_library_category',
848 'product_visibility',
849 'product_shipping_class',
850 ];
851 }
852
853 /**
854 * Get Popup Modal Markup
855 */
856 public static function get_modal_markup() {
857 $html = null;
858 $html .= '<div class="md-modal rt-md-effect" id="rt-modal">
859 <div class="md-content">
860 <div class="rt-md-content-holder"></div>
861 <div class="md-cls-btn">
862 <button class="md-close"><i class="fa fa-times" aria-hidden="true"></i></button>
863 </div>
864 </div>
865 </div>';
866 $html .= "<div class='md-overlay'></div>";
867 echo $html;
868 }
869
870 /**
871 * Get Archive page title
872 */
873 public static function get_archive_title() {
874 $queried_obj = get_queried_object();
875 if ( is_tag() || is_category() ) {
876 echo esc_html( $queried_obj->name );
877 } else if ( is_author() ) {
878 echo esc_html( $queried_obj->display_name );
879 } else if ( is_date() ) {
880 $year = get_query_var( 'year' );
881 $monthnum = get_query_var( 'monthnum' );
882 $day = get_query_var( 'day' );
883 $time_string = $year . '/' . $monthnum . '/' . $day;
884 $time_stamp = strtotime( $time_string );
885 echo date( get_option( 'date_format' ), $time_stamp );
886 }
887 }
888
889 /**
890 * Get Last Category ID
891 *
892 * @return mixed
893 */
894 public static function get_last_category_id() {
895 if ( is_archive() ) {
896 return;
897 }
898 $categories = get_terms( [
899 'taxonomy' => 'category',
900 'hide_empty' => false,
901 'number' => 1,
902 ] );
903 if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) {
904 return $categories[0]->term_id;
905 }
906 }
907
908 /**
909 * @param $data
910 *
911 * @return string
912 */
913 public static function get_dynamic_class_gutenberg( $data ) {
914 $uniqueId = isset( $data['uniqueId'] ) ? $data['uniqueId'] : null;
915 $uniqueClass = 'rttpg-block-postgrid rttpg-block-wrapper rttpg-block-' . $uniqueId;
916 $dynamicClass = $uniqueClass;
917 $dynamicClass .= ! empty( $data['align'] ) ? ' align' . $data['align'] : null;
918 $dynamicClass .= ! empty( $data['className'] ) ? ' ' . $data['className'] : null;
919 $dynamicClass .= ! empty( $data['full_wrapper_align']['lg'] ) ? " tpg-wrapper-align-{$data['full_wrapper_align']['lg']}" : null;
920 $dynamicClass .= ! empty( $data['filter_type'] ) ? " tpg-filter-type-{$data['filter_type']}" : null;
921 $dynamicClass .= ! empty( $data['show_pagination'] ) ? " pagination-visibility-{$data['show_pagination']}" : null;
922 $dynamicClass .= ! empty( $data['ajax_pagination_type'] ) ? " ajax-pagination-type-next-prev-{$data['ajax_pagination_type']}" : null;
923 $dynamicClass .= ! empty( $data['show_meta'] ) ? " meta-visibility-{$data['show_meta']}" : null;
924 $dynamicClass .= ! empty( $data['section_title_style'] ) ? " section-title-style-{$data['section_title_style']}" : null;
925 $dynamicClass .= ! empty( $data['section_title_alignment'] ) ? " section-title-align-{$data['section_title_alignment']}" : null;
926 $dynamicClass .= ! empty( $data['hover_animation'] ) ? " img_hover_animation_{$data['hover_animation']}" : null;
927 $dynamicClass .= ! empty( $data['title_visibility_style'] ) ? " title-{$data['title_visibility_style']}" : null;
928 $dynamicClass .= ! empty( $data['title_position'] ) ? " title_position_{$data['title_position']}" : null;
929 $dynamicClass .= ! empty( $data['title_hover_underline'] ) ? " title_hover_border_{$data['title_hover_underline']}" : null;
930 $dynamicClass .= ! empty( $data['meta_position'] ) ? " meta_position_{$data['meta_position']}" : null;
931 $dynamicClass .= ! empty( $data['author_icon_visibility'] ) ? " tpg-is-author-icon-{$data['author_icon_visibility']}" : null;
932 $dynamicClass .= ! empty( $data['show_author_image'] ) ? " author-image-visibility-{$data['show_author_image']}" : null;
933 $dynamicClass .= ! empty( $data['category_position'] ) ? " tpg-category-position-{$data['category_position']}" : null;
934 $dynamicClass .= ! empty( $data['readmore_btn_style'] ) ? " readmore-btn-{$data['readmore_btn_style']}" : null;
935 $dynamicClass .= ! empty( $data['grid_hover_overlay_type'] ) ? " grid-hover-overlay-type-{$data['grid_hover_overlay_type']}" : null;
936 $dynamicClass .= ! empty( $data['grid_hover_overlay_height'] ) ? " grid-hover-overlay-height-{$data['grid_hover_overlay_height']}" : null;
937 $dynamicClass .= ! empty( $data['on_hover_overlay'] ) ? " hover-overlay-height-{$data['on_hover_overlay']}" : null;
938 $dynamicClass .= ! empty( $data['title_border_visibility'] ) ? " tpg-title-border-{$data['title_border_visibility']}" : null;
939 $dynamicClass .= ! empty( $data['title_alignment'] ) ? " title-alignment-{$data['title_alignment']}" : null;
940 $dynamicClass .= ! empty( $data['filter_v_alignment'] ) ? " tpg-filter-alignment-{$data['filter_v_alignment']}" : null;
941 $dynamicClass .= ! empty( $data['border_style'] ) ? " filter-button-border-{$data['border_style']}" : null;
942 $dynamicClass .= ! empty( $data['filter_next_prev_btn'] ) ? " filter-nex-prev-btn-{$data['filter_next_prev_btn']}" : null;
943 $dynamicClass .= ! empty( $data['filter_h_alignment'] ) ? " tpg-filter-h-alignment-{$data['filter_h_alignment']}" : null;
944 $dynamicClass .= ! empty( $data['is_box_border'] ) ? " tpg-el-box-border-{$data['is_box_border']}" : null;
945 $dynamicClass .= ! empty( $data['category_style'] ) ? " tpg-cat-{$data['category_style']}" : null;
946
947 //Slider layout
948 $dynamicClass .= ! empty( $data['arrow_position'] ) ? " slider-arrow-position-{$data['arrow_position']}" : null;
949 $dynamicClass .= ! empty( $data['dots'] ) ? " slider-dot-enable-{$data['dots']}" : null;
950 $dynamicClass .= ! empty( $data['dots_style'] ) ? " slider-dots-style-{$data['dots_style']}" : null;
951 $dynamicClass .= ! empty( $data['lazyLoad'] ) ? " is-lazy-load-{$data['lazyLoad']}" : null;
952 $dynamicClass .= ! empty( $data['carousel_overflow'] ) ? " is-carousel-overflow-{$data['carousel_overflow']}" : null;
953 $dynamicClass .= ! empty( $data['slider_direction'] ) ? " slider-direction-{$data['slider_direction']}" : null;
954 $dynamicClass .= ! empty( $data['dots_text_align'] ) ? " slider-dots-align-{$data['dots_text_align']}" : null;
955 $dynamicClass .= ! empty( $data['pagination_btn_space_btween'] ) && $data['pagination_btn_space_btween'] === 'space-between' ? " tpg-prev-next-space-between" : null;
956 $dynamicClass .= ! empty( $data['pagination_btn_position'] ) && $data['pagination_btn_position'] === 'absolute' ? " tpg-prev-next-absolute" : null;
957 $dynamicClass .= ! empty( $data['box_border_bottom'] ) && $data['box_border_bottom'] === 'enable' ? " tpg-border-bottom-enable" : null;
958 $dynamicClass .= ! empty( $data['offset_img_position'] ) && $data['offset_img_position'] === 'offset-image-right' ? " offset-image-right" : null;
959 $dynamicClass .= ! empty( $data['scroll_visibility'] ) && $data['scroll_visibility'] === 'yes' ? "" : " slider-scroll-hide";
960 $dynamicClass .= ! empty( $data['enable_external_link'] ) && $data['enable_external_link'] === 'show' ? " has-external-link" : "";
961
962 //ACF
963 $dynamicClass .= ! empty( $data['acf_label_style'] ) ? " act-label-style-{$data['acf_label_style']}" : null;
964 $dynamicClass .= ! empty( $data['acf_alignment'] ) && ! is_array( $data['acf_alignment'] ) ? " tpg-acf-align-{$data['acf_alignment']}" : null;
965
966 return $dynamicClass;
967 }
968
969
970 /**
971 * Get Section Title
972 *
973 * @param $data
974 */
975 public static function get_section_title( $data ) {
976 if ( 'show' != $data['show_section_title'] ) {
977 return;
978 }
979
980 $_is_link = false;
981 if ( ! empty( $data['section_title_link']['url'] ) ) {
982 $_is_link = true;
983 }
984
985 ob_start();
986 ?>
987
988 <div class="tpg-widget-heading-wrapper rt-clear heading-<?php echo esc_attr( $data['section_title_style'] ); ?> ">
989 <span class="tpg-widget-heading-line line-left"></span>
990
991 <?php printf( "<%s class='tpg-widget-heading'>", $data['section_title_tag'] ); ?>
992
993 <?php
994 if ( $_is_link ) : ?>
995 <a href="#">
996 <?php endif; ?>
997
998 <?php
999 if ( 'page_title' == $data['section_title_source'] ) {
1000 $archive_prefix = $data['title_prefix'] ? $data['title_prefix'] . ' ' : null;
1001 $archive_suffix = $data['title_suffix'] ? ' ' . $data['title_suffix'] : null;
1002 printf( "<span class='prefix-text'>%s</span>", esc_html( $archive_prefix ) );
1003 if ( is_archive() ) {
1004 self::get_archive_title();
1005 } else if ( is_search() ) {
1006 echo get_query_var( 's' );
1007 } else {
1008 the_title();
1009 }
1010 printf( "<span class='suffix-text'>%s</span>", esc_html( $archive_suffix ) );
1011 } else {
1012 ?>
1013 <span>
1014 <?php echo $data['section_title_text'] ?>
1015 </span>
1016 <?php
1017 }
1018 ?>
1019
1020 <?php if ( $_is_link ) : ?>
1021 </a>
1022
1023 <?php endif; ?>
1024 <?php printf( "</%s>", $data['section_title_tag'] ); ?>
1025 <span class="tpg-widget-heading-line line-right"></span>
1026
1027 <?php if ( isset( $data['enable_external_link'] ) && 'show' === $data['enable_external_link'] ) : ?>
1028 <a class='external-link' href='<?php echo esc_url( $data['section_external_link'] ) ?>'>
1029 <?php if ( $data['section_external_text'] ) : ?>
1030 <span class="external-lable"><?php echo esc_html( $data['section_external_text'] ) ?></span>
1031 <?php endif; ?>
1032 <?php echo "<i class='left-icon " . Fns::change_icon( 'fas fa-angle-right', 'right-arrow', 'left-icon' ) . "'></i>"; ?>
1033 </a>
1034 <?php endif; ?>
1035
1036 </div>
1037
1038 <?php if ( isset( $data['show_cat_desc'] ) && $data['show_cat_desc'] == 'yes' && category_description( self::get_last_category_id() ) ) : ?>
1039 <div class="tpg-category-description">
1040 <?php echo category_description( self::get_last_category_id() ); ?>
1041 </div>
1042 <?php endif; ?>
1043
1044 <?php echo ob_get_clean();
1045 }
1046
1047 /**
1048 * rtAllOptionFields
1049 * All settings.
1050 *
1051 * @return array
1052 */
1053 public static function rtAllOptionFields() {
1054 $fields = array_merge(
1055 Options::rtTPGCommonFilterFields(),
1056 Options::rtTPGLayoutSettingFields(),
1057 Options::responsiveSettingsColumn(),
1058 Options::layoutMiscSettings(),
1059 Options::stickySettings(),
1060 // settings.
1061 Options::rtTPGSCHeadingSettings(),
1062 Options::rtTPGSCCategorySettings(),
1063 Options::rtTPGSCTitleSettings(),
1064 Options::rtTPGSCMetaSettings(),
1065 Options::rtTPGSCImageSettings(),
1066 Options::rtTPGSCExcerptSettings(),
1067 Options::rtTPGSCButtonSettings(),
1068 // style.
1069 Options::rtTPGStyleFields(),
1070 Options::rtTPGStyleHeading(),
1071 Options::rtTPGStyleFullArea(),
1072 Options::rtTPGStyleContentWrap(),
1073 Options::rtTPGStyleCategory(),
1074 Options::rtTPGPostType(),
1075 Options::rtTPGStyleButtonColorFields(),
1076 Options::rtTPAdvanceFilters(),
1077 Options::itemFields()
1078 );
1079
1080 return $fields;
1081 }
1082
1083 public static function rt_get_all_term_by_taxonomy( $taxonomy = null, $count = false, $parent = false ) {
1084 $terms = [];
1085
1086 if ( $taxonomy ) {
1087 $temp_terms = get_terms(
1088 [
1089 'taxonomy' => $taxonomy,
1090 'hide_empty' => 0,
1091 ]
1092 );
1093
1094 if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) {
1095 foreach ( $temp_terms as $term ) {
1096 $order = get_term_meta( $term->term_id, '_rt_order', true );
1097 if ( $order === '' ) {
1098 update_term_meta( $term->term_id, '_rt_order', 0 );
1099 }
1100 }
1101
1102 global $wp_version;
1103
1104 $args = [
1105 'taxonomy' => $taxonomy,
1106 'orderby' => 'meta_value_num',
1107 'meta_key' => '_rt_order',
1108 'hide_empty' => apply_filters( 'rttpg_category_hide_empty', false ),
1109 ];
1110
1111 if ( $parent >= 0 && $parent !== false ) {
1112 $args['parent'] = absint( $parent );
1113 }
1114
1115 $args['orderby'] = 'meta_value_num';
1116 $args['meta_key'] = '_rt_order';
1117
1118 $termObjs = get_terms( $args );
1119
1120 foreach ( $termObjs as $term ) {
1121 if ( $count ) {
1122 $terms[ $term->term_id ] = [
1123 'name' => $term->name,
1124 'count' => $term->count,
1125 ];
1126 } else {
1127 $terms[ $term->term_id ] = $term->name;
1128 }
1129 }
1130 }
1131 }
1132
1133 return $terms;
1134 }
1135
1136 public static function rt_get_selected_term_by_taxonomy( $taxonomy = null, $include = [], $count = false, $parent = false ) {
1137 $terms = [];
1138
1139 if ( $taxonomy ) {
1140 $temp_terms = get_terms(
1141 [
1142 'taxonomy' => $taxonomy,
1143 'hide_empty' => 0,
1144 ]
1145 );
1146
1147 if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) {
1148 foreach ( $temp_terms as $term ) {
1149 $order = get_term_meta( $term->term_id, '_rt_order', true );
1150 if ( $order === '' ) {
1151 update_term_meta( $term->term_id, '_rt_order', 0 );
1152 }
1153 }
1154
1155 global $wp_version;
1156
1157 $args = [
1158 'taxonomy' => $taxonomy,
1159 'orderby' => 'meta_value_num',
1160 'meta_key' => '_rt_order',
1161 'include' => $include,
1162 'hide_empty' => false,
1163 ];
1164
1165 if ( $parent >= 0 && $parent !== false ) {
1166 $args['parent'] = absint( $parent );
1167 }
1168
1169 $args['orderby'] = 'meta_value_num';
1170 $args['meta_key'] = '_rt_order';
1171
1172 $termObjs = get_terms( $args );
1173
1174 foreach ( $termObjs as $term ) {
1175 if ( $count ) {
1176 $terms[ $term->term_id ] = [
1177 'name' => $term->name,
1178 'count' => $term->count,
1179 ];
1180 } else {
1181 $terms[ $term->term_id ] = $term->name;
1182 }
1183 }
1184 }
1185 }
1186
1187 return $terms;
1188 }
1189
1190 public static function getCurrentUserRoles() {
1191 global $current_user;
1192
1193 return $current_user->roles;
1194 }
1195
1196 public static function rt_get_taxonomy_for_filter( $post_type = null ) {
1197 if ( ! $post_type ) {
1198 $post_type = get_post_meta( get_the_ID(), 'tpg_post_type', true );
1199 }
1200
1201 if ( ! $post_type ) {
1202 $post_type = 'post';
1203 }
1204
1205 return self::rt_get_all_taxonomy_by_post_type( $post_type );
1206 }
1207
1208 public static function rt_get_all_taxonomy_by_post_type( $post_type = null ) {
1209 $taxonomies = [];
1210
1211 if ( $post_type && post_type_exists( $post_type ) ) {
1212 $taxObj = get_object_taxonomies( $post_type, 'objects' );
1213
1214 if ( is_array( $taxObj ) && ! empty( $taxObj ) ) {
1215 foreach ( $taxObj as $tKey => $taxonomy ) {
1216 $taxonomies[ $tKey ] = $taxonomy->label;
1217 }
1218 }
1219 }
1220
1221 if ( $post_type == 'post' ) {
1222 unset( $taxonomies['post_format'] );
1223 }
1224
1225 return $taxonomies;
1226 }
1227
1228 public static function rt_get_users() {
1229 $users = [];
1230 $u = get_users( apply_filters( 'tpg_author_arg', [] ) );
1231
1232 if ( ! empty( $u ) ) {
1233 foreach ( $u as $user ) {
1234 $users[ $user->ID ] = $user->display_name;
1235 }
1236 }
1237
1238 return $users;
1239 }
1240
1241 public static function rtFieldGenerator( $fields = [] ) {
1242 $html = null;
1243
1244 if ( is_array( $fields ) && ! empty( $fields ) ) {
1245 $tpgField = new Field();
1246 foreach ( $fields as $fieldKey => $field ) {
1247 $html .= $tpgField->Field( $fieldKey, $field );
1248 }
1249 }
1250
1251 return $html;
1252 }
1253
1254 /**
1255 * Sanitize field value
1256 *
1257 * @param array $field
1258 * @param null $value
1259 *
1260 * @return array|null
1261 * @internal param $value
1262 */
1263 public static function sanitize( $field = [], $value = null ) {
1264 $newValue = null;
1265
1266 if ( is_array( $field ) ) {
1267 $type = ( ! empty( $field['type'] ) ? $field['type'] : 'text' );
1268
1269 if ( empty( $field['multiple'] ) ) {
1270 if ( $type == 'text' || $type == 'number' || $type == 'select' || $type == 'checkbox' || $type == 'radio' ) {
1271 $newValue = sanitize_text_field( $value );
1272 } else if ( $type == 'url' ) {
1273 $newValue = esc_url( $value );
1274 } else if ( $type == 'slug' ) {
1275 $newValue = sanitize_title_with_dashes( $value );
1276 } else if ( $type == 'textarea' ) {
1277 $newValue = wp_kses_post( $value );
1278 } else if ( $type == 'script' ) {
1279 $newValue = trim( $value );
1280 } else if ( $type == 'colorpicker' ) {
1281 $newValue = self::sanitize_hex_color( $value );
1282 } else if ( $type == 'image_size' ) {
1283 $newValue = [];
1284
1285 foreach ( $value as $k => $v ) {
1286 $newValue[ $k ] = esc_attr( $v );
1287 }
1288 } else if ( $type == 'style' ) {
1289 $newValue = [];
1290
1291 foreach ( $value as $k => $v ) {
1292 if ( $k == 'color' ) {
1293 $newValue[ $k ] = self::sanitize_hex_color( $v );
1294 } else {
1295 $newValue[ $k ] = self::sanitize( [ 'type' => 'text' ], $v );
1296 }
1297 }
1298 } else {
1299 $newValue = sanitize_text_field( $value );
1300 }
1301 } else {
1302 $newValue = [];
1303
1304 if ( ! empty( $value ) ) {
1305 if ( is_array( $value ) ) {
1306 foreach ( $value as $key => $val ) {
1307 if ( $type == 'style' && $key == 0 ) {
1308 if ( function_exists( 'sanitize_hex_color' ) ) {
1309 $newValue = sanitize_hex_color( $val );
1310 } else {
1311 $newValue[] = self::sanitize_hex_color( $val );
1312 }
1313 } else {
1314 $newValue[] = sanitize_text_field( $val );
1315 }
1316 }
1317 } else {
1318 $newValue[] = sanitize_text_field( $value );
1319 }
1320 }
1321 }
1322 }
1323
1324 return $newValue;
1325 }
1326
1327 public static function sanitize_hex_color( $color ) {
1328 if ( function_exists( 'sanitize_hex_color' ) ) {
1329 return sanitize_hex_color( $color );
1330 } else {
1331 if ( '' === $color ) {
1332 return '';
1333 }
1334
1335 // 3 or 6 hex digits, or the empty string.
1336 if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
1337 return $color;
1338 }
1339 }
1340 }
1341
1342 public static function rtFieldGeneratorBackup( $fields = [], $multi = false ) {
1343 $html = null;
1344
1345 if ( is_array( $fields ) && ! empty( $fields ) ) {
1346 $rtField = new Field();
1347
1348 if ( $multi ) {
1349 foreach ( $fields as $field ) {
1350 $html .= $rtField->Field( $field );
1351 }
1352 } else {
1353 $html .= $rtField->Field( $fields );
1354 }
1355 }
1356
1357 return $html;
1358 }
1359
1360 public static function rtSmartStyle( $fields = [] ) {
1361 $h = null;
1362
1363 if ( ! empty( $fields ) ) {
1364 foreach ( $fields as $key => $label ) {
1365 $atts = '';
1366 $proText = '';
1367 $class = '';
1368
1369 $h .= '<div class="field-holder ' . esc_attr( $class ) . '">';
1370
1371 $h .= '<div class="field-label"><label>' . esc_html( $label ) . '' . self::htmlKses( $proText, 'basic' ) . '</label></div>';
1372 $h .= "<div class='field'>";
1373 // color.
1374 $h .= "<div class='field-inner col-4'>";
1375 $h .= "<div class='field-inner-container size'>";
1376 $h .= "<span class='label'>Color</span>";
1377 $cValue = get_post_meta( get_the_ID(), $key . '_color', true );
1378 $h .= '<input type="text" value="' . esc_attr( $cValue ) . '" class="rt-color" name="' . esc_attr( $key ) . '_color">';
1379 $h .= '</div>';
1380 $h .= '</div>';
1381
1382 // Font size.
1383 $h .= "<div class='field-inner col-4'>";
1384 $h .= "<div class='field-inner-container size'>";
1385 $h .= "<span class='label'>Font size</span>";
1386 $h .= '<select ' . self::htmlKses( $atts, 'basic' ) . ' name="' . esc_attr( $key ) . '_size" class="rt-select2">';
1387 $fSizes = Options::scFontSize();
1388 $sValue = get_post_meta( get_the_ID(), $key . '_size', true );
1389 $h .= "<option value=''>Default</option>";
1390
1391 foreach ( $fSizes as $size => $sizeLabel ) {
1392 $sSlt = ( $size == $sValue ? 'selected' : null );
1393 $h .= '<option value="' . esc_attr( $size ) . '" ' . esc_attr( $sSlt ) . '>' . esc_html( $sizeLabel ) . '</option>';
1394 }
1395
1396 $h .= '</select>';
1397 $h .= '</div>';
1398 $h .= '</div>';
1399
1400 // Weight.
1401 $h .= "<div class='field-inner col-4'>";
1402 $h .= "<div class='field-inner-container weight'>";
1403 $h .= "<span class='label'>Weight</span>";
1404 $h .= '<select ' . self::htmlKses( $atts, 'basic' ) . ' name="' . esc_attr( $key ) . '_weight" class="rt-select2">';
1405 $h .= "<option value=''>Default</option>";
1406 $weights = Options::scTextWeight();
1407 $wValue = get_post_meta( get_the_ID(), $key . '_weight', true );
1408
1409 foreach ( $weights as $weight => $weightLabel ) {
1410 $wSlt = ( $weight == $wValue ? 'selected' : null );
1411 $h .= '<option value="' . esc_attr( $weight ) . '" ' . esc_attr( $wSlt ) . '>' . esc_html( $weightLabel ) . '</option>';
1412 }
1413
1414 $h .= '</select>';
1415 $h .= '</div>';
1416 $h .= '</div>';
1417
1418 // Alignment.
1419 $h .= "<div class='field-inner col-4'>";
1420 $h .= "<div class='field-inner-container alignment'>";
1421 $h .= "<span class='label'>Alignment</span>";
1422 $h .= '<select ' . self::htmlKses( $atts, 'basic' ) . ' name="' . esc_attr( $key ) . '_alignment" class="rt-select2">';
1423 $h .= "<option value=''>Default</option>";
1424 $aligns = Options::scAlignment();
1425 $aValue = get_post_meta( get_the_ID(), $key . '_alignment', true );
1426
1427 foreach ( $aligns as $align => $alignLabel ) {
1428 $aSlt = ( $align == $aValue ? 'selected' : null );
1429 $h .= '<option value="' . esc_attr( $align ) . '" ' . esc_attr( $aSlt ) . '>' . esc_html( $alignLabel ) . '</option>';
1430 }
1431
1432 $h .= '</select>';
1433 $h .= '</div>';
1434 $h .= '</div>';
1435
1436 $h .= '</div>';
1437 $h .= '</div>';
1438 }
1439 }
1440
1441 return $h;
1442 }
1443
1444 public static function custom_variation_price( $product ) {
1445 $price = '';
1446 $max = $product->get_variation_sale_price( 'max' );
1447 $min = $product->get_variation_sale_price( 'min' );
1448
1449 if ( ! $min || $min !== $max ) {
1450 $price .= wc_price( $product->get_price() );
1451 }
1452
1453 if ( $max && $max !== $min ) {
1454 $price .= ' - ';
1455 $price .= wc_price( $max );
1456 }
1457
1458 return $price;
1459 }
1460
1461 public static function getTPGShortCodeList() {
1462 $scList = null;
1463 $scQ = get_posts(
1464 [
1465 'post_type' => rtTPG()->post_type,
1466 'order_by' => 'title',
1467 'order' => 'DESC',
1468 'post_status' => 'publish',
1469 'posts_per_page' => - 1,
1470 'meta_query' => [
1471 [
1472 'key' => 'layout',
1473 'value' => 'layout',
1474 'compare' => 'LIKE',
1475 ],
1476 ],
1477 ]
1478 );
1479
1480 if ( ! empty( $scQ ) ) {
1481 foreach ( $scQ as $sc ) {
1482 $scList[ $sc->ID ] = $sc->post_title;
1483 }
1484 }
1485
1486 return $scList;
1487 }
1488
1489 public static function getAllTPGShortCodeList() {
1490 $scList = null;
1491 $scQ = get_posts(
1492 [
1493 'post_type' => rtTPG()->post_type,
1494 'order_by' => 'title',
1495 'order' => 'ASC',
1496 'post_status' => 'publish',
1497 'posts_per_page' => - 1,
1498 ]
1499 );
1500 if ( ! empty( $scQ ) ) {
1501 foreach ( $scQ as $sc ) {
1502 $scList[ $sc->ID ] = $sc->post_title;
1503 }
1504 }
1505
1506 return $scList;
1507 }
1508
1509 public static function socialShare( $pLink ) {
1510 $html = null;
1511 $html .= "<div class='single-tpg-share'>
1512 <div class='fb-share'>
1513 <div class='fb-share-button' data-href='" . esc_url( $pLink ) . "' data-layout='button_count'></div>
1514 </div>
1515 <div class='twitter-share'>
1516 <a href='" . esc_url( $pLink ) . "' class='twitter-share-button'{count} data-url='https://about.twitter.com/resources/buttons#tweet'>Tweet</a>
1517 </div>
1518 <div class='googleplus-share'>
1519 <div class='g-plusone'></div>
1520 </div>
1521 <div class='linkedin-share'>
1522 <script type='IN/Share' data-counter='right'></script>
1523 </div>
1524 <div class='linkedin-share'>
1525 <a data-pin-do='buttonPin' data-pin-count='beside' href='https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=https%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest'><img src='//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png' /></a>
1526 </div>
1527 </div>";
1528 $html .= '<div id="fb-root"></div>
1529 <script>(function(d, s, id) {
1530 var js, fjs = d.getElementsByTagName(s)[0];
1531 if (d.getElementById(id)) return;
1532 js = d.createElement(s); js.id = id;
1533 js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
1534 fjs.parentNode.insertBefore(js, fjs);
1535 }(document, "script", "facebook-jssdk"));</script>';
1536 $html .= "<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
1537 <script>window.___gcfg = { lang: 'en-US', parsetags: 'onload', };</script>";
1538 $html .= "<script src='https://apis.google.com/js/platform.js' async defer></script>";
1539 $html .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>';
1540 $html .= '<script async defer src="//assets.pinterest.com/js/pinit.js"></script>';
1541
1542 return $html;
1543 }
1544
1545 public static function get_image_sizes() {
1546 global $_wp_additional_image_sizes;
1547
1548 $sizes = [];
1549 $interSizes = get_intermediate_image_sizes();
1550 if ( ! empty( $interSizes ) ) {
1551 foreach ( get_intermediate_image_sizes() as $_size ) {
1552 if ( in_array( $_size, [ 'thumbnail', 'medium', 'large' ] ) ) {
1553 $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" );
1554 $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" );
1555 $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" );
1556 } else if ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
1557 $sizes[ $_size ] = [
1558 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
1559 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
1560 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
1561 ];
1562 }
1563 }
1564 }
1565
1566 $imgSize = [];
1567
1568 if ( ! empty( $sizes ) ) {
1569 $imgSize['full'] = esc_html__( 'Full Size', 'the-post-grid' );
1570 foreach ( $sizes as $key => $img ) {
1571 $imgSize[ $key ] = ucfirst( $key ) . " ({$img['width']}*{$img['height']})";
1572 }
1573 }
1574
1575 return apply_filters( 'tpg_image_sizes', $imgSize );
1576 }
1577
1578 public static function getFeatureImageSrc(
1579 $post_id = null,
1580 $fImgSize = 'medium',
1581 $mediaSource = 'feature_image',
1582 $defaultImgId = null,
1583 $customImgSize = [],
1584 $img_Class = ''
1585 ) {
1586 global $post;
1587
1588 $imgSrc = null;
1589 $img_class = 'rt-img-responsive ';
1590
1591 if ( $img_Class ) {
1592 $img_class .= $img_Class;
1593 }
1594
1595 $post_id = ( $post_id ? absint( $post_id ) : $post->ID );
1596 $alt = get_the_title( $post_id );
1597 $image = null;
1598 $cSize = false;
1599
1600 if ( $fImgSize == 'rt_custom' ) {
1601 $fImgSize = 'full';
1602 $cSize = true;
1603 }
1604
1605 if ( $mediaSource == 'feature_image' ) {
1606 if ( $aID = get_post_thumbnail_id( $post_id ) ) {
1607 $image = wp_get_attachment_image(
1608 $aID,
1609 $fImgSize,
1610 '',
1611 [
1612 'class' => $img_class,
1613 'loading' => false,
1614 ]
1615 );
1616 $imgSrc = wp_get_attachment_image_src( $aID, $fImgSize );
1617
1618 if ( ! empty( $imgSrc ) && $img_Class == 'swiper-lazy' ) {
1619 $image = '<img class="' . esc_attr( $img_class ) . '" data-src="' . esc_url( $imgSrc[0] ) . '" src="#none" width="' . absint( $imgSrc[1] ) . '" height="' . absint( $imgSrc[2] ) . '" alt="' . esc_attr( $alt ) . '"/><div class="lazy-overlay-wrap"><div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div></div>';
1620 }
1621
1622 $imgSrc = ! empty( $imgSrc ) ? $imgSrc[0] : $imgSrc;
1623 }
1624 } else if ( $mediaSource == 'first_image' ) {
1625 if ( $img = preg_match_all(
1626 '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
1627 get_the_content( $post_id ),
1628 $matches
1629 )
1630 ) {
1631 $imgSrc = $matches[1][0];
1632 $size = '';
1633
1634 if ( strpos( $imgSrc, site_url() ) !== false ) {
1635 $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc );
1636 } else {
1637 $imgAbs = ABSPATH . $imgSrc;
1638 }
1639
1640 $imgAbs = apply_filters( 'rt_tpg_sc_first_image_src', $imgAbs );
1641
1642 if ( file_exists( $imgAbs ) ) {
1643 $info = getimagesize( $imgAbs );
1644 $size = isset( $info[3] ) ? $info[3] : '';
1645 }
1646
1647 $image = '<img class="' . esc_attr( $img_class ) . '" src="' . esc_url( $imgSrc ) . '" ' . $size . ' alt="' . esc_attr( $alt ) . '"/>';
1648
1649 if ( $img_Class == 'swiper-lazy' ) {
1650 $image = '<img class="' . esc_attr( $img_class ) . ' img-responsive" data-src="' . esc_url( $imgSrc ) . '" src="#none" ' . $size . ' alt="' . esc_attr( $alt ) . '"/><div class="lazy-overlay-wrap"><div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div></div>';
1651 }
1652 }
1653 }
1654
1655 if ( ! $imgSrc && $defaultImgId ) {
1656 $image = wp_get_attachment_image( $defaultImgId, $fImgSize );
1657 }
1658
1659 if ( $imgSrc && $cSize ) {
1660 $w = ( ! empty( $customImgSize[0] ) ? absint( $customImgSize[0] ) : null );
1661 $h = ( ! empty( $customImgSize[1] ) ? absint( $customImgSize[1] ) : null );
1662 $c = ( ! empty( $customImgSize[2] ) && $customImgSize[2] == 'soft' ? false : true );
1663
1664 if ( $w && $h ) {
1665 $post_thumb_id = get_post_thumbnail_id( $post_id );
1666
1667 if ( $post_thumb_id ) {
1668 $featured_image = wp_get_attachment_image_src( $post_thumb_id, 'full' );
1669 $w = $featured_image[1] < $w ? $featured_image[1] : $w;
1670 $h = $featured_image[2] < $h ? $featured_image[2] : $h;
1671 }
1672
1673 $imgSrc = self::rtImageReSize( $imgSrc, $w, $h, $c );
1674
1675 if ( $img_Class !== 'swiper-lazy' ) {
1676 $image = '<img class="' . esc_attr( $img_class ) . '" src="' . esc_url( $imgSrc ) . '" width="' . absint( $w ) . '" height="' . absint( $h ) . '" alt="' . esc_attr( $alt ) . '"/>';
1677 } else {
1678 $image = '<img class="' . esc_attr( $img_class ) . ' img-responsive" data-src="' . esc_url( $imgSrc ) . '" src="#none" width="' . absint( $w ) . '" height="' . absint( $h ) . '" alt="' . esc_attr( $alt ) . '"/><div class="lazy-overlay-wrap"><div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div></div>';
1679 }
1680 }
1681 }
1682
1683 return $image;
1684 }
1685
1686 public static function getFeatureImageUrl( $post_id = null, $fImgSize = 'medium' ) {
1687 $image = $imgSrc = null;
1688
1689 if ( $aID = get_post_thumbnail_id( $post_id ) ) {
1690 $image = wp_get_attachment_image_src( $aID, $fImgSize );
1691 }
1692
1693 if ( is_array( $image ) ) {
1694 $imgSrc = $image[0];
1695 }
1696
1697 return $imgSrc;
1698 }
1699
1700 public static function tpgCharacterLimit( $limit, $content ) {
1701 $limit ++;
1702
1703 $text = '';
1704
1705 if ( mb_strlen( $content ) > $limit ) {
1706 $subex = mb_substr( $content, 0, $limit );
1707 $exwords = explode( ' ', $subex );
1708 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1709
1710 if ( $excut < 0 ) {
1711 $text = mb_substr( $subex, 0, $excut );
1712 } else {
1713 $text = $subex;
1714 }
1715 } else {
1716 $text = $content;
1717 }
1718
1719 return $text;
1720 }
1721
1722 public static function get_the_excerpt( $post_id, $data = [] ) {
1723 $type = $data['excerpt_type'];
1724 $post = get_post( $post_id );
1725
1726 if ( empty( $post ) ) {
1727 return '';
1728 }
1729
1730 if ( $type == 'full' ) {
1731 ob_start();
1732 the_content();
1733 $content = ob_get_clean();
1734
1735 return apply_filters( 'tpg_content_full', $content, $post_id, $data );
1736 } else {
1737 if ( class_exists( 'ET_GB_Block_Layout' ) ) {
1738 $defaultExcerpt = $post->post_excerpt ?: wp_trim_words( $post->post_content, 55 );
1739 } else if ( defined( 'WPB_VC_VERSION' ) ) {
1740 $the_content = $post->post_excerpt ?: wp_trim_words( $post->post_content, 55 );
1741 $shortcode_tags = [ 'VC_COLUMN_INNTER' ];
1742 $values = array_values( $shortcode_tags );
1743 $exclude_codes = implode( '|', $values );
1744 $defaultExcerpt = trim( preg_replace( "~(?:\[/?)(?!(?:$exclude_codes))[^/\]]+/?\]~s", '', $the_content ) );
1745 } else {
1746 $defaultExcerpt = get_the_excerpt( $post_id );
1747 }
1748
1749 $limit = isset( $data['excerpt_limit'] ) && $data['excerpt_limit'] ? abs( $data['excerpt_limit'] ) : 0;
1750 $more = $data['excerpt_more_text'];
1751 $excerpt = preg_replace( '`\[[^\]]*\]`', '', $defaultExcerpt );
1752 $excerpt = strip_shortcodes( $excerpt );
1753 $excerpt = preg_replace( '`[[^]]*]`', '', $excerpt );
1754 $excerpt = str_replace( '', '', $excerpt );
1755
1756 if ( $limit ) {
1757 $excerpt = wp_strip_all_tags( $excerpt );
1758
1759 if ( $type == 'word' ) {
1760 $limit = $limit + 1;
1761 $rawExcerpt = $excerpt;
1762 $excerpt = explode( ' ', $excerpt, $limit );
1763
1764 if ( count( $excerpt ) >= $limit ) {
1765 array_pop( $excerpt );
1766 $excerpt = implode( ' ', $excerpt );
1767 } else {
1768 $excerpt = $rawExcerpt;
1769 }
1770 } else {
1771 $excerpt = self::tpgCharacterLimit( $limit, $excerpt );
1772 }
1773 $excerpt = stripslashes( $excerpt );
1774 } else {
1775 $allowed_html = [
1776 'a' => [
1777 'href' => [],
1778 'title' => [],
1779 ],
1780 'strong' => [],
1781 'b' => [],
1782 'br' => [ [] ],
1783 ];
1784
1785 $excerpt = nl2br( wp_kses( $excerpt, $allowed_html ) );
1786 }
1787
1788 $excerpt = ( $more ? rtrim($excerpt, " .,-_") . $more : $excerpt );
1789
1790 return apply_filters( 'tpg_get_the_excerpt', $excerpt, $post_id, $data, $defaultExcerpt );
1791 }
1792 }
1793
1794 public static function get_the_title( $post_id, $data = [] ) {
1795 $title = $originalTitle = get_the_title( $post_id );
1796 $limit = isset( $data['title_limit'] ) ? absint( $data['title_limit'] ) : 0;
1797 $limit_type = isset( $data['title_limit_type'] ) ? trim( $data['title_limit_type'] ) : 'character';
1798
1799 if ( $limit ) {
1800 if ( $limit_type == 'word' ) {
1801 $limit = $limit + 1;
1802 $title = explode( ' ', $title, $limit );
1803
1804 if ( count( $title ) >= $limit ) {
1805 array_pop( $title );
1806 $title = implode( ' ', $title );
1807 } else {
1808 $title = $originalTitle;
1809 }
1810 } else {
1811 if ( $limit > 0 && strlen( $title ) > $limit ) {
1812 $title = mb_substr( $title, 0, $limit, 'utf-8' );
1813 $title = preg_replace( '/\W\w+\s*(\W*)$/', '$1', $title );
1814 }
1815 }
1816 }
1817
1818 return apply_filters( 'tpg_get_the_title', $title, $post_id, $data, $originalTitle );
1819 }
1820
1821
1822 public static function rt_pagination( $postGrid, $range = 4, $ajax = false ) {
1823 $html = $pages = null;
1824 $showitems = ( $range * 2 ) + 1;
1825
1826 $wpQuery = $postGrid;
1827
1828 global $wp_query;
1829
1830 if ( empty( $wpQuery ) ) {
1831 $wpQuery = $wp_query;
1832 }
1833
1834 $pages = ! empty( $wpQuery->max_num_pages ) ? $wpQuery->max_num_pages : 1;
1835 $paged = ! empty( $wpQuery->query['paged'] ) ? $wpQuery->query['paged'] : 1;
1836
1837 if ( is_front_page() ) {
1838 $paged = ! empty( $wp_query->query['paged'] ) ? $wp_query->query['paged'] : 1;
1839 }
1840
1841 $ajaxClass = null;
1842 $dataAttr = null;
1843
1844 if ( $ajax ) {
1845 $ajaxClass = ' rt-ajax';
1846 $dataAttr = "data-paged='1'";
1847 }
1848
1849 if ( 1 != $pages ) {
1850 $html .= '<div class="rt-pagination' . $ajaxClass . '" ' . $dataAttr . '>';
1851 $html .= '<ul class="pagination-list">';
1852 if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages && ! $ajax ) {
1853 $html .= "<li><a data-paged='1' href='" . get_pagenum_link( 1 ) . "' aria-label='First'>&laquo;</a></li>";
1854 }
1855
1856 if ( $paged > 1 && $showitems < $pages && ! $ajax ) {
1857 $p = $paged - 1;
1858 $html .= "<li><a data-paged='{$p}' href='" . get_pagenum_link( $p ) . "' aria-label='Previous'>&lsaquo;</a></li>";
1859 }
1860
1861 if ( $ajax ) {
1862 for ( $i = 1; $i <= $pages; $i ++ ) {
1863 $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>';
1864 }
1865 } else {
1866 for ( $i = 1; $i <= $pages; $i ++ ) {
1867 if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
1868 $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>';
1869 }
1870 }
1871 }
1872
1873 if ( $paged < $pages && $showitems < $pages && ! $ajax ) {
1874 $p = $paged + 1;
1875 $html .= "<li><a data-paged='{$p}' href=\"" . get_pagenum_link( $paged + 1 ) . "\" aria-label='Next'>&rsaquo;</a></li>";
1876 }
1877
1878 if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages && ! $ajax ) {
1879 $html .= "<li><a data-paged='{$pages}' href='" . get_pagenum_link( $pages ) . "' aria-label='Last'>&raquo;</a></li>";
1880 }
1881
1882 $html .= '</ul>';
1883 $html .= '</div>';
1884 }
1885
1886 return $html;
1887 }
1888
1889 public static function rt_pagination_ajax( $scID, $range = 4, $pages = '' ) {
1890 $html = null;
1891
1892 $html .= "<div class='rt-tpg-pagination-ajax' data-sc-id='{$scID}' data-paged='1'>";
1893 $html .= '</div>';
1894
1895 return $html;
1896 }
1897
1898 /**
1899 * Call the Image resize model for resize function
1900 *
1901 * @param $url
1902 * @param null $width
1903 * @param null $height
1904 * @param null $crop
1905 * @param bool|true $single
1906 * @param bool|false $upscale
1907 *
1908 * @return array|bool|string
1909 * @throws Exception
1910 * @throws Rt_Exception
1911 */
1912 public static function rtImageReSize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
1913 $rtResize = new ReSizer();
1914
1915 return $rtResize->process( $url, $width, $height, $crop, $single, $upscale );
1916 }
1917
1918
1919 /* Convert hexdec color string to rgb(a) string */
1920 public static function rtHex2rgba( $color, $opacity = .5 ) {
1921 $default = 'rgb(0,0,0)';
1922
1923 // Return default if no color provided.
1924 if ( empty( $color ) ) {
1925 return $default;
1926 }
1927
1928 // Sanitize $color if "#" is provided.
1929 if ( $color[0] == '#' ) {
1930 $color = substr( $color, 1 );
1931 }
1932
1933 // Check if color has 6 or 3 characters and get values.
1934 if ( strlen( $color ) == 6 ) {
1935 $hex = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ];
1936 } else if ( strlen( $color ) == 3 ) {
1937 $hex = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ];
1938 } else {
1939 return $default;
1940 }
1941
1942 // Convert hexadec to rgb.
1943 $rgb = array_map( 'hexdec', $hex );
1944
1945 // Check if opacity is set(rgba or rgb).
1946 if ( $opacity ) {
1947 if ( absint( $opacity ) > 1 ) {
1948 $opacity = 1.0;
1949 }
1950
1951 $output = 'rgba(' . implode( ',', $rgb ) . ',' . $opacity . ')';
1952 } else {
1953 $output = 'rgb(' . implode( ',', $rgb ) . ')';
1954 }
1955
1956 // Return rgb(a) color string.
1957 return $output;
1958 }
1959
1960 public static function meta_exist( $meta_key, $post_id = null, $type = 'post' ) {
1961 if ( ! $post_id ) {
1962 return false;
1963 }
1964
1965 return metadata_exists( $type, $post_id, $meta_key );
1966 }
1967
1968
1969 public static function get_offset_col( $col ) {
1970 $return = [
1971 'big' => 6,
1972 'small' => 6,
1973 ];
1974
1975 if ( $col ) {
1976 if ( $col == 12 ) {
1977 $return['big'] = 12;
1978 $return['small'] = 12;
1979 } else if ( $col == 6 ) {
1980 $return['big'] = 6;
1981 $return['small'] = 6;
1982 } else if ( $col == 4 ) {
1983 $return['big'] = 4;
1984 $return['small'] = 8;
1985 }
1986 }
1987
1988 return $return;
1989 }
1990
1991 public static function formatSpacing( $data = '' ) {
1992 if ( ! empty( $data ) ) {
1993 $spacing = array_filter( explode( ',', $data ), 'is_numeric' );
1994
1995 if ( count( $spacing ) > 4 ) {
1996 $spacing = array_slice( $spacing, 0, 4, true );
1997 }
1998
1999 $data = implode( 'px ', $spacing );
2000 }
2001
2002 return $data;
2003 }
2004
2005 public static function layoutStyle( $layoutID, $scMeta, $layout, $scId = null ) {
2006 $css = null;
2007 $css .= "<style type='text/css' media='all'>";
2008 // primary color
2009 if ( $scId ) {
2010 $primaryColor = ( isset( $scMeta['primary_color'][0] ) ? $scMeta['primary_color'][0] : null );
2011 $button_bg_color = ( isset( $scMeta['button_bg_color'][0] ) ? $scMeta['button_bg_color'][0] : null );
2012 $button_active_bg_color = ( isset( $scMeta['button_active_bg_color'][0] ) ? $scMeta['button_active_bg_color'][0] : null );
2013 $button_hover_bg_color = ( isset( $scMeta['button_hover_bg_color'][0] ) ? $scMeta['button_hover_bg_color'][0] : null );
2014 $button_text_color = ( isset( $scMeta['button_text_bg_color'][0] ) ? $scMeta['button_text_bg_color'][0]
2015 : ( isset( $scMeta['button_text_color'][0] ) ? $scMeta['button_text_color'][0] : null ) );
2016 $button_hover_text_color = ( isset( $scMeta['button_hover_text_color'][0] ) ? $scMeta['button_hover_text_color'][0] : null );
2017 $button_border_color = ( isset( $scMeta['button_border_color'][0] ) ? $scMeta['button_border_color'][0] : null );
2018 $overlay_color = ( ! empty( $scMeta['overlay_color'][0] ) ? self::rtHex2rgba(
2019 $scMeta['overlay_color'][0],
2020 ! empty( $scMeta['overlay_opacity'][0] ) ? absint( $scMeta['overlay_opacity'][0] ) / 10 : .8
2021 ) : null );
2022 $overlay_padding = ( ! empty( $scMeta['overlay_padding'][0] ) ? absint( $scMeta['overlay_padding'][0] ) : null );
2023 $gutter = ! empty( $scMeta['tgp_gutter'][0] ) ? absint( $scMeta['tgp_gutter'][0] ) : null;
2024 $read_more_button_border_radius = isset( $scMeta['tpg_read_more_button_border_radius'][0] ) ? $scMeta['tpg_read_more_button_border_radius'][0] : '';
2025 // Section
2026 $sectionBg = ( isset( $scMeta['tpg_full_area_bg'][0] ) ? $scMeta['tpg_full_area_bg'][0] : null );
2027 $sectionMargin = ( isset( $scMeta['tpg_full_area_margin'][0] ) ? $scMeta['tpg_full_area_margin'][0] : null );
2028 $sectionMargin = self::formatSpacing( $sectionMargin );
2029 $sectionPadding = ( isset( $scMeta['tpg_full_area_padding'][0] ) ? $scMeta['tpg_full_area_padding'][0] : null );
2030 $sectionPadding = self::formatSpacing( $sectionPadding );
2031 // Box
2032 $boxBg = ( isset( $scMeta['tpg_content_wrap_bg'][0] ) ? $scMeta['tpg_content_wrap_bg'][0] : null );
2033 $boxBorder = ( isset( $scMeta['tpg_content_wrap_border'][0] ) ? $scMeta['tpg_content_wrap_border'][0] : null );
2034 $boxBorderColor = ( isset( $scMeta['tpg_content_wrap_border_color'][0] ) ? $scMeta['tpg_content_wrap_border_color'][0] : null );
2035 $boxBorderRadius = ( isset( $scMeta['tpg_content_wrap_border_radius'][0] ) ? $scMeta['tpg_content_wrap_border_radius'][0] : null );
2036 $boxShadow = ( isset( $scMeta['tpg_content_wrap_shadow'][0] ) ? $scMeta['tpg_content_wrap_shadow'][0] : null );
2037 $boxPadding = ( isset( $scMeta['tpg_box_padding'][0] ) ? $scMeta['tpg_box_padding'][0] : null );
2038 $boxPadding = self::formatSpacing( $boxPadding );
2039 $contentPadding = ( isset( $scMeta['tpg_content_padding'][0] ) ? $scMeta['tpg_content_padding'][0] : null );
2040 $contentPadding = self::formatSpacing( $contentPadding );
2041 // Heading
2042 $headingBg = ( isset( $scMeta['tpg_heading_bg'][0] ) ? $scMeta['tpg_heading_bg'][0] : null );
2043 $headingColor = ( isset( $scMeta['tpg_heading_color'][0] ) ? $scMeta['tpg_heading_color'][0] : null );
2044 $headingBorderColor = ( isset( $scMeta['tpg_heading_border_color'][0] ) ? $scMeta['tpg_heading_border_color'][0] : null );
2045 $headingBorderSize = ( isset( $scMeta['tpg_heading_border_size'][0] ) ? $scMeta['tpg_heading_border_size'][0] : null );
2046 $headingMargin = ( isset( $scMeta['tpg_heading_margin'][0] ) ? $scMeta['tpg_heading_margin'][0] : null );
2047 $headingMargin = self::formatSpacing( $headingMargin );
2048 $headingPadding = ( isset( $scMeta['tpg_heading_padding'][0] ) ? $scMeta['tpg_heading_padding'][0] : null );
2049 $headingPadding = self::formatSpacing( $headingPadding );
2050 // Category
2051 $catBg = ( isset( $scMeta['tpg_category_bg'][0] ) ? $scMeta['tpg_category_bg'][0] : null );
2052 $catTextColor = ( isset( $scMeta['tpg_category_color'][0] ) ? $scMeta['tpg_category_color'][0] : null );
2053 $catBorderRadius = ( isset( $scMeta['tpg_category_border_radius'][0] ) ? $scMeta['tpg_category_border_radius'][0] : null );
2054 $catMargin = ( isset( $scMeta['tpg_category_margin'][0] ) ? $scMeta['tpg_category_margin'][0] : null );
2055 $catMargin = self::formatSpacing( $catMargin );
2056 $catPadding = ( isset( $scMeta['tpg_category_padding'][0] ) ? $scMeta['tpg_category_padding'][0] : null );
2057 $catPadding = self::formatSpacing( $catPadding );
2058 $categorySize = ( ! empty( $scMeta['rt_tpg_category_font_size'][0] ) ? absint( $scMeta['rt_tpg_category_font_size'][0] ) : null );
2059 // Image
2060 $image_border_radius = isset( $scMeta['tpg_image_border_radius'][0] ) ? $scMeta['tpg_image_border_radius'][0] : '';
2061 // Title
2062 $title_color = ( ! empty( $scMeta['title_color'][0] ) ? $scMeta['title_color'][0] : null );
2063 $title_size = ( ! empty( $scMeta['title_size'][0] ) ? absint( $scMeta['title_size'][0] ) : null );
2064 $title_weight = ( ! empty( $scMeta['title_weight'][0] ) ? $scMeta['title_weight'][0] : null );
2065 $title_alignment = ( ! empty( $scMeta['title_alignment'][0] ) ? $scMeta['title_alignment'][0] : null );
2066
2067 $title_hover_color = ( ! empty( $scMeta['title_hover_color'][0] ) ? $scMeta['title_hover_color'][0] : null );
2068
2069 $excerpt_color = ( ! empty( $scMeta['excerpt_color'][0] ) ? $scMeta['excerpt_color'][0] : null );
2070 $excerpt_size = ( ! empty( $scMeta['excerpt_size'][0] ) ? absint( $scMeta['excerpt_size'][0] ) : null );
2071 $excerpt_weight = ( ! empty( $scMeta['excerpt_weight'][0] ) ? $scMeta['excerpt_weight'][0] : null );
2072 $excerpt_alignment = ( ! empty( $scMeta['excerpt_alignment'][0] ) ? $scMeta['excerpt_alignment'][0] : null );
2073
2074 $meta_data_color = ( ! empty( $scMeta['meta_data_color'][0] ) ? $scMeta['meta_data_color'][0] : null );
2075 $meta_data_size = ( ! empty( $scMeta['meta_data_size'][0] ) ? absint( $scMeta['meta_data_size'][0] ) : null );
2076 $meta_data_weight = ( ! empty( $scMeta['meta_data_weight'][0] ) ? $scMeta['meta_data_weight'][0] : null );
2077 $meta_data_alignment = ( ! empty( $scMeta['meta_data_alignment'][0] ) ? $scMeta['meta_data_alignment'][0] : null );
2078 } else {
2079 $primaryColor = ( isset( $scMeta['primary_color'] ) ? $scMeta['primary_color'] : null );
2080 $button_bg_color = ( isset( $scMeta['button_bg_color'] ) ? $scMeta['button_bg_color'] : null );
2081 $button_active_bg_color = ( isset( $scMeta['button_active_bg_color'] ) ? $scMeta['button_active_bg_color'] : null );
2082 $button_hover_bg_color = ( isset( $scMeta['button_hover_bg_color'] ) ? $scMeta['button_hover_bg_color'] : null );
2083 $btn_text_color = ( isset( $scMeta['button_text_color'] ) ? $scMeta['button_text_color'] : null );
2084 $button_text_color = ( ! empty( $scMeta['button_text_bg_color'] ) ? $scMeta['button_text_bg_color']
2085 : ( ! empty( $btn_text_color ) ? $btn_text_color : null ) );
2086 $button_border_color = ( isset( $scMeta['button_border_color'] ) ? $scMeta['button_border_color'] : null );
2087 $button_hover_text_color = ( isset( $scMeta['button_hover_text_color'] ) ? $scMeta['button_hover_text_color'] : null );
2088 $overlay_color = ( ! empty( $scMeta['overlay_color'] ) ? self::rtHex2rgba(
2089 $scMeta['overlay_color'],
2090 ! empty( $scMeta['overlay_opacity'] ) ? absint( $scMeta['overlay_opacity'] ) / 10 : .8
2091 ) : null );
2092 $overlay_padding = ( ! empty( $scMeta['overlay_padding'] ) ? absint( $scMeta['overlay_padding'] ) : null );
2093 $gutter = ! empty( $scMeta['tgp_gutter'] ) ? absint( $scMeta['tgp_gutter'] ) : null;
2094 $read_more_button_border_radius = isset( $scMeta['tpg_read_more_button_border_radius'] ) ? $scMeta['tpg_read_more_button_border_radius'] : '';
2095 // Section
2096 $sectionBg = ( isset( $scMeta['tpg_full_area_bg'] ) ? $scMeta['tpg_full_area_bg'] : null );
2097 $sectionMargin = ( isset( $scMeta['tpg_full_area_margin'] ) ? $scMeta['tpg_full_area_margin'] : null );
2098 $sectionMargin = self::formatSpacing( $sectionMargin );
2099 $sectionPadding = ( isset( $scMeta['tpg_full_area_padding'] ) ? $scMeta['tpg_full_area_padding'] : null );
2100 $sectionPadding = self::formatSpacing( $sectionPadding );
2101 // Box
2102 $boxBg = ( isset( $scMeta['tpg_content_wrap_bg'] ) ? $scMeta['tpg_content_wrap_bg'] : null );
2103 $boxBorder = ( isset( $scMeta['tpg_content_wrap_border'] ) ? $scMeta['tpg_content_wrap_border'] : null );
2104 $boxBorderColor = ( isset( $scMeta['tpg_content_wrap_border_color'] ) ? $scMeta['tpg_content_wrap_border_color'] : null );
2105 $boxBorderRadius = ( isset( $scMeta['tpg_content_wrap_border_radius'] ) ? $scMeta['tpg_content_wrap_border_radius'] : null );
2106 $boxShadow = ( isset( $scMeta['tpg_content_wrap_shadow'] ) ? $scMeta['tpg_content_wrap_shadow'] : null );
2107 $boxPadding = ( isset( $scMeta['tpg_box_padding'] ) ? $scMeta['tpg_box_padding'] : null );
2108 $boxPadding = self::formatSpacing( $boxPadding );
2109 $contentPadding = ( isset( $scMeta['tpg_content_padding'] ) ? $scMeta['tpg_content_padding'] : null );
2110 $contentPadding = self::formatSpacing( $contentPadding );
2111 // Heading
2112 $headingBg = ( isset( $scMeta['tpg_heading_bg'] ) ? $scMeta['tpg_heading_bg'] : null );
2113 $headingColor = ( isset( $scMeta['tpg_heading_color'] ) ? $scMeta['tpg_heading_color'] : null );
2114 $headingBorderColor = ( isset( $scMeta['tpg_heading_border_color'] ) ? $scMeta['tpg_heading_border_color'] : null );
2115 $headingBorderSize = ( isset( $scMeta['tpg_heading_border_size'] ) ? $scMeta['tpg_heading_border_size'] : null );
2116 $headingMargin = ( isset( $scMeta['tpg_heading_margin'] ) ? $scMeta['tpg_heading_margin'] : null );
2117 $headingMargin = self::formatSpacing( $headingMargin );
2118 $headingPadding = ( isset( $scMeta['tpg_heading_padding'] ) ? $scMeta['tpg_heading_padding'] : null );
2119 $headingPadding = self::formatSpacing( $headingPadding );
2120 // Category
2121 $catBg = ( isset( $scMeta['tpg_category_bg'] ) ? $scMeta['tpg_category_bg'] : null );
2122 $catTextColor = ( isset( $scMeta['tpg_category_color'] ) ? $scMeta['tpg_category_color'] : null );
2123 $catBorderRadius = ( isset( $scMeta['tpg_category_border_radius'] ) ? $scMeta['tpg_category_border_radius'] : null );
2124 $catMargin = ( isset( $scMeta['tpg_category_margin'] ) ? $scMeta['tpg_category_margin'] : null );
2125 $catPadding = ( isset( $scMeta['tpg_category_padding'] ) ? $scMeta['tpg_category_padding'] : null );
2126 $categorySize = ( ! empty( $scMeta['rt_tpg_category_font_size'] ) ? absint( $scMeta['rt_tpg_category_font_size'] ) : null );
2127 // Image
2128 $image_border_radius = isset( $scMeta['tpg_image_border_radius'] ) ? $scMeta['tpg_image_border_radius'] : '';
2129 // Title
2130 $title_color = ( ! empty( $scMeta['title_color'] ) ? $scMeta['title_color'] : null );
2131 $title_size = ( ! empty( $scMeta['title_size'] ) ? absint( $scMeta['title_size'] ) : null );
2132 $title_weight = ( ! empty( $scMeta['title_weight'] ) ? $scMeta['title_weight'] : null );
2133 $title_alignment = ( ! empty( $scMeta['title_alignment'] ) ? $scMeta['title_alignment'] : null );
2134
2135 $title_hover_color = ( ! empty( $scMeta['title_hover_color'] ) ? $scMeta['title_hover_color'] : null );
2136
2137 $excerpt_color = ( ! empty( $scMeta['excerpt_color'] ) ? $scMeta['excerpt_color'] : null );
2138 $excerpt_size = ( ! empty( $scMeta['excerpt_size'] ) ? absint( $scMeta['excerpt_size'] ) : null );
2139 $excerpt_weight = ( ! empty( $scMeta['excerpt_weight'] ) ? $scMeta['excerpt_weight'] : null );
2140 $excerpt_alignment = ( ! empty( $scMeta['excerpt_alignment'] ) ? $scMeta['excerpt_alignment'] : null );
2141
2142 $meta_data_color = ( ! empty( $scMeta['meta_data_color'] ) ? $scMeta['meta_data_color'] : null );
2143 $meta_data_size = ( ! empty( $scMeta['meta_data_size'] ) ? absint( $scMeta['meta_data_size'] ) : null );
2144 $meta_data_weight = ( ! empty( $scMeta['meta_data_weight'] ) ? $scMeta['meta_data_weight'] : null );
2145 $meta_data_alignment = ( ! empty( $scMeta['meta_data_alignment'] ) ? $scMeta['meta_data_alignment'] : null );
2146 }
2147
2148 $id = str_replace( 'rt-tpg-container-', '', $layoutID );
2149
2150 if ( $primaryColor ) {
2151 $css .= "#{$layoutID} .rt-holder .rt-woo-info .price{";
2152 $css .= 'color:' . $primaryColor . ';';
2153 $css .= '}';
2154 $css .= "body .rt-tpg-container .rt-tpg-isotope-buttons .selected,
2155 #{$layoutID} .layout12 .rt-holder:hover .rt-detail,
2156 #{$layoutID} .isotope8 .rt-holder:hover .rt-detail,
2157 #{$layoutID} .carousel8 .rt-holder:hover .rt-detail,
2158 #{$layoutID} .layout13 .rt-holder .overlay .post-info,
2159 #{$layoutID} .isotope9 .rt-holder .overlay .post-info,
2160 #{$layoutID}.rt-tpg-container .layout4 .rt-holder .rt-detail,
2161 .rt-modal-{$id} .md-content,
2162 .rt-modal-{$id} .md-content > .rt-md-content-holder .rt-md-content,
2163 .rt-popup-wrap-{$id}.rt-popup-wrap .rt-popup-navigation-wrap,
2164 #{$layoutID} .carousel9 .rt-holder .overlay .post-info{";
2165 $css .= 'background-color:' . $primaryColor . ';';
2166 $css .= '}';
2167
2168 $ocp = self::rtHex2rgba(
2169 $primaryColor,
2170 ! empty( $scMeta['overlay_opacity'][0] ) ? absint( $scMeta['overlay_opacity'][0] ) / 10 : .8
2171 );
2172 $css .= "#{$layoutID} .layout5 .rt-holder .overlay, #{$layoutID} .isotope2 .rt-holder .overlay, #{$layoutID} .carousel2 .rt-holder .overlay,#{$layoutID} .layout15 .rt-holder h3, #{$layoutID} .isotope11 .rt-holder h3, #{$layoutID} .carousel11 .rt-holder h3, #{$layoutID} .layout16 .rt-holder h3,
2173 #{$layoutID} .isotope12 .rt-holder h3, #{$layoutID} .carousel12 .rt-holder h3 {";
2174 $css .= 'background-color:' . $ocp . ';';
2175 $css .= '}';
2176 }
2177
2178 if ( $button_border_color ) {
2179 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
2180 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item,
2181 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn,
2182 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action,
2183 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item,
2184 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap{";
2185 $css .= 'border-color:' . $button_border_color . ' !important;';
2186 $css .= '}';
2187 $css .= "#{$layoutID} .rt-holder .read-more a {";
2188 $css .= 'border-color:' . $button_border_color . ';';
2189 $css .= '}';
2190 }
2191
2192 if ( $button_bg_color ) {
2193 $css .= "#{$layoutID} .pagination-list li a,
2194 {$layoutID} .pagination-list li span,
2195 {$layoutID} .pagination li a,
2196 #{$layoutID} .rt-tpg-isotope-buttons button,
2197 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button,
2198 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn,
2199 #{$layoutID}.rt-tpg-container .swiper-pagination-bullet,
2200 #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a,
2201 #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart,
2202 #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart,
2203 #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart,
2204 #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart,
2205 #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart,
2206 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown,
2207 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item,
2208 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a,
2209 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
2210 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn,
2211 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *,
2212 #{$layoutID} .rt-read-more,
2213 #rt-tooltip-{$id}, #rt-tooltip-{$id} .rt-tooltip-bottom:after{";
2214 $css .= 'background-color:' . $button_bg_color . ';';
2215 $css .= '}';
2216 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
2217 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item{";
2218 $css .= 'border-color:' . $button_bg_color . ';';
2219 $css .= '}';
2220 $css .= "#{$layoutID}.rt-tpg-container .layout17 .rt-holder .overlay a.tpg-zoom .fa{";
2221 $css .= 'color:' . $button_bg_color . ';';
2222 $css .= '}';
2223
2224 $css .= "#{$layoutID} .rt-holder .read-more a {";
2225 $css .= 'background-color:' . $button_bg_color . ';padding: 8px 15px;';
2226 $css .= '}';
2227 }
2228
2229 // button active color.
2230 if ( $button_active_bg_color ) {
2231 $css .= "#{$layoutID} .pagination li.active span,
2232 #{$layoutID} .pagination-list li.active span,
2233 #{$layoutID} .rt-tpg-isotope-buttons button.selected,
2234 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected,
2235 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item.selected,
2236 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a,
2237 #{$layoutID}.rt-tpg-container .swiper-pagination-bullet.swiper-pagination-bullet-active-main{";
2238 $css .= 'background-color:' . $button_active_bg_color . ';';
2239 $css .= '}';
2240
2241 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected,
2242 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item.selected,
2243 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a{";
2244 $css .= 'border-color:' . $button_active_bg_color . ';';
2245 $css .= '}';
2246 }
2247
2248 // Button hover bg color.
2249 if ( $button_hover_bg_color ) {
2250 $css .= "#{$layoutID} .pagination-list li a:hover,
2251 #{$layoutID} .pagination li a:hover,
2252 #{$layoutID} .rt-tpg-isotope-buttons button:hover,
2253 #{$layoutID} .rt-holder .read-more a:hover,
2254 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button:hover,
2255 #{$layoutID}.rt-tpg-container .swiper-pagination-bullet:hover,
2256 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover,
2257 #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a:hover,
2258 #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart:hover,
2259 #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart:hover,
2260 #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart:hover,
2261 #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart:hover,
2262 #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart:hover,
2263 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item:hover,
2264 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item.selected,
2265 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover,
2266 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover,
2267 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a:hover,
2268 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *:hover,
2269 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn:hover,
2270 #{$layoutID} .rt-read-more:hover,
2271 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button:hover{";
2272 $css .= 'background-color:' . $button_hover_bg_color . ';';
2273 $css .= '}';
2274
2275 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover,
2276 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover,
2277 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover,
2278 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a:hover{";
2279 $css .= 'border-color:' . $button_hover_bg_color . ';';
2280 $css .= '}';
2281 $css .= "#{$layoutID}.rt-tpg-container .layout17 .rt-holder .overlay a.tpg-zoom:hover .fa{";
2282 $css .= 'color:' . $button_hover_bg_color . ';';
2283 $css .= '}';
2284 }
2285
2286 // Button text color.
2287 if ( $button_text_color ) {
2288 $css .= "#{$layoutID} .pagination-list li a,
2289 #{$layoutID} .pagination li a,
2290 #{$layoutID} .rt-tpg-isotope-buttons button,
2291 #{$layoutID} .rt-holder .read-more a,
2292 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button,
2293 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn,
2294 #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a,
2295 #{$layoutID} .edd1 .rt-holder .rt-img-holder .overlay .product-more ul li a,
2296 #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart,
2297 #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart,
2298 #{$layoutID} .edd2 .rt-detail .rt-wc-add-to-cart,
2299 #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart,
2300 #{$layoutID} .edd3 .rt-detail .rt-wc-add-to-cart,
2301 #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart,
2302 #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart,
2303 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button,
2304 #rt-tooltip-{$id},
2305 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
2306 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item,
2307 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action,
2308 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item,
2309 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a,
2310 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *,
2311 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn,
2312 #{$layoutID} .rt-read-more,
2313 #rt-tooltip-{$id} .rt-tooltip-bottom:after{";
2314 $css .= 'color:' . $button_text_color . ';';
2315 $css .= '}';
2316 }
2317
2318 if ( $button_hover_text_color ) {
2319 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover,
2320 #{$layoutID} .rt-holder .read-more a:hover,
2321 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover,
2322 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover,
2323 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item:hover,
2324 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item.selected,
2325 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action:hover,
2326 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a:hover,
2327 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected,
2328 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action,
2329 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn:hover,
2330 #{$layoutID} .rt-read-more:hover,
2331 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a{";
2332 $css .= 'color:' . $button_hover_text_color . ';';
2333 $css .= '}';
2334 }
2335
2336 if ( $overlay_color || $overlay_padding ) {
2337 if ( in_array( $layout, [ 'layout15', 'isotope11', 'carousel11' ] ) ) {
2338 $css .= "#{$layoutID} .{$layout} .rt-holder:hover .overlay .post-info{";
2339 } else if ( in_array(
2340 $layout,
2341 [ 'layout10', 'isotope7', 'carousel6', 'carousel7', 'layout9', 'offset04' ]
2342 )
2343 ) {
2344 $css .= "#{$layoutID} .{$layout} .rt-holder .post-info{";
2345 } else if ( in_array( $layout, [ 'layout7', 'isotope4', 'carousel4' ] ) ) {
2346 $css .= "#{$layoutID} .{$layout} .rt-holder .overlay:hover{";
2347 } else if ( in_array( $layout, [ 'layout16', 'isotope12', 'carousel12' ] ) ) {
2348 $css .= "#{$layoutID} .{$layout} .rt-holder .overlay .post-info {";
2349 } else if ( in_array( $layout, [ 'offset03', 'carousel5' ] ) ) {
2350 $css .= "#{$layoutID} .{$layout} .rt-holder .overlay{";
2351 } else {
2352 $css .= "#{$layoutID} .rt-post-overlay .post-img > a:first-of-type::after,";
2353 $css .= "#{$layoutID} .rt-holder .overlay:hover{";
2354 }
2355
2356 if ( $overlay_color ) {
2357 $css .= 'background-image: none;';
2358 $css .= 'background-color:' . $overlay_color . ';';
2359 }
2360
2361 if ( $overlay_padding ) {
2362 $css .= 'padding-top:' . $overlay_padding . '%;';
2363 }
2364
2365 $css .= '}';
2366 }
2367
2368 if ( $boxShadow ) {
2369 $css .= "#{$layoutID} .{$layout} .rt-holder {";
2370 $css .= "box-shadow : 0px 0px 2px 0px {$boxShadow};";
2371 $css .= '}';
2372 }
2373
2374 /* gutter */
2375 if ( $gutter ) {
2376 $css .= "#{$layoutID} [class*='rt-col-'] {";
2377 $css .= "padding-left : {$gutter}px !important;";
2378 $css .= "padding-right : {$gutter}px !important;";
2379 $css .= "margin-top : {$gutter}px;";
2380 $css .= "margin-bottom : {$gutter}px;";
2381 $css .= '}';
2382 $css .= "#{$layoutID} .rt-row{";
2383 $css .= "margin-left : -{$gutter}px !important;";
2384 $css .= "margin-right : -{$gutter}px !important;";
2385 $css .= '}';
2386 $css .= "#{$layoutID}.rt-container-fluid,#{$layoutID}.rt-container{";
2387 $css .= "padding-left : {$gutter}px;";
2388 $css .= "padding-right : {$gutter}px;";
2389 $css .= '}';
2390
2391 // remove inner row margin.
2392 $css .= "#{$layoutID} .rt-row .rt-row [class*='rt-col-'] {";
2393 $css .= 'margin-top : 0;';
2394 $css .= '}';
2395 }
2396
2397 // Read more button border radius.
2398 if ( isset( $read_more_button_border_radius ) || trim( $read_more_button_border_radius ) !== '' ) {
2399 $css .= "#{$layoutID} .read-more a{";
2400 $css .= 'border-radius:' . $read_more_button_border_radius . 'px;';
2401 $css .= '}';
2402 }
2403
2404 // Section.
2405 if ( $sectionBg ) {
2406 $css .= "#{$layoutID}.rt-tpg-container {";
2407 $css .= 'background:' . $sectionBg . ';';
2408 $css .= '}';
2409 }
2410
2411 if ( $sectionMargin ) {
2412 $css .= "#{$layoutID}.rt-tpg-container {";
2413 $css .= 'margin:' . $sectionMargin . 'px;';
2414 $css .= '}';
2415 }
2416
2417 if ( $sectionPadding ) {
2418 $css .= "#{$layoutID}.rt-tpg-container {";
2419 $css .= 'padding:' . $sectionPadding . 'px;';
2420 $css .= '}';
2421 }
2422
2423 // Box.
2424 if ( $boxBg ) {
2425 $css .= "#{$layoutID} .rt-holder, #{$layoutID} .rt-holder .rt-detail,#{$layoutID} .rt-post-overlay .post-img + .post-content {";
2426 $css .= 'background-color:' . $boxBg . ';';
2427 $css .= '}';
2428 }
2429
2430 if ( $boxBorderColor ) {
2431 $css .= "#{$layoutID} .rt-holder {";
2432 $css .= 'border-color:' . $boxBorderColor . ';';
2433 $css .= '}';
2434 }
2435
2436 if ( $boxBorder ) {
2437 $css .= "#{$layoutID} .rt-holder {";
2438 $css .= 'border-style: solid;';
2439 $css .= 'border-width:' . $boxBorder . 'px;';
2440 $css .= '}';
2441 }
2442
2443 if ( $boxBorderRadius ) {
2444 $css .= "#{$layoutID} .rt-holder {";
2445 $css .= 'border-radius:' . $boxBorderRadius . 'px;';
2446 $css .= '}';
2447 }
2448
2449 if ( $boxPadding ) {
2450 $css .= "#{$layoutID} .rt-holder {";
2451 $css .= 'padding:' . $boxPadding . 'px;';
2452 $css .= '}';
2453 }
2454
2455 if ( $contentPadding ) {
2456 $css .= "#{$layoutID} .rt-holder .rt-detail {";
2457 $css .= 'padding:' . $contentPadding . 'px;';
2458 $css .= '}';
2459 }
2460
2461 // Widget heading.
2462 if ( $headingBg ) {
2463 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 .tpg-widget-heading {";
2464 $css .= 'background:' . $headingBg . ';';
2465 $css .= '}';
2466
2467 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading::after {";
2468 $css .= 'border-top-color:' . $headingBg . ';';
2469 $css .= '}';
2470 }
2471
2472 if ( $headingColor ) {
2473 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading a, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading a, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 .tpg-widget-heading a {";
2474 $css .= 'color:' . $headingColor . ';';
2475 $css .= '}';
2476 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading::before {";
2477 $css .= 'background-color:' . $headingColor . ';';
2478 $css .= '}';
2479 }
2480
2481 if ( $headingBorderSize ) {
2482 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 {";
2483 // $css .= "border-bottom-style: solid;";
2484 $css .= 'border-bottom-width:' . $headingBorderSize . 'px;';
2485 $css .= '}';
2486
2487 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading-line {";
2488 $css .= 'border-width:' . $headingBorderSize . 'px 0;';
2489 $css .= '}';
2490 }
2491
2492 if ( $headingBorderColor ) {
2493 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading-line, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 {";
2494 $css .= 'border-color:' . $headingBorderColor . ';';
2495 $css .= '}';
2496 }
2497
2498 if ( $headingMargin ) {
2499 $css .= "#{$layoutID} .tpg-widget-heading-wrapper {";
2500 $css .= 'margin:' . $headingMargin . 'px;';
2501 $css .= '}';
2502 }
2503
2504 if ( $headingPadding ) {
2505 $css .= "#{$layoutID} .tpg-widget-heading-wrapper .tpg-widget-heading {";
2506 $css .= 'padding:' . $headingPadding . 'px;';
2507 $css .= '}';
2508 }
2509
2510 // Image border.
2511 if ( isset( $image_border_radius ) || trim( $image_border_radius ) !== '' ) {
2512 $css .= "#{$layoutID} .rt-img-holder img.rt-img-responsive,#{$layoutID} .rt-img-holder,
2513 #{$layoutID} .rt-post-overlay .post-img,
2514 #{$layoutID} .post-sm .post-img,
2515 #{$layoutID} .rt-post-grid .post-img,
2516 #{$layoutID} .post-img img {";
2517 $css .= 'border-radius:' . $image_border_radius . 'px;';
2518 $css .= '}';
2519 }
2520
2521 // Title decoration.
2522 if ( $title_color || $title_size || $title_weight || $title_alignment ) {
2523 $css .= "#{$layoutID} .{$layout} .rt-holder h2.entry-title,
2524 #{$layoutID} .{$layout} .rt-holder h3.entry-title,
2525 #{$layoutID} .{$layout} .rt-holder h4.entry-title,
2526 #{$layoutID} .{$layout} .rt-holder h2.entry-title a,
2527 #{$layoutID} .{$layout} .rt-holder h3.entry-title a,
2528 #{$layoutID} .{$layout} .rt-holder h4.entry-title a,
2529 #{$layoutID} .rt-holder .rt-woo-info h2 a,
2530 #{$layoutID} .rt-holder .rt-woo-info h3 a,
2531 #{$layoutID} .rt-holder .rt-woo-info h4 a,
2532 #{$layoutID} .post-content .post-title,
2533 #{$layoutID} .rt-post-grid .post-title,
2534 #{$layoutID} .rt-post-grid .post-title a,
2535 #{$layoutID} .post-content .post-title a,
2536 #{$layoutID} .rt-holder .rt-woo-info h2,
2537 #{$layoutID} .rt-holder .rt-woo-info h3,
2538 #{$layoutID} .rt-holder .rt-woo-info h4{";
2539
2540 if ( $title_color ) {
2541 $css .= 'color:' . $title_color . ';';
2542 }
2543
2544 if ( $title_size ) {
2545 $lineHeight = $title_size + 10;
2546 $css .= 'font-size:' . $title_size . 'px;';
2547 $css .= 'line-height:' . $lineHeight . 'px;';
2548 }
2549
2550 if ( $title_weight ) {
2551 $css .= 'font-weight:' . $title_weight . ';';
2552 }
2553
2554 if ( $title_alignment ) {
2555 $css .= 'text-align:' . $title_alignment . ';';
2556 }
2557
2558 $css .= '}';
2559
2560 if ( $title_size ) {
2561 $css .= "#{$layoutID} .post-grid-lg-style-1 .post-title,
2562 #{$layoutID} .post-grid-lg-style-1 .post-title a,
2563 #{$layoutID} .big-layout .post-title,
2564 #{$layoutID} .big-layout .post-title a,
2565 #{$layoutID} .post-grid-lg-style-1 .post-title,
2566 #{$layoutID} .post-grid-lg-style-1 .post-title a {";
2567 $css .= 'font-size:' . ( $title_size + 8 ) . 'px;';
2568 $css .= 'line-height:' . ( $lineHeight + 8 ) . 'px;';
2569 $css .= '}';
2570 }
2571 }
2572
2573 // Title hover color.
2574 if ( $title_hover_color ) {
2575 $css .= "#{$layoutID} .{$layout} .rt-holder h2.entry-title:hover,
2576 #{$layoutID} .{$layout} .rt-holder h3.entry-title:hover,
2577 #{$layoutID} .{$layout} .rt-holder h4.entry-title:hover,
2578 #{$layoutID} .{$layout} .rt-holder h2.entry-title a:hover,
2579 #{$layoutID} .{$layout} .rt-holder h3.entry-title a:hover,
2580 #{$layoutID} .{$layout} .rt-holder h4.entry-title a:hover,
2581 #{$layoutID} .post-content .post-title a:hover,
2582 #{$layoutID} .rt-post-grid .post-title a:hover,
2583 #{$layoutID} .rt-holder .rt-woo-info h2 a:hover,
2584 #{$layoutID} .rt-holder .rt-woo-info h3 a:hover,
2585 #{$layoutID} .rt-holder .rt-woo-info h4 a:hover,
2586 #{$layoutID} .rt-holder .rt-woo-info h2:hover,
2587 #{$layoutID} .rt-holder .rt-woo-info h3:hover,
2588 #{$layoutID} .rt-holder .rt-woo-info h4:hover{";
2589 $css .= 'color:' . $title_hover_color . ' !important;';
2590 $css .= '}';
2591 }
2592 // Excerpt decoration.
2593 if ( $excerpt_color || $excerpt_size || $excerpt_weight || $excerpt_alignment ) {
2594 $css .= "#{$layoutID} .{$layout} .rt-holder .tpg-excerpt,#{$layoutID} .{$layout} .tpg-excerpt,#{$layoutID} .{$layout} .rt-holder .post-content,#{$layoutID} .rt-holder .rt-woo-info p,#{$layoutID} .post-content p {";
2595
2596 if ( $excerpt_color ) {
2597 $css .= 'color:' . $excerpt_color . ';';
2598 }
2599
2600 if ( $excerpt_size ) {
2601 $css .= 'font-size:' . $excerpt_size . 'px;';
2602 }
2603
2604 if ( $excerpt_weight ) {
2605 $css .= 'font-weight:' . $excerpt_weight . ';';
2606 }
2607
2608 if ( $excerpt_alignment ) {
2609 $css .= 'text-align:' . $excerpt_alignment . ';';
2610 }
2611
2612 $css .= '}';
2613 }
2614
2615 // Post meta decoration.
2616 if ( $meta_data_color || $meta_data_size || $meta_data_weight || $meta_data_alignment ) {
2617 $css .= "#{$layoutID} .{$layout} .rt-holder .post-meta-user,
2618 #{$layoutID} .{$layout} .rt-meta,
2619 #{$layoutID} .{$layout} .rt-meta a,
2620 #{$layoutID} .{$layout} .rt-holder .post-meta-user .meta-data,
2621 #{$layoutID} .{$layout} .rt-holder .post-meta-user a,
2622 #{$layoutID} .{$layout} .rt-holder .rt-detail .post-meta .rt-tpg-social-share,
2623 #{$layoutID} .rt-post-overlay .post-meta-user span,
2624 #{$layoutID} .rt-post-overlay .post-meta-user,
2625 #{$layoutID} .rt-post-overlay .post-meta-user a,
2626 #{$layoutID} .rt-post-grid .post-meta-user,
2627 #{$layoutID} .rt-post-grid .post-meta-user a,
2628 #{$layoutID} .rt-post-box-media-style .post-meta-user,
2629 #{$layoutID} .rt-post-box-media-style .post-meta-user a,
2630 #{$layoutID} .{$layout} .post-meta-user i,
2631 #{$layoutID} .rt-detail .post-meta-category a,
2632 #{$layoutID} .{$layout} .post-meta-user a
2633 #{$layoutID} .{$layout} .post-meta-user a {";
2634
2635 if ( $meta_data_color ) {
2636 $css .= 'color:' . $meta_data_color . ';';
2637 }
2638
2639 if ( $meta_data_size ) {
2640 $css .= 'font-size:' . $meta_data_size . 'px;';
2641 }
2642
2643 if ( $meta_data_weight ) {
2644 $css .= 'font-weight:' . $meta_data_weight . ';';
2645 }
2646
2647 if ( $meta_data_alignment ) {
2648 $css .= 'text-align:' . $meta_data_alignment . ';';
2649 }
2650
2651 $css .= '}';
2652 }
2653
2654 // Category.
2655 if ( $catBg ) {
2656 $css .= "#{$layoutID} .cat-over-image.style2 .categories-links a,
2657 #{$layoutID} .cat-over-image.style3 .categories-links a,
2658 #{$layoutID} .cat-above-title.style2 .categories-links a,
2659 #{$layoutID} .cat-above-title.style3 .categories-links a,
2660 #{$layoutID} .rt-tpg-category > a {
2661 background-color: {$catBg};
2662 }";
2663
2664 $css .= "#{$layoutID} .cat-above-title.style3 .categories-links a:after,
2665 .cat-over-image.style3 .categories-links a:after,
2666 #{$layoutID} .rt-tpg-category > a,
2667 #{$layoutID} .rt-tpg-category.style3 > a:after {
2668 border-top-color: {$catBg} ;
2669 }";
2670
2671 $css .= "#{$layoutID} .rt-tpg-category:not(style1) i {
2672 color: {$catBg};
2673 }";
2674 }
2675
2676 if ( $catTextColor ) {
2677 $css .= "#{$layoutID} .cat-over-image .categories-links a,
2678 #{$layoutID} .cat-above-title .categories-links a,
2679 #{$layoutID} .rt-tpg-category.style1 > i,
2680 #{$layoutID} .rt-tpg-category > a {";
2681 $css .= 'color:' . $catTextColor . ';';
2682 $css .= '}';
2683 }
2684
2685 if ( $catBorderRadius ) {
2686 $css .= "#{$layoutID} .cat-over-image .categories-links a,#{$layoutID} .cat-above-title .categories-links a,#{$layoutID} .rt-tpg-category > a{";
2687 $css .= 'border-radius:' . $catBorderRadius . 'px;';
2688 $css .= '}';
2689 }
2690
2691 if ( $catPadding ) {
2692 $css .= "#{$layoutID} .cat-over-image .categories-links a,#{$layoutID} .cat-above-title .categories-links a,#{$layoutID} .rt-tpg-category > a{";
2693 $css .= 'padding:' . $catPadding . 'px;';
2694 $css .= '}';
2695 }
2696
2697 if ( $catMargin ) {
2698 $css .= "#{$layoutID} .categories-links,#{$layoutID} .rt-tpg-category > a{";
2699 $css .= 'margin:' . $catMargin . 'px;';
2700 $css .= '}';
2701 }
2702
2703 if ( $categorySize ) {
2704 $css .= "#{$layoutID} .categories-links,#{$layoutID} .rt-tpg-category > a {";
2705 $css .= 'font-size:' . $categorySize . 'px;';
2706 $css .= '}';
2707 }
2708
2709 $css .= '</style>';
2710
2711 return $css;
2712 }
2713
2714 public static function get_meta_keys( $post_type ) {
2715 $meta_keys = self::generate_meta_keys( $post_type );
2716
2717 return $meta_keys;
2718 }
2719
2720 public static function generate_meta_keys( $post_type ) {
2721 $meta_keys = [];
2722
2723 if ( $post_type ) {
2724 global $wpdb;
2725
2726 $query = "SELECT DISTINCT($wpdb->postmeta.meta_key)
2727 FROM $wpdb->posts
2728 LEFT JOIN $wpdb->postmeta
2729 ON $wpdb->posts.ID = $wpdb->postmeta.post_id
2730 WHERE $wpdb->posts.post_type = '%s'
2731 AND $wpdb->postmeta.meta_key != ''
2732 AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)'
2733 AND $wpdb->postmeta.meta_key NOT RegExp '(^[0-9]+$)'";
2734 $meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
2735 }
2736
2737 return $meta_keys;
2738 }
2739
2740 public static function remove_all_shortcode( $content ) {
2741 return preg_replace( '#\[[^\]]+\]#', '', $content );
2742 }
2743
2744 public static function remove_divi_shortcodes( $content ) {
2745 $content = preg_replace( '/\[\/?et_pb.*?\]/', '', $content );
2746
2747 return $content;
2748 }
2749
2750 public static function is_acf() {
2751 $plugin = null;
2752
2753 if ( class_exists( 'acf' ) ) {
2754 $plugin = 'acf';
2755 }
2756
2757 return $plugin;
2758 }
2759
2760 public static function is_woocommerce() {
2761 $plugin = null;
2762 if ( class_exists( 'WooCommerce' ) ) {
2763 $plugin = 'woo';
2764 }
2765
2766 return $plugin;
2767 }
2768
2769 public static function get_groups_by_post_type( $post_type ) {
2770 $post_type = $post_type ? $post_type : 'post';
2771 $groups = [];
2772 $plugin = self::is_acf();
2773
2774 switch ( $plugin ) {
2775 case 'acf':
2776 $groups = self::get_groups_by_post_type_acf( $post_type );
2777 break;
2778 }
2779
2780 return $groups;
2781 }
2782
2783 /**
2784 * Get ACF post group
2785 *
2786 * @param $post_type
2787 *
2788 * @return array
2789 */
2790 public static function get_groups_by_post_type_acf( $post_type ) {
2791 $groups = [];
2792 $groups_q = get_posts(
2793 [
2794 'post_type' => 'acf-field-group',
2795 'posts_per_page' => - 1,
2796 ]
2797 );
2798
2799 if ( ! empty( $groups_q ) ) {
2800 foreach ( $groups_q as $group ) {
2801 $c = $group->post_content ? unserialize( $group->post_content ) : [];
2802 $flag = false;
2803
2804 if ( ! empty( $c['location'] ) ) {
2805 foreach ( $c['location'] as $rules ) {
2806 foreach ( $rules as $rule ) {
2807 if ( 'all' === $post_type ) {
2808 if ( ( ! empty( $rule['param'] ) && $rule['param'] == 'post_type' ) && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' )
2809 ) {
2810 $flag = true;
2811 }
2812 } else {
2813 if ( ( ! empty( $rule['param'] ) && ( $rule['param'] == 'post_type' || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) ) && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' ) && ( ! empty( $rule['value'] ) && ( $rule['value'] == $post_type || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) )
2814
2815 ) {
2816 $flag = true;
2817 }
2818 }
2819 }
2820 }
2821 }
2822 if ( $flag ) {
2823 $groups[ $group->ID ] = $group->post_title;
2824 }
2825 }
2826 }
2827
2828 return $groups;
2829 }
2830
2831 /**
2832 * Get Post view count meta key
2833 *
2834 * @return string
2835 */
2836 public static function get_post_view_count_meta_key() {
2837 $count_key = 'tpg-post-view-count';
2838
2839 return apply_filters( 'tpg_post_view_count', $count_key );
2840 }
2841
2842
2843 /**
2844 * Elementor Functionality
2845 * ************************************************
2846 */
2847
2848
2849 /**
2850 * Default layout style check
2851 *
2852 * @param $data
2853 *
2854 * @return bool
2855 */
2856 public static function el_ignore_layout( $data ) {
2857
2858 if ( isset( $data['category'] ) && 'category' == $data['category'] ) {
2859 return true;
2860 }
2861 $all_layout_list = [
2862 'grid-layout4',
2863 'grid-layout5',
2864 'grid-layout5-2',
2865 'grid-layout6',
2866 'grid-layout6-2',
2867 'list-layout4',
2868 'list-layout5',
2869 'grid_hover-layout5',
2870 'grid_hover-layout6',
2871 'grid_hover-layout7',
2872 'grid_hover-layout8',
2873 'grid_hover-layout9',
2874 'grid_hover-layout10',
2875 'grid_hover-layout5-2',
2876 'grid_hover-layout6-2',
2877 'grid_hover-layout7-2',
2878 'grid_hover-layout9-2',
2879 'grid_hover-layout11',
2880 'slider-layout3',
2881 'slider-layout5',
2882 'slider-layout6',
2883 'slider-layout7',
2884 'slider-layout8',
2885 'slider-layout9',
2886 'slider-layout11',
2887 'slider-layout12',
2888 ];
2889
2890 if ( 'default' == $data['category_position'] && in_array( $data['layout'], $all_layout_list ) ) {
2891 return false;
2892 }
2893
2894 return true;
2895 }
2896
2897 /**
2898 * Get Post Link
2899 *
2900 * @param $data
2901 * @param $pID
2902 *
2903 * @return array
2904 */
2905 public static function get_post_link( $pID, $data ) {
2906 $link_class = $link_start = $link_end = $readmore_link_start = $readmore_link_end = null;
2907 $external_link = get_post_meta($pID, 'tpg_read_more', true);
2908
2909 if ( 'default' == $data['post_link_type'] ) {
2910 $link_class = 'tpg-post-link';
2911 $link_start = $readmore_link_start = sprintf(
2912 '<a data-id="%s" href="%s" class="%s" target="%s">',
2913 absint( $pID ),
2914 esc_url( $external_link['url'] ?? get_permalink() ),
2915 esc_attr( $link_class ),
2916 esc_attr( $external_link['target'] ?? $data['link_target'] )
2917 );
2918 $link_end = $readmore_link_end = '</a>';
2919 } else if ( 'popup' == $data['post_link_type'] ) {
2920 $link_class = 'tpg-single-popup tpg-post-link';
2921
2922 if ( did_action( 'elementor/loaded' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
2923 $link_class = 'tpg-post-link';
2924 }
2925
2926 $link_start = $readmore_link_start = sprintf(
2927 '<a data-id="%s" href="%s" class="%s" target="%s">',
2928 absint( $pID ),
2929 esc_url( get_permalink() ),
2930 esc_attr( $link_class ),
2931 esc_attr( $data['link_target'] )
2932 );
2933 $link_end = $readmore_link_end = '</a>';
2934 } else if ( 'multi_popup' == $data['post_link_type'] ) {
2935 $link_class = 'tpg-multi-popup tpg-post-link';
2936 $link_start = $readmore_link_start = sprintf(
2937 '<a data-id="%s" href="%s" class="%s" target="%s">',
2938 absint( $pID ),
2939 esc_url( get_permalink() ),
2940 esc_attr( $link_class ),
2941 esc_attr( $data['link_target'] )
2942 );
2943 $link_end = $readmore_link_end = '</a>';
2944 } else {
2945 $link_class = 'tpg-post-link';
2946 $readmore_link_start = sprintf(
2947 '<a data-id="%s" href="%s" class="%s" target="%s">',
2948 absint( $pID ),
2949 esc_url( get_permalink() ),
2950 esc_attr( $link_class ),
2951 esc_attr( $data['link_target'] )
2952 );
2953 $readmore_link_end = '</a>';
2954 }
2955
2956 return [
2957 'link_start' => $link_start,
2958 'link_end' => $link_end,
2959 'readmore_link_start' => $readmore_link_start,
2960 'readmore_link_end' => $readmore_link_end,
2961 ];
2962 }
2963
2964 /**
2965 * Get Post Type
2966 *
2967 * @return string[]|\WP_Post_Type[]
2968 */
2969 public static function get_post_types() {
2970 $post_types = get_post_types(
2971 [
2972 'public' => true,
2973 'show_in_nav_menus' => true,
2974 ],
2975 'objects'
2976 );
2977 $post_types = wp_list_pluck( $post_types, 'label', 'name' );
2978
2979 $exclude = [ 'attachment', 'revision', 'nav_menu_item', 'elementor_library', 'tpg_builder', 'e-landing-page' ];
2980
2981 foreach ( $exclude as $ex ) {
2982 unset( $post_types[ $ex ] );
2983 }
2984
2985 if ( ! rtTPG()->hasPro() ) {
2986 $post_types = [
2987 'post' => $post_types['post'],
2988 'page' => $post_types['page'],
2989 ];
2990 }
2991
2992 return $post_types;
2993 }
2994
2995 public static function rt_get_the_term_list( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) {
2996 $terms = get_the_terms( $post_id, $taxonomy );
2997
2998 if ( is_wp_error( $terms ) ) {
2999 return $terms;
3000 }
3001
3002 if ( empty( $terms ) ) {
3003 return false;
3004 }
3005
3006 $links = [];
3007
3008 foreach ( $terms as $term ) {
3009 $meta_color = get_term_meta( $term->term_id, 'rttpg_category_color', true );
3010 $meta_color_code = $meta_color ? "--tpg-primary-color:#" . ltrim( $meta_color, '#' ) : '';
3011
3012 $link = get_term_link( $term, $taxonomy );
3013 if ( is_wp_error( $link ) ) {
3014 return $link;
3015 }
3016 if ( rtTPG()->hasPro() ) {
3017 $links[] = '<a class="' . $term->slug . '" style="' . esc_attr( $meta_color_code ) . '" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
3018 } else {
3019 $links[] = '<a class="' . $term->slug . '" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
3020 }
3021 }
3022
3023 return $before . implode( $sep, $links ) . $after;
3024 }
3025
3026 /**
3027 * Get Post Meta HTML for Elementor
3028 *
3029 * @param $post_id
3030 * @param $data
3031 *
3032 * @return html markup
3033 */
3034 public static function get_post_meta_html( $post_id, $data ) {
3035 global $post;
3036
3037 $author_id = $post->post_author;
3038 $author_name = get_the_author_meta( 'display_name', $post->post_author );
3039 $author = apply_filters( 'rttpg_author_link', sprintf( '<a href="%s">%s</a>', get_author_posts_url( $author_id ), $author_name ) );
3040
3041 $comments_number = get_comments_number( $post_id );
3042 $comment_label = '';
3043
3044 if ( isset( $data['show_comment_count_label'] ) && $data['show_comment_count_label'] ) {
3045 $comment_label = $data['comment_count_label_singular'];
3046
3047 if ( $comments_number > 1 ) {
3048 $comment_label = $data['comment_count_label_plural'];
3049 }
3050 }
3051
3052 $comments_text = sprintf( '%s (%s)', esc_html( $comment_label ), number_format_i18n( $comments_number ) );
3053 $date = get_the_date();
3054
3055
3056 //Category and Tags Management
3057 $_cat_id = isset( $data['post_type'] ) ? $data['post_type'] . '_taxonomy' : 'category';
3058 $_tag_id = isset( $data['post_type'] ) ? $data['post_type'] . '_tags' : 'post_tag';
3059 $_category_id = isset( $data[ $_cat_id ] ) ? $data[ $_cat_id ] : 'category';
3060 $_tag_id = isset( $data[ $_tag_id ] ) ? $data[ $_tag_id ] : 'post_tag';
3061 $categories = self::rt_get_the_term_list( $post_id, $_category_id, null, '<span class="rt-separator">,</span>' );
3062 $tags = self::rt_get_the_term_list( $post_id, $_tag_id, null, '<span class="rt-separator">,</span>' );
3063
3064 $count_key = self::get_post_view_count_meta_key();
3065 $get_view_count = get_post_meta( $post_id, $count_key, true );
3066
3067 $meta_separator = ( $data['meta_separator'] && 'default' !== $data['meta_separator'] ) ? sprintf( "<span class='separator'>%s</span>", $data['meta_separator'] ) : null;
3068
3069 // Author Meta.
3070
3071 $post_meta_html = [];
3072 ob_start();
3073 if ( 'show' === $data['show_author'] ) {
3074 $is_author_avatar = null;
3075
3076 if ( 'icon' !== $data['show_author_image'] ) {
3077 $is_author_avatar = 'has-author-avatar';
3078 }
3079 ?>
3080 <span class='author <?php echo esc_attr( $is_author_avatar ); ?>'>
3081
3082 <?php
3083
3084 if ( isset( $data['author_icon_visibility'] ) && $data['author_icon_visibility'] !== 'hide' ) {
3085 if ( 'icon' !== $data['show_author_image'] ) {
3086 echo get_avatar( $author_id, 80 );
3087 } else {
3088 if ( $data['show_meta_icon'] === 'yes' ) {
3089 if ( did_action( 'elementor/loaded' ) && isset( $data['user_icon']['value'] ) && $data['user_icon']['value'] ) {
3090 \Elementor\Icons_Manager::render_icon( $data['user_icon'], [ 'aria-hidden' => 'true' ] );
3091 } else {
3092 echo "<i class='" . Fns::change_icon( 'fa fa-user', 'user' ) . "'></i>";
3093 }
3094 }
3095 }
3096 }
3097
3098 if ( $data['author_prefix'] ) {
3099 echo "<span class='author-prefix'>" . esc_html( $data['author_prefix'] ) . '</span>';
3100 }
3101 echo wp_kses( $author, self::allowedHtml() );
3102 ?>
3103 </span>
3104 <?php
3105 echo wp_kses( $meta_separator, self::allowedHtml() );
3106 }
3107
3108 $post_meta_html['author'] = ob_get_clean();
3109
3110 ob_start();
3111 // Category Meta.
3112
3113 $category_condition = ( $categories && 'show' == $data['show_category'] && self::el_ignore_layout( $data ) && in_array( $data['category_position'], [
3114 'default',
3115 'with_meta'
3116 ] ) );
3117
3118 if ( ! rtTPG()->hasPro() ) {
3119 $category_condition = ( $categories && 'show' == $data['show_category'] );
3120 }
3121
3122 if ( $category_condition ) {
3123 ?>
3124 <span class='categories-links'>
3125 <?php
3126 if ( $data['show_meta_icon'] === 'yes' ) {
3127 if ( did_action( 'elementor/loaded' ) && isset( $data['cat_icon']['value'] ) && $data['cat_icon']['value'] ) {
3128 \Elementor\Icons_Manager::render_icon( $data['cat_icon'], [ 'aria-hidden' => 'true' ] );
3129 } else {
3130 echo "<i class='" . Fns::change_icon( 'fas fa-folder-open', 'folder' ) . "'></i>";
3131 }
3132 }
3133 echo wp_kses( $categories, self::allowedHtml( 'basic' ) );
3134 ?>
3135
3136 </span>
3137 <?php
3138 echo wp_kses( $meta_separator, self::allowedHtml( 'basic' ) );
3139 }
3140 $post_meta_html['category'] = ob_get_clean();
3141
3142 ob_start();
3143 // Date Meta.
3144 if ( '' !== $data['show_date'] ) {
3145 $archive_year = get_the_date( 'Y' );
3146 $archive_month = get_the_date( 'm' );
3147 $archive_day = get_the_date( 'j' );
3148
3149 ?>
3150 <span class='date'>
3151
3152 <?php
3153 if ( $data['show_meta_icon'] === 'yes' ) {
3154 if ( did_action( 'elementor/loaded' ) && isset( $data['date_icon']['value'] ) && $data['date_icon']['value'] ) {
3155 \Elementor\Icons_Manager::render_icon( $data['date_icon'], [ 'aria-hidden' => 'true' ] );
3156 } else {
3157 echo "<i class='" . Fns::change_icon( 'far fa-calendar-alt', 'calendar' ) . "'></i>";
3158 }
3159 }
3160 ?>
3161 <a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>">
3162 <?php echo esc_html( $date ); ?>
3163 </a>
3164 </span>
3165 <?php
3166 echo wp_kses( $meta_separator, self::allowedHtml() );
3167 }
3168
3169 $post_meta_html['date'] = ob_get_clean();
3170
3171 ob_start();
3172 // Tags Meta.
3173 if ( $tags && 'show' == $data['show_tags'] ) {
3174 ?>
3175 <span class='post-tags-links'>
3176 <?php
3177 if ( $data['show_meta_icon'] === 'yes' ) {
3178 if ( did_action( 'elementor/loaded' ) && isset( $data['tag_icon']['value'] ) && $data['tag_icon']['value'] ) {
3179 \Elementor\Icons_Manager::render_icon( $data['tag_icon'], [ 'aria-hidden' => 'true' ] );
3180 } else {
3181 echo "<i class='" . Fns::change_icon( 'fa fa-tags', 'tag' ) . "'></i>";
3182 }
3183 }
3184 echo wp_kses( $tags, self::allowedHtml() );
3185 ?>
3186 </span>
3187 <?php
3188 echo wp_kses( $meta_separator, self::allowedHtml() );
3189 }
3190 $post_meta_html['tags'] = ob_get_clean();
3191
3192 ob_start();
3193 // Comment Meta.
3194 if ( 'show' == $data['show_comment_count'] ) {
3195 ?>
3196 <span class="comment-count">
3197 <?php
3198 if ( $data['show_meta_icon'] === 'yes' ) {
3199 if ( did_action( 'elementor/loaded' ) && isset( $data['comment_icon']['value'] ) && $data['comment_icon']['value'] ) {
3200 \Elementor\Icons_Manager::render_icon( $data['comment_icon'], [ 'aria-hidden' => 'true' ] );
3201 } else {
3202 echo "<i class='" . Fns::change_icon( 'fas fa-comments', 'chat' ) . "'></i>";
3203 }
3204 }
3205 echo wp_kses( $comments_text, self::allowedHtml() );
3206 ?>
3207 </span>
3208 <?php
3209 echo wp_kses( $meta_separator, self::allowedHtml() );
3210 }
3211
3212 $post_meta_html['comment_count'] = ob_get_clean();
3213
3214 ob_start();
3215 // Post Count.
3216 if ( rtTPG()->hasPro() && 'show' == $data['show_post_count'] && ! empty( $get_view_count ) ) {
3217 ?>
3218 <span class="post-count">
3219 <?php
3220 if ( $data['show_meta_icon'] === 'yes' ) {
3221 if ( did_action( 'elementor/loaded' ) && isset( $data['post_count_icon']['value'] ) && $data['post_count_icon']['value'] ) {
3222 \Elementor\Icons_Manager::render_icon( $data['post_count_icon'], [ 'aria-hidden' => 'true' ] );
3223 } else {
3224 echo "<i class='" . Fns::change_icon( 'fa fa-eye', 'view' ) . "'></i>";
3225 }
3226 }
3227 echo wp_kses( $get_view_count, self::allowedHtml() );
3228 ?>
3229 </span>
3230 <?php
3231 echo wp_kses( $meta_separator, self::allowedHtml() );
3232 }
3233
3234 $post_meta_html['post_count'] = ob_get_clean();
3235
3236 if ( isset( $data['is_gutenberg'] ) && $data['is_gutenberg'] ) {
3237 $meta_ordering = array_keys( $post_meta_html );
3238
3239 if ( isset( $data['meta_ordering'] ) && is_array( $data['meta_ordering'] ) ) {
3240 $meta_ordering = wp_list_pluck( $data['meta_ordering'], 'value' );
3241 $extra_meta = [];
3242 $post_meta_html_key = array_keys( $post_meta_html );
3243
3244 $count_order = count( $meta_ordering );
3245
3246 if ( $count_order != count( $post_meta_html_key ) ) {
3247 foreach ( $post_meta_html_key as $key ) {
3248 if ( ! in_array( $key, $meta_ordering ) ) {
3249 $extra_meta[] = $key;
3250 }
3251 }
3252 }
3253
3254 if ( ! empty( $extra_meta ) ) {
3255 $meta_ordering = array_merge( $meta_ordering, $extra_meta );
3256 }
3257 }
3258 foreach ( $meta_ordering as $val ) {
3259 echo $post_meta_html[ $val ];
3260 }
3261
3262 } else {
3263 $meta_ordering = isset( $data['meta_ordering'] ) && is_array( $data['meta_ordering'] ) ? $data['meta_ordering'] : [];
3264 foreach ( $meta_ordering as $val ) {
3265 if ( isset( $post_meta_html[ $val['meta_name'] ] ) ) {
3266 echo wp_kses_post( $post_meta_html[ $val['meta_name'] ] );
3267 }
3268
3269 }
3270 }
3271 }
3272
3273 /**
3274 * Custom wp_kses
3275 *
3276 * @param $string
3277 *
3278 * @return string
3279 */
3280 public static function wp_kses( $string ) {
3281 $allowed_html = [
3282 'a' => [
3283 'href' => [],
3284 'title' => [],
3285 'data-id' => [],
3286 'target' => [],
3287 'class' => [],
3288 ],
3289 'strong' => [],
3290 'b' => [],
3291 'br' => [ [] ],
3292 ];
3293
3294 return wp_kses( $string, $allowed_html );
3295 }
3296
3297
3298 /**
3299 * Get Elementor Post Title for Elementor
3300 *
3301 * @param $title_tag
3302 * @param $title
3303 * @param $link_start
3304 * @param $link_end
3305 * @param $data
3306 */
3307
3308 public static function get_el_post_title( $title_tag, $title, $link_start, $link_end, $data ) {
3309
3310 echo '<div class="entry-title-wrapper">';
3311
3312 if ( rtTPG()->hasPro() && 'above_title' === $data['category_position'] || ! self::el_ignore_layout( $data ) ) {
3313 self::get_el_thumb_cat( $data, 'cat-above-title' );
3314 }
3315
3316 printf( '<%s class="entry-title">', esc_attr( $title_tag ) );
3317 self::print_html( $link_start );
3318 self::print_html( $title );
3319 self::print_html( $link_end );
3320 printf( '</%s>', esc_attr( $title_tag ) );
3321 echo '</div>';
3322 }
3323
3324 static function get_el_thumb_cat( $data, $class = 'cat-over-image' ) {
3325 if ( ! ( 'show' == $data['show_meta'] && 'show' == $data['show_category'] ) ) {
3326 return;
3327 }
3328
3329 $pID = get_the_ID();
3330 $_cat_id = $data['post_type'] . '_taxonomy';
3331 $_post_taxonomy = isset( $data[ $_cat_id ] ) ? $data[ $_cat_id ] : 'category';
3332 $categories = self::rt_get_the_term_list( $pID, $_post_taxonomy, null, '<span class="rt-separator">,</span>' );
3333 $category_position = $data['category_position'];
3334
3335 if ( in_array( $data['layout'], [
3336 'grid-layout4',
3337 'slider-layout3',
3338 'grid_hover-layout11'
3339 ] ) && 'default' === $data['category_position'] ) {
3340 $category_position = 'top_left';
3341 }
3342 ?>
3343 <div class="tpg-separate-category <?php echo esc_attr( $data['category_style'] . ' ' . $category_position . ' ' . $class ); ?>">
3344 <span class='categories-links'>
3345 <?php echo ( 'yes' === $data['show_cat_icon'] ) ? "<i class='" . Fns::change_icon( 'fas fa-folder-open', 'folder' ) . "'></i>" : null; ?>
3346 <?php echo wp_kses( $categories, self::allowedHtml() ); ?>
3347 </span>
3348 </div>
3349 <?php
3350 }
3351
3352
3353 /**
3354 * Get first image from the content
3355 *
3356 * @param $post_id
3357 * @param string $type
3358 *
3359 * @return mixed|string
3360 */
3361 public static function get_content_first_image( $post_id, $type = 'markup', $imgClass = '' ) {
3362 if ( $img = preg_match_all(
3363 '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
3364 get_the_content( $post_id ),
3365 $matches
3366 )
3367 ) {
3368 $imgSrc = $matches[1][0];
3369 $size = '';
3370
3371 $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc );
3372
3373 if ( file_exists( $imgAbs ) ) {
3374 $info = getimagesize( $imgAbs );
3375 $size = isset( $info[3] ) ? $info[3] : '';
3376 }
3377
3378 $attachment_id = attachment_url_to_postid( $imgSrc );
3379 $alt_text = null;
3380
3381 if ( ! empty( $attachment_id ) ) {
3382 $alt_text = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
3383 }
3384
3385 $alt = $alt_text ? $alt_text : get_the_title( $post_id );
3386
3387 if ( $type == 'markup' ) {
3388 if ( $imgClass !== 'swiper-lazy' ) {
3389 return "<img class='rt-img-responsive' src='{$imgSrc}' {$size} alt='{$alt}'>";
3390 } else {
3391 return "<img class='{$imgClass}' data-src='{$imgSrc}' alt='{$alt}'>";
3392 }
3393 } else {
3394 return $imgSrc;
3395 }
3396 }
3397 }
3398
3399 /**
3400 * Get post thumbnail html
3401 *
3402 * @param $pID
3403 * @param $data
3404 * @param $link_start
3405 * @param $link_end
3406 * @param false $offset_size
3407 */
3408 public static function get_post_thumbnail( $pID, $data, $link_start, $link_end, $offset_size = false ) {
3409 $thumb_cat_condition = ( ! ( 'above_title' === $data['category_position'] || 'default' === $data['category_position'] ) );
3410
3411 if ( 'grid-layout4' === $data['layout'] && 'default' === $data['category_position'] ) {
3412 $thumb_cat_condition = true;
3413 } else if ( in_array( $data['layout'], [
3414 'grid-layout4',
3415 'grid_hover-layout11',
3416 'slider-layout3'
3417 ] ) && 'default' === $data['category_position'] ) {
3418 $thumb_cat_condition = true;
3419 }
3420
3421 if ( rtTPG()->hasPro() && $data['show_category'] == 'show' && $thumb_cat_condition && 'with_meta' !== $data['category_position'] ) {
3422 self::get_el_thumb_cat( $data );
3423 }
3424
3425 $img_link = get_the_post_thumbnail_url( $pID, 'full' );
3426 $img_size_key = 'image_size';
3427
3428
3429 if ( $offset_size ) {
3430 $img_size_key = 'image_offset_size';
3431 }
3432
3433 $lazy_load = ( $data['prefix'] == 'slider' && $data['lazy_load'] == 'yes' ) ? true : false;
3434 $lazy_class = 'rt-img-responsive';
3435
3436 if ( $lazy_load ) {
3437 $lazy_class = 'swiper-lazy';
3438 }
3439
3440 echo 'yes' === $data['is_thumb_linked'] ? self::print_html( $link_start ) : null;
3441
3442 if ( has_post_thumbnail() && 'feature_image' === $data['media_source'] ) {
3443 $fImgSize = $data['image_size'];
3444
3445 if ( $offset_size ) {
3446 echo get_the_post_thumbnail( $pID, $data['image_offset'] );
3447 } else {
3448 if ( $data['image_size'] !== 'custom' ) {
3449 $attachment_id = get_post_thumbnail_id( $pID );
3450 $thumb_info = wp_get_attachment_image_src( $attachment_id, $fImgSize );
3451 $thumb_alt = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
3452 if ( $lazy_load ) {
3453 ?>
3454 <img data-src="<?php echo esc_url( isset( $thumb_info[0] ) ? $thumb_info[0] : '' ); ?>"
3455 src="#none"
3456 class="<?php echo esc_attr( $lazy_class ); ?>"
3457 width="<?php echo esc_attr( isset( $thumb_info[1] ) ? $thumb_info[1] : '' ); ?>"
3458 height="<?php echo esc_attr( isset( $thumb_info[2] ) ? $thumb_info[2] : '' ); ?>"
3459 alt="<?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ); ?>">
3460 <?php
3461 } else {
3462 ?>
3463 <img src="<?php echo esc_url( isset( $thumb_info[0] ) ? $thumb_info[0] : '' ); ?>"
3464 class="<?php echo esc_attr( $lazy_class ); ?>"
3465 width="<?php echo esc_attr( isset( $thumb_info[1] ) ? $thumb_info[1] : '' ); ?>"
3466 height="<?php echo esc_attr( isset( $thumb_info[2] ) ? $thumb_info[2] : '' ); ?>"
3467 alt="<?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ); ?>">
3468 <?php
3469 }
3470 ?>
3471
3472 <?php
3473 } else {
3474 $fImgSize = 'rt_custom';
3475 $mediaSource = 'feature_image';
3476 $defaultImgId = null;
3477 $customImgSize = [];
3478
3479
3480 if ( $data['is_gutenberg'] && isset( $data['c_image_width'] ) && isset( $data['c_image_height'] ) ) {
3481 $data['image_custom_dimension']['width'] = intval( $data['c_image_width'] );
3482 $data['image_custom_dimension']['height'] = intval( $data['c_image_height'] );
3483 }
3484
3485
3486 if ( isset( $data['image_custom_dimension'] ) ) {
3487 $post_thumb_id = get_post_thumbnail_id( $pID );
3488 $default_image_dimension = wp_get_attachment_image_src( $post_thumb_id, 'full' );
3489
3490 if ( $default_image_dimension[1] <= $data['image_custom_dimension']['width'] || $default_image_dimension[2] <= $data['image_custom_dimension']['height'] ) {
3491 $customImgSize = [];
3492 } else {
3493 $customImgSize[0] = $data['image_custom_dimension']['width'];
3494 $customImgSize[1] = $data['image_custom_dimension']['height'];
3495 $customImgSize[2] = $data['img_crop_style'];
3496 }
3497 }
3498
3499 echo wp_kses_post( self::getFeatureImageSrc( $pID, $fImgSize, $mediaSource, $defaultImgId, $customImgSize, $lazy_class ) );
3500 }
3501 }
3502 } else if ( 'first_image' === $data['media_source'] && self::get_content_first_image( $pID ) ) {
3503 echo wp_kses_post( self::get_content_first_image( $pID, 'markup', $lazy_class ) );
3504 $img_link = self::get_content_first_image( $pID, 'url' );
3505 } else if ( 'yes' === $data['is_default_img'] || 'grid_hover' == $data['prefix'] ) {
3506 //echo \Elementor\Group_Control_Image_Size::get_attachment_image_html( $data, $img_size_key, 'default_image' );
3507 if ( isset( $data['default_image']['id'] ) ) {
3508 echo wp_get_attachment_image( $data['default_image']['id'], $data[ $img_size_key ], '', [ 'class' => 'rt-img-responsive' ] );
3509 }
3510 if ( ! empty( $data['default_image'] ) && isset( $data['default_image']['url'] ) ) {
3511 $img_link = $data['default_image']['url'];
3512 }
3513 }
3514
3515 ?>
3516 <?php if ( $lazy_load ) : ?>
3517 <div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
3518 <?php endif; ?>
3519
3520 <?php echo 'yes' === $data['is_thumb_linked'] ? wp_kses( $link_end, self::allowedHtml() ) : null; ?>
3521
3522 <?php
3523 if ( 'show' === $data['is_thumb_lightbox'] || ( in_array( $data['layout'], [
3524 'grid-layout7',
3525 'slider-layout4'
3526 ] ) && in_array( $data['is_thumb_lightbox'], [ 'default', 'show' ] ) ) ) :
3527 ?>
3528
3529 <a class="tpg-zoom mfp-fade"
3530 data-elementor-open-lightbox="yes"
3531 data-elementor-lightbox-slideshow="<?php echo esc_attr( $data['layout'] ); ?>"
3532 title="<?php echo esc_attr( get_the_title() ); ?>"
3533 href="<?php echo esc_url( $img_link ) ?>">
3534
3535 <?php
3536 if ( did_action( 'elementor/loaded' ) && isset( $data['light_box_icon']['value'] ) && $data['light_box_icon']['value'] ) {
3537 \Elementor\Icons_Manager::render_icon( $data['light_box_icon'], [ 'aria-hidden' => 'true' ] );
3538 } else {
3539 echo "<i class='fa fa-plus'></i>";
3540 }
3541 ?>
3542 </a>
3543
3544 <?php endif; ?>
3545 <div class="overlay grid-hover-content"></div>
3546 <?php
3547 }
3548
3549
3550 /**
3551 * Get ACF data for elementor
3552 *
3553 * @param $data
3554 * @param $pID
3555 *
3556 * @return bool
3557 */
3558 public static function tpg_get_acf_data_elementor( $data, $pID, $return_type = true ) {
3559 if ( ! ( rtTPG()->hasPro() && self::is_acf() ) ) {
3560 return;
3561 }
3562
3563 if ( isset( $data['show_acf'] ) && 'show' == $data['show_acf'] ) {
3564 $cf_group = $data['cf_group'];
3565
3566
3567 $format = [
3568 'hide_empty' => ( isset( $data['cf_hide_empty_value'] ) && $data['cf_hide_empty_value'] ) ? 'yes' : '',
3569 'show_value' => ( isset( $data['cf_show_only_value'] ) && $data['cf_show_only_value'] ) ? '' : 'yes',
3570 'hide_group_title' => ( isset( $data['cf_hide_group_title'] ) && $data['cf_hide_group_title'] ) ? '' : 'yes',
3571 ];
3572
3573 if ( ! empty( $cf_group ) ) {
3574
3575 $acf_html = "<div class='acf-custom-field-wrap'>";
3576
3577 $acf_html .= \RT\ThePostGridPro\Helpers\Functions::get_cf_formatted_fields( $cf_group, $format, $pID );
3578 $acf_html .= '</div>';
3579
3580 if ( $return_type ) {
3581 self::print_html( $acf_html, true );
3582 } else {
3583 return $acf_html;
3584 }
3585 }
3586 }
3587 }
3588
3589 /**
3590 * Get Read More Button
3591 *
3592 * @param $data
3593 * @param $readmore_link_start
3594 * @param $readmore_link_end
3595 *
3596 * @return void
3597 */
3598 public static function get_read_more_button( $data, $readmore_link_start, $readmore_link_end, $type = 'elementor' ) {
3599 ?>
3600 <div class="post-footer">
3601 <div class="post-footer">
3602 <div class="read-more">
3603 <?php
3604 echo self::wp_kses( $readmore_link_start );
3605 if ( 'yes' == $data['show_btn_icon'] && 'left' == $data['readmore_icon_position'] ) {
3606 if ( $type === 'elementor' ) {
3607 if ( did_action( 'elementor/loaded' ) ) {
3608 \Elementor\Icons_Manager::render_icon( $data['readmore_btn_icon'], [
3609 'aria-hidden' => 'true',
3610 'class' => 'left-icon'
3611 ] );
3612 }
3613 } else {
3614 //TODO: FlatIcon should chagne
3615 echo "<i class='left-icon " . Fns::change_icon( 'fas fa-angle-right', 'left-arrow', 'left-icon' ) . "'></i>";
3616 }
3617 }
3618 echo esc_html( $data['read_more_label'] );
3619 if ( 'yes' == $data['show_btn_icon'] && 'right' == $data['readmore_icon_position'] ) {
3620 if ( $type === 'elementor' ) {
3621 if ( did_action( 'elementor/loaded' ) ) {
3622 \Elementor\Icons_Manager::render_icon( $data['readmore_btn_icon'], [
3623 'aria-hidden' => 'true',
3624 'class' => 'right-icon'
3625 ] );
3626 }
3627 } else {
3628 //TODO: FlatIcon should chagne
3629 echo "<i class='left-icon " . Fns::change_icon( 'fas fa-angle-right', 'right-arrow', 'right-icon' ) . "'></i>";
3630 }
3631 }
3632 echo self::wp_kses( $readmore_link_end );
3633 ?>
3634 </div>
3635 </div>
3636 </div>
3637 <?php
3638 }
3639
3640
3641 /**
3642 * Check is filter enable or not
3643 *
3644 * @param $data
3645 *
3646 * @return bool
3647 */
3648 public static function is_filter_enable( $data ) {
3649 if ( rtTPG()->hasPro()
3650 && ( $data['show_taxonomy_filter'] == 'show'
3651 || $data['show_author_filter'] == 'show'
3652 || $data['show_order_by'] == 'show'
3653 || $data['show_sort_order'] == 'show'
3654 || $data['show_search'] == 'show'
3655 || ( $data['show_pagination'] == 'show' && $data['pagination_type'] != 'pagination' ) )
3656 ) {
3657 return true;
3658 }
3659
3660 return false;
3661 }
3662
3663
3664 //Get Custom post category:
3665 public static function tpg_get_categories_by_id( $cat = 'category' ) {
3666 $terms = get_terms( [
3667 'taxonomy' => $cat,
3668 'hide_empty' => true,
3669 ] );
3670
3671 $options = [];
3672 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
3673 foreach ( $terms as $term ) {
3674 $options[ $term->term_id ] = $term->name;
3675 }
3676 }
3677
3678 return $options;
3679 }
3680
3681
3682
3683 /**
3684 * Gutenberg Functionality
3685 * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
3686 */
3687
3688 /**
3689 * Get Post Types.
3690 *
3691 * @since 1.0.9
3692 */
3693 public static function get_post_types_guten() {
3694 $post_types = get_post_types(
3695 [
3696 'public' => true,
3697 'show_in_rest' => true,
3698 ],
3699 'objects'
3700 );
3701
3702 $options = [];
3703
3704 foreach ( $post_types as $post_type ) {
3705 if ( 'product' === $post_type->name ) {
3706 continue;
3707 }
3708
3709 if ( 'attachment' === $post_type->name ) {
3710 continue;
3711 }
3712
3713 if ( 'page' === $post_type->name ) {
3714 continue;
3715 }
3716
3717 $options[] = [
3718 'value' => $post_type->name,
3719 'label' => $post_type->label,
3720 ];
3721 }
3722
3723 return $options;
3724 }
3725
3726 /**
3727 * Get all taxonomies.
3728 *
3729 * @since 1.0.9
3730 */
3731
3732 public static function get_all_taxonomy_guten() {
3733 $post_types = Fns::get_post_types();
3734 $taxonomies = get_taxonomies( [], 'objects' );
3735 $all_taxonomies = [];
3736 foreach ( $taxonomies as $taxonomy => $object ) {
3737 if ( ! isset( $object->object_type[0] ) || ! in_array( $object->object_type[0], array_keys( $post_types ) )
3738 || in_array( $taxonomy, Fns::get_excluded_taxonomy() )
3739 ) {
3740 continue;
3741 }
3742 $all_taxonomies[ $taxonomy ] = Fns::tpg_get_categories_by_id( $taxonomy );
3743 }
3744
3745 return $all_taxonomies;
3746
3747 }
3748
3749 /**
3750 * Get all image sizes.
3751 *
3752 * @since 1.0.9
3753 */
3754 public static function get_all_image_sizes_guten() {
3755 global $_wp_additional_image_sizes;
3756
3757 $sizes = get_intermediate_image_sizes();
3758 $image_sizes = [];
3759
3760 $image_sizes[] = [
3761 'value' => 'full',
3762 'label' => esc_html__( 'Full', 'the-post-grid' ),
3763 ];
3764
3765 foreach ( $sizes as $size ) {
3766 if ( in_array( $size, [ 'thumbnail', 'medium', 'medium_large', 'large' ], true ) ) {
3767 $image_sizes[] = [
3768 'value' => $size,
3769 'label' => ucwords( trim( str_replace( [ '-', '_' ], [ ' ', ' ' ], $size ) ) ),
3770 ];
3771 } else {
3772 $image_sizes[] = [
3773 'value' => $size,
3774 'label' => sprintf(
3775 '%1$s (%2$sx%3$s)',
3776 ucwords( trim( str_replace( [ '-', '_' ], [ ' ', ' ' ], $size ) ) ),
3777 $_wp_additional_image_sizes[ $size ]['width'],
3778 $_wp_additional_image_sizes[ $size ]['height']
3779 ),
3780 ];
3781 }
3782 }
3783
3784 if ( rtTPG()->hasPro() ) {
3785 $image_sizes[] = [
3786 'value' => 'custom',
3787 'label' => esc_html__( 'Custom', 'the-post-grid' ),
3788 ];
3789 }
3790
3791 return apply_filters( 'tpg_image_size_guten', $image_sizes );
3792 }
3793
3794
3795 /**
3796 * Prints HTML.
3797 *
3798 * @param string $html HTML.
3799 * @param bool $allHtml All HTML.
3800 *
3801 * @return mixed
3802 */
3803 public static function print_html( $html, $allHtml = false ) {
3804 if ( $allHtml ) {
3805 echo stripslashes_deep( $html );
3806 } else {
3807 echo wp_kses_post( stripslashes_deep( $html ) );
3808 }
3809 }
3810
3811 /**
3812 * Allowed HTML for wp_kses.
3813 *
3814 * @param string $level Tag level.
3815 *
3816 * @return mixed
3817 */
3818 public static function allowedHtml( $level = 'basic' ) {
3819 $allowed_html = [];
3820
3821 switch ( $level ) {
3822 case 'basic':
3823 $allowed_html = [
3824 'b' => [
3825 'class' => [],
3826 'id' => [],
3827 ],
3828 'i' => [
3829 'class' => [],
3830 'id' => [],
3831 ],
3832 'u' => [
3833 'class' => [],
3834 'id' => [],
3835 ],
3836 'br' => [
3837 'class' => [],
3838 'id' => [],
3839 ],
3840 'em' => [
3841 'class' => [],
3842 'id' => [],
3843 ],
3844 'span' => [
3845 'class' => [],
3846 'id' => [],
3847 ],
3848 'strong' => [
3849 'class' => [],
3850 'id' => [],
3851 ],
3852 'hr' => [
3853 'class' => [],
3854 'id' => [],
3855 ],
3856 'a' => [
3857 'href' => [],
3858 'title' => [],
3859 'class' => [],
3860 'id' => [],
3861 'target' => [],
3862 'style' => [],
3863 ],
3864 'div' => [
3865 'class' => [],
3866 'id' => [],
3867 ],
3868 ];
3869 break;
3870
3871 case 'advanced':
3872 $allowed_html = [
3873 'b' => [
3874 'class' => [],
3875 'id' => [],
3876 ],
3877 'i' => [
3878 'class' => [],
3879 'id' => [],
3880 ],
3881 'u' => [
3882 'class' => [],
3883 'id' => [],
3884 ],
3885 'br' => [
3886 'class' => [],
3887 'id' => [],
3888 ],
3889 'em' => [
3890 'class' => [],
3891 'id' => [],
3892 ],
3893 'span' => [
3894 'class' => [],
3895 'id' => [],
3896 ],
3897 'strong' => [
3898 'class' => [],
3899 'id' => [],
3900 ],
3901 'hr' => [
3902 'class' => [],
3903 'id' => [],
3904 ],
3905 'a' => [
3906 'href' => [],
3907 'title' => [],
3908 'class' => [],
3909 'id' => [],
3910 'data-id' => [],
3911 'target' => [],
3912 ],
3913 'input' => [
3914 'type' => [],
3915 'name' => [],
3916 'class' => [],
3917 'value' => [],
3918 ],
3919 ];
3920 break;
3921
3922 case 'image':
3923 $allowed_html = [
3924 'img' => [
3925 'src' => [],
3926 'data-src' => [],
3927 'alt' => [],
3928 'height' => [],
3929 'width' => [],
3930 'class' => [],
3931 'id' => [],
3932 'style' => [],
3933 'srcset' => [],
3934 'loading' => [],
3935 'sizes' => [],
3936 ],
3937 'div' => [
3938 'class' => [],
3939 ],
3940 ];
3941 break;
3942
3943 case 'anchor':
3944 $allowed_html = [
3945 'a' => [
3946 'href' => [],
3947 'title' => [],
3948 'class' => [],
3949 'id' => [],
3950 'style' => [],
3951 ],
3952 ];
3953 break;
3954
3955 default:
3956 // code...
3957 break;
3958 }
3959
3960 return $allowed_html;
3961 }
3962
3963 /**
3964 * Definition for wp_kses.
3965 *
3966 * @param string $string String to check.
3967 * @param string $level Tag level.
3968 *
3969 * @return mixed
3970 */
3971 public static function htmlKses( $string, $level ) {
3972 if ( empty( $string ) ) {
3973 return;
3974 }
3975
3976 return wp_kses( $string, self::allowedHtml( $level ) );
3977 }
3978
3979
3980 /**
3981 * Insert Array Item in specific position
3982 *
3983 * @param $array
3984 * @param $position
3985 * @param $insert_array
3986 *
3987 * @return void
3988 */
3989 public static function array_insert( &$array, $position, $insert_array ) {
3990 $first_array = array_splice( $array, 0, $position + 1 );
3991 $array = array_merge( $first_array, $insert_array, $array );
3992 }
3993
3994 /**
3995 * tpg_option
3996 *
3997 * @param $option_name
3998 * @param $default_value
3999 *
4000 * @return string
4001 */
4002 public static function tpg_option( $option_name, $default_value = '' ) {
4003 $settings = get_option( rtTPG()->options['settings'] );
4004 if ( ! empty( $settings[ $option_name ] ) ) {
4005 return $settings[ $option_name ];
4006 } else if ( $default_value ) {
4007 return $default_value;
4008 }
4009
4010 return '';
4011 }
4012
4013 /**
4014 * change_icon
4015 *
4016 * @param $fontawesome
4017 * @param $flaticon
4018 * @param $default_class
4019 *
4020 * @return mixed|string
4021 */
4022 public static function change_icon( $fontawesome, $flaticon, $default_class = '' ) {
4023 if ( self::tpg_option( 'tpg_icon_font' ) === 'fontawesome' ) {
4024 return $fontawesome . ' ' . $default_class;
4025 } else {
4026 return 'flaticon-tpg-' . $flaticon . ' ' . $default_class;
4027 }
4028 }
4029
4030 }