break; } } $_SESSION['Base_Notify']['notified_cache'][$module][$id] = 1; if ($group_similar && count($new_messages) > 1) { continue; } $title = EPESI . ' ' . Base_NotifyCommon::strip_html($message['title']); $body = Base_NotifyCommon::strip_html($message['body']); $icon = Base_NotifyCommon::get_icon($module, $message); $ret[] = array('title' => $title, 'opts' => array('body' => $body, 'icon' => $icon), 'timeout' => $timeout); } if ($notify_count > Base_NotifyCommon::message_refresh_limit) { break; } if (!$group_similar || $msg_count <= 1) { continue; } $notify_count++; $title = EPESI . ' ' . Base_NotifyCommon::get_module_caption($module); $body = __('%d new notifications', array($msg_count)); $icon = Base_NotifyCommon::get_icon($module); $ret[] = array('title' => $title, 'opts' => array('body' => $body, 'icon' => $icon), 'timeout' => $timeout); } if (!isset($title) || !isset($icon)) { exit; } if (isset($ret)) { echo json_encode($ret); } exit;
$timeout = Base_NotifyCommon::get_module_setting($module); if ($group_similar && count($module_new_notifications) > 1) { $message_count++; if ($message_count > Base_NotifyCommon::message_refresh_limit) { break; } $notified_cache[$module] = array_keys($module_new_notifications); $title = EPESI . ' ' . Base_NotifyCommon::get_module_caption($module); $body = __('%d new notifications', array(count($module_new_notifications))); $icon = Base_NotifyCommon::get_icon($module); $ret[] = array('title' => $title, 'opts' => array('body' => $body, 'icon' => $icon), 'timeout' => $timeout); } else { foreach ($module_new_notifications as $id => $message) { $message_count++; if ($message_count > Base_NotifyCommon::message_refresh_limit) { break 2; } $notified_cache[$module][] = $id; $title = EPESI . ' ' . Base_NotifyCommon::strip_html($message['title']); $body = Base_NotifyCommon::strip_html($message['body']); $icon = Base_NotifyCommon::get_icon($module, $message); $ret[] = array('title' => $title, 'opts' => array('body' => $body, 'icon' => $icon, 'tag' => $id), 'timeout' => $timeout); } } $all_notified &= count($module_new_notifications) == count($notified_cache[$module]); } Base_NotifyCommon::set_notified_cache($notified_cache, $token, $all_notified ? $refresh_time : Base_NotifyCommon::get_last_refresh($token)); if (count($ret)) { echo json_encode(array('messages' => $ret)); } exit;
/** * * @author Pawel Bukowski <*****@*****.**> * @copyright Copyright © 2015, Telaxus LLC * @license MIT * @version 2.0 * @package epesi-notify * */ define('CID', false); define('READ_ONLY_SESSION', true); require_once '../../../include.php'; ModuleManager::load_modules(); if (!Acl::is_user()) { exit; } $token = Base_NotifyCommon::get_session_token(true); if (!$token) { exit; } DB::Execute('UPDATE base_notify SET telegram=1 WHERE token=%s', array($token)); $domain_name = Base_UserCommon::get_my_user_login(); if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) { $domain_name .= '-' . $_SERVER['HTTP_HOST']; } else { if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']) { $domain_name .= '-' . $_SERVER['SERVER_NAME']; } } $domain_name = preg_replace('/[^a-z0-9\\-\\_]/i', '-', $domain_name); header('Location: https://telegram.me/EpesiBot?' . http_build_query(array('start' => md5(Base_AclCommon::get_user() . '#' . Base_UserCommon::get_my_user_login() . '#' . $token) . '-' . substr($domain_name, 0, 31))));
public static function telegram() { $tokens = DB::GetAssoc('SELECT token,single_cache_uid FROM base_notify WHERE telegram=1 AND single_cache_uid is not null'); if (!$tokens) { return; } $ret = array(); $map = array(); $refresh_time = time(); $notified_cache = array(); foreach ($tokens as $token => $uid) { $msgs = array(); if (Base_NotifyCommon::is_refresh_due_telegram($token)) { Base_AclCommon::set_user($uid); $notified_cache[$token] = array(); $notifications = Base_NotifyCommon::get_notifications($token); foreach ($notifications as $module => $module_new_notifications) { foreach ($module_new_notifications as $id => $message) { $notified_cache[$token][$module][] = $id; $title = EPESI . ' ' . Base_NotifyCommon::strip_html($message['title']); $body = Base_NotifyCommon::strip_html($message['body']); //$icon = Base_NotifyCommon::get_icon($module, $message); $msgs[] = array('title' => $title, 'body' => $body); } } } $remote_token = md5($uid . '#' . Base_UserCommon::get_user_login($uid) . '#' . $token); $ret[$remote_token] = $msgs ? $msgs : '0'; $map[$remote_token] = $token; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://telegram.epesicrm.com/"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($ret)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $status = curl_exec($ch); curl_close($ch); $status = @json_decode($status); if (is_array($status)) { foreach ($status as $remove) { if (isset($map[$remove])) { DB::Execute('UPDATE base_notify SET telegram=0 WHERE token=%s', array($map[$remove])); unset($notified_cache[$map[$remove]]); } } foreach ($notified_cache as $token => $nc) { Base_NotifyCommon::set_notified_cache($nc, $token, $refresh_time); } } }