publicFrontTasks = [ 'openStats', ]; } public function openStats(): void { $mailId = acym_getVar('int', 'id'); $userId = acym_getVar('int', 'userid'); if (!empty($mailId) && !empty($userId) && !acym_isRobot()) { $this->recordOpen($mailId, $userId); } acym_noCache(); if (ob_get_level() > 0) { ob_end_clean(); } $statsPicture = ACYM_MEDIA_RELATIVE.'images/editor/statpicture.png'; $statsPicture = ACYM_ROOT.ltrim(str_replace(['\\', '/'], DS, $statsPicture), DS); $handle = fopen($statsPicture, 'r'); if (!$handle) { exit; } acym_header('Content-type: image/png'); $contents = fread($handle, filesize($statsPicture)); fclose($handle); echo $contents; exit; } private function recordOpen(int $mailId, int $userId): void { $userStatClass = new UserStatClass(); $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId); if (empty($userStat)) { return; } $mailStatClass = new MailStatClass(); $mailStatClass->save( [ 'mail_id' => $mailId, 'open_unique' => $userStat->open > 0 ? 0 : 1, 'open_total' => 1, ] ); $userStatToInsert = [ 'user_id' => $userId, 'mail_id' => $mailId, 'open' => 1, 'open_date' => acym_date('now', 'Y-m-d H:i:s'), 'device' => '', 'opened_with' => '', ]; if (isset($_SERVER['HTTP_USER_AGENT'])) { $browserDetection = new BrowserDetection(); $openingInformation = $browserDetection->getAll($_SERVER['HTTP_USER_AGENT']); $userStatToInsert['device'] = $openingInformation['os_name'] === 'unknown' ? '' : $openingInformation['os_name']; $userStatToInsert['opened_with'] = $openingInformation['browser_name'] === 'unknown' ? '' : $openingInformation['browser_name']; } $userStatClass->save($userStatToInsert); $userClass = new UserClass(); $subscriber = $userClass->getOneById($userId); if (!empty($subscriber)) { $subscriber->last_open_date = acym_date('now', 'Y-m-d H:i:s'); $userClass->triggers = false; $userClass->sendConf = false; $userClass->save($subscriber); } } }