Changeset 3007751
- Timestamp:
- 12/10/2023 09:34:05 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
bulk-attachment-download/trunk/incl/class-bulk-attachment-download-manager.php
r2932984 r3007751 1348 1348 'size_incl_int' => 0 1349 1349 ); 1350 1350 1351 $int_sizes = get_intermediate_image_sizes(); 1351 1352 $upload_dir_info = wp_upload_dir(); … … 1354 1355 $file_path = get_attached_file( $permitted_file->ID, true ); 1355 1356 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. 1357 1361 $download_data['count']++; 1358 1362 $download_data['count_incl_int']++; … … 1365 1369 if ( ! empty( $int_sizes ) ) { 1366 1370 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 ) { 1368 1375 $download_data['count_incl_int']++; 1369 1376 $int_filepath = false === strpos( $int_image_data['path'], $upload_dir_info['basedir'] ) ? $upload_dir_info['basedir'] . '/' . $int_image_data['path'] : $int_image_data['path']; … … 1377 1384 1378 1385 // If we have files to assess... 1379 if ( $download_data['count '] > 0 ) {1386 if ( $download_data['count_incl_int'] > 0 ) { 1380 1387 1381 1388 $settings = get_option( 'jabd_options' ); … … 1549 1556 // Add the files to the zip. 1550 1557 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 ) ) { 1554 1560 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. 1556 1564 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 { 1559 1571 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 } 1564 1576 1577 $added_rel_filepaths = $this->add_file_to_zip( $zip, $file_path, $relative_file_path, $added_rel_filepaths, $zip_pword ); 1578 1565 1579 } 1566 1567 $added_rel_filepaths = $this->add_file_to_zip( $zip, $file_path, $relative_file_path, $added_rel_filepaths, $zip_pword );1568 1580 1569 1581 } … … 1574 1586 if ( ! empty( $int_sizes ) ) { 1575 1587 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 ) { 1578 1592 $int_file_path = $int_image_data['path']; 1579 1593 … … 1591 1605 1592 1606 $added_rel_filepaths = $this->add_file_to_zip( $zip, $int_file_path, $int_rel_filepath, $added_rel_filepaths, $zip_pword ); 1593 1594 1607 } 1595 1608 } … … 1601 1614 // Close the zip. 1602 1615 $zip->close(); 1616 1617 if ( $added_rel_filepaths ) { 1603 1618 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 } 1618 1634 } 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> '; 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' ); 1619 1661 } 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> '; 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' ); 1642 1665 } 1643 1666
Note: See TracChangeset
for help on using the changeset viewer.