PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.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 / global / global.php

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

226 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Classes\ConfigurationClass;
4
5 function acydump($arg, bool $ajax = false, array $options = []): void
6 {
7 $indent = $options['indent'] ?? true;
8 $htmlentities = $options['htmlentities'] ?? true;
9
10 ob_start();
11 if (is_object($arg) && isset($arg->config)) {
12 $safeArg = clone $arg;
13 unset($safeArg->config);
14 var_dump($safeArg);
15 } else {
16 var_dump($arg);
17 }
18 $result = ob_get_clean();
19
20 if ($ajax) {
21 $logsPath = ACYM_ROOT.ACYM_LOGS_FOLDER.'debug.log';
22 acym_createDir(dirname($logsPath), true, true);
23
24 if (($options['clear_file'] ?? false) === true) {
25 file_put_contents($logsPath, '');
26 }
27
28 file_put_contents($logsPath, $result, FILE_APPEND);
29 } else {
30 $style = $indent ? 'margin-left: 220px;' : '';
31 echo '<pre style="'.$style.'">';
32 echo $htmlentities ? htmlentities($result) : $result;
33 echo '</pre>';
34 }
35 }
36
37 function acym_debug(bool $file = false, bool $indent = true)
38 {
39 $debug = debug_backtrace();
40 $takenPath = [];
41 foreach ($debug as $step) {
42 if (empty($step['file']) || empty($step['line'])) continue;
43 $takenPath[] = $step['file'].' => '.$step['line'];
44 }
45 acydump(implode("\n", $takenPath), $file, ['indent' => $indent]);
46 }
47
48 function acym_config(bool $reload = false): ConfigurationClass
49 {
50 static $configClass = null;
51 if ($configClass === null || $reload) {
52 $configClass = new ConfigurationClass();
53 $configClass->load();
54 }
55
56 return $configClass;
57 }
58
59 function acym_display($messages, string $type = 'success', bool $close = true): void
60 {
61 if (empty($messages)) return;
62 if (!is_array($messages)) $messages = [$messages];
63 $config = acym_config();
64 $remindme = json_decode($config->get('remindme', '[]'), true);
65 foreach ($messages as $id => $message) {
66 if (strpos($message, 'acym__do__not__remindme') !== false) {
67 preg_match('/title="(.*)"/Ui', $message, $matches);
68 if (in_array($matches[1], $remindme)) continue;
69 }
70
71 echo '<div class="acym__message grid-x acym__message__'.$type.'">';
72
73 if (is_array($message)) $message = implode('</div><div>', $message);
74
75 echo '<div class="cell auto"><div>'.$message.'</div></div>';
76
77 if ($close && strpos($message, 'acym__do__not__remindme') === false) {
78 echo '<i data-id="'.acym_escape($id).'" class="cell shrink acym__message__close acymicon-close"></i>';
79 }
80 echo '</div>';
81 }
82 }
83
84 function acym_increasePerf(): int
85 {
86 @ini_set('pcre.backtrack_limit', 1000000);
87
88 $maxExecutionTime = (int)ini_get('max_execution_time');
89
90 if (empty($maxExecutionTime) || $maxExecutionTime < 600) {
91 return set_time_limit(600) ? 600 : $maxExecutionTime;
92 }
93
94 return $maxExecutionTime;
95 }
96
97 function acym_session(): void
98 {
99 if (empty(session_id()) || session_status() !== PHP_SESSION_ACTIVE) {
100 @session_start();
101 }
102 }
103
104 function acym_getCID(string $field = ''): int
105 {
106 $oneResult = acym_getVar('array', 'cid', [], '');
107 $oneResult = intval(reset($oneResult));
108 if (!empty($oneResult) || empty($field)) {
109 return $oneResult;
110 }
111
112 $oneResult = acym_getVar('int', $field, 0, '');
113
114 return intval($oneResult);
115 }
116
117 function acym_header(string $header, bool $replace = true): void
118 {
119 if (headers_sent()) {
120 return;
121 }
122
123 header($header, $replace);
124 }
125
126 function acym_getSocialMedias(): array
127 {
128 return json_decode(ACYM_SOCIAL_MEDIA, true);
129 }
130
131 function acym_isAcyCheckerInstalled(): bool
132 {
133 $installed = ACYM_CMS === 'joomla' && acym_isExtensionActive('com_acychecker');
134
135 return $installed || (ACYM_CMS === 'wordpress' && acym_isExtensionActive('acychecker/acychecker.php'));
136 }
137
138 function acym_getErrorLogFilename(string $prefix = ''): string
139 {
140 if (!empty($prefix)) {
141 $prefix .= '_';
142 }
143
144 return $prefix.'errors.log';
145 }
146
147 function acym_logError(string $message, string $prefix = '', int $maxLines = 0)
148 {
149 $reportPath = acym_getLogPath(acym_getErrorLogFilename($prefix), true);
150
151 if ($maxLines > 0 && file_exists($reportPath)) {
152 $lines = file($reportPath);
153 if (!empty($lines)) {
154 $lines = array_slice($lines, -$maxLines);
155 file_put_contents($reportPath, implode("\n", $lines));
156 }
157 }
158
159 $lr = "\r\n";
160 file_put_contents(
161 $reportPath,
162 $lr.acym_getDate(time()).': '.$message,
163 FILE_APPEND
164 );
165 }
166
167 function acym_isLogFileErrorExist(string $prefix = ''): bool
168 {
169 $reportPath = acym_getLogPath(acym_getErrorLogFilename($prefix));
170
171 return file_exists($reportPath);
172 }
173
174 function acym_getJsonData(): array
175 {
176 $rawData = file_get_contents('php://input');
177 $decodedData = @json_decode($rawData, true);
178
179 return empty($decodedData) ? [] : $decodedData;
180 }
181
182 function displayFreeTrialMessage(): void
183 {
184 if (!acym_isAdmin()) {
185 return;
186 }
187
188 $config = acym_config();
189
190 if ($config->get('isTrial', 0) != 1) {
191 return;
192 }
193
194 $expirationDate = $config->get('expirationdate', 0);
195 $href = ACYM_ACYMAILING_WEBSITE.'account/license';
196 if ($config->get('expirationdate', 0) > time()) {
197 $days = ceil(($expirationDate - time()) / 86400);
198 $buttonFullAccess = '<a target="_blank" class="button button-secondary margin-left-1 shrink margin-bottom-0" href="'.$href.'">'.acym_translation(
199 'ACYM_GET_FULL_ACCESS'
200 ).'</a>';
201 $message = '<span class="shrink">'.acym_translationSprintf('ACYM_FREE_TRIAL_EXPIRATION_X_DAYS', $days).'</span>';
202 $type = 'warning';
203 } else {
204 $buttonFullAccess = '<a target="_blank" class="button acym__button__upgrade margin-left-1 shrink margin-bottom-0" href="'.$href.'">'.acym_translation(
205 'ACYM_GET_FULL_ACCESS'
206 ).'</a>';
207 $message = '<span class="shrink">'.acym_translation('ACYM_FREE_TRIAL_ENDED').'</span>';
208 $type = 'error';
209 }
210 acym_enqueueMessage('<div class="cell grid-x acym_vcenter">'.$message.$buttonFullAccess.'</div>', $type, false);
211 }
212
213 function acym_removeDashboardNotification(string $name): void
214 {
215 $config = acym_config();
216 $existingNotifications = json_decode($config->get('dashboard_notif', '[]'), true) ?? [];
217
218 foreach ($existingNotifications as $key => $existingNotification) {
219 if (is_array($existingNotification) && $existingNotification['name'] === $name) {
220 unset($existingNotifications[$key]);
221 }
222 }
223
224 $config->saveConfig(['dashboard_notif' => json_encode($existingNotifications)], false);
225 }
226