⭐'; } } if ( ! function_exists( 'jetpack_rating_star_get_symbol_high_fidelity' ) ) { /** * Return the high fidelity symbol for the block. * * @param string $classname_whole Name of the whole symbol class. * @param string $classname_half Name of the half symbol class. * @param string $color Color of the block. * * @return string */ function jetpack_rating_star_get_symbol_high_fidelity( $classname_whole, $classname_half, $color ) { return << ELO; } } if ( ! function_exists( 'jetpack_rating_meta_get_symbol_high_fidelity' ) ) { /** * Returns the high fidelity symbol for the block. * * @param array $attributes Array containing the block attributes. * @param integer $pos Value to render whole and half symbols. * @return string */ function jetpack_rating_meta_get_symbol_high_fidelity( $attributes, $pos ) { $classname_whole = ( $attributes['rating'] >= ( $pos - 0.5 ) ) ? '' : 'is-rating-unfilled'; $classname_half = ( $attributes['rating'] >= $pos ) ? '' : 'is-rating-unfilled'; $color = empty( $attributes['color'] ) ? 'currentColor' : esc_attr( $attributes['color'] ); return jetpack_rating_star_get_symbol_high_fidelity( $classname_whole, $classname_half, $color ); } } if ( ! function_exists( 'jetpack_rating_get_schema_for_symbol' ) ) { /** * Returns an itemprop and content for rating symbols * * @param integer $position the position of the symbol. * @param integer $max_rating the maximum symbol score. * * @return string */ function jetpack_rating_get_schema_for_symbol( $position, $max_rating ) { $schema = ''; if ( 1 === $position ) { $schema = 'itemprop="worstRating" content="0.5"'; } elseif ( $max_rating === $position ) { $schema = 'itemprop="bestRating" content="' . esc_attr( $max_rating ) . '"'; } return $schema; } } if ( ! function_exists( 'jetpack_rating_meta_get_symbols' ) ) { /** * Returns the symbol for the block. * * @param array $attributes Array containing the block attributes. * * @return string */ function jetpack_rating_meta_get_symbols( $attributes ) { // Output SVGs for high fidelity contexts, then color them according to rating. // These are hidden by default, then unhid when CSS loads. $symbols_hifi = array(); for ( $pos = 1; $pos <= $attributes['maxRating']; $pos++ ) { $symbols_hifi[] = '' . jetpack_rating_meta_get_symbol_high_fidelity( $attributes, $pos ) . ''; } // Output fallback symbols for low fidelity contexts, like AMP, // where CSS is not loaded so the high-fidelity symbols won't be rendered. $symbols_lofi = ''; for ( $i = 0; $i < $attributes['rating']; $i++ ) { $symbols_lofi .= jetpack_rating_meta_get_symbol_low_fidelity(); } return '

' . $symbols_lofi . '

' . implode( $symbols_hifi ); } } if ( ! function_exists( 'jetpack_rating_meta_render_block' ) ) { /** * Dynamic rendering of the block. * * @param array $attributes Array containing the block attributes. * * @return string */ function jetpack_rating_meta_render_block( $attributes ) { $classname = empty( $attributes['className'] ) ? '' : ' ' . $attributes['className']; return sprintf( '
%2$s%3$s
', esc_attr( 'wp-block-jetpack-rating-' . $attributes['ratingStyle'] . $classname ), jetpack_rating_meta_get_symbols( $attributes ), // translators: %1$s is awarded rating score, %2$s is the best possible rating. '' . sprintf( __( 'Rating: %1$s out of %2$s.', 'jetpack' ), esc_attr( $attributes['rating'] ), esc_attr( $attributes['maxRating'] ) ) . '', ( isset( $attributes['align'] ) ) ? esc_attr( $attributes['align'] ) : '' ); } }