Plugin Directory

Changeset 3007751


Ignore:
Timestamp:
12/10/2023 09:34:05 AM (2 years ago)
Author:
janwyl
Message:

Add dev version 1.3.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bulk-attachment-download/trunk/incl/class-bulk-attachment-download-manager.php

    r2932984 r3007751  
    13481348                'size_incl_int'     => 0
    13491349            );
     1350
    13501351            $int_sizes = get_intermediate_image_sizes();
    13511352            $upload_dir_info = wp_upload_dir();
     
    13541355                $file_path = get_attached_file( $permitted_file->ID, true );
    13551356
    1356                 if ( file_exists( $file_path ) ) { // If the file actually exists, include in stats.
     1357                if (
     1358                    file_exists( $file_path ) &&
     1359                    apply_filters( 'jabd_include_original_file', true, $permitted_file )
     1360                ) { // If the file actually exists and is selected, include in stats.
    13571361                    $download_data['count']++;
    13581362                    $download_data['count_incl_int']++;
     
    13651369                    if ( ! empty( $int_sizes ) ) {
    13661370                        foreach ( $int_sizes as $size ) {
    1367                             if ( $int_image_data = image_get_intermediate_size( $permitted_file->ID, $size ) ) {
     1371                            if (
     1372                                ( $int_image_data = image_get_intermediate_size( $permitted_file->ID, $size ) ) &&
     1373                                apply_filters( 'jabd_include_intermediate_image_size', true, $size, $permitted_file )
     1374                            ) {
    13681375                                $download_data['count_incl_int']++;
    13691376                                $int_filepath = false === strpos( $int_image_data['path'], $upload_dir_info['basedir'] ) ? $upload_dir_info['basedir'] . '/' . $int_image_data['path'] : $int_image_data['path'];
     
    13771384           
    13781385            // If we have files to assess...
    1379             if ( $download_data['count'] > 0 ) {
     1386            if ( $download_data['count_incl_int'] > 0 ) {
    13801387               
    13811388                $settings = get_option( 'jabd_options' );
     
    15491556                            // Add the files to the zip.
    15501557                            foreach ( $permitted_files as $permitted_file ) {
    1551                                 $file_path = get_attached_file( $permitted_file->ID, true );
    1552 
    1553                                 if ( file_exists( $file_path ) ) { // If the file actually exists, add it to the zip file.
     1558
     1559                                if ( apply_filters( 'jabd_include_original_file', true, $permitted_file ) ) {
    15541560                                   
    1555                                     if ( $no_folders ) {
     1561                                    $file_path = get_attached_file( $permitted_file->ID, true );
     1562
     1563                                    if ( file_exists( $file_path ) ) { // If the file actually exists, add it to the zip file.
    15561564                                       
    1557                                         // Just use filename for relative file path.
    1558                                         $relative_file_path = wp_basename( $file_path );
     1565                                        if ( $no_folders ) {
     1566                                           
     1567                                            // Just use filename for relative file path.
     1568                                            $relative_file_path = wp_basename( $file_path );
     1569                                           
     1570                                        } else {
    15591571                                       
    1560                                     } else {
    1561                                    
    1562                                         // Attempt to work out the path relative to the uploads folder.
    1563                                         $relative_file_path = $this->file_path_rel_to_uploads( $file_path, $permitted_file, $upload_dir_info['basedir'] );
     1572                                            // Attempt to work out the path relative to the uploads folder.
     1573                                            $relative_file_path = $this->file_path_rel_to_uploads( $file_path, $permitted_file, $upload_dir_info['basedir'] );
     1574                                           
     1575                                        }
    15641576                                       
     1577                                        $added_rel_filepaths = $this->add_file_to_zip( $zip, $file_path, $relative_file_path, $added_rel_filepaths, $zip_pword );
     1578
    15651579                                    }
    1566                                    
    1567                                     $added_rel_filepaths = $this->add_file_to_zip( $zip, $file_path, $relative_file_path, $added_rel_filepaths, $zip_pword );
    15681580
    15691581                                }
     
    15741586                                    if ( ! empty( $int_sizes ) ) {
    15751587                                        foreach ( $int_sizes as $size ) {
    1576                                             if ( $int_image_data = image_get_intermediate_size( $permitted_file->ID, $size ) ) {
    1577                                                
     1588                                            if (
     1589                                                ( $int_image_data = image_get_intermediate_size( $permitted_file->ID, $size ) ) &&
     1590                                                apply_filters( 'jabd_include_intermediate_image_size', true, $size, $permitted_file )
     1591                                            ) {
    15781592                                                $int_file_path = $int_image_data['path'];
    15791593
     
    15911605                                               
    15921606                                                $added_rel_filepaths = $this->add_file_to_zip( $zip, $int_file_path, $int_rel_filepath, $added_rel_filepaths, $zip_pword );
    1593 
    15941607                                            }
    15951608                                        }
     
    16011614                            // Close the zip.
    16021615                            $zip->close();
     1616
     1617                            if ( $added_rel_filepaths ) {
    16031618                           
    1604                             if ( file_exists( $zip_path ) ) {
    1605                            
    1606                                 // Create the download post.
    1607                                 date_default_timezone_set( 'UTC' );
    1608 
    1609                                 $meta_input = array(
    1610                                     'jabd_path'     => addslashes( $rel_zip_path ),
    1611                                     'jabd_expiry'   => date( 'Y-m-d H:i:s', strtotime( '+1 hours' ) )
    1612                                 );
    1613 
    1614                                 $store_pwd = false;
    1615                                 if ( isset( $settings['jabd_store_pwds'] ) ) {
    1616                                     if ( $settings['jabd_store_pwds'] ) {
    1617                                         $store_pwd = true;
     1619                                if ( file_exists( $zip_path ) ) {
     1620                               
     1621                                    // Create the download post.
     1622                                    date_default_timezone_set( 'UTC' );
     1623
     1624                                    $meta_input = array(
     1625                                        'jabd_path'     => addslashes( $rel_zip_path ),
     1626                                        'jabd_expiry'   => date( 'Y-m-d H:i:s', strtotime( '+1 hours' ) )
     1627                                    );
     1628
     1629                                    $store_pwd = false;
     1630                                    if ( isset( $settings['jabd_store_pwds'] ) ) {
     1631                                        if ( $settings['jabd_store_pwds'] ) {
     1632                                            $store_pwd = true;
     1633                                        }
    16181634                                    }
     1635                                    if ( $zip_pword && $store_pwd ) {
     1636                                        $meta_input['jabd_pword'] = $zip_pword;
     1637                                    }
     1638
     1639                                    $download_id = wp_insert_post( array(
     1640                                        'post_title'    => $post_title,
     1641                                        'post_type'     => 'jabd_download',
     1642                                        'post_status'   => 'publish',
     1643                                        'meta_input'    => $meta_input
     1644                                    ) );
     1645                                   
     1646                                    $uploads_dir_info = wp_upload_dir();
     1647                                    $post_link = $uploads_dir_info['baseurl'] . '/' . JABD_DOWNLOADS_DIR . '/' . get_post_meta( $download_id, 'jabd_path', true );
     1648
     1649                                    $results_msg = '<div class="jabd-popup-msg"><span>' . __( 'Download created!', 'bulk-attachment-download' ) . '</span></div>';
     1650                                    $results_download_btn = '<a href = "' . $post_link . '"><button class="button button-primary button-large">' . __( 'Download', 'bulk-attachment-download' ) . '</button></a>&nbsp; ';
     1651                                    $results_close_btn = '<button id="jabd-close-download-popup" class="button button-primary button-large">' . __( 'Close', 'bulk-attachment-download' ) . '</button>';
     1652                                    $results_btns = '<div class="jabd-popup-buttons">' . $results_download_btn.$results_view_btn.$results_close_btn . '</div>';
     1653                                    $results_view_link = '<div class=jabd-view-downloads-link"><a href = "' . admin_url( 'edit.php?post_type=jabd_download' ) . '">' . __( 'View all downloads', 'bulk-attachment-download' ) . '</a></div>';
     1654
     1655                                    $ajax_result = array(
     1656                                        'messages'  => $results_msg . $results_btns . $results_view_link
     1657                                    );
     1658                               
     1659                                } else { // ...zip file does not exist...
     1660                                    $permissions_errors[] = __( 'Error. Your download could not be created.', 'bulk-attachment-download' );
    16191661                                }
    1620                                 if ( $zip_pword && $store_pwd ) {
    1621                                     $meta_input['jabd_pword'] = $zip_pword;
    1622                                 }
    1623 
    1624                                 $download_id = wp_insert_post( array(
    1625                                     'post_title'    => $post_title,
    1626                                     'post_type'     => 'jabd_download',
    1627                                     'post_status'   => 'publish',
    1628                                     'meta_input'    => $meta_input
    1629                                 ) );
    1630                                
    1631                                 $results_msg = '<div class="jabd-popup-msg"><span>' . __( 'Download created!', 'bulk-attachment-download' ) . '</span></div>';
    1632                                 $results_view_btn = '<a href = "' . admin_url( 'edit.php?post_type=jabd_download' ) . '"><button class="button button-primary button-large">' . __( 'View', 'bulk-attachment-download' ) . '</button></a>&nbsp; ';
    1633                                 $results_close_btn = '<button id="jabd-close-download-popup" class="button button-primary button-large">' . __( 'Close', 'bulk-attachment-download' ) . '</button>';
    1634                                 $results_btns = '<div class="jabd-popup-buttons">' . $results_view_btn.$results_close_btn . '</div>';
    1635                                
    1636                                 $ajax_result = array(
    1637                                     'messages'  => $results_msg . $results_btns
    1638                                 );
    1639                            
    1640                             } else { // ...zip file does not exist...
    1641                                 $permissions_errors[] = __( 'Error. Your download could not be created.', 'bulk-attachment-download' );
     1662
     1663                            } else { // ...no files added to the zip...
     1664                                $permissions_errors[] = __( 'Error. Your download could not be created because no files were selected. Are you filtering out all the image sizes using filters ? (jabd_include_intermediate_image_size and/or jabd_include_original_file)', 'bulk-attachment-download' );
    16421665                            }
    16431666                           
Note: See TracChangeset for help on using the changeset viewer.