This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use cmsemail\email; |
||
4 | use CMSFactory\assetManager; |
||
5 | |||
6 | (defined('BASEPATH')) OR exit('No direct script access allowed'); |
||
7 | |||
8 | /** |
||
9 | * Image CMS |
||
10 | * Email Module Admin |
||
11 | * @property Cache $cache |
||
12 | * @property Cms_base $cms_base |
||
13 | */ |
||
14 | class Admin extends BaseAdminController |
||
15 | { |
||
16 | |||
17 | const MAX_DEFAULT_TEMPLATES_CORPORATE = 3; |
||
18 | const MAX_DEFAULT_TEMPLATES_SHOP = 7; |
||
19 | |||
20 | /** |
||
21 | * Object of Email class |
||
22 | * @var Email |
||
23 | */ |
||
24 | public $email; |
||
25 | |||
26 | public function __construct() { |
||
27 | parent::__construct(); |
||
28 | $this->load->language('email'); |
||
29 | $this->email = email::getInstance(); |
||
30 | $lang = new MY_Lang(); |
||
31 | $lang->load('cmsemail'); |
||
32 | } |
||
33 | |||
34 | public function index() { |
||
35 | assetManager::create() |
||
36 | ->setData( |
||
37 | [ |
||
38 | 'models' => $this->email->getAllTemplates(), |
||
39 | 'defaultTemplatesCount' => $this->getMaxDefaultTemplatesCount(), |
||
40 | ] |
||
41 | ) |
||
42 | ->renderAdmin('list'); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return int |
||
47 | */ |
||
48 | private function getMaxDefaultTemplatesCount() { |
||
49 | if (MY_Controller::isCorporateCMS()) { |
||
50 | return self::MAX_DEFAULT_TEMPLATES_CORPORATE; |
||
51 | } |
||
52 | |||
53 | return self::MAX_DEFAULT_TEMPLATES_SHOP; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param string $locale |
||
58 | */ |
||
59 | public function settings($locale) { |
||
60 | |||
61 | $locale = $locale ?: MY_Controller::defaultLocale(); |
||
62 | $encryption = [ |
||
63 | 'tls', |
||
64 | 'ssl', |
||
65 | ]; |
||
66 | assetManager::create() |
||
67 | ->registerScript('email') |
||
68 | ->registerStyle('style') |
||
69 | ->setData('settings', $this->email->getSettings($locale)) |
||
70 | ->setData('languages', $this->cms_base->get_langs()) |
||
71 | ->setData('locale', $locale) |
||
72 | ->setData('encryption', $encryption) |
||
73 | ->renderAdmin('settings'); |
||
74 | } |
||
75 | |||
76 | public function create() { |
||
77 | |||
78 | if ($this->input->post()) { |
||
79 | $id = $this->email->create(); |
||
80 | if ($id) { |
||
81 | $this->lib_admin->log(lang('E-mail template created', 'cmsemail') . ' - ' . $this->input->post('mail_name')); |
||
82 | showMessage(lang('Template created', 'cmsemail')); |
||
83 | |||
84 | View Code Duplication | if ($this->input->post('action') == 'tomain') { |
|
85 | pjax('/admin/components/cp/cmsemail/index'); |
||
86 | } else { |
||
87 | pjax('/admin/components/cp/cmsemail/edit/' . $id . '#settings'); |
||
88 | } |
||
89 | } else { |
||
90 | showMessage($this->email->errors, '', 'r'); |
||
91 | } |
||
92 | } else { |
||
93 | assetManager::create() |
||
94 | ->registerScript('email') |
||
95 | ->setData('settings', $this->email->getSettings()) |
||
96 | ->renderAdmin('create'); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | public function mailTest() { |
||
101 | lang('email_sent', 'admin'); |
||
102 | echo $this->email->mailTest(); |
||
103 | } |
||
104 | |||
105 | public function delete() { |
||
106 | |||
107 | $this->db->select('name'); |
||
108 | foreach ($this->input->post('ids') as $id) { |
||
109 | $this->db->or_where('id', $id); |
||
110 | } |
||
111 | $names = $this->db->get('mod_email_paterns')->result_array(); |
||
112 | $this->email->delete($this->input->post('ids')); |
||
113 | foreach ($names as $val) { |
||
114 | $logNames[] = $val['name']; |
||
0 ignored issues
–
show
|
|||
115 | } |
||
116 | $this->lib_admin->log(lang('Email template deleted', 'cmsemail') . ' - ' . implode(', ', $logNames)); |
||
117 | showMessage(lang('Email template deleted', 'cmsemail'), lang('Message', 'cmsemail')); |
||
118 | } |
||
119 | |||
120 | public function edit($id, $locale = null) { |
||
121 | |||
122 | if (null === $locale) { |
||
123 | $locale = chose_language(); |
||
124 | } |
||
125 | |||
126 | $model = $this->email->getTemplateById($id, $locale); |
||
127 | |||
128 | if (!$model) { |
||
129 | $this->load->module('core'); |
||
130 | $this->core->error_404(); |
||
131 | exit; |
||
132 | } |
||
133 | $variables = unserialize($model['variables']); |
||
134 | |||
135 | if ($this->input->post()) { |
||
136 | if ($this->email->edit($id, [], $locale)) { |
||
137 | $name = $this->db->select('name')->where('id', $id)->get('mod_email_paterns')->row()->name; |
||
138 | |||
139 | $this->lib_admin->log(lang('Email template was edited', 'cmsemail') . ' - ' . $name); |
||
140 | showMessage(lang('Template edited', 'cmsemail')); |
||
141 | |||
142 | if ($this->input->post('action') == 'tomain') { |
||
143 | pjax('/admin/components/cp/cmsemail/index'); |
||
144 | } |
||
145 | } else { |
||
146 | showMessage($this->email->errors, '', 'r'); |
||
147 | } |
||
148 | } else { |
||
149 | assetManager::create() |
||
150 | ->setData('locale', $locale) |
||
151 | ->setData('languages', $this->db->get('languages')->result_array()) |
||
152 | ->setData('model', $model) |
||
153 | ->setData('variables', $variables) |
||
154 | ->registerScript('email') |
||
155 | ->renderAdmin('edit'); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * update settings for email |
||
161 | * @param string $locale |
||
162 | */ |
||
163 | public function update_settings($locale) { |
||
164 | |||
165 | $locale = $locale ?: MY_Controller::defaultLocale(); |
||
166 | |||
167 | if ($this->input->post()) { |
||
168 | $this->form_validation->set_rules('settings[admin_email]', lang('Admin email', 'cmsemail'), 'required|xss_clean|callback_email_check|trim'); |
||
169 | $this->form_validation->set_rules('settings[from_email]', lang('Email sender', 'cmsemail'), 'required|xss_clean|valid_email'); |
||
170 | $this->form_validation->set_rules('settings[from]', lang('From', 'cmsemail'), 'required|xss_clean'); |
||
171 | $this->form_validation->set_rules('settings[theme]', lang('From email', 'cmsemail'), 'xss_clean|required'); |
||
172 | |||
173 | $post_settings = $this->input->post('settings'); |
||
174 | if ($post_settings['wraper_activ']) { |
||
175 | $this->form_validation->set_rules('settings[wraper]', lang('Wraper', 'cmsemail'), 'required|xss_clean|callback_wraper_check'); |
||
176 | } else { |
||
177 | $this->form_validation->set_rules('settings[wraper]', lang('Wraper', 'cmsemail'), 'xss_clean'); |
||
178 | } |
||
179 | |||
180 | if ($this->form_validation->run($this) == FALSE) { |
||
181 | showMessage(validation_errors(), lang('Message', 'cmsemail'), 'r'); |
||
182 | View Code Duplication | } else { |
|
183 | $data = [ |
||
184 | 'locale' => $locale, |
||
185 | 'settings' => $this->input->post('settings'), |
||
186 | ]; |
||
187 | |||
188 | $this->email->setSettings($data); |
||
189 | showMessage(lang('Settings saved', 'cmsemail'), lang('Message', 'cmsemail')); |
||
190 | $this->lib_admin->log(lang('Template customization mails have been changed', 'cmsemail') . '. Id: '); // . $id);?? |
||
191 | } |
||
192 | |||
193 | $this->cache->delete_all(); |
||
194 | } |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * @param string $wrapper |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function wraper_check($wrapper) { |
||
202 | |||
203 | if (preg_match('/\$content/', htmlentities($wrapper))) { |
||
204 | return TRUE; |
||
205 | } else { |
||
206 | $this->form_validation->set_message('wraper_check', lang('Field', 'cmsemail') . ' %s ' . lang('Must contain variable', 'cmsemail') . ' $content'); |
||
207 | return FALSE; |
||
208 | } |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * @param $emails |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | View Code Duplication | public function email_check($emails) { |
|
217 | |||
218 | $emails = str_replace(' ', '', $emails); |
||
219 | |||
220 | foreach (explode(',', $emails) as $e) { |
||
221 | if (!filter_var($e, FILTER_VALIDATE_EMAIL)) { |
||
222 | $this->form_validation->set_message('email_check', lang('Field', 'cmsemail') . ' %s ' . lang('Must contain valid email', 'cmsemail')); |
||
223 | |||
224 | return false; |
||
225 | } |
||
226 | } |
||
227 | |||
228 | return TRUE; |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * @param null|string $locale |
||
233 | * @return bool|object |
||
234 | */ |
||
235 | public function deleteVariable($locale = null) { |
||
236 | |||
237 | if (null === $locale) { |
||
238 | $locale = chose_language(); |
||
239 | } |
||
240 | $template_id = $this->input->post('template_id'); |
||
241 | $variable = $this->input->post('variable'); |
||
242 | |||
243 | return $this->email->deleteVariable($template_id, $variable, $locale); |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @param null|string $locale |
||
248 | * @return bool|object |
||
249 | */ |
||
250 | public function updateVariable($locale = null) { |
||
251 | |||
252 | if (null === $locale) { |
||
253 | $locale = chose_language(); |
||
254 | } |
||
255 | $template_id = $this->input->post('template_id'); |
||
256 | $variable = $this->input->post('variable'); |
||
257 | $variableNewValue = $this->input->post('variableValue'); |
||
258 | $oldVariable = $this->input->post('oldVariable'); |
||
259 | return $this->email->updateVariable($template_id, $variable, $variableNewValue, $oldVariable, $locale); |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @param null|string $locale |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function addVariable($locale = null) { |
||
267 | |||
268 | if (null === $locale) { |
||
269 | $locale = chose_language(); |
||
270 | } |
||
271 | $template_id = $this->input->post('template_id'); |
||
272 | $variable = $this->input->post('variable'); |
||
273 | $variableValue = $this->input->post('variableValue'); |
||
274 | |||
275 | if ($this->email->addVariable($template_id, $variable, $variableValue, $locale)) { |
||
276 | assetManager::create() |
||
277 | ->setData('template_id', $template_id) |
||
278 | ->setData('variable', $variable) |
||
279 | ->setData('variable_value', $variableValue) |
||
280 | ->setData('locale', $locale) |
||
281 | ->render('newVariable', true); |
||
282 | } else { |
||
283 | return FALSE; |
||
284 | } |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * @param null|string $locale |
||
289 | * @return bool |
||
290 | */ |
||
291 | public function getTemplateVariables($locale = null) { |
||
292 | |||
293 | if (null === $locale) { |
||
294 | $locale = chose_language(); |
||
295 | } |
||
296 | $template_id = $this->input->post('template_id'); |
||
297 | $variables = $this->email->getTemplateVariables($template_id, $locale); |
||
298 | if ($variables) { |
||
299 | assetManager::create() |
||
300 | ->setData('variables', $variables) |
||
301 | ->render('variablesSelectOptions', true); |
||
302 | } else { |
||
303 | return FALSE; |
||
304 | } |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * import templates from file |
||
309 | */ |
||
310 | public function import_templates() { |
||
311 | |||
312 | $this->db->where_in('id', [1, 2, 3, 4, 5, 6, 7, 8, 9])->delete('mod_email_paterns'); |
||
313 | $this->db->where_in('id', [1, 2, 3, 4, 5, 6, 7, 8, 9])->delete('mod_email_paterns_i18n'); |
||
314 | |||
315 | if (MY_Controller::isCorporateCMS()) { |
||
316 | $file = $this->load->file(__DIR__ . '/models/paterns_corporate.sql', true); |
||
317 | $file_i18n = $this->load->file(__DIR__ . '/models/patterns_i18n_corporate.sql', true); |
||
318 | } else { |
||
319 | $file = $this->load->file(__DIR__ . '/models/paterns.sql', true); |
||
320 | $file_i18n = $this->load->file(__DIR__ . '/models/patterns_i18n.sql', true); |
||
321 | } |
||
322 | $this->db->query($file); |
||
323 | $this->db->query($file_i18n); |
||
324 | |||
325 | $this->lib_admin->log(lang('Email templates were successfully imported', 'cmsemail')); |
||
326 | |||
327 | redirect('/admin/components/cp/cmsemail/'); |
||
328 | } |
||
329 | |||
330 | } |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.