PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
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.1.4, at back/Helpers/global/global.php

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