Changeset 2278615
- Timestamp:
- 04/07/2020 04:41:29 PM (6 years ago)
- Location:
- cf7-db-tool/trunk
- Files:
-
- 4 edited
-
cf7-db-tool.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
src/BulkMail.php (modified) (8 diffs)
-
src/connected_mail/mailgun.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cf7-db-tool/trunk/cf7-db-tool.php
r2278550 r2278615 8 8 * Text Domain: cf7-db-tool 9 9 * Tags: contact, cf7, zapier, integration, webhook, bulk mail, contact form 7, db, export, save, wpcf7, contact form 7 db, contact form 7 database, contact form 7 data export, contact form 7 database addon 10 * Version: 4.2. 310 * Version: 4.2.4 11 11 */ 12 12 13 define('CF7_DBT_VERSION', '4.2. 3');14 define('CF7_DBT_DB_VERSION', '4.2. 3');13 define('CF7_DBT_VERSION', '4.2.4'); 14 define('CF7_DBT_DB_VERSION', '4.2.4'); 15 15 define('CF7_DBT_PATH', __DIR__); 16 16 define('CF7_DBT_URL', plugins_url(basename(CF7_DBT_PATH))); -
cf7-db-tool/trunk/readme.txt
r2278550 r2278615 3 3 Tags: contact, cf7, zapier, integration, webhook, bulk mail, contact form 7, db, export, save, wpcf7, contact form 7 db, contact form 7 database, contact form 7 data export, contact form 7 database addon 4 4 Requires at least: 4.8 5 Tested up to: 5. 36 Stable tag: 4.2. 35 Tested up to: 5.4 6 Stable tag: 4.2.4 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
cf7-db-tool/trunk/src/BulkMail.php
r2278550 r2278615 8 8 class BulkMail extends ListEntries{ 9 9 10 public function __construct(){ 11 12 $this->cf7DBBulkMail(); 13 add_action('wp_ajax_nopriv_bulkMailAjaxDataAction', array( $this, 'bulkMailAjaxDataAction' )); 14 add_action('wp_ajax_bulkMailAjaxDataAction', array( $this, 'bulkMailAjaxDataAction' )); 15 16 } 17 18 /** 19 * 20 */ 21 public function cf7DBBulkMail() { 22 // get site info to construct 'FROM' for email 23 $from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); 24 $from_email = get_bloginfo('admin_email'); 25 26 // initialize 27 $send_mail_message = false; 28 29 //wp_nonce_field( 'dbtool_send_email', 'dbtool-form-nonce' ); 30 31 if ( !empty( $_POST ) && check_admin_referer( 'dbtool_send_email', 'dbtool-form-nonce' ) ) { 32 33 34 // handle attachment 35 $attachment_path = ''; 36 if ( $_FILES ) { 37 if ( !function_exists( 'wp_handle_upload' ) ) { 38 require_once( ABSPATH . 'wp-admin/includes/file.php' ); 39 } 40 $uploaded_file = $_FILES['attachment']; 41 $upload_overrides = array( 'test_form' => false ); 42 $attachment = wp_handle_upload( $uploaded_file, $upload_overrides ); 43 44 45 if ( $attachment && ! isset( $attachment['error'] ) ) { 46 echo __( 'File is valid, and was successfully uploaded.', 'textdomain' ) . "\n"; 47 var_dump( $attachment ); 48 } else { 49 /* 50 * Error generated by _wp_handle_upload() 51 * @see _wp_handle_upload() in wp-admin/includes/file.php 52 */ 53 echo $attachment['error']; 54 } 55 56 57 } 58 59 // get the posted form values 60 $dbtool_recipient_emails = isset( $_POST['dbtool_recipient_emails'] ) ? trim($_POST['dbtool_recipient_emails']) : ''; // Get email list 61 $dbtool_subject = isset( $_POST['dbtool_subject'] ) ? stripslashes(trim($_POST['dbtool_subject'])) : ''; 62 $dbtool_body = isset( $_POST['dbtool_body'] ) ? stripslashes(nl2br($_POST['dbtool_body'])) : ''; 63 $dbtool_group_email = isset( $_POST['dbtool_group_email'] ) ? trim($_POST['dbtool_group_email']) : 'no'; 64 $recipients = explode( ',',$dbtool_recipient_emails ); // Email list to array 65 66 67 // initialize some vars 68 $errors = array(); 69 $valid_email = true; 70 71 // simple form validation 72 if ( empty( $dbtool_recipient_emails ) ) { 73 $errors[] = __( "Please enter an email recipient in the To: field.", 'dbtool' ); 74 } else { 75 // Loop through each email and validate it 76 foreach( $recipients as $recipient ) { 77 if ( !filter_var( trim($recipient), FILTER_VALIDATE_EMAIL ) ) { 78 $valid_email = false; 79 break; 80 } 81 } 82 // create appropriate error msg 83 if ( !$valid_email ) { 84 $errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'dbtool-toolkit' ); 85 } 86 } 87 if ( empty($dbtool_subject) ) $errors[] = __( "Please enter a Subject.", 'dbtool-toolkit' ); 88 if ( empty($dbtool_body) ) $errors[] = __( "Please enter a Message.", 'dbtool-toolkit' ); 89 90 // send the email if no errors were found 91 if ( empty($errors) ) { 92 $headers[] = "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; 93 $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; 94 $attachments = $attachment_path; 95 96 97 $active_mailer = get_option('active_mailer'); 98 if($active_mailer){ 99 require_once 'connected_mail/mailgun.php'; 100 101 if($dbtool_group_email === 'yes' ){ 102 103 $result = sendmailbymailgun($dbtool_recipient_emails,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments); 104 105 if(in_array('id',array_keys($result))){ 106 $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'dbtool-toolkit' ) . '</div>'; 107 } 108 else{ 109 $send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'dbtool-toolkit' ) . '</div>'; 110 } 111 }else{ 112 foreach( $recipients as $recipient ) { 113 $result = sendmailbymailgun($recipient,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments); 114 115 if(in_array('id',array_keys($result))){ 116 $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'dbtool-toolkit' ) . esc_html($recipient) . '!</div>'; 117 }else{ 118 $send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'dbtool-toolkit' ) . esc_html($recipient) . '</div>'; 119 } 120 } 121 } 122 123 124 } 125 else{ 126 if ( $dbtool_group_email === 'yes' ) { 127 if ( wp_mail( $dbtool_recipient_emails, $dbtool_subject, $dbtool_body, $headers, $attachments ) ) { 128 $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'dbtool-toolkit' ) . '</div>'; 129 } else { 130 $send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'dbtool-toolkit' ) . '</div>'; 131 } 132 } else { 133 foreach( $recipients as $recipient ) { 134 if ( wp_mail( $recipient, $dbtool_subject, $dbtool_body, $headers, $attachments ) ) { 135 $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'dbtool-toolkit' ) . esc_html($recipient) . '!</div>'; 136 } else { 137 $send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'dbtool-toolkit' ) . esc_html($recipient) . '</div>'; 138 } 139 } 140 } 141 } 142 143 144 145 // delete the uploaded file (attachment) from the server 146 if ( $attachment_path ) { 147 unlink($attachment_path); 148 } 149 } 150 } 151 ?> 10 public function __construct(){ 11 12 $this->cf7DBBulkMail(); 13 add_action('wp_ajax_nopriv_bulkMailAjaxDataAction', array( $this, 'bulkMailAjaxDataAction' )); 14 add_action('wp_ajax_bulkMailAjaxDataAction', array( $this, 'bulkMailAjaxDataAction' )); 15 16 } 17 18 /** 19 * 20 */ 21 public function cf7DBBulkMail() { 22 // get site info to construct 'FROM' for email 23 $from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); 24 $from_email = get_bloginfo('admin_email'); 25 26 // initialize 27 $send_mail_message = false; 28 29 //wp_nonce_field( 'dbtool_send_email', 'dbtool-form-nonce' ); 30 31 if ( !empty( $_POST ) && check_admin_referer( 'dbtool_send_email', 'dbtool-form-nonce' ) ) { 32 33 34 // handle attachment 35 $attachment_path = ''; 36 if ( $_FILES ) { 37 if ( !function_exists( 'wp_handle_upload' ) ) { 38 require_once( ABSPATH . 'wp-admin/includes/file.php' ); 39 } 40 $uploaded_file = $_FILES['attachment']; 41 $upload_overrides = array( 'test_form' => false ); 42 $attachment = wp_handle_upload( $uploaded_file, $upload_overrides ); 43 if ( $attachment && !isset( $attachment['error'] ) ) { 44 // file was successfully uploaded 45 $attachment_path = $attachment['file']; 46 } else { 47 // echo $attachment['error']; 48 } 49 } 50 51 52 53 54 55 56 // get the posted form values 57 $dbtool_recipient_emails = isset( $_POST['dbtool_recipient_emails'] ) ? trim($_POST['dbtool_recipient_emails']) : ''; // Get email list 58 $dbtool_subject = isset( $_POST['dbtool_subject'] ) ? stripslashes(trim($_POST['dbtool_subject'])) : ''; 59 $dbtool_body = isset( $_POST['dbtool_body'] ) ? stripslashes(nl2br($_POST['dbtool_body'])) : ''; 60 $dbtool_group_email = isset( $_POST['dbtool_group_email'] ) ? trim($_POST['dbtool_group_email']) : 'no'; 61 $recipients = explode( ',',$dbtool_recipient_emails ); // Email list to array 62 63 64 // initialize some vars 65 $errors = array(); 66 $valid_email = true; 67 68 // simple form validation 69 if ( empty( $dbtool_recipient_emails ) ) { 70 $errors[] = __( "Please enter an email recipient in the To: field.", 'dbtool' ); 71 } else { 72 // Loop through each email and validate it 73 foreach( $recipients as $recipient ) { 74 if ( !filter_var( trim($recipient), FILTER_VALIDATE_EMAIL ) ) { 75 $valid_email = false; 76 break; 77 } 78 } 79 // create appropriate error msg 80 if ( !$valid_email ) { 81 $errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'dbtool-toolkit' ); 82 } 83 } 84 if ( empty($dbtool_subject) ) $errors[] = __( "Please enter a Subject.", 'dbtool-toolkit' ); 85 if ( empty($dbtool_body) ) $errors[] = __( "Please enter a Message.", 'dbtool-toolkit' ); 86 87 // send the email if no errors were found 88 if ( empty($errors) ) { 89 $headers[] = "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; 90 $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; 91 $attachments = $attachment_path; 92 93 94 $active_mailer = get_option('active_mailer'); 95 if($active_mailer){ 96 require_once 'connected_mail/mailgun.php'; 97 98 if($dbtool_group_email === 'yes' ){ 99 100 $result = sendmailbymailgun($dbtool_recipient_emails,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments); 101 102 if(in_array('id',array_keys($result))){ 103 $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'dbtool-toolkit' ) . '</div>'; 104 } 105 else{ 106 $send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'dbtool-toolkit' ) . '</div>'; 107 } 108 }else{ 109 foreach( $recipients as $recipient ) { 110 $result = sendmailbymailgun($recipient,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments); 111 112 if(in_array('id',array_keys($result))){ 113 $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'dbtool-toolkit' ) . esc_html($recipient) . '!</div>'; 114 }else{ 115 $send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'dbtool-toolkit' ) . esc_html($recipient) . '</div>'; 116 } 117 } 118 } 119 120 121 } 122 else{ 123 if ( $dbtool_group_email === 'yes' ) { 124 if ( wp_mail( $dbtool_recipient_emails, $dbtool_subject, $dbtool_body, $headers, $attachments ) ) { 125 $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'dbtool-toolkit' ) . '</div>'; 126 } else { 127 $send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'dbtool-toolkit' ) . '</div>'; 128 } 129 } else { 130 foreach( $recipients as $recipient ) { 131 if ( wp_mail( $recipient, $dbtool_subject, $dbtool_body, $headers, $attachments ) ) { 132 $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'dbtool-toolkit' ) . esc_html($recipient) . '!</div>'; 133 } else { 134 $send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'dbtool-toolkit' ) . esc_html($recipient) . '</div>'; 135 } 136 } 137 } 138 } 139 140 141 142 // delete the uploaded file (attachment) from the server 143 if ( $attachment_path ) { 144 unlink($attachment_path); 145 } 146 } 147 } 148 ?> 152 149 153 150 … … 159 156 <div class="wrap" id="cf7-db-bulkmail-wrapper"> 160 157 <h2><?php _e( 'Send Email From Admin', 'dbtool-toolkit' ); ?></h2> 161 <?php162 163 if ( !empty($errors) ) {164 echo '<div class="error"><ul>';165 foreach ($errors as $error) {166 echo "<li>$error</li>";167 }168 echo "</ul></div>\n";169 }170 if ( $send_mail_message ) {171 echo $send_mail_message;172 }173 ?>158 <?php 159 160 if ( !empty($errors) ) { 161 echo '<div class="error"><ul>'; 162 foreach ($errors as $error) { 163 echo "<li>$error</li>"; 164 } 165 echo "</ul></div>\n"; 166 } 167 if ( $send_mail_message ) { 168 echo $send_mail_message; 169 } 170 ?> 174 171 <div> 175 172 <div id="post-body" class="metabox-holder columns-2"> 176 173 <div id="post-body-content"> 177 174 <form method="POST" id="cf7-db-bulkmail" enctype="multipart/form-data"> 178 <?php wp_nonce_field( 'dbtool_send_email', 'dbtool-form-nonce' ); ?>175 <?php wp_nonce_field( 'dbtool_send_email', 'dbtool-form-nonce' ); ?> 179 176 <table cellpadding="0" border="0" class="form-table"> 180 177 <tr> … … 192 189 <input type="email" multiple id="dbtool-recipient-emails" name="dbtool_recipient_emails" value="<?php echo esc_attr($this->cf7PluginInstector($dbtool_recipient_emails) ); ?>" required> 193 190 <div class="note"> 194 <?php _e( 'To send to multiple recipients, enter each email address separated by a comma or choose from the user list below.', 'dbtool-toolkit' ); ?>191 <?php _e( 'To send to multiple recipients, enter each email address separated by a comma or choose from the user list below.', 'dbtool-toolkit' ); ?> 195 192 </div> 196 193 <div class="select_user_wrapper"> 197 194 <select multiple="multiple" id="dbtool-user-list" name="dbtool-user-list[]"> 198 <?php199 200 201 $allMails = $this->get_prepare_mail_items();202 $usersEmail=[];203 204 foreach ($allMails as $mail){205 $fields = unserialize($mail->fields);206 207 if(!in_array($fields["your-email"],$usersEmail)){208 array_push($usersEmail,$fields["your-email"]);209 }210 211 }212 213 foreach ( $usersEmail as $email ) {214 215 echo '<option value="' . esc_html( $email ) . '">' . esc_html( $email ) . '</option>';216 };217 ?>195 <?php 196 197 198 $allMails = $this->get_prepare_mail_items(); 199 $usersEmail=[]; 200 201 foreach ($allMails as $mail){ 202 $fields = unserialize($mail->fields); 203 204 if(!in_array($fields["your-email"],$usersEmail)){ 205 array_push($usersEmail,$fields["your-email"]); 206 } 207 208 } 209 210 foreach ( $usersEmail as $email ) { 211 212 echo '<option value="' . esc_html( $email ) . '">' . esc_html( $email ) . '</option>'; 213 }; 214 ?> 218 215 </select> 219 216 <div class="select-all"> … … 228 225 229 226 </optgroup> 230 <?php231 232 $allForms = $this->get_prepare_forms_list();233 foreach ($allForms as $form){234 echo ' <option value="'.$form->form_id.'">'.$form->title.'</option>';235 }236 ?>237 238 <optgroup label="Upload By CSV">239 <option value="csv"> <?php _e( 'Select CSV', 'dumhall' ); ?> </option>240 </optgroup>227 <?php 228 229 $allForms = $this->get_prepare_forms_list(); 230 foreach ($allForms as $form){ 231 echo ' <option value="'.$form->form_id.'">'.$form->title.'</option>'; 232 } 233 ?> 234 235 <optgroup label="Upload By CSV"> 236 <option value="csv"> <?php _e( 'Select CSV', 'dumhall' ); ?> </option> 237 </optgroup> 241 238 242 239 </select> … … 273 270 <th scope=”row”><label for="dbtool_body">Message:</label></th> 274 271 <td align="left"> 275 <?php276 $settings = array( "editor_height" => "200" );277 wp_editor( $this->cf7PluginInstector($dbtool_body), "dbtool_body", $settings );278 ?>272 <?php 273 $settings = array( "editor_height" => "200" ); 274 wp_editor( $this->cf7PluginInstector($dbtool_body), "dbtool_body", $settings ); 275 ?> 279 276 </td> 280 277 </tr> … … 315 312 316 313 317 <?php318 }319 320 // Ajax request for load targeted form users321 public function bulkMailAjaxDataActionss(){314 <?php 315 } 316 317 // Ajax request for load targeted form users 318 public function bulkMailAjaxDataActionss(){ 322 319 323 320 324 321 // this is required to terminate immediately and return a proper response 325 echo "test";326 $cf7form = '';327 if(isset($_POST['cf7form'])){328 $cf7form = sanitize_text_field($_POST['cf7form']);329 }322 echo "test"; 323 $cf7form = ''; 324 if(isset($_POST['cf7form'])){ 325 $cf7form = sanitize_text_field($_POST['cf7form']); 326 } 330 327 // if(isset($_POST['session'])){ 331 328 // $session = sanitize_text_field($_POST['session']); … … 359 356 // 360 357 // }; 361 echo '<option value="maruf@gmail.com">'.$cf7form.'</option>';362 wp_die();363 }364 365 /**366 * Helper function for form values367 *368 * @since 0.9369 *370 * @param string $var Var name to test isset371 *372 * @return string $var value if isset or ''373 */374 public function cf7PluginInstector(&$var) {375 return isset($var) ? $var : '';376 }377 378 379 public function member_search_script(){380 ?>358 echo '<option value="maruf@gmail.com">'.$cf7form.'</option>'; 359 wp_die(); 360 } 361 362 /** 363 * Helper function for form values 364 * 365 * @since 0.9 366 * 367 * @param string $var Var name to test isset 368 * 369 * @return string $var value if isset or '' 370 */ 371 public function cf7PluginInstector(&$var) { 372 return isset($var) ? $var : ''; 373 } 374 375 376 public function member_search_script(){ 377 ?> 381 378 <script type="text/javascript" > 382 379 jQuery(document).ready(function($) { … … 392 389 }); 393 390 </script> 394 <?php395 }391 <?php 392 } 396 393 } 397 394 -
cf7-db-tool/trunk/src/connected_mail/mailgun.php
r2278541 r2278615 8 8 function sendmailbymailgun($to,$toname,$mailfromname,$mailfrom,$subject,$html, $attachments){ 9 9 10 // Get File info 11 $finfo = finfo_open(FILEINFO_MIME); 12 $mimeType = finfo_file($finfo, $attachments); 13 finfo_close($finfo); 14 if ($mimeType) { 15 $tempArr = explode(";", $mimeType); 16 $mimeType = $tempArr[0]; 10 11 12 if($attachments){ 13 // Get File info 14 $finfo = finfo_open(FILEINFO_MIME); 15 $mimeType = finfo_file($finfo, $attachments); 16 finfo_close($finfo); 17 if ($mimeType) { 18 $tempArr = explode(";", $mimeType); 19 $mimeType = $tempArr[0]; 20 } 21 $array_data = array( 22 'from'=> $mailfromname .'<'.$mailfrom.'>', 23 'to'=>$to, 24 'subject'=>$subject, 25 'html'=>$html, 26 'text'=>$html, 27 'attachment[1]' => curl_file_create($attachments, $mimeType), 28 'o:tracking'=>'yes', 29 'o:tracking-clicks'=>'yes', 30 'o:tracking-opens'=>'yes', 31 // 'o:tag'=>$tag, 32 // 'h:Reply-To'=>$replyto 33 ); 34 }else{ 35 $array_data = array( 36 'from'=> $mailfromname .'<'.$mailfrom.'>', 37 'to'=>$to, 38 'subject'=>$subject, 39 'html'=>$html, 40 'text'=>$html, 41 'o:tracking'=>'yes', 42 'o:tracking-clicks'=>'yes', 43 'o:tracking-opens'=>'yes', 44 // 'o:tag'=>$tag, 45 // 'h:Reply-To'=>$replyto 46 ); 47 17 48 } 18 49 19 $array_data = array(20 'from'=> $mailfromname .'<'.$mailfrom.'>',21 'to'=>$to,22 'subject'=>$subject,23 'html'=>$html,24 'text'=>$html,25 'attachment[1]' => curl_file_create($attachments, $mimeType),26 'o:tracking'=>'yes',27 'o:tracking-clicks'=>'yes',28 'o:tracking-opens'=>'yes',29 // 'o:tag'=>$tag,30 // 'h:Reply-To'=>$replyto31 );32 50 33 51 $session = curl_init(MAILGUN_URL.'/messages');
Note: See TracChangeset
for help on using the changeset viewer.