PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
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
acymailing / back / dynamics / acychecker / plugin.php

plugin.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/dynamics/acychecker/plugin.php

124 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Core\AcymPlugin;
4 use AcyChecker\Classes\ConfigurationClass;
5 use AcyChecker\Services\ApiService;
6
7 class plgAcymAcychecker extends AcymPlugin
8 {
9 private function loadAcychecker()
10 {
11 if (ACYM_CMS === 'joomla') {
12 $cteFolder = rtrim(JPATH_ADMINISTRATOR, DS).DS.'components'.DS.'com_acychecker'.DS;
13 } else {
14 $cteFolder = WP_PLUGIN_DIR.DS.'acychecker'.DS;
15 }
16 include_once $cteFolder.'vendor'.DS.'autoload.php';
17 include_once $cteFolder.'defines.php';
18 }
19
20 public function onBeforeSaveConfigFields(&$formData)
21 {
22 if (!isset($formData['email_verification'])) return;
23 if (!acym_isAcyCheckerInstalled()) return;
24 $this->loadAcychecker();
25
26 $cteConfig = new ConfigurationClass();
27 $registrationIntegrations = explode(',', $cteConfig->get('registration_integrations'));
28 if (empty($formData['email_verification'])) {
29 if (in_array('acymailing', $registrationIntegrations)) {
30 unset($registrationIntegrations[array_search('acymailing', $registrationIntegrations)]);
31
32 $cteConfig->save(
33 [
34 'registration_integrations' => implode(',', $registrationIntegrations),
35 ]
36 );
37 }
38 } else {
39 if (!in_array('acymailing', $registrationIntegrations)) {
40 $registrationIntegrations[] = 'acymailing';
41 }
42
43 $verificationOptions = [
44 'email_verification_non_existing' => 'invalid_smtp',
45 'email_verification_disposable' => 'disposable',
46 'email_verification_free' => 'free_domain',
47 'email_verification_role' => 'role_based',
48 'email_verification_acceptall' => 'accept_all',
49 'email_checkdomain' => 'domain_not_exists',
50 ];
51 $registrationConditions = [];
52 $newConfig = [];
53 $acy5installed = false;
54 if (ACYM_CMS === 'joomla') {
55 if (acym_isExtensionActive('com_acymailing')) {
56 include_once rtrim(JPATH_ADMINISTRATOR, DS).DS.'components'.DS.'com_acymailing'.DS.'helpers'.DS.'helper.php';
57 $acy5installed = true;
58 }
59 } else {
60 if (acym_isExtensionActive('acymailing5/index.php')) {
61 include_once WP_PLUGIN_DIR.DS.'acymailing5'.DS.'back'.DS.'helpers'.DS.'helper.php';
62 $acy5installed = true;
63 }
64 }
65 if ($acy5installed) {
66 $acym5Config = acymailing_config();
67 }
68
69 foreach ($verificationOptions as $acymOption => $acycOption) {
70 if (!empty($formData[$acymOption])) {
71 $registrationConditions[] = $acycOption;
72 $newConfig[$acymOption] = 1;
73 } else {
74 $newConfig[$acymOption] = 0;
75 }
76 }
77 if ($acy5installed) {
78 $acym5Config->save($newConfig);
79 }
80
81 $cteConfig->save(
82 [
83 'registration_integrations' => trim(implode(',', $registrationIntegrations), ','),
84 'registration_conditions' => trim(implode(',', $registrationConditions), ','),
85 ]
86 );
87 }
88 }
89
90 public function onAcymBeforeUserCreate(&$user)
91 {
92 if (!acym_isAcyCheckerInstalled()) return true;
93
94 if ($this->config->get('email_verification') == 0) return true;
95
96 $this->loadAcychecker();
97
98 $cteConfig = new ConfigurationClass();
99 $conditions = $cteConfig->get('registration_conditions');
100
101 if (empty($conditions) || $conditions === 'domain_not_exists') return true;
102
103 $apiService = new ApiService();
104
105 if (method_exists($apiService, 'testUser')) {
106 $testUser = new stdClass();
107 $testUser->email = $user->email;
108 $testUser->name = $user->name;
109 $emailOk = $apiService->testUser($testUser, $conditions);
110 } else {
111 $emailOk = $apiService->testEmail($user->email, $conditions);
112 }
113
114 if ($emailOk !== true) {
115 $message = $emailOk === 'blacklisted_name' ? 'ACYM_INVALID_NAME' : 'ACYM_INVALID_EMAIL_ADDRESS';
116 acym_setVar('acychecker_error', acym_translation($message));
117
118 return false;
119 }
120
121 return true;
122 }
123 }
124