| @@ -20,11 +20,13 @@ | ||
| 20 | 20 | public static function call(string $path, string $method = 'GET', array $data = [], array $headers = [], array $options = []): array |
| 21 | 21 | { |
| 22 | 22 | $url = ACYM_UPDATEME_API_URL.$path; |
| 23 | 23 | |
| 24 | + // No array merge because we need to keep the keys | |
| 24 | 25 | $headers = $headers + self::getDefaultHeaders(); |
| 25 | 26 | |
| 26 | 27 | if (ACYM_CMS === 'joomla' && acym_getCMSConfig('proxy_enable', false)) { |
| 28 | + // https://github.com/WordPress/Requests/blob/stable/docs/proxy.md | |
| 27 | 29 | $options['proxy'] = ['host' => acym_getCMSConfig('proxy_host', '').':'.acym_getCMSConfig('proxy_port', '')]; |
| 28 | 30 | if (!empty(acym_getCMSConfig('proxy_user', '')) && !empty(acym_getCMSConfig('proxy_pass', ''))) { |
| 29 | 31 | $options['proxy']['auth'] = acym_getCMSConfig('proxy_user', '').':'.acym_getCMSConfig('proxy_pass', ''); |
| 30 | 32 | } |
| @@ -45,8 +47,11 @@ | ||
| 45 | 47 | $return['success'] = true; |
| 46 | 48 | |
| 47 | 49 | if ($request['status_code'] < 200 || $request['status_code'] > 299) { |
| 48 | 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 | + } | |
| 49 | 54 | $return['success'] = false; |
| 50 | 55 | } |
| 51 | 56 | |
| 52 | 57 | return $return; |
| @@ -51,15 +56,18 @@ | ||
| 51 | 56 | |
| 52 | 57 | return $return; |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | - public static function getLicenseInfo(bool $ajax): string | |
| 60 | + public static function getLicenseInfo(bool $ajax = false): void | |
| 56 | 61 | { |
| 62 | + // Get any error correctly | |
| 57 | 63 | ob_start(); |
| 58 | - $config = acym_config(); | |
| 64 | + $config = acym_config(true); | |
| 59 | 65 | $url = 'public/getLicenseInfo'; |
| 66 | + // Know which version to look at | |
| 60 | 67 | $url .= '?level='.urlencode(strtolower($config->get('level', 'starter'))); |
| 61 | - if (acym_level(ACYM_ESSENTIAL)) { | |
| 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 | |
| 62 | 70 | if ($config->get('different_admin_url_toggle', 0) === 1) { |
| 63 | 71 | $url .= '&domain='.$config->get('different_admin_url_value', 0); |
| 64 | 72 | } else { |
| 65 | 73 | $url .= '&domain='.urlencode(rtrim(ACYM_LIVE, '/')); |
| @@ -64,38 +72,44 @@ | ||
| 64 | 72 | } else { |
| 65 | 73 | $url .= '&domain='.urlencode(rtrim(ACYM_LIVE, '/')); |
| 66 | 74 | } |
| 67 | 75 | } |
| 76 | + // Tell the user if a newer version is available | |
| 68 | 77 | $url .= '&version=latest'; |
| 69 | 78 | $userInformation = self::call($url); |
| 70 | 79 | $warnings = ob_get_clean(); |
| 71 | 80 | $result = (!empty($warnings) && acym_isDebug()) ? $warnings : ''; |
| 72 | 81 | |
| 82 | + // Could not load the user information | |
| 73 | 83 | if (empty($userInformation)) { |
| 74 | - $config->save(['lastlicensecheck' => time()]); | |
| 84 | + $config->saveConfig(['lastlicensecheck' => time()]); | |
| 75 | 85 | if ($ajax) { |
| 76 | 86 | acym_sendAjaxResponse( |
| 77 | 87 | '', |
| 78 | 88 | [ |
| 79 | 89 | 'content' => '<br/><span style="color:#C10000;">'.acym_translation('ACYM_ERROR_LOAD_FROM_ACYBA').'</span><br/>'.$result, |
| 80 | - 'lastcheck' => acym_date(time(), 'Y/m/d H:i'), | |
| 90 | + 'lastcheck' => acym_date(time(), 'ACYM_DATE_FORMAT_LC2'), | |
| 81 | 91 | ], |
| 82 | 92 | false |
| 83 | 93 | ); |
| 84 | 94 | } else { |
| 85 | - return ''; | |
| 95 | + return; | |
| 86 | 96 | } |
| 87 | 97 | } |
| 88 | 98 | |
| 89 | - $newConfig = new \stdClass(); | |
| 99 | + $newConfig = [ | |
| 100 | + 'latestversion' => $userInformation['latestversion'], | |
| 101 | + 'expirationdate' => $userInformation['expiration'], | |
| 102 | + 'lastlicensecheck' => time(), | |
| 103 | + ]; | |
| 90 | 104 | |
| 91 | - $newConfig->latestversion = $userInformation['latestversion']; | |
| 92 | - $newConfig->expirationdate = $userInformation['expiration']; | |
| 93 | - $newConfig->lastlicensecheck = time(); | |
| 94 | - $newConfig->isTrial = empty($userInformation['isTrial']) ? 0 : 1; | |
| 95 | - $config->save($newConfig); | |
| 105 | + $licenseKey = $config->get('license_key'); | |
| 106 | + if (!empty($licenseKey)) { | |
| 107 | + $newConfig['isTrial'] = empty($userInformation['isTrial']) ? 0 : 1; | |
| 108 | + } | |
| 96 | 109 | |
| 110 | + $config->saveConfig($newConfig); | |
| 111 | + | |
| 112 | + //check for plugins | |
| 97 | 113 | acym_checkPluginsVersion(); |
| 98 | - | |
| 99 | - return $newConfig->lastlicensecheck; | |
| 100 | 114 | } |
| 101 | 115 | } |