| @@ -1,115 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Helpers; | |
| 4 | - | |
| 5 | -use AcyMailing\Core\AcymObject; | |
| 6 | - | |
| 7 | -class UpdatemeHelper extends AcymObject | |
| 8 | -{ | |
| 9 | - public static function getDefaultHeaders(): array | |
| 10 | - { | |
| 11 | - $config = acym_config(); | |
| 12 | - $apiKey = $config->get('license_key', ''); | |
| 13 | - | |
| 14 | - return [ | |
| 15 | - 'Content-Type' => 'application/json', | |
| 16 | - 'API-KEY' => $apiKey, | |
| 17 | - ]; | |
| 18 | - } | |
| 19 | - | |
| 20 | - public static function call(string $path, string $method = 'GET', array $data = [], array $headers = [], array $options = []): array | |
| 21 | - { | |
| 22 | - $url = ACYM_UPDATEME_API_URL.$path; | |
| 23 | - | |
| 24 | - // No array merge because we need to keep the keys | |
| 25 | - $headers = $headers + self::getDefaultHeaders(); | |
| 26 | - | |
| 27 | - if (ACYM_CMS === 'joomla' && acym_getCMSConfig('proxy_enable', false)) { | |
| 28 | - // https://github.com/WordPress/Requests/blob/stable/docs/proxy.md | |
| 29 | - $options['proxy'] = ['host' => acym_getCMSConfig('proxy_host', '').':'.acym_getCMSConfig('proxy_port', '')]; | |
| 30 | - if (!empty(acym_getCMSConfig('proxy_user', '')) && !empty(acym_getCMSConfig('proxy_pass', ''))) { | |
| 31 | - $options['proxy']['auth'] = acym_getCMSConfig('proxy_user', '').':'.acym_getCMSConfig('proxy_pass', ''); | |
| 32 | - } | |
| 33 | - } | |
| 34 | - $options['verifySsl'] = false; | |
| 35 | - $options['headers'] = $headers; | |
| 36 | - $options['method'] = $method; | |
| 37 | - $options['data'] = $data; | |
| 38 | - $request = acym_makeCurlCall($url, $options); | |
| 39 | - | |
| 40 | - if (!empty($request['error'])) { | |
| 41 | - acym_logError('Error while calling our API on path '.$path.' with the message: '.$request['error'], 'updateme'); | |
| 42 | - | |
| 43 | - return []; | |
| 44 | - } | |
| 45 | - | |
| 46 | - $return = $request; | |
| 47 | - $return['success'] = true; | |
| 48 | - | |
| 49 | - if ($request['status_code'] < 200 || $request['status_code'] > 299) { | |
| 50 | - acym_logError('Error while calling updateme on path '.$path.' with the status code: '.$request['status_code']."\r\n and body".json_encode($request), 'updateme'); | |
| 51 | - if (!empty($request['message']) && $request['message'] === 'MAX_SITES_ATTACH') { | |
| 52 | - acym_enqueueMessage(acym_translation('ACYM_REACHED_MAX_SITES_ATTACHED'), 'error'); | |
| 53 | - } | |
| 54 | - $return['success'] = false; | |
| 55 | - } | |
| 56 | - | |
| 57 | - return $return; | |
| 58 | - } | |
| 59 | - | |
| 60 | - public static function getLicenseInfo(bool $ajax = false): void | |
| 61 | - { | |
| 62 | - // Get any error correctly | |
| 63 | - ob_start(); | |
| 64 | - $config = acym_config(true); | |
| 65 | - $url = 'public/getLicenseInfo'; | |
| 66 | - // Know which version to look at | |
| 67 | - $url .= '?level='.urlencode(strtolower($config->get('level', 'starter'))); | |
| 68 | - if (acym_level(ACYM_ESSENTIAL) || $config->get('isTrial', 0) == 1) { | |
| 69 | - // Tell the user if the automatic features are available for the current installation | |
| 70 | - if ($config->get('different_admin_url_toggle', 0) === 1) { | |
| 71 | - $url .= '&domain='.$config->get('different_admin_url_value', 0); | |
| 72 | - } else { | |
| 73 | - $url .= '&domain='.urlencode(rtrim(ACYM_LIVE, '/')); | |
| 74 | - } | |
| 75 | - } | |
| 76 | - // Tell the user if a newer version is available | |
| 77 | - $url .= '&version=latest'; | |
| 78 | - $userInformation = self::call($url); | |
| 79 | - $warnings = ob_get_clean(); | |
| 80 | - $result = (!empty($warnings) && acym_isDebug()) ? $warnings : ''; | |
| 81 | - | |
| 82 | - // Could not load the user information | |
| 83 | - if (empty($userInformation)) { | |
| 84 | - $config->saveConfig(['lastlicensecheck' => time()]); | |
| 85 | - if ($ajax) { | |
| 86 | - acym_sendAjaxResponse( | |
| 87 | - '', | |
| 88 | - [ | |
| 89 | - 'content' => '<br/><span style="color:#C10000;">'.acym_translation('ACYM_ERROR_LOAD_FROM_ACYBA').'</span><br/>'.$result, | |
| 90 | - 'lastcheck' => acym_date(time(), 'ACYM_DATE_FORMAT_LC2'), | |
| 91 | - ], | |
| 92 | - false | |
| 93 | - ); | |
| 94 | - } else { | |
| 95 | - return; | |
| 96 | - } | |
| 97 | - } | |
| 98 | - | |
| 99 | - $newConfig = [ | |
| 100 | - 'latestversion' => $userInformation['latestversion'], | |
| 101 | - 'expirationdate' => $userInformation['expiration'], | |
| 102 | - 'lastlicensecheck' => time(), | |
| 103 | - ]; | |
| 104 | - | |
| 105 | - $licenseKey = $config->get('license_key'); | |
| 106 | - if (!empty($licenseKey)) { | |
| 107 | - $newConfig['isTrial'] = empty($userInformation['isTrial']) ? 0 : 1; | |
| 108 | - } | |
| 109 | - | |
| 110 | - $config->saveConfig($newConfig); | |
| 111 | - | |
| 112 | - //check for plugins | |
| 113 | - acym_checkPluginsVersion(); | |
| 114 | - } | |
| 115 | -} | |