| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- View file, its variables are local to the include scope, not true globals. |
| 3 |
defined('ABSPATH') || die('Restricted Access'); |
| 4 |
?> |
| 5 |
<div id="acym_fulldiv_<?php echo esc_attr($form->form_tag_name); ?>" |
| 6 |
class="acym__subscription__form__popup__overlay acym__subscription__form-erase" |
| 7 |
<?php |
| 8 |
if (!$edition && isset($form->settings['display']['scroll']) && $form->settings['display']['scroll'] != 0) { |
| 9 |
echo 'style="display: none;"'; |
| 10 |
} |
| 11 |
?>> |
| 12 |
<div class="acym__subscription__form__popup"> |
| 13 |
<div class="acym__subscription__form__popup__close acymicon-close"></div> |
| 14 |
<?php |
| 15 |
if ($edition) { |
| 16 |
echo '<form action="#" onsubmit="return false;" id="'.esc_attr($form->form_tag_name).'">'; |
| 17 |
} else { |
| 18 |
$isButton = $form->settings['display']['display_action'] === 'yes'; |
| 19 |
if ($isButton) { |
| 20 |
$cookieExpiration = '0'; |
| 21 |
} else { |
| 22 |
$cookieExpiration = empty($form->settings['cookie']['cookie_expiration']) ? '1' : $form->settings['cookie']['cookie_expiration']; |
| 23 |
} |
| 24 |
echo '<form acym-data-id="'.esc_attr($form->id).'" |
| 25 |
acym-data-cookie="'.intval($cookieExpiration).'" |
| 26 |
action="'.esc_url($form->form_tag_action).'" |
| 27 |
id="'.esc_attr($form->form_tag_name).'" |
| 28 |
name="'.esc_attr($form->form_tag_name).'" |
| 29 |
enctype="multipart/form-data" |
| 30 |
onsubmit="return submitAcymForm(\'subscribe\',\''.esc_attr($form->form_tag_name).'\', \'acymSubmitSubForm\')">'; |
| 31 |
} |
| 32 |
if (in_array($form->settings['style']['position'], ['image-top', 'image-left'])) { |
| 33 |
if (!empty($form->settings['message']['text']) && $form->settings['message']['position'] === 'before-image') { |
| 34 |
echo '<p id="acym__subscription__form__popup-text">'.nl2br(esc_html(acym_translation($form->settings['message']['text']))).'</p>'; |
| 35 |
} |
| 36 |
include acym_getPartial('forms', 'image'); |
| 37 |
} |
| 38 |
echo '<div class="acym__subscription__form__popup__fields-button">'; |
| 39 |
include acym_getPartial('forms', 'fields'); |
| 40 |
if (!empty($form->settings['message']['text']) && $form->settings['message']['position'] == 'before-button') { |
| 41 |
echo '<p id="acym__subscription__form__popup-text">'.nl2br(esc_html(acym_translation($form->settings['message']['text']))).'</p>'; |
| 42 |
} |
| 43 |
include acym_getPartial('forms', 'button'); |
| 44 |
echo '</div>'; |
| 45 |
if (in_array($form->settings['style']['position'], ['image-bottom', 'image-right'])) { |
| 46 |
if (!empty($form->settings['message']['text']) && $form->settings['message']['position'] == 'before-image') { |
| 47 |
echo '<p id="acym__subscription__form__popup-text">'.nl2br(esc_html(acym_translation($form->settings['message']['text']))).'</p>'; |
| 48 |
} |
| 49 |
include acym_getPartial('forms', 'image'); |
| 50 |
} |
| 51 |
include acym_getPartial('forms', 'hidden_params'); |
| 52 |
echo '</form>'; |
| 53 |
?> |
| 54 |
</div> |
| 55 |
</div> |
| 56 |
<?php |
| 57 |
$popupPosition = $form->settings['display']['popup_position'] ?? 'center'; |
| 58 |
$positionMap = [ |
| 59 |
'top_left' => 'top: 20px; left: 20px;', |
| 60 |
'top_center' => 'top: 20px; left: 50%; transform: translateX(-50%);', |
| 61 |
'top_right' => 'top: 20px; right: 20px;', |
| 62 |
'middle_left' => 'top: 50%; left: 20px; transform: translateY(-50%);', |
| 63 |
'middle_right' => 'top: 50%; right: 20px; transform: translateY(-50%);', |
| 64 |
'bottom_left' => 'bottom: 20px; left: 20px;', |
| 65 |
'bottom_center' => 'bottom: 20px; left: 50%; transform: translateX(-50%);', |
| 66 |
'bottom_right' => 'bottom: 20px; right: 20px;', |
| 67 |
]; |
| 68 |
$positionCss = $positionMap[$popupPosition] ?? 'top: 50%; left: 50%; transform: translate(-50%, -50%);'; |
| 69 |
?> |
| 70 |
<style> |
| 71 |
#acym_fulldiv_<?php echo esc_html($form->form_tag_name); ?>.acym__subscription__form__popup__overlay{ |
| 72 |
display: <?php echo $edition ? 'inline' : 'none'; ?>; |
| 73 |
<?php if ($popupPosition === 'center') { ?> |
| 74 |
position: fixed; |
| 75 |
top: 0; |
| 76 |
bottom: 0; |
| 77 |
right: 0; |
| 78 |
left: 0; |
| 79 |
background-color: rgba(200, 200, 200, .5); |
| 80 |
<?php } else { ?> |
| 81 |
position: static; |
| 82 |
<?php } ?> z-index: 999999; |
| 83 |
} |
| 84 |
|
| 85 |
#acym_fulldiv_<?php echo esc_html($form->form_tag_name); ?> .acym__subscription__form__popup__close{ |
| 86 |
position: absolute; |
| 87 |
top: 10px; |
| 88 |
right: 10px; |
| 89 |
font-weight: bold; |
| 90 |
font-size: 1rem; |
| 91 |
cursor: pointer; |
| 92 |
} |
| 93 |
|
| 94 |
#acym_fulldiv_<?php echo esc_html($form->form_tag_name); ?> .acym__subscription__form__popup{ |
| 95 |
position: fixed; |
| 96 |
<?php echo esc_html($positionCss); ?> padding: <?php echo esc_html($form->settings['style']['padding']['height']); ?>px <?php echo esc_html($form->settings['style']['padding']['width']); ?>px; |
| 97 |
background-color: <?php echo esc_html($form->settings['style']['background_color']); ?>; |
| 98 |
color: <?php echo esc_html($form->settings['style']['text_color']); ?> !important; |
| 99 |
background-image: url("<?php echo esc_url($form->settings['style']['background_image']); ?>"); |
| 100 |
background-size: <?php echo esc_html($form->settings['style']['background_size']); ?>; |
| 101 |
background-position: <?php echo esc_html(str_replace('_', ' ', $form->settings['style']['background_position'])); ?>; |
| 102 |
background-repeat: <?php echo esc_html($form->settings['style']['background_repeat']); ?>; |
| 103 |
border-radius: <?php echo intval($form->settings['style']['border_radius'] ?? 0); ?>px; |
| 104 |
box-shadow: <?php echo intval($form->settings['style']['shadow_x'] ?? 0); ?>px <?php echo intval($form->settings['style']['shadow_y'] ?? 0); ?>px <?php echo intval($form->settings['style']['shadow_blur'] ?? 0); ?>px<?php echo esc_html($form->settings['style']['shadow_color'] ?? 'rgba(0,0,0,0.2)'); ?>; |
| 105 |
z-index: 999999; |
| 106 |
text-align: center; |
| 107 |
display: flex; |
| 108 |
justify-content: center; |
| 109 |
align-items: center; |
| 110 |
} |
| 111 |
|
| 112 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .responseContainer{ |
| 113 |
margin-bottom: 0 !important; |
| 114 |
padding: .4rem !important; |
| 115 |
} |
| 116 |
|
| 117 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup <?php echo '#'.esc_html($form->form_tag_name); ?>{ |
| 118 |
margin: 0; |
| 119 |
} |
| 120 |
|
| 121 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__fields, <?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__button{ |
| 122 |
display: block; |
| 123 |
width: 100%; |
| 124 |
margin: 1rem 0 !important; |
| 125 |
} |
| 126 |
|
| 127 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__fields input:not([type="radio"]):not([type="checkbox"]), <?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__fields label{ |
| 128 |
display: block; |
| 129 |
} |
| 130 |
|
| 131 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__fields input[type="radio"], <?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__fields input[type="checkbox"]{ |
| 132 |
margin-left: 5px; |
| 133 |
} |
| 134 |
|
| 135 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__fields .acym__subscription__form__lists{ |
| 136 |
display: block; |
| 137 |
width: 100%; |
| 138 |
margin: 1rem 10px !important; |
| 139 |
} |
| 140 |
|
| 141 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup .acym__subscription__form__fields .acym__user__edit__email{ |
| 142 |
margin: auto; |
| 143 |
} |
| 144 |
|
| 145 |
<?php if (!empty($form->settings['message']['color'])) { ?> |
| 146 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>#acym__subscription__form__popup-text{ |
| 147 |
color: <?php echo esc_html($form->settings['message']['color']); ?>; |
| 148 |
} |
| 149 |
|
| 150 |
<?php } ?> |
| 151 |
|
| 152 |
<?php if (in_array($form->settings['style']['position'], ['image-right', 'image-left'])) { ?> |
| 153 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup <?php echo '#'.esc_html($form->form_tag_name); ?>{ |
| 154 |
display: flex; |
| 155 |
justify-content: center; |
| 156 |
align-items: center |
| 157 |
} |
| 158 |
|
| 159 |
<?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__popup__fields-button, <?php echo '#acym_fulldiv_'.esc_html($form->form_tag_name).' '; ?>.acym__subscription__form__image{ |
| 160 |
display: inline-block; |
| 161 |
} |
| 162 |
|
| 163 |
<?php } ?> |
| 164 |
|
| 165 |
</style> |
| 166 |
<?php if (!$edition) { ?> |
| 167 |
<script type="text/javascript"> |
| 168 |
const acymBackupFormTimeout<?php echo esc_html($form->form_tag_name); ?> = setTimeout(() => { |
| 169 |
acym_initPopupDisplay<?php echo esc_html($form->form_tag_name); ?>(true); |
| 170 |
}, 1000); |
| 171 |
|
| 172 |
window.addEventListener('DOMContentLoaded', function () { |
| 173 |
clearTimeout(acymBackupFormTimeout<?php echo esc_html($form->form_tag_name); ?>); |
| 174 |
acym_initPopupDisplay<?php echo esc_html($form->form_tag_name); ?>(); |
| 175 |
}); |
| 176 |
|
| 177 |
function acym_initPopupDisplay<?php echo esc_html($form->form_tag_name); ?>(addedDelayForBackup = false) { |
| 178 |
const acym_popupForm = document.querySelector('#acym_fulldiv_<?php echo esc_html($form->form_tag_name); ?>.acym__subscription__form__popup__overlay'); |
| 179 |
|
| 180 |
if (!acym_popupForm) { |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
const isDisplayButton = <?php echo $isButton ? 'true' : 'false'; ?>; |
| 185 |
|
| 186 |
function acym_closePopupform<?php echo esc_html($form->form_tag_name); ?>(element) { |
| 187 |
element.style.display = 'none'; |
| 188 |
|
| 189 |
if (isDisplayButton) { |
| 190 |
return; |
| 191 |
} |
| 192 |
|
| 193 |
let expirationDate = new Date(); |
| 194 |
expirationDate.setDate(expirationDate.getDate() + <?php echo empty($form->settings['cookie']['cookie_expiration']) ? 1 |
| 195 |
: intval($form->settings['cookie']['cookie_expiration']); ?>); |
| 196 |
document.cookie = 'acym_form_<?php echo esc_html($form->id); ?>=' + Date.now() + ';expires=' + expirationDate.toUTCString() + ';path=/'; |
| 197 |
} |
| 198 |
|
| 199 |
<?php if ($popupPosition === 'center') { ?> |
| 200 |
acym_popupForm.addEventListener('click', function (event) { |
| 201 |
if (event.target.closest('.acym__subscription__form__popup') === null) { |
| 202 |
acym_closePopupform<?php echo esc_html($form->form_tag_name); ?>(this); |
| 203 |
} |
| 204 |
}); |
| 205 |
<?php } ?> |
| 206 |
document.querySelector('#acym_fulldiv_<?php echo esc_html($form->form_tag_name); ?> .acym__subscription__form__popup__close') |
| 207 |
.addEventListener('click', function (event) { |
| 208 |
acym_closePopupform<?php echo esc_html($form->form_tag_name); ?>(event.target.closest('.acym__subscription__form__popup__overlay')); |
| 209 |
}); |
| 210 |
|
| 211 |
if (isDisplayButton) { |
| 212 |
displayByButton(); |
| 213 |
} else { |
| 214 |
displayByDelayAndScroll(); |
| 215 |
} |
| 216 |
|
| 217 |
function displayByButton() { |
| 218 |
const button = document.querySelector('#<?php echo esc_html($form->settings['display']['button']); ?>'); |
| 219 |
|
| 220 |
if (!button) { |
| 221 |
console.error('Could not find the button with the ID <?php echo esc_html($form->settings['display']['button']); ?>'); |
| 222 |
return; |
| 223 |
} |
| 224 |
|
| 225 |
button.addEventListener('click', function () { |
| 226 |
acym_popupForm.style.display = 'inline'; |
| 227 |
}); |
| 228 |
} |
| 229 |
|
| 230 |
function displayByDelayAndScroll() { |
| 231 |
const delayDisplay = parseInt(<?php echo esc_html($form->settings['display']['delay']); ?>); |
| 232 |
const scrollPercentLimit = parseInt(<?php echo esc_html($form->settings['display']['scroll']); ?>); |
| 233 |
let windowSize; |
| 234 |
let browserHeight; |
| 235 |
let delayRemaining = false; |
| 236 |
|
| 237 |
if (delayDisplay > 0) { |
| 238 |
delayRemaining = true; |
| 239 |
} |
| 240 |
|
| 241 |
let scrollRemaining = false; |
| 242 |
if (scrollPercentLimit > 0) { |
| 243 |
scrollRemaining = true; |
| 244 |
} |
| 245 |
|
| 246 |
windowSize = document.getElementsByTagName('body')[0].clientHeight; |
| 247 |
browserHeight = document.documentElement.clientHeight; |
| 248 |
|
| 249 |
if (!delayRemaining && ( |
| 250 |
windowSize <= browserHeight || !scrollRemaining |
| 251 |
)) { |
| 252 |
scrollRemaining = false; |
| 253 |
acym_popupForm.style.display = 'inline'; |
| 254 |
} else { |
| 255 |
function displayAcymPopupForm() { |
| 256 |
let scrollPercent = Math.round(( |
| 257 |
window.scrollY |
| 258 |
) / ( |
| 259 |
windowSize - browserHeight |
| 260 |
) * 100); |
| 261 |
if (scrollPercent >= scrollPercentLimit) { |
| 262 |
scrollRemaining = false; |
| 263 |
window.removeEventListener('scroll', displayAcymPopupForm); |
| 264 |
if (!delayRemaining && acym_popupForm) { |
| 265 |
acym_popupForm.style.display = 'inline'; |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
window.addEventListener('scroll', displayAcymPopupForm); |
| 271 |
|
| 272 |
let delayInMs = delayDisplay * 1000; |
| 273 |
if (addedDelayForBackup && delayDisplay > 1000) { |
| 274 |
delayInMs -= 1000; |
| 275 |
} |
| 276 |
|
| 277 |
setTimeout(function () { |
| 278 |
if (acym_popupForm !== null) { |
| 279 |
delayRemaining = false; |
| 280 |
if (!scrollRemaining) { |
| 281 |
acym_popupForm.style.display = 'inline'; |
| 282 |
window.removeEventListener('scroll', displayAcymPopupForm); |
| 283 |
} |
| 284 |
} |
| 285 |
}, delayInMs); |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
</script> |
| 290 |
<?php |
| 291 |
include acym_getPartial('forms', 'cookie'); |
| 292 |
} |
| 293 |
?> |
| 294 |
|