| @@ -1,13 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +defined('ABSPATH') || die('Restricted Access'); | |
| 2 | 3 | |
| 3 | 4 | function acym_getModuleFormName(): string |
| 4 | 5 | { |
| 5 | 6 | static $i = 1; |
| 6 | 7 | |
| 7 | - return 'formAcym'.rand(1000, 9999).$i++; | |
| 8 | + //The static sometimes does not work... but the rand should really do the job, REALLY! | |
| 9 | + return 'formAcym'.acym_rand(1000, 9999).$i++; | |
| 8 | 10 | } |
| 9 | 11 | |
| 12 | +/** | |
| 13 | + * $params Is mainly an AcymParameter, but is of unknown type in the subscription module (mod_acym.php) | |
| 14 | + */ | |
| 10 | 15 | function acym_initModule(?object $params = null, array $options = []): void |
| 11 | 16 | { |
| 12 | 17 | if (acym_isAjax()) { |
| 13 | 18 | return; |
| @@ -36,23 +41,23 @@ | ||
| 36 | 41 | if (empty($emailCaption)) { |
| 37 | 42 | $emailCaption = acym_translation('ACYM_EMAIL'); |
| 38 | 43 | } |
| 39 | 44 | |
| 40 | - $js = " | |
| 41 | - if(typeof acymModule === 'undefined'){ | |
| 42 | - var acymModule = []; | |
| 43 | - acymModule['emailRegex'] = /^".acym_getEmailRegex(true)."$/i; | |
| 44 | - acymModule['NAMECAPTION'] = '".str_replace("'", "\'", $nameCaption)."'; | |
| 45 | - acymModule['NAME_MISSING'] = '".str_replace("'", "\'", acym_translation('ACYM_MISSING_NAME'))."'; | |
| 46 | - acymModule['EMAILCAPTION'] = '".str_replace("'", "\'", $emailCaption)."'; | |
| 47 | - acymModule['VALID_EMAIL'] = '".str_replace("'", "\'", acym_translation('ACYM_VALID_EMAIL'))."'; | |
| 48 | - acymModule['VALID_EMAIL_CONFIRMATION'] = '".str_replace("'", "\'", acym_translation('ACYM_VALID_EMAIL_CONFIRMATION'))."'; | |
| 49 | - acymModule['CAPTCHA_MISSING'] = '".str_replace("'", "\'", acym_translation('ACYM_WRONG_CAPTCHA'))."'; | |
| 50 | - acymModule['NO_LIST_SELECTED'] = '".str_replace("'", "\'", acym_translation('ACYM_SELECT_LIST'))."'; | |
| 51 | - acymModule['NO_LIST_SELECTED_UNSUB'] = '".str_replace("'", "\'", acym_translation('ACYM_SELECT_LIST_UNSUB'))."'; | |
| 52 | - acymModule['ACCEPT_TERMS'] = '".str_replace("'", "\'", acym_translation('ACYM_ACCEPT_TERMS'))."'; | |
| 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; | |
| 53 | 58 | } |
| 54 | - "; | |
| 59 | + '; | |
| 55 | 60 | |
| 56 | 61 | $config = acym_config(); |
| 57 | 62 | $version = str_replace('.', '', $config->get('version')); |
| 58 | 63 | |
| @@ -60,10 +65,15 @@ | ||
| 60 | 65 | $spellChecker = empty($acymEmailMisspelledLoaded) && !empty($config->get('email_spellcheck')); |
| 61 | 66 | if ($spellChecker) $acymEmailMisspelledLoaded = true; |
| 62 | 67 | |
| 63 | 68 | if (!empty($options['loadJsInModule'])) { |
| 64 | - if ($spellChecker) echo '<script type="text/javascript" src="'.ACYM_JS.'libraries/email-misspelled.min.js?v='.$version.'"></script>'; | |
| 65 | - echo '<script type="text/javascript" src="'.ACYM_JS.'module.min.js?v='.$version.'"></script>'; | |
| 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. | |
| 66 | 76 | echo '<script type="text/javascript">'.$js.'</script>'; |
| 67 | 77 | } else { |
| 68 | 78 | $scriptOptions = ['defer' => !empty($options['defer'])]; |
| 69 | 79 | if (!empty($options['async'])) { |
| @@ -77,10 +87,22 @@ | ||
| 77 | 87 | acym_addScript(true, $js, array_merge($scriptOptions, ['dependencies' => ['script_name' => $scriptName]])); |
| 78 | 88 | } |
| 79 | 89 | |
| 80 | 90 | if ('wordpress' === ACYM_CMS && !in_array(acym_getVar('string', 'action'), ['elementor', 'elementor_ajax'])) { |
| 81 | - if ($spellChecker) wp_enqueue_style('style_email_spellchecker', ACYM_CSS.'libraries/email-misspelled.min.css?v='.$version); | |
| 82 | - wp_enqueue_style('style_acymailing_module', ACYM_CSS.'module.min.css?v='.$version); | |
| 91 | + if ($spellChecker) { | |
| 92 | + wp_enqueue_style( | |
| 93 | + 'style_email_spellchecker', | |
| 94 | + ACYM_CSS.'libraries/email-misspelled.min.css?v='.$version, | |
| 95 | + [], | |
| 96 | + '11.1.0' | |
| 97 | + ); | |
| 98 | + } | |
| 99 | + wp_enqueue_style( | |
| 100 | + 'style_acymailing_module', | |
| 101 | + ACYM_CSS.'module.min.css?v='.$version, | |
| 102 | + [], | |
| 103 | + '11.1.0' | |
| 104 | + ); | |
| 83 | 105 | } else { |
| 84 | 106 | if ($spellChecker) acym_addStyle(false, ACYM_CSS.'libraries/email-misspelled.min.css?v='.$version); |
| 85 | 107 | acym_addStyle(false, ACYM_CSS.'module.min.css?v='.$version); |
| 86 | 108 | } |