Esempio n. 1
0
 public function subscribe($data)
 {
     $query = $this->db->query("SELECT history_id, stats_personal_id FROM `" . DB_PREFIX . "ne_stats_personal` WHERE stats_personal_id = '" . (int) $data['uid'] . "' AND email = '" . $this->db->escape($data['email']) . "'");
     if (!$query->row) {
         return false;
     }
     $result = false;
     $email = $data['email'];
     $query = $this->db->query("SELECT customer_id FROM " . DB_PREFIX . "customer WHERE email = '" . $this->db->escape($email) . "' AND store_id = '" . (int) $this->config->get('config_store_id') . "'");
     $info = $query->row;
     if ($info) {
         $this->db->query("UPDATE " . DB_PREFIX . "customer SET `newsletter` = '" . (int) (!$this->config->get('ne_subscribe_confirmation')) . "' WHERE customer_id = '" . (int) $info['customer_id'] . "'");
         $result = true;
     }
     $query = $this->db->query("SELECT marketing_id FROM " . DB_PREFIX . "ne_marketing WHERE email = '" . $this->db->escape($email) . "' AND store_id = '" . (int) $this->config->get('config_store_id') . "'");
     $info = $query->row;
     if ($info) {
         $this->db->query("UPDATE " . DB_PREFIX . "ne_marketing SET `subscribed` = '" . (int) (!$this->config->get('ne_subscribe_confirmation')) . "' WHERE marketing_id = '" . (int) $info['marketing_id'] . "'");
         $result = true;
     }
     if ($result && $this->config->get('ne_subscribe_confirmation')) {
         require_once DIR_SYSTEM . 'library/mail_ne.php';
         $mail = new Mail_NE();
         if ($this->config->get('ne_use_smtp')) {
             $mail_config = $this->config->get('ne_smtp');
             $mail->protocol = $mail_config[$data['store_id']]['protocol'];
             $mail->parameter = $mail_config[$data['store_id']]['parameter'];
             $mail->hostname = $mail_config[$data['store_id']]['host'];
             $mail->username = $mail_config[$data['store_id']]['username'];
             $mail->password = $mail_config[$data['store_id']]['password'];
             $mail->port = $mail_config[$data['store_id']]['port'];
             $mail->timeout = $mail_config[$data['store_id']]['timeout'];
             $mail->setFrom($mail_config[$data['store_id']]['email']);
         } else {
             $mail->protocol = $this->config->get('config_mail_protocol');
             $mail->parameter = $this->config->get('config_mail_parameter');
             $mail->hostname = $this->config->get('config_smtp_host');
             $mail->username = $this->config->get('config_smtp_username');
             $mail->password = $this->config->get('config_smtp_password');
             $mail->port = $this->config->get('config_smtp_port');
             $mail->timeout = $this->config->get('config_smtp_timeout');
             $mail->setFrom($this->config->get('config_email'));
         }
         $mail->setTo($email);
         $mail->setSender($this->config->get('config_name'));
         $subject = $this->config->get('ne_subscribe_confirmation_subject');
         $subject = $subject[$this->config->get('config_store_id')][$this->config->get('config_language_id')];
         $message = $this->config->get('ne_subscribe_confirmation_message');
         $message = $message[$this->config->get('config_store_id')][$this->config->get('config_language_id')];
         if ($info['firstname']) {
             $info['firstname'] = mb_convert_case($info['firstname'], MB_CASE_TITLE, 'UTF-8');
         }
         if ($info['lastname']) {
             $info['lastname'] = mb_convert_case($info['lastname'], MB_CASE_TITLE, 'UTF-8');
         }
         $link = HTTPS_SERVER . 'index.php?route=ne/subscribe/confirm&code=' . md5($this->config->get('ne_key') . $email) . '&email=' . $email;
         $subject = str_replace(array('{name}', '{lastname}', '{email}', '{link}'), array($info['firstname'], $info['lastname'], $email, $link), $subject);
         $message = str_replace(array('{name}', '{lastname}', '{email}', '{link}'), array($info['firstname'], $info['lastname'], $email, $link), $message);
         $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
         $mail->setSubject($subject);
         $mail->setHtml($message);
         $mail->send();
     }
     return $result;
 }
Esempio n. 2
0
 public function send($data)
 {
     require_once DIR_SYSTEM . 'library/mail_ne.php';
     $message = '<html dir="ltr" lang="en">' . PHP_EOL;
     $message .= '<head>' . PHP_EOL;
     $message .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . PHP_EOL;
     $message .= '<title>' . $data['subject'] . '</title>' . PHP_EOL;
     if (!empty($data['custom_css'])) {
         $message .= html_entity_decode($data['custom_css'], ENT_COMPAT, 'UTF-8') . PHP_EOL;
     }
     $message .= '</head>' . PHP_EOL;
     $message .= '<body style="padding:0;margin:0;">' . $data['message'] . '</body>' . PHP_EOL;
     $message .= '</html>' . PHP_EOL;
     $message = str_replace(array(chr(3)), '', $message);
     $emails_count = count($data['emails']);
     if (!isset($data['history_id'])) {
         $newsletter_id = $this->addHistory(array('to' => $data['to'], 'subject' => $data['subject'], 'message' => $data['message'], 'store_id' => $data['store_id'], 'template_id' => $data['template_id'], 'language_id' => $data['language_id'], 'queue' => $this->config->get('ne_throttle') && $emails_count > $this->config->get('ne_throttle_count') ? 0 : $emails_count, 'recipients' => $emails_count));
     } else {
         $newsletter_id = (int) $data['history_id'];
     }
     if (isset($data['store_id']) && $data['store_id'] > 0) {
         $store = $this->getStore($data['store_id']);
         if ($store) {
             $url = rtrim($store['url'], '/') . '/';
         } else {
             $url = HTTP_SERVER;
         }
     } else {
         $url = HTTP_SERVER;
     }
     libxml_use_internal_errors(true);
     $dom = new DOMDocument();
     $dom->loadHTML($message);
     foreach ($dom->getElementsByTagName('a') as $node) {
         if ($node->hasAttribute('href')) {
             $link = $node->getAttribute('href');
             if (strpos($link, 'http://') === 0 || strpos($link, 'https://') === 0) {
                 $add_key = strpos($link, '{key}') !== false || strpos($link, '%7Bkey%7D') !== false;
                 $node->setAttribute('href', $url . 'index.php?route=ne/track/click&amp;link=' . urlencode(base64_encode($link)) . '&amp;uid={uid}&amp;language=' . $data['language_code'] . ($add_key ? '&amp;key={key}' : ''));
             }
         }
     }
     if ($this->config->get('ne_embedded_images')) {
         if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
             $server = defined('HTTPS_IMAGE') ? HTTPS_IMAGE : HTTPS_SERVER . 'image/';
         } else {
             $server = defined('HTTP_IMAGE') ? HTTP_IMAGE : HTTP_SERVER . 'image/';
         }
         foreach ($dom->getElementsByTagName('img') as $node) {
             if ($node->hasAttribute('src')) {
                 $src = $node->getAttribute('src');
                 $src = str_replace($server, DIR_IMAGE, $src);
                 $node->setAttribute('src', $this->base64_encode_image($src));
             }
         }
     }
     $message = $dom->saveHTML();
     libxml_clear_errors();
     $message .= '<div><img width="0" height="0" alt="" src="' . $url . 'index.php?route=ne/track/gif&amp;uid={uid}" /></div>';
     $store_info = $this->getStore($data['store_id']);
     if ($store_info) {
         $store_name = $store_info['name'];
     } else {
         $store_name = $this->config->get('config_name');
     }
     $this->load->model('setting/setting');
     $store_info = $this->model_setting_setting->getSetting('config', $data['store_id']);
     foreach ($data['emails'] as $email => $info) {
         if ($this->config->get('ne_throttle')) {
             if ($emails_count > $this->config->get('ne_throttle_count')) {
                 $this->db->query("INSERT INTO " . DB_PREFIX . "ne_queue SET email = '" . $this->db->escape($email) . "', firstname = '" . $this->db->escape($info['firstname']) . "', lastname = '" . $this->db->escape($info['lastname']) . "', history_id = '" . (int) $newsletter_id . "'");
                 continue;
             }
         }
         if (isset($info['queue_id'])) {
             $this->db->query("UPDATE " . DB_PREFIX . "ne_queue SET `locked` = '1' WHERE queue_id = '" . (int) $info['queue_id'] . "'");
         }
         $mail = new Mail_NE();
         if ($this->config->get('ne_use_smtp')) {
             $mail_config = $this->config->get('ne_smtp');
             $mail->protocol = $mail_config[$data['store_id']]['protocol'];
             $mail->parameter = $mail_config[$data['store_id']]['parameter'];
             $mail->hostname = $mail_config[$data['store_id']]['host'];
             $mail->username = $mail_config[$data['store_id']]['username'];
             $mail->password = $mail_config[$data['store_id']]['password'];
             $mail->port = $mail_config[$data['store_id']]['port'];
             $mail->timeout = $mail_config[$data['store_id']]['timeout'];
             $mail->setFrom($mail_config[$data['store_id']]['email']);
         } else {
             $mail->protocol = $this->config->get('config_mail_protocol');
             $mail->parameter = $this->config->get('config_mail_parameter');
             $mail->hostname = $this->config->get('config_smtp_host');
             $mail->username = $this->config->get('config_smtp_username');
             $mail->password = $this->config->get('config_smtp_password');
             $mail->port = $this->config->get('config_smtp_port');
             $mail->timeout = $this->config->get('config_smtp_timeout');
             $mail->setFrom($store_info['config_email']);
         }
         $mail->setTo($email);
         if ($this->config->get('ne_bounce')) {
             $mail->setReturn($this->config->get('ne_bounce_email'));
         }
         $mail->setSender($store_name);
         if (isset($data['attachments']) && $data['attachments']) {
             foreach ($data['attachments'] as $attachment) {
                 $mail->addAttachment($attachment, basename($attachment));
             }
         }
         $subject_to_send = $data['subject'];
         $message_to_send = str_replace(array('{key}', '%7Bkey%7D'), md5($this->config->get('ne_key') . $email), $message);
         if ($info) {
             $firstname = mb_convert_case($info['firstname'], MB_CASE_TITLE, 'UTF-8');
             $lastname = mb_convert_case($info['lastname'], MB_CASE_TITLE, 'UTF-8');
             $subject_to_send = str_replace(array('{name}', '{lastname}', '{email}'), array($firstname, $lastname, $email), $subject_to_send);
             $message_to_send = str_replace(array('{name}', '{lastname}', '{email}'), array($firstname, $lastname, $email), $message_to_send);
             if (isset($info['reward'])) {
                 $subject_to_send = str_replace('{reward}', $info['reward'], $subject_to_send);
                 $message_to_send = str_replace('{reward}', $info['reward'], $message_to_send);
             }
         }
         $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "ne_stats_personal SET history_id = '" . (int) $newsletter_id . "', email = '" . $this->db->escape($email) . "', views = '0'");
         $personal_id = $this->db->getLastId();
         if (!$personal_id) {
             $personal_id = $this->db->query("SELECT stats_personal_id FROM " . DB_PREFIX . "ne_stats_personal WHERE history_id = '" . (int) $newsletter_id . "' AND email = '" . $this->db->escape($email) . "'")->row;
             if ($personal_id) {
                 $personal_id = $personal_id['stats_personal_id'];
             }
         }
         if ($personal_id) {
             $uid = urlencode(base64_encode($email . '|' . $personal_id));
             $message_to_send = str_replace(array('{uid}', '%7Buid%7D'), $uid, $message_to_send);
             $mail->addHeader('X-NEMail', $uid);
         }
         $message_to_send = html_entity_decode($message_to_send, ENT_QUOTES, 'UTF-8');
         $mail->setSubject($subject_to_send);
         if ($data['text_message_products']) {
             $data['text_message'] .= PHP_EOL . PHP_EOL . $url . 'index.php?route=ne/show&uid=' . (isset($uid) ? $uid : '');
         }
         if ($data['text_message']) {
             $mail->setText($data['text_message']);
         }
         $mail->setHtml($message_to_send);
         $send_ok = $mail->send();
         if (isset($info['queue_id'])) {
             $this->db->query("UPDATE " . DB_PREFIX . "ne_queue SET retries = retries + 1 WHERE queue_id = '" . (int) $info['queue_id'] . "'");
         }
         if ($send_ok && isset($info['queue_id']) || !$send_ok && isset($info['queue_id']) && isset($info['retries']) && $info['retries'] > $this->config->get('ne_sent_retries')) {
             $this->remove_queue($info['queue_id']);
             $this->update_stat($newsletter_id);
         }
         if (!$send_ok && !isset($info['queue_id']) || !$send_ok && isset($info['queue_id']) && isset($info['retries']) && $info['retries'] > $this->config->get('ne_sent_retries')) {
             $this->db->query("UPDATE " . DB_PREFIX . "ne_stats_personal SET `success` = '0' WHERE stats_personal_id = '" . (int) $personal_id . "'");
         }
     }
 }
Esempio n. 3
0
 public function subscribe($data, $salt, $list = array())
 {
     if (!isset($data['lastname'])) {
         $data['lastname'] = '';
     }
     if (!isset($data['name'])) {
         $data['name'] = '';
     }
     $code = md5($salt . $data['email']);
     $this->db->query("INSERT INTO " . DB_PREFIX . "ne_marketing SET email = '" . $this->db->escape($data['email']) . "', firstname = '" . $this->db->escape($data['name']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', code = '" . $this->db->escape($code) . "', store_id = '" . (int) $this->config->get('config_store_id') . "', subscribed = '" . (int) (!$this->config->get('ne_subscribe_confirmation')) . "' ON DUPLICATE KEY UPDATE subscribed = '" . (int) (!$this->config->get('ne_subscribe_confirmation')) . "', firstname = '" . $this->db->escape($data['name']) . "', lastname = '" . $this->db->escape($data['lastname']) . "'");
     if ($this->db->countAffected() > 0) {
         if ($list) {
             $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "ne_marketing WHERE email = '" . $this->db->escape($data['email']) . "' AND store_id = '" . (int) $this->config->get('config_store_id') . "'");
             $this->db->query("DELETE FROM " . DB_PREFIX . "ne_marketing_to_list WHERE marketing_id = '" . (int) $query->row['marketing_id'] . "'");
             foreach ($list as $id) {
                 $this->db->query("INSERT INTO " . DB_PREFIX . "ne_marketing_to_list SET marketing_id = '" . (int) $query->row['marketing_id'] . "', marketing_list_id = '" . (int) $id . "'");
             }
         }
         if ($this->config->get('ne_subscribe_confirmation')) {
             require_once DIR_SYSTEM . 'library/mail_ne.php';
             $mail = new Mail_NE();
             if ($this->config->get('ne_use_smtp')) {
                 $mail_config = $this->config->get('ne_smtp');
                 $mail->protocol = $mail_config[$data['store_id']]['protocol'];
                 $mail->parameter = $mail_config[$data['store_id']]['parameter'];
                 $mail->hostname = $mail_config[$data['store_id']]['host'];
                 $mail->username = $mail_config[$data['store_id']]['username'];
                 $mail->password = $mail_config[$data['store_id']]['password'];
                 $mail->port = $mail_config[$data['store_id']]['port'];
                 $mail->timeout = $mail_config[$data['store_id']]['timeout'];
                 $mail->setFrom($mail_config[$data['store_id']]['email']);
             } else {
                 $mail->protocol = $this->config->get('config_mail_protocol');
                 $mail->parameter = $this->config->get('config_mail_parameter');
                 $mail->hostname = $this->config->get('config_smtp_host');
                 $mail->username = $this->config->get('config_smtp_username');
                 $mail->password = $this->config->get('config_smtp_password');
                 $mail->port = $this->config->get('config_smtp_port');
                 $mail->timeout = $this->config->get('config_smtp_timeout');
                 $mail->setFrom($this->config->get('config_email'));
             }
             $mail->setTo($data['email']);
             $mail->setSender($this->config->get('config_name'));
             $subject = $this->config->get('ne_subscribe_confirmation_subject');
             $subject = $subject[$this->config->get('config_store_id')][$this->config->get('config_language_id')];
             $message = $this->config->get('ne_subscribe_confirmation_message');
             $message = $message[$this->config->get('config_store_id')][$this->config->get('config_language_id')];
             if ($data['name']) {
                 $data['name'] = mb_convert_case($data['name'], MB_CASE_TITLE, 'UTF-8');
             }
             if ($data['lastname']) {
                 $data['lastname'] = mb_convert_case($data['lastname'], MB_CASE_TITLE, 'UTF-8');
             }
             $link = HTTPS_SERVER . 'index.php?route=ne/subscribe/confirm&code=' . $code . '&email=' . $data['email'];
             $subject = str_replace(array('{name}', '{lastname}', '{email}', '{link}'), array($data['name'], $data['lastname'], $data['email'], $link), $subject);
             $message = str_replace(array('{name}', '{lastname}', '{email}', '{link}'), array($data['name'], $data['lastname'], $data['email'], $link), $message);
             $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
             $mail->setSubject($subject);
             $mail->setHtml($message);
             $mail->send();
         }
         return true;
     }
     return false;
 }