Changeset 3407018
- Timestamp:
- 12/01/2025 04:13:32 PM (3 months ago)
- Location:
- waterwoo-pdf/trunk
- Files:
-
- 3 edited
-
classes/wwpdf-file-handler.php (modified) (16 diffs)
-
readme.txt (modified) (2 diffs)
-
waterwoo-pdf.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
waterwoo-pdf/trunk/classes/wwpdf-file-handler.php
r3400576 r3407018 16 16 */ 17 17 protected $email = ''; 18 19 /** 20 * @var string 21 */ 22 protected $temp_folder = ''; 18 23 19 24 /** … … 31 36 if ( isset( $_GET['eddfile'] ) || isset( $_GET['edd-all-access-download'] ) ) { 32 37 add_filter( 'edd_requested_file', [ $this, 'dispatch_edd' ], 15, 4 ); 33 }34 35 if ( apply_filters( 'wwpdf_do_cleanup', true ) ) {36 $this->do_cleanup();37 38 } 38 39 … … 50 51 * @return void|string $file_path 51 52 */ 52 public function dispatch_woo( $file_path,$email, $order, $product, $download ) {53 public function dispatch_woo( string $file_path, string $email, $order, $product, $download ) { 53 54 54 55 if ( apply_filters( 'wwpdf_abort_watermarking', false, $file_path, $email, $order, $product, $download ) ) { … … 93 94 * @return string 94 95 */ 95 public function dispatch_dlm( $file_path, $remote_file,$download ) {96 public function dispatch_dlm( string $file_path, bool $remote_file, object $download ) { 96 97 97 98 // Sorry, the free version of PDF Ink (pdfink.com) doesn't handle remote PDF files … … 147 148 * @return string 148 149 */ 149 public function dispatch_edd( $file_path, $download_files, $file_key, $args ) {150 public function dispatch_edd( string $file_path, $download_files, $file_key, $args ) { 150 151 151 152 if ( empty( $file_path ) ) { … … 186 187 * @return mixed|void 187 188 */ 188 protected function dispatch( $source,$file_path, $order_id, $product_id ) {189 protected function dispatch( string $source, string $file_path, $order_id, $product_id ) { 189 190 190 191 // Check if it's a PDF … … 244 245 * @deprecated in PDF Watermark v4.0 245 246 */ 246 public function pdf_filepath( $file_path, $email, $order,$product, $download ) {247 public function pdf_filepath( string $file_path, string $email, object $order, object $product, $download ) { 247 248 // Sorry guys 248 249 } … … 253 254 * @return string 254 255 */ 255 protected function get_requested_filename( $file_path ) {256 protected function get_requested_filename( string $file_path ) { 256 257 257 258 $name = basename( $file_path ); … … 270 271 * @return boolean|string $content 271 272 */ 272 public function get_content( $source, $order_id, $product_id ) {273 public function get_content( string $source, $order_id, $product_id ) { 273 274 274 275 $email = ''; … … 456 457 457 458 if ( ! empty( $order_id ) ) { 458 $ watermarked_path= PDFINK_LITE_UPLOADS_PATH . $source . DIRECTORY_SEPARATOR . $order_id;459 $temp_folder = PDFINK_LITE_UPLOADS_PATH . $source . DIRECTORY_SEPARATOR . $order_id; 459 460 } else { 460 $watermarked_path = PDFINK_LITE_UPLOADS_PATH . $source . DIRECTORY_SEPARATOR . date( 'Y' ) . DIRECTORY_SEPARATOR . date( 'm' ) . DIRECTORY_SEPARATOR . date( 'd' ) . $order_id; 461 } 462 463 if ( ! wp_mkdir_p( $watermarked_path ) || ! is_writable( $watermarked_path ) ) { 464 throw new Exception( __( 'The PDF destination folder, ' . $watermarked_path .' is not writable.', 'waterwoo-pdf' ) ); 465 } 461 $temp_folder = PDFINK_LITE_UPLOADS_PATH . $source . DIRECTORY_SEPARATOR . date( 'Y' ) . DIRECTORY_SEPARATOR . date( 'm' ) . DIRECTORY_SEPARATOR . date( 'd' ) . $order_id; 462 } 463 464 if ( ! wp_mkdir_p( $temp_folder ) || ! is_writable( $temp_folder ) ) { 465 throw new Exception( __( 'The PDF destination folder, ' . $temp_folder .' is not writable.', 'waterwoo-pdf' ) ); 466 } 467 $this->temp_folder = $temp_folder; 466 468 467 469 $_file_path = $parsed_file_path['file_path']; … … 472 474 // Attempt to watermark using the open source TCPDI/TCPDF libraries 473 475 // There are other better libraries available which you can use easily if you upgrade to PDF Ink (www.pdfink.com) 474 $watermarker = new WWPDF_Watermark( $_file_path, $ watermarked_path. DIRECTORY_SEPARATOR . $this->get_requested_filename( $_file_path ), $settings );476 $watermarker = new WWPDF_Watermark( $_file_path, $temp_folder . DIRECTORY_SEPARATOR . $this->get_requested_filename( $_file_path ), $settings ); 475 477 $watermarker->do_watermark(); 476 478 … … 481 483 $watermarked_file = $watermarker->newfile; 482 484 } 483 // @todo cleanup using $this->watermarked file 484 $this->watermarked_file = $watermarked_file; 485 486 $this->watermarked_file = $watermarker->newfile; 487 488 if ( apply_filters( 'wwpdf_do_cleanup', true ) ) { 489 $this->do_cleanup(); 490 } 485 491 486 492 // Send watermarked file back to WooCommerce … … 608 614 /** 609 615 * Check if there is a stamped file and maybe delete it 616 * This only happens if download type is set to FORCE. 610 617 * 611 618 * @return void … … 613 620 public function cleanup_file() { 614 621 615 // This only happens if download type is set to FORCE 616 if ( isset( $this->watermarked_file ) && ! empty( $this->watermarked_file->newfile ) ) { 617 unlink( $this->watermarked_file->newfile ); 618 $this->watermarked_file = ''; 622 if ( isset( $this->watermarked_file ) && ! empty( $this->watermarked_file ) ) { 623 $file_path = wp_normalize_path( $this->watermarked_file ); 624 } else { 625 wwpdf_debug_log( 'Could not establish which file to delete.', 'warning' ); 626 return; 627 } 628 629 $temp_folder = wp_normalize_path( $this->temp_folder ); 630 631 if ( ! is_file( $file_path ) ) { 632 wwpdf_debug_log( 'Could not delete watermarked PDF: does not exist or is not a regular file.', 'warning' ); 633 return; 634 } 635 636 require_once ABSPATH . 'wp-admin/includes/file.php'; 637 638 if ( ! function_exists( 'WP_Filesystem' ) ) { 639 wwpdf_debug_log( 'Unable to get WP_Filesystem on board to delete watermarked PDF.', 'warning' ); 640 return; 641 } 642 643 $creds = request_filesystem_credentials( wp_nonce_url( site_url() ) ); 644 645 // If credentials cannot be obtained (rare on uninstall), abort 646 if ( ! $creds ) { 647 wwpdf_debug_log( 'Credentials to manipulate WP Filesystem not obtained, so cannot delete watermarked PDF.', 'warning' ); 648 return; 649 } 650 651 // Initialise the global $wp_filesystem object 652 if ( ! WP_Filesystem( $creds ) ) { 653 // Initialization failed (e.g., host disallows direct access). 654 // You could fall back to PHP's native functions, but for safety we stop. 655 return; 656 } 657 658 global $wp_filesystem; 659 660 if ( ! $wp_filesystem->delete( $file_path ) ) { 661 wwpdf_debug_log( 'Unable to delete watermarked PDF (filesystem error).', 'warning' ); 662 } 663 664 // Attempt to delete the parent directory – if empty 665 $parent_dir = dirname( $file_path ); 666 // Safety check to make sure directories match 667 if ( $parent_dir === $temp_folder && is_dir( $parent_dir ) ) { 668 // is_dir() + is_readable() + is_writable() checks are implicit in $wp_filesystem->rmdir() 669 $wp_filesystem->rmdir( $parent_dir, false ); // false = non‑recursive (only if empty) 670 } else { 671 wwpdf_debug_log( 'PDF Ink temp dir not removed, maybe because it is not empty.', 'notice' ); 619 672 } 620 673 … … 629 682 private function do_cleanup() { 630 683 631 // We can only *try* to cleanup if we have a forced download. 632 if ( 'force' === get_option( 'woocommerce_file_download_method' ) ) { 684 // We can only *try* to clean up if we have a forced download, using PHP shutdown 685 if ( ( 'force' === get_option( 'woocommerce_file_download_method' ) && doing_filter( 'woocommerce_download_product_filepath' ) ) 686 || ( 'direct' === edd_get_file_download_method() && doing_filter( 'edd_requested_file' ) ) 687 ) { 633 688 add_action( 'shutdown', [ $this, 'cleanup_file' ] ); // this will not work every time because we cannot know download is complete before PHP shutdown 634 689 } … … 637 692 // but adding a hook here just in case you have other plans. The upgraded version of this plugin 638 693 // includes automatic file cleanup, on a chosen schedule. 639 do_action( 'wwpdf_file_cleanup', $this->watermarked_file );694 do_action( 'wwpdf_file_cleanup', $this->watermarked_file, $this->temp_folder ); 640 695 641 696 } -
waterwoo-pdf/trunk/readme.txt
r3400576 r3407018 6 6 Tested up to: 6.8 7 7 Requires PHP: 7.4 8 Stable tag: 4.0. 58 Stable tag: 4.0.6 9 9 License: GPLv3 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 202 202 == Changelog == 203 203 204 = 4.0.5 - 21 November 2024 = 204 = 4.0.6 - 1 December 2025 = 205 * Fix - automatic temp file deletion (when used with WooCommerce forced and EDD forced file delivery) 206 207 = 4.0.5 - 21 November 2025 = 205 208 * Fix - move load_plugin_textdomain() to 'init' hook 206 209 * Tweak - provide debug log feedback for people getting unexpected white bars on PDF (answer: upgrade) -
waterwoo-pdf/trunk/waterwoo-pdf.php
r3400576 r3407018 4 4 * Plugin URI: https://wordpress.org/plugins/waterwoo-pdf/ 5 5 * Description: Custom watermark your PDF files upon WooCommerce, Download Monitor, and Easy Digital Download customer download. Since 2014. FKA "WaterWoo" 6 * Version: 4.0. 56 * Version: 4.0.6 7 7 * Author: Little Package 8 8 * Author URI: https://pdfink.com/ … … 50 50 51 51 if ( ! defined( 'WWPDF_FREE_VERSION' ) ) { 52 define( 'WWPDF_FREE_VERSION', '4.0. 5' );52 define( 'WWPDF_FREE_VERSION', '4.0.6' ); 53 53 } 54 54
Note: See TracChangeset
for help on using the changeset viewer.