| 1 |
<?php |
| 2 |
defined('ABSPATH') || die('Restricted Access'); |
| 3 |
|
| 4 |
function acym_getModuleFormName(): string |
| 5 |
{ |
| 6 |
static $i = 1; |
| 7 |
|
| 8 |
//The static sometimes does not work... but the rand should really do the job, REALLY! |
| 9 |
return 'formAcym'.acym_rand(1000, 9999).$i++; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* $params Is mainly an AcymParameter, but is of unknown type in the subscription module (mod_acym.php) |
| 14 |
*/ |
| 15 |
function acym_initModule(?object $params = null, array $options = []): void |
| 16 |
{ |
| 17 |
if (acym_isAjax()) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
if (!file_exists(ACYM_ROOT.'plugins'.DS.'system'.DS.'modulesanywhere')) { |
| 22 |
static $loaded = false; |
| 23 |
if ($loaded) { |
| 24 |
return; |
| 25 |
} |
| 26 |
$loaded = true; |
| 27 |
} |
| 28 |
|
| 29 |
if (!is_null($params) && method_exists($params, 'get')) { |
| 30 |
$nameCaption = $params->get('nametext'); |
| 31 |
$emailCaption = $params->get('emailtext'); |
| 32 |
$jsLoading = $params->get('includejs'); |
| 33 |
$options['loadJsInModule'] = $jsLoading === 'module'; |
| 34 |
$options['defer'] = in_array($jsLoading, ['all', 'defer']); |
| 35 |
$options['async'] = in_array($jsLoading, ['all', 'async']); |
| 36 |
} |
| 37 |
|
| 38 |
if (empty($nameCaption)) { |
| 39 |
$nameCaption = acym_translation('ACYM_NAME'); |
| 40 |
} |
| 41 |
if (empty($emailCaption)) { |
| 42 |
$emailCaption = acym_translation('ACYM_EMAIL'); |
| 43 |
} |
| 44 |
|
| 45 |
$js = 'if (typeof window.acymModule === "undefined") { |
| 46 |
window.acymModule = '.json_encode([ |
| 47 |
'NAMECAPTION' => $nameCaption, |
| 48 |
'NAME_MISSING' => acym_translation('ACYM_MISSING_NAME'), |
| 49 |
'EMAILCAPTION' => $emailCaption, |
| 50 |
'VALID_EMAIL' => acym_translation('ACYM_VALID_EMAIL'), |
| 51 |
'VALID_EMAIL_CONFIRMATION' => acym_translation('ACYM_VALID_EMAIL_CONFIRMATION'), |
| 52 |
'CAPTCHA_MISSING' => acym_translation('ACYM_WRONG_CAPTCHA'), |
| 53 |
'NO_LIST_SELECTED' => acym_translation('ACYM_SELECT_LIST'), |
| 54 |
'NO_LIST_SELECTED_UNSUB' => acym_translation('ACYM_SELECT_LIST_UNSUB'), |
| 55 |
'ACCEPT_TERMS' => acym_translation('ACYM_ACCEPT_TERMS'), |
| 56 |
]).'; |
| 57 |
window.acymModule.emailRegex = /^'.acym_getEmailRegex(true).'$/i; |
| 58 |
} |
| 59 |
'; |
| 60 |
|
| 61 |
$config = acym_config(); |
| 62 |
$version = str_replace('.', '', $config->get('version')); |
| 63 |
|
| 64 |
global $acymEmailMisspelledLoaded; |
| 65 |
$spellChecker = empty($acymEmailMisspelledLoaded) && !empty($config->get('email_spellcheck')); |
| 66 |
if ($spellChecker) $acymEmailMisspelledLoaded = true; |
| 67 |
|
| 68 |
if (!empty($options['loadJsInModule'])) { |
| 69 |
if ($spellChecker) { |
| 70 |
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript -- Option to include the JS inside the module. |
| 71 |
echo '<script type="text/javascript" src="'.esc_url(ACYM_JS.'libraries/email-misspelled.min.js?v='.$version).'"></script>'; |
| 72 |
} |
| 73 |
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript -- Option to include the JS inside the module. |
| 74 |
echo '<script type="text/javascript" src="'.esc_url(ACYM_JS.'module.min.js?v='.$version).'"></script>'; |
| 75 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped, generated above. |
| 76 |
echo '<script type="text/javascript">'.$js.'</script>'; |
| 77 |
} else { |
| 78 |
$scriptOptions = ['defer' => !empty($options['defer'])]; |
| 79 |
if (!empty($options['async'])) { |
| 80 |
$scriptOptions['async'] = true; |
| 81 |
} |
| 82 |
|
| 83 |
if ($spellChecker) { |
| 84 |
acym_addScript(false, ACYM_JS.'libraries/email-misspelled.min.js?v='.$version, $scriptOptions); |
| 85 |
} |
| 86 |
$scriptName = acym_addScript(false, ACYM_JS.'module.min.js?v='.$version, $scriptOptions); |
| 87 |
acym_addScript(true, $js, array_merge($scriptOptions, ['dependencies' => ['script_name' => $scriptName]])); |
| 88 |
} |
| 89 |
|
| 90 |
if ('wordpress' === ACYM_CMS && !in_array(acym_getVar('string', 'action'), ['elementor', 'elementor_ajax'])) { |
| 91 |
if ($spellChecker) { |
| 92 |
wp_enqueue_style( |
| 93 |
'style_email_spellchecker', |
| 94 |
ACYM_CSS.'libraries/email-misspelled.min.css?v='.$version, |
| 95 |
[], |
| 96 |
'11.0.1' |
| 97 |
); |
| 98 |
} |
| 99 |
wp_enqueue_style( |
| 100 |
'style_acymailing_module', |
| 101 |
ACYM_CSS.'module.min.css?v='.$version, |
| 102 |
[], |
| 103 |
'11.0.1' |
| 104 |
); |
| 105 |
} else { |
| 106 |
if ($spellChecker) acym_addStyle(false, ACYM_CSS.'libraries/email-misspelled.min.css?v='.$version); |
| 107 |
acym_addStyle(false, ACYM_CSS.'module.min.css?v='.$version); |
| 108 |
} |
| 109 |
} |
| 110 |
|