Making WordPress.org


Ignore:
Timestamp:
12/19/2017 04:22:37 PM (9 years ago)
Author:
obenland
Message:

PLugins: Clean up formatting with phpcbf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php

    r5389 r6287  
    33
    44// The API caches here expire every 24~25hours, avoids cache races when multiple change at the same time.
    5 define( 'API_CACHE_EXPIRY', 24*60*60 + rand( 0, 60*60 ) );
     5define( 'API_CACHE_EXPIRY', 24 * 60 * 60 + rand( 0, 60 * 60 ) );
    66class Plugins_Info_API {
    77
     
    99        const CACHE_EXPIRY = API_CACHE_EXPIRY;
    1010
    11         protected $format = 'json';
    12         protected $jsonp  = false;
     11        protected $format  = 'json';
     12        protected $jsonp   = false;
    1313        protected $formats = array(
    1414                'jsonp' => 'application/javascript',
     
    2121                if ( is_array( $format ) && 'jsonp' == $format[0] ) {
    2222                        $this->jsonp = preg_replace( '/[^a-zA-Z0-9_]/', '', $format[1] );
    23                         $format = 'jsonp';
     23                        $format      = 'jsonp';
    2424                }
    2525                $this->format = $format;
     
    5353                                } else {
    5454                                        $this->output( (object) array(
    55                                                 'error' => 'Action not implemented'
     55                                                'error' => 'Action not implemented',
    5656                                        ) );
    5757                                }
     
    7272                        if ( 200 != $response->status ) {
    7373                                $response = array( 'error' => 'Plugin not found.' );
    74                                 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, 15*60 ); // shorter TTL for missing/erroring plugins.
     74                                wp_cache_set( $cache_key, $response, self::CACHE_GROUP, 15 * 60 ); // shorter TTL for missing/erroring plugins.
    7575                        } else {
    7676                                $response = $response->data;
     
    8888                        return;
    8989                }
    90 
    9190
    9291                // Only include the fields requested.
     
    129128                // Back-compatible routines.
    130129                // WordPress 4.x and older need a "bare" contributor map
    131                 if ( !empty( $fields['bare_contributors'] ) ) {
    132                         $contribs = $response['contributors'];
     130                if ( ! empty( $fields['bare_contributors'] ) ) {
     131                        $contribs                 = $response['contributors'];
    133132                        $response['contributors'] = array();
    134133                        if ( $contribs ) {
     
    147146        public function query_plugins( $request ) {
    148147                $response = array(
    149                         'info' => array(
    150                                 'page' => 0,
    151                                 'pages' => 0,
     148                        'info'    => array(
     149                                'page'    => 0,
     150                                'pages'   => 0,
    152151                                'results' => 0,
    153152                        ),
    154                         'plugins' => array()
     153                        'plugins' => array(),
    155154                );
    156155
     
    175174                // Fill in the plugin details
    176175                foreach ( $response['plugins'] as $i => $plugin_slug ) {
    177                         $plugin = $this->plugin_information( new Plugins_Info_API_Request( array( 'slug' => $plugin_slug, 'locale' => $request->locale ) ), true );
     176                        $plugin = $this->plugin_information(
     177                                new Plugins_Info_API_Request(
     178                                        array(
     179                                                'slug'   => $plugin_slug,
     180                                                'locale' => $request->locale,
     181                                        )
     182                                ), true
     183                        );
    178184                        if ( isset( $plugin['error'] ) ) {
    179185                                unset( $response['plugins'][ $i ] );
     
    186192                // Trim fields and cast to object
    187193                foreach ( $response['plugins'] as $i => $plugin_data ) {
    188                         $response['plugins'][$i] = (object) $this->remove_unexpected_fields( $plugin_data, $request, 'query_plugins' );
     194                        $response['plugins'][ $i ] = (object) $this->remove_unexpected_fields( $plugin_data, $request, 'query_plugins' );
    189195                }
    190196
     
    216222
    217223                $number_items_requested = 100;
    218                 if ( !empty( $request->number ) ) {
     224                if ( ! empty( $request->number ) ) {
    219225                        $number_items_requested = $request->number;
    220226                }
     
    242248                switch ( $this->format ) {
    243249                        default:
    244                         case 'json' :
    245                         case 'jsonp' :
     250                        case 'json':
     251                        case 'jsonp':
    246252                                if ( ! function_exists( 'wp_json_encode' ) && defined( 'WPORGAPIPATH' ) ) {
    247253                                        require WPORGAPIPATH . '/includes/wp-json-encode.php';
     
    254260                                }
    255261                                break;
    256        
    257                         case 'php' :
     262
     263                        case 'php':
    258264                                echo serialize( $response ? (object) $response : $response );
    259265                                break;
    260        
    261                         case 'xml' :
     266
     267                        case 'xml':
    262268                                echo '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
    263269                                echo "<plugin>\n";
     
    281287                define( 'REST_REQUEST', true );
    282288
    283                 $host = $_SERVER['HTTP_HOST'];
    284                 $request_uri = $_SERVER['REQUEST_URI'];
    285                 $_SERVER['HTTP_HOST'] = 'wordpress.org';
     289                $host                   = $_SERVER['HTTP_HOST'];
     290                $request_uri            = $_SERVER['REQUEST_URI'];
     291                $_SERVER['HTTP_HOST']   = 'wordpress.org';
    286292                $_SERVER['REQUEST_URI'] = '/plugins/';
    287293
    288294                require_once WPORGPATH . '/wp-load.php';
    289295
    290                 $_SERVER['HTTP_HOST'] = $host;
     296                $_SERVER['HTTP_HOST']   = $host;
    291297                $_SERVER['REQUEST_URI'] = $request_uri;
    292298
     
    322328                        $xml_tag = function( $tag, $type, $empty = false ) {
    323329                                static $NameStartChar = ':A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\x{2FF}\x{370}-\x{37D}\x{37F}-\x{1FFF}\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}';
    324                                 static $NameChar = '.0-9\xB7\x{0300}-\x{036F}\x{203F}-\x{2040}-';
     330                                static $NameChar      = '.0-9\xB7\x{0300}-\x{036F}\x{203F}-\x{2040}-';
    325331
    326332                                $start_right = $empty ? ' />' : '>';
     
    340346                echo str_repeat( "\t", $tabs );
    341347                switch ( $type = gettype( $data ) ) {
    342                         case 'string' :
     348                        case 'string':
    343349                                $data = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $data ) . ']]>';
    344                         case 'boolean' :
    345                         case 'integer' :
    346                         case 'double' :
    347                         case 'float' :
     350                        case 'boolean':
     351                        case 'integer':
     352                        case 'double':
     353                        case 'float':
    348354                                list( $start, $close ) = $xml_tag( $key, $type, false );
    349355                                echo "$start$data$close";
    350356                                break;
    351                         case 'NULL' :
     357                        case 'NULL':
    352358                                list( $start, $close ) = $xml_tag( $key, $type, true );
    353359                                echo $start;
    354360                                break;
    355                         case 'array' :
     361                        case 'array':
    356362                                if ( empty( $data ) ) {
    357363                                        list( $start, $close ) = $xml_tag( $key, $type, true );
     
    368374                                echo $close;
    369375                                break;
    370                         case 'object' :
    371                                 if ( !$array = get_object_vars( $data ) ) {
    372                                         if ( !$tabs ) {
     376                        case 'object':
     377                                if ( ! $array = get_object_vars( $data ) ) {
     378                                        if ( ! $tabs ) {
    373379                                                break;
    374380                                        }
    375381
    376                                         list( $start, $close ) = $xml_tag( $key, $type, true);
     382                                        list( $start, $close ) = $xml_tag( $key, $type, true );
    377383                                        echo $start;
    378384                                        break;
     
    391397                                }
    392398                                break;
    393                         case 'resource' :
    394                         case 'unknown type' :
    395                         default :
     399                        case 'resource':
     400                        case 'unknown type':
     401                        default:
    396402                                break;
    397403                }
Note: See TracChangeset for help on using the changeset viewer.