PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Classes/FieldClass.php +0 -841 10.2.2 → 11.1.1 View file →
@@ -1,841 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Classes;
4 -
5 -use AcyMailing\Core\AcymClass;
6 -
7 -class FieldClass extends AcymClass
8 -{
9 - const LANGUAGE_FIELD_ID_KEY = 'language_field_id';
10 -
11 - public function __construct()
12 - {
13 - parent::__construct();
14 -
15 - $this->table = 'field';
16 - $this->pkey = 'id';
17 - }
18 -
19 - public function getMatchingElements(array $settings = []): array
20 - {
21 - $query = 'SELECT * FROM #__acym_field';
22 - $queryCount = 'SELECT COUNT(*) FROM #__acym_field';
23 -
24 - $where = [];
25 - if (!empty($settings['types'])) {
26 - foreach ($settings['types'] as $i => $oneType) {
27 - $settings['types'][$i] = acym_escapeDB($oneType);
28 - }
29 - $where[] = ' type IN ('.implode(',', $settings['types']).')';
30 - }
31 -
32 - if (!empty($where)) {
33 - $query .= ' WHERE '.implode(' AND ', $where);
34 - $queryCount .= ' WHERE '.implode(' AND ', $where);
35 - }
36 -
37 - $query .= ' ORDER BY `ordering` ASC';
38 -
39 - return [
40 - 'elements' => acym_loadObjectList($query, 'id'),
41 - 'total' => acym_loadResult($queryCount),
42 - ];
43 - }
44 -
45 - public function getFieldsByID($ids)
46 - {
47 - acym_arrayToInteger($ids);
48 - if (empty($ids)) return [];
49 - $query = 'SELECT * FROM #__acym_field WHERE `id` IN('.implode(',', $ids).') ORDER BY `ordering` ASC';
50 -
51 - return acym_loadObjectList($query);
52 - }
53 -
54 - public function getFieldsByNameKey(array $nameKeys): array
55 - {
56 - if (empty($nameKeys)) {
57 - return [];
58 - }
59 -
60 - $nameKeys = array_map('acym_escapeDB', $nameKeys);
61 -
62 - return acym_loadObjectList('SELECT * FROM #__acym_field WHERE `namekey` IN('.implode(',', $nameKeys).') ORDER BY `ordering` ASC', 'id');
63 - }
64 -
65 - public function getFieldsByType($types)
66 - {
67 - if (empty($types)) return [];
68 - if (!is_array($types)) $types = [$types];
69 - $types = array_map('acym_escapeDB', $types);
70 - $query = 'SELECT * FROM #__acym_field WHERE `type` IN('.implode(',', $types).') ORDER BY `ordering` ASC';
71 -
72 - return acym_loadObjectList($query);
73 - }
74 -
75 - public function getOrdering()
76 - {
77 - return acym_loadResult('SELECT COUNT(id) FROM #__acym_field');
78 - }
79 -
80 - public function getAllFieldsForUser()
81 - {
82 - $query = 'SELECT * FROM #__acym_field WHERE id NOT IN (1, 2) ORDER BY `ordering` ASC';
83 -
84 - return acym_loadObjectList($query, 'id');
85 - }
86 -
87 - public function getAllFieldsForModuleFront()
88 - {
89 - return acym_loadObjectList(
90 - 'SELECT *
91 - FROM #__acym_field
92 - WHERE id != 2
93 - AND active = 1
94 - ORDER BY `ordering` ASC',
95 - 'id'
96 - );
97 - }
98 -
99 - public function getFieldsValueByUserId($userId)
100 - {
101 - $query = 'SELECT * FROM #__acym_user_has_field WHERE user_id = '.intval($userId);
102 -
103 - return acym_loadObjectList($query, 'field_id');
104 - }
105 -
106 - public function getFieldsValueByFieldId($fieldId)
107 - {
108 - return acym_loadObjectList('SELECT * FROM #__acym_user_has_field WHERE field_id = '.intval($fieldId));
109 - }
110 -
111 - public function generateNamekey($name, $namekey = '')
112 - {
113 - $fieldsNamekey = acym_loadResultArray('SELECT namekey FROM #__acym_field');
114 - $columnsUser = acym_getColumns('user');
115 - $namekeyForbidden = array_merge($fieldsNamekey, $columnsUser);
116 -
117 - $namekey = empty($namekey) ? substr(preg_replace('#[^a-z0-9_]#i', '', strtolower($name)), 0, 50) : $namekey;
118 - $baseNamekey = $namekey;
119 - $baseCount = count($namekeyForbidden);
120 -
121 - while (in_array($namekey, $namekeyForbidden)) {
122 - $namekey = $baseNamekey.'_'.$baseCount;
123 - $baseCount++;
124 - }
125 -
126 - return $namekey;
127 - }
128 -
129 - public function getValueFromDB($fieldDB)
130 - {
131 - $query = 'SELECT '.acym_secureDBColumn($fieldDB->value).' AS value, '.acym_secureDBColumn($fieldDB->title).' AS title
132 - FROM `'.acym_secureDBColumn($fieldDB->database).'`.`'.acym_secureDBColumn($fieldDB->table).'`';
133 - $query .= isset($fieldDB->where_value) && strlen($fieldDB->where_value) > 0 ? ' WHERE `'.acym_secureDBColumn($fieldDB->where).'` '.$fieldDB->where_sign.' '.acym_escapeDB(
134 - $fieldDB->where_value
135 - ) : '';
136 - if (!empty($fieldDB->order_by)) $query .= ' ORDER BY '.acym_secureDBColumn($fieldDB->order_by).' '.acym_secureDBColumn($fieldDB->sort_order);
137 -
138 - return acym_loadObjectList($query);
139 - }
140 -
141 - public function store($userID, $fields, $ajax = false)
142 - {
143 - if (!empty($_FILES['customField'])) {
144 - $uploadFolder = trim(acym_cleanPath(html_entity_decode(acym_getFilesFolder(true))), DS.' ').DS;
145 - $uploadPath = acym_cleanPath(ACYM_ROOT.$uploadFolder.'userfiles'.DS);
146 - $allowedExtensions = explode(',', $this->config->get('allowed_files'));
147 -
148 - foreach ($_FILES['customField']['tmp_name'] as $key => $value) {
149 - if (is_array($value) && isset($value[0])) $value = $value[0];
150 - if (empty($value)) continue;
151 -
152 - $fileName = $_FILES['customField']['name'][$key];
153 - while (is_array($fileName) && isset($fileName[0])) {
154 - $fileName = $fileName[0];
155 - }
156 -
157 - if (!preg_match('#\.('.implode('|', $allowedExtensions).')$#Ui', $fileName)) {
158 - $ext = substr($fileName, strrpos($fileName, '.') + 1);
159 - if ($ajax) {
160 - $this->errors[] = acym_translationSprintf(
161 - 'ACYM_ACCEPTED_TYPE',
162 - acym_escape($ext),
163 - implode(', ', $allowedExtensions)
164 - );
165 - } else {
166 - acym_enqueueMessage(
167 - acym_translationSprintf(
168 - 'ACYM_ACCEPTED_TYPE',
169 - acym_escape($ext),
170 - implode(', ', $allowedExtensions)
171 - ),
172 - 'error',
173 - 5000
174 - );
175 - }
176 -
177 - continue;
178 - }
179 -
180 - if (!acym_uploadFile($value, $uploadPath.$fileName)) {
181 - if ($ajax) {
182 - $this->errors[] = acym_translation('ACYM_ERROR_SAVING');
183 - } else {
184 - acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error');
185 - }
186 -
187 - continue;
188 - }
189 - $fields[$key] = $_FILES['customField']['name'][$key];
190 - }
191 - }
192 -
193 - if (empty($fields)) return;
194 -
195 - foreach ($fields as $id => $value) {
196 - $field = $this->getOneById($id);
197 - if (empty($field)) {
198 - acym_enqueueMessage(acym_translationSprintf('ACYM_WRONG_FIELD_ID', $id), 'error');
199 - continue;
200 - }
201 - $fieldOptions = @json_decode(empty($field->option) ? '{}' : $field->option);
202 -
203 - if (is_array($value)) {
204 - if (in_array($field->type, ['multiple_dropdown', 'radio', 'phone'])) {
205 - if ($field->type === 'phone' && !empty($fieldOptions->max_characters) && !empty($value['phone'])) {
206 - $value['phone'] = substr($value['phone'], 0, $fieldOptions->max_characters);
207 - }
208 -
209 - $value = implode(',', $value);
210 - if ($value === ',') $value = '';
211 - } elseif ($field->type == 'checkbox') {
212 - $value = implode(',', array_keys($value));
213 - } elseif ($field->type == 'date') {
214 - $formatToDisplay = explode('%', $fieldOptions->format);
215 - unset($formatToDisplay[0]);
216 -
217 - $year = '0000';
218 - $month = '00';
219 - $day = '00';
220 - $i = 0;
221 - foreach ($formatToDisplay as $one) {
222 - if ($one === 'd') {
223 - $day = $value[$i];
224 - }
225 - if ($one === 'm') {
226 - $month = $value[$i];
227 - }
228 - if ($one === 'y') {
229 - $year = $value[$i];
230 - }
231 - $i++;
232 - }
233 -
234 - $value = $year.'-'.$month.'-'.$day;
235 - } else {
236 - $value = json_encode($value);
237 - }
238 - }
239 -
240 - if (in_array($field->type, ['text', 'textarea']) && !empty($fieldOptions->max_characters)) {
241 - $value = substr($value, 0, $fieldOptions->max_characters);
242 - }
243 -
244 - if (strlen($value) === 0) {
245 - $query = 'DELETE FROM `#__acym_user_has_field`
246 - WHERE `user_id` = '.intval($userID).'
247 - AND `field_id` = '.intval($id);
248 - } else {
249 - $query = 'INSERT INTO #__acym_user_has_field (`user_id`, `field_id`, `value`) VALUES ('.intval($userID).', '.intval($id).', '.acym_escapeDB($value).')';
250 - $query .= ' ON DUPLICATE KEY UPDATE `value`= VALUES(`value`)';
251 - }
252 -
253 - acym_query($query);
254 - }
255 - }
256 -
257 - public function getAllFieldsByUserIds($userIds)
258 - {
259 - acym_arrayToInteger($userIds);
260 - if (empty($userIds)) return [];
261 -
262 - $query = 'SELECT user_field.user_id, user_field.value, field.name FROM #__acym_user_has_field AS user_field
263 - JOIN #__acym_field AS field ON user_field.field_id = field.id
264 - WHERE user_field.user_id IN ('.implode(',', $userIds).')';
265 -
266 - return acym_loadObjectList($query);
267 - }
268 -
269 - public function getAllFieldsListingByUserIds($userIds, $fieldIds, $listing = ''): array
270 - {
271 - $query = 'SELECT field.type AS `type`, field.value AS `value`, field.name AS field_name, user_field.user_id AS user_id, user_field.field_id AS field_id, user_field.value AS field_value, field.active, field.option
272 - FROM #__acym_user_has_field AS user_field
273 - JOIN #__acym_field AS field ON user_field.field_id = field.id';
274 -
275 - $conditions = [];
276 -
277 - if (!empty($listing)) $conditions[] = $listing;
278 -
279 - if (!is_array($userIds)) $userIds = [$userIds];
280 - acym_arrayToInteger($userIds);
281 - if (empty($userIds)) return [];
282 -
283 - if (!is_array($fieldIds)) $fieldIds = [$fieldIds];
284 - acym_arrayToInteger($fieldIds);
285 - if (empty($fieldIds)) return [];
286 -
287 - $conditions[] = 'user_field.user_id IN ('.implode(',', $userIds).')';
288 - $conditions[] = 'user_field.field_id IN ('.implode(',', $fieldIds).')';
289 -
290 - if (!empty($conditions)) {
291 - $query .= ' WHERE ('.implode(') AND (', $conditions).')';
292 - }
293 -
294 - $fieldValues = [];
295 - $values = acym_loadObjectList($query);
296 -
297 - $fieldsTypeWithInField = ['radio', 'checkbox', 'single_dropdown', 'multiple_dropdown'];
298 - foreach ($values as $one) {
299 - if (intval($one->active) === 0) {
300 - continue;
301 - }
302 -
303 - $key = $one->field_id.'-'.$one->user_id;
304 -
305 - if (!in_array($one->type, $fieldsTypeWithInField)) {
306 - if ($one->type === 'phone') {
307 - if (empty($one->field_value)) {
308 - $fieldValues[$key] = '';
309 - } else {
310 - if (substr($one->field_value, 0, 1) === ',') {
311 - $fieldValues[$key] = str_replace(',', '', $one->field_value);
312 - } else {
313 - $fieldValues[$key] = '+'.str_replace(',', ' ', $one->field_value);
314 - }
315 - }
316 - } elseif ($one->type === 'date') {
317 - if (empty($one->field_value)) {
318 - $fieldValues[$key] = '';
319 - } else {
320 - $one->option = json_decode($one->option);
321 - $fieldValues[$key] = acym_displayDateFormat($one->option->format, '', $one->field_value, [], false);
322 - }
323 - } else {
324 - $decoded = json_decode($one->field_value);
325 - $fieldValues[$key] = is_array($decoded) ? implode(', ', $decoded) : $one->field_value;
326 - }
327 - } else {
328 - $defaultValues = json_decode($one->value, true);
329 - $defaultValues = array_filter($defaultValues, function ($fieldOption) {
330 - return !empty($fieldOption['value']) || !empty($fieldOption['title']);
331 - });
332 -
333 - if (empty($defaultValues)) {
334 - if (!empty($one->field_value)) {
335 - $fieldOptions = json_decode($one->option, true);
336 - if (!empty($fieldOptions['fieldDB'])) {
337 - $dbOptions = json_decode($fieldOptions['fieldDB'], true);
338 - if (!empty($dbOptions['database']) && !empty($dbOptions['table']) && !empty($dbOptions['value']) && !empty($dbOptions['title'])) {
339 - $query = 'SELECT '.acym_secureDBColumn($dbOptions['title']).'
340 - FROM '.acym_secureDBColumn($dbOptions['database']).'.'.acym_secureDBColumn($dbOptions['table']).'
341 - WHERE '.acym_secureDBColumn($dbOptions['value']).' = '.acym_escapeDB($one->field_value);
342 - $fieldValues[$key][] = acym_loadResult($query);
343 - }
344 - }
345 - }
346 - } else {
347 - foreach ($defaultValues as $oneValue) {
348 - if (!in_array($oneValue['value'], explode(',', $one->field_value))) continue;
349 - $fieldValues[$key][] = $oneValue['title'];
350 - }
351 - }
352 -
353 - if (!empty($fieldValues[$key])) {
354 - $fieldValues[$key] = implode(', ', $fieldValues[$key]);
355 - }
356 - }
357 - }
358 -
359 - return $fieldValues;
360 - }
361 -
362 - public function getAllFieldsBackendListing()
363 - {
364 - $whereLanguage = '(backend_listing = 1 OR `type` = "language")';
365 - $query = 'SELECT id, name FROM #__acym_field WHERE '.$whereLanguage.' AND active = 1 AND id NOT IN (1, 2) ORDER BY ordering';
366 -
367 - $return = [
368 - 'names' => [],
369 - 'ids' => [],
370 - ];
371 -
372 - foreach (acym_loadObjectList($query) as $one) {
373 - $return['names'][] = $one->name;
374 - $return['ids'][] = $one->id;
375 - }
376 -
377 - return $return;
378 - }
379 -
380 - public function getAllFieldsFrontendListing()
381 - {
382 - $query = 'SELECT id, name FROM #__acym_field WHERE frontend_listing = 1 AND active = 1 AND id NOT IN (1, 2)';
383 -
384 - $return = [
385 - 'names' => [],
386 - 'ids' => [],
387 - ];
388 -
389 - foreach (acym_loadObjectList($query) as $one) {
390 - $return['names'][] = $one->name;
391 - $return['ids'][] = $one->id;
392 - }
393 -
394 - return $return;
395 - }
396 -
397 - public function delete($elements)
398 - {
399 - if (empty($elements)) return 0;
400 -
401 - if (!is_array($elements)) $elements = [$elements];
402 - acym_arrayToInteger($elements);
403 -
404 - acym_trigger('specialActionOnDelete', ['field', $elements]);
405 -
406 - acym_query('DELETE FROM #__acym_user_has_field WHERE field_id IN ('.implode(',', $elements).')');
407 -
408 - return parent::delete($elements);
409 - }
410 -
411 - public function displayField(
412 - $field,
413 - $defaultValue,
414 - $size,
415 - $valuesArray,
416 - $displayOutside = true,
417 - $displayFront = false,
418 - $user = null,
419 - $display = 1,
420 - $displayIf = '',
421 - $userClasses = []
422 - ) {
423 - $allClasses = !empty($userClasses['all']) ? $userClasses['all'] : '';
424 - $textClasses = !empty($userClasses['text']) ? $userClasses['text'] : '';
425 - $emailClasses = !empty($userClasses['email']) ? $userClasses['email'] : '';
426 - $radioClasses = !empty($userClasses['radio']) ? $userClasses['radio'] : '';
427 - $checkboxClasses = !empty($userClasses['checkbox']) ? $userClasses['checkbox'] : '';
428 - $dateClasses = !empty($userClasses['date']) ? $userClasses['date'] : '';
429 - $phoneClasses = !empty($userClasses['phone']) ? $userClasses['phone'] : '';
430 - $multipleDropdownClasses = !empty($userClasses['multiple_dropdown']) ? $userClasses['multiple_dropdown'] : '';
431 -
432 - $extraErrors = $this->config->get('extra_errors', '0');
433 - $isCoreField = $field->core == 1;
434 -
435 - if (!$isCoreField && !acym_level(ACYM_ENTERPRISE)) return '';
436 -
437 - if ($display == 0 && acym_isAdmin() && acym_level(ACYM_ENTERPRISE) && !$isCoreField) return '';
438 -
439 - if ($display == 0 && !acym_isAdmin()) return '';
440 -
441 - $return = '';
442 -
443 - $cmsUser = false;
444 - if ($displayFront && !empty($user->id)) {
445 - $cmsUser = !empty($user->cms_id);
446 - if ($field->id == 1) {
447 - $defaultValue = $user->name;
448 - } elseif ($field->id == 2) {
449 - $defaultValue = $user->email;
450 - } else {
451 - $allValues = [];
452 - $defaultUserValue = $this->getFieldsValueByUserId($user->id);
453 - if (!empty($defaultUserValue)) {
454 - foreach ($defaultUserValue as $one) {
455 - $allValues[$one->field_id] = $one->value;
456 - }
457 - }
458 -
459 - if (isset($allValues[$field->id])) {
460 - $defaultValue = is_null(json_decode($allValues[$field->id])) ? $allValues[$field->id] : json_decode($allValues[$field->id]);
461 - }
462 - }
463 - }
464 -
465 - if (in_array($field->type, ['radio', 'checkbox'])) {
466 - $valuesArrayTmp = [];
467 - foreach ($valuesArray as $oneValue) {
468 - if (!is_object($oneValue)) {
469 - $valuesArrayTmp = $valuesArray;
470 - break;
471 - }
472 -
473 - if (!empty($oneValue->disable)) continue;
474 - $valuesArrayTmp[$oneValue->value] = $oneValue->text;
475 - }
476 - $valuesArray = $valuesArrayTmp;
477 - }
478 -
479 - if (is_array($valuesArray)) {
480 - foreach ($valuesArray as $key => $oneValue) {
481 - if (is_object($oneValue) && !empty($valuesArray[$key]->text)) {
482 - $valuesArray[$key]->text = acym_translation($valuesArray[$key]->text);
483 - } elseif (is_string($oneValue)) {
484 - $valuesArray[$key] = acym_translation($valuesArray[$key]);
485 - }
486 - }
487 - }
488 -
489 - if (acym_isMultilingual() && $displayFront && !empty($field->translation)) {
490 - $field->translation = json_decode($field->translation, true);
491 - if (!empty($field->translation[acym_getLanguageTag()]) && !empty($field->translation[acym_getLanguageTag()]['name'])) {
492 - $field->name = $field->translation[acym_getLanguageTag()]['name'];
493 - }
494 - }
495 -
496 - $field->name = acym_translation($field->name);
497 -
498 - if (empty((array)$field->option) || !isset($field->option->authorized_content)) {
499 - $authorizedContent = '';
500 - } else {
501 - if (empty($field->option->error_message_invalid)) {
502 - $field->option->authorized_content->message = acym_translationSprintf('ACYM_INCORRECT_FIELD_VALUE', $field->name);
503 - } else {
504 - $field->option->authorized_content->message = $field->option->error_message_invalid;
505 - }
506 - $authorizedContent = ' data-authorized-content="'.acym_escape($field->option->authorized_content, false).'"';
507 - }
508 -
509 - $attributesSelectField = [];
510 - $maxCharacters = empty($field->option->max_characters) ? '' : ' maxlength="'.$field->option->max_characters.'"';
511 - $style = '';
512 - if (!empty($size)) {
513 - $attributesSelectField['style'] = $size;
514 - $style = ' style="'.$size.'"';
515 - }
516 -
517 - $placeholder = '';
518 - if (!$displayOutside) $placeholder = ' placeholder="'.acym_escape($field->name).'"';
519 -
520 - $name = 'customField['.intval($field->id).']';
521 - $nameAttribute = ' name="'.$name.'"';
522 - if ($field->type === 'text') {
523 - $value = ' value="'.acym_escape($defaultValue).'"';
524 - }
525 -
526 - if (($displayOutside && (in_array($field->id, [1, 2]) || in_array(
527 - $field->type,
528 - ['text', 'textarea', 'single_dropdown', 'multiple_dropdown', 'custom_text', 'file', 'language']
529 - )))) {
530 - $return .= '<label '.$displayIf.' class="cell margin-top-1"><span class="acym__users__creation__fields__title">'.$field->name.'</span>';
531 - }
532 - if ($displayOutside && in_array($field->type, ['date', 'radio', 'checkbox'])) {
533 - $return .= '<div '.$displayIf.' class="cell margin-top-1"><div class="acym__users__creation__fields__title">'.$field->name.'</div>';
534 - }
535 -
536 - $messageRequired = empty($field->option->error_message) ? '' : acym_translation($field->option->error_message);
537 - $requiredJson = json_encode(['type' => $field->type, 'message' => $messageRequired]);
538 - $required = '';
539 - if ($field->required) {
540 - $required = ' data-required="'.acym_escape($requiredJson).'"';
541 - $attributesSelectField['data-required'] = $requiredJson;
542 - }
543 -
544 - $readonly = '';
545 - if ($display == 0 && acym_isAdmin() && acym_level(ACYM_ENTERPRISE) && $isCoreField) {
546 - $attributesSelectField['disabled'] = true;
547 - unset($attributesSelectField['data-required']);
548 - $readonly = ' disabled ';
549 - $required = '';
550 - }
551 -
552 - if ($field->id == 1) {
553 - $nameAttribute = ' name="user[name]"';
554 - $inputTmp = '<input '.$nameAttribute.$placeholder.$required.$value.$authorizedContent.$style.$maxCharacters.$readonly.' type="text" class="cell '.$allClasses.' '.$textClasses.'"'.'>';
555 - if (!empty($readonly)) {
556 - $inputTmp = acym_tooltip(
557 - [
558 - 'hoveredText' => $inputTmp,
559 - 'textShownInTooltip' => acym_translation('ACYM_CF_EDITION_BLOCKED'),
560 - ]
561 - );
562 - }
563 - $return .= $inputTmp;
564 - } elseif ($field->id == 2) {
565 - $nameAttribute = ' name="user[email]"';
566 - $uniqueId = 'email_field_'.rand(100, 900);
567 - $inputTmp = '<input id="'.$uniqueId.'" '.$nameAttribute.$placeholder.$value.$authorizedContent.$style.$maxCharacters.$readonly.' required type="email" class="cell acym__user__edit__email '.$allClasses.' '.$emailClasses.'"'.($displayFront && $cmsUser
568 - ? 'disabled' : '').'>';
569 - if (!empty($readonly)) {
570 - $inputTmp = acym_tooltip(
571 - [
572 - 'hoveredText' => $inputTmp,
573 - 'textShownInTooltip' => acym_translation('ACYM_CF_EDITION_BLOCKED'),
574 - ]
575 - );
576 - }
577 - $return .= $inputTmp;
578 - if ($displayFront && !$cmsUser && !empty($this->config->get('email_spellcheck'))) {
579 - $return .= '<ul acym-data-field="'.$uniqueId.'" class="acym_email_suggestions" style="display: none;"></ul>';
580 - }
581 - } elseif ($field->type === 'language') {
582 - if (empty($defaultValue) && !empty($user->language)) {
583 - $defaultValue = $user->language;
584 - }
585 -
586 - $attributesSelectField['class'] = 'acym__select '.$allClasses;
587 - if (!empty($userClasses['language'])) {
588 - $attributesSelectField['class'] .= ' '.$userClasses['language'];
589 - }
590 - $selectTmp = acym_select(
591 - $this->getLanguagesForDropdown(),
592 - 'user[language]',
593 - empty($defaultValue) ? acym_getLanguageTag() : $defaultValue,
594 - $attributesSelectField
595 - );
596 -
597 - if (!empty($readonly)) {
598 - $selectTmp = acym_tooltip(
599 - [
600 - 'hoveredText' => $selectTmp,
601 - 'textShownInTooltip' => acym_translation('ACYM_CF_EDITION_BLOCKED'),
602 - ]
603 - );
604 - }
605 - $return .= $selectTmp;
606 - } elseif ($field->type === 'text') {
607 - $return .= '<input '.$nameAttribute.$placeholder.$required.$value.$authorizedContent.$style.$maxCharacters.' type="text">';
608 - } elseif ($field->type === 'textarea') {
609 - $return .= '<textarea '.$nameAttribute.$required.$maxCharacters.' rows="'.intval($field->option->rows).'" cols="'.intval(
610 - $field->option->columns
611 - ).'">'.(empty($defaultValue) ? '' : $defaultValue).'</textarea>';
612 - } elseif ($field->type === 'radio') {
613 - $defaultValue = strlen($defaultValue) === 0 ? null : $defaultValue;
614 - if ($displayFront) {
615 - foreach ($valuesArray as $key => $oneValue) {
616 - $isCkecked = $defaultValue == $key ? 'checked' : '';
617 - $return .= '<label><input '.$nameAttribute.$required.' type="radio" value="'.acym_escape(
618 - $key
619 - ).'" '.$isCkecked.((!empty($allClasses) || !empty($radioClasses)) ? ' class="'.$allClasses.' '.$radioClasses.'"' : '').'> '.$oneValue.'</label>';
620 - }
621 - } else {
622 - $return .= acym_radio(
623 - $valuesArray,
624 - $name.'[]',
625 - $defaultValue,
626 - $field->required ? ['data-required' => $requiredJson] : []
627 - );
628 - }
629 - } elseif ($field->type === 'checkbox') {
630 - if ($displayFront) {
631 - $defaultValue = empty($defaultValue) ? null : (explode(',', $defaultValue));
632 - foreach ($valuesArray as $key => $oneValue) {
633 - $checked = !empty($defaultValue) && in_array($key, $defaultValue) ? 'checked' : '';
634 - $return .= '<label><input '.$required.' type="checkbox" name="'.$name.'['.acym_escape($key).']" value="'.acym_escape(
635 - $key
636 - ).'" '.$checked.((!empty($allClasses) || !empty($checkboxClasses)) ? ' class="'.$allClasses.' '.$checkboxClasses.'"' : '').'> '.$oneValue.'</label>';
637 - }
638 - } else {
639 - if (!empty($defaultValue) && !is_object($defaultValue)) {
640 - $defaultValue = explode(',', $defaultValue);
641 - $temporaryObject = new \stdClass();
642 - foreach ($defaultValue as $oneValue) {
643 - $temporaryObject->$oneValue = 'on';
644 - }
645 - $defaultValue = $temporaryObject;
646 - }
647 - $defaultValue = is_object($defaultValue) ? $defaultValue : new \stdClass();
648 - foreach ($valuesArray as $key => $oneValue) {
649 - if (empty($defaultValue->$key)) {
650 - $labelClass = 'class="cell margin-top-1"';
651 - $attributes = '';
652 - } else {
653 - $labelClass = '';
654 - $attributes = 'checked '.$required;
655 - }
656 - $return .= '<label '.$labelClass.'>';
657 - $return .= '<input '.$attributes.' type="checkbox" name="'.$name.'['.acym_escape(
658 - $key
659 - ).']" class="acym__users__creation__fields__checkbox">'.$oneValue.'</label>';
660 - }
661 - }
662 - } elseif ($field->type === 'single_dropdown') {
663 - $attributesSelectField['class'] = 'acym__custom__fields__select__form acym__select '.$allClasses;
664 - if (!empty($userClasses['single_dropdown'])) {
665 - $attributesSelectField['class'] .= ' '.$userClasses['single_dropdown'];
666 - }
667 - $return .= acym_select(
668 - $valuesArray,
669 - $name,
670 - empty($defaultValue) ? '' : $defaultValue,
671 - $attributesSelectField
672 - );
673 - } elseif ($field->type === 'multiple_dropdown') {
674 - $defaultValue = is_array($defaultValue) ? $defaultValue : explode(',', $defaultValue);
675 -
676 - $attributes = [
677 - 'class' => 'acym__custom__fields__select__multiple__form acym__select '.$allClasses.' '.$multipleDropdownClasses,
678 - 'style' => $size,
679 - ];
680 - if ($field->required) $attributes['data-required'] = $displayFront ? acym_escape($requiredJson) : $requiredJson;
681 -
682 - $return .= acym_selectMultiple($valuesArray, $name, empty($defaultValue) ? [] : $defaultValue, $attributes);
683 - } elseif ($field->type === 'date') {
684 - $attributes = [
685 - 'class' => 'acym__custom__fields__select__form acym__select '.$allClasses.' '.$dateClasses,
686 - 'acym-field-type' => 'date',
687 - ];
688 - if (!empty($required)) {
689 - $attributes['data-required'] = $requiredJson;
690 - }
691 - $return .= acym_displayDateFormat(
692 - $field->option->format,
693 - $name.'[]',
694 - $defaultValue,
695 - $attributes
696 - );
697 - } elseif ($field->type === 'file') {
698 - $defaultValue = is_array($defaultValue) ? $defaultValue[0] : $defaultValue;
699 - if ($displayFront) {
700 - $return .= '<input '.$nameAttribute.$required.' type="file">';
701 - } else {
702 - $return .= acym_inputFile($name.'[]', $defaultValue, '', '', $required);
703 - }
704 - } elseif ($field->type === 'phone') {
705 - $defaultValue = !empty($defaultValue) ? explode(',', $defaultValue) : '';
706 - $indicator = !empty($defaultValue[0]) ? $defaultValue[0] : '';
707 - $number = !empty($defaultValue[1]) ? $defaultValue[1] : '';
708 -
709 - if ($displayOutside) $return .= '<div '.$displayIf.' class="cell margin-top-1 grid-x"><div class="acym__users__creation__fields__title cell">'.$field->name.'</div>';
710 - $return .= '<div class="cell large-5 medium-4 padding-right-1">';
711 - $return .= acym_generateCountryNumber($name.'[code]', $indicator);
712 - $return .= '</div>';
713 - $return .= '<input '.$placeholder.$required.$style.$maxCharacters.' class="cell large-7 medium-8 '.$allClasses.' '.$phoneClasses.'"'.' type="tel" name="'.$name.'[phone]" value="'.acym_escape(
714 - $number
715 - ).'">';
716 - if ($displayOutside) $return .= '</div>';
717 - } elseif ($field->type === 'custom_text') {
718 - $return .= $field->option->custom_text;
719 - }
720 -
721 - $labelTypes = ['text', 'textarea', 'single_dropdown', 'multiple_dropdown', 'custom_text', 'file', 'language'];
722 - if ($displayOutside && (in_array($field->id, [1, 2]) || in_array($field->type, $labelTypes))) {
723 - $return .= '</label>';
724 - }
725 - if ($displayOutside && in_array($field->type, ['date', 'radio', 'checkbox'])) {
726 - $return .= '</div>';
727 - }
728 -
729 - $return .= '<div class="acym__field__error__block" data-acym-field-id="'.intval($field->id).'"></div>';
730 - if ($displayFront && $extraErrors && !acym_isAdmin()) {
731 - $return .= '<div class="acym__message__invalid__field acym__color__error" style="display: none;">';
732 - $return .= '<i class="acymicon-times-circle acym__cross__invalid acym__color__error"></i>'.acym_translation('ACYM_THANKS_TO_FILL_IN_THIS_FIELD').'</div>';
733 - }
734 -
735 - return $return;
736 - }
737 -
738 - public function getFieldTypeById($id)
739 - {
740 - $query = 'SELECT type FROM #__acym_field WHERE id = '.intval($id);
741 -
742 - return acym_loadResult($query);
743 - }
744 -
745 - public function setInactive($elements)
746 - {
747 - if (!is_array($elements)) $elements = [$elements];
748 - if (empty($elements)) return 0;
749 - acym_arrayToInteger($elements);
750 -
751 - $excludedFields = acym_loadResultArray('SELECT `id` FROM #__acym_field WHERE `core` = 1');
752 - acym_arrayToInteger($excludedFields);
753 -
754 - $elements = array_diff($elements, $excludedFields);
755 -
756 - parent::setInactive($elements);
757 - }
758 -
759 - public function insertLanguageField()
760 - {
761 - if ($this->getLanguageFieldId() !== false) {
762 - return false;
763 - }
764 -
765 - $field = new \stdClass();
766 - $field->name = 'ACYM_LANGUAGE';
767 - $field->type = 'language';
768 - $field->active = 1;
769 - $field->required = 1;
770 - $field->ordering = $this->getOrdering() + 1;
771 - $field->core = 1;
772 - $field->backend_edition = 1;
773 - $field->backend_listing = 0;
774 - $field->frontend_edition = 1;
775 - $field->frontend_listing = 0;
776 - $field->namekey = 'acym_language';
777 -
778 - $rowId = acym_insertObject('#__acym_field', $field);
779 -
780 - if (empty($rowId)) return false;
781 -
782 - return $this->config->save([self::LANGUAGE_FIELD_ID_KEY => $rowId]);
783 - }
784 -
785 - public function getLanguageFieldId()
786 - {
787 - $languageFieldId = acym_loadResult('SELECT `id` FROM `#__acym_field` WHERE `namekey` = "acym_language"');
788 -
789 - return empty($languageFieldId) ? false : $languageFieldId;
790 - }
791 -
792 - public function getLanguagesForDropdown()
793 - {
794 - $languages = acym_getLanguages(false, true);
795 - $dataLanguages = [];
796 -
797 - foreach ($languages as $langCode => $language) {
798 - if ($langCode == "xx-XX") continue;
799 -
800 - $oneLanguage = new \stdClass();
801 - $oneLanguage->value = $langCode;
802 - $oneLanguage->text = $language->name;
803 -
804 - $dataLanguages[] = $oneLanguage;
805 - }
806 -
807 - usort($dataLanguages, function ($a, $b) {
808 - return strtolower($a->text) > strtolower($b->text) ? 1 : -1;
809 - });
810 -
811 - return $dataLanguages;
812 - }
813 -
814 - public function setEmailConfirmationField($displayOutside, $size, $container = 'div', $displayInline = false)
815 - {
816 - $uniqueId = 'email_confirmation_field_'.rand(100, 900);
817 - $name = acym_translation('ACYM_EMAIL_CONFIRMATION');
818 - $placeholder = !$displayOutside ? acym_translation('ACYM_EMAIL_CONFIRMATION') : '';
819 - $style = empty($size) ? '' : ' style="'.$size.'"';
820 - $extraErrors = $this->config->get('extra_errors', '0');
821 -
822 -
823 - $return = '<'.$container.' class="onefield acym_email_confirmation_field acyfield_text">';
824 - if ($displayOutside) $return .= '<label class="cell margin-top-1"><span class="acym__users__creation__fields__title">'.$name.'</span>';
825 - $return .= '<input id="'.$uniqueId.'" '.$style.' required type="email" class="cell acym__user__edit__email" name="user[email_confirmation]" placeholder="'.$placeholder.'">';
826 - $return .= '<span class="acym__field__error__block"></span>';
827 - if ($extraErrors && !acym_isAdmin()) {
828 - $return .= '<span class="acym__message__invalid__field acym__color__error" style="display: none;">';
829 - $return .= '<i class="acymicon-times-circle acym__cross__invalid acym__color__error"></i>'.acym_translation('ACYM_THANKS_TO_FILL_IN_THIS_FIELD').'</span>';
830 - }
831 - if ($displayOutside) $return .= '</label>';
832 - $return .= '</'.$container.'>';
833 -
834 - if ($container == 'td' && !$displayInline) {
835 - $return .= '</tr>';
836 - }
837 -
838 - return $return;
839 - }
840 -}
841 -