Changeset 836735
- Timestamp:
- 01/11/2014 04:12:27 PM (12 years ago)
- Location:
- wp-download-codes/trunk
- Files:
-
- 7 edited
-
README.txt (modified) (3 diffs)
-
includes/admin/download-code-settings.php (modified) (2 diffs)
-
includes/admin/manage-releases.php (modified) (4 diffs)
-
includes/download.php (modified) (5 diffs)
-
includes/helpers/file.php (modified) (1 diff)
-
includes/helpers/options.php (modified) (1 diff)
-
wp-download-codes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-download-codes/trunk/README.txt
r832961 r836735 5 5 Requires at least: 2.5 6 6 Tested up to: 3.8 7 Stable tag: 2. 3.07 Stable tag: 2.4.0 8 8 9 9 The plugin enables to generation and management of download codes for all types of files (zip, mp3, ...). … … 54 54 Most providers do not allow an upload quota which is sufficient to upload larger zip files. Therefore, an option using an upload form has not been considered yet. 55 55 56 = Can I influence the request headers which are being sent for each download file? 56 = Can I influence the request headers which are being sent for each download file? = 57 57 58 58 Yes, you can override the content type header which by default sends the MIME content type of the download file. If this does not work in your environment, you can specify alternative fixed headers like application/download. 59 60 = Can I use the x-sendfile header functionality provided by my Apache server? = 61 62 Yes, if you have an Apache server running with mod_xsendfile (https://tn123.org/mod_xsendfile/) being installed and configured properly, you can turn on the respective setting in the Download Codes settings. The download then uses the plain x-sendfile header instead of streaming it with the general logic. 59 63 60 64 == Screenshots == … … 62 66 63 67 == Changelog == 68 69 = 2.4.0 = 70 * Consolidated and incorporated several additional best practices to handle file downloads in order to solve current issues with certain client-server constellations. 71 * Added ID of release to 'Manage Release' list so that it can be used more easily with the `[download-code id="xyz"]` shortcode. 72 * Enabled support for Apache header x-sendfile (if configured in the settings). 73 * Fixed bug with file extensions for release files which did not match a length of 3 (e.g. '.epub'). 64 74 65 75 = 2.3.0 = -
wp-download-codes/trunk/includes/admin/download-code-settings.php
r832961 r836735 46 46 update_option( 'dc_header_content_type' , $_POST['dc_header_content_type'] == '' ? DC_HEADER_CONTENT_TYPE : $_POST['dc_header_content_type'] ); 47 47 48 // Update xsenfile enabled flag 49 update_option( 'dc_xsendfile_enabled' , isset( $_POST['dc_xsendfile_enabled'] ) ? 'true' : 'false' ); 50 48 51 // Update messages 49 52 update_option( 'dc_msg_code_enter' , $_POST['dc_msg_code_enter'] ); … … 137 140 echo '</tr>'; 138 141 142 // Support for x-sendfile 143 echo '<tr valign="top">'; 144 echo '<th scope="row"><label for="headers-xsendfile-enabled">Apache X-Sendfile</label></th>'; 145 echo '<td><input type="checkbox" name="dc_xsendfile_enabled" id="dc-xsendfile-enabled" ' . ( dc_xsendfile_enabled() ? 'checked' : '') . ' />'; 146 echo '<span class="description">Only check this setting if Apache\'s x-sendfile module is installed and configured properly</span>'; 147 echo '</td>'; 148 echo '</tr>'; 149 139 150 echo '</table>'; 140 151 -
wp-download-codes/trunk/includes/admin/manage-releases.php
r832961 r836735 131 131 echo '</tr>'; 132 132 133 // file133 // File 134 134 echo '<tr valign="top">'; 135 135 echo '<th scope="row"><label for="release-file">File</label></th>'; 136 echo '<td>' . dc_file_location() . ' <select name="filename" id="release-file">'; 136 echo '<td>' . dc_file_location() . ' <select name="filename" id="release-file">-->'; 137 138 // Get array of allowed file types/extensions 139 $allowed_file_types = dc_file_types(); 140 141 // List all files matching the allowed extensions 137 142 foreach ( $files as $filename ) { 138 if ( in_array(strtolower( substr($filename, -3) ), dc_file_types() ) ) { 143 $file_extension_array = split( "\.", $filename ); 144 $file_extension = strtolower( $file_extension_array[ sizeof( $file_extension_array ) - 1 ] ); 145 if ( in_array( $file_extension, $allowed_file_types ) ) { 139 146 echo '<option' . ( $filename == $release->filename ? ' selected="selected"' : '' ) . '>' . $filename . '</option>'; 140 147 } … … 179 186 180 187 echo '<thead>'; 181 echo '<tr><th>Title</th><th>Artist</th><th> File</th><th>Codes</th><th>Downloaded</th><th>Actions</th></tr>';188 echo '<tr><th>Title</th><th>Artist</th><th>ID</th><th>File</th><th>Codes</th><th>Downloaded</th><th>Actions</th></tr>'; 182 189 echo '</thead>'; 183 190 … … 186 193 echo '<tr>'; 187 194 echo '<td><strong>' . $release->title . '</strong></td><td>' . $release->artist . '</td>'; 195 echo '<td>' . $release-> ID . '</td>'; 188 196 echo '<td>' . $release->filename . '</td>'; 189 197 echo '<td>' . $release->codes . '</td><td>' . $release->downloads . '</td>'; … … 199 207 200 208 echo '<tfoot>'; 201 echo '<tr><th>Title</th><th>Artist</th><th> File</th><th>Codes</th><th>Downloaded</th><th>Actions</th></tr>';209 echo '<tr><th>Title</th><th>Artist</th><th>ID</th><th>File</th><th>Codes</th><th>Downloaded</th><th>Actions</th></tr>'; 202 210 echo '</tfoot>'; 203 211 -
wp-download-codes/trunk/includes/download.php
r832961 r836735 17 17 18 18 // Only continue if lease is provided as a query parameter 19 if (isset( $_GET['lease'] )) { 20 21 // Set timeout 22 set_time_limit( 1200 ); 23 19 if ( isset( $_GET['lease'] ) ) { 24 20 // Get details for code and release 25 21 $release = $wpdb->get_row( "SELECT r.*, c.ID as code, c.code_prefix, c.code_suffix FROM " . dc_tbl_releases() . " r INNER JOIN " . dc_tbl_codes() ." c ON c.release = r.ID WHERE MD5(CONCAT('wp-dl-hash',c.ID)) = '" . $_GET['lease'] . "'" ); … … 29 25 30 26 // Start download if maximum of allowed downloads is not reached 31 if ( $downloads->downloads < $release->allowed_downloads) {27 if ( $downloads->downloads < $release->allowed_downloads ) { 32 28 // Get current IP 33 29 $IP = $_SERVER['REMOTE_ADDR']; … … 38 34 array( '%d', '%s') ); 39 35 40 // Send header for cache 41 header( 'Pragma: public' ); 42 header( 'Expires: 0' ); 43 header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); 36 // If Apache's xsendfile is enabled (must be installed and working on server side) 37 if ( dc_xsendfile_enabled() ) { 38 header( 'X-Sendfile: ' . dc_file_location() . $release->filename ); 39 header( 'Content-Type: application/octet-stream' ); 40 header( 'Content-Disposition: attachment; filename=\"' . urlencode ( $release->filename ) . '\"' ); 41 exit; 42 } 43 44 // Increase timeout for slow connections 45 set_time_limit( 0 ); 46 47 // Deactivate output compression (required for IE, otherwise Content-Disposition is ignored) 48 if( ini_get( 'zlib.output_compression' ) ) { 49 ini_set( 'zlib.output_compression', 'Off' ); 50 } 51 52 // Content description 44 53 header( 'Content-Description: File Transfer' ); 45 54 46 // Send header for content type 47 $content_type = dc_header_content_type(); 48 if ( $content_type == DC_HEADER_CONTENT_TYPE) { 49 // Send MIME type of current file 50 header( 'Content-Type: ' . get_mime_content_type( dc_file_location() . $release->filename ) ); 51 } 52 else { 53 // Override content type with header setting 54 header( 'Content-Type: ' . $content_type ); 55 } 56 57 // Send header for content disposition 55 // Content disposition 58 56 if ( strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], "MSIE" ) > 0 ) 59 57 { … … 65 63 } 66 64 67 // Send header for content length 65 // Content type 66 $content_type = dc_header_content_type(); 67 if ( $content_type == DC_HEADER_CONTENT_TYPE ) { 68 // Send MIME type of current file 69 header( 'Content-Type: ' . get_mime_content_type( dc_file_location() . $release->filename ) ); 70 } 71 else { 72 // Override content type with header setting 73 header( 'Content-Type: ' . $content_type ); 74 } 75 76 // Transfer encoding 77 header( 'Content-Transfer-Encoding: binary' ); 78 79 // Content length 68 80 header( 'Content-Length: '.filesize( dc_file_location() . $release->filename )); 69 81 82 // Cache handling 83 header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); 84 header( 'Pragma: public' ); 85 header( 'Expires: 0' ); 86 70 87 // Stream file 88 ob_clean(); 71 89 flush(); 72 90 ob_end_flush(); 73 91 $handle = fopen( dc_file_location() . $release->filename, 'rb' ); 74 $chunksize = 1 *(1024*1024);92 $chunksize = 1 * ( 1024 * 1024 ); 75 93 $buffer = ''; 76 94 if ($handle === false) { … … 85 103 // Close file 86 104 fclose($handle); 105 106 // Exit 107 exit; 87 108 } 88 109 } -
wp-download-codes/trunk/includes/helpers/file.php
r832961 r836735 50 50 } 51 51 52 // trim white space52 // Trim white space 53 53 array_walk($arr_file_types, 'dc_trim_value'); 54 54 -
wp-download-codes/trunk/includes/helpers/options.php
r832961 r836735 31 31 return ( '' == get_option( 'dc_header_content_type' ) ? DC_HEADER_CONTENT_TYPE : get_option( 'dc_header_content_type' ) ); 32 32 } 33 34 /** 35 * Checks if x-sendfile support is enabled 36 */ 37 function dc_xsendfile_enabled() { 38 return ( 'true' == get_option( 'dc_xsendfile_enabled' ) ? true : false ); 39 } 33 40 ?> -
wp-download-codes/trunk/wp-download-codes.php
r832961 r836735 6 6 Description: The plugin enables to generation and management of download codes for .zip files. It was written to enable the free download of records and CDs with dedicated codes printed on the cover of the releases or on separate download cards. 7 7 8 Version: 2. 3.08 Version: 2.4.0 9 9 Author: misanthrop, spalmer 10 10 Author URI: http://www.misantropolis.de, http://quoperative.com
Note: See TracChangeset
for help on using the changeset viewer.