| @@ -1,128 +1,0 @@ | ||
| 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 | - // CTE isn't installed | |
| 93 | - if (!acym_isAcyCheckerInstalled()) return true; | |
| 94 | - | |
| 95 | - // The email verification is disabled in the configuration | |
| 96 | - if ($this->config->get('email_verification') == 0) return true; | |
| 97 | - | |
| 98 | - $this->loadAcychecker(); | |
| 99 | - | |
| 100 | - $cteConfig = ConfigurationClass::getConfiguration(); | |
| 101 | - $conditions = $cteConfig->get('registration_conditions'); | |
| 102 | - | |
| 103 | - // If no condition is selected, return | |
| 104 | - if (empty($conditions) || $conditions === 'domain_not_exists') return true; | |
| 105 | - | |
| 106 | - // Perform test using CTE code API | |
| 107 | - $apiService = new ApiService(); | |
| 108 | - | |
| 109 | - // Retro compatibility for AcyChecker 1.4 | |
| 110 | - if (method_exists($apiService, 'testUser')) { | |
| 111 | - $testUser = new stdClass(); | |
| 112 | - $testUser->email = $user->email; | |
| 113 | - $testUser->name = $user->name; | |
| 114 | - $emailOk = $apiService->testUser($testUser, $conditions); | |
| 115 | - } else { | |
| 116 | - $emailOk = $apiService->testEmail($user->email, $conditions); | |
| 117 | - } | |
| 118 | - | |
| 119 | - if ($emailOk !== true) { | |
| 120 | - $message = $emailOk === 'blacklisted_name' ? 'ACYM_INVALID_NAME' : 'ACYM_INVALID_EMAIL_ADDRESS'; | |
| 121 | - acym_setVar('acychecker_error', acym_translation($message)); | |
| 122 | - | |
| 123 | - return false; | |
| 124 | - } | |
| 125 | - | |
| 126 | - return true; | |
| 127 | - } | |
| 128 | -} | |