Changeset 3009 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
- Timestamp:
- 04/26/2016 07:33:28 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r2994 r3009 10 10 11 11 /** 12 * @param \WP_Post|int $post Optional. 13 * @return int 14 */ 15 static function get_active_installs_count( $post = null ) { 12 * Returns a string representing the number of active installs for an item. 13 * 14 * @param bool $full whether to include "actuve installs" suffix. Default: true. 15 * @return string "1+ million" or "1+ milllion active installs" depending on $full. 16 */ 17 static function active_installs( $full = true, $post = null ) { 16 18 $post = get_post( $post ); 17 19 18 return (int) get_post_meta( $post->ID, 'active_installs', true ); 19 } 20 $count = get_post_meta( $post->ID, 'active_installs', true ); 21 22 if ( $count <= 10 ) { 23 $text = __( 'Less than 10', 'wporg-plugins' ); 24 } elseif ( $count >= 1000000 ) { 25 $text = __( '1+ million', 'wporg-plugins' ); 26 } else { 27 $text = number_format_i18n( $count ) . '+'; 28 } 29 return $full ? sprintf( __( '%s active installs', 'wporg-plugins' ), $text ) : $text; 30 } 31 20 32 21 33 /** … … 276 288 ) ); 277 289 } 290 291 /** 292 * A helper method to create dashicon stars. 293 * 294 * @type int|array { 295 * If numeric arg passed, assumed to be 'rating'. 296 * 297 * @type int $rating The rating to display. 298 * @type string $template The HTML template to use for each star. 299 * %1$s is the class, %2$s is the rating. 300 * } 301 * @return string The Rating HTML. 302 */ 303 static function dashicons_stars( $args = array() ) { 304 $defaults = array( 305 'rating' => 0, 306 'template' => '<span class="%1$s"></span>' 307 ); 308 $r = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), $defaults ); 309 310 $rating = round( $r['rating'] / 0.5 ) * 0.5; 311 $template = $r['template']; 312 $title_template = __( '%s out of 5 stars', 'wporg-plugins' ); 313 $title = sprintf( $title_template, $rating ); 314 315 $output = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">'; 316 $counter = round( $rating * 2 ); 317 for ( $i = 1; $i <= 5; $i++ ) { 318 switch ($counter) { 319 case 0: 320 $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i ); 321 break; 322 case 1: 323 $output .= sprintf( $template, 'dashicons dashicons-star-half', $i ); 324 $counter--; 325 break; 326 default: 327 $output .= sprintf( $template, 'dashicons dashicons-star-filled', $i ); 328 $counter -= 2; 329 break; 330 } 331 } 332 $output .= '</div>'; 333 return $output; 334 } 335 278 336 }
Note: See TracChangeset
for help on using the changeset viewer.