Changeset 3511 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
- Timestamp:
- 06/20/2016 05:34:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r3495 r3511 12 12 * Returns a string representing the number of active installs for an item. 13 13 * 14 * @param bool $full Whether to include "active installs" suffix. Default: true. 14 * @static 15 * 16 * @param bool $full Optional. Whether to include "active installs" suffix. Default: true. 15 17 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 16 18 * @return string "1+ million" or "1+ million active installs" depending on $full. 17 19 */ 18 static function active_installs( $full = true, $post = null ) { 19 $post = get_post( $post ); 20 20 public static function active_installs( $full = true, $post = null ) { 21 $post = get_post( $post ); 21 22 $count = get_post_meta( $post->ID, 'active_installs', true ); 22 23 … … 28 29 $text = number_format_i18n( $count ) . '+'; 29 30 } 31 30 32 return $full ? sprintf( __( '%s active installs', 'wporg-plugins' ), $text ) : $text; 31 33 } 32 34 33 34 /** 35 * @param \WP_Post|int $post Optional. 35 /** 36 * Returns the number of downloads for a plugin. 37 * 38 * @static 39 * @global \wpdb $wpdb WordPress database abstraction object. 40 * 41 * @param int|\WP_Post|null $post Optional. 36 42 * @return int 37 43 */ 38 static function get_downloads_count( $post = null ) {44 public static function get_downloads_count( $post = null ) { 39 45 $post = get_post( $post ); 40 46 … … 52 58 53 59 /** 60 * Returns the cumulative number of downloads of all plugins. 61 * 62 * @static 63 * @global \wpdb $wpdb WordPress database abstraction object. 64 * 54 65 * @return int 55 66 */ 56 static function get_total_downloads() {67 public static function get_total_downloads() { 57 68 if ( false === ( $count = wp_cache_get( 'plugin_download_count', 'plugin_download_count' ) ) ) { 58 69 global $wpdb; … … 67 78 /** 68 79 * Displays a plugin's rating with the amount of ratings it has received. 80 * 81 * @static 69 82 * 70 83 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. … … 87 100 88 101 /** 102 * Returns the available sections for a plugin. 103 * 104 * @static 105 * 89 106 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 90 107 * @return array 91 108 */ 92 static function get_plugin_sections( $post = null ) {109 public static function get_plugin_sections( $post = null ) { 93 110 $plugin = get_post( $post ); 94 111 $plugin_slug = $plugin->post_name; … … 109 126 $raw_sections = array_unique( array_merge( $raw_sections, $default_sections ) ); 110 127 111 $sections 112 $title = $url = '';113 $permalink 128 $sections = array(); 129 $title = $url = ''; 130 $permalink = get_permalink(); 114 131 115 132 foreach ( $raw_sections as $section_slug ) { … … 183 200 * Retrieve the Plugin Icon details for a plugin. 184 201 * 202 * @static 203 * 185 204 * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug. 186 * @param string $output O utput type. 'html' or 'raw'. Default: 'raw'.205 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'. 187 206 * @return mixed 188 207 */ 189 static function get_plugin_icon( $plugin, $output = 'raw' ) {208 public static function get_plugin_icon( $plugin, $output = 'raw' ) { 190 209 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 191 210 if ( ! $plugin ) { … … 209 228 /* false = the resolution of the icon, this is NOT disabled */ 210 229 case false && 'icon.svg' == $file: 211 $svg 230 $svg = self::get_asset_url( $plugin_slug, $info ); 212 231 break; 213 232 } … … 226 245 // Use the average color of the first known banner as the icon background color 227 246 if ( $color = get_post_meta( $plugin->ID, 'assets_banners_color', true ) ) { 228 if ( strlen( $color ) == 6 && strspn( $color, 'abcdef0123456789' )== 6 ) {247 if ( strlen( $color ) === 6 && strspn( $color, 'abcdef0123456789' ) === 6 ) { 229 248 $icon->setColor( '#' . $color ); 230 249 } … … 236 255 switch ( $output ) { 237 256 case 'html': 238 $id = "plugin-icon-{$plugin_slug}";239 $html = "<style type='text/css'>";257 $id = "plugin-icon-{$plugin_slug}"; 258 $html = "<style type='text/css'>"; 240 259 $html .= "#{$id} { background-image: url('{$icon}'); } .plugin-icon { background-size: 128px 128px; height: 128px; width: 128px; }"; 241 260 if ( ! empty( $icon_2x ) && ! $generated ) { … … 257 276 * Retrieve the Plugin Icon details for a plugin. 258 277 * 278 * @static 279 * 259 280 * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug. 260 * @param string $output O utput type. 'html' or 'raw'. Default: 'raw'.281 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'. 261 282 * @return mixed 262 283 */ 263 static function get_plugin_banner( $plugin, $output = 'raw' ) {284 public static function get_plugin_banner( $plugin, $output = 'raw' ) { 264 285 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 265 286 if ( ! $plugin ) { … … 267 288 } 268 289 269 $banner = $banner_2x = false;290 $banner = $banner_2x = false; 270 291 $plugin_slug = $plugin->post_name; 271 292 $raw_banners = get_post_meta( $plugin->ID, 'assets_banners', true ); 272 293 273 294 // Split in rtl and non-rtl banners. 274 $rtl_banners = array_filter( $raw_banners, function ( $info ) {295 $rtl_banners = array_filter( $raw_banners, function ( $info ) { 275 296 return (bool) stristr( $info['filename'], '-rtl' ); 276 297 } ); … … 310 331 switch ( $output ) { 311 332 case 'html': 312 $id = "plugin-banner-{$plugin_slug}";313 $html = "<style type='text/css'>";333 $id = "plugin-banner-{$plugin_slug}"; 334 $html = "<style type='text/css'>"; 314 335 $html .= "#{$id} { background-image: url('{$banner}'); }"; 315 336 if ( ! empty( $banner_2x ) ) { … … 329 350 330 351 /** 331 * @param $plugin 332 * @param $asset 352 * Generates and returns the URL to a passed asset. 353 * 354 * Assets can be screenshots, icons, banners, etc. 355 * 356 * @static 357 * 358 * @param string $plugin Plugin slug. 359 * @param array $asset Assets folder information. 333 360 * @return string 334 361 */ 335 static function get_asset_url( $plugin, $asset ) {362 public static function get_asset_url( $plugin, $asset ) { 336 363 if ( ! empty( $asset['location'] ) && 'plugin' == $asset['location'] ) { 337 // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png 364 365 // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png. 338 366 $format = 'https://s.w.org/plugins/%s/%s?rev=%s'; 339 367 } else { 340 // Images in the assets folder - /plugin-name/assets/screenshot-1.png 368 369 // Images in the assets folder - /plugin-name/assets/screenshot-1.png. 341 370 $format = 'https://ps.w.org/%s/assets/%s?rev=%s'; 342 371 } … … 353 382 * A helper method to create dashicon stars. 354 383 * 355 * @type int|array { 384 * @static 385 * 386 * @param int|array $args { 356 387 * If numeric arg passed, assumed to be 'rating'. 357 388 * … … 362 393 * @return string The Rating HTML. 363 394 */ 364 static function dashicons_stars( $args = array() ) { 365 $defaults = array( 366 'rating' => 0, 367 'template' => '<span class="%1$s"></span>' 368 ); 369 $r = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), $defaults ); 370 371 $rating = round( $r['rating'] / 0.5 ) * 0.5; 372 $template = $r['template']; 395 public static function dashicons_stars( $args = array() ) { 396 $args = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), array( 397 'rating' => 0, 398 'template' => '<span class="%1$s"></span>', 399 ) ); 400 401 $rating = round( $args['rating'] / 0.5 ) * 0.5; 402 $template = $args['template']; 373 403 $title_template = __( '%s out of 5 stars', 'wporg-plugins' ); 374 $title = sprintf( $title_template, $rating );375 376 $output = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">';404 $title = sprintf( $title_template, $rating ); 405 406 $output = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">'; 377 407 $counter = round( $rating * 2 ); 378 for ( $i = 1; $i <= 5; $i++ ) { 379 switch ($counter) { 380 case 0: 381 $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i ); 382 break; 383 case 1: 384 $output .= sprintf( $template, 'dashicons dashicons-star-half', $i ); 385 $counter--; 386 break; 387 default: 388 $output .= sprintf( $template, 'dashicons dashicons-star-filled', $i ); 389 $counter -= 2; 390 break; 408 for ( $i = 1; $i <= 5; $i++ ) { 409 switch ( $counter ) { 410 case 0: 411 $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i ); 412 break; 413 414 case 1: 415 $output .= sprintf( $template, 'dashicons dashicons-star-half', $i ); 416 $counter--; 417 break; 418 419 default: 420 $output .= sprintf( $template, 'dashicons dashicons-star-filled', $i ); 421 $counter -= 2; 422 break; 391 423 } 392 424 } 393 425 $output .= '</div>'; 426 394 427 return $output; 395 428 } 396 429 397 430 /** 398 * Generate a Download link for a given plugin & version.431 * Generate a download link for a given plugin & version. 399 432 * 400 433 * @param \WP_Post $post The Plugin Post. … … 419 452 * Properly encodes a string to UTF-8. 420 453 * 454 * @static 455 * 421 456 * @param string $string 422 457 * @return string
Note: See TracChangeset
for help on using the changeset viewer.