Changeset 3190613
- Timestamp:
- 11/17/2024 12:32:19 PM (17 months ago)
- Location:
- pdf-for-woocommerce/trunk
- Files:
-
- 5 edited
-
backend/settings.php (modified) (3 diffs)
-
frontend/index.php (modified) (1 diff)
-
pdf-for-woocommerce.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
woocommerce/emails/index.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pdf-for-woocommerce/trunk/backend/settings.php
r3189941 r3190613 8 8 add_action( 'yeepdf_custom_sizes', array($this,"add_sizes")); 9 9 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); 10 } 11 public static function generateRandomString($length = 15) { 12 $characters = '0123456789abcdefghijklmnopqrstuvwxyz_'; 13 $charactersLength = strlen($characters); 14 $randomString = ''; 15 for ($i = 0; $i < $length; $i++) { 16 $randomString .= $characters[random_int(0, $charactersLength - 1)]; 17 } 18 return $randomString; 19 } 20 public static function maybe_get_random_dir() { 21 $uploads_folder = apply_filters("yeepdf_folder_download","pdfs/downloads"); 22 return $uploads_folder; 23 } 24 public static function maybe_add_random_dir() { 25 $upload_dir = wp_upload_dir(); 26 $uploads_folder = self::maybe_get_random_dir(); 27 $dir = $upload_dir['basedir'] . '/'.$uploads_folder.'/'; 28 $url = $upload_dir['baseurl'] . '/'.$uploads_folder.'/'; 29 do { 30 $rand_max = mt_getrandmax(); 31 $rand = self::generateRandomString(); 32 $dir_new = path_join( $dir, $rand ); 33 $url_new = $url.$rand; 34 } while ( file_exists( $dir_new ) ); 35 if ( wp_mkdir_p( $dir_new ) ) { 36 return array("path"=>$dir_new."/","url"=>$url_new."/"); 37 } 38 return array("path"=>$dir,"url"=>$url);; 39 } 40 public static function destroy_all_files($dirPath=null) { 41 if(!$dirPath) { 42 $upload_dir = wp_upload_dir(); 43 $uploads_folder = self::maybe_get_random_dir(); 44 $dirPath = $upload_dir['basedir'] . '/'.$uploads_folder.'/'; 45 if (! is_dir($dirPath)) { 46 throw new InvalidArgumentException("$dirPath must be a directory"); 47 } 48 if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { 49 $dirPath .= '/'; 50 } 51 } 52 $files = glob($dirPath . '*', GLOB_MARK); 53 foreach ($files as $file) { 54 if (is_dir($file)) { 55 self::destroy_all_files($file); 56 } else { 57 unlink($file); 58 } 59 } 60 rmdir($dirPath); 10 61 } 11 62 public function plugins_loaded() { … … 149 200 $part = $path_main.$files['name']; 150 201 if ( ! file_exists( $path_main ) ) { 151 wp_mkdir_p( $path_main );152 }202 wp_mkdir_p( $path_main ); 203 } 153 204 if(file_exists($part)){ 154 205 unlink($part); … … 340 391 <?php $save = get_option("pdf_creator_save_pdf","") ?> 341 392 <input <?php checked($save,"yes") ?> type="checkbox" name="pdf_creator_save_pdf" value="yes"> 342 <?php esc_html_e("It will automatically delete pdf when sending attachment to email","pdf-for-wpforms") ?>393 <?php esc_html_e("It will automatically delete the PDF after attaching the file to the email.","pdf-for-wpforms") ?> 343 394 </td> 344 395 </tr> -
pdf-for-woocommerce/trunk/frontend/index.php
r3189941 r3190613 278 278 break; 279 279 case "upload": 280 $path_main = $upload_dir['basedir'] . '/pdfs/'; 281 if ( ! file_exists( $path_main ) ) { 282 wp_mkdir_p( $path_main ); 280 $upload_dir = Yeepdf_Settings_Main::maybe_add_random_dir(); 281 $path_name = $upload_dir["path"].$data_attrs["name"].".pdf"; 282 $url_name = $upload_dir["url"].$data_attrs["name"].".pdf"; 283 if(file_exists($path_name)){ 284 unlink($path_name); 283 285 } 284 $file_name = $path_main.$data_attrs["name"].".pdf";285 if(file_exists($file_name)){286 unlink($file_name);287 }288 286 $mpdf->WriteHTML($html); 289 $output = $mpdf->Output($ file_name,"F");290 return $file_name;287 $output = $mpdf->Output($path_name,"F"); 288 return array("path"=>$path_name,"url"=>$url_name); 291 289 break; 292 290 case "html": -
pdf-for-woocommerce/trunk/pdf-for-woocommerce.php
r3189947 r3190613 6 6 * Text Domain: pdf-for-woocommerce 7 7 * Domain Path: /languages 8 * Version: 4. 3.08 * Version: 4.4.0 9 9 * Requires PHP: 5.6 10 10 * Author: add-ons.org … … 36 36 include_once YEEPDF_CREATOR_BUILDER_PATH."libs/phpqrcode.php"; 37 37 include_once YEEPDF_CREATOR_BUILDER_PATH."frontend/index.php"; 38 register_activation_hook( __FILE__, array($this,'register_activation_hook') );39 add_action( 'yeepdf_remove_all_file', array($this,"yeepdf_remove_all_file") );40 }41 function register_activation_hook(){42 if (! wp_next_scheduled ( 'yeepdf_remove_all_file' )) {43 wp_schedule_event( time(), 'daily', 'yeepdf_remove_all_file' );44 }45 }46 function yeepdf_remove_all_file(){47 $check_settings = get_option("pdf_creator_save_pdf");48 if($check_settings == "yes"){49 $upload_dir = wp_upload_dir();50 $path_main = $upload_dir['basedir'] . '/pdfs/*';51 $files = glob($path_main);52 foreach($files as $file){ // iterate files53 if(is_file($file)) {54 unlink($file); // delete file55 }56 }57 }58 38 } 59 39 } … … 174 154 } 175 155 } 176 177 156 } 178 157 } -
pdf-for-woocommerce/trunk/readme.txt
r3189947 r3190613 4 4 Requires at least: 2.0 5 5 Tested up to: 6.7 6 Stable tag: 4. 3.06 Stable tag: 4.4.0 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later … … 104 104 105 105 == Changelog == 106 = 4.4.0 = 107 - Fixed: Do not save PDFs on the server 108 - Added: Secure the folder for downloading PDFs 109 106 110 = 4.3.0 = 107 111 - Added: Random number shortcode -
pdf-for-woocommerce/trunk/woocommerce/emails/index.php
r3157698 r3190613 15 15 add_action( 'manage_woocommerce_page_wc-orders_custom_column', array($this,'add_buton_link'), 10, 2 ); 16 16 //add_filter('bulk_actions-edit-shop_order', array($this,"acc_actions"),10, 2); ///7.8 don't update 17 add_action( "woocommerce_email_sent", array($this,"yeepdf_remove_all_file")); 17 18 } 19 function yeepdf_remove_all_file(){ 20 $check_settings = get_option("pdf_creator_save_pdf"); 21 if($check_settings == "yes"){ 22 Yeepdf_Settings_Main::destroy_all_files(); 23 } 24 } 18 25 function acc_actions($actions){ 19 26 $actions['pdf_creator'] = esc_html__( 'Invoices PDF', "pdf-customizer-for-woocommerce" ); … … 46 53 switch( $my_account_buttons ){ 47 54 case "available": 55 $folder_downloads = Yeepdf_Settings_Main::maybe_get_random_dir(); 56 $upload_dir = wp_upload_dir(); 48 57 foreach ($order->get_meta_data() as $object) { 49 58 $object_array = array_values((array)$object); … … 51 60 if ('_yeepdf' == $object_item['key']) {; 52 61 if(isset($object_item['value'][$data["id"]])){ 53 $link_download_pdfs[$data["id"]] = $object_item['value'][$data["id"]]; 62 $links = explode( $folder_downloads, $object_item['value'][$data["id"]]["link"] ); 63 if(isset($links[1])){ 64 if (file_exists($upload_dir["basedir"]."/".$folder_downloads.$links[1])) { 65 $link_download_pdfs[$data["id"]] = $object_item['value'][$data["id"]]; 66 } 67 } 54 68 } 55 69 break; … … 204 218 ); 205 219 $data_send_settings_download = apply_filters("pdf_before_render_datas",$data_send_settings_download); 206 $ path=Yeepdf_Create_PDF::pdf_creator_preview($data_send_settings_download);207 $attachments[] = $ path;208 $link_pdf = $ upload_dir['baseurl'] . '/pdfs/'.$name.".pdf";220 $folder_uploads =Yeepdf_Create_PDF::pdf_creator_preview($data_send_settings_download); 221 $attachments[] = $folder_uploads["path"]; 222 $link_pdf = $folder_uploads["url"]; 209 223 $yeepdf_data[$data["id"]] = array("label"=>$data["label"],"link"=>$link_pdf,"date"=>date(get_option('date_format'))); 210 224 }
Note: See TracChangeset
for help on using the changeset viewer.