Changeset 2611 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php
- Timestamp:
- 02/25/2016 05:03:19 AM (10 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes
- Files:
-
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php
r2560 r2611 1 1 <?php 2 add_shortcode( 'wporg-plugins-screenshots', 'wporg_plugins_screenshots' ); 2 namespace WordPressdotorg\Plugin_Directory\Shortcodes; 3 use WordPressdotorg\Plugin_Directory\Template; 3 4 4 function wporg_plugins_screenshots() { 5 $plugin = get_post(); 5 /** 6 * The [wporg-plugins-screenshots] shortcode handler to display a plugins screenshots. 7 * 8 * @package WordPressdotorg_Plugin_Directory 9 */ 10 class Screenshots { 11 static function display() { 12 $plugin = get_post(); 6 13 7 // All indexed from 18 $screenshot_descriptions = get_post_meta( $plugin->ID, 'screenshots', true );9 $assets_screenshots = get_post_meta( $plugin->ID, 'assets_screenshots', true );14 // All indexed from 1 15 $screenshot_descriptions = get_post_meta( $plugin->ID, 'screenshots', true ); 16 $assets_screenshots = get_post_meta( $plugin->ID, 'assets_screenshots', true ); 10 17 11 $output = ''; 12 foreach ( $screenshot_descriptions as $index => $description ) { 13 // Find the image that corresponds with the text. 14 // The image numbers are stored within the 'resolution' key. 15 $found = false; 16 foreach ( $assets_screenshots as $image ) { 17 if ( $index == $image['resolution'] ) { 18 $found = true; 19 break; 18 $output = ''; 19 foreach ( $screenshot_descriptions as $index => $description ) { 20 // Find the image that corresponds with the text. 21 // The image numbers are stored within the 'resolution' key. 22 $found = false; 23 foreach ( $assets_screenshots as $image ) { 24 if ( $index == $image['resolution'] ) { 25 $found = true; 26 break; 27 } 20 28 } 21 } 22 if ( ! $found ) { 23 continue; 24 } 29 if ( ! $found ) { 30 continue; 31 } 25 32 26 if ( ! empty( $image['location'] ) && 'plugin' == $image['location'] ) { 27 // Screenshot is within the plugin folder 28 $url = sprintf( 29 'https://s.w.org/plugins/%s/%s?rev=%s', 30 $plugin->post_name, 31 $image['filename'], 32 $image['revision'] 33 ); 34 } else { 35 // In the /assets/ folder 36 $url = sprintf( 37 'https://ps.w.org/%s/assets/%s?rev=%s', 38 $plugin->post_name, 39 $image['filename'], 40 $image['revision'] 33 $url = Template::get_asset_url( $plugin->post_name, $image ); 34 35 $output .= sprintf( 36 '<li> 37 <a href="%1$s" rel="nofollow"> 38 <img class="screenshot" src="%1$s"> 39 </a> 40 <p>%2$s</p> 41 </li>', 42 $url, 43 $description 41 44 ); 42 45 } 43 46 44 $output .= sprintf( 45 '<li> 46 <a href="%1$s" rel="nofollow"> 47 <img class="screenshot" src="%1$s"> 48 </a> 49 <p>%2$s</p> 50 </li>', 51 $url, 52 $description 53 ); 47 return '<ol class="screenshots">' . $output . '</ol>'; 48 54 49 } 55 56 return '<ol class="screenshots">' . $output . '</ol>';57 58 50 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)