-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
116 lines (93 loc) · 4.18 KB
/
index.php
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
<?php
/******************************************************************************
*
* Subrion - open source content management system
* Copyright (C) 2018 Intelliants, LLC <https://intelliants.com>
*
* This file is part of Subrion.
*
* Subrion is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Subrion is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Subrion. If not, see <http://www.gnu.org/licenses/>.
*
*
* @link https://subrion.org/
*
******************************************************************************/
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$subjects = $iaCore->get('contact_us_subjects');
if ($subjects) {
$subjects = explode(PHP_EOL, $subjects);
foreach ($subjects as $key => $subject) {
$subjects[$key] = trim($subject);
}
}
if (isset($_POST['msg'])) {
$error = false;
$messages = [];
// min and max message length
$len = ['min' => 10, 'max' => 500];
iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
// default email address to send contact requests to
$email_to_send = $iaCore->get('site_email');
$data = [];
$data['fullname'] = iaUtil::checkPostParam('name');
$data['email'] = iaUtil::checkPostParam('email');
$data['phone'] = iaUtil::checkPostParam('phone');
$data['subject'] = isset($_POST['subject']) && $_POST['subject'] ? $_POST['subject'] : iaLanguage::get('contact_request_from') . ' ' . $iaCore->get('site');
$data['body'] = preg_replace('[\r\n]', '', nl2br(iaUtil::checkPostParam('msg')));
$data['ip'] = iaUtil::getIp();
$body_len = utf8_strlen($data['body']);
if (empty($data['email'])) {
$error = true;
$messages[] = iaLanguage::getf('field_is_empty', ['field' => iaLanguage::get('email')]);
} elseif (!iaValidate::isEmail($data['email'])) {
$error = true;
$messages[] = iaLanguage::get('error_email_incorrect');
}
if (!$data['fullname']) {
$error = true;
$messages[] = iaLanguage::getf('field_is_empty', ['field' => iaLanguage::get('fullname')]);
}
if ($len['min'] > $body_len || $len['max'] < $body_len) {
$error = true;
$messages[] = iaLanguage::getf('contact_body_len', ['num' => $len['min'] . '-' . $len['max']]);
}
if (!iaUsers::hasIdentity() && !iaValidate::isCaptchaValid()) {
$error = true;
$messages[] = iaLanguage::get('confirmation_code_incorrect');
}
if (!$error) {
$data = array_map(['iaSanitize', 'sql'], $data);
$iaDb->insert($data, ['date' => iaDb::FUNCTION_NOW], 'contacts');
if ('Email' == $iaCore->get('contact_notif')) {
$iaMailer = $iaCore->factory('mailer');
// validate config email address
if (iaValidate::isEmail($iaCore->get('contact_us_email'))) {
$email_to_send = $iaCore->get('contact_us_email');
}
$data['body'] .= '<br><br>' . iaSanitize::html($data['fullname']) . '<br>'
. iaSanitize::html($data['email']) . '<br>'
. iaSanitize::html($data['phone']);
$iaMailer->AddAddress($email_to_send);
$iaMailer->setSubject($data['subject']);
$iaMailer->setBody($data['body']);
$iaMailer->Send();
}
$messages = [iaLanguage::get('message_sent')];
}
$error || $_POST = [];
$iaView->setMessages($messages, $error ? iaView::ERROR : iaView::SUCCESS);
}
$iaView->assign('subjects', $subjects);
$iaView->display();
}