docs/api/source-catalog.controller.information.contact.html
| 1: | <?php | | 2: | namespace Opencart\Catalog\Controller\Information; | | 3: | /** | | 4: | * Class Contact | | 5: | * | | 6: | * @package Opencart\Catalog\Controller\Information | | 7: | */ | | 8: | class Contact extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * @return void | | 11: | */ | | 12: | public function index(): void { | | 13: | $this->load->language('information/contact'); | | 14: | | | 15: | $this->document->setTitle($this->language->get('heading_title')); | | 16: | | | 17: | $data['breadcrumbs'] = []; | | 18: | | | 19: | $data['breadcrumbs'][] = [ | | 20: | 'text' => $this->language->get('text_home'), | | 21: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language')) | | 22: | ]; | | 23: | | | 24: | $data['breadcrumbs'][] = [ | | 25: | 'text' => $this->language->get('heading_title'), | | 26: | 'href' => $this->url->link('information/contact', 'language=' . $this->config->get('config_language')) | | 27: | ]; | | 28: | | | 29: | $data['send'] = $this->url->link('information/contact.send', 'language=' . $this->config->get('config_language')); | | 30: | | | 31: | $this->load->model('tool/image'); | | 32: | | | 33: | if ($this->config->get('config_image') && is_file(DIR_IMAGE . html_entity_decode($this->config->get('config_image'), ENT_QUOTES, 'UTF-8'))) { | | 34: | $data['image'] = $this->model_tool_image->resize($this->config->get('config_image'), $this->config->get('config_image_location_width'), $this->config->get('config_image_location_height')); | | 35: | } else { | | 36: | $data['image'] = ''; | | 37: | } | | 38: | | | 39: | $data['store'] = $this->config->get('config_name'); | | 40: | $data['address'] = nl2br($this->config->get('config_address')); | | 41: | $data['geocode'] = $this->config->get('config_geocode'); | | 42: | $data['geocode_hl'] = $this->config->get('config_language'); | | 43: | $data['telephone'] = $this->config->get('config_telephone'); | | 44: | $data['open'] = nl2br($this->config->get('config_open')); | | 45: | $data['comment'] = nl2br($this->config->get('config_comment')); | | 46: | | | 47: | $data['locations'] = []; | | 48: | | | 49: | $this->load->model('localisation/location'); | | 50: | | | 51: | foreach ((array)$this->config->get('config_location') as $location_id) { | | 52: | $location_info = $this->model_localisation_location->getLocation((int)$location_id); | | 53: | | | 54: | if ($location_info) { | | 55: | if ($location_info['image'] && is_file(DIR_IMAGE . html_entity_decode($location_info['image'], ENT_QUOTES, 'UTF-8'))) { | | 56: | $image = $this->model_tool_image->resize($location_info['image'], $this->config->get('config_image_location_width'), $this->config->get('config_image_location_height')); | | 57: | } else { | | 58: | $image = ''; | | 59: | } | | 60: | | | 61: | $data['locations'][] = [ | | 62: | 'location_id' => $location_info['location_id'], | | 63: | 'name' => $location_info['name'], | | 64: | 'address' => nl2br($location_info['address']), | | 65: | 'geocode' => $location_info['geocode'], | | 66: | 'telephone' => $location_info['telephone'], | | 67: | 'image' => $image, | | 68: | 'open' => nl2br($location_info['open']), | | 69: | 'comment' => $location_info['comment'] | | 70: | ]; | | 71: | } | | 72: | } | | 73: | | | 74: | $data['name'] = $this->customer->getFirstName(); | | 75: | $data['email'] = $this->customer->getEmail(); | | 76: | | | 77: | // Captcha | | 78: | $this->load->model('setting/extension'); | | 79: | | | 80: | $extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha')); | | 81: | | | 82: | if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) { | | 83: | $data['captcha'] = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code']); | | 84: | } else { | | 85: | $data['captcha'] = ''; | | 86: | } | | 87: | | | 88: | $data['column_left'] = $this->load->controller('common/column_left'); | | 89: | $data['column_right'] = $this->load->controller('common/column_right'); | | 90: | $data['content_top'] = $this->load->controller('common/content_top'); | | 91: | $data['content_bottom'] = $this->load->controller('common/content_bottom'); | | 92: | $data['footer'] = $this->load->controller('common/footer'); | | 93: | $data['header'] = $this->load->controller('common/header'); | | 94: | | | 95: | $this->response->setOutput($this->load->view('information/contact', $data)); | | 96: | } | | 97: | | | 98: | /** | | 99: | * Send | | 100: | * | | 101: | * @throws \Exception | | 102: | * | | 103: | * @return void | | 104: | */ | | 105: | public function send(): void { | | 106: | $this->load->language('information/contact'); | | 107: | | | 108: | $json = []; | | 109: | | | 110: | $keys = [ | | 111: | 'name', | | 112: | 'email', | | 113: | 'enquiry' | | 114: | ]; | | 115: | | | 116: | foreach ($keys as $key) { | | 117: | if (!isset($this->request->post[$key])) { | | 118: | $this->request->post[$key] = ''; | | 119: | } | | 120: | } | | 121: | | | 122: | if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 32)) { | | 123: | $json['error']['name'] = $this->language->get('error_name'); | | 124: | } | | 125: | | | 126: | if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { | | 127: | $json['error']['email'] = $this->language->get('error_email'); | | 128: | } | | 129: | | | 130: | if ((oc_strlen($this->request->post['enquiry']) < 10) || (oc_strlen($this->request->post['enquiry']) > 3000)) { | | 131: | $json['error']['enquiry'] = $this->language->get('error_enquiry'); | | 132: | } | | 133: | | | 134: | // Captcha | | 135: | $this->load->model('setting/extension'); | | 136: | | | 137: | $extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha')); | | 138: | | | 139: | if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) { | | 140: | $captcha = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code'] . '.validate'); | | 141: | | | 142: | if ($captcha) { | | 143: | $json['error']['captcha'] = $captcha; | | 144: | } | | 145: | } | | 146: | | | 147: | if (!$json) { | | 148: | if ($this->config->get('config_mail_engine')) { | | 149: | $mail_option = [ | | 150: | 'parameter' => $this->config->get('config_mail_parameter'), | | 151: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'), | | 152: | 'smtp_username' => $this->config->get('config_mail_smtp_username'), | | 153: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'), | | 154: | 'smtp_port' => $this->config->get('config_mail_smtp_port'), | | 155: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout') | | 156: | ]; | | 157: | | | 158: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option); | | 159: | $mail->setTo($this->config->get('config_email')); | | 160: | // Less spam and fix bug when using SMTP like sendgrid. | | 161: | $mail->setFrom($this->config->get('config_email')); | | 162: | $mail->setReplyTo($this->request->post['email']); | | 163: | $mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8')); | | 164: | $mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8')); | | 165: | $mail->setText($this->request->post['enquiry']); | | 166: | $mail->send(); | | 167: | } | | 168: | | | 169: | $json['redirect'] = $this->url->link('information/contact.success', 'language=' . $this->config->get('config_language'), true); | | 170: | } | | 171: | | | 172: | $this->response->addHeader('Content-Type: application/json'); | | 173: | $this->response->setOutput(json_encode($json)); | | 174: | } | | 175: | | | 176: | /** | | 177: | * Success | | 178: | * | | 179: | * @return void | | 180: | */ | | 181: | public function success(): void { | | 182: | $this->load->language('information/contact'); | | 183: | | | 184: | $this->document->setTitle($this->language->get('heading_title')); | | 185: | | | 186: | $data['breadcrumbs'] = []; | | 187: | | | 188: | $data['breadcrumbs'][] = [ | | 189: | 'text' => $this->language->get('text_home'), | | 190: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language')) | | 191: | ]; | | 192: | | | 193: | $data['breadcrumbs'][] = [ | | 194: | 'text' => $this->language->get('heading_title'), | | 195: | 'href' => $this->url->link('information/contact', 'language=' . $this->config->get('config_language')) | | 196: | ]; | | 197: | | | 198: | $data['text_message'] = $this->language->get('text_message'); | | 199: | | | 200: | $data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language')); | | 201: | | | 202: | $data['column_left'] = $this->load->controller('common/column_left'); | | 203: | $data['column_right'] = $this->load->controller('common/column_right'); | | 204: | $data['content_top'] = $this->load->controller('common/content_top'); | | 205: | $data['content_bottom'] = $this->load->controller('common/content_bottom'); | | 206: | $data['footer'] = $this->load->controller('common/footer'); | | 207: | $data['header'] = $this->load->controller('common/header'); | | 208: | | | 209: | $this->response->setOutput($this->load->view('common/success', $data)); | | 210: | } | | 211: | } | | 212: | |
OpenCart API API documentation generated by ApiGen dev-master