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