config)) { $safeArg = clone $arg; unset($safeArg->config); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_dump -- For debug during support only. var_dump($safeArg); } else { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_dump -- For debug during support only. var_dump($arg); } $result = ob_get_clean(); if ($ajax) { $logsPath = ACYM_ROOT.ACYM_LOGS_FOLDER.'debug.log'; acym_createDir(dirname($logsPath), true, true); if (($options['clear_file'] ?? false) === true) { file_put_contents($logsPath, ''); } file_put_contents($logsPath, $result, FILE_APPEND); } else { $style = $indent ? 'margin-left: 220px;' : ''; echo '
';
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- For debug during support only.
        echo $htmlentities ? htmlentities($result) : $result;
        echo '
'; } } function acym_debug(bool $file = false, bool $indent = true) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- Debug for support tickets. $debug = debug_backtrace(); $takenPath = []; foreach ($debug as $step) { if (empty($step['file']) || empty($step['line'])) continue; $takenPath[] = $step['file'].' => '.$step['line']; } acym_dump(implode("\n", $takenPath), $file, ['indent' => $indent]); } function acym_config(bool $reload = false): ConfigurationClass { static $configClass = null; if ($configClass === null || $reload) { $configClass = new ConfigurationClass(); $configClass->load(); } return $configClass; } /** * @param mixed $messages The messages displayed, either a string or an array or strings * @param string $type Type of the message: success, error, warning, info * @param bool $close Allow or not to close the message zone */ function acym_display($messages, string $type = 'success', bool $close = true): void { if (empty($messages)) return; if (!is_array($messages)) $messages = [$messages]; $config = acym_config(); $remindme = json_decode($config->get('remindme', '[]'), true); foreach ($messages as $id => $message) { if (strpos($message, 'acym__do__not__remindme') !== false) { if (preg_match('/title="(.*)"/Ui', $message, $matches) && in_array($matches[1], $remindme)) { continue; } } echo '
'; if (is_array($message)) $message = implode('
', $message); echo '
'.wp_kses($message, SecurityHelper::ALLOWED_HTML_MESSAGE).'
'; if ($close && strpos($message, 'acym__do__not__remindme') === false) { echo ''; } echo '
'; } } function acym_increasePerf(): int { // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- This is for big regex, the default value is 100 000. @ini_set('pcre.backtrack_limit', 1000000); // Increase the max exec time to be able to handle long processes such as the send process $maxExecutionTime = (int)ini_get('max_execution_time'); if (empty($maxExecutionTime) || $maxExecutionTime < 600) { // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- Needed for long processes like email sending. return set_time_limit(600) ? 600 : $maxExecutionTime; } return $maxExecutionTime; } function acym_session(): void { if (empty(session_id()) || session_status() !== PHP_SESSION_ACTIVE) { @session_start(); } } function acym_getCID(string $field = ''): int { $oneResult = acym_getVar('array', 'cid', [], ''); $oneResult = intval(reset($oneResult)); if (!empty($oneResult) || empty($field)) { return $oneResult; } $oneResult = acym_getVar('int', $field, 0, ''); return intval($oneResult); } function acym_header(string $header, bool $replace = true): void { if (headers_sent()) { return; } header($header, $replace); } function acym_getSocialMedias(): array { return json_decode(ACYM_SOCIAL_MEDIA, true); } function acym_isAcyCheckerInstalled(): bool { $installed = ACYM_CMS === 'joomla' && acym_isExtensionActive('com_acychecker'); return $installed || (ACYM_CMS === 'wordpress' && acym_isExtensionActive('acychecker/acychecker.php')); } function acym_getErrorLogFilename(string $prefix = ''): string { if (!empty($prefix)) { $prefix .= '_'; } return $prefix.'errors.log'; } function acym_logError(string $message, string $prefix = '', int $maxLines = 0) { $reportPath = acym_getLogPath(acym_getErrorLogFilename($prefix), true); if ($maxLines > 0 && file_exists($reportPath)) { $lines = file($reportPath); if (!empty($lines)) { $lines = array_slice($lines, -$maxLines); file_put_contents($reportPath, implode("\n", $lines)); } } $lr = "\r\n"; file_put_contents( $reportPath, $lr.acym_getDate(time()).': '.$message, FILE_APPEND ); } function acym_isLogFileErrorExist(string $prefix = ''): bool { $reportPath = acym_getLogPath(acym_getErrorLogFilename($prefix)); return file_exists($reportPath); } function acym_getJsonData(): array { $rawData = file_get_contents('php://input'); $decodedData = @json_decode($rawData, true); return empty($decodedData) ? [] : $decodedData; } function acym_displayFreeTrialMessage(): void { if (!acym_isAdmin()) { return; } $config = acym_config(); if ($config->get('isTrial', 0) != 1) { return; } $expirationDate = $config->get('expirationdate', 0); $href = ACYM_ACYMAILING_WEBSITE.'account/license'; if ($config->get('expirationdate', 0) > time()) { $days = ceil(($expirationDate - time()) / 86400); $buttonFullAccess = ''.acym_translation( 'ACYM_GET_FULL_ACCESS' ).''; $message = ''.acym_translationSprintf('ACYM_FREE_TRIAL_EXPIRATION_X_DAYS', $days).''; $type = 'warning'; } else { $buttonFullAccess = ''.acym_translation( 'ACYM_GET_FULL_ACCESS' ).''; $message = ''.acym_translation('ACYM_FREE_TRIAL_ENDED').''; $type = 'error'; } acym_enqueueMessage('
'.$message.$buttonFullAccess.'
', $type, false); } function acym_removeDashboardNotification(string $name): void { $config = acym_config(); $existingNotifications = json_decode($config->get('dashboard_notif', '[]'), true) ?? []; foreach ($existingNotifications as $key => $existingNotification) { if (is_array($existingNotification) && $existingNotification['name'] === $name) { unset($existingNotifications[$key]); } } $config->saveConfig(['dashboard_notif' => json_encode($existingNotifications)], false); }