PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.1.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.1.0
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 4 years ago Install.php 4 years ago Options.php 4 years ago
Fns.php
2438 lines
1 <?php
2
3 namespace RT\ThePostGrid\Helpers;
4
5 use RT\ThePostGrid\Models\Field;
6 use RT\ThePostGrid\Models\ReSizer;
7 use RT\ThePostGridPro\Helpers\Functions;
8
9 class Fns {
10
11 /**
12 * Get Ajax URL.
13 *
14 * @return string
15 */
16 public function ajax_url() {
17 return admin_url( 'admin-ajax.php', 'relative' );
18 }
19
20
21 /**
22 * @param $viewName
23 * @param array $args
24 * @param bool $return
25 *
26 * @return string|void
27 */
28 public static function view( $viewName, $args = [], $return = false ) {
29 $file = str_replace( ".", "/", $viewName );
30 $file = ltrim( $file, '/' );
31 $viewFile = trailingslashit( RT_THE_POST_GRID_PLUGIN_PATH . '/resources' ) . $file . '.php';
32 if ( ! file_exists( $viewFile ) ) {
33 return new \WP_Error( "brock", __( "$viewFile file not found" ) );
34 }
35 if ( $args ) {
36 extract( $args );
37 }
38 if ( $return ) {
39 ob_start();
40 include $viewFile;
41
42 return ob_get_clean();
43 }
44 include $viewFile;
45 }
46
47 /**
48 * @param integer $post_id Listing ID
49 */
50 static function update_post_views_count( $post_id ) {
51 if ( ! $post_id && is_admin() ) {
52 return;
53 }
54
55 $user_ip = $_SERVER['REMOTE_ADDR']; // retrieve the current IP address of the visitor
56 $key = 'tpg_cache_' . $user_ip . '_' . $post_id;
57 $value = [ $user_ip, $post_id ];
58 $visited = get_transient( $key );
59 if ( false === ( $visited ) ) {
60 set_transient( $key, $value, HOUR_IN_SECONDS * 12 ); // store the unique key, Post ID & IP address for 12 hours if it does not exist
61
62 // now run post views function
63 $count_key = self::get_post_view_count_meta_key();
64 $count = get_post_meta( $post_id, $count_key, true );
65 if ( '' == $count ) {
66 update_post_meta( $post_id, $count_key, 1 );
67 } else {
68 $count = absint( $count );
69 $count ++;
70 update_post_meta( $post_id, $count_key, $count );
71 }
72 }
73 }
74
75 /**
76 * Template Content
77 *
78 * @param string $template_name Template name.
79 * @param array $args Arguments. (default: array).
80 * @param string $template_path Template path. (default: '').
81 * @param string $default_path Default path. (default: '').
82 */
83 static function get_template( $template_name, $args = null, $template_path = '', $default_path = '' ) {
84 if ( ! empty( $args ) && is_array( $args ) ) {
85 extract( $args ); // @codingStandardsIgnoreLine
86 }
87
88 $located = self::locate_template( $template_name, $template_path, $default_path );
89
90
91 if ( ! file_exists( $located ) ) {
92 /* translators: %s template */
93 self::doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'the-post-grid' ), '<code>' . $located . '</code>' ), '1.0' );
94
95 return;
96 }
97
98 // Allow 3rd party plugin filter template file from their plugin.
99 $located = apply_filters( 'rttpg_get_template', $located, $template_name, $args );
100
101 do_action( 'rttpg_before_template_part', $template_name, $located, $args );
102
103 include $located;
104
105 do_action( 'rttpg_after_template_part', $template_name, $located, $args );
106 }
107
108 /**
109 * Get template content and return
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 * @return string
117 */
118 public static function get_template_html( $template_name, $args = [], $template_path = '', $default_path = '' ) {
119 ob_start();
120 self::get_template( $template_name, $args, $template_path, $default_path );
121
122 return ob_get_clean();
123 }
124
125 /**
126 * @param $template_name
127 * @param string $template_path
128 * @param string $default_path
129 *
130 * @return mixed|void
131 */
132 public static function locate_template( $template_name, $template_path = '', $default_path = '' ) {
133 $template_name = $template_name . ".php";
134 if ( ! $template_path ) {
135 $template_path = rtTPG()->get_template_path();
136 }
137
138 if ( ! $default_path ) {
139 $default_path = rtTPG()->default_template_path() . '/templates/';
140 }
141 // Look within passed path within the theme - this is priority.
142 $template_files = [];
143 $template_files[] = trailingslashit( $template_path ) . $template_name;
144
145 $template = locate_template( apply_filters( 'rttpg_locate_template_files', $template_files, $template_name, $template_path, $default_path ) );
146
147 // Get default template/.
148 if ( ! $template ) {
149 $template = trailingslashit( $default_path ) . $template_name;
150 }
151
152 return apply_filters( 'rttpg_locate_template', $template, $template_name );
153 }
154
155 static function doing_it_wrong( $function, $message, $version ) {
156 // @codingStandardsIgnoreStart
157 $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
158 _doing_it_wrong( $function, $message, $version );
159 }
160
161 public static function verifyNonce() {
162 $nonce = isset( $_REQUEST[ rtTPG()->nonceId() ] ) ? $_REQUEST[ rtTPG()->nonceId() ] : null;
163 $nonceText = rtTPG()->nonceText();
164 if ( ! wp_verify_nonce( $nonce, $nonceText ) ) {
165 return false;
166 }
167
168 return true;
169 }
170
171 public static function print_html( $html, $allHtml = false ) {
172 if ( $allHtml ) {
173 echo stripslashes_deep( $html );
174 } else {
175 echo wp_kses_post( stripslashes_deep( $html ) );
176 }
177 }
178
179 public static function rtAllOptionFields() {
180 $fields = array_merge(
181 Options::rtTPGCommonFilterFields(),
182 Options::rtTPGLayoutSettingFields(),
183 Options::responsiveSettingsColumn(),
184 Options::layoutMiscSettings(),
185 Options::stickySettings(),
186 // settings
187 Options::rtTPGSCHeadingSettings(),
188 Options::rtTPGSCCategorySettings(),
189 Options::rtTPGSCTitleSettings(),
190 Options::rtTPGSCMetaSettings(),
191 Options::rtTPGSCImageSettings(),
192 Options::rtTPGSCExcerptSettings(),
193 Options::rtTPGSCButtonSettings(),
194 // style
195 Options::rtTPGStyleFields(),
196 Options::rtTPGStyleHeading(),
197 Options::rtTPGStyleFullArea(),
198 Options::rtTPGStyleContentWrap(),
199 Options::rtTPGStyleCategory(),
200 Options::rtTPGPostType(),
201 Options::rtTPGStyleButtonColorFields(),
202 Options::rtTPAdvanceFilters(),
203 Options::itemFields()
204 );
205
206 return $fields;
207 }
208
209 public static function rt_get_all_term_by_taxonomy( $taxonomy = null, $count = false, $parent = false ) {
210 $terms = [];
211 if ( $taxonomy ) {
212 $temp_terms = get_terms( [ 'taxonomy' => $taxonomy, 'hide_empty' => 0 ] );
213 if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) {
214 foreach ( $temp_terms as $term ) {
215 $order = get_term_meta( $term->term_id, '_rt_order', true );
216 if ( $order === "" ) {
217 update_term_meta( $term->term_id, '_rt_order', 0 );
218 }
219 }
220 global $wp_version;
221 $args = [
222 'taxonomy' => $taxonomy,
223 'orderby' => 'meta_value_num',
224 'meta_key' => '_rt_order',
225 'hide_empty' => false,
226 ];
227 if ( $parent >= 0 && $parent !== false ) {
228 $args['parent'] = absint( $parent );
229 }
230 $args['orderby'] = 'meta_value_num';
231 $args['meta_key'] = '_rt_order';
232
233 $termObjs = get_terms( $args );
234
235 foreach ( $termObjs as $term ) {
236 if ( $count ) {
237 $terms[ $term->term_id ] = [ 'name' => $term->name, 'count' => $term->count ];
238 } else {
239 $terms[ $term->term_id ] = $term->name;
240 }
241 }
242 }
243 }
244
245 return $terms;
246 }
247
248 public static function rt_get_selected_term_by_taxonomy( $taxonomy = null, $include = [], $count = false, $parent = false ) {
249 $terms = [];
250 if ( $taxonomy ) {
251 $temp_terms = get_terms( [ 'taxonomy' => $taxonomy, 'hide_empty' => 0 ] );
252 if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) {
253 foreach ( $temp_terms as $term ) {
254 $order = get_term_meta( $term->term_id, '_rt_order', true );
255 if ( $order === "" ) {
256 update_term_meta( $term->term_id, '_rt_order', 0 );
257 }
258 }
259 global $wp_version;
260 $args = [
261 'taxonomy' => $taxonomy,
262 'orderby' => 'meta_value_num',
263 'meta_key' => '_rt_order',
264 'include' => $include,
265 'hide_empty' => false,
266 ];
267 if ( $parent >= 0 && $parent !== false ) {
268 $args['parent'] = absint( $parent );
269 }
270 $args['orderby'] = 'meta_value_num';
271 $args['meta_key'] = '_rt_order';
272
273 $termObjs = get_terms( $args );
274
275 foreach ( $termObjs as $term ) {
276 if ( $count ) {
277 $terms[ $term->term_id ] = [ 'name' => $term->name, 'count' => $term->count ];
278 } else {
279 $terms[ $term->term_id ] = $term->name;
280 }
281 }
282 }
283 }
284
285 return $terms;
286 }
287
288 public static function getCurrentUserRoles() {
289 global $current_user;
290
291 return $current_user->roles;
292 }
293
294 public static function rt_get_taxonomy_for_filter( $post_type = null ) {
295 if ( ! $post_type ) {
296 $post_type = get_post_meta( get_the_ID(), 'tpg_post_type', true );
297 }
298 if ( ! $post_type ) {
299 $post_type = 'post';
300 }
301
302 return self::rt_get_all_taxonomy_by_post_type( $post_type );
303 }
304
305 public static function rt_get_all_taxonomy_by_post_type( $post_type = null ) {
306 $taxonomies = [];
307 if ( $post_type && post_type_exists( $post_type ) ) {
308 $taxObj = get_object_taxonomies( $post_type, 'objects' );
309 if ( is_array( $taxObj ) && ! empty( $taxObj ) ) {
310 foreach ( $taxObj as $tKey => $taxonomy ) {
311 $taxonomies[ $tKey ] = $taxonomy->label;
312 }
313 }
314 }
315 if ( $post_type == 'post' ) {
316 unset( $taxonomies['post_format'] );
317 }
318
319 return $taxonomies;
320 }
321
322 public static function rt_get_users() {
323 $users = [];
324 $u = get_users( apply_filters( 'tpg_author_arg', [] ) );
325 if ( ! empty( $u ) ) {
326 foreach ( $u as $user ) {
327 $users[ $user->ID ] = $user->display_name;
328 }
329 }
330
331 return $users;
332 }
333
334 public static function rtFieldGenerator( $fields = [] ) {
335 $html = null;
336 if ( is_array( $fields ) && ! empty( $fields ) ) {
337 $tpgField = new Field();
338 foreach ( $fields as $fieldKey => $field ) {
339 $html .= $tpgField->Field( $fieldKey, $field );
340 }
341 }
342
343 return $html;
344 }
345
346 /**
347 * Sanitize field value
348 *
349 * @param array $field
350 * @param null $value
351 *
352 * @return array|null
353 * @internal param $value
354 */
355 public static function sanitize( $field = [], $value = null ) {
356 $newValue = null;
357 if ( is_array( $field ) ) {
358 $type = ( ! empty( $field['type'] ) ? $field['type'] : 'text' );
359 if ( empty( $field['multiple'] ) ) {
360 if ( $type == 'text' || $type == 'number' || $type == 'select' || $type == 'checkbox' || $type == 'radio' ) {
361 $newValue = sanitize_text_field( $value );
362 } elseif ( $type == 'url' ) {
363 $newValue = esc_url( $value );
364 } elseif ( $type == 'slug' ) {
365 $newValue = sanitize_title_with_dashes( $value );
366 } elseif ( $type == 'textarea' ) {
367 $newValue = wp_kses_post( $value );
368 } elseif ( $type == 'script' ) {
369 $newValue = trim( $value );
370 } elseif ( $type == 'colorpicker' ) {
371 $newValue = self::sanitize_hex_color( $value );
372 } elseif ( $type == 'image_size' ) {
373 $newValue = [];
374 foreach ( $value as $k => $v ) {
375 $newValue[ $k ] = esc_attr( $v );
376 }
377 } elseif ( $type == 'style' ) {
378 $newValue = [];
379 foreach ( $value as $k => $v ) {
380 if ( $k == 'color' ) {
381 $newValue[ $k ] = self::sanitize_hex_color( $v );
382 } else {
383 $newValue[ $k ] = self::sanitize( [ 'type' => 'text' ], $v );
384 }
385 }
386 } else {
387 $newValue = sanitize_text_field( $value );
388 }
389 } else {
390 $newValue = [];
391 if ( ! empty( $value ) ) {
392 if ( is_array( $value ) ) {
393 foreach ( $value as $key => $val ) {
394 if ( $type == 'style' && $key == 0 ) {
395 if ( function_exists( 'sanitize_hex_color' ) ) {
396 $newValue = sanitize_hex_color( $val );
397 } else {
398 $newValue[] = self::sanitize_hex_color( $val );
399 }
400 } else {
401 $newValue[] = sanitize_text_field( $val );
402 }
403 }
404 } else {
405 $newValue[] = sanitize_text_field( $value );
406 }
407 }
408 }
409 }
410
411 return $newValue;
412 }
413
414 public static function sanitize_hex_color( $color ) {
415 if ( function_exists( 'sanitize_hex_color' ) ) {
416 return sanitize_hex_color( $color );
417 } else {
418 if ( '' === $color ) {
419 return '';
420 }
421
422 // 3 or 6 hex digits, or the empty string.
423 if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
424 return $color;
425 }
426 }
427 }
428
429 public static function rtFieldGeneratorBackup( $fields = [], $multi = false ) {
430 $html = null;
431 if ( is_array( $fields ) && ! empty( $fields ) ) {
432 $rtField = new Field();
433 if ( $multi ) {
434 foreach ( $fields as $field ) {
435 $html .= $rtField->Field( $field );
436 }
437 } else {
438 $html .= $rtField->Field( $fields );
439 }
440 }
441
442 return $html;
443 }
444
445 public static function rtSmartStyle( $fields = [] ) {
446 $h = null;
447 if ( ! empty( $fields ) ) {
448 foreach ( $fields as $key => $label ) {
449 $atts = '';
450 $proText = '';
451 $class = '';
452
453 $h .= "<div class='field-holder {$class}'>";
454
455 $h .= "<div class='field-label'><label>{$label}{$proText}</label></div>";
456 $h .= "<div class='field'>";
457 // color
458 $h .= "<div class='field-inner col-4'>";
459 $h .= "<div class='field-inner-container size'>";
460 $h .= "<span class='label'>Color</span>";
461 $cValue = get_post_meta( get_the_ID(), $key . "_color", true );
462 $h .= "<input type='text' value='{$cValue}' class='rt-color' name='{$key}_color'>";
463 $h .= "</div>";
464 $h .= "</div>";
465
466 // Font size
467 $h .= "<div class='field-inner col-4'>";
468 $h .= "<div class='field-inner-container size'>";
469 $h .= "<span class='label'>Font size</span>";
470 $h .= "<select {$atts} name='{$key}_size' class='rt-select2'>";
471 $fSizes = Options::scFontSize();
472 $sValue = get_post_meta( get_the_ID(), $key . "_size", true );
473 $h .= "<option value=''>Default</option>";
474 foreach ( $fSizes as $size => $sizeLabel ) {
475 $sSlt = ( $size == $sValue ? "selected" : null );
476 $h .= "<option value='{$size}' {$sSlt}>{$sizeLabel}</option>";
477 }
478 $h .= "</select>";
479 $h .= "</div>";
480 $h .= "</div>";
481
482 // Weight
483
484 $h .= "<div class='field-inner col-4'>";
485 $h .= "<div class='field-inner-container weight'>";
486 $h .= "<span class='label'>Weight</span>";
487 $h .= "<select {$atts} name='{$key}_weight' class='rt-select2'>";
488 $h .= "<option value=''>Default</option>";
489 $weights = Options::scTextWeight();
490 $wValue = get_post_meta( get_the_ID(), $key . "_weight", true );
491 foreach ( $weights as $weight => $weightLabel ) {
492 $wSlt = ( $weight == $wValue ? "selected" : null );
493 $h .= "<option value='{$weight}' {$wSlt}>{$weightLabel}</option>";
494 }
495 $h .= "</select>";
496 $h .= "</div>";
497 $h .= "</div>";
498
499 // Alignment
500
501 $h .= "<div class='field-inner col-4'>";
502 $h .= "<div class='field-inner-container alignment'>";
503 $h .= "<span class='label'>Alignment</span>";
504 $h .= "<select {$atts} name='{$key}_alignment' class='rt-select2'>";
505 $h .= "<option value=''>Default</option>";
506 $aligns = Options::scAlignment();
507 $aValue = get_post_meta( get_the_ID(), $key . "_alignment", true );
508 foreach ( $aligns as $align => $alignLabel ) {
509 $aSlt = ( $align == $aValue ? "selected" : null );
510 $h .= "<option value='{$align}' {$aSlt}>{$alignLabel}</option>";
511 }
512 $h .= "</select>";
513 $h .= "</div>";
514 $h .= "</div>";
515
516 $h .= "</div>";
517 $h .= "</div>";
518 }
519 }
520
521 return $h;
522 }
523
524 public static function custom_variation_price( $product ) {
525 $price = '';
526 $max = $product->get_variation_sale_price( 'max' );
527 $min = $product->get_variation_sale_price( 'min' );
528
529 if ( ! $min || $min !== $max ) {
530 $price .= wc_price( $product->get_price() );
531 }
532
533 if ( $max && $max !== $min ) {
534 $price .= " - ";
535 $price .= wc_price( $max );
536 }
537
538 return $price;
539 }
540
541 public static function getTPGShortCodeList() {
542 $scList = null;
543 $scQ = get_posts( [
544 'post_type' => rtTPG()->post_type,
545 'order_by' => 'title',
546 'order' => 'DESC',
547 'post_status' => 'publish',
548 'posts_per_page' => - 1,
549 'meta_query' => [
550 [
551 'key' => 'layout',
552 'value' => 'layout',
553 'compare' => 'LIKE',
554 ],
555 ],
556 ] );
557 if ( ! empty( $scQ ) ) {
558 foreach ( $scQ as $sc ) {
559 $scList[ $sc->ID ] = $sc->post_title;
560 }
561 }
562
563 return $scList;
564 }
565
566 public static function getAllTPGShortCodeList() {
567 $scList = null;
568 $scQ = get_posts( [
569 'post_type' => rtTPG()->post_type,
570 'order_by' => 'title',
571 'order' => 'ASC',
572 'post_status' => 'publish',
573 'posts_per_page' => - 1,
574 ] );
575 if ( ! empty( $scQ ) ) {
576 foreach ( $scQ as $sc ) {
577 $scList[ $sc->ID ] = $sc->post_title;
578 }
579 }
580
581 return $scList;
582 }
583
584 public static function socialShare( $pLink ) {
585 $html = null;
586 $html .= "<div class='single-tpg-share'>
587 <div class='fb-share'>
588 <div class='fb-share-button' data-href='{$pLink}' data-layout='button_count'></div>
589 </div>
590 <div class='twitter-share'>
591 <a href='{$pLink}' class='twitter-share-button'{count} data-url='https://about.twitter.com/resources/buttons#tweet'>Tweet</a>
592 </div>
593 <div class='googleplus-share'>
594 <div class='g-plusone'></div>
595 </div>
596 <div class='linkedin-share'>
597 <script type='IN/Share' data-counter='right'></script>
598 </div>
599 <div class='linkedin-share'>
600 <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>
601 </div>
602 </div>";
603 $html .= '<div id="fb-root"></div>
604 <script>(function(d, s, id) {
605 var js, fjs = d.getElementsByTagName(s)[0];
606 if (d.getElementById(id)) return;
607 js = d.createElement(s); js.id = id;
608 js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
609 fjs.parentNode.insertBefore(js, fjs);
610 }(document, "script", "facebook-jssdk"));</script>';
611 $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>
612 <script>window.___gcfg = { lang: 'en-US', parsetags: 'onload', };</script>";
613 $html .= "<script src='https://apis.google.com/js/platform.js' async defer></script>";
614 $html .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>';
615 $html .= '<script async defer src="//assets.pinterest.com/js/pinit.js"></script>';
616
617 return $html;
618 }
619
620 public static function get_image_sizes() {
621 global $_wp_additional_image_sizes;
622
623 $sizes = [];
624 $interSizes = get_intermediate_image_sizes();
625 if ( ! empty( $interSizes ) ) {
626 foreach ( get_intermediate_image_sizes() as $_size ) {
627 if ( in_array( $_size, [ 'thumbnail', 'medium', 'large' ] ) ) {
628 $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" );
629 $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" );
630 $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" );
631 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
632 $sizes[ $_size ] = [
633 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
634 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
635 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
636 ];
637 }
638 }
639 }
640
641 $imgSize = [];
642 if ( ! empty( $sizes ) ) {
643 $imgSize['full'] = __( "Full Size", 'the-post-grid' );
644 foreach ( $sizes as $key => $img ) {
645 $imgSize[ $key ] = ucfirst( $key ) . " ({$img['width']}*{$img['height']})";
646 }
647 }
648
649 return apply_filters( 'tpg_image_sizes', $imgSize );
650 }
651
652 public static function getFeatureImageSrc(
653 $post_id = null,
654 $fImgSize = 'medium',
655 $mediaSource = 'feature_image',
656 $defaultImgId = null,
657 $customImgSize = [],
658 $img_Class = ''
659 ) {
660 global $post;
661 $imgSrc = null;
662 $img_class = "rt-img-responsive ";
663 if ( $img_Class ) {
664 $img_class .= $img_Class;
665 }
666 $post_id = ( $post_id ? absint( $post_id ) : $post->ID );
667 $alt = get_the_title( $post_id );
668 $image = null;
669 $cSize = false;
670 if ( $fImgSize == 'rt_custom' ) {
671 $fImgSize = 'full';
672 $cSize = true;
673 }
674
675 if ( $mediaSource == 'feature_image' ) {
676 if ( $aID = get_post_thumbnail_id( $post_id ) ) {
677 $image = wp_get_attachment_image( $aID, $fImgSize, '', [ 'class' => $img_class, 'loading' => false ] );
678 $imgSrc = wp_get_attachment_image_src( $aID, $fImgSize );
679 if ( ! empty( $imgSrc ) && $img_Class == 'swiper-lazy' ) {
680 $image = "<img class='{$img_class}' data-src='{$imgSrc[0]}' src='#none' width='{$imgSrc[1]}' height='{$imgSrc[2]}' alt='{$alt}'/><div class='lazy-overlay-wrap'><div class='swiper-lazy-preloader swiper-lazy-preloader-white'></div></div>";
681 }
682 $imgSrc = ! empty( $imgSrc ) ? $imgSrc[0] : $imgSrc;
683 }
684 } elseif ( $mediaSource == 'first_image' ) {
685 if ( $img = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
686 get_the_content( $post_id ),
687 $matches )
688 ) {
689 $imgSrc = $matches[1][0];
690 $size = '';
691
692 if ( strpos( $imgSrc, site_url() ) !== false ) {
693 $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc );
694 } else {
695 $imgAbs = ABSPATH . $imgSrc;
696 }
697
698 $imgAbs = apply_filters( 'rt_tpg_sc_first_image_src', $imgAbs );
699
700 if ( file_exists( $imgAbs ) ) {
701 $info = getimagesize( $imgAbs );
702 $size = isset( $info[3] ) ? $info[3] : '';
703 }
704
705 $image = "<img class='{$img_class}' src='{$imgSrc}' {$size} alt='{$alt}'>";
706 if ( $img_Class == 'swiper-lazy' ) {
707 $image = "<img class='{$img_class} img-responsive' data-src='{$imgSrc}' src='#none' {$size} alt='{$alt}'/><div class='lazy-overlay-wrap'><div class='swiper-lazy-preloader swiper-lazy-preloader-white'></div></div>";
708 }
709 }
710 }
711
712 if ( ! $imgSrc && $defaultImgId ) {
713 $image = wp_get_attachment_image( $defaultImgId, $fImgSize );
714 }
715
716 if ( $imgSrc && $cSize ) {
717 $w = ( ! empty( $customImgSize[0] ) ? absint( $customImgSize[0] ) : null );
718 $h = ( ! empty( $customImgSize[1] ) ? absint( $customImgSize[1] ) : null );
719 $c = ( ! empty( $customImgSize[2] ) && $customImgSize[2] == 'soft' ? false : true );
720
721 if ( $w && $h ) {
722 $post_thumb_id = get_post_thumbnail_id( $post_id );
723 if ( $post_thumb_id ) {
724 $featured_image = wp_get_attachment_image_src( $post_thumb_id, 'full' );
725 $w = $featured_image[1] < $w ? $featured_image[1] : $w;
726 $h = $featured_image[2] < $h ? $featured_image[2] : $h;
727 }
728 $imgSrc = Fns::rtImageReSize( $imgSrc, $w, $h, $c );
729 if ( $img_Class !== 'swiper-lazy' ) {
730 $image = "<img class='{$img_class}' src='{$imgSrc}' width='{$w}' height='{$h}' alt='{$alt}'/>";
731 } else {
732 $image = "<img class='{$img_class} img-responsive' data-src='{$imgSrc}' src='#none' width='{$w}' height='{$h}' alt='{$alt}'/><div class='lazy-overlay-wrap'><div class='swiper-lazy-preloader swiper-lazy-preloader-white'></div></div>";
733 }
734 }
735 }
736
737 return $image;
738 }
739
740 public static function getFeatureImageUrl( $post_id = null, $fImgSize = 'medium' ) {
741 $image = $imgSrc = null;
742
743 if ( $aID = get_post_thumbnail_id( $post_id ) ) {
744 $image = wp_get_attachment_image_src( $aID, $fImgSize );
745 }
746
747 if ( is_array( $image ) ) {
748 $imgSrc = $image[0];
749 }
750
751 return $imgSrc;
752 }
753
754 public static function tpgCharacterLimit( $limit, $content ) {
755 $limit ++;
756
757 $text = '';
758
759 if ( mb_strlen( $content ) > $limit ) {
760 $subex = mb_substr( $content, 0, $limit );
761 $exwords = explode( ' ', $subex );
762 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
763
764 if ( $excut < 0 ) {
765 $text = mb_substr( $subex, 0, $excut );
766 } else {
767 $text = $subex;
768 }
769 } else {
770 $text = $content;
771 }
772
773 return $text;
774 }
775
776 public static function get_the_excerpt( $post_id, $data = [] ) {
777 $type = $data['excerpt_type'];
778 $post = get_post( $post_id );
779 if ( empty( $post ) ) {
780 return '';
781 }
782 if ( $type == 'full' ) {
783 ob_start();
784 the_content();
785 $content = ob_get_clean();
786
787 return apply_filters( 'tpg_content_full', $content, $post_id, $data );
788 } else {
789 if ( class_exists( 'ET_GB_Block_Layout' ) ) {
790 $defaultExcerpt = $post->post_excerpt ?: wp_trim_words( $post->post_content, 55 );
791 } else {
792 $defaultExcerpt = get_the_excerpt( $post_id );
793 }
794 $limit = isset( $data['excerpt_limit'] ) && $data['excerpt_limit'] ? abs( $data['excerpt_limit'] ) : 0;
795 $more = $data['excerpt_more_text'];
796 $excerpt = preg_replace( '`\[[^\]]*\]`', '', $defaultExcerpt );
797 $excerpt = strip_shortcodes( $excerpt );
798 $excerpt = preg_replace( '`[[^]]*]`', '', $excerpt );
799 $excerpt = str_replace( '', '', $excerpt );
800 if ( $limit ) {
801 $excerpt = wp_strip_all_tags( $excerpt );
802 if ( $type == "word" ) {
803 $limit = $limit + 1;
804 $rawExcerpt = $excerpt;
805 $excerpt = explode( ' ', $excerpt, $limit );
806 if ( count( $excerpt ) >= $limit ) {
807 array_pop( $excerpt );
808 $excerpt = implode( " ", $excerpt );
809 } else {
810 $excerpt = $rawExcerpt;
811 }
812 } else {
813 $excerpt = self::tpgCharacterLimit( $limit, $excerpt );
814 }
815 $excerpt = stripslashes( $excerpt );
816 } else {
817 $allowed_html = [
818 'a' => [
819 'href' => [],
820 'title' => [],
821 ],
822 'strong' => [],
823 'b' => [],
824 'br' => [ [] ],
825 ];
826 $excerpt = nl2br( wp_kses( $excerpt, $allowed_html ) );
827 }
828
829 $excerpt = ( $more ? $excerpt . " " . $more : $excerpt );
830
831 return apply_filters( 'tpg_get_the_excerpt', $excerpt, $post_id, $data, $defaultExcerpt );
832 }
833 }
834
835 public static function get_the_title( $post_id, $data = [] ) {
836 $title = $originalTitle = get_the_title( $post_id );
837 $limit = isset( $data['title_limit'] ) ? absint( $data['title_limit'] ) : 0;
838 $limit_type = isset( $data['title_limit_type'] ) ? trim( $data['title_limit_type'] ) : 'character';
839 if ( $limit ) {
840 if ( $limit_type == "word" ) {
841 $limit = $limit + 1;
842 $title = explode( ' ', $title, $limit );
843 if ( count( $title ) >= $limit ) {
844 array_pop( $title );
845 $title = implode( " ", $title );
846 } else {
847 $title = $originalTitle;
848 }
849 } else {
850 if ( $limit > 0 && strlen( $title ) > $limit ) {
851 $title = mb_substr( $title, 0, $limit, "utf-8" );
852 $title = preg_replace( '/\W\w+\s*(\W*)$/', '$1', $title );
853 }
854 }
855 }
856
857 return apply_filters( 'tpg_get_the_title', $title, $post_id, $data, $originalTitle );
858 }
859
860
861 public static function rt_pagination( $postGrid, $range = 4, $ajax = false ) {
862 $html = $pages = null;
863 $showitems = ( $range * 2 ) + 1;
864
865 $wpQuery = $postGrid;
866 global $wp_query;
867 if ( empty( $wpQuery ) ) {
868 $wpQuery = $wp_query;
869 }
870
871 $pages = ! empty( $wpQuery->max_num_pages ) ? $wpQuery->max_num_pages : 1;
872 $paged = ! empty( $wpQuery->query['paged'] ) ? $wpQuery->query['paged'] : 1;
873 if ( is_front_page() ) {
874 $paged = ! empty( $wp_query->query['paged'] ) ? $wp_query->query['paged'] : 1;
875 }
876
877
878 $ajaxClass = null;
879 $dataAttr = null;
880
881 if ( $ajax ) {
882 $ajaxClass = ' rt-ajax';
883 $dataAttr = "data-paged='1'";
884 }
885
886 if ( 1 != $pages ) {
887 $html .= '<div class="rt-pagination' . $ajaxClass . '" ' . $dataAttr . '>';
888 $html .= '<ul class="pagination-list">';
889 if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages && ! $ajax ) {
890 $html .= "<li><a data-paged='1' href='" . get_pagenum_link( 1 ) . "' aria-label='First'>&laquo;</a></li>";
891 }
892
893 if ( $paged > 1 && $showitems < $pages && ! $ajax ) {
894 $p = $paged - 1;
895 $html .= "<li><a data-paged='{$p}' href='" . get_pagenum_link( $p ) . "' aria-label='Previous'>&lsaquo;</a></li>";
896 }
897
898 if ( $ajax ) {
899 for ( $i = 1; $i <= $pages; $i ++ ) {
900 $html .= ( $paged == $i ) ? "<li class=\"active\"><span>" . $i . "</span>
901
902 </li>" : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . "</a></li>";
903 }
904 } else {
905 for ( $i = 1; $i <= $pages; $i ++ ) {
906 if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
907 $html .= ( $paged == $i ) ? "<li class=\"active\"><span>" . $i . "</span>
908
909 </li>" : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . "</a></li>";
910 }
911 }
912 }
913
914 if ( $paged < $pages && $showitems < $pages && ! $ajax ) {
915 $p = $paged + 1;
916 $html .= "<li><a data-paged='{$p}' href=\"" . get_pagenum_link( $paged + 1 ) . "\" aria-label='Next'>&rsaquo;</a></li>";
917 }
918
919 if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages && ! $ajax ) {
920 $html .= "<li><a data-paged='{$pages}' href='" . get_pagenum_link( $pages ) . "' aria-label='Last'>&raquo;</a></li>";
921 }
922
923 $html .= "</ul>";
924 $html .= "</div>";
925 }
926
927 return $html;
928 }
929
930 public static function rt_pagination_ajax( $scID, $range = 4, $pages = '' ) {
931 $html = null;
932
933
934 $html .= "<div class='rt-tpg-pagination-ajax' data-sc-id='{$scID}' data-paged='1'>";
935
936 $html .= "</div>";
937
938 return $html;
939 }
940
941 /**
942 * Call the Image resize model for resize function
943 *
944 * @param $url
945 * @param null $width
946 * @param null $height
947 * @param null $crop
948 * @param bool|true $single
949 * @param bool|false $upscale
950 *
951 * @return array|bool|string
952 * @throws Exception
953 * @throws Rt_Exception
954 */
955 public static function rtImageReSize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
956 $rtResize = new ReSizer();
957
958 return $rtResize->process( $url, $width, $height, $crop, $single, $upscale );
959 }
960
961
962 /* Convert hexdec color string to rgb(a) string */
963 public static function rtHex2rgba( $color, $opacity = .5 ) {
964 $default = 'rgb(0,0,0)';
965
966 //Return default if no color provided
967 if ( empty( $color ) ) {
968 return $default;
969 }
970
971 //Sanitize $color if "#" is provided
972 if ( $color[0] == '#' ) {
973 $color = substr( $color, 1 );
974 }
975
976 //Check if color has 6 or 3 characters and get values
977 if ( strlen( $color ) == 6 ) {
978 $hex = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ];
979 } elseif ( strlen( $color ) == 3 ) {
980 $hex = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ];
981 } else {
982 return $default;
983 }
984
985 //Convert hexadec to rgb
986 $rgb = array_map( 'hexdec', $hex );
987
988 //Check if opacity is set(rgba or rgb)
989 if ( $opacity ) {
990 if ( absint( $opacity ) > 1 ) {
991 $opacity = 1.0;
992 }
993 $output = 'rgba(' . implode( ",", $rgb ) . ',' . $opacity . ')';
994 } else {
995 $output = 'rgb(' . implode( ",", $rgb ) . ')';
996 }
997
998 //Return rgb(a) color string
999 return $output;
1000 }
1001
1002 public static function meta_exist( $meta_key, $post_id = null, $type = "post" ) {
1003 if ( ! $post_id ) {
1004 return false;
1005 }
1006
1007 return metadata_exists( $type, $post_id, $meta_key );
1008 }
1009
1010
1011 public static function get_offset_col( $col ) {
1012 $return = [
1013 'big' => 6,
1014 'small' => 6,
1015 ];
1016 if ( $col ) {
1017 if ( $col == 12 ) {
1018 $return['big'] = 12;
1019 $return['small'] = 12;
1020 } elseif ( $col == 6 ) {
1021 $return['big'] = 6;
1022 $return['small'] = 6;
1023 } elseif ( $col == 4 ) {
1024 $return['big'] = 4;
1025 $return['small'] = 8;
1026 }
1027 }
1028
1029 return $return;
1030 }
1031
1032 public static function formatSpacing( $data = '' ) {
1033 if ( ! empty( $data ) ) {
1034 $spacing = array_filter( explode( ',', $data ), 'is_numeric' );
1035 if ( count( $spacing ) > 4 ) {
1036 $spacing = array_slice( $spacing, 0, 4, true );
1037 }
1038 $data = implode( "px ", $spacing );
1039 }
1040
1041 return $data;
1042 }
1043
1044 public static function layoutStyle( $layoutID, $scMeta, $layout, $scId = null ) {
1045 $css = null;
1046 $css .= "<style type='text/css' media='all'>";
1047 // primary color
1048 if ( $scId ) {
1049 $primaryColor = ( isset( $scMeta['primary_color'][0] ) ? $scMeta['primary_color'][0] : null );
1050 $button_bg_color = ( isset( $scMeta['button_bg_color'][0] ) ? $scMeta['button_bg_color'][0] : null );
1051 $button_active_bg_color = ( isset( $scMeta['button_active_bg_color'][0] ) ? $scMeta['button_active_bg_color'][0] : null );
1052 $button_hover_bg_color = ( isset( $scMeta['button_hover_bg_color'][0] ) ? $scMeta['button_hover_bg_color'][0] : null );
1053 $button_text_color = ( isset( $scMeta['button_text_bg_color'][0] ) ? $scMeta['button_text_bg_color'][0]
1054 : ( isset( $scMeta['button_text_color'][0] ) ? $scMeta['button_text_color'][0] : null ) );
1055 $button_hover_text_color = ( isset( $scMeta['button_hover_text_color'][0] ) ? $scMeta['button_hover_text_color'][0] : null );
1056 $button_border_color = ( isset( $scMeta['button_border_color'][0] ) ? $scMeta['button_border_color'][0] : null );
1057 $overlay_color = ( ! empty( $scMeta['overlay_color'][0] ) ? Fns::rtHex2rgba( $scMeta['overlay_color'][0],
1058 ! empty( $scMeta['overlay_opacity'][0] ) ? absint( $scMeta['overlay_opacity'][0] ) / 10 : .8 ) : null );
1059 $overlay_padding = ( ! empty( $scMeta['overlay_padding'][0] ) ? absint( $scMeta['overlay_padding'][0] ) : null );
1060 $gutter = ! empty( $scMeta['tgp_gutter'][0] ) ? absint( $scMeta['tgp_gutter'][0] ) : null;
1061 $read_more_button_border_radius = isset( $scMeta['tpg_read_more_button_border_radius'][0] ) ? $scMeta['tpg_read_more_button_border_radius'][0] : '';
1062 // Section
1063 $sectionBg = ( isset( $scMeta['tpg_full_area_bg'][0] ) ? $scMeta['tpg_full_area_bg'][0] : null );
1064 $sectionMargin = ( isset( $scMeta['tpg_full_area_margin'][0] ) ? $scMeta['tpg_full_area_margin'][0] : null );
1065 $sectionMargin = self::formatSpacing( $sectionMargin );
1066 $sectionPadding = ( isset( $scMeta['tpg_full_area_padding'][0] ) ? $scMeta['tpg_full_area_padding'][0] : null );
1067 $sectionPadding = self::formatSpacing( $sectionPadding );
1068 // Box
1069 $boxBg = ( isset( $scMeta['tpg_content_wrap_bg'][0] ) ? $scMeta['tpg_content_wrap_bg'][0] : null );
1070 $boxBorder = ( isset( $scMeta['tpg_content_wrap_border'][0] ) ? $scMeta['tpg_content_wrap_border'][0] : null );
1071 $boxBorderColor = ( isset( $scMeta['tpg_content_wrap_border_color'][0] ) ? $scMeta['tpg_content_wrap_border_color'][0] : null );
1072 $boxBorderRadius = ( isset( $scMeta['tpg_content_wrap_border_radius'][0] ) ? $scMeta['tpg_content_wrap_border_radius'][0] : null );
1073 $boxShadow = ( isset( $scMeta['tpg_content_wrap_shadow'][0] ) ? $scMeta['tpg_content_wrap_shadow'][0] : null );
1074 $boxPadding = ( isset( $scMeta['tpg_box_padding'][0] ) ? $scMeta['tpg_box_padding'][0] : null );
1075 $boxPadding = self::formatSpacing( $boxPadding );
1076 $contentPadding = ( isset( $scMeta['tpg_content_padding'][0] ) ? $scMeta['tpg_content_padding'][0] : null );
1077 $contentPadding = self::formatSpacing( $contentPadding );
1078 // Heading
1079 $headingBg = ( isset( $scMeta['tpg_heading_bg'][0] ) ? $scMeta['tpg_heading_bg'][0] : null );
1080 $headingColor = ( isset( $scMeta['tpg_heading_color'][0] ) ? $scMeta['tpg_heading_color'][0] : null );
1081 $headingBorderColor = ( isset( $scMeta['tpg_heading_border_color'][0] ) ? $scMeta['tpg_heading_border_color'][0] : null );
1082 $headingBorderSize = ( isset( $scMeta['tpg_heading_border_size'][0] ) ? $scMeta['tpg_heading_border_size'][0] : null );
1083 $headingMargin = ( isset( $scMeta['tpg_heading_margin'][0] ) ? $scMeta['tpg_heading_margin'][0] : null );
1084 $headingMargin = self::formatSpacing( $headingMargin );
1085 $headingPadding = ( isset( $scMeta['tpg_heading_padding'][0] ) ? $scMeta['tpg_heading_padding'][0] : null );
1086 $headingPadding = self::formatSpacing( $headingPadding );
1087 // Category
1088 $catBg = ( isset( $scMeta['tpg_category_bg'][0] ) ? $scMeta['tpg_category_bg'][0] : null );
1089 $catTextColor = ( isset( $scMeta['tpg_category_color'][0] ) ? $scMeta['tpg_category_color'][0] : null );
1090 $catBorderRadius = ( isset( $scMeta['tpg_category_border_radius'][0] ) ? $scMeta['tpg_category_border_radius'][0] : null );
1091 $catMargin = ( isset( $scMeta['tpg_category_margin'][0] ) ? $scMeta['tpg_category_margin'][0] : null );
1092 $catMargin = self::formatSpacing( $catMargin );
1093 $catPadding = ( isset( $scMeta['tpg_category_padding'][0] ) ? $scMeta['tpg_category_padding'][0] : null );
1094 $catPadding = self::formatSpacing( $catPadding );
1095 $categorySize = ( ! empty( $scMeta['rt_tpg_category_font_size'][0] ) ? absint( $scMeta['rt_tpg_category_font_size'][0] ) : null );
1096 // Image
1097 $image_border_radius = isset( $scMeta['tpg_image_border_radius'][0] ) ? $scMeta['tpg_image_border_radius'][0] : '';
1098 // Title
1099 $title_color = ( ! empty( $scMeta['title_color'][0] ) ? $scMeta['title_color'][0] : null );
1100 $title_size = ( ! empty( $scMeta['title_size'][0] ) ? absint( $scMeta['title_size'][0] ) : null );
1101 $title_weight = ( ! empty( $scMeta['title_weight'][0] ) ? $scMeta['title_weight'][0] : null );
1102 $title_alignment = ( ! empty( $scMeta['title_alignment'][0] ) ? $scMeta['title_alignment'][0] : null );
1103
1104 $title_hover_color = ( ! empty( $scMeta['title_hover_color'][0] ) ? $scMeta['title_hover_color'][0] : null );
1105
1106 $excerpt_color = ( ! empty( $scMeta['excerpt_color'][0] ) ? $scMeta['excerpt_color'][0] : null );
1107 $excerpt_size = ( ! empty( $scMeta['excerpt_size'][0] ) ? absint( $scMeta['excerpt_size'][0] ) : null );
1108 $excerpt_weight = ( ! empty( $scMeta['excerpt_weight'][0] ) ? $scMeta['excerpt_weight'][0] : null );
1109 $excerpt_alignment = ( ! empty( $scMeta['excerpt_alignment'][0] ) ? $scMeta['excerpt_alignment'][0] : null );
1110
1111 $meta_data_color = ( ! empty( $scMeta['meta_data_color'][0] ) ? $scMeta['meta_data_color'][0] : null );
1112 $meta_data_size = ( ! empty( $scMeta['meta_data_size'][0] ) ? absint( $scMeta['meta_data_size'][0] ) : null );
1113 $meta_data_weight = ( ! empty( $scMeta['meta_data_weight'][0] ) ? $scMeta['meta_data_weight'][0] : null );
1114 $meta_data_alignment = ( ! empty( $scMeta['meta_data_alignment'][0] ) ? $scMeta['meta_data_alignment'][0] : null );
1115 } else {
1116 $primaryColor = ( isset( $scMeta['primary_color'] ) ? $scMeta['primary_color'] : null );
1117 $button_bg_color = ( isset( $scMeta['button_bg_color'] ) ? $scMeta['button_bg_color'] : null );
1118 $button_active_bg_color = ( isset( $scMeta['button_active_bg_color'] ) ? $scMeta['button_active_bg_color'] : null );
1119 $button_hover_bg_color = ( isset( $scMeta['button_hover_bg_color'] ) ? $scMeta['button_hover_bg_color'] : null );
1120 $btn_text_color = get_post_meta( $scMeta['sc_id'], 'button_text_color', true );
1121 $button_text_color = ( ! empty( $scMeta['button_text_bg_color'] ) ? $scMeta['button_text_bg_color']
1122 : ( ! empty( $btn_text_color ) ? $btn_text_color : null ) );
1123 $button_border_color = ( isset( $scMeta['button_border_color'] ) ? $scMeta['button_border_color'] : null );
1124 $button_hover_text_color = ( isset( $scMeta['button_hover_text_color'] ) ? $scMeta['button_hover_text_color'] : null );
1125 $overlay_color = ( ! empty( $scMeta['overlay_color'] ) ? Fns::rtHex2rgba( $scMeta['overlay_color'],
1126 ! empty( $scMeta['overlay_opacity'] ) ? absint( $scMeta['overlay_opacity'] ) / 10 : .8 ) : null );
1127 $overlay_padding = ( ! empty( $scMeta['overlay_padding'] ) ? absint( $scMeta['overlay_padding'] ) : null );
1128 $gutter = ! empty( $scMeta['tgp_gutter'] ) ? absint( $scMeta['tgp_gutter'] ) : null;
1129 $read_more_button_border_radius = isset( $scMeta['tpg_read_more_button_border_radius'] ) ? $scMeta['tpg_read_more_button_border_radius'] : '';
1130 // Section
1131 $sectionBg = ( isset( $scMeta['tpg_full_area_bg'] ) ? $scMeta['tpg_full_area_bg'] : null );
1132 $sectionMargin = ( isset( $scMeta['tpg_full_area_margin'] ) ? $scMeta['tpg_full_area_margin'] : null );
1133 $sectionMargin = self::formatSpacing( $sectionMargin );
1134 $sectionPadding = ( isset( $scMeta['tpg_full_area_padding'] ) ? $scMeta['tpg_full_area_padding'] : null );
1135 $sectionPadding = self::formatSpacing( $sectionPadding );
1136 // Box
1137 $boxBg = ( isset( $scMeta['tpg_content_wrap_bg'] ) ? $scMeta['tpg_content_wrap_bg'] : null );
1138 $boxBorder = ( isset( $scMeta['tpg_content_wrap_border'] ) ? $scMeta['tpg_content_wrap_border'] : null );
1139 $boxBorderColor = ( isset( $scMeta['tpg_content_wrap_border_color'] ) ? $scMeta['tpg_content_wrap_border_color'] : null );
1140 $boxBorderRadius = ( isset( $scMeta['tpg_content_wrap_border_radius'] ) ? $scMeta['tpg_content_wrap_border_radius'] : null );
1141 $boxShadow = ( isset( $scMeta['tpg_content_wrap_shadow'] ) ? $scMeta['tpg_content_wrap_shadow'] : null );
1142 $boxPadding = ( isset( $scMeta['tpg_box_padding'] ) ? $scMeta['tpg_box_padding'] : null );
1143 $boxPadding = self::formatSpacing( $boxPadding );
1144 $contentPadding = ( isset( $scMeta['tpg_content_padding'] ) ? $scMeta['tpg_content_padding'] : null );
1145 $contentPadding = self::formatSpacing( $contentPadding );
1146 // Heading
1147 $headingBg = ( isset( $scMeta['tpg_heading_bg'] ) ? $scMeta['tpg_heading_bg'] : null );
1148 $headingColor = ( isset( $scMeta['tpg_heading_color'] ) ? $scMeta['tpg_heading_color'] : null );
1149 $headingBorderColor = ( isset( $scMeta['tpg_heading_border_color'] ) ? $scMeta['tpg_heading_border_color'] : null );
1150 $headingBorderSize = ( isset( $scMeta['tpg_heading_border_size'] ) ? $scMeta['tpg_heading_border_size'] : null );
1151 $headingMargin = ( isset( $scMeta['tpg_heading_margin'] ) ? $scMeta['tpg_heading_margin'] : null );
1152 $headingMargin = self::formatSpacing( $headingMargin );
1153 $headingPadding = ( isset( $scMeta['tpg_heading_padding'] ) ? $scMeta['tpg_heading_padding'] : null );
1154 $headingPadding = self::formatSpacing( $headingPadding );
1155 // Category
1156 $catBg = ( isset( $scMeta['tpg_category_bg'] ) ? $scMeta['tpg_category_bg'] : null );
1157 $catTextColor = ( isset( $scMeta['tpg_category_color'] ) ? $scMeta['tpg_category_color'] : null );
1158 $catBorderRadius = ( isset( $scMeta['tpg_category_border_radius'] ) ? $scMeta['tpg_category_border_radius'] : null );
1159 $catMargin = ( isset( $scMeta['tpg_category_margin'] ) ? $scMeta['tpg_category_margin'] : null );
1160 $catPadding = ( isset( $scMeta['tpg_category_padding'] ) ? $scMeta['tpg_category_padding'] : null );
1161 $categorySize = ( ! empty( $scMeta['rt_tpg_category_font_size'] ) ? absint( $scMeta['rt_tpg_category_font_size'] ) : null );
1162 // Image
1163 $image_border_radius = isset( $scMeta['tpg_image_border_radius'] ) ? $scMeta['tpg_image_border_radius'] : '';
1164 // Title
1165 $title_color = ( ! empty( $scMeta['title_color'] ) ? $scMeta['title_color'] : null );
1166 $title_size = ( ! empty( $scMeta['title_size'] ) ? absint( $scMeta['title_size'] ) : null );
1167 $title_weight = ( ! empty( $scMeta['title_weight'] ) ? $scMeta['title_weight'] : null );
1168 $title_alignment = ( ! empty( $scMeta['title_alignment'] ) ? $scMeta['title_alignment'] : null );
1169
1170 $title_hover_color = ( ! empty( $scMeta['title_hover_color'] ) ? $scMeta['title_hover_color'] : null );
1171
1172 $excerpt_color = ( ! empty( $scMeta['excerpt_color'] ) ? $scMeta['excerpt_color'] : null );
1173 $excerpt_size = ( ! empty( $scMeta['excerpt_size'] ) ? absint( $scMeta['excerpt_size'] ) : null );
1174 $excerpt_weight = ( ! empty( $scMeta['excerpt_weight'] ) ? $scMeta['excerpt_weight'] : null );
1175 $excerpt_alignment = ( ! empty( $scMeta['excerpt_alignment'] ) ? $scMeta['excerpt_alignment'] : null );
1176
1177 $meta_data_color = ( ! empty( $scMeta['meta_data_color'] ) ? $scMeta['meta_data_color'] : null );
1178 $meta_data_size = ( ! empty( $scMeta['meta_data_size'] ) ? absint( $scMeta['meta_data_size'] ) : null );
1179 $meta_data_weight = ( ! empty( $scMeta['meta_data_weight'] ) ? $scMeta['meta_data_weight'] : null );
1180 $meta_data_alignment = ( ! empty( $scMeta['meta_data_alignment'] ) ? $scMeta['meta_data_alignment'] : null );
1181 }
1182
1183 $id = str_replace( 'rt-tpg-container-', '', $layoutID );
1184
1185 if ( $primaryColor ) {
1186 $css .= "#{$layoutID} .rt-holder .rt-woo-info .price{";
1187 $css .= "color:" . $primaryColor . ";";
1188 $css .= "}";
1189 $css .= "body .rt-tpg-container .rt-tpg-isotope-buttons .selected,
1190 #{$layoutID} .layout12 .rt-holder:hover .rt-detail,
1191 #{$layoutID} .isotope8 .rt-holder:hover .rt-detail,
1192 #{$layoutID} .carousel8 .rt-holder:hover .rt-detail,
1193 #{$layoutID} .layout13 .rt-holder .overlay .post-info,
1194 #{$layoutID} .isotope9 .rt-holder .overlay .post-info,
1195 #{$layoutID}.rt-tpg-container .layout4 .rt-holder .rt-detail,
1196 .rt-modal-{$id} .md-content,
1197 .rt-modal-{$id} .md-content > .rt-md-content-holder .rt-md-content,
1198 .rt-popup-wrap-{$id}.rt-popup-wrap .rt-popup-navigation-wrap,
1199 #{$layoutID} .carousel9 .rt-holder .overlay .post-info{";
1200 $css .= "background-color:" . $primaryColor . ";";
1201 $css .= "}";
1202
1203
1204 $ocp = Fns::rtHex2rgba( $primaryColor,
1205 ! empty( $scMeta['overlay_opacity'][0] ) ? absint( $scMeta['overlay_opacity'][0] ) / 10 : .8 );
1206 $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,
1207 #{$layoutID} .isotope12 .rt-holder h3, #{$layoutID} .carousel12 .rt-holder h3 {";
1208 $css .= "background-color:" . $ocp . ";";
1209 $css .= "}";
1210 }
1211
1212 if ( $button_border_color ) {
1213 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
1214 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item,
1215 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn,
1216 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action,
1217 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item,
1218 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap{";
1219 $css .= "border-color:" . $button_border_color . " !important;";
1220 $css .= "}";
1221 $css .= "#{$layoutID} .rt-holder .read-more a {";
1222 $css .= "border-color:" . $button_border_color . ";";
1223 $css .= "}";
1224 }
1225
1226 if ( $button_bg_color ) {
1227 $css .= "#{$layoutID} .pagination-list li a,
1228 {$layoutID} .pagination-list li span,
1229 {$layoutID} .pagination li a,
1230 #{$layoutID} .rt-tpg-isotope-buttons button,
1231 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button,
1232 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn,
1233 #{$layoutID}.rt-tpg-container .swiper-pagination-bullet,
1234 #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a,
1235 #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart,
1236 #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart,
1237 #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart,
1238 #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart,
1239 #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart,
1240 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown,
1241 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item,
1242 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a,
1243 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
1244 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn,
1245 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *,
1246 #{$layoutID} .rt-read-more,
1247 #rt-tooltip-{$id}, #rt-tooltip-{$id} .rt-tooltip-bottom:after{";
1248 $css .= "background-color:" . $button_bg_color . ";";
1249 $css .= "}";
1250 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
1251 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item{";
1252 $css .= "border-color:" . $button_bg_color . ";";
1253 $css .= "}";
1254 $css .= "#{$layoutID}.rt-tpg-container .layout17 .rt-holder .overlay a.tpg-zoom .fa{";
1255 $css .= "color:" . $button_bg_color . ";";
1256 $css .= "}";
1257
1258 $css .= "#{$layoutID} .rt-holder .read-more a {";
1259 $css .= "background-color:" . $button_bg_color . ";padding: 8px 15px;";
1260 $css .= "}";
1261 }
1262
1263 // button active color
1264 if ( $button_active_bg_color ) {
1265 $css .= "#{$layoutID} .pagination li.active span,
1266 #{$layoutID} .pagination-list li.active span,
1267 #{$layoutID} .rt-tpg-isotope-buttons button.selected,
1268 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected,
1269 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item.selected,
1270 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a,
1271 #{$layoutID}.rt-tpg-container .swiper-pagination-bullet.swiper-pagination-bullet-active-main{";
1272 $css .= "background-color:" . $button_active_bg_color . ";";
1273 $css .= "}";
1274
1275 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected,
1276 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item.selected,
1277 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a{";
1278 $css .= "border-color:" . $button_active_bg_color . ";";
1279 $css .= "}";
1280 }
1281
1282 // Button hover bg color
1283 if ( $button_hover_bg_color ) {
1284 $css .= "#{$layoutID} .pagination-list li a:hover,
1285 #{$layoutID} .pagination li a:hover,
1286 #{$layoutID} .rt-tpg-isotope-buttons button:hover,
1287 #{$layoutID} .rt-holder .read-more a:hover,
1288 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button:hover,
1289 #{$layoutID}.rt-tpg-container .swiper-pagination-bullet:hover,
1290 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover,
1291 #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a:hover,
1292 #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart:hover,
1293 #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart:hover,
1294 #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart:hover,
1295 #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart:hover,
1296 #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart:hover,
1297 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item:hover,
1298 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item.selected,
1299 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover,
1300 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover,
1301 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a:hover,
1302 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *:hover,
1303 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn:hover,
1304 #{$layoutID} .rt-read-more:hover,
1305 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button:hover{";
1306 $css .= "background-color:" . $button_hover_bg_color . ";";
1307 $css .= "}";
1308
1309 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover,
1310 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover,
1311 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover,
1312 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a:hover{";
1313 $css .= "border-color:" . $button_hover_bg_color . ";";
1314 $css .= "}";
1315 $css .= "#{$layoutID}.rt-tpg-container .layout17 .rt-holder .overlay a.tpg-zoom:hover .fa{";
1316 $css .= "color:" . $button_hover_bg_color . ";";
1317 $css .= "}";
1318 }
1319
1320 //Button text color
1321 if ( $button_text_color ) {
1322 $css .= "#{$layoutID} .pagination-list li a,
1323 #{$layoutID} .pagination li a,
1324 #{$layoutID} .rt-tpg-isotope-buttons button,
1325 #{$layoutID} .rt-holder .read-more a,
1326 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button,
1327 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn,
1328 #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a,
1329 #{$layoutID} .edd1 .rt-holder .rt-img-holder .overlay .product-more ul li a,
1330 #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart,
1331 #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart,
1332 #{$layoutID} .edd2 .rt-detail .rt-wc-add-to-cart,
1333 #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart,
1334 #{$layoutID} .edd3 .rt-detail .rt-wc-add-to-cart,
1335 #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart,
1336 #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart,
1337 #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button,
1338 #rt-tooltip-{$id},
1339 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item,
1340 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item,
1341 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action,
1342 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item,
1343 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a,
1344 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *,
1345 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn,
1346 #{$layoutID} .rt-read-more,
1347 #rt-tooltip-{$id} .rt-tooltip-bottom:after{";
1348 $css .= "color:" . $button_text_color . ";";
1349 $css .= "}";
1350 }
1351
1352 if ( $button_hover_text_color ) {
1353 $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover,
1354 #{$layoutID} .rt-holder .read-more a:hover,
1355 #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover,
1356 #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover,
1357 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item:hover,
1358 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item.selected,
1359 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action:hover,
1360 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a:hover,
1361 #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected,
1362 #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action,
1363 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn:hover,
1364 #{$layoutID} .rt-read-more:hover,
1365 #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a{";
1366 $css .= "color:" . $button_hover_text_color . ";";
1367 $css .= "}";
1368 }
1369
1370 if ( $overlay_color || $overlay_padding ) {
1371 if ( in_array( $layout, [ 'layout15', 'isotope11', 'carousel11' ] ) ) {
1372 $css .= "#{$layoutID} .{$layout} .rt-holder:hover .overlay .post-info{";
1373 } elseif ( in_array( $layout,
1374 [ 'layout10', 'isotope7', 'carousel6', 'carousel7', 'layout9', 'offset04' ] )
1375 ) {
1376 $css .= "#{$layoutID} .{$layout} .rt-holder .post-info{";
1377 } elseif ( in_array( $layout, [ 'layout7', 'isotope4', 'carousel4' ] ) ) {
1378 $css .= "#{$layoutID} .{$layout} .rt-holder .overlay:hover{";
1379 } elseif ( in_array( $layout, [ 'layout16', 'isotope12', 'carousel12' ] ) ) {
1380 $css .= "#{$layoutID} .{$layout} .rt-holder .overlay .post-info {";
1381 } elseif ( in_array( $layout, [ 'offset03', 'carousel5' ] ) ) {
1382 $css .= "#{$layoutID} .{$layout} .rt-holder .overlay{";
1383 } else {
1384 $css .= "#{$layoutID} .rt-post-overlay .post-img > a:first-of-type::after,";
1385 $css .= "#{$layoutID} .rt-holder .overlay:hover{";
1386 }
1387 if ( $overlay_color ) {
1388 $css .= "background-image: none;";
1389 $css .= "background-color:" . $overlay_color . ";";
1390 }
1391 if ( $overlay_padding ) {
1392 $css .= "padding-top:" . $overlay_padding . "%;";
1393 }
1394 $css .= "}";
1395 }
1396
1397 if ( $boxShadow ) {
1398 $css .= "#{$layoutID} .{$layout} .rt-holder {";
1399 $css .= "box-shadow : 0px 0px 2px 0px {$boxShadow};";
1400 $css .= "}";
1401 }
1402
1403 /* gutter */
1404 if ( $gutter ) {
1405 $css .= "#{$layoutID} [class*='rt-col-'] {";
1406 $css .= "padding-left : {$gutter}px !important;";
1407 $css .= "padding-right : {$gutter}px !important;";
1408 $css .= "margin-top : {$gutter}px;";
1409 $css .= "margin-bottom : {$gutter}px;";
1410 $css .= "}";
1411 $css .= "#{$layoutID} .rt-row{";
1412 $css .= "margin-left : -{$gutter}px !important;";
1413 $css .= "margin-right : -{$gutter}px !important;";
1414 $css .= "}";
1415 $css .= "#{$layoutID}.rt-container-fluid,#{$layoutID}.rt-container{";
1416 $css .= "padding-left : {$gutter}px;";
1417 $css .= "padding-right : {$gutter}px;";
1418 $css .= "}";
1419
1420 // remove inner row margin
1421 $css .= "#{$layoutID} .rt-row .rt-row [class*='rt-col-'] {";
1422 $css .= "margin-top : 0;";
1423 $css .= "}";
1424 }
1425
1426 // Read more button border radius
1427 if ( isset( $read_more_button_border_radius ) || trim( $read_more_button_border_radius ) !== '' ) {
1428 $css .= "#{$layoutID} .read-more a{";
1429 $css .= "border-radius:" . $read_more_button_border_radius . "px;";
1430 $css .= "}";
1431 }
1432
1433 // Section
1434 if ( $sectionBg ) {
1435 $css .= "#{$layoutID}.rt-tpg-container {";
1436 $css .= "background:" . $sectionBg . ";";
1437 $css .= "}";
1438 }
1439 if ( $sectionMargin ) {
1440 $css .= "#{$layoutID}.rt-tpg-container {";
1441 $css .= "margin:" . $sectionMargin . "px;";
1442 $css .= "}";
1443 }
1444 if ( $sectionPadding ) {
1445 $css .= "#{$layoutID}.rt-tpg-container {";
1446 $css .= "padding:" . $sectionPadding . "px;";
1447 $css .= "}";
1448 }
1449 // Box
1450 if ( $boxBg ) {
1451 $css .= "#{$layoutID} .rt-holder, #{$layoutID} .rt-holder .rt-detail,#{$layoutID} .rt-post-overlay .post-img + .post-content {";
1452 $css .= "background-color:" . $boxBg . ";";
1453 $css .= "}";
1454 }
1455 if ( $boxBorderColor ) {
1456 $css .= "#{$layoutID} .rt-holder {";
1457 $css .= "border-color:" . $boxBorderColor . ";";
1458 $css .= "}";
1459 }
1460 if ( $boxBorder ) {
1461 $css .= "#{$layoutID} .rt-holder {";
1462 $css .= "border-style: solid;";
1463 $css .= "border-width:" . $boxBorder . "px;";
1464 $css .= "}";
1465 }
1466 if ( $boxBorderRadius ) {
1467 $css .= "#{$layoutID} .rt-holder {";
1468 $css .= "border-radius:" . $boxBorderRadius . "px;";
1469 $css .= "}";
1470 }
1471 if ( $boxPadding ) {
1472 $css .= "#{$layoutID} .rt-holder {";
1473 $css .= "padding:" . $boxPadding . "px;";
1474 $css .= "}";
1475 }
1476 if ( $contentPadding ) {
1477 $css .= "#{$layoutID} .rt-holder .rt-detail {";
1478 $css .= "padding:" . $contentPadding . "px;";
1479 $css .= "}";
1480 }
1481 // Widget heading
1482 if ( $headingBg ) {
1483 $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 {";
1484 $css .= "background:" . $headingBg . ";";
1485 $css .= "}";
1486
1487 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading::after {";
1488 $css .= "border-top-color:" . $headingBg . ";";
1489 $css .= "}";
1490 }
1491 if ( $headingColor ) {
1492 $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 {";
1493 $css .= "color:" . $headingColor . ";";
1494 $css .= "}";
1495 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading::before {";
1496 $css .= "background-color:" . $headingColor . ";";
1497 $css .= "}";
1498 }
1499 if ( $headingBorderSize ) {
1500 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 {";
1501 // $css .= "border-bottom-style: solid;";
1502 $css .= "border-bottom-width:" . $headingBorderSize . "px;";
1503 $css .= "}";
1504
1505 $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading-line {";
1506 $css .= "border-width:" . $headingBorderSize . "px 0;";
1507 $css .= "}";
1508 }
1509 if ( $headingBorderColor ) {
1510 $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 {";
1511 $css .= "border-color:" . $headingBorderColor . ";";
1512 $css .= "}";
1513 }
1514 if ( $headingMargin ) {
1515 $css .= "#{$layoutID} .tpg-widget-heading-wrapper {";
1516 $css .= "margin:" . $headingMargin . "px;";
1517 $css .= "}";
1518 }
1519 if ( $headingPadding ) {
1520 $css .= "#{$layoutID} .tpg-widget-heading-wrapper .tpg-widget-heading {";
1521 $css .= "padding:" . $headingPadding . "px;";
1522 $css .= "}";
1523 }
1524 // Image border
1525 if ( isset( $image_border_radius ) || trim( $image_border_radius ) !== '' ) {
1526 $css .= "#{$layoutID} .rt-img-holder img.rt-img-responsive,#{$layoutID} .rt-img-holder,
1527 #{$layoutID} .rt-post-overlay .post-img,
1528 #{$layoutID} .post-sm .post-img,
1529 #{$layoutID} .rt-post-grid .post-img,
1530 #{$layoutID} .post-img img {";
1531 $css .= "border-radius:" . $image_border_radius . "px;";
1532 $css .= "}";
1533 }
1534
1535 // Title decoration
1536 if ( $title_color || $title_size || $title_weight || $title_alignment ) {
1537 $css .= "#{$layoutID} .{$layout} .rt-holder h2.entry-title,
1538 #{$layoutID} .{$layout} .rt-holder h3.entry-title,
1539 #{$layoutID} .{$layout} .rt-holder h4.entry-title,
1540 #{$layoutID} .{$layout} .rt-holder h2.entry-title a,
1541 #{$layoutID} .{$layout} .rt-holder h3.entry-title a,
1542 #{$layoutID} .{$layout} .rt-holder h4.entry-title a,
1543 #{$layoutID} .rt-holder .rt-woo-info h2 a,
1544 #{$layoutID} .rt-holder .rt-woo-info h3 a,
1545 #{$layoutID} .rt-holder .rt-woo-info h4 a,
1546 #{$layoutID} .post-content .post-title,
1547 #{$layoutID} .rt-post-grid .post-title,
1548 #{$layoutID} .rt-post-grid .post-title a,
1549 #{$layoutID} .post-content .post-title a,
1550 #{$layoutID} .rt-holder .rt-woo-info h2,
1551 #{$layoutID} .rt-holder .rt-woo-info h3,
1552 #{$layoutID} .rt-holder .rt-woo-info h4{";
1553 if ( $title_color ) {
1554 $css .= "color:" . $title_color . ";";
1555 }
1556 if ( $title_size ) {
1557 $lineHeight = $title_size + 10;
1558 $css .= "font-size:" . $title_size . "px;";
1559 $css .= "line-height:" . $lineHeight . "px;";
1560 }
1561 if ( $title_weight ) {
1562 $css .= "font-weight:" . $title_weight . ";";
1563 }
1564 if ( $title_alignment ) {
1565 $css .= "text-align:" . $title_alignment . ";";
1566 }
1567 $css .= "}";
1568 if ( $title_size ) {
1569 $css .= "#{$layoutID} .post-grid-lg-style-1 .post-title,
1570 #{$layoutID} .post-grid-lg-style-1 .post-title a,
1571 #{$layoutID} .big-layout .post-title,
1572 #{$layoutID} .big-layout .post-title a,
1573 #{$layoutID} .post-grid-lg-style-1 .post-title,
1574 #{$layoutID} .post-grid-lg-style-1 .post-title a {";
1575 $css .= "font-size:" . ( $title_size + 8 ) . "px;";
1576 $css .= "line-height:" . ( $lineHeight + 8 ) . "px;";
1577 $css .= "}";
1578 }
1579 }
1580 // Title hover color
1581 if ( $title_hover_color ) {
1582 $css .= "#{$layoutID} .{$layout} .rt-holder h2.entry-title:hover,
1583 #{$layoutID} .{$layout} .rt-holder h3.entry-title:hover,
1584 #{$layoutID} .{$layout} .rt-holder h4.entry-title:hover,
1585 #{$layoutID} .{$layout} .rt-holder h2.entry-title a:hover,
1586 #{$layoutID} .{$layout} .rt-holder h3.entry-title a:hover,
1587 #{$layoutID} .{$layout} .rt-holder h4.entry-title a:hover,
1588 #{$layoutID} .post-content .post-title a:hover,
1589 #{$layoutID} .rt-post-grid .post-title a:hover,
1590 #{$layoutID} .rt-holder .rt-woo-info h2 a:hover,
1591 #{$layoutID} .rt-holder .rt-woo-info h3 a:hover,
1592 #{$layoutID} .rt-holder .rt-woo-info h4 a:hover,
1593 #{$layoutID} .rt-holder .rt-woo-info h2:hover,
1594 #{$layoutID} .rt-holder .rt-woo-info h3:hover,
1595 #{$layoutID} .rt-holder .rt-woo-info h4:hover{";
1596 $css .= "color:" . $title_hover_color . " !important;";
1597 $css .= "}";
1598 }
1599 // Excerpt decoration
1600 if ( $excerpt_color || $excerpt_size || $excerpt_weight || $excerpt_alignment ) {
1601 $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 {";
1602 if ( $excerpt_color ) {
1603 $css .= "color:" . $excerpt_color . ";";
1604 }
1605 if ( $excerpt_size ) {
1606 $css .= "font-size:" . $excerpt_size . "px;";
1607 }
1608 if ( $excerpt_weight ) {
1609 $css .= "font-weight:" . $excerpt_weight . ";";
1610 }
1611 if ( $excerpt_alignment ) {
1612 $css .= "text-align:" . $excerpt_alignment . ";";
1613 }
1614 $css .= "}";
1615 }
1616 // Post meta decoration
1617 if ( $meta_data_color || $meta_data_size || $meta_data_weight || $meta_data_alignment ) {
1618 $css .= "#{$layoutID} .{$layout} .rt-holder .post-meta-user,
1619 #{$layoutID} .{$layout} .rt-meta,
1620 #{$layoutID} .{$layout} .rt-meta a,
1621 #{$layoutID} .{$layout} .rt-holder .post-meta-user .meta-data,
1622 #{$layoutID} .{$layout} .rt-holder .post-meta-user a,
1623 #{$layoutID} .{$layout} .rt-holder .rt-detail .post-meta .rt-tpg-social-share,
1624 #{$layoutID} .rt-post-overlay .post-meta-user span,
1625 #{$layoutID} .rt-post-overlay .post-meta-user,
1626 #{$layoutID} .rt-post-overlay .post-meta-user a,
1627 #{$layoutID} .rt-post-grid .post-meta-user,
1628 #{$layoutID} .rt-post-grid .post-meta-user a,
1629 #{$layoutID} .rt-post-box-media-style .post-meta-user,
1630 #{$layoutID} .rt-post-box-media-style .post-meta-user a,
1631 #{$layoutID} .{$layout} .post-meta-user i,
1632 #{$layoutID} .rt-detail .post-meta-category a,
1633 #{$layoutID} .{$layout} .post-meta-user a
1634 #{$layoutID} .{$layout} .post-meta-user a {";
1635 if ( $meta_data_color ) {
1636 $css .= "color:" . $meta_data_color . ";";
1637 }
1638 if ( $meta_data_size ) {
1639 $css .= "font-size:" . $meta_data_size . "px;";
1640 }
1641 if ( $meta_data_weight ) {
1642 $css .= "font-weight:" . $meta_data_weight . ";";
1643 }
1644 if ( $meta_data_alignment ) {
1645 $css .= "text-align:" . $meta_data_alignment . ";";
1646 }
1647 $css .= "}";
1648 }
1649 // Category
1650 if ( $catBg ) {
1651 $css .= "#{$layoutID} .cat-over-image.style2 .categories-links a,
1652 #{$layoutID} .cat-over-image.style3 .categories-links a,
1653 #{$layoutID} .cat-above-title.style2 .categories-links a,
1654 #{$layoutID} .cat-above-title.style3 .categories-links a,
1655 #{$layoutID} .rt-tpg-category > a {
1656 background-color: {$catBg};
1657 }";
1658
1659 $css .= "#{$layoutID} .cat-above-title.style3 .categories-links a:after,
1660 .cat-over-image.style3 .categories-links a:after,
1661 #{$layoutID} .rt-tpg-category > a,
1662 #{$layoutID} .rt-tpg-category.style3 > a:after {
1663 border-top-color: {$catBg} ;
1664 }";
1665
1666 $css .= "#{$layoutID} .rt-tpg-category:not(style1) i {
1667 color: {$catBg};
1668 }";
1669 }
1670 if ( $catTextColor ) {
1671 $css .= "#{$layoutID} .cat-over-image .categories-links a,
1672 #{$layoutID} .cat-above-title .categories-links a,
1673 #{$layoutID} .rt-tpg-category.style1 > i,
1674 #{$layoutID} .rt-tpg-category > a {";
1675 $css .= "color:" . $catTextColor . ";";
1676 $css .= "}";
1677 }
1678 if ( $catBorderRadius ) {
1679 $css .= "#{$layoutID} .cat-over-image .categories-links a,#{$layoutID} .cat-above-title .categories-links a,#{$layoutID} .rt-tpg-category > a{";
1680 $css .= "border-radius:" . $catBorderRadius . "px;";
1681 $css .= "}";
1682 }
1683 if ( $catPadding ) {
1684 $css .= "#{$layoutID} .cat-over-image .categories-links a,#{$layoutID} .cat-above-title .categories-links a,#{$layoutID} .rt-tpg-category > a{";
1685 $css .= "padding:" . $catPadding . "px;";
1686 $css .= "}";
1687 }
1688 if ( $catMargin ) {
1689 $css .= "#{$layoutID} .categories-links,#{$layoutID} .rt-tpg-category > a{";
1690 $css .= "margin:" . $catMargin . "px;";
1691 $css .= "}";
1692 }
1693 if ( $categorySize ) {
1694 $css .= "#{$layoutID} .categories-links,#{$layoutID} .rt-tpg-category > a {";
1695 $css .= "font-size:" . $categorySize . "px;";
1696 $css .= "}";
1697 }
1698
1699 $css .= "</style>";
1700
1701 return $css;
1702 }
1703
1704 public static function get_meta_keys( $post_type ) {
1705 // $cache = get_transient( 'tpg_' . $post_type . '_meta_keys' );
1706 // $meta_keys = $cache ? $cache : self::generate_meta_keys( $post_type );
1707 $meta_keys = self::generate_meta_keys( $post_type );
1708
1709 return $meta_keys;
1710 }
1711
1712 public static function generate_meta_keys( $post_type ) {
1713 $meta_keys = [];
1714 if ( $post_type ) {
1715 global $wpdb;
1716 $query = "SELECT DISTINCT($wpdb->postmeta.meta_key)
1717 FROM $wpdb->posts
1718 LEFT JOIN $wpdb->postmeta
1719 ON $wpdb->posts.ID = $wpdb->postmeta.post_id
1720 WHERE $wpdb->posts.post_type = '%s'
1721 AND $wpdb->postmeta.meta_key != ''
1722 AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)'
1723 AND $wpdb->postmeta.meta_key NOT RegExp '(^[0-9]+$)'";
1724 $meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
1725 // set_transient( 'tpg_' . $post_type . '_meta_keys', $meta_keys, 60 * 60 * 24 ); # create 1 Day Expiration
1726 }
1727
1728 return $meta_keys;
1729 }
1730
1731 public static function remove_all_shortcode( $content ) {
1732 return preg_replace( '#\[[^\]]+\]#', '', $content );
1733 }
1734
1735 public static function remove_divi_shortcodes( $content ) {
1736 $content = preg_replace( '/\[\/?et_pb.*?\]/', '', $content );
1737
1738 return $content;
1739 }
1740
1741 public static function is_acf() {
1742 $plugin = null;
1743 if ( class_exists( 'acf' ) ) {
1744 $plugin = 'acf';
1745 }
1746
1747 return $plugin;
1748 }
1749
1750 public static function get_groups_by_post_type( $post_type ) {
1751 $post_type = $post_type ? $post_type : "post";
1752 $groups = [];
1753 $plugin = self::is_acf();
1754 switch ( $plugin ) {
1755 case 'acf':
1756 $groups = self::get_groups_by_post_type_acf( $post_type );
1757 break;
1758 }
1759
1760 return $groups;
1761 }
1762
1763 /**
1764 * Get ACF post group
1765 *
1766 * @param $post_type
1767 *
1768 * @return array
1769 */
1770 public static function get_groups_by_post_type_acf( $post_type ) {
1771 $groups = [];
1772 $groups_q = get_posts( [ 'post_type' => 'acf-field-group', 'posts_per_page' => - 1 ] );
1773
1774 if ( ! empty( $groups_q ) ) {
1775 foreach ( $groups_q as $group ) {
1776 $c = $group->post_content ? unserialize( $group->post_content ) : [];
1777 $flag = false;
1778 if ( ! empty( $c['location'] ) ) {
1779 foreach ( $c['location'] as $rules ) {
1780 foreach ( $rules as $rule ) {
1781 if ( $post_type === 'all' ) {
1782 if ( ( ! empty( $rule['param'] ) && $rule['param'] == 'post_type' )
1783 && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' )
1784 ) {
1785 $flag = true;
1786 }
1787 } else {
1788 if ( ( ! empty( $rule['param'] ) && ( $rule['param'] == 'post_type' || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) )
1789 && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' )
1790 && ( ! empty( $rule['value'] ) && ( $rule['value'] == $post_type || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) )
1791
1792 ) {
1793 $flag = true;
1794 }
1795 }
1796 }
1797 }
1798 }
1799 if ( $flag ) {
1800 $groups[ $group->ID ] = $group->post_title;
1801 }
1802 }
1803 }
1804
1805 return $groups;
1806 }
1807
1808 /**
1809 * Get Post view count meta key
1810 *
1811 * @return string
1812 */
1813 public static function get_post_view_count_meta_key() {
1814 $count_key = 'tpg-post-view-count';
1815
1816 return $count_key;
1817 }
1818
1819
1820 /**
1821 * Elementor Functionality
1822 *************************************************
1823 */
1824
1825
1826 /**
1827 * Default layout style check
1828 *
1829 * @param $data
1830 *
1831 * @return bool
1832 */
1833 public static function el_ignore_layout( $data ) {
1834 if ( isset( $data['category'] ) && 'category' == $data['category'] ) {
1835 return true;
1836 }
1837 if ( 'default' == $data['category_position']
1838 && in_array( $data['layout'],
1839 [
1840 'grid-layout4',
1841 'grid-layout5',
1842 'grid-layout5-2',
1843 'grid-layout6',
1844 'grid-layout6-2',
1845 'list-layout4',
1846 'list-layout5',
1847 'grid_hover-layout5',
1848 'grid_hover-layout6',
1849 'grid_hover-layout7',
1850 'grid_hover-layout8',
1851 'grid_hover-layout9',
1852 'grid_hover-layout10',
1853 'grid_hover-layout5-2',
1854 'grid_hover-layout6-2',
1855 'grid_hover-layout7-2',
1856 'grid_hover-layout9-2',
1857 'slider-layout5',
1858 'slider-layout6',
1859 'slider-layout7',
1860 'slider-layout8',
1861 'slider-layout9',
1862 'slider-layout11',
1863 'slider-layout12',
1864 ] )
1865 ) {
1866 return false;
1867 }
1868
1869 return true;
1870 }
1871
1872 /**
1873 * Get Post Link
1874 *
1875 * @param $data
1876 * @param $pID
1877 *
1878 * @return array
1879 */
1880 public static function get_post_link( $pID, $data ) {
1881 $link_class = $link_start = $link_end = $readmore_link_start = $readmore_link_end = null;
1882 if ( 'default' == $data['post_link_type'] ) {
1883 $link_class = "tpg-post-link";
1884 $link_start = $readmore_link_start = sprintf( '<a data-id="%s" href="%s" class="%s" target="%s">',
1885 esc_attr( $pID ),
1886 esc_attr( esc_url( get_permalink() ) ),
1887 $link_class,
1888 $data['link_target'] );
1889 $link_end = $readmore_link_end = "</a>";
1890 } elseif ( 'popup' == $data['post_link_type'] ) {
1891 $link_class = "tpg-single-popup tpg-post-link";
1892 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
1893 $link_class = "tpg-post-link";
1894 }
1895 $link_start = $readmore_link_start = sprintf( '<a data-id="%s" href="%s" class="%s" target="%s">',
1896 esc_attr( $pID ),
1897 esc_url( get_permalink() ),
1898 $link_class,
1899 $data['link_target'] );
1900 $link_end = $readmore_link_end = "</a>";
1901 } elseif ( 'multi_popup' == $data['post_link_type'] ) {
1902 $link_class = "tpg-multi-popup tpg-post-link";
1903 $link_start = $readmore_link_start = sprintf( '<a data-id="%s" href="%s" class="%s" target="%s">',
1904 esc_attr( $pID ),
1905 esc_attr( esc_url( get_permalink() ) ),
1906 $link_class,
1907 $data['link_target'] );
1908 $link_end = $readmore_link_end = "</a>";
1909 } else {
1910 $link_class = "tpg-post-link";
1911 $readmore_link_start = sprintf( '<a data-id="%s" href="%s" class="%s" target="%s">',
1912 esc_attr( $pID ),
1913 esc_attr( esc_url( get_permalink() ) ),
1914 $link_class,
1915 $data['link_target'] );
1916 $readmore_link_end = "</a>";
1917 }
1918
1919 return [
1920 'link_start' => $link_start,
1921 'link_end' => $link_end,
1922 'readmore_link_start' => $readmore_link_start,
1923 'readmore_link_end' => $readmore_link_end,
1924 ];
1925 }
1926
1927 /**
1928 * Get Post Type
1929 *
1930 * @return string[]|\WP_Post_Type[]
1931 */
1932 public static function get_post_types() {
1933 $post_types = get_post_types( [ 'public' => true, 'show_in_nav_menus' => true ], 'objects' );
1934 $post_types = wp_list_pluck( $post_types, 'label', 'name' );
1935
1936 return array_diff_key( $post_types, [ 'elementor_library', 'attachment' ] );
1937 }
1938
1939 /**
1940 * Get Post Meta HTML for Elementor
1941 *
1942 * @param $post_id
1943 * @param $data
1944 *
1945 * @return html markup
1946 */
1947 public static function get_post_meta_html( $post_id, $data ) {
1948 global $post;
1949 $author_id = $post->post_author;
1950 $author_name = get_the_author_meta( 'display_name', $post->post_author );
1951 $author = apply_filters( 'rttpg_author_link', sprintf( '<a href="%s">%s</a>', get_author_posts_url( $author_id ), $author_name ) );
1952
1953 $comments_number = get_comments_number( $post_id );
1954
1955
1956 $comment_label = '';
1957 if ( isset( $data['show_comment_count_label'] ) && $data['show_comment_count_label'] ) {
1958 $comment_label = $data['comment_count_label_singular'];
1959 if ( $comments_number > 1 ) {
1960 $comment_label = $data['comment_count_label_plural'];
1961 }
1962 }
1963
1964 $comments_text = sprintf( '%s (%s)', esc_html( $comment_label ), number_format_i18n( $comments_number ) );
1965 $date = get_the_date();
1966
1967 //Category and Tags Management
1968 $_cat_id = isset( $data['post_type'] ) ? $data['post_type'] . '_taxonomy' : 'category';
1969 $_tag_id = isset( $data['post_type'] ) ? $data['post_type'] . '_tags' : 'post_tag';
1970 $categories = get_the_term_list( $post_id, $data[ $_cat_id ], null, '<span class="rt-separator">,</span>' );
1971 $tags = get_the_term_list( $post_id, $data[ $_tag_id ], null, '<span class="rt-separator">,</span>' );
1972
1973 $count_key = Fns::get_post_view_count_meta_key();
1974 $get_view_count = get_post_meta( $post_id, $count_key, true );
1975
1976 $meta_separator = ( $data['meta_separator'] && $data['meta_separator'] !== 'default' ) ? sprintf( "<span class='separator'>%s</span>", $data['meta_separator'] ) : null;
1977
1978 //Author Meta
1979
1980
1981 $post_meta_html = [];
1982
1983 ob_start();
1984 if ( '' !== $data['show_author'] ) {
1985 $is_author_avatar = null;
1986
1987 if ( '' !== $data['show_author_image'] ) {
1988 $is_author_avatar = 'has-author-avatar';
1989 }
1990 ?>
1991 <span class='author <?php echo esc_attr( $is_author_avatar ); ?>'>
1992
1993 <?php
1994 if ( '' !== $data['show_author_image'] ) {
1995 echo get_avatar( $author_id, 80 );
1996 } else {
1997 if ( $data['show_meta_icon'] === 'yes' ) {
1998 if ( isset( $data['user_icon']['value'] ) && $data['user_icon']['value'] ) {
1999 \Elementor\Icons_Manager::render_icon( $data['user_icon'], [ 'aria-hidden' => 'true' ] );
2000 } else {
2001 echo "<i class='fa fa-user'></i>";
2002 }
2003 }
2004 }
2005
2006 if ( $data['author_prefix'] ) {
2007 echo "<span class='author-prefix'>" . esc_html( $data['author_prefix'] ) . "</span>";
2008 }
2009 echo $author;
2010 ?>
2011 </span>
2012 <?php echo $meta_separator;
2013 }
2014
2015 $post_meta_html['author'] = ob_get_clean();
2016
2017 ob_start();
2018 //Category Meta
2019
2020 $category_condition = ( $categories && 'show' == $data['show_category'] && self::el_ignore_layout( $data )
2021 && in_array( $data['category_position'],
2022 [ 'default', 'with_meta' ] ) );
2023 if ( ! rtTPG()->hasPro() ) {
2024 $category_condition = ( $categories && 'show' == $data['show_category'] );
2025 }
2026
2027 if ( $category_condition ) { ?>
2028 <span class='categories-links'>
2029 <?php
2030 if ( $data['show_meta_icon'] === 'yes' ) {
2031 if ( isset( $data['cat_icon']['value'] ) && $data['cat_icon']['value'] ) {
2032 \Elementor\Icons_Manager::render_icon( $data['cat_icon'], [ 'aria-hidden' => 'true' ] );
2033 } else {
2034 echo "<i class='fa fa-user'></i>";
2035 }
2036 }
2037 echo $categories;
2038 ?>
2039 </span>
2040 <?php
2041 echo $meta_separator;
2042 }
2043 $post_meta_html['category'] = ob_get_clean();
2044
2045 ob_start();
2046 //Date Meta
2047 if ( '' !== $data['show_date'] ) {
2048 $archive_year = get_the_date( 'Y' );
2049 $archive_month = get_the_date( 'm' );
2050 $archive_day = get_the_date( 'j' );
2051
2052 ?>
2053 <span class='date'>
2054
2055 <?php
2056 if ( $data['show_meta_icon'] === 'yes' ) {
2057 if ( isset( $data['date_icon']['value'] ) && $data['date_icon']['value'] ) {
2058 \Elementor\Icons_Manager::render_icon( $data['date_icon'], [ 'aria-hidden' => 'true' ] );
2059 } else {
2060 echo "<i class='fa fa-user'></i>";
2061 }
2062 }
2063 ?>
2064 <a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>">
2065 <?php echo esc_html( $date ); ?>
2066 </a>
2067 </span>
2068 <?php
2069 echo $meta_separator;
2070 }
2071 $post_meta_html['date'] = ob_get_clean();
2072
2073
2074 ob_start();
2075 //Tags Meta
2076 if ( $tags && 'show' == $data['show_tags'] ) {
2077 ?>
2078 <span class='post-tags-links'>
2079 <?php
2080 if ( $data['show_meta_icon'] === 'yes' ) {
2081 if ( isset( $data['tag_icon']['value'] ) && $data['tag_icon']['value'] ) {
2082 \Elementor\Icons_Manager::render_icon( $data['tag_icon'], [ 'aria-hidden' => 'true' ] );
2083 } else {
2084 echo "<i class='fa fa-user'></i>";
2085 }
2086 }
2087 echo $tags;
2088 ?>
2089 </span>
2090 <?php
2091 echo $meta_separator;
2092 }
2093 $post_meta_html['tags'] = ob_get_clean();
2094
2095 ob_start();
2096 //Comment Meta
2097 if ( 'show' == $data['show_comment_count'] ) {
2098 ?>
2099 <span class="comment-count">
2100 <?php
2101 if ( $data['show_meta_icon'] === 'yes' ) {
2102 if ( isset( $data['comment_icon']['value'] ) && $data['comment_icon']['value'] ) {
2103 \Elementor\Icons_Manager::render_icon( $data['comment_icon'], [ 'aria-hidden' => 'true' ] );
2104 } else {
2105 echo "<i class='fa fa-user'></i>";
2106 }
2107 }
2108 echo $comments_text;
2109 ?>
2110 </span>
2111 <?php
2112 echo $meta_separator;
2113 }
2114
2115 $post_meta_html['comment_count'] = ob_get_clean();
2116
2117 ob_start();
2118 //Comment Meta
2119 if ( rtTPG()->hasPro() && 'show' == $data['show_post_count'] && ! empty( $get_view_count ) ) {
2120 ?>
2121 <span class="post-count">
2122 <?php
2123 if ( $data['show_meta_icon'] === 'yes' ) {
2124 if ( isset( $data['post_count_icon']['value'] ) && $data['post_count_icon']['value'] ) {
2125 \Elementor\Icons_Manager::render_icon( $data['post_count_icon'], [ 'aria-hidden' => 'true' ] );
2126 } else {
2127 echo "<i class='fa fa-eye'></i>";
2128 }
2129 }
2130 echo $get_view_count;
2131 ?>
2132 </span>
2133 <?php
2134 echo $meta_separator;
2135 }
2136
2137 $post_meta_html['post_count'] = ob_get_clean();
2138
2139 $meta_orering = isset( $data['meta_ordering'] ) && is_array( $data['meta_ordering'] ) ? $data['meta_ordering'] : [];
2140 foreach ( $meta_orering as $val ) {
2141 if ( isset( $post_meta_html[ $val['meta_name'] ] ) ) {
2142 echo $post_meta_html[ $val['meta_name'] ];
2143 }
2144 }
2145 }
2146
2147 /**
2148 * Custom wp_kses
2149 *
2150 * @param $string
2151 *
2152 * @return string
2153 */
2154 public static function wp_kses( $string ) {
2155 $allowed_html = [
2156 'a' => [
2157 'href' => [],
2158 'title' => [],
2159 'data-id' => [],
2160 'target' => [],
2161 'class' => [],
2162 ],
2163 'strong' => [],
2164 'b' => [],
2165 'br' => [ [] ],
2166 ];
2167
2168 return wp_kses( $string, $allowed_html );
2169 }
2170
2171
2172 /**
2173 * Get Elementor Post Title for Elementor
2174 *
2175 * @param $title_tag
2176 * @param $title
2177 * @param $link_start
2178 * @param $link_end
2179 * @param $data
2180 */
2181
2182 public static function get_el_post_title( $title_tag, $title, $link_start, $link_end, $data ) {
2183 echo '<div class="entry-title-wrapper">';
2184 if ( rtTPG()->hasPro() && 'above_title' === $data['category_position'] || ! self::el_ignore_layout( $data ) ) {
2185 self::get_el_thumb_cat( $data, 'cat-above-title' );
2186 }
2187 printf( '<%s class="entry-title">', esc_attr( $title_tag ) );
2188 echo self::wp_kses( $link_start );
2189 echo self::wp_kses( $title );
2190 echo self::wp_kses( $link_end );
2191 printf( '</%s>', esc_attr( $title_tag ) );
2192 echo '</div>';
2193 }
2194
2195 static function get_el_thumb_cat( $data, $class = 'cat-over-image' ) {
2196 if ( ! ( 'show' == $data['show_meta'] && 'show' == $data['show_category'] ) ) {
2197 return;
2198 }
2199 $pID = get_the_ID();
2200 $_cat_id = $data['post_type'] . '_taxonomy';
2201 $categories = get_the_term_list( $pID, $data[ $_cat_id ], null, '<span class="rt-separator">,</span>' );
2202 $category_position = $data['category_position'];
2203 if ( in_array( $data['layout'], [ 'grid-layout4' ] ) && 'default' === $data['category_position'] ) {
2204 $category_position = 'top_left';
2205 }
2206 ?>
2207 <div class="tpg-separate-category <?php echo esc_attr( $data['category_style'] . ' ' . $category_position . ' ' . $class ); ?>">
2208 <span class='categories-links'>
2209 <?php echo ( $data['show_cat_icon'] === 'yes' ) ? "<i class='fas fa-folder-open'></i>" : null; ?>
2210 <?php echo $categories; ?>
2211 </span>
2212 </div>
2213 <?php
2214 }
2215
2216
2217 /**
2218 * Get first image from the content
2219 *
2220 * @param $post_id
2221 * @param string $type
2222 *
2223 * @return mixed|string
2224 */
2225 public static function get_content_first_image( $post_id, $type = 'markup', $imgClass = '' ) {
2226 if ( $img = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
2227 get_the_content( $post_id ),
2228 $matches )
2229 ) {
2230 $imgSrc = $matches[1][0];
2231 $size = '';
2232
2233 $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc );
2234
2235 if ( file_exists( $imgAbs ) ) {
2236 $info = getimagesize( $imgAbs );
2237 $size = isset( $info[3] ) ? $info[3] : '';
2238 }
2239 $attachment_id = attachment_url_to_postid( $imgSrc );
2240 $alt_text = null;
2241 if ( ! empty( $attachment_id ) ) {
2242 $alt_text = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
2243 }
2244 $alt = $alt_text ? $alt_text : get_the_title( $post_id );
2245
2246 if ( $type == 'markup' ) {
2247 if ( $imgClass !== 'swiper-lazy' ) {
2248 return "<img class='rt-img-responsive' src='{$imgSrc}' {$size} alt='{$alt}'>";
2249 } else {
2250 return "<img class='{$imgClass}' data-src='{$imgSrc}' alt='{$alt}'>";
2251 }
2252 } else {
2253 return $imgSrc;
2254 }
2255 }
2256 }
2257
2258 /**
2259 * Get post thumbnail html
2260 *
2261 * @param $pID
2262 * @param $data
2263 * @param $link_start
2264 * @param $link_end
2265 * @param false $offset_size
2266 */
2267 public static function get_post_thumbnail( $pID, $data, $link_start, $link_end, $offset_size = false ) {
2268 $thumb_cat_condition = ( ! ( 'above_title' === $data['category_position'] || 'default' === $data['category_position'] ) );
2269 if ( 'grid-layout4' === $data['layout'] && 'default' === $data['category_position'] ) {
2270 $thumb_cat_condition = true;
2271 } elseif ( in_array( $data['layout'], [ 'grid-layout4',
2272 'grid_hover-layout11'
2273 ] ) && 'default' === $data['category_position'] ) {
2274 $thumb_cat_condition = true;
2275 }
2276
2277 if ( rtTPG()->hasPro() && $data['show_category'] == 'show' && $thumb_cat_condition && 'with_meta' !== $data['category_position'] ) {
2278 self::get_el_thumb_cat( $data );
2279 }
2280 $img_link = get_the_post_thumbnail_url( $pID, 'full' );
2281
2282 $img_size_key = 'image';
2283
2284
2285 if ( $offset_size ) {
2286 $img_size_key = 'image_offset';
2287 }
2288 $lazy_load = ( $data['prefix'] == 'slider' && $data['lazy_load'] == 'yes' ) ? true : false;
2289 $lazy_class = 'rt-img-responsive';
2290 if ( $lazy_load ) {
2291 $lazy_class = 'swiper-lazy';
2292 }
2293
2294 echo $data['is_thumb_linked'] === 'yes' ? self::wp_kses( $link_start ) : null;
2295 if ( has_post_thumbnail() && 'feature_image' === $data['media_source'] ) {
2296 $fImgSize = $data['image_size'];
2297 if ( $offset_size ) {
2298 echo get_the_post_thumbnail( $pID, $data['image_offset'] );
2299 } else {
2300 if ( $data['image_size'] !== 'custom' ) {
2301 $attachment_id = get_post_thumbnail_id( $pID );
2302 $thumb_info = wp_get_attachment_image_src( $attachment_id, $fImgSize );
2303 $thumb_alt = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
2304 if ( $lazy_load ) { ?>
2305 <img data-src="<?php echo esc_url( $thumb_info[0] ); ?>"
2306 src="#none"
2307 class="<?php echo esc_attr( $lazy_class ); ?>"
2308 width="<?php echo esc_attr( $thumb_info[1] ); ?>"
2309 height="<?php echo esc_attr( $thumb_info[2] ); ?>"
2310 alt="<?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ) ?>">
2311 <?php
2312 } else { ?>
2313 <img src="<?php echo esc_url( $thumb_info[0] ); ?>"
2314 class="<?php echo esc_attr( $lazy_class ); ?>"
2315 width="<?php echo esc_attr( $thumb_info[1] ); ?>"
2316 height="<?php echo esc_attr( $thumb_info[2] ); ?>"
2317 alt="<?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ) ?>">
2318 <?php
2319 }
2320 ?>
2321
2322 <?php
2323 } else {
2324 $fImgSize = 'rt_custom';
2325 $mediaSource = 'feature_image';
2326 $defaultImgId = null;
2327 $customImgSize = [];
2328
2329
2330 if ( isset( $data['image_custom_dimension'] ) ) {
2331 $post_thumb_id = get_post_thumbnail_id( $pID );
2332 $default_image_dimension = wp_get_attachment_image_src( $post_thumb_id, 'full' );
2333 if ( $default_image_dimension[1] <= $data['image_custom_dimension']['width'] || $default_image_dimension[2] <= $data['image_custom_dimension']['height'] ) {
2334 $customImgSize = [];
2335 } else {
2336 $customImgSize[0] = $data['image_custom_dimension']['width'];
2337 $customImgSize[1] = $data['image_custom_dimension']['height'];
2338 $customImgSize[2] = $data['img_crop_style'];
2339 }
2340 }
2341 echo Fns::getFeatureImageSrc( $pID, $fImgSize, $mediaSource, $defaultImgId, $customImgSize, $lazy_class );
2342 }
2343 }
2344 } elseif ( 'first_image' === $data['media_source'] && self::get_content_first_image( $pID ) ) {
2345 echo self::get_content_first_image( $pID, 'markup', $lazy_class );
2346 $img_link = self::get_content_first_image( $pID, 'url' );
2347 } elseif ( 'yes' === $data['is_default_img'] || 'grid_hover' == $data['prefix'] ) {
2348 echo \Elementor\Group_Control_Image_Size::get_attachment_image_html( $data, $img_size_key, 'default_image' );
2349 if ( ! empty( $data['default_image'] ) && isset( $data['default_image']['url'] ) ) {
2350 $img_link = $data['default_image']['url'];
2351 }
2352 }
2353
2354 ?>
2355 <?php if ( $lazy_load ) : ?>
2356 <div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
2357 <?php endif; ?>
2358
2359 <?php echo $data['is_thumb_linked'] === 'yes' ? self::wp_kses( $link_end ) : null; ?>
2360
2361 <?php if ( 'show' === $data['is_thumb_lightbox']
2362 || ( in_array( $data['layout'], [ 'grid-layout7',
2363 'slider-layout4'
2364 ] ) && in_array( $data['is_thumb_lightbox'], [ 'default', 'show' ] ) )
2365 ) :
2366 ?>
2367 <a class="tpg-zoom"
2368 data-elementor-open-lightbox="yes"
2369 data-elementor-lightbox-slideshow="<?php echo esc_attr( $data['layout'] ); ?>"
2370 title="<?php echo esc_attr( get_the_title() ); ?>"
2371 href="<?php echo esc_url( $img_link ) ?>">
2372 <i class="fa fa-plus" aria-hidden="true"></i>
2373 </a>
2374 <?php endif; ?>
2375 <div class="overlay grid-hover-content"></div>
2376 <?php
2377 }
2378
2379
2380 /**
2381 * Get ACF data for elementor
2382 *
2383 * @param $data
2384 * @param $pID
2385 *
2386 * @return bool
2387 */
2388 public static function tpg_get_acf_data_elementor( $data, $pID, $return_type = true ) {
2389 if ( ! ( rtTPG()->hasPro() && Fns::is_acf() ) ) {
2390 return;
2391 }
2392
2393 if ( isset( $data['show_acf'] ) && 'show' == $data['show_acf'] ) {
2394 $cf_group = $data['cf_group'];
2395
2396 $format = [
2397 'hide_empty' => ( isset( $data['cf_hide_empty_value'] ) && $data['cf_hide_empty_value'] ) ? 'yes' : '',
2398 'show_value' => ( isset( $data['cf_show_only_value'] ) && $data['cf_show_only_value'] ) ? '' : 'yes',
2399 'hide_group_title' => ( isset( $data['cf_hide_group_title'] ) && $data['cf_hide_group_title'] ) ? '' : 'yes',
2400 ];
2401
2402 if ( ! empty( $cf_group ) ) {
2403 $acf_html = "<div class='acf-custom-field-wrap'>";
2404 $acf_html .= Functions::get_cf_formatted_fields( $cf_group, $format, $pID );
2405 $acf_html .= "</div>";
2406 if ( $return_type ) {
2407 echo $acf_html;
2408 } else {
2409 return $acf_html;
2410 }
2411 }
2412 }
2413 }
2414
2415
2416 /**
2417 * Check is filter enable or not
2418 *
2419 * @param $data
2420 *
2421 * @return bool
2422 */
2423 public static function is_filter_enable( $data ) {
2424 if ( rtTPG()->hasPro()
2425 && ( $data['show_taxonomy_filter'] == 'show'
2426 || $data['show_author_filter'] == 'show'
2427 || $data['show_order_by'] == 'show'
2428 || $data['show_sort_order'] == 'show'
2429 || $data['show_search'] == 'show'
2430 || ( $data['show_pagination'] == 'show' && $data['pagination_type'] != 'pagination' ) )
2431 ) {
2432 return true;
2433 }
2434
2435 return false;
2436 }
2437
2438 }