Changeset 6022 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php
- Timestamp:
- 10/13/2017 08:56:56 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php
r5305 r6022 37 37 $zip = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ); 38 38 39 $slug = false; 39 if ( ! preg_match( "!^(?P<slug>[a-z0-9-_]+)(\.(?P<version>.+?))?\.(?P<request_type>zip|checksums\.json)$!i", $zip, $m ) ) { 40 throw new Exception( __METHOD__ . ": Invalid URL." ); 41 } 42 43 $slug = strtolower( $m['slug'] ); 44 40 45 $version = 'trunk'; 41 42 if ( ! preg_match( "!^(?P<slug>[a-z0-9-_]+)(.(?P<version>.+))?.zip$!i", $zip, $m ) ) { 43 throw new Exception( __METHOD__ . ": Invalid URL." ); 44 } 45 46 $slug = strtolower( $m['slug'] ); 47 if ( isset( $m['version'] ) ) { 46 if ( isset( $m['version'] ) && '' !== $m['version'] ) { 48 47 $version = $m['version']; 49 48 } 50 51 49 if ( 'latest-stable' == $version ) { 52 50 $version = $this->get_stable_tag( $slug ); 51 } 52 53 if ( 'zip' == strtolower( $m['request_type'] ) ) { 54 $checksum_request = false; 55 } else { 56 $checksum_request = true; 57 58 // Checksum requests for 'trunk' are not possible. 59 if ( 'trunk' == $version ) { 60 throw new Exception( __METHOD__ . ": Checksum requests must include a version." ); 61 } 62 53 63 } 54 64 … … 56 66 'stats' => true, 57 67 ); 58 if ( isset( $_GET['stats'] ) ) { 68 69 if ( $checksum_request ) { 70 $args['stats'] = false; 71 72 } elseif ( isset( $_GET['stats'] ) ) { 59 73 $args['stats'] = (bool) $_GET['stats']; 74 60 75 } elseif ( isset( $_GET['nostats'] ) ) { 61 76 $args['stats'] = !empty( $_GET['nostats'] ); 62 77 } 63 78 64 return compact( 'zip', 'slug', 'version', 'args' );79 return compact( 'zip', 'slug', 'version', 'args', 'checksum_request' ); 65 80 } 66 81 … … 118 133 119 134 /** 120 * Returns the file s to usefor the request.135 * Returns the file to be served for the request. 121 136 * 122 137 * @param array $request The request object for the request. 123 * @return array An array containing the files to use for the request, 'zip' and 'md5'.138 * @return array The file to serve. 124 139 */ 125 140 protected function get_file( $request ) { 126 if ( empty( $request['version'] ) || 'trunk' == $request['version'] ) { 141 // Checksum requests must include a version 142 if ( $request['checksum_request'] ) { 143 return "{$request['slug']}/{$request['slug']}.{$request['version']}.checksums.json"; 144 145 } elseif ( empty( $request['version'] ) || 'trunk' == $request['version'] ) { 127 146 return "{$request['slug']}/{$request['slug']}.zip"; 147 128 148 } else { 129 149 return "{$request['slug']}/{$request['slug']}.{$request['version']}.zip"; 130 150 } 151 131 152 } 132 153 … … 137 158 */ 138 159 protected function serve_zip( $request ) { 139 $ zip= $this->get_file( $request );160 $file = $this->get_file( $request ); 140 161 141 162 if ( defined( 'PLUGIN_ZIP_X_ACCEL_REDIRECT_LOCATION' ) ) { 142 $zip_url = PLUGIN_ZIP_X_ACCEL_REDIRECT_LOCATION . $zip; 143 144 header( 'Content-Type: application/zip' ); 145 header( 'Content-Disposition: attachment; filename=' . basename( $zip ) ); 146 header( "X-Accel-Redirect: $zip_url" ); 163 $file_url = PLUGIN_ZIP_X_ACCEL_REDIRECT_LOCATION . $file; 164 165 if ( $request['checksum_request'] ) { 166 header( 'Content-Type: application/json' ); 167 } else { 168 header( 'Content-Type: application/zip' ); 169 header( 'Content-Disposition: attachment; filename=' . basename( $file ) ); 170 } 171 header( "X-Accel-Redirect: $file_url" ); 147 172 } else { 148 173 header( 'Content-Type: text/plain' ); 149 echo "This is a request for $ zip, this server isn't currently configured to serve zipfiles.\n";174 echo "This is a request for $file, this server isn't currently configured to serve files.\n"; 150 175 } 151 176
Note: See TracChangeset
for help on using the changeset viewer.