Skip to content

Commit

Permalink
support-forums: Replace ratings bars/stars with shared component.
Browse files Browse the repository at this point in the history
See: WordPress#408


git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14173 74240141-8908-4e6f-9713-ba540dce6ec7
  • Loading branch information
StevenDufresne committed Nov 14, 2024
1 parent de01b7a commit fb9f9ed
Showing 1 changed file with 13 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,65 +212,9 @@ public function do_view_header() {
add_filter( 'bbp_get_topic_last_topic_title', array( $this, 'undo_topic_title' ), 10, 1 );
?>
<div class="review-ratings">
<div class="col-3">
<div class="reviews-about" style="display:none;"><?php echo esc_html( $this->object->post_title ); ?></div>
<div class="reviews-total-count"><?php
printf(
/* translators: %s: number of reviews */
_n( '%s review', '%s reviews', $this->reviews_count, 'wporg-forums' ),
'<span>' . number_format_i18n( $this->reviews_count ) . '</span>'
);
?></div>
<?php
foreach ( array( 5, 4, 3, 2, 1 ) as $rating ) {
$ratings_count = isset( $this->ratings_counts[ $rating ] ) ? $this->ratings_counts[ $rating ] : 0;
$ratings_count_total = isset( $this->ratings_counts ) ? array_sum( $this->ratings_counts) : 0;
$stars_title = sprintf(
/* translators: %s: number of stars */
_n(
'Click to see reviews that provided a rating of %d star',
'Click to see reviews that provided a rating of %d stars',
$rating,
'wporg-forums'
),
$rating
);
/* translators: %d: number of stars */
$stars_text = sprintf(
/* translators: %d: number of stars */
_n( '%d star', '%d stars', $rating, 'wporg-forums' ),
$rating
);
$width = 0;
if ( $ratings_count && $ratings_count_total ) {
$width = 100 * ( $ratings_count / $ratings_count_total );
}
?>
<div class="counter-container">
<a href="<?php echo esc_url( sprintf( home_url( '/%s/%s/reviews/?filter=%s' ), $this->compat, $this->slug, $rating ) ); ?>"
title="<?php echo esc_attr( $stars_title ); ?>">
<span class="counter-label" style="float:left;margin-right:5px;min-width:58px;"><?php echo esc_html( $stars_text ); ?></span>
<span class="counter-back" style="height:17px;width:100px;background-color:#ececec;float:left;">
<span class="counter-bar" style="width:<?php echo esc_attr( $width ); ?>px;height:17px;background-color:#ffc733;float:left;"></span>
</span>
</a>
<span class="counter-count" style="margin-left:5px;"><?php echo esc_html( number_format_i18n( $ratings_count ) ); ?></span>
</div>
<?php
}
?>
</div>
<div class="col-5">
<div>
<div style="font-weight:bold;"><?php _e( 'Average Rating', 'wporg-forums' ); ?></div>
<?php
echo \WPORG_Ratings::get_dashicons_stars( $this->avg_rating );
printf(
/* translators: 1: number of stars in rating, 2: total number of stars (5) */
__( '%1$s out of %2$s stars', 'wporg-forums' ),
round( isset( $this->avg_rating ) ? $this->avg_rating : 0, 1 ),
'<span>5</span>'
);
?>
<?php echo do_blocks( '<!-- wp:wporg/ratings-stars /-->' ); ?>
<div class="reviews-submit-link">
<?php
if ( is_user_logged_in() ) {
Expand All @@ -297,6 +241,17 @@ public function do_view_header() {
?>
</div>
</div>
<div>
<div class="reviews-about" style="display:none;"><?php echo esc_html( $this->object->post_title ); ?></div>
<div class="reviews-total-count"><?php
printf(
/* translators: %s: number of reviews */
_n( '%s review', '%s reviews', $this->reviews_count, 'wporg-forums' ),
'<span>' . number_format_i18n( $this->reviews_count ) . '</span>'
);
?></div>
<?php echo do_blocks( '<!-- wp:wporg/ratings-bars /-->' ); ?>
</div>
</div>
<?php
// If current listing is filtered by rating, display message indicating this,
Expand Down

0 comments on commit fb9f9ed

Please sign in to comment.