| @@ -1,32 +1,48 @@ | ||
| 1 | 1 | <?php |
| 2 | +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- View file, its variables are local to the include scope, not true globals. | |
| 2 | 3 | |
| 4 | +defined('ABSPATH') || die('Restricted Access'); | |
| 5 | + | |
| 6 | +// Prepare list display | |
| 3 | 7 | use AcyMailing\Helpers\CaptchaHelper; |
| 8 | +use AcyMailing\Helpers\SecurityHelper; | |
| 4 | 9 | |
| 5 | -$listsContent = ''; | |
| 6 | -if (!empty($visibleLists)) { | |
| 7 | - $listsContent .= '<div class="acym_lists">'; | |
| 8 | - foreach ($visibleLists as $myListId) { | |
| 9 | - $check = ''; | |
| 10 | - if (in_array($myListId, $checkedLists)) { | |
| 11 | - $check = 'checked="checked"'; | |
| 10 | +if (!function_exists('acymailing_displayWidgetLists')) { | |
| 11 | + function acymailing_displayWidgetLists($allLists, $visibleLists, $checkedLists, $formName) | |
| 12 | + { | |
| 13 | + if (empty($visibleLists)) { | |
| 14 | + return; | |
| 12 | 15 | } |
| 16 | + ?> | |
| 13 | 17 | |
| 14 | - $listsContent .= ' | |
| 15 | - <div class="onelist"> | |
| 16 | - <input type="checkbox" class="acym_checkbox" name="subscription[]" id="acylist_'.$myListId.'_'.$formName.'" '.$check.' value="'.$myListId.'"/> | |
| 17 | - <label for="acylist_'.$myListId.'_'.$formName.'">'.(!empty($allLists[$myListId]->display_name) ? $allLists[$myListId]->display_name : $allLists[$myListId]->name).'</label> | |
| 18 | - </div>'; | |
| 18 | + <div class="acym_lists" role="group" aria-label="<?php echo esc_attr(acym_translation('ACYM_NEWSLETTERS')); ?>"> | |
| 19 | + <?php foreach ($visibleLists as $myListId) { ?> | |
| 20 | + <div class="onelist"> | |
| 21 | + <input type="checkbox" | |
| 22 | + class="acym_checkbox" | |
| 23 | + name="subscription[]" | |
| 24 | + id="acylist_<?php echo esc_attr($myListId.'_'.$formName); ?>" | |
| 25 | + <?php checked(in_array($myListId, $checkedLists)); ?> | |
| 26 | + value="<?php echo esc_attr($myListId); ?>" /> | |
| 27 | + <label for="acylist_<?php echo esc_attr($myListId.'_'.$formName); ?>"> | |
| 28 | + <?php echo esc_html(!empty($allLists[$myListId]->display_name) ? $allLists[$myListId]->display_name : $allLists[$myListId]->name); ?> | |
| 29 | + </label> | |
| 30 | + </div> | |
| 31 | + <?php } ?> | |
| 32 | + </div> | |
| 33 | + <?php | |
| 19 | 34 | } |
| 20 | - $listsContent .= '</div>'; | |
| 21 | 35 | } |
| 22 | -if ($listPosition == 'before') echo $listsContent; | |
| 36 | +if ($listPosition === 'before') { | |
| 37 | + acymailing_displayWidgetLists($allLists, $visibleLists, $checkedLists, $formName); | |
| 38 | +} | |
| 23 | 39 | ?> |
| 24 | 40 | |
| 25 | 41 | <div class="acym_form"> |
| 26 | 42 | <?php |
| 27 | 43 | foreach ($fields as $field) { |
| 28 | - $field->option = json_decode($field->option); | |
| 44 | + $field->option = !empty($field->option) ? json_decode($field->option) : new stdClass(); | |
| 29 | 45 | $fieldDB = empty($field->option->fieldDB) ? '' : json_decode($field->option->fieldDB); |
| 30 | 46 | $field->value = empty($field->value) ? '' : json_decode($field->value); |
| 31 | 47 | $valuesArray = []; |
| 32 | 48 | if (!empty($field->value)) { |
| @@ -43,55 +59,76 @@ | ||
| 43 | 59 | foreach ($fromDB as $value) { |
| 44 | 60 | $valuesArray[$value->value] = $value->title; |
| 45 | 61 | } |
| 46 | 62 | } |
| 47 | - $size = empty($field->option->size) ? '' : 'width:'.$field->option->size.'px'; | |
| 48 | - echo '<div class="onefield fieldacy'.$field->id.' acyfield_'.$field->type.'" id="field_'.$field->id.'">'; | |
| 49 | - echo $fieldClass->displayField($field, $field->default_value, $size, $valuesArray, $displayOutside, true, $identifiedUser); | |
| 63 | + echo '<div class="onefield fieldacy'.esc_attr($field->id).' acyfield_'.esc_attr($field->type).'" id="field_'.esc_attr($field->id).'">'; | |
| 64 | + $fieldClass->displayField($field, $field->default_value, $valuesArray, $displayOutside, true, $identifiedUser); | |
| 50 | 65 | echo '</div>'; |
| 51 | 66 | |
| 52 | 67 | if ($field->id == 2 && $config->get('email_confirmation')) { |
| 53 | - echo $fieldClass->setEmailConfirmationField($displayOutside, $size); | |
| 68 | + $fieldClass->setEmailConfirmationField($displayOutside, $field); | |
| 54 | 69 | } |
| 55 | 70 | } |
| 56 | 71 | |
| 57 | - if ($listPosition != 'before') echo $listsContent; | |
| 72 | + if ($listPosition !== 'before') { | |
| 73 | + acymailing_displayWidgetLists($allLists, $visibleLists, $checkedLists, $formName); | |
| 74 | + } | |
| 58 | 75 | |
| 59 | 76 | if (empty($identifiedUser->id) && $config->get('captcha', 'none') !== 'none' && acym_level(ACYM_ESSENTIAL)) { |
| 60 | - echo '<div class="onefield fieldacycaptcha" id="field_captcha_'.$formName.'">'; | |
| 77 | + echo '<div class="onefield fieldacycaptcha" id="field_captcha_'.esc_attr($formName).'">'; | |
| 61 | 78 | $captcha = new CaptchaHelper(); |
| 62 | - echo $captcha->display($formName); | |
| 79 | + $captcha->display($formName); | |
| 63 | 80 | echo '</div>'; |
| 64 | 81 | } |
| 65 | 82 | |
| 66 | 83 | if (!empty($termslink)) { |
| 67 | - echo '<div class="onefield fieldacyterms" id="field_terms_'.$formName.'">'; | |
| 68 | - echo '<label for="mailingdata_terms_'.$formName.'">'; | |
| 69 | - echo '<input id="mailingdata_terms_'.$formName.'" class="checkbox" type="checkbox" name="terms" title="'.acym_translation('ACYM_TERMS_CONDITIONS').'"/> '.$termslink; | |
| 84 | + echo '<div class="onefield fieldacyterms" id="field_terms_'.esc_attr($formName).'">'; | |
| 85 | + echo '<label for="mailingdata_terms_'.esc_attr($formName).'">'; | |
| 86 | + echo '<input id="mailingdata_terms_'.esc_attr($formName).'" class="checkbox" type="checkbox" name="terms" aria-required="true" title="'.esc_attr( | |
| 87 | + acym_translation( | |
| 88 | + 'ACYM_TERMS_CONDITIONS' | |
| 89 | + ) | |
| 90 | + ).'"/> '; | |
| 91 | + echo wp_kses( | |
| 92 | + $termslink, | |
| 93 | + SecurityHelper::ALLOWED_HTML_TERMS | |
| 94 | + ); | |
| 70 | 95 | echo '</label>'; |
| 71 | 96 | echo '</div>'; |
| 72 | 97 | } |
| 98 | + | |
| 99 | + if (!empty($showTrackingConsent)) { | |
| 100 | + $trackingChecked = (int)($identifiedUser->tracking ?? 0) === 1; | |
| 101 | + echo '<div class="onefield fieldacytracking" id="field_tracking_'.esc_attr($formName).'">'; | |
| 102 | + echo '<label for="mailingdata_tracking_'.esc_attr($formName).'">'; | |
| 103 | + echo '<input type="hidden" name="user[tracking]" value="0"/>'; | |
| 104 | + echo '<input id="mailingdata_tracking_'.esc_attr($formName).'" class="acym_checkbox" type="checkbox" name="user[tracking]" value="1" '.checked($trackingChecked, true, false).'/> '.esc_html( | |
| 105 | + acym_translation('ACYM_TRACKING_CONSENT') | |
| 106 | + ); | |
| 107 | + echo '</label>'; | |
| 108 | + echo '</div>'; | |
| 109 | + } | |
| 73 | 110 | ?> |
| 74 | 111 | </div> |
| 75 | 112 | |
| 76 | 113 | <p class="acysubbuttons"> |
| 77 | -<noscript> | |
| 78 | - <?php echo acym_translation('ACYM_NO_JAVASCRIPT'); ?> | |
| 79 | -</noscript> | |
| 80 | -<?php | |
| 81 | -$onclickSubscribe = 'try{ return submitAcymForm("subscribe","'.$formName.'", "acymSubmitSubForm"); }catch(err){alert("The form could not be submitted "+err);return false;}'; | |
| 82 | -$onclickUnsubscribe = 'try{ return submitAcymForm("unsubscribe","'.$formName.'", "acymSubmitSubForm"); }catch(err){alert("The form could not be submitted "+err);return false;}'; | |
| 83 | -?> | |
| 84 | -<input type="button" | |
| 85 | - class="btn btn-primary button subbutton" | |
| 86 | - value="<?php echo acym_translation($subscribeText, true); ?>" | |
| 87 | - name="Submit" | |
| 88 | - onclick="<?php echo $disableButtons ? 'return true' : acym_escape($onclickSubscribe); ?>" /> | |
| 89 | -<?php if ($unsubButton === '2' || ($unsubButton === '1' && !empty($countUnsub))) { ?> | |
| 90 | - <span style="display: none;"></span> | |
| 91 | - <input type="button" | |
| 92 | - class="btn button unsubbutton" | |
| 93 | - value="<?php echo acym_translation($unsubscribeText, true); ?>" | |
| 94 | - name="Submit" | |
| 95 | - onclick="<?php echo $disableButtons ? 'return true' : acym_escape($onclickUnsubscribe); ?>" /> | |
| 96 | -<?php } ?> | |
| 114 | + <noscript><?php echo esc_html(acym_translation('ACYM_NO_JAVASCRIPT')); ?></noscript> | |
| 115 | + <?php | |
| 116 | + $onclickSubscribe = 'try{ return submitAcymForm("subscribe","'.$formName.'", "acymSubmitSubForm"); }catch(err){alert("The form could not be submitted "+err);return false;}'; | |
| 117 | + $onclickUnsubscribe = 'try{ return submitAcymForm("unsubscribe","'.$formName.'", "acymSubmitSubForm"); }catch(err){alert("The form could not be submitted "+err);return false;}'; | |
| 118 | + | |
| 119 | + if ($disableButtons) { | |
| 120 | + $onclickSubscribe = 'return false;'; | |
| 121 | + $onclickUnsubscribe = 'return false;'; | |
| 122 | + } | |
| 123 | + ?> | |
| 124 | + <button type="submit" | |
| 125 | + class="btn btn-primary button subbutton" | |
| 126 | + onclick="<?php echo esc_attr($onclickSubscribe); ?>"><?php echo esc_html(acym_translation($subscribeText)); ?> | |
| 127 | + </button> | |
| 128 | + <?php if ($unsubButton === '2' || ($unsubButton === '1' && !empty($countUnsub))) { ?> | |
| 129 | + <button type="submit" | |
| 130 | + class="btn button unsubbutton" | |
| 131 | + onclick="<?php echo esc_attr($onclickUnsubscribe); ?>"><?php echo esc_html(acym_translation($unsubscribeText)); ?> | |
| 132 | + </button> | |
| 133 | + <?php } ?> | |
| 97 | 134 | </p> |