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 / Helpers / UpdatemeHelper.php

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

102 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $headers = $headers + self::getDefaultHeaders();
25
26 if (ACYM_CMS === 'joomla' && acym_getCMSConfig('proxy_enable', false)) {
27 $options['proxy'] = ['host' => acym_getCMSConfig('proxy_host', '').':'.acym_getCMSConfig('proxy_port', '')];
28 if (!empty(acym_getCMSConfig('proxy_user', '')) && !empty(acym_getCMSConfig('proxy_pass', ''))) {
29 $options['proxy']['auth'] = acym_getCMSConfig('proxy_user', '').':'.acym_getCMSConfig('proxy_pass', '');
30 }
31 }
32 $options['verifySsl'] = false;
33 $options['headers'] = $headers;
34 $options['method'] = $method;
35 $options['data'] = $data;
36 $request = acym_makeCurlCall($url, $options);
37
38 if (!empty($request['error'])) {
39 acym_logError('Error while calling our API on path '.$path.' with the message: '.$request['error'], 'updateme');
40
41 return [];
42 }
43
44 $return = $request;
45 $return['success'] = true;
46
47 if ($request['status_code'] < 200 || $request['status_code'] > 299) {
48 acym_logError('Error while calling updateme on path '.$path.' with the status code: '.$request['status_code']."\r\n and body".json_encode($request), 'updateme');
49 $return['success'] = false;
50 }
51
52 return $return;
53 }
54
55 public static function getLicenseInfo(bool $ajax): string
56 {
57 ob_start();
58 $config = acym_config();
59 $url = 'public/getLicenseInfo';
60 $url .= '?level='.urlencode(strtolower($config->get('level', 'starter')));
61 if (acym_level(ACYM_ESSENTIAL)) {
62 if ($config->get('different_admin_url_toggle', 0) === 1) {
63 $url .= '&domain='.$config->get('different_admin_url_value', 0);
64 } else {
65 $url .= '&domain='.urlencode(rtrim(ACYM_LIVE, '/'));
66 }
67 }
68 $url .= '&version=latest';
69 $userInformation = self::call($url);
70 $warnings = ob_get_clean();
71 $result = (!empty($warnings) && acym_isDebug()) ? $warnings : '';
72
73 if (empty($userInformation)) {
74 $config->save(['lastlicensecheck' => time()]);
75 if ($ajax) {
76 acym_sendAjaxResponse(
77 '',
78 [
79 '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'),
81 ],
82 false
83 );
84 } else {
85 return '';
86 }
87 }
88
89 $newConfig = new \stdClass();
90
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);
96
97 acym_checkPluginsVersion();
98
99 return $newConfig->lastlicensecheck;
100 }
101 }
102