'', 'star-empty' => ' ', 'star-half' => '', 'star-full' => '', 'x' => '', ); return apply_filters( 'affreviews_svg_icons', $icons ); } } /** * Review rating. */ if ( ! function_exists( 'affreviews_get_rating' ) ) { function affreviews_get_rating( $post_id ) { if ( ! $post_id ) { return; } $html = ''; $count = 0; $rating_num = affreviews_get_rating_num( $post_id ); $half_icon = apply_filters( 'affreviews_rating_half_icon', true ); $icons = affreviews_svg_icons(); if ( ! $rating_num ) { return 'No rating available.'; } $html .= '
'; $rest = 5 - $rating_num; while ( $count < floor( $rating_num ) ) { $html .= $icons['star-full']; $count++; } if ( $rest > 0 ) { $count = 0; while ( $count < $rest ) { $dec = $rating_num - floor( $rating_num ); if ( $half_icon ) { if ( 0.7 > $dec && 0.3 < $dec && is_float( $rest ) && 0 == $count ) { $html .= $icons['star-half']; } elseif ( 0.7 <= $dec && is_float( $rest ) && 0 == $count ) { $html .= $icons['star-full']; } else { $html .= $icons['star-empty']; } } else { if ( $dec >= 0.6 && is_float( $rest ) && 0 === $count ) { $html .= $icons['star-full']; } else { $html .= $icons['star-empty']; } } $count++; } } $html .= '
'; return apply_filters( 'affreviews_rating_html', $html ); } } /** * Return affiliate rating number */ if ( ! function_exists( 'affreviews_get_rating_num' ) ) { function affreviews_get_rating_num( $post_id ) { if ( ! $post_id ) { return; } $rating_num = (float) get_post_meta( $post_id, 'affreviews_rating', true ); return $rating_num; } } /** * Extend ruleset of wp_kses for SVG icons * * @return void */ if ( ! function_exists( 'affreviews_kses_extended_ruleset' ) ) { function affreviews_kses_extended_ruleset() { $kses_defaults = wp_kses_allowed_html( 'post' ); $svg_args = array( 'svg' => array( 'class' => true, 'aria-hidden' => true, 'aria-labelledby' => true, 'role' => true, 'xmlns' => true, 'width' => true, 'height' => true, 'viewbox' => true, // <= Must be lower case! ), 'g' => array( 'fill' => true ), 'title' => array( 'title' => true ), 'path' => array( 'd' => true, 'fill' => true, ), ); return array_merge( $kses_defaults, $svg_args ); } } /** * Review thumbnail element * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_thumb' ) ) { function affreviews_get_thumb( $post_id, $atts = array() ) { if ( ! $post_id ) { return; } if ( ! has_post_thumbnail( $post_id ) ) { return; } $link = affreviews_get_review_link_url( $post_id ); $classes = ''; $css_vars = ''; $image = ''; $pre_image_html = $link ? '' : ''; $post_image_html = $link ? '' : ''; if ( in_array( 'logo-box', $atts, true ) || in_array( 'logo-circle', $atts, true ) ) { $background_color = get_post_meta( $post_id, 'affreviews_logo_background_color', true ); if ( in_array( 'logo-circle', $atts, true ) ) { $classes .= ' affr-thumb--circle'; $pre_image_html .= '
'; $post_image_html = '
' . $post_image_html; } elseif ( in_array( 'logo-box', $atts, true ) ) { $classes .= ' affr-thumb--box'; } if ( $background_color && '' !== $background_color ) { $css_vars = '--affr-logo-background-color: ' . $background_color . ';'; } $image = get_the_post_thumbnail( $post_id, 'affreviews-logo' ); } else { $image = get_the_post_thumbnail( $post_id, 'affreviews-product' ); } $output = '
'; $output .= $pre_image_html; $output .= $image; $output .= $post_image_html; $output .= '
'; return $output; } } /** * Review pros list * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_pros' ) ) { function affreviews_get_pros( $post_id, $num = 999999 ) { if ( ! $post_id ) { return; } $positives = get_post_meta( $post_id, 'affreviews_positives', false ); $output = ''; $icons = affreviews_svg_icons(); if ( ! $positives ) { return; } $output .= '
'; $output .= ''; $output .= '
'; return $output; } } /** * Review cons list * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_cons' ) ) { function affreviews_get_cons( $post_id, $num = 999999 ) { if ( ! $post_id ) { return; } $negatives = get_post_meta( $post_id, 'affreviews_negatives', false ); $output = ''; $icons = affreviews_svg_icons(); if ( ! $negatives ) { return; } $output .= '
'; $output .= ''; $output .= '
'; return $output; } } /** * Review infolist * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_infolist' ) ) { function affreviews_get_infolist( $post_id ) { if ( ! $post_id ) { return; } $infolist = get_post_meta( $post_id, 'affreviews_group_info_list', false ); $output = ''; $icons = affreviews_svg_icons(); if ( ! isset( $infolist[0] ) ) { return; } $output .= '
'; $output .= ''; $output .= '
'; return $output; } } /** * Review title * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_title' ) ) { function affreviews_get_title( $post_id ) { if ( ! $post_id ) { return; } $output = '
'; $output .= get_the_title( $post_id ); $output .= '
'; return $output; } } /** * Review bonus * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_bonus' ) ) { function affreviews_get_bonus( $post_id ) { if ( ! $post_id ) { return; } $affbonus = get_post_meta( $post_id, 'affreviews_bonus', true ); if ( empty( $affbonus ) ) { return; } $output = '
'; $output .= '

' . $affbonus . '

'; $output .= '
'; return $output; } } /** * Review link * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_review_link' ) ) { function affreviews_get_review_link( $post_id, $review_link_text = null ) { if ( ! $post_id ) { return; } $link = affreviews_get_review_link_url( $post_id ); if ( ! $link ) { return; } $review_link_text = $review_link_text ?? __( 'Read Review', 'affreviews' ); $output = ''; return $output; } } /** * Review link URL * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_review_link_url' ) ) { function affreviews_get_review_link_url( $post_id ) { if ( ! $post_id ) { return; } $settings = get_option( 'affreviews_general_settings' ); $affreviews_afflink = get_post_meta( $post_id, 'affreviews_review_link', true ); if ( isset( $settings['reviews_visibility'] ) && 'visible' === $settings['reviews_visibility'] ) { return get_permalink( $post_id ); } elseif ( $affreviews_afflink ) { return $affreviews_afflink; } else { return; } } } /** * Review counter * * @param [int] $count * @return void */ if ( ! function_exists( 'affreviews_get_review_count' ) ) { function affreviews_get_review_count( $count ) { if ( ! $count ) { return; } $output = '
'; $output .= $count; $output .= '
'; return $output; } } /** * Review tag * * @param [int] $count * @return void */ if ( ! function_exists( 'affreviews_get_tag' ) ) { function affreviews_get_tag( $post_id ) { if ( ! $post_id ) { return; } $affreviews_tag_text = get_post_meta( $post_id, 'affreviews_tag_text', true ); $affreviews_tag_background_color = get_post_meta( $post_id, 'affreviews_tag_background_color', true ); $affreviews_text_color = ''; $css = ''; if ( empty( $affreviews_tag_text ) ) { return; } if ( isset( $affreviews_tag_background_color ) && ! empty( $affreviews_tag_background_color ) ) { $affreviews_text_color = affreviews_get_contrast_color( $affreviews_tag_background_color ); $css = "--affr-tag-text-color:{$affreviews_text_color};--affr-tag-background-color:{$affreviews_tag_background_color};"; } $output = '
'; $output .= $affreviews_tag_text; $output .= '
'; return $output; } } /** * Get contrast color based on background color * * @param [int] $hex_color * @return void */ if ( ! function_exists( 'affreviews_get_contrast_color' ) ) { function affreviews_get_contrast_color( $hex_color ) { // hex_color RGB $r1 = hexdec( substr( $hex_color, 1, 2 ) ); $g1 = hexdec( substr( $hex_color, 3, 2 ) ); $b1 = hexdec( substr( $hex_color, 5, 2 ) ); // Black RGB $blackcolor = '#000000'; $r2blackcolor = hexdec( substr( $blackcolor, 1, 2 ) ); $g2blackcolor = hexdec( substr( $blackcolor, 3, 2 ) ); $b2blackcolor = hexdec( substr( $blackcolor, 5, 2 ) ); // Calc contrast ratio $l1 = 0.2126 * pow( $r1 / 255, 2.2 ) + 0.7152 * pow( $g1 / 255, 2.2 ) + 0.0722 * pow( $b1 / 255, 2.2 ); $l2 = 0.2126 * pow( $r2blackcolor / 255, 2.2 ) + 0.7152 * pow( $g2blackcolor / 255, 2.2 ) + 0.0722 * pow( $b2blackcolor / 255, 2.2 ); $contrastratio = 0; if ( $l1 > $l2 ) { $contrastratio = (int) ( ( $l1 + 0.05 ) / ( $l2 + 0.05 ) ); } else { $contrastratio = (int) ( ( $l2 + 0.05 ) / ( $l1 + 0.05 ) ); } // If contrast is more than 5, return black color if ( $contrastratio > 5 ) { return '#000000'; } else { // if not, return white color. return '#FFFFFF'; } } } /** * Review affiliate button * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_aff_button' ) ) { function affreviews_get_aff_button( $post_id, $button_text = null ) { if ( ! $post_id ) { return; } $button_text = $button_text ?? __( 'Check Best Deals', 'affreviews' ); $afflink = get_post_meta( $post_id, 'affreviews_afflink', true ); if ( empty( $afflink ) ) { return; } $button_atts = apply_filters( 'affreviews_aff_button_atts', 'target="_blank" rel="nofollow"' ); $output = '
'; $output .= '' . $button_text; $output .= '
'; return $output; } } /** * Review terms * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_terms' ) ) { function affreviews_get_terms( $post_id ) { if ( ! $post_id ) { return; } $terms = get_post_meta( $post_id, 'affreviews_terms', true ); if ( empty( $terms ) ) { return; } $output = '
'; $output .= '

' . nl2br( $terms ) . '

'; $output .= '
'; return $output; } } /** * Review description * * @param [type] $post_id * @return void */ if ( ! function_exists( 'affreviews_get_description' ) ) { function affreviews_get_description( $post_id ) { if ( ! $post_id ) { return; } $descr = get_post_meta( $post_id, 'affreviews_description', true ); if ( empty( $descr ) ) { return; } $output = '
'; $output .= '

' . nl2br( $descr ) . '

'; $output .= '
'; return $output; } } /** * Set CSS variables to the head * * @return void */ if ( ! function_exists( 'affreviews_register_css_vars' ) ) { function affreviews_register_css_vars( $plugin_name = 'affreviews' ) { $settings = get_option( 'affreviews_visual_settings' ); if ( empty( $settings ) ) { return; } $css = ':root {'; $css .= isset( $settings['button_color'] ) ? "--affr-button-color:{$settings['button_color']};" : ''; $css .= isset( $settings['button_text_color'] ) ? "--affr-button-text-color:{$settings['button_text_color']};" : ''; $css .= isset( $settings['button_radius'] ) ? "--affr-button-radius:{$settings['button_radius']};" : ''; $css .= isset( $settings['button_font_weight'] ) ? "--affr-button-font-weight:{$settings['button_font_weight']};" : ''; $css .= isset( $settings['button_font_size'] ) ? "--affr-button-font-size:{$settings['button_font_size']};" : ''; $css .= isset( $settings['button_padding'] ) ? "--affr-button-padding:{$settings['button_padding']['top']} {$settings['button_padding']['left']} {$settings['button_padding']['bottom']} {$settings['button_padding']['right']};" : ''; $css .= isset( $settings['secondary_color'] ) ? "--affr-secondary-color:{$settings['secondary_color']};" : ''; $css .= isset( $settings['rating_color'] ) ? "--affr-rating-color:{$settings['rating_color']};" : ''; $css .= isset( $settings['link_color'] ) ? "--affr-link-color:{$settings['link_color']};" : ''; $css .= isset( $settings['box_bg_color'] ) ? "--affr-box-bg-color:{$settings['box_bg_color']};" : ''; $css .= isset( $settings['text_color'] ) ? "--affr-text-color:{$settings['text_color']};" : ''; $css .= '}'; wp_add_inline_style( $plugin_name, $css ); } }