oct_subscribe.php
7.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* @copyright OCTemplates
* @support https://octemplates.net/
* @license LICENSE.txt
*/
class ModelOCTemplatesModuleOctSubscribe extends Model {
public function addSubscribe($data) {
$this->load->language('octemplates/module/oct_subscribe');
$hash = sha1("NOW()" . sha1(sha1($data['email'])));
$this->db->query("INSERT INTO `" . DB_PREFIX . "oct_subscribe` SET email = '" . $this->db->escape($data['email']) . "', ip = '" . $this->db->escape($data['ip']) . "', approved = '0', hash = '" . $this->db->escape($hash) . "', date_added = NOW()");
$subscribe_id = $this->db->getLastId();
$store_name = $this->config->get('config_name');
$link = htmlspecialchars_decode($this->url->link('octemplates/module/oct_subscribe/subscribe_confirm', 'approve=' . (int)$subscribe_id . '&hash='.$hash, true));
if ($this->config->get('oct_subscribe_template_status')) {
$oct_subscribe_text_data = $this->config->get('oct_subscribe_text_data');
$subject = (isset($oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['subject_email_template_first']) && !empty($oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['subject_email_template_first'])) ? $oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['subject_email_template_first'] : sprintf($this->language->get('text_approve_subject'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$message = html_entity_decode(str_replace('{approve_link}', $link, $oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['email_template_first']), ENT_QUOTES, 'UTF-8');
} else {
$subject = sprintf($this->language->get('text_approve_subject'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$message = sprintf($this->language->get('text_approve_welcome'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8')) . "\n\n";
$message .= $this->language->get('text_approve_services') . "\n\n";
$message .= sprintf($this->language->get('text_subscribe_services'), $link) . "\n\n";
$message .= $this->language->get('text_thanks') . "\n";
$message .= html_entity_decode($store_name, ENT_QUOTES, 'UTF-8');
}
$this->load->model('setting/setting');
$from = $this->model_setting_setting->getSettingValue('config_email', (int)$this->config->get('config_store_id'));
if (!$from) {
$from = $this->config->get('config_email');
}
$mail = new Mail($this->config->get('config_mail_engine'));
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($data['email']);
$mail->setFrom($from);
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$mail->setSubject($subject);
if ($this->config->get('oct_subscribe_template_status')) {
$mail->setHtml($message);
} else {
$mail->setText($message);
}
$mail->send();
}
public function checkSubscribe($email) {
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "oct_subscribe` WHERE email = '" . $this->db->escape($email) . "'");
if ($query->row) {
return true;
} else {
return false;
}
}
public function getSubscribe($subscribe_id, $hash) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "oct_subscribe` WHERE subscribe_id = '" . (int) $subscribe_id . "' AND hash = '" . $this->db->escape($hash) . "'");
return $query->row;
}
public function getSubscribeById($subscribe_id) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "oct_subscribe` WHERE subscribe_id = '" . (int) $subscribe_id . "'");
return $query->row;
}
public function unSubscribe($subscribe_id) {
$this->db->query("DELETE FROM `" . DB_PREFIX . "oct_subscribe` WHERE subscribe_id = '" . (int) $subscribe_id . "'");
}
public function approve($subscribe_id) {
$subscribe_info = $this->getSubscribeById($subscribe_id);
if ($subscribe_info) {
$this->db->query("UPDATE `" . DB_PREFIX . "oct_subscribe` SET approved = '1' WHERE subscribe_id = '" . (int) $subscribe_id . "'");
$this->load->language('octemplates/module/oct_subscribe/subscribe_confirm');
$store_name = $this->config->get('config_name');
$link = htmlspecialchars_decode($this->url->link('octemplates/module/oct_subscribe/subscribe_confirm', 'unsubscribe=' . (int)$subscribe_id . '&hash='.$subscribe_info['hash'], true));
if ($this->config->get('oct_subscribe_template_status')) {
$oct_subscribe_text_data = $this->config->get('oct_subscribe_text_data');
$subject = (isset($oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['subject_email_template_second']) && !empty($oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['subject_email_template_second'])) ? $oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['subject_email_template_second'] : sprintf($this->language->get('text_approve_subject'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$message = html_entity_decode(str_replace('{unsubscribe_link}', $link, $oct_subscribe_text_data[(int)$this->config->get('config_language_id')]['email_template_second']), ENT_QUOTES, 'UTF-8');
} else {
$subject = sprintf($this->language->get('text_unsubscribe_subject'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$message = sprintf($this->language->get('text_unsubscribe_welcome'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8')) . "\n\n";
$message .= sprintf($this->language->get('text_unsubscribe_services'), $link) . "\n\n";
$message .= $this->language->get('text_thanks') . "\n";
$message .= html_entity_decode($store_name, ENT_QUOTES, 'UTF-8');
}
$this->load->model('setting/setting');
$from = $this->model_setting_setting->getSettingValue('config_email', (int)$this->config->get('config_store_id'));
if (!$from) {
$from = $this->config->get('config_email');
}
$mail = new Mail($this->config->get('config_mail_engine'));
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($subscribe_info['email']);
$mail->setFrom($from);
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$mail->setSubject($subject);
if ($this->config->get('oct_subscribe_template_status')) {
$mail->setHtml($message);
} else {
$mail->setText($message);
}
$mail->send();
}
}
}