Making WordPress.org


Ignore:
Timestamp:
02/25/2016 05:03:19 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Switch to using namespaces instead of implemeting them through classnames.
This change introduces an autoloader and relies upon it for most file inclusions, this should encourage us to keep a standard naming schema and writing more component classes going forward.
See #1584

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  
    11<?php
    2 add_shortcode( 'wporg-plugins-screenshots', 'wporg_plugins_screenshots' );
     2namespace WordPressdotorg\Plugin_Directory\Shortcodes;
     3use WordPressdotorg\Plugin_Directory\Template;
    34
    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 */
     10class Screenshots {
     11        static function display() {
     12                $plugin = get_post();
    613
    7         // All indexed from 1
    8         $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 );
    1017
    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                                }
    2028                        }
    21                 }
    22                 if ( ! $found ) {
    23                         continue;
    24                 }
     29                        if ( ! $found ) {
     30                                continue;
     31                        }
    2532
    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
    4144                        );
    4245                }
    4346
    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
    5449        }
    55 
    56         return '<ol class="screenshots">' . $output . '</ol>';
    57 
    5850}
Note: See TracChangeset for help on using the changeset viewer.