Changeset 6287 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php
- Timestamp:
- 12/19/2017 04:22:37 PM (8 years ago)
- 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 3 3 4 4 // 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 ) );5 define( 'API_CACHE_EXPIRY', 24 * 60 * 60 + rand( 0, 60 * 60 ) ); 6 6 class Plugins_Info_API { 7 7 … … 9 9 const CACHE_EXPIRY = API_CACHE_EXPIRY; 10 10 11 protected $format = 'json';12 protected $jsonp = false;11 protected $format = 'json'; 12 protected $jsonp = false; 13 13 protected $formats = array( 14 14 'jsonp' => 'application/javascript', … … 21 21 if ( is_array( $format ) && 'jsonp' == $format[0] ) { 22 22 $this->jsonp = preg_replace( '/[^a-zA-Z0-9_]/', '', $format[1] ); 23 $format = 'jsonp';23 $format = 'jsonp'; 24 24 } 25 25 $this->format = $format; … … 53 53 } else { 54 54 $this->output( (object) array( 55 'error' => 'Action not implemented' 55 'error' => 'Action not implemented', 56 56 ) ); 57 57 } … … 72 72 if ( 200 != $response->status ) { 73 73 $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. 75 75 } else { 76 76 $response = $response->data; … … 88 88 return; 89 89 } 90 91 90 92 91 // Only include the fields requested. … … 129 128 // Back-compatible routines. 130 129 // 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']; 133 132 $response['contributors'] = array(); 134 133 if ( $contribs ) { … … 147 146 public function query_plugins( $request ) { 148 147 $response = array( 149 'info' => array(150 'page' => 0,151 'pages' => 0,148 'info' => array( 149 'page' => 0, 150 'pages' => 0, 152 151 'results' => 0, 153 152 ), 154 'plugins' => array() 153 'plugins' => array(), 155 154 ); 156 155 … … 175 174 // Fill in the plugin details 176 175 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 ); 178 184 if ( isset( $plugin['error'] ) ) { 179 185 unset( $response['plugins'][ $i ] ); … … 186 192 // Trim fields and cast to object 187 193 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' ); 189 195 } 190 196 … … 216 222 217 223 $number_items_requested = 100; 218 if ( ! empty( $request->number ) ) {224 if ( ! empty( $request->number ) ) { 219 225 $number_items_requested = $request->number; 220 226 } … … 242 248 switch ( $this->format ) { 243 249 default: 244 case 'json' 245 case 'jsonp' 250 case 'json': 251 case 'jsonp': 246 252 if ( ! function_exists( 'wp_json_encode' ) && defined( 'WPORGAPIPATH' ) ) { 247 253 require WPORGAPIPATH . '/includes/wp-json-encode.php'; … … 254 260 } 255 261 break; 256 257 case 'php' 262 263 case 'php': 258 264 echo serialize( $response ? (object) $response : $response ); 259 265 break; 260 261 case 'xml' 266 267 case 'xml': 262 268 echo '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n"; 263 269 echo "<plugin>\n"; … … 281 287 define( 'REST_REQUEST', true ); 282 288 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'; 286 292 $_SERVER['REQUEST_URI'] = '/plugins/'; 287 293 288 294 require_once WPORGPATH . '/wp-load.php'; 289 295 290 $_SERVER['HTTP_HOST'] = $host;296 $_SERVER['HTTP_HOST'] = $host; 291 297 $_SERVER['REQUEST_URI'] = $request_uri; 292 298 … … 322 328 $xml_tag = function( $tag, $type, $empty = false ) { 323 329 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}-'; 325 331 326 332 $start_right = $empty ? ' />' : '>'; … … 340 346 echo str_repeat( "\t", $tabs ); 341 347 switch ( $type = gettype( $data ) ) { 342 case 'string' 348 case 'string': 343 349 $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': 348 354 list( $start, $close ) = $xml_tag( $key, $type, false ); 349 355 echo "$start$data$close"; 350 356 break; 351 case 'NULL' 357 case 'NULL': 352 358 list( $start, $close ) = $xml_tag( $key, $type, true ); 353 359 echo $start; 354 360 break; 355 case 'array' 361 case 'array': 356 362 if ( empty( $data ) ) { 357 363 list( $start, $close ) = $xml_tag( $key, $type, true ); … … 368 374 echo $close; 369 375 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 ) { 373 379 break; 374 380 } 375 381 376 list( $start, $close ) = $xml_tag( $key, $type, true );382 list( $start, $close ) = $xml_tag( $key, $type, true ); 377 383 echo $start; 378 384 break; … … 391 397 } 392 398 break; 393 case 'resource' 394 case 'unknown type' 395 default 399 case 'resource': 400 case 'unknown type': 401 default: 396 402 break; 397 403 }
Note: See TracChangeset
for help on using the changeset viewer.