css
1 year ago
img
1 year ago
js
1 year ago
partials
1 year ago
class-email.php
1 year ago
class-eqw-advance.php
1 year ago
class-eqw-enquiry-cart.php
1 year ago
class-eqw-enquiry-shortcode.php
1 year ago
class-eqw-product.php
1 year ago
class-eqw-save-enquiry.php
1 year ago
class-pisol-enquiry-quotation-woocommerce-public.php
1 year ago
class-pisol-form.php
1 year ago
class-webhook.php
1 year ago
index.php
1 year ago
class-email.php
161 lines
| 1 | <?php |
| 2 | |
| 3 | class class_pisol_eqw_email{ |
| 4 | |
| 5 | public $items; |
| 6 | public $enq_id; |
| 7 | public $email; |
| 8 | public $subject; |
| 9 | public $message; |
| 10 | public $customer_email; |
| 11 | public $customer_subject; |
| 12 | public $send_copy_to_customer; |
| 13 | public $products; |
| 14 | |
| 15 | function __construct($items, $enq_id){ |
| 16 | |
| 17 | $this->items = $items; |
| 18 | $this->enq_id = $enq_id; |
| 19 | |
| 20 | $this->email = $this->explodeEmail(get_option('pi_eqw_email', get_option('admin_email'))); |
| 21 | |
| 22 | |
| 23 | $this->subject = str_replace('{enquiry_no}', $this->enq_id, get_option('pi_eqw_email_subject','New Enquiry')); |
| 24 | |
| 25 | $this->message = $this->message(); |
| 26 | |
| 27 | $this->customer_email = sanitize_email($_POST['pi_email']); |
| 28 | $this->customer_subject = str_replace('{enquiry_no}', $this->enq_id,__('Your enquiry is submitted, your enquiry no is {enquiry_no}', 'pisol-enquiry-quotation-woocommerce')); |
| 29 | $this->send_copy_to_customer = 1; |
| 30 | |
| 31 | add_action('phpmailer_init',array($this,'attachInlineImage')); |
| 32 | |
| 33 | } |
| 34 | |
| 35 | function explodeEmail($email_ids){ |
| 36 | $array = explode(',',$email_ids); |
| 37 | return $array[0]; |
| 38 | } |
| 39 | |
| 40 | function sendEmail(){ |
| 41 | $this->send(); |
| 42 | if($this->send_copy_to_customer == 1){ |
| 43 | $this->sendCustomer(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | function message(){ |
| 48 | ob_start(); |
| 49 | |
| 50 | $woo_template = get_option('pi_eqw_email_template',1); |
| 51 | if(empty($woo_template)){ |
| 52 | include_once('partials/email-template.php'); |
| 53 | }else{ |
| 54 | include_once('partials/email-template-woo.php'); |
| 55 | } |
| 56 | |
| 57 | $template = ob_get_contents(); |
| 58 | ob_end_clean(); |
| 59 | |
| 60 | ob_start(); |
| 61 | $this->products = class_eqw_enquiry_cart::getProductsInEnquirySession(); |
| 62 | include_once('partials/pisol-eqw-email.php'); |
| 63 | $content = ob_get_contents(); |
| 64 | ob_end_clean(); |
| 65 | |
| 66 | $logo = $this->logo(); |
| 67 | |
| 68 | $find = array('{content}','{logo}', '{enquiry_no}'); |
| 69 | |
| 70 | $replace = array($content, $logo, $this->enq_id); |
| 71 | |
| 72 | $message = str_replace( $find, $replace, $template); |
| 73 | |
| 74 | return $message; |
| 75 | } |
| 76 | |
| 77 | function send(){ |
| 78 | $headers = array('Content-Type: text/html; charset=UTF-8', 'Reply-To: '.$this->customer_email); |
| 79 | |
| 80 | if(wp_mail($this->email, $this->subject, $this->message, $headers)){ |
| 81 | return true; |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | function sendCustomer(){ |
| 87 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
| 88 | |
| 89 | if(wp_mail($this->customer_email, $this->customer_subject, $this->message, $headers)){ |
| 90 | return true; |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | function attachInlineImage() { |
| 96 | global $phpmailer; |
| 97 | |
| 98 | $add_img_url = get_option('pi_enq_add_img_url',''); |
| 99 | |
| 100 | if(!empty($add_img_url)) return; |
| 101 | |
| 102 | /** attach logo */ |
| 103 | $file = plugin_dir_path( dirname( __FILE__ ) ) . '/public/img/Logo.png'; //phpmailer will load this file |
| 104 | $uid = 'pi_logo'; //will map it to this UID |
| 105 | $name = 'Logo.png'; //this will be the file name for the attachment |
| 106 | if (is_file($file)) { |
| 107 | $phpmailer->AddEmbeddedImage($file, $uid, $name); |
| 108 | } |
| 109 | /* end attach logo */ |
| 110 | |
| 111 | $this->attachProductImages($phpmailer); |
| 112 | } |
| 113 | |
| 114 | function attachImage($image_id, $phpmailer){ |
| 115 | $file = get_attached_file($image_id); |
| 116 | $uid = 'image_'.$image_id; |
| 117 | $name = basename(get_attached_file($image_id)); |
| 118 | if (is_file($file)) { |
| 119 | $phpmailer->AddEmbeddedImage($file, $uid, $name); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | function attachProductImages($phpmailer){ |
| 124 | foreach($this->products as $key => $product){ |
| 125 | $prod = wc_get_product($product['id']); |
| 126 | $image_id = $prod->get_image_id(); |
| 127 | $this->attachImage($image_id, $phpmailer); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | function logo(){ |
| 132 | $show_logo = get_option('pi_eqw_email_disable_logo',1); |
| 133 | |
| 134 | if(empty($show_logo)) return ''; |
| 135 | |
| 136 | $add_img_url = get_option('pi_enq_add_img_url',''); |
| 137 | |
| 138 | if(!empty($add_img_url)){ |
| 139 | $image_id = plugin_dir_url( dirname( __FILE__ ) ) . 'public/img/Logo.png'; |
| 140 | }else{ |
| 141 | $image_id = 'cid:pi_logo'; |
| 142 | } |
| 143 | |
| 144 | return '<img alt="Image" border="0" src="'.$image_id.'" style="max-width:100%; width:300px; height:auto;">'; |
| 145 | |
| 146 | } |
| 147 | |
| 148 | static function imageUrl( $image_id ){ |
| 149 | $img = 'image_'.$image_id; |
| 150 | $url = 'cid:'.$img; |
| 151 | $add_img_url = get_option('pi_enq_add_img_url',''); |
| 152 | if(!empty($add_img_url)){ |
| 153 | $url = wp_get_attachment_url( $image_id ); |
| 154 | } |
| 155 | $src = apply_filters('pi_eqw_image_src', $url, $image_id); |
| 156 | return $src; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | |
| 161 |