Plugin Directory

Changeset 836735


Ignore:
Timestamp:
01/11/2014 04:12:27 PM (12 years ago)
Author:
misanthrop
Message:

Version 2.4.0 committed

Location:
wp-download-codes/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • wp-download-codes/trunk/README.txt

    r832961 r836735  
    55Requires at least: 2.5
    66Tested up to: 3.8
    7 Stable tag: 2.3.0
     7Stable tag: 2.4.0
    88
    99The plugin enables to generation and management of download codes for all types of files (zip, mp3, ...).
     
    5454Most 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.
    5555
    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? =
    5757
    5858Yes, 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
     62Yes, 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.
    5963
    6064== Screenshots ==
     
    6266
    6367== 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').
    6474
    6575= 2.3.0 =
  • wp-download-codes/trunk/includes/admin/download-code-settings.php

    r832961 r836735  
    4646        update_option( 'dc_header_content_type' , $_POST['dc_header_content_type'] == '' ? DC_HEADER_CONTENT_TYPE : $_POST['dc_header_content_type'] );
    4747       
     48        // Update xsenfile enabled flag
     49        update_option( 'dc_xsendfile_enabled' , isset( $_POST['dc_xsendfile_enabled'] ) ? 'true' : 'false' );
     50               
    4851        // Update messages
    4952        update_option( 'dc_msg_code_enter' , $_POST['dc_msg_code_enter'] );
     
    137140    echo '</tr>';
    138141   
     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   
    139150    echo '</table>';
    140151   
  • wp-download-codes/trunk/includes/admin/manage-releases.php

    r832961 r836735  
    131131        echo '</tr>';
    132132       
    133         // file
     133        // File
    134134        echo '<tr valign="top">';
    135135        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
    137142        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 ) ) {
    139146                echo '<option' . ( $filename == $release->filename ? ' selected="selected"' : '' ) . '>' . $filename . '</option>';
    140147            }
     
    179186           
    180187            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>';
    182189            echo '</thead>';
    183190           
     
    186193                echo '<tr>';
    187194                echo '<td><strong>' . $release->title . '</strong></td><td>' . $release->artist . '</td>';
     195                echo '<td>' . $release-> ID . '</td>';
    188196                echo '<td>' . $release->filename . '</td>';
    189197                echo '<td>' . $release->codes . '</td><td>' . $release->downloads . '</td>';
     
    199207           
    200208            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>';
    202210            echo '</tfoot>';
    203211
  • wp-download-codes/trunk/includes/download.php

    r832961 r836735  
    1717   
    1818    // 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'] ) ) {
    2420        // Get details for code and release
    2521        $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'] . "'" );
     
    2925       
    3026        // Start download if maximum of allowed downloads is not reached
    31         if ($downloads->downloads < $release->allowed_downloads) {
     27        if ( $downloads->downloads < $release->allowed_downloads ) {
    3228            // Get current IP
    3329            $IP = $_SERVER['REMOTE_ADDR'];
     
    3834                            array( '%d', '%s') );
    3935           
    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
    4453            header( 'Content-Description: File Transfer' );
    4554           
    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
    5856            if ( strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], "MSIE" ) > 0 )
    5957            {
     
    6563            }
    6664           
    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
    6880            header( 'Content-Length: '.filesize( dc_file_location() . $release->filename ));
    6981           
     82            // Cache handling
     83            header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
     84            header( 'Pragma: public' );
     85            header( 'Expires: 0' );
     86           
    7087            // Stream file
     88            ob_clean();
    7189            flush();
    7290            ob_end_flush();
    7391            $handle = fopen( dc_file_location() . $release->filename, 'rb' );
    74             $chunksize = 1*(1024*1024);
     92            $chunksize = 1 * ( 1024 * 1024 );
    7593            $buffer = '';
    7694            if ($handle === false) {
     
    85103            // Close file
    86104            fclose($handle);
     105           
     106            // Exit
     107            exit;
    87108        }
    88109    }
  • wp-download-codes/trunk/includes/helpers/file.php

    r832961 r836735  
    5050    }
    5151   
    52     // trim white space
     52    // Trim white space
    5353    array_walk($arr_file_types, 'dc_trim_value');
    5454   
  • wp-download-codes/trunk/includes/helpers/options.php

    r832961 r836735  
    3131    return ( '' == get_option( 'dc_header_content_type' ) ? DC_HEADER_CONTENT_TYPE : get_option( 'dc_header_content_type' ) );
    3232}
     33
     34/**
     35 * Checks if x-sendfile support is enabled
     36 */
     37function dc_xsendfile_enabled() {
     38    return ( 'true' == get_option( 'dc_xsendfile_enabled' ) ? true : false );
     39}
    3340?>
  • wp-download-codes/trunk/wp-download-codes.php

    r832961 r836735  
    66Description: 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.
    77
    8 Version: 2.3.0
     8Version: 2.4.0
    99Author: misanthrop, spalmer
    1010Author URI: http://www.misantropolis.de, http://quoperative.com
Note: See TracChangeset for help on using the changeset viewer.