Changeset 4505
- Timestamp:
- 12/08/2016 01:58:37 PM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php
r4458 r4505 14 14 class Plugin extends Base { 15 15 16 /** 17 * Plugin constructor. 18 */ 16 19 function __construct() { 17 20 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/?', array( … … 124 127 foreach ( $screen_shots as $image ) { 125 128 $result['screenshots'][ $image['resolution'] ] = array( 126 'src' => Template::get_asset_url( $post ->post_name, $image ),129 'src' => Template::get_asset_url( $post, $image ), 127 130 'caption' => array_key_exists( $image['resolution'], $descriptions ) ? $descriptions[ $image['resolution'] ] : '' 128 131 ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r4411 r4505 117 117 */ 118 118 public static function get_plugin_sections( $post = null ) { 119 $plugin = get_post( $post ); 120 $plugin_slug = $plugin->post_name; 119 $plugin = get_post( $post ); 121 120 122 121 $default_sections = array( … … 174 173 case 'support': 175 174 $title = _x( 'Support', 'plugin tab title', 'wporg-plugins' ); 176 $url = 'https://wordpress.org/support/plugin/' . $plugin _slug;175 $url = 'https://wordpress.org/support/plugin/' . $plugin->post_name; 177 176 break; 178 177 179 178 case 'reviews': 180 179 $title = _x( 'Reviews', 'plugin tab title', 'wporg-plugins' ); 181 $url = 'https://wordpress.org/support/plugin/' . $plugin _slug. '/reviews/';180 $url = 'https://wordpress.org/support/plugin/' . $plugin->post_name . '/reviews/'; 182 181 break; 183 182 … … 211 210 * @static 212 211 * 213 * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug.214 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'.212 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 213 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'. 215 214 * @return mixed 216 215 */ 217 public static function get_plugin_icon( $plugin, $output = 'raw' ) { 218 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 219 if ( ! $plugin ) { 220 return false; 221 } 222 $plugin_slug = $plugin->post_name; 223 216 public static function get_plugin_icon( $post = null, $output = 'raw' ) { 217 $plugin = get_post( $post ); 224 218 $raw_icons = get_post_meta( $plugin->ID, 'assets_icons', true ); 225 219 … … 228 222 switch ( $info['resolution'] ) { 229 223 case '256x256': 230 $icon_2x = self::get_asset_url( $plugin _slug, $info );224 $icon_2x = self::get_asset_url( $plugin, $info ); 231 225 break; 232 226 233 227 case '128x128': 234 $icon = self::get_asset_url( $plugin _slug, $info );228 $icon = self::get_asset_url( $plugin, $info ); 235 229 break; 236 230 237 231 /* false = the resolution of the icon, this is NOT disabled */ 238 232 case false && 'icon.svg' == $file: 239 $svg = self::get_asset_url( $plugin _slug, $info );233 $svg = self::get_asset_url( $plugin, $info ); 240 234 break; 241 235 } … … 270 264 switch ( $output ) { 271 265 case 'html': 272 $id = "plugin-icon-{$plugin _slug}";266 $id = "plugin-icon-{$plugin->post_name}"; 273 267 $html = "<style type='text/css'>"; 274 268 $html .= "#{$id} { background-image: url('{$icon}'); } .plugin-icon { background-size: cover; height: 128px; width: 128px; }"; … … 293 287 * @static 294 288 * 295 * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug.296 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'.289 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 290 * @param string $output Optional. Output type. 'html' or 'raw'. Default: 'raw'. 297 291 * @return mixed 298 292 */ 299 public static function get_plugin_banner( $plugin, $output = 'raw' ) { 300 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 301 if ( ! $plugin ) { 302 return false; 303 } 293 public static function get_plugin_banner( $post = null, $output = 'raw' ) { 294 $plugin = get_post( $post ); 304 295 305 296 $banner = $banner_2x = false; 306 $plugin_slug = $plugin->post_name;307 297 $raw_banners = get_post_meta( $plugin->ID, 'assets_banners', true ); 308 298 … … 317 307 switch ( $info['resolution'] ) { 318 308 case '1544x500': 319 $banner_2x = self::get_asset_url( $plugin _slug, $info );309 $banner_2x = self::get_asset_url( $plugin, $info ); 320 310 break; 321 311 322 312 case '772x250': 323 $banner = self::get_asset_url( $plugin _slug, $info );313 $banner = self::get_asset_url( $plugin, $info ); 324 314 break; 325 315 } … … 330 320 switch ( $info['resolution'] ) { 331 321 case '1544x500': 332 $banner_2x = self::get_asset_url( $plugin _slug, $info );322 $banner_2x = self::get_asset_url( $plugin, $info ); 333 323 break; 334 324 335 325 case '772x250': 336 $banner = self::get_asset_url( $plugin _slug, $info );326 $banner = self::get_asset_url( $plugin, $info ); 337 327 break; 338 328 } … … 346 336 switch ( $output ) { 347 337 case 'html': 348 $id = "plugin-banner-{$plugin _slug}";338 $id = "plugin-banner-{$plugin->post_name}"; 349 339 $html = "<style type='text/css'>"; 350 340 $html .= "#{$id} { background-image: url('{$banner}'); }"; … … 371 361 * @static 372 362 * 373 * @param string $plugin Plugin slug.374 * @param array $assetAssets folder information.363 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 364 * @param array $asset Assets folder information. 375 365 * @return string 376 366 */ 377 public static function get_asset_url( $p lugin, $asset ) {367 public static function get_asset_url( $post, $asset ) { 378 368 if ( ! empty( $asset['location'] ) && 'plugin' == $asset['location'] ) { 379 369 … … 394 384 $format, 395 385 $asset['revision'], 396 $plugin,386 get_post( $post )->post_name, 397 387 $asset['filename'] 398 388 ) ); … … 451 441 * Generate a download link for a given plugin & version. 452 442 * 453 * @param \WP_Post $post The Plugin Post.454 * @param string $version The version to link to. Optional. Default: latest.443 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 444 * @param string $version The version to link to. Optional. Default: latest. 455 445 * @return string The Download URL. 456 446 */ … … 486 476 * Generates a link to toggle a plugin favorites state. 487 477 * 488 * @param string $plugin_slug The plugin slug.489 * @param mixed $userThe user to alter the favorite status for.478 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 479 * @param mixed $user The user to alter the favorite status for. 490 480 * @return string URL to toggle status. 491 481 */ 492 public static function get_favourite_link( $plugin_slug, $user = 0 ) { 493 $post = Plugin_Directory::get_plugin_post( $plugin_slug ); 494 if ( ! $post ) { 495 return false; 496 } 482 public static function get_favorite_link( $post = null, $user = 0 ) { 483 $post = get_post( $post ); 497 484 498 485 $favorited = Tools::favorited_plugin( $post, $user ); 499 486 500 return add_query_arg( 501 array( 502 '_wpnonce' => wp_create_nonce( 'wp_rest' ), 503 ( $favorited ? 'unfavorite' : 'favorite' ) => '1' 504 ), 505 home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/favorite' ) 506 ); 487 return add_query_arg( array( 488 '_wpnonce' => wp_create_nonce( 'wp_rest' ), 489 ( $favorited ? 'unfavorite' : 'favorite' ) => '1' 490 ), home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/favorite' ) ); 507 491 } 508 492 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r4423 r4505 180 180 if ( $first_banner = reset( $assets['banner'] ) ) { 181 181 // The Banners are not stored locally, which is why a URL is used here 182 $banner_average_color = Tools::get_image_average_color( Template::get_asset_url( $plugin _slug, $first_banner ) );182 $banner_average_color = Tools::get_image_average_color( Template::get_asset_url( $plugin, $first_banner ) ); 183 183 } 184 184 update_post_meta( $plugin->ID, 'assets_banners_color', wp_slash( $banner_average_color ) ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php
r4471 r4505 31 31 foreach ( $screen_shots as $image ) { 32 32 $screen_shot = sprintf( '<a href="%1$s" rel="nofollow"><img class="screenshot" src="%1$s" alt="" /></a>', 33 Template::get_asset_url( $plugin ->post_name, $image )33 Template::get_asset_url( $plugin, $image ) 34 34 ); 35 35 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php
r4504 r4505 164 164 } 165 165 166 $post_id = get_the_ID(); 167 $banner = Template::get_plugin_banner( $post_id ); 166 $banner = Template::get_plugin_banner(); 168 167 $banner['banner_2x'] = $banner['banner_2x'] ? $banner['banner'] : false; 169 $icon = Template::get_plugin_icon( $post_id);170 171 printf( '<meta property="og:title" content="%s" />' . "\n", the_title_attribute( array( 'echo' => false , 'post' => $post_id) ) );172 printf( '<meta property="og:description" content="%s" />' . "\n", esc_attr( strip_tags( get_the_excerpt( $post_id) ) ) );168 $icon = Template::get_plugin_icon(); 169 170 printf( '<meta property="og:title" content="%s" />' . "\n", the_title_attribute( array( 'echo' => false ) ) ); 171 printf( '<meta property="og:description" content="%s" />' . "\n", esc_attr( strip_tags( get_the_excerpt() ) ) ); 173 172 printf( '<meta property="og:site_name" content="WordPress.org" />' . "\n" ); 174 173 printf( '<meta property="og:type" content="website" />' . "\n" ); 175 printf( '<meta property="og:url" content="%s" />' . "\n", esc_url( get_permalink( $post_id) ) );174 printf( '<meta property="og:url" content="%s" />' . "\n", esc_url( get_permalink() ) ); 176 175 printf( '<meta name="twitter:card" content="summary_large_image">' . "\n" ); 177 176 printf( '<meta name="twitter:site" content="@WordPress">' . "\n" ); 178 177 179 178 if ( $banner['banner_2x'] ) { 180 printf( '<meta name="twitter:image" content="%s" />' . "\n", $banner['banner_2x']);179 printf( '<meta name="twitter:image" content="%s" />' . "\n", esc_url( $banner['banner_2x'] ) ); 181 180 } 182 181 if ( isset( $banner['banner'] ) ) { 183 printf( '<meta property="og:image" content="%s" />' . "\n", $banner['banner']);182 printf( '<meta property="og:image" content="%s" />' . "\n", esc_url( $banner['banner'] ) ); 184 183 } 185 184 if ( ! $icon['generated'] && ( $icon['icon_2x'] || $icon['icon'] ) ) { 186 printf( '<meta name="thumbnail" content="%s" />' , $icon['icon_2x'] ?: $icon['icon']);185 printf( '<meta name="thumbnail" content="%s" />' . "\n", esc_url( $icon['icon_2x'] ?: $icon['icon'] ) ); 187 186 } 188 187 } -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php
r4467 r4505 67 67 <?php 68 68 if ( is_user_logged_in() ) : 69 $url = Template::get_favo urite_link( $post);69 $url = Template::get_favorite_link(); 70 70 $is_favorited = Tools::favorited_plugin( $post ); 71 71 ?> … … 141 141 $section_no_read_mores[] = 'faq'; 142 142 } 143 143 144 144 $section_read_more = ! in_array( $section_slug, $section_no_read_mores ); 145 145
Note: See TracChangeset
for help on using the changeset viewer.