Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 94 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
admin_form | |
0.00% |
0 / 94 |
|
0.00% |
0 / 5 |
210 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
check_allow | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
bind | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
submit | |
0.00% |
0 / 55 |
|
0.00% |
0 / 1 |
56 | |||
render | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\message; |
15 | |
16 | use phpbb\messenger\method\messenger_interface; |
17 | |
18 | /** |
19 | * Class admin_form |
20 | * Displays a message to the user and allows him to send an email |
21 | */ |
22 | class admin_form extends form |
23 | { |
24 | /** @var \phpbb\config\db_text */ |
25 | protected $config_text; |
26 | |
27 | /** @var \phpbb\event\dispatcher_interface */ |
28 | protected $dispatcher; |
29 | |
30 | /** @var string */ |
31 | protected $subject; |
32 | /** @var string */ |
33 | protected $sender_name; |
34 | /** @var string */ |
35 | protected $sender_address; |
36 | |
37 | /** |
38 | * Construct |
39 | * |
40 | * @param \phpbb\auth\auth $auth |
41 | * @param \phpbb\config\config $config |
42 | * @param \phpbb\config\db_text $config_text |
43 | * @param \phpbb\db\driver\driver_interface $db |
44 | * @param \phpbb\user $user |
45 | * @param \phpbb\event\dispatcher_interface $dispatcher |
46 | * @param string $phpbb_root_path |
47 | * @param string $phpEx |
48 | */ |
49 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\config\db_text $config_text, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\event\dispatcher_interface $dispatcher, $phpbb_root_path, $phpEx) |
50 | { |
51 | parent::__construct($auth, $config, $db, $user, $phpbb_root_path, $phpEx); |
52 | $this->config_text = $config_text; |
53 | $this->dispatcher = $dispatcher; |
54 | } |
55 | |
56 | /** |
57 | * {inheritDoc} |
58 | */ |
59 | public function check_allow() |
60 | { |
61 | $error = parent::check_allow(); |
62 | if ($error) |
63 | { |
64 | return $error; |
65 | } |
66 | |
67 | if (!$this->config['contact_admin_form_enable']) |
68 | { |
69 | return 'NO_CONTACT_PAGE'; |
70 | } |
71 | |
72 | return false; |
73 | } |
74 | |
75 | /** |
76 | * {inheritDoc} |
77 | */ |
78 | public function bind(\phpbb\request\request_interface $request) |
79 | { |
80 | parent::bind($request); |
81 | |
82 | $this->subject = $request->variable('subject', '', true); |
83 | $this->sender_address = $request->variable('email', ''); |
84 | $this->sender_name = $request->variable('name', '', true); |
85 | } |
86 | |
87 | /** |
88 | * {inheritDoc} |
89 | */ |
90 | public function submit(\phpbb\di\service_collection $messenger) |
91 | { |
92 | if (!$this->subject) |
93 | { |
94 | $this->errors[] = $this->user->lang['EMPTY_SUBJECT_EMAIL']; |
95 | } |
96 | if (!$this->body) |
97 | { |
98 | $this->errors[] = $this->user->lang['EMPTY_MESSAGE_EMAIL']; |
99 | } |
100 | |
101 | $subject = $this->subject; |
102 | $body = $this->body; |
103 | $errors = $this->errors; |
104 | |
105 | /** |
106 | * You can use this event to modify subject and/or body and add new errors. |
107 | * |
108 | * @event core.message_admin_form_submit_before |
109 | * @var string subject Message subject |
110 | * @var string body Message body |
111 | * @var array errors Form errors |
112 | * @since 3.2.6-RC1 |
113 | */ |
114 | $vars = [ |
115 | 'subject', |
116 | 'body', |
117 | 'errors', |
118 | ]; |
119 | extract($this->dispatcher->trigger_event('core.message_admin_form_submit_before', compact($vars))); |
120 | $this->subject = $subject; |
121 | $this->body = $body; |
122 | $this->errors = $errors; |
123 | |
124 | if ($this->user->data['is_registered']) |
125 | { |
126 | $this->message->set_sender_from_user($this->user); |
127 | $this->sender_name = $this->user->data['username']; |
128 | $this->sender_address = $this->user->data['user_email']; |
129 | } |
130 | else |
131 | { |
132 | if (!$this->sender_name) |
133 | { |
134 | $this->errors[] = $this->user->lang['EMPTY_SENDER_NAME']; |
135 | } |
136 | |
137 | if (!function_exists('validate_data')) |
138 | { |
139 | require($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); |
140 | } |
141 | |
142 | $validate_array = validate_data( |
143 | array( |
144 | 'email' => $this->sender_address, |
145 | ), |
146 | array( |
147 | 'email' => array( |
148 | array('string', false, 6, 60), |
149 | array('email'), |
150 | ), |
151 | ) |
152 | ); |
153 | |
154 | foreach ($validate_array as $error) |
155 | { |
156 | $this->errors[] = $this->user->lang[$error]; |
157 | } |
158 | |
159 | $this->message->set_sender($this->user->ip, $this->sender_name, $this->sender_address, $this->user->lang_name); |
160 | $this->message->set_sender_notify_type(messenger_interface::NOTIFY_EMAIL); |
161 | } |
162 | |
163 | $this->message->set_template('contact_admin'); |
164 | $this->message->set_subject($this->subject); |
165 | $this->message->set_body($this->body); |
166 | $this->message->add_recipient( |
167 | $this->user->lang['ADMINISTRATOR'], |
168 | $this->config['board_contact'], |
169 | $this->config['default_lang'], |
170 | messenger_interface::NOTIFY_EMAIL |
171 | ); |
172 | |
173 | $this->message->set_template_vars(array( |
174 | 'FROM_EMAIL_ADDRESS' => $this->sender_address, |
175 | 'FROM_IP_ADDRESS' => $this->user->ip, |
176 | 'S_IS_REGISTERED' => $this->user->data['is_registered'], |
177 | |
178 | 'U_FROM_PROFILE' => generate_board_url() . '/memberlist.' . $this->phpEx . '?mode=viewprofile&u=' . $this->user->data['user_id'], |
179 | )); |
180 | |
181 | parent::submit($messenger); |
182 | } |
183 | |
184 | /** |
185 | * {inheritDoc} |
186 | */ |
187 | public function render(\phpbb\template\template $template) |
188 | { |
189 | $l_admin_info = $this->config_text->get('contact_admin_info'); |
190 | if ($l_admin_info) |
191 | { |
192 | $contact_admin_data = $this->config_text->get_array(array( |
193 | 'contact_admin_info', |
194 | 'contact_admin_info_uid', |
195 | 'contact_admin_info_bitfield', |
196 | 'contact_admin_info_flags', |
197 | )); |
198 | |
199 | $l_admin_info = generate_text_for_display( |
200 | $contact_admin_data['contact_admin_info'], |
201 | $contact_admin_data['contact_admin_info_uid'], |
202 | $contact_admin_data['contact_admin_info_bitfield'], |
203 | $contact_admin_data['contact_admin_info_flags'] |
204 | ); |
205 | } |
206 | |
207 | $template->assign_vars(array( |
208 | 'S_CONTACT_ADMIN' => true, |
209 | 'S_CONTACT_FORM' => $this->config['contact_admin_form_enable'], |
210 | 'S_IS_REGISTERED' => $this->user->data['is_registered'], |
211 | 'S_POST_ACTION' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=contactadmin'), |
212 | |
213 | 'CONTACT_INFO' => $l_admin_info, |
214 | 'MESSAGE' => $this->body, |
215 | 'SUBJECT' => $this->subject, |
216 | 'NAME' => $this->sender_name, |
217 | 'EMAIL' => $this->sender_address, |
218 | )); |
219 | |
220 | parent::render($template); |
221 | } |
222 | } |