oct_subscribe.php
8.23 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
 * @copyright    OCTemplates
 * @support      https://octemplates.net/
 * @license      LICENSE.txt
 */
class ControllerOCTemplatesModuleOctSubscribe extends Controller {
    public function index() {
	    if ($this->config->get('oct_subscribe_status') && isset($this->request->server['HTTP_X_REQUESTED_WITH']) && !empty($this->request->server['HTTP_X_REQUESTED_WITH']) && strtolower($this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
	        $this->load->model('catalog/product');
			$this->load->model('tool/image');
			$this->load->model('octemplates/module/oct_subscribe');
	        $this->load->language('octemplates/module/oct_subscribe');
			$oct_subscribe_text_data = $this->config->get('oct_subscribe_text_data');
			$data['oct_subscribe_form_data'] = $oct_subscribe_form_data = $this->config->get('oct_subscribe_form_data');
			$data['expire'] = $oct_subscribe_form_data['expire'] ? $oct_subscribe_form_data['expire'] : '1';
			if ($oct_subscribe_form_data['image']) {
				$data['thumb'] = $oct_subscribe_form_data['image'];
			} else {
				$data['thumb'] = false;
			}
			if (isset($oct_subscribe_text_data[$this->session->data['language']])) {
				$data['promo_text'] = html_entity_decode($oct_subscribe_text_data[$this->session->data['language']]['promo_text'], ENT_QUOTES, 'UTF-8');
			}
			if ($this->customer->isLogged()) {
				$data['email'] = $this->customer->getEmail();
			} else {
				$data['email'] = '';
			}
			if ($this->config->get('config_account_id')) {
	            $this->load->model('catalog/information');
	            $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
	            if ($information_info) {
	                $data['text_terms'] = sprintf($this->language->get('text_oct_terms'), $this->url->link('information/information', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['title'], $information_info['title']);
	            } else {
	                $data['text_terms'] = '';
	            }
	        } else {
	            $data['text_terms'] = '';
	        }
			$this->response->setOutput($this->load->view('octemplates/module/oct_popup_subscribe', $data));
        } else {
		    $this->load->language('octemplates/module/oct_subscribe');
		    if ($this->config->get('config_account_id')) {
	            $this->load->model('catalog/information');
	            $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
	            if ($information_info) {
	                $data['text_terms'] = sprintf($this->language->get('text_oct_terms'), $this->url->link('information/information', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['information_id'], $information_info['title']);
	            } else {
	                $data['text_terms'] = '';
	            }
	        } else {
	            $data['text_terms'] = '';
	        }
	        return $this->load->view('octemplates/module/oct_static_subscribe', $data);
        }
    }
    public function subscribe_confirm(){
		$this->load->language('octemplates/module/oct_subscribe');
        $this->load->model('octemplates/module/oct_subscribe');
        $this->document->setTitle($this->language->get('title_subscribe'));
        $data['breadcrumbs'] = array();
        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/home')
        );
        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('title_subscribe'),
            'href' => $this->url->link('octemplates/module/oct_subscribe/subscribe_confirm')
        );
		$oct_data['breadcrumbs'] = $data['breadcrumbs'];
		$data['oct_breadcrumbs'] = $this->load->controller('octemplates/main/oct_functions/octBreadcrumbs', $oct_data);
        $data['heading_title'] = $this->language->get('title_subscribe');
        $data['text_message'] = $this->language->get('text_message_default');
        if (isset($this->request->get['unsubscribe']) && isset($this->request->get['hash'])) {
            $subscribe_info = $this->model_octemplates_module_oct_subscribe->getSubscribe($this->request->get['unsubscribe'], $this->request->get['hash']);
            if ($subscribe_info) {
                $this->model_octemplates_module_oct_subscribe->unSubscribe($subscribe_info['subscribe_id']);
                $data['text_message'] = $this->language->get('text_message_unsubscribe');
            }
        }
        if (isset($this->request->get['approve']) && isset($this->request->get['hash'])) {
            $subscribe_info = $this->model_octemplates_module_oct_subscribe->getSubscribe($this->request->get['approve'], $this->request->get['hash']);
            if ($subscribe_info) {
                $this->model_octemplates_module_oct_subscribe->approve($subscribe_info['subscribe_id']);
                $data['text_message'] = $this->language->get('text_message_approve');
            }
        }
        $data['button_continue'] = $this->language->get('button_continue');
        $data['continue'] = $this->url->link('common/home');
        $data['column_left']    = $this->load->controller('common/column_left');
        $data['column_right']   = $this->load->controller('common/column_right');
        $data['content_top']    = $this->load->controller('common/content_top');
        $data['content_bottom'] = $this->load->controller('common/content_bottom');
        $data['footer']         = $this->load->controller('common/footer');
        $data['header']         = $this->load->controller('common/header');
        $this->response->setOutput($this->load->view('common/success', $data));
    }
    public function makeSubscribe() {
	    if (isset($this->request->server['HTTP_X_REQUESTED_WITH']) && !empty($this->request->server['HTTP_X_REQUESTED_WITH']) && strtolower($this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
	        $json = [];
	        $this->language->load('octemplates/module/oct_subscribe');
	        $this->load->model('octemplates/module/oct_subscribe');
	        $oct_subscribe_form_data = (array)$this->config->get('oct_subscribe_form_data');
	        if (isset($this->request->post['email'])) {
	            if (empty($this->request->post['email'])) {
	                $json['error']['email'] = $this->language->get('error_enter_email');
	            }
	            if (!preg_match('/^[^\@]+@.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
	                $json['error']['email']  = $this->language->get('error_valid_email');
	            }
	            $subscribe_status = $this->model_octemplates_module_oct_subscribe->checkSubscribe($this->request->post['email']);
	            if ($subscribe_status) {
	                $json['error']['email'] = $this->language->get('error_already_subscribed_email');
	            }
				if ($this->config->get('config_account_id') && !isset($this->request->post['agree'])) {
					$this->load->model('catalog/information');
					$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
					$json['error']['agree'] = sprintf($this->language->get('error_oct_terms'), $information_info['title']);
				}
	            if (!isset($json['error'])) {
	                if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) {
	                    $ip = $this->request->server['HTTP_X_FORWARDED_FOR'];
	                } elseif (!empty($this->request->server['HTTP_CLIENT_IP'])) {
	                    $ip = $this->request->server['HTTP_CLIENT_IP'];
	                } else {
	                    $ip = $this->request->server['REMOTE_ADDR'];
	                }
	                $subscribe_data = [
	                    'email' => $this->request->post['email'],
	                    'ip' => $ip
	                ];
	                $this->model_octemplates_module_oct_subscribe->addSubscribe($subscribe_data);
	                $json['output'] = $this->language->get('text_success_subscribe');
	            }
	        }
	        $this->response->addHeader('Content-Type: application/json');
	        $this->response->setOutput(json_encode($json));
        } else {
	        $this->response->redirect($this->url->link('error/not_found', '', true));
        }
    }
}