function sendUserMails($u) { $uid = $u['id']; if (empty($u['email'])) { return; } $sendType = User::canSendNotifications($uid); if ($sendType == false) { return; } $coreName = Config::get('core_name'); // $coreUrl = Config::get('core_url'); $languages = Config::get('languages'); $lang = $languages[$u['language_id'] - 1]; if (filter_var($u['email'], FILTER_VALIDATE_EMAIL)) { //group mails into digest and separate ones (where user is mentioned) $mails = array('digest' => array(), 'separate' => array()); foreach ($u['mails'] as $notificationId => $notification) { //[$core #$nodeId] $action_type $template_name: $object_title $templateId = Objects::getTemplateId($notification['object_id']); $templateName = Objects::getName($templateId); $subject = '[' . $coreName . ' #' . $notification['object_id'] . '] ' . Notifications::getActionDeclination($notification['action_type'], $lang) . ' ' . $templateName . ' "' . htmlspecialchars_decode($notification['data']['name']) . '"'; $sender = Notifications::getSender($notification['from_user_id']); //divide notification into separate number of actions it consist of $actions = getNotificationActions($notification); for ($i = 0; $i < sizeof($actions); $i++) { $a = $actions[$i]; $message = Notifications::getMailBodyForAction($a, $u); $isMentioned = !empty($a['data']['mentioned']) && in_array($uid, $a['data']['mentioned']); $mails[$isMentioned ? 'separate' : 'digest'][] = array('subject' => $subject, 'body' => $message, 'sender' => $sender, 'nId' => $notificationId); } } //merge digest emails group into one email and put it into separate group if (sizeof($mails['digest']) == 1) { $mails['separate'][] = $mails['digest'][0]; } elseif (!empty($mails['digest'])) { $mail = array(); $ids = array(); $sender = ''; foreach ($mails['digest'] as $m) { $mail[] = $m['body']; $sender = $m['sender']; $ids[] = $m['nId']; } $mails['separate'][] = array('subject' => '[' . $coreName . '] Notifications digest', 'body' => implode('<hr />', $mail), 'sender' => $sender, 'nId' => $ids); } foreach ($mails['separate'] as $mail) { echo $u['email'] . ': ' . $mail['subject'] . "\n"; if (!mail($u['email'], $mail['subject'], $mail['body'], "Content-type: text/html; charset=utf-8\r\nFrom: " . $mail['sender'] . "\r\n")) { System::notifyAdmin('CaseBox cron notification: Cant send notification (' . $mail['nId'] . ') mail to "' . $u['email'] . '"', $mail['body']); } else { DM\Notifications::markAsSeen($mail['nId'], $uid); } } if (!empty($mails['digest'])) { User::setUserConfigParam('lastNotifyTime', Util\dateISOToMysql('now'), $uid); } } }
public function create($p) { $rez = array('succes' => false, 'data' => array()); if (empty($p['node_id']) || empty($p['data'])) { return $rez; } $data = array('name' => Purify::filename($p['data']['name']), 'path' => $p['data']['path'], 'pathText' => empty($p['data']['pathText']) ? '' : $p['data']['pathText']); if (is_numeric($p['node_id'])) { $data['template_id'] = Objects::getTemplateId($p['node_id']); $data['iconCls'] = Browser::getIcon($data); } elseif (!empty($p['data']['iconCls'])) { $data['iconCls'] = $p['data']['iconCls']; } $d = array('user_id' => User::getId(), 'node_id' => $p['node_id'], 'data' => Util\jsonEncode($data)); $id = DM\Favorites::create($d); $rez = array('success' => true, 'data' => array('id' => $id, 'node_id' => $d['node_id'], 'data' => $data)); return $rez; }
/** * process a message: * - replace urls with links * - replace object references with links * @param varchar $message */ public static function processAndFormatMessage($message, $replacements = 'user,object,url') { if (empty($message)) { return $message; } $replacements = Util\toTrimmedArray($replacements); // replace urls with links if (in_array('url', $replacements)) { $message = \Kwi\UrlLinker::getInstance()->linkUrlsAndEscapeHtml($message); } //replace object references with links if (in_array('object', $replacements) && preg_match_all('/(.?)#(\\d+)(.?)/', $message, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { // check if not a html code if ($match[1] == '&' && $match[3] == ';') { continue; } $templateId = Objects::getTemplateId($match[2]); $name = Objects::getName($match[2]); $name = strlen($name) > 30 ? mb_substr($name, 0, 30) . '…' : $name; $message = str_replace($match[0], $match[1] . '<a class="click obj-ref" itemid="' . $match[2] . '" templateid= "' . $templateId . '" title="' . $name . '"' . '>#' . $match[2] . '</a>' . $match[3], $message); } } //replace users with their names if (in_array('user', $replacements) && preg_match_all('/@([\\w\\.\\-]+[\\w])/', $message, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $userId = DM\User::getIdByName($match[1]); if (is_numeric($userId)) { $userName = $match[1]; $message = str_replace($match[0], '<span class="cDB user-ref" title="' . User::getDisplayName($userId) . '">@' . $userName . '</span>', $message); } } } return $message; }
$uid = $r['to_user_id']; if (!isset($users[$uid])) { $users[$uid] = User::getPreferences($uid); } $users[$uid]['mails'][$r['id']] = $r; } //iterate mails for each user and send them foreach ($users as $u) { if (empty($u['email'])) { continue; } $lang = $languages[$u['language_id'] - 1]; if (filter_var($u['email'], FILTER_VALIDATE_EMAIL)) { foreach ($u['mails'] as $notificationId => $action) { //[$core #$nodeId] $action_type $template_name: $object_title $templateId = Objects::getTemplateId($action['object_id']); $templateName = Objects::getName($templateId); $subject = '[' . $coreName . ' #' . $action['object_id'] . '] ' . Notifications::getActionDeclination($action['action_type'], $lang) . ' ' . $templateName . ' "' . htmlspecialchars_decode($action['data']['name']) . '"'; //skip sending notifications from devel server to other emails than Admin if (!$sendNotificationMails && $u['email'] !== $adminEmail) { echo 'Devel skip: ' . $u['email'] . ': ' . $subject . "\n"; } else { echo $u['email'] . ': ' . $subject . "\n"; $message = Notifications::getMailBodyForAction($action, $u); $sender = Notifications::getSender($action['from_user_id']); // file_put_contents(TEMP_DIR . $action['id'].'.html', "$sender<br />\n<h1>$subject<h1>" . $message); // COMMENTED FOR TEST if (!mail($u['email'], $subject, $message, "Content-type: text/html; charset=utf-8\r\nFrom: " . $sender . "\r\n")) { $markNotificationAsSent = false; System::notifyAdmin('CaseBox cron notification: Cant send notification (' . $notificationId . ') mail to "' . $u['email'] . '"', $message); } else {