Ejemplo n.º 1
0
	public static function GetMobileTemplateJS($arParams, $arTemplate)
	{
		global $USER;

		$ppStatus = 'false';
		$ppServerStatus = 'false';
		$updateStateInterval = 'auto';
		if (CModule::IncludeModule("pull"))
		{
			$ppStatus = CPullOptions::ModuleEnable()? 'true': 'false';
			$ppServerStatus = CPullOptions::GetNginxStatus()? 'true': 'false';
			$updateStateInterval = CPullOptions::GetNginxStatus()? self::GetSessionLifeTime(): 80;
			if ($updateStateInterval > 100)
			{
				if ($updateStateInterval > 3600)
					$updateStateInterval = 3600;

				$updateStateInterval = $updateStateInterval-60;
			}
		}

		$diskStatus = CIMDisk::Enabled();

		$phoneSipAvailable = 0;
		$phoneEnabled = false;

		$mobileAction = isset($arTemplate["ACTION"])? $arTemplate["ACTION"]: 'none';

		$sJS = "
			BX.ready(function() {
				BXIM = new BX.ImMobile({
					'mobileAction': '".$mobileAction."',

					'mailCount': ".intval($arTemplate["MAIL_COUNTER"]).",
					'notifyCount': ".intval($arTemplate["NOTIFY_COUNTER"]).",
					'messageCount': ".intval($arTemplate["MESSAGE_COUNTER"]).",
					'counters': ".(empty($arTemplate['COUNTERS'])? '{}': CUtil::PhpToJSObject($arTemplate['COUNTERS'])).",
					'ppStatus': ".$ppStatus.",
					'ppServerStatus': ".$ppServerStatus.",
					'updateStateInterval': '".$updateStateInterval."',
					'xmppStatus': ".(CIMMessenger::CheckXmppStatusOnline()? 'true': 'false').",
					'bitrixNetworkStatus': ".(CIMMessenger::CheckNetworkStatus()? 'true': 'false').",
					'bitrix24Status': ".(IsModuleInstalled('bitrix24')? 'true': 'false').",
					'bitrix24Admin': ".(CModule::IncludeModule('bitrix24') && CBitrix24::IsPortalAdmin($USER->GetId())? 'true': 'false').",
					'bitrix24net': ".(IsModuleInstalled('b24network')? 'true': 'false').",
					'bitrixIntranet': ".(IsModuleInstalled('intranet')? 'true': 'false').",
					'bitrixXmpp': ".(IsModuleInstalled('xmpp')? 'true': 'false').",
					'desktopStatus': ".(CIMMessenger::CheckDesktopStatusOnline()? 'true': 'false').",
					'desktopVersion': ".CIMMessenger::GetDesktopVersion().",
					'language': '".LANGUAGE_ID."',

					'smile': ".(empty($arTemplate['SMILE'])? '{}': CUtil::PhpToJSObject($arTemplate["SMILE"])).",
					'smileSet': ".(empty($arTemplate['SMILE_SET'])? '{}': CUtil::PhpToJSObject($arTemplate["SMILE_SET"])).",
					'settings': ".(empty($arTemplate['SETTINGS'])? '{}': CUtil::PhpToJSObject($arTemplate['SETTINGS'])).",
					'settingsNotifyBlocked': ".(empty($arTemplate['SETTINGS_NOTIFY_BLOCKED'])? '{}': CUtil::PhpToJSObject($arTemplate['SETTINGS_NOTIFY_BLOCKED'])).",

					'notify': ".(empty($arTemplate['NOTIFY']['notify'])? '{}': CUtil::PhpToJSObject($arTemplate['NOTIFY']['notify'])).",
					'unreadNotify' : ".(empty($arTemplate['NOTIFY']['unreadNotify'])? '{}': CUtil::PhpToJSObject($arTemplate['NOTIFY']['unreadNotify'])).",
					'flashNotify' : ".(empty($arTemplate['NOTIFY']['flashNotify'])? '{}': CUtil::PhpToJSObject($arTemplate['NOTIFY']['flashNotify'])).",
					'countNotify' : ".intval($arTemplate['NOTIFY']['countNotify']).",
					'loadNotify' : ".($arTemplate['NOTIFY']['loadNotify']? 'true': 'false').",

					'recent': ".(empty($arTemplate['RECENT'])? '{}': CUtil::PhpToJSObject($arTemplate['RECENT'])).",
					'users': ".(empty($arTemplate['CONTACT_LIST']['users'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['users'])).",
					'groups': ".(empty($arTemplate['CONTACT_LIST']['groups'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['groups'])).",
					'userInGroup': ".(empty($arTemplate['CONTACT_LIST']['userInGroup'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['userInGroup'])).",
					'woGroups': ".(empty($arTemplate['CONTACT_LIST']['woGroups'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woGroups'])).",
					'woUserInGroup': ".(empty($arTemplate['CONTACT_LIST']['woUserInGroup'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woUserInGroup'])).",
					'chat': ".(empty($arTemplate['CHAT']['chat'])? '{}': CUtil::PhpToJSObject($arTemplate['CHAT']['chat'])).",
					'userInChat': ".(empty($arTemplate['CHAT']['userInChat'])? '{}': CUtil::PhpToJSObject($arTemplate['CHAT']['userInChat'])).",
					'userChatBlockStatus': ".(empty($arTemplate['CHAT']['userChatBlockStatus'])? '{}': CUtil::PhpToJSObject($arTemplate['CHAT']['userChatBlockStatus'])).",
					'message' : ".(empty($arTemplate['MESSAGE']['message'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['message'])).",
					'files' : ".(empty($arTemplate['MESSAGE']['files'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['files'])).",
					'showMessage' : ".(empty($arTemplate['MESSAGE']['usersMessage'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['usersMessage'])).",
					'unreadMessage' : ".(empty($arTemplate['MESSAGE']['unreadMessage'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['unreadMessage'])).",
					'flashMessage' : ".(empty($arTemplate['MESSAGE']['flashMessage'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['flashMessage'])).",
					'history' : {},
					'openMessenger' : ".(isset($_GET['IM_DIALOG'])? "'".CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_DIALOG']))."'": 'false').",
					'openHistory' : ".(isset($_GET['IM_HISTORY'])? "'".CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_HISTORY']))."'": 'false').",
					'openNotify' : ".(isset($_GET['IM_NOTIFY']) && $_GET['IM_NOTIFY'] == 'Y'? 'true': 'false').",
					'openSettings' : ".(isset($_GET['IM_SETTINGS'])? $_GET['IM_SETTINGS'] == 'Y'? "'true'": "'".CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_SETTINGS']))."'": 'false').",

					'currentTab' : '".($arTemplate['CURRENT_TAB']? CUtil::JSEscape($arTemplate['CURRENT_TAB']): 0)."',
					'userId': ".$USER->GetID().",
					'userEmail': '".CUtil::JSEscape($USER->GetEmail())."',
					'webrtc': {'turnServer' : '".(empty($arTemplate['TURN_SERVER'])? '': CUtil::JSEscape($arTemplate['TURN_SERVER']))."', 'turnServerLogin' : '".(empty($arTemplate['TURN_SERVER_LOGIN'])? '': CUtil::JSEscape($arTemplate['TURN_SERVER_LOGIN']))."', 'turnServerPassword' : '".(empty($arTemplate['TURN_SERVER_PASSWORD'])? '': CUtil::JSEscape($arTemplate['TURN_SERVER_PASSWORD']))."', 'mobileSupport': ".($arTemplate['WEBRTC_MOBILE_SUPPORT']? 'true': 'false').", 'phoneEnabled': ".($phoneEnabled? 'true': 'false').", 'phoneSipAvailable': ".($phoneSipAvailable? 'true': 'false')."},
					'disk': {'enable' : ".($diskStatus? 'true': 'false')."},
					'path' : {'profile' : '".(empty($arTemplate['PATH_TO_USER_PROFILE'])? '': CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE']))."', 'profileTemplate' : '".(empty($arTemplate['PATH_TO_USER_PROFILE_TEMPLATE'])? '': CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE_TEMPLATE']))."', 'mail' : '".(empty($arTemplate['PATH_TO_USER_MAIL'])? '': CUtil::JSEscape($arTemplate['PATH_TO_USER_MAIL']))."'}
				});
			});
		";

		return $sJS;
	}
Ejemplo n.º 2
0
 public function GetUnreadMessage($arParams = array())
 {
     global $DB;
     $bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N' ? false : true;
     $lastId = !isset($arParams['LAST_ID']) || $arParams['LAST_ID'] == null ? null : IntVal($arParams['LAST_ID']);
     $order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC' ? 'ASC' : 'DESC';
     $loadDepartment = isset($arParams['LOAD_DEPARTMENT']) && $arParams['LOAD_DEPARTMENT'] == 'N' ? false : true;
     $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N' ? false : true;
     $bGroupByChat = isset($arParams['GROUP_BY_CHAT']) && $arParams['GROUP_BY_CHAT'] == 'Y' ? true : false;
     $bUserLoad = isset($arParams['USER_LOAD']) && $arParams['USER_LOAD'] == 'N' ? false : true;
     $bFileLoad = isset($arParams['FILE_LOAD']) && $arParams['FILE_LOAD'] == 'N' ? false : true;
     $arExistUserData = isset($arParams['EXIST_USER_DATA']) && is_array($arParams['EXIST_USER_DATA']) ? $arParams['EXIST_USER_DATA'] : array();
     $messageType = isset($arParams['MESSAGE_TYPE']) && in_array($arParams['MESSAGE_TYPE'], array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT)) ? $arParams['MESSAGE_TYPE'] : 'ALL';
     $arMessages = array();
     $arUnreadMessage = array();
     $arUsersMessage = array();
     $arResult = array('message' => array(), 'unreadMessage' => array(), 'usersMessage' => array(), 'users' => array(), 'userInGroup' => array(), 'woUserInGroup' => array(), 'files' => array(), 'countMessage' => 0, 'chat' => array(), 'userChatBlockStatus' => array(), 'userInChat' => array(), 'result' => false);
     $bLoadMessage = $bSpeedCheck ? CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_GROUP) : false;
     $count = CIMMessenger::SpeedFileGet($this->user_id, IM_SPEED_GROUP);
     if (!$bLoadMessage || $bLoadMessage && intval($count) > 0) {
         $ssqlLastId = "R1.LAST_ID";
         $ssqlStatus = " AND R1.STATUS < " . IM_STATUS_READ;
         if (!is_null($lastId) && intval($lastId) > 0 && !CIMMessenger::CheckXmppStatusOnline()) {
             $ssqlLastId = intval($lastId);
             $ssqlStatus = "";
         }
         $arRelations = array();
         if (strlen($ssqlStatus) > 0) {
             $strSql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tR1.USER_ID,\n\t\t\t\t\t\tR1.CHAT_ID,\n\t\t\t\t\t\tR1.LAST_ID\n\t\t\t\t\tFROM\n\t\t\t\t\t\tb_im_relation R1\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tR1.USER_ID = " . $this->user_id . "\n\t\t\t\t\t\t" . ($messageType == 'ALL' ? "AND R1.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "')" : "AND R1.MESSAGE_TYPE = '" . $messageType . "'") . "\n\t\t\t\t\t\t" . $ssqlStatus . "\n\t\t\t\t";
             $dbSubRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             while ($arRes = $dbSubRes->Fetch()) {
                 $arRelations[] = $arRes;
             }
         }
         $arMessageId = array();
         $arMessageChatId = array();
         $arLastMessage = array();
         $arMark = array();
         $arChat = array();
         $arPrepareResult = array();
         $arFilteredResult = array();
         if (!empty($arRelations)) {
             if (!$bTimeZone) {
                 CTimeZone::Disable();
             }
             $strSql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tM.ID,\n\t\t\t\t\t\tM.CHAT_ID,\n\t\t\t\t\t\tM.MESSAGE,\n\t\t\t\t\t\t" . $DB->DatetimeToTimestampFunction('M.DATE_CREATE') . " DATE_CREATE,\n\t\t\t\t\t\tM.AUTHOR_ID,\n\t\t\t\t\t\tR1.STATUS R1_STATUS,\n\t\t\t\t\t\tR1.MESSAGE_TYPE MESSAGE_TYPE\n\t\t\t\t\tFROM b_im_message M\n\t\t\t\t\tINNER JOIN b_im_relation R1 ON M.ID > " . $ssqlLastId . " AND M.CHAT_ID = R1.CHAT_ID AND R1.USER_ID != M.AUTHOR_ID\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tR1.USER_ID = " . $this->user_id . "\n\t\t\t\t\t\t" . ($messageType == 'ALL' ? "AND R1.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "')" : "AND R1.MESSAGE_TYPE = '" . $messageType . "'") . "\n\t\t\t\t\t\t" . $ssqlStatus . "\n\t\t\t\t";
             if (!$bTimeZone) {
                 CTimeZone::Enable();
             }
             $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             $CCTP = new CTextParser();
             $CCTP->MaxStringLen = 200;
             $CCTP->allow = array("HTML" => "N", "ANCHOR" => $this->bHideLink ? "N" : "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => $this->bHideLink ? "N" : "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
             while ($arRes = $dbRes->Fetch()) {
                 $arPrepareResult[$arRes['CHAT_ID']][$arRes['ID']] = $arRes;
             }
             foreach ($arPrepareResult as $chatId => $arRes) {
                 if (count($arPrepareResult[$chatId]) > 100) {
                     $arPrepareResult[$chatId] = array_slice($arRes, -100, 100);
                 }
                 $arFilteredResult = array_merge($arFilteredResult, $arPrepareResult[$chatId]);
             }
             unset($arPrepareResult);
         }
         foreach ($arFilteredResult as $arRes) {
             $arUsers[] = $arRes['AUTHOR_ID'];
             $arMessages[$arRes['ID']] = array('id' => $arRes['ID'], 'chatId' => $arRes['CHAT_ID'], 'senderId' => $arRes['AUTHOR_ID'], 'recipientId' => $arRes['CHAT_ID'], 'date' => $arRes['DATE_CREATE'], 'text' => $arRes['MESSAGE'], 'messageType' => $arRes['MESSAGE_TYPE']);
             if ($bGroupByChat) {
                 $arMessages[$arRes['ID']]['conversation'] = $arRes['CHAT_ID'];
                 $arMessages[$arRes['ID']]['unread'] = $this->user_id != $arRes['AUTHOR_ID'] ? 'Y' : 'N';
             } else {
                 $arUsersMessage[$arRes['CHAT_ID']][] = $arRes['ID'];
                 if ($this->user_id != $arRes['AUTHOR_ID']) {
                     $arUnreadMessage[$arRes['CHAT_ID']][] = $arRes['ID'];
                 }
             }
             if ($arRes['R1_STATUS'] == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"])) {
                 $arMark[$arRes["CHAT_ID"]] = $arRes["ID"];
             }
             if (!isset($arLastMessage[$arRes["CHAT_ID"]]) || $arLastMessage[$arRes["CHAT_ID"]] < $arRes["ID"]) {
                 $arLastMessage[$arRes["CHAT_ID"]] = $arRes["ID"];
             }
             $arChat[$arRes["CHAT_ID"]] = $arRes["CHAT_ID"];
             $arMessageId[] = $arRes['ID'];
             $arMessageChatId[$arRes['CHAT_ID']][$arRes["ID"]] = $arRes["ID"];
         }
         $params = CIMMessageParam::Get($arMessageId);
         if ($bFileLoad) {
             foreach ($arMessageChatId as $chatId => $messages) {
                 $files = array();
                 foreach ($messages as $messageId) {
                     $arMessages[$messageId]['params'] = $params[$messageId];
                     if (isset($params[$messageId]['FILE_ID'])) {
                         foreach ($params[$messageId]['FILE_ID'] as $fileId) {
                             $files[$fileId] = $fileId;
                         }
                     }
                 }
                 $arMessageFiles = CIMDisk::GetFiles($chatId, $files);
                 foreach ($arMessageFiles as $key => $value) {
                     $arResult['files'][$chatId][$key] = $value;
                 }
             }
         } else {
             foreach ($params as $messageId => $param) {
                 $arMessages[$messageId]['params'] = $param;
             }
         }
         if (!empty($arMessages)) {
             foreach ($arMark as $chatId => $lastSendId) {
                 CIMMessage::SetLastSendId($chatId, $this->user_id, $lastSendId);
             }
         } else {
             foreach ($arRelations as $relation) {
                 CIMMessage::SetLastId($relation['CHAT_ID'], $relation['USER_ID']);
             }
         }
         if ($bGroupByChat) {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$arLastMessage[$value['conversation']]]['counter']++;
                 if ($arLastMessage[$value['conversation']] != $value['id']) {
                     unset($arMessages[$key]);
                 } else {
                     $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                     $arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "\$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $value['text'])))), '<br>');
                     $arUsersMessage[$value['conversation']][] = $value['id'];
                     if ($value['unread'] == 'Y') {
                         $arUnreadMessage[$value['conversation']][] = $value['id'];
                     }
                     unset($arMessages[$key]['conversation']);
                     unset($arMessages[$key]['unread']);
                 }
             }
         } else {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                 $arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "\$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $value['text'])))), '<br>');
             }
         }
         $arResult['message'] = $arMessages;
         $arResult['unreadMessage'] = $arUnreadMessage;
         $arResult['usersMessage'] = $arUsersMessage;
         $arChat = self::GetChatData(array('ID' => $arChat, 'USE_CACHE' => 'N'));
         if (!empty($arChat)) {
             $arResult['chat'] = $arChat['chat'];
             $arResult['userChatBlockStatus'] = $arChat['userChatBlockStatus'];
             $arResult['userInChat'] = $arChat['userInChat'];
             foreach ($arChat['userInChat'] as $value) {
                 $arUsers[] = $value;
             }
         }
         if ($bUserLoad && !empty($arUsers)) {
             $arUserData = CIMContactList::GetUserData(array('ID' => array_diff(array_unique($arUsers), $arExistUserData), 'DEPARTMENT' => $loadDepartment ? 'Y' : 'N'));
             $arResult['users'] = $arUserData['users'];
             $arResult['userInGroup'] = $arUserData['userInGroup'];
             $arResult['woUserInGroup'] = $arUserData['woUserInGroup'];
         } else {
             $arResult['users'] = array();
             $arResult['userInGroup'] = array();
             $arResult['userInGroup'] = array();
         }
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
         if (!$bGroupByChat) {
             CIMMessenger::SpeedFileCreate($this->user_id, $arResult['countMessage'], IM_SPEED_GROUP);
         }
         $arResult['result'] = true;
     } else {
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
     }
     return $arResult;
 }
Ejemplo n.º 3
0
             $arSend['WO_USER_IN_GROUP'][$key] = $value;
         }
         $arSend['CHAT'] = $arMessage['chat'];
         $arSend['USER_IN_CHAT'] = $arMessage['userInChat'];
         $arSend['ERROR'] = '';
     }
     // Notify
     $CIMNotify = new CIMNotify();
     $arNotify = $CIMNotify->GetUnreadNotify(array('USE_TIME_ZONE' => 'N'));
     if ($arNotify['result']) {
         $arSend['NOTIFY'] = $arNotify['notify'];
         $arSend['UNREAD_NOTIFY'] = $arNotify['unreadNotify'];
         $arSend['FLASH_NOTIFY'] = CIMNotify::GetFlashNotify($arNotify['unreadNotify']);
         $arSend['ERROR'] = '';
     }
     $arSend['XMPP_STATUS'] = CIMMessenger::CheckXmppStatusOnline() ? 'Y' : 'N';
     $arSend['DESKTOP_STATUS'] = CIMMessenger::CheckDesktopStatusOnline() ? 'Y' : 'N';
     echo CUtil::PhpToJsObject($arSend);
 } else {
     if ($_POST['IM_UPDATE_STATE_LIGHT'] == 'Y') {
         $errorMessage = "";
         CIMContactList::SetOnline();
         $arResult["REVISION"] = IM_REVISION;
         $arResult['SERVER_TIME'] = time();
         if (isset($_POST['NOTIFY'])) {
             $CIMNotify = new CIMNotify();
             $arNotify = $CIMNotify->GetUnreadNotify(array('SPEED_CHECK' => 'N', 'USE_TIME_ZONE' => 'N'));
             $arResult['COUNTER_NOTIFICATIONS'] = count($arNotify['notify']);
             $arResult['NOTIFY_LAST_ID'] = $arNotify['maxNotify'];
         }
         if (isset($_POST['MESSAGE'])) {
Ejemplo n.º 4
0
	public function GetUnreadMessage($arParams = Array())
	{
		global $DB;

		$bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N'? false: true;
		$lastId = !isset($arParams['LAST_ID']) || $arParams['LAST_ID'] == null? null: IntVal($arParams['LAST_ID']);
		$order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC'? 'ASC': 'DESC';
		$loadDepartment = isset($arParams['LOAD_DEPARTMENT']) && $arParams['LOAD_DEPARTMENT'] == 'N'? false: true;
		$bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N'? false: true;
		$bGroupByChat = isset($arParams['GROUP_BY_CHAT']) && $arParams['GROUP_BY_CHAT'] == 'Y'? true: false;
		$bUserLoad = isset($arParams['USER_LOAD']) && $arParams['USER_LOAD'] == 'N'? false: true;
		$bFileLoad = isset($arParams['FILE_LOAD']) && $arParams['FILE_LOAD'] == 'N'? false: true;
		$arExistUserData = isset($arParams['EXIST_USER_DATA']) && is_array($arParams['EXIST_USER_DATA'])? $arParams['EXIST_USER_DATA']: Array();
		$bSmiles = isset($arParams['USE_SMILES']) && $arParams['USE_SMILES'] == 'N'? false: true;

		$arMessages = Array();
		$arUnreadMessage = Array();
		$arUsersMessage = Array();

		$arResult = Array(
			'message' => Array(),
			'unreadMessage' => Array(),
			'usersMessage' => Array(),
			'users' => Array(),
			'files' => Array(),
			'userInGroup' => Array(),
			'woUserInGroup' => Array(),
			'countMessage' => 0,
			'result' => false
		);
		$bLoadMessage = $bSpeedCheck? CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_MESSAGE): false;
		$count = CIMMessenger::SpeedFileGet($this->user_id, IM_SPEED_MESSAGE);
		if (!$bLoadMessage || ($bLoadMessage && intval($count) > 0))
		{
			$ssqlLastId = "R1.LAST_ID";
			$ssqlStatus = " AND R1.STATUS < ".IM_STATUS_READ;
			if (!is_null($lastId) && intval($lastId) > 0 && !CIMMessenger::CheckXmppStatusOnline())
			{
				$ssqlLastId = intval($lastId);
				$ssqlStatus = "";
			}

			if (!$bTimeZone)
				CTimeZone::Disable();
			$strSql ="
				SELECT
					M.ID,
					M.CHAT_ID,
					M.MESSAGE,
					".$DB->DatetimeToTimestampFunction('M.DATE_CREATE')." DATE_CREATE,
					M.AUTHOR_ID,
					M.NOTIFY_EVENT,
					R1.USER_ID R1_USER_ID,
					R1.STATUS R1_STATUS,
					M.AUTHOR_ID R2_USER_ID
				FROM b_im_message M
				INNER JOIN b_im_relation R1 ON M.ID > ".$ssqlLastId." AND M.CHAT_ID = R1.CHAT_ID AND R1.USER_ID != M.AUTHOR_ID
				WHERE R1.USER_ID = ".$this->user_id." AND R1.MESSAGE_TYPE = '".IM_MESSAGE_PRIVATE."' ".$ssqlStatus."
			";
			if (!$bTimeZone)
				CTimeZone::Enable();
			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

			$arLastMessage = Array();
			$arMark = Array();
			$arMessageId = Array();
			$arMessageChatId = Array();

			while ($arRes = $dbRes->Fetch())
			{
				$arUsers[] = $arRes['R1_USER_ID'];
				$arUsers[] = $arRes['R2_USER_ID'];
				if ($this->user_id == $arRes['AUTHOR_ID'])
				{
					$arRes['TO_USER_ID'] = $arRes['R2_USER_ID'];
					$arRes['FROM_USER_ID'] = $arRes['R1_USER_ID'];
					$convId = $arRes['TO_USER_ID'];
				}
				else
				{
					$arRes['TO_USER_ID'] = $arRes['R1_USER_ID'];
					$arRes['FROM_USER_ID'] = $arRes['R2_USER_ID'];
					$convId = $arRes['FROM_USER_ID'];
				}

				$arMessages[$arRes['ID']] = Array(
					'id' => $arRes['ID'],
					'chatId' => $arRes['CHAT_ID'],
					'senderId' => $arRes['FROM_USER_ID'],
					'recipientId' => $arRes['TO_USER_ID'],
					'date' => $arRes['DATE_CREATE'],
					'system' => $arRes['NOTIFY_EVENT'] == 'private'? 'N': 'Y',
					'text' => $arRes['MESSAGE'],
				);
				if ($bGroupByChat)
				{
					$arMessages[$arRes['ID']]['conversation'] = $convId;
					$arMessages[$arRes['ID']]['unread'] = $this->user_id != $arRes['AUTHOR_ID']? 'Y': 'N';
				}
				else
				{
					$arUsersMessage[$convId][] = $arRes['ID'];
					if ($this->user_id != $arRes['AUTHOR_ID'])
						$arUnreadMessage[$convId][] = $arRes['ID'];
				}

				if ($arRes['R1_STATUS'] == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"]))
					$arMark[$arRes["CHAT_ID"]] = $arRes["ID"];

				if (!isset($arLastMessage[$convId]) || $arLastMessage[$convId] < $arRes["ID"])
					$arLastMessage[$convId] = $arRes["ID"];

				$arMessageId[] = $arRes['ID'];
				$arMessageChatId[$arRes['CHAT_ID']][$arRes["ID"]] = $arRes["ID"];
			}
			$params = CIMMessageParam::Get($arMessageId);
			if ($bFileLoad)
			{
				foreach ($arMessageChatId as $chatId => $messages)
				{
					$files = Array();
					foreach ($messages as $messageId)
					{
						$arMessages[$messageId]['params'] = $params[$messageId];

						if (isset($params[$messageId]['FILE_ID']))
						{
							foreach ($params[$messageId]['FILE_ID'] as $fileId)
							{
								$files[$fileId] = $fileId;
							}
						}
					}

					$arMessageFiles = CIMDisk::GetFiles($chatId, $files);
					foreach ($arMessageFiles as $key => $value)
					{
						$arResult['files'][$chatId][$key] = $value;
					}
				}
			}
			else
			{
				foreach ($params as $messageId => $param)
				{
					$arMessages[$messageId]['params'] = $param;
				}
			}

			if (!empty($arMessages))
			{
				$CCTP = new CTextParser();
				$CCTP->MaxStringLen = 200;
				$CCTP->allow = array("HTML" => "N", "ANCHOR" => $this->bHideLink? "N": "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => ($bSmiles? "Y": "N"), "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
			}

			foreach ($arMark as $chatId => $lastSendId)
				self::SetLastSendId($chatId, $this->user_id, $lastSendId);

			if ($bGroupByChat)
			{
				foreach ($arMessages as $key => $value)
				{
					$arMessages[$arLastMessage[$value['conversation']]]['counter']++;
					if ($arLastMessage[$value['conversation']] != $value['id'])
					{
						unset($arMessages[$key]);
					}
					else
					{
						$arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
						$arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\[s\].*?\[\/s\]/i", "", $value['text'])))) , '<br>');

						$arUsersMessage[$value['conversation']][] = $value['id'];

						if ($value['unread'] == 'Y')
							$arUnreadMessage[$value['conversation']][] = $value['id'];

						unset($arMessages[$key]['conversation']);
						unset($arMessages[$key]['unread']);
					}
				}
			}
			else
			{
				foreach ($arMessages as $key => $value)
				{
					$arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
					$arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\[s\].*?\[\/s\]/i", "", $value['text'])))) , '<br>');
				}
			}

			$arResult['message'] = $arMessages;
			$arResult['unreadMessage'] = $arUnreadMessage;
			$arResult['usersMessage'] = $arUsersMessage;

			if ($bUserLoad && !empty($arUsers))
			{
				$arUserData = CIMContactList::GetUserData(Array('ID' => array_diff(array_unique($arUsers), $arExistUserData), 'DEPARTMENT' => ($loadDepartment? 'Y': 'N')));
				$arResult['users'] = $arUserData['users'];
				$arResult['userInGroup'] = $arUserData['userInGroup'];
				$arResult['woUserInGroup'] = $arUserData['woUserInGroup'];
			}
			else
			{
				$arResult['users'] = Array();
				$arResult['userInGroup'] = Array();
				$arResult['userInGroup'] = Array();
			}

			$arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
			if (!$bGroupByChat)
				CIMMessenger::SpeedFileCreate($this->user_id, $arResult['countMessage'], IM_SPEED_MESSAGE);
			$arResult['result'] = true;
		}
		else
		{
			$arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
		}

		return $arResult;
	}
Ejemplo n.º 5
0
 public function GetUnreadMessage($arParams = array())
 {
     global $DB;
     $bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N' ? false : true;
     $lastId = !isset($arParams['LAST_ID']) || $arParams['LAST_ID'] == null ? null : IntVal($arParams['LAST_ID']);
     $order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC' ? 'ASC' : 'DESC';
     $loadDepartment = isset($arParams['LOAD_DEPARTMENT']) && $arParams['LOAD_DEPARTMENT'] == 'N' ? false : true;
     $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N' ? false : true;
     $bGroupByChat = isset($arParams['GROUP_BY_CHAT']) && $arParams['GROUP_BY_CHAT'] == 'Y' ? true : false;
     $bUserLoad = isset($arParams['USER_LOAD']) && $arParams['USER_LOAD'] == 'N' ? false : true;
     $arExistUserData = isset($arParams['EXIST_USER_DATA']) && is_array($arParams['EXIST_USER_DATA']) ? $arParams['EXIST_USER_DATA'] : array();
     $arMessages = array();
     $arUnreadMessage = array();
     $arUsersMessage = array();
     $arResult = array('message' => array(), 'unreadMessage' => array(), 'usersMessage' => array(), 'users' => array(), 'userInGroup' => array(), 'woUserInGroup' => array(), 'countMessage' => 0, 'result' => false);
     $bLoadMessage = $bSpeedCheck ? CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_MESSAGE) : false;
     $count = CIMMessenger::SpeedFileGet($this->user_id, IM_SPEED_MESSAGE);
     if (!$bLoadMessage || $bLoadMessage && $count > 0) {
         $ssqlLastId = "R1.LAST_ID";
         $ssqlStatus = " AND R1.STATUS < " . IM_STATUS_READ;
         if (!is_null($lastId) && intval($lastId) > 0 && !CIMMessenger::CheckXmppStatusOnline()) {
             $ssqlLastId = intval($lastId);
             $ssqlStatus = "";
         }
         if (!$bTimeZone) {
             CTimeZone::Disable();
         }
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tM.ID,\n\t\t\t\t\tM.CHAT_ID,\n\t\t\t\t\tM.MESSAGE,\n\t\t\t\t\t" . $DB->DateToCharFunction('M.DATE_CREATE') . " DATE_CREATE,\n\t\t\t\t\tM.AUTHOR_ID,\n\t\t\t\t\tR1.USER_ID R1_USER_ID,\n\t\t\t\t\tR1.STATUS R1_STATUS,\n\t\t\t\t\tR2.USER_ID R2_USER_ID\n\t\t\t\tFROM b_im_relation R1\n\t\t\t\tINNER JOIN b_im_relation R2 on R2.CHAT_ID = R1.CHAT_ID AND R2.USER_ID != R1.USER_ID\n\t\t\t\tINNER JOIN b_im_message M ON M.ID > " . $ssqlLastId . " AND M.CHAT_ID = R2.CHAT_ID AND IMPORT_ID IS NULL\n\t\t\t\tWHERE R1.USER_ID = " . $this->user_id . " AND R1.USER_ID != M.AUTHOR_ID AND R1.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "' " . $ssqlStatus . "\n\t\t\t\tORDER BY ID " . ($order == "DESC" ? "DESC" : "ASC") . "\n\t\t\t";
         if (!$bTimeZone) {
             CTimeZone::Enable();
         }
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $arLastMessage = array();
         $arMark = array();
         $CCTP = new CTextParser();
         $CCTP->MaxStringLen = 200;
         $CCTP->allow = array("HTML" => "N", "ANCHOR" => $this->bHideLink ? "N" : "Y", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
         if (!$this->bHideLink) {
             $CCTPM = new CTextParser();
             $CCTPM->MaxStringLen = 200;
             $CCTPM->allow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
         }
         while ($arRes = $dbRes->Fetch()) {
             $arUsers[] = $arRes['R1_USER_ID'];
             $arUsers[] = $arRes['R2_USER_ID'];
             if ($this->user_id == $arRes['AUTHOR_ID']) {
                 $arRes['TO_USER_ID'] = $arRes['R2_USER_ID'];
                 $arRes['FROM_USER_ID'] = $arRes['R1_USER_ID'];
                 $convId = $arRes['TO_USER_ID'];
             } else {
                 $arRes['TO_USER_ID'] = $arRes['R1_USER_ID'];
                 $arRes['FROM_USER_ID'] = $arRes['R2_USER_ID'];
                 $convId = $arRes['FROM_USER_ID'];
             }
             $arMessages[$arRes['ID']] = array('id' => $arRes['ID'], 'senderId' => $arRes['FROM_USER_ID'], 'recipientId' => $arRes['TO_USER_ID'], 'date' => MakeTimeStamp($arRes['DATE_CREATE']), 'text' => $arRes['MESSAGE']);
             if ($bGroupByChat) {
                 $arMessages[$arRes['ID']]['conversation'] = $convId;
                 $arMessages[$arRes['ID']]['unread'] = $this->user_id != $arRes['AUTHOR_ID'] ? 'Y' : 'N';
             } else {
                 $arUsersMessage[$convId][] = $arRes['ID'];
                 if ($this->user_id != $arRes['AUTHOR_ID']) {
                     $arUnreadMessage[$convId][] = $arRes['ID'];
                 }
             }
             if ($arRes['R1_STATUS'] == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"])) {
                 $arMark[$arRes["CHAT_ID"]] = $arRes["ID"];
             }
             if (!isset($arLastMessage[$convId]) || $arLastMessage[$convId] < $arRes["ID"]) {
                 $arLastMessage[$convId] = $arRes["ID"];
             }
         }
         if ($bGroupByChat) {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$arLastMessage[$value['conversation']]]['counter']++;
                 if ($arLastMessage[$value['conversation']] != $value['id']) {
                     unset($arMessages[$key]);
                 } else {
                     $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                     if ($this->bHideLink) {
                         $arMessages[$key]['text_mobile'] = $arMessages[$key]['text'];
                     } else {
                         $arMessages[$key]['text_mobile'] = $CCTPM->convertText(htmlspecialcharsbx($value['text']));
                     }
                     $arUsersMessage[$value['conversation']][] = $value['id'];
                     if ($value['unread'] == 'Y') {
                         $arUnreadMessage[$value['conversation']][] = $value['id'];
                     }
                     unset($arMessages[$key]['conversation']);
                     unset($arMessages[$key]['unread']);
                 }
             }
         } else {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                 if ($this->bHideLink) {
                     $arMessages[$key]['text_mobile'] = $arMessages[$key]['text'];
                 } else {
                     $arMessages[$key]['text_mobile'] = $CCTPM->convertText(htmlspecialcharsbx($value['text']));
                 }
             }
         }
         foreach ($arMark as $chatId => $lastSendId) {
             self::SetLastSendId($chatId, $this->user_id, $lastSendId);
         }
         $arResult['message'] = $arMessages;
         $arResult['unreadMessage'] = $arUnreadMessage;
         $arResult['usersMessage'] = $arUsersMessage;
         if ($bUserLoad && !empty($arUsers)) {
             $arUserData = CIMContactList::GetUserData(array('ID' => array_diff(array_unique($arUsers), $arExistUserData), 'DEPARTMENT' => $loadDepartment ? 'Y' : 'N'));
             $arResult['users'] = $arUserData['users'];
             $arResult['userInGroup'] = $arUserData['userInGroup'];
             $arResult['woUserInGroup'] = $arUserData['woUserInGroup'];
         } else {
             $arResult['users'] = array();
             $arResult['userInGroup'] = array();
             $arResult['userInGroup'] = array();
         }
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
         if (!$bGroupByChat) {
             CIMMessenger::SpeedFileCreate($this->user_id, $arResult['countMessage'], IM_SPEED_MESSAGE);
         }
         $arResult['result'] = true;
     } else {
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
     }
     return $arResult;
 }
Ejemplo n.º 6
0
 public static function GetTemplateJS($arParams, $arTemplate)
 {
     global $USER;
     $ppStatus = 'false';
     $ppServerStatus = 'false';
     if (CModule::IncludeModule("pull")) {
         $ppStatus = CPullOptions::ModuleEnable() ? 'true' : 'false';
         $ppServerStatus = CPullOptions::GetNginxStatus() ? 'true' : 'false';
     }
     if ($arTemplate['INIT'] == 'Y') {
         $sJS = "\n\t\t\t\tBX.ready(function() {\n\t\t\t\t\tBXIM = new BX.IM(BX('bx-notifier-panel'), {\n\t\t\t\t\t\t'panelPosition': {'horizontal' : '" . $arTemplate['PANEL_POSTION_HORIZONTAL'] . "', 'vertical' : '" . $arTemplate['PANEL_POSTION_VERTICAL'] . "'},\n\t\t\t\t\t\t'userStatus': '" . $arTemplate['STATUS'] . "',\n\t\t\t\t\t\t'mailCount': " . $arTemplate["MAIL_COUNTER"] . ",\n\t\t\t\t\t\t'notifyCount': " . $arTemplate["NOTIFY_COUNTER"] . ",\n\t\t\t\t\t\t'messageCount': " . $arTemplate["MESSAGE_COUNTER"] . ",\n\t\t\t\t\t\t'counters': " . (empty($arTemplate['COUNTERS']) ? '{}' : CUtil::PhpToJSObject($arTemplate['COUNTERS'])) . ",\n\t\t\t\t\t\t'ppStatus': " . $ppStatus . ",\n\t\t\t\t\t\t'ppServerStatus': " . $ppServerStatus . ",\n\t\t\t\t\t\t'xmppStatus': " . (CIMMessenger::CheckXmppStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrix24Status': " . (IsModuleInstalled('bitrix24') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrixIntranet': " . (IsModuleInstalled('intranet') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'desktop': " . $arTemplate["DESKTOP"] . ",\n\t\t\t\t\t\t'desktopStatus': " . (CIMMessenger::CheckDesktopStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'desktopLinkOpen': " . $arTemplate["DESKTOP_LINK_OPEN"] . ",\n\n\t\t\t\t\t\t'notify': " . (empty($arTemplate['NOTIFY']['notify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['notify'])) . ",\n\t\t\t\t\t\t'unreadNotify' : " . (empty($arTemplate['NOTIFY']['unreadNotify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['unreadNotify'])) . ",\n\t\t\t\t\t\t'flashNotify' : " . (empty($arTemplate['NOTIFY']['flashNotify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['flashNotify'])) . ",\n\t\t\t\t\t\t'countNotify' : " . intval($arTemplate['NOTIFY']['countNotify']) . ",\n\t\t\t\t\t\t'loadNotify' : " . ($arTemplate['NOTIFY']['loadNotify'] ? 'true' : 'false') . ",\n\n\t\t\t\t\t\t'recent': " . CUtil::PhpToJSObject($arTemplate['RECENT']) . ",\n\t\t\t\t\t\t'users': " . (empty($arTemplate['CONTACT_LIST']['users']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['users'])) . ",\n\t\t\t\t\t\t'groups': " . (empty($arTemplate['CONTACT_LIST']['groups']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['groups'])) . ",\n\t\t\t\t\t\t'userInGroup': " . (empty($arTemplate['CONTACT_LIST']['userInGroup']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['userInGroup'])) . ",\n\t\t\t\t\t\t'woGroups': " . (empty($arTemplate['CONTACT_LIST']['woGroups']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woGroups'])) . ",\n\t\t\t\t\t\t'woUserInGroup': " . (empty($arTemplate['CONTACT_LIST']['woUserInGroup']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woUserInGroup'])) . ",\n\t\t\t\t\t\t'chat': " . (empty($arTemplate['CHAT']['chat']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['chat'])) . ",\n\t\t\t\t\t\t'userInChat': " . (empty($arTemplate['CHAT']['userInChat']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['userInChat'])) . ",\n\t\t\t\t\t\t'message' : " . (empty($arTemplate['MESSAGE']['message']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['message'])) . ",\n\t\t\t\t\t\t'showMessage' : " . (empty($arTemplate['MESSAGE']['usersMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['usersMessage'])) . ",\n\t\t\t\t\t\t'unreadMessage' : " . (empty($arTemplate['MESSAGE']['unreadMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['unreadMessage'])) . ",\n\t\t\t\t\t\t'flashMessage' : " . (empty($arTemplate['MESSAGE']['flashMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['flashMessage'])) . ",\n\t\t\t\t\t\t'history' : {},\n\t\t\t\t\t\t'openMessenger' : " . (isset($_GET['IM_DIALOG']) ? "'" . htmlspecialcharsbx($_GET['IM_DIALOG']) . "'" : 'false') . ",\n\t\t\t\t\t\t'openHistory' : " . (isset($_GET['IM_HISTORY']) ? "'" . htmlspecialcharsbx($_GET['IM_HISTORY']) . "'" : 'false') . ",\n\t\t\t\t\t\t'viewOffline': " . $arTemplate['VIEW_OFFLINE'] . ",\n\t\t\t\t\t\t'viewGroup': " . $arTemplate['VIEW_GROUP'] . ",\n\t\t\t\t\t\t'enableSound': " . $arTemplate['ENABLE_SOUND'] . ",\n\t\t\t\t\t\t'sendByEnter': " . $arTemplate['SEND_BY_ENTER'] . ",\n\t\t\t\t\t\t'currentTab' : " . ($arTemplate['CURRENT_TAB'] > 0 ? $arTemplate['CURRENT_TAB'] : '0') . ",\n\t\t\t\t\t\t'userId': " . $USER->GetID() . ",\n\t\t\t\t\t\t'path' : {'profile' : '" . $arTemplate['PATH_TO_USER_PROFILE'] . "', 'profileTemplate' : '" . $arTemplate['PATH_TO_USER_PROFILE_TEMPLATE'] . "', 'mail' : '" . $arTemplate['PATH_TO_USER_MAIL'] . "'}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t";
     } else {
         $sJS = "\n\t\t\t\tBX.ready(function() {\n\t\t\t\t\tBXIM = new BX.IM(BX('bx-notifier-panel'), {\n\t\t\t\t\t\t'init': false,\n\n\t\t\t\t\t\t'desktop': " . $arTemplate["DESKTOP"] . ",\n\t\t\t\t\t\t'desktopStatus': " . (CIMMessenger::CheckDesktopStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'desktopLinkOpen': " . $arTemplate["DESKTOP_LINK_OPEN"] . ",\n\n\t\t\t\t\t\t'userStatus': '" . $arTemplate['STATUS'] . "',\n\t\t\t\t\t\t'ppStatus': " . $ppStatus . ",\n\t\t\t\t\t\t'ppServerStatus': " . $ppServerStatus . ",\n\t\t\t\t\t\t'xmppStatus': " . (CIMMessenger::CheckXmppStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrix24Status': " . (IsModuleInstalled('bitrix24') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrixIntranet': " . (IsModuleInstalled('intranet') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'enableSound': " . $arTemplate['ENABLE_SOUND'] . ",\n\t\t\t\t\t\t'notify' : {},\n\t\t\t\t\t\t'users' : {},\n\t\t\t\t\t\t'userId': " . $USER->GetID() . ",\n\n\t\t\t\t\t\t'openMessenger' : " . (isset($_GET['IM_DIALOG']) ? intval($_GET['IM_DIALOG']) : 'false') . ",\n\t\t\t\t\t\t'openHistory' : " . (isset($_GET['IM_HISTORY']) ? intval($_GET['IM_HISTORY']) : 'false') . ",\n\n\t\t\t\t\t\t'path' : {'profile' : '" . $arTemplate['PATH_TO_USER_PROFILE'] . "', 'profileTemplate' : '" . $arTemplate['PATH_TO_USER_PROFILE_TEMPLATE'] . "', 'mail' : '" . $arTemplate['PATH_TO_USER_MAIL'] . "'}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t";
     }
     return $sJS;
 }
Ejemplo n.º 7
0
	public static function GetTemplateJS($arParams, $arTemplate)
	{
		global $USER;

		$ppStatus = 'false';
		$ppServerStatus = 'false';
		$updateStateInterval = 'auto';
		if (CModule::IncludeModule("pull"))
		{
			$ppStatus = CPullOptions::ModuleEnable()? 'true': 'false';
			$ppServerStatus = CPullOptions::GetNginxStatus()? 'true': 'false';
			$updateStateInterval = CPullOptions::GetNginxStatus()? self::GetSessionLifeTime(): 80;
			if ($updateStateInterval > 100)
			{
				if ($arTemplate['DESKTOP'] == 'true')
					$updateStateInterval = intval($updateStateInterval/2);
				else
					$updateStateInterval = $updateStateInterval-20;
			}
		}

		if ($arTemplate['INIT'] == 'Y')
		{
			$sJS = "
				BX.ready(function() {
					BXIM = new BX.IM(BX('bx-notifier-panel'), {
						'mailCount': ".$arTemplate["MAIL_COUNTER"].",
						'notifyCount': ".$arTemplate["NOTIFY_COUNTER"].",
						'messageCount': ".$arTemplate["MESSAGE_COUNTER"].",
						'counters': ".(empty($arTemplate['COUNTERS'])? '{}': CUtil::PhpToJSObject($arTemplate['COUNTERS'])).",
						'ppStatus': ".$ppStatus.",
						'ppServerStatus': ".$ppServerStatus.",
						'updateStateInterval': '".$updateStateInterval."',
						'xmppStatus': ".(CIMMessenger::CheckXmppStatusOnline()? 'true': 'false').",
						'bitrix24Status': ".(IsModuleInstalled('bitrix24')? 'true': 'false').",
						'bitrixIntranet': ".(IsModuleInstalled('intranet')? 'true': 'false').",
						'bitrixXmpp': ".(IsModuleInstalled('xmpp')? 'true': 'false').",
						'desktop': ".$arTemplate["DESKTOP"].",
						'desktopStatus': ".(CIMMessenger::CheckDesktopStatusOnline()? 'true': 'false').",
						'desktopLinkOpen': ".$arTemplate["DESKTOP_LINK_OPEN"].",
						'language': '".LANGUAGE_ID."',

						'smile': ".CUtil::PhpToJSObject($arTemplate["SMILE"]).",
						'smileSet': ".CUtil::PhpToJSObject($arTemplate["SMILE_SET"]).",
						'settings': ".CUtil::PhpToJSObject($arTemplate['SETTINGS']).",
						'settingsNotifyBlocked': ".(empty($arTemplate['SETTINGS_NOTIFY_BLOCKED'])? '{}': CUtil::PhpToJSObject($arTemplate['SETTINGS_NOTIFY_BLOCKED'])).",

						'notify': ".(empty($arTemplate['NOTIFY']['notify'])? '{}': CUtil::PhpToJSObject($arTemplate['NOTIFY']['notify'])).",
						'unreadNotify' : ".(empty($arTemplate['NOTIFY']['unreadNotify'])? '{}': CUtil::PhpToJSObject($arTemplate['NOTIFY']['unreadNotify'])).",
						'flashNotify' : ".(empty($arTemplate['NOTIFY']['flashNotify'])? '{}': CUtil::PhpToJSObject($arTemplate['NOTIFY']['flashNotify'])).",
						'countNotify' : ".intval($arTemplate['NOTIFY']['countNotify']).",
						'loadNotify' : ".($arTemplate['NOTIFY']['loadNotify']? 'true': 'false').",

						'recent': ".CUtil::PhpToJSObject($arTemplate['RECENT']).",
						'users': ".(empty($arTemplate['CONTACT_LIST']['users'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['users'])).",
						'groups': ".(empty($arTemplate['CONTACT_LIST']['groups'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['groups'])).",
						'userInGroup': ".(empty($arTemplate['CONTACT_LIST']['userInGroup'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['userInGroup'])).",
						'woGroups': ".(empty($arTemplate['CONTACT_LIST']['woGroups'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woGroups'])).",
						'woUserInGroup': ".(empty($arTemplate['CONTACT_LIST']['woUserInGroup'])? '{}': CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woUserInGroup'])).",
						'chat': ".(empty($arTemplate['CHAT']['chat'])? '{}': CUtil::PhpToJSObject($arTemplate['CHAT']['chat'])).",
						'userInChat': ".(empty($arTemplate['CHAT']['userInChat'])? '{}': CUtil::PhpToJSObject($arTemplate['CHAT']['userInChat'])).",
						'message' : ".(empty($arTemplate['MESSAGE']['message'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['message'])).",
						'showMessage' : ".(empty($arTemplate['MESSAGE']['usersMessage'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['usersMessage'])).",
						'unreadMessage' : ".(empty($arTemplate['MESSAGE']['unreadMessage'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['unreadMessage'])).",
						'flashMessage' : ".(empty($arTemplate['MESSAGE']['flashMessage'])? '{}': CUtil::PhpToJSObject($arTemplate['MESSAGE']['flashMessage'])).",
						'history' : {},
						'openMessenger' : ".(isset($_GET['IM_DIALOG'])? "'".CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_DIALOG']))."'": 'false').",
						'openHistory' : ".(isset($_GET['IM_HISTORY'])? "'".CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_HISTORY']))."'": 'false').",
						'openSettings' : ".(isset($_GET['IM_SETTINGS']) && $_GET['IM_SETTINGS'] == 'Y'? "'true'": 'false').",
						'currentTab' : '".CUtil::JSEscape($arTemplate['CURRENT_TAB'])."',
						'userId': ".$USER->GetID().",
						'userEmail': '".CUtil::JSEscape($USER->GetEmail())."',
						'webrtc': {'turnServer' : '".CUtil::JSEscape($arTemplate['TURN_SERVER'])."', 'turnServerFirefox' : '".CUtil::JSEscape($arTemplate['TURN_SERVER_FIREFOX'])."', 'turnServerLogin' : '".CUtil::JSEscape($arTemplate['TURN_SERVER_LOGIN'])."', 'turnServerPassword' : '".CUtil::JSEscape($arTemplate['TURN_SERVER_PASSWORD'])."'},
						'path' : {'profile' : '".CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE'])."', 'profileTemplate' : '".CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE_TEMPLATE'])."', 'mail' : '".CUtil::JSEscape($arTemplate['PATH_TO_USER_MAIL'])."'}
					});
				});
			";
		}
		else
		{
			$sJS = "
				BX.ready(function() {
					BXIM = new BX.IM(BX('bx-notifier-panel'), {
						'init': false,
						'settings': ".CUtil::PhpToJSObject($arTemplate['SETTINGS']).",
						'updateStateInterval': '".$updateStateInterval."',
						'desktop': ".$arTemplate["DESKTOP"].",
						'ppStatus': ".$ppStatus.",
						'ppServerStatus': ".$ppServerStatus.",
						'xmppStatus': ".(CIMMessenger::CheckXmppStatusOnline()? 'true': 'false').",
						'bitrix24Status': ".(IsModuleInstalled('bitrix24')? 'true': 'false').",
						'bitrixIntranet': ".(IsModuleInstalled('intranet')? 'true': 'false').",
						'bitrixXmpp': ".(IsModuleInstalled('xmpp')? 'true': 'false').",
						'notify' : {},
						'users' : {},
						'userId': ".$USER->GetID().",
						'userEmail': '".CUtil::JSEscape($USER->GetEmail())."',

						'openMessenger' : ".(isset($_GET['IM_DIALOG'])? "'".CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_DIALOG']))."'": 'false').",
						'openHistory' : ".(isset($_GET['IM_HISTORY'])? "'".CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_HISTORY']))."'": 'false').",
						'openSettings' : ".(isset($_GET['IM_SETTINGS']) && $_GET['IM_SETTINGS'] == 'Y'? "'true'": 'false').",

						'path' : {'profile' : '".$arTemplate['PATH_TO_USER_PROFILE']."', 'profileTemplate' : '".$arTemplate['PATH_TO_USER_PROFILE_TEMPLATE']."', 'mail' : '".$arTemplate['PATH_TO_USER_MAIL']."'}
					});
				});
			";
		}

		return $sJS;
	}
Ejemplo n.º 8
0
 public static function GetMobileTemplateJS($arParams, $arTemplate)
 {
     global $USER;
     $ppStatus = 'false';
     $ppServerStatus = 'false';
     $updateStateInterval = 'auto';
     if (CModule::IncludeModule("pull")) {
         $ppStatus = CPullOptions::ModuleEnable() ? 'true' : 'false';
         $ppServerStatus = CPullOptions::GetNginxStatus() ? 'true' : 'false';
         $updateStateInterval = CPullOptions::GetNginxStatus() ? self::GetSessionLifeTime() : 80;
         if ($updateStateInterval > 100) {
             if ($updateStateInterval > 3600) {
                 $updateStateInterval = 3600;
             }
             $updateStateInterval = $updateStateInterval - 60;
         }
     }
     $diskStatus = CIMDisk::Enabled();
     $phoneSipAvailable = false;
     $phoneDeviceActive = false;
     $phoneEnabled = self::CheckPhoneStatus() && CModule::IncludeModule('mobileapp') && \Bitrix\MobileApp\Mobile::getInstance()->isWebRtcSupported();
     if ($phoneEnabled && CModule::IncludeModule('voximplant')) {
         $phoneSipAvailable = CVoxImplantConfig::GetModeStatus(CVoxImplantConfig::MODE_SIP);
         $phoneDeviceActive = CVoxImplantUser::GetPhoneActive($USER->GetId());
     }
     $mobileAction = isset($arTemplate["ACTION"]) ? $arTemplate["ACTION"] : 'none';
     $mobileCallMethod = isset($arTemplate["CALL_METHOD"]) ? $arTemplate["CALL_METHOD"] : 'device';
     $userColor = isset($arTemplate['CONTACT_LIST']['users'][$USER->GetID()]['color']) ? $arTemplate['CONTACT_LIST']['users'][$USER->GetID()]['color'] : '';
     $sJS = "\n\t\t\tBX.ready(function() {\n\t\t\t\tBXIM = new BX.ImMobile({\n\t\t\t\t\t'mobileAction': '" . $mobileAction . "',\n\t\t\t\t\t'mobileCallMethod': '" . $mobileCallMethod . "',\n\n\t\t\t\t\t'colors': " . (IM\Color::isEnabled() ? CUtil::PhpToJSObject(IM\Color::getSafeColorNames()) : 'false') . ",\n\t\t\t\t\t'mailCount': " . intval($arTemplate["MAIL_COUNTER"]) . ",\n\t\t\t\t\t'notifyCount': " . intval($arTemplate["NOTIFY_COUNTER"]) . ",\n\t\t\t\t\t'messageCount': " . intval($arTemplate["MESSAGE_COUNTER"]) . ",\n\t\t\t\t\t'counters': " . (empty($arTemplate['COUNTERS']) ? '{}' : CUtil::PhpToJSObject($arTemplate['COUNTERS'])) . ",\n\t\t\t\t\t'ppStatus': " . $ppStatus . ",\n\t\t\t\t\t'ppServerStatus': " . $ppServerStatus . ",\n\t\t\t\t\t'updateStateInterval': '" . $updateStateInterval . "',\n\t\t\t\t\t'openChatEnable': " . (CIMMessenger::CheckEnableOpenChat() ? 'true' : 'false') . ",\n\t\t\t\t\t'xmppStatus': " . (CIMMessenger::CheckXmppStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrixNetwork': " . (CIMMessenger::CheckNetwork() ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrixNetwork2': " . (CIMMessenger::CheckNetwork2() ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrix24': " . (IsModuleInstalled('bitrix24') ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrix24Admin': " . (CModule::IncludeModule('bitrix24') && CBitrix24::IsPortalAdmin($USER->GetId()) ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrix24net': " . (IsModuleInstalled('b24network') ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrixIntranet': " . (IsModuleInstalled('intranet') ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrixXmpp': " . (IsModuleInstalled('xmpp') ? 'true' : 'false') . ",\n\t\t\t\t\t'bitrixMobile': " . (IsModuleInstalled('mobile') ? 'true' : 'false') . ",\n\t\t\t\t\t'desktopStatus': " . (CIMMessenger::CheckDesktopStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t'desktopVersion': " . CIMMessenger::GetDesktopVersion() . ",\n\t\t\t\t\t'language': '" . LANGUAGE_ID . "',\n\n\t\t\t\t\t'smile': " . (empty($arTemplate['SMILE']) ? '{}' : CUtil::PhpToJSObject($arTemplate["SMILE"])) . ",\n\t\t\t\t\t'smileSet': " . (empty($arTemplate['SMILE_SET']) ? '{}' : CUtil::PhpToJSObject($arTemplate["SMILE_SET"])) . ",\n\t\t\t\t\t'settings': " . (empty($arTemplate['SETTINGS']) ? '{}' : CUtil::PhpToJSObject($arTemplate['SETTINGS'])) . ",\n\t\t\t\t\t'settingsNotifyBlocked': " . (empty($arTemplate['SETTINGS_NOTIFY_BLOCKED']) ? '{}' : CUtil::PhpToJSObject($arTemplate['SETTINGS_NOTIFY_BLOCKED'])) . ",\n\n\t\t\t\t\t'notify': " . (empty($arTemplate['NOTIFY']['notify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['notify'])) . ",\n\t\t\t\t\t'unreadNotify' : " . (empty($arTemplate['NOTIFY']['unreadNotify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['unreadNotify'])) . ",\n\t\t\t\t\t'flashNotify' : " . (empty($arTemplate['NOTIFY']['flashNotify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['flashNotify'])) . ",\n\t\t\t\t\t'countNotify' : " . intval($arTemplate['NOTIFY']['countNotify']) . ",\n\t\t\t\t\t'loadNotify' : " . ($arTemplate['NOTIFY']['loadNotify'] ? 'true' : 'false') . ",\n\n\t\t\t\t\t'recent': " . (empty($arTemplate['RECENT']) && $arTemplate['RECENT'] !== false ? '[]' : CUtil::PhpToJSObject($arTemplate['RECENT'])) . ",\n\t\t\t\t\t'users': " . (empty($arTemplate['CONTACT_LIST']['users']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['users'])) . ",\n\t\t\t\t\t'groups': " . (empty($arTemplate['CONTACT_LIST']['groups']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['groups'])) . ",\n\t\t\t\t\t'userInGroup': " . (empty($arTemplate['CONTACT_LIST']['userInGroup']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['userInGroup'])) . ",\n\t\t\t\t\t'woGroups': " . (empty($arTemplate['CONTACT_LIST']['woGroups']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woGroups'])) . ",\n\t\t\t\t\t'woUserInGroup': " . (empty($arTemplate['CONTACT_LIST']['woUserInGroup']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woUserInGroup'])) . ",\n\t\t\t\t\t'chat': " . (empty($arTemplate['CHAT']['chat']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['chat'])) . ",\n\t\t\t\t\t'userInChat': " . (empty($arTemplate['CHAT']['userInChat']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['userInChat'])) . ",\n\t\t\t\t\t'userChatBlockStatus': " . (empty($arTemplate['CHAT']['userChatBlockStatus']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['userChatBlockStatus'])) . ",\n\t\t\t\t\t'message' : " . (empty($arTemplate['MESSAGE']['message']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['message'])) . ",\n\t\t\t\t\t'files' : " . (empty($arTemplate['MESSAGE']['files']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['files'])) . ",\n\t\t\t\t\t'showMessage' : " . (empty($arTemplate['MESSAGE']['usersMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['usersMessage'])) . ",\n\t\t\t\t\t'unreadMessage' : " . (empty($arTemplate['MESSAGE']['unreadMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['unreadMessage'])) . ",\n\t\t\t\t\t'flashMessage' : " . (empty($arTemplate['MESSAGE']['flashMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['flashMessage'])) . ",\n\t\t\t\t\t'history' : {},\n\t\t\t\t\t'openMessenger' : " . (isset($_GET['IM_DIALOG']) ? "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_DIALOG'])) . "'" : 'false') . ",\n\t\t\t\t\t'openHistory' : " . (isset($_GET['IM_HISTORY']) ? "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_HISTORY'])) . "'" : 'false') . ",\n\t\t\t\t\t'openNotify' : " . (isset($_GET['IM_NOTIFY']) && $_GET['IM_NOTIFY'] == 'Y' ? 'true' : 'false') . ",\n\t\t\t\t\t'openSettings' : " . (isset($_GET['IM_SETTINGS']) ? $_GET['IM_SETTINGS'] == 'Y' ? "'true'" : "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_SETTINGS'])) . "'" : 'false') . ",\n\n\t\t\t\t\t'currentTab' : '" . ($arTemplate['CURRENT_TAB'] ? CUtil::JSEscape($arTemplate['CURRENT_TAB']) : 0) . "',\n\t\t\t\t\t'generalChatId': " . CIMChat::GetGeneralChatId() . ",\n\t\t\t\t\t'canSendMessageGeneralChat': " . (CIMChat::CanSendMessageToGeneralChat($USER->GetID()) ? 'true' : 'false') . ",\n\t\t\t\t\t'userId': " . $USER->GetID() . ",\n\t\t\t\t\t'userEmail': '" . CUtil::JSEscape($USER->GetEmail()) . "',\n\t\t\t\t\t'userColor': '" . IM\Color::getCode($userColor) . "',\n\t\t\t\t\t'userGender': '" . IM\User::getInstance()->getGender() . "',\n\t\t\t\t\t'userExtranet': " . (IM\User::getInstance()->isExtranet() ? 'true' : 'false') . ",\n\t\t\t\t\t'webrtc': {'turnServer' : '" . (empty($arTemplate['TURN_SERVER']) ? '' : CUtil::JSEscape($arTemplate['TURN_SERVER'])) . "', 'turnServerLogin' : '" . (empty($arTemplate['TURN_SERVER_LOGIN']) ? '' : CUtil::JSEscape($arTemplate['TURN_SERVER_LOGIN'])) . "', 'turnServerPassword' : '" . (empty($arTemplate['TURN_SERVER_PASSWORD']) ? '' : CUtil::JSEscape($arTemplate['TURN_SERVER_PASSWORD'])) . "', 'mobileSupport': " . ($arTemplate['WEBRTC_MOBILE_SUPPORT'] ? 'true' : 'false') . ", 'phoneEnabled': " . ($phoneEnabled ? 'true' : 'false') . ", 'phoneSipAvailable': " . ($phoneSipAvailable ? 'true' : 'false') . "},\n\t\t\t\t\t'disk': {'enable' : " . ($diskStatus ? 'true' : 'false') . "},\n\t\t\t\t\t'path' : {'profile' : '" . (empty($arTemplate['PATH_TO_USER_PROFILE']) ? '' : CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE'])) . "', 'profileTemplate' : '" . (empty($arTemplate['PATH_TO_USER_PROFILE_TEMPLATE']) ? '' : CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE_TEMPLATE'])) . "', 'mail' : '" . (empty($arTemplate['PATH_TO_USER_MAIL']) ? '' : CUtil::JSEscape($arTemplate['PATH_TO_USER_MAIL'])) . "'}\n\t\t\t\t});\n\t\t\t});\n\t\t";
     return $sJS;
 }
Ejemplo n.º 9
0
 public static function GetTemplateJS($arParams, $arTemplate)
 {
     global $USER;
     $ppStatus = 'false';
     $ppServerStatus = 'false';
     $updateStateInterval = 'auto';
     if (CModule::IncludeModule("pull")) {
         $ppStatus = CPullOptions::ModuleEnable() ? 'true' : 'false';
         $ppServerStatus = CPullOptions::GetNginxStatus() ? 'true' : 'false';
         $updateStateInterval = CPullOptions::GetNginxStatus() ? self::GetSessionLifeTime() : 80;
         if ($updateStateInterval > 100) {
             if ($updateStateInterval > 3600) {
                 $updateStateInterval = 3600;
             }
             if ($arTemplate['DESKTOP'] == 'true') {
                 $updateStateInterval = intval($updateStateInterval / 2);
             } else {
                 $updateStateInterval = $updateStateInterval - 60;
             }
         }
     }
     $diskStatus = CIMDisk::Enabled();
     if ($arTemplate['INIT'] == 'Y') {
         $phoneAvailable = 0;
         $phoneSipAvailable = 0;
         $phoneEnabled = self::CheckPhoneStatus();
         if ($phoneEnabled && CModule::IncludeModule('voximplant')) {
             $phoneBalance = COption::GetOptionString("voximplant", "account_balance", 0);
             if (floatval($phoneBalance) >= 0) {
                 $phoneAvailable = floatval($phoneBalance) > 0 ? 2 : 1;
             }
             $phoneSipAvailable = CVoxImplantConfig::GetModeStatus(CVoxImplantConfig::MODE_SIP);
         }
         $pathToIm = isset($arTemplate['PATH_TO_IM']) ? $arTemplate['PATH_TO_IM'] : '';
         $pathToCall = isset($arTemplate['PATH_TO_CALL']) ? $arTemplate['PATH_TO_CALL'] : '';
         $pathToFile = isset($arTemplate['PATH_TO_FILE']) ? $arTemplate['PATH_TO_FILE'] : '';
         $sJS = "\n\t\t\t\tBX.ready(function() {\n\t\t\t\t\tBXIM = new BX.IM(BX('bx-notifier-panel'), {\n\t\t\t\t\t\t'mailCount': " . $arTemplate["MAIL_COUNTER"] . ",\n\t\t\t\t\t\t'notifyCount': " . $arTemplate["NOTIFY_COUNTER"] . ",\n\t\t\t\t\t\t'messageCount': " . $arTemplate["MESSAGE_COUNTER"] . ",\n\t\t\t\t\t\t'counters': " . (empty($arTemplate['COUNTERS']) ? '{}' : CUtil::PhpToJSObject($arTemplate['COUNTERS'])) . ",\n\t\t\t\t\t\t'ppStatus': " . $ppStatus . ",\n\t\t\t\t\t\t'ppServerStatus': " . $ppServerStatus . ",\n\t\t\t\t\t\t'updateStateInterval': '" . $updateStateInterval . "',\n\t\t\t\t\t\t'xmppStatus': " . (CIMMessenger::CheckXmppStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrixNetworkStatus': " . (CIMMessenger::CheckNetworkStatus() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrix24Status': " . (IsModuleInstalled('bitrix24') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrix24Admin': " . (CModule::IncludeModule('bitrix24') && CBitrix24::IsPortalAdmin($USER->GetId()) ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrix24net': " . (IsModuleInstalled('b24network') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrixIntranet': " . (IsModuleInstalled('intranet') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrixXmpp': " . (IsModuleInstalled('xmpp') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'desktop': " . $arTemplate["DESKTOP"] . ",\n\t\t\t\t\t\t'desktopStatus': " . (CIMMessenger::CheckDesktopStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'desktopVersion': " . CIMMessenger::GetDesktopVersion() . ",\n\t\t\t\t\t\t'desktopLinkOpen': " . $arTemplate["DESKTOP_LINK_OPEN"] . ",\n\t\t\t\t\t\t'language': '" . LANGUAGE_ID . "',\n\n\t\t\t\t\t\t'smile': " . CUtil::PhpToJSObject($arTemplate["SMILE"]) . ",\n\t\t\t\t\t\t'smileSet': " . CUtil::PhpToJSObject($arTemplate["SMILE_SET"]) . ",\n\t\t\t\t\t\t'settings': " . CUtil::PhpToJSObject($arTemplate['SETTINGS']) . ",\n\t\t\t\t\t\t'settingsNotifyBlocked': " . (empty($arTemplate['SETTINGS_NOTIFY_BLOCKED']) ? '{}' : CUtil::PhpToJSObject($arTemplate['SETTINGS_NOTIFY_BLOCKED'])) . ",\n\n\t\t\t\t\t\t'notify': " . (empty($arTemplate['NOTIFY']['notify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['notify'])) . ",\n\t\t\t\t\t\t'unreadNotify' : " . (empty($arTemplate['NOTIFY']['unreadNotify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['unreadNotify'])) . ",\n\t\t\t\t\t\t'flashNotify' : " . (empty($arTemplate['NOTIFY']['flashNotify']) ? '{}' : CUtil::PhpToJSObject($arTemplate['NOTIFY']['flashNotify'])) . ",\n\t\t\t\t\t\t'countNotify' : " . intval($arTemplate['NOTIFY']['countNotify']) . ",\n\t\t\t\t\t\t'loadNotify' : " . ($arTemplate['NOTIFY']['loadNotify'] ? 'true' : 'false') . ",\n\n\t\t\t\t\t\t'recent': " . CUtil::PhpToJSObject($arTemplate['RECENT']) . ",\n\t\t\t\t\t\t'users': " . (empty($arTemplate['CONTACT_LIST']['users']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['users'])) . ",\n\t\t\t\t\t\t'groups': " . (empty($arTemplate['CONTACT_LIST']['groups']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['groups'])) . ",\n\t\t\t\t\t\t'userInGroup': " . (empty($arTemplate['CONTACT_LIST']['userInGroup']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['userInGroup'])) . ",\n\t\t\t\t\t\t'woGroups': " . (empty($arTemplate['CONTACT_LIST']['woGroups']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woGroups'])) . ",\n\t\t\t\t\t\t'woUserInGroup': " . (empty($arTemplate['CONTACT_LIST']['woUserInGroup']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CONTACT_LIST']['woUserInGroup'])) . ",\n\t\t\t\t\t\t'chat': " . (empty($arTemplate['CHAT']['chat']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['chat'])) . ",\n\t\t\t\t\t\t'userInChat': " . (empty($arTemplate['CHAT']['userInChat']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['userInChat'])) . ",\n\t\t\t\t\t\t'userChatBlockStatus': " . (empty($arTemplate['CHAT']['userChatBlockStatus']) ? '{}' : CUtil::PhpToJSObject($arTemplate['CHAT']['userChatBlockStatus'])) . ",\n\t\t\t\t\t\t'message' : " . (empty($arTemplate['MESSAGE']['message']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['message'])) . ",\n\t\t\t\t\t\t'files' : " . (empty($arTemplate['MESSAGE']['files']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['files'])) . ",\n\t\t\t\t\t\t'showMessage' : " . (empty($arTemplate['MESSAGE']['usersMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['usersMessage'])) . ",\n\t\t\t\t\t\t'unreadMessage' : " . (empty($arTemplate['MESSAGE']['unreadMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['unreadMessage'])) . ",\n\t\t\t\t\t\t'flashMessage' : " . (empty($arTemplate['MESSAGE']['flashMessage']) ? '{}' : CUtil::PhpToJSObject($arTemplate['MESSAGE']['flashMessage'])) . ",\n\t\t\t\t\t\t'history' : {},\n\t\t\t\t\t\t'openMessenger' : " . (isset($_GET['IM_DIALOG']) ? "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_DIALOG'])) . "'" : 'false') . ",\n\t\t\t\t\t\t'openHistory' : " . (isset($_GET['IM_HISTORY']) ? "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_HISTORY'])) . "'" : 'false') . ",\n\t\t\t\t\t\t'openNotify' : " . (isset($_GET['IM_NOTIFY']) && $_GET['IM_NOTIFY'] == 'Y' ? 'true' : 'false') . ",\n\t\t\t\t\t\t'openSettings' : " . (isset($_GET['IM_SETTINGS']) ? $_GET['IM_SETTINGS'] == 'Y' ? "'true'" : "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_SETTINGS'])) . "'" : 'false') . ",\n\t\t\t\t\t\t'currentTab' : '" . CUtil::JSEscape($arTemplate['CURRENT_TAB']) . "',\n\t\t\t\t\t\t'userId': " . $USER->GetID() . ",\n\t\t\t\t\t\t'userEmail': '" . CUtil::JSEscape($USER->GetEmail()) . "',\n\t\t\t\t\t\t'webrtc': {'turnServer' : '" . CUtil::JSEscape($arTemplate['TURN_SERVER']) . "', 'turnServerFirefox' : '" . CUtil::JSEscape($arTemplate['TURN_SERVER_FIREFOX']) . "', 'turnServerLogin' : '" . CUtil::JSEscape($arTemplate['TURN_SERVER_LOGIN']) . "', 'turnServerPassword' : '" . CUtil::JSEscape($arTemplate['TURN_SERVER_PASSWORD']) . "', 'phoneEnabled': " . ($phoneEnabled ? 'true' : 'false') . ", 'phoneAvailable': " . $phoneAvailable . ", 'phoneSipAvailable': " . ($phoneSipAvailable ? 'true' : 'false') . "},\n\t\t\t\t\t\t'disk': {'enable' : " . ($diskStatus ? 'true' : 'false') . "},\n\t\t\t\t\t\t'path' : {'profile' : '" . CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE']) . "', 'profileTemplate' : '" . CUtil::JSEscape($arTemplate['PATH_TO_USER_PROFILE_TEMPLATE']) . "', 'mail' : '" . CUtil::JSEscape($arTemplate['PATH_TO_USER_MAIL']) . "', 'im': '" . CUtil::JSEscape($pathToIm) . "', 'call': '" . CUtil::JSEscape($pathToCall) . "', 'file': '" . CUtil::JSEscape($pathToFile) . "'}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t";
     } else {
         $sJS = "\n\t\t\t\tBX.ready(function() {\n\t\t\t\t\tBXIM = new BX.IM(BX('bx-notifier-panel'), {\n\t\t\t\t\t\t'init': false,\n\t\t\t\t\t\t'settings': " . CUtil::PhpToJSObject($arTemplate['SETTINGS']) . ",\n\t\t\t\t\t\t'updateStateInterval': '" . $updateStateInterval . "',\n\t\t\t\t\t\t'desktop': " . $arTemplate["DESKTOP"] . ",\n\t\t\t\t\t\t'ppStatus': " . $ppStatus . ",\n\t\t\t\t\t\t'ppServerStatus': " . $ppServerStatus . ",\n\t\t\t\t\t\t'xmppStatus': " . (CIMMessenger::CheckXmppStatusOnline() ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrix24Status': " . (IsModuleInstalled('bitrix24') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrixIntranet': " . (IsModuleInstalled('intranet') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'bitrixXmpp': " . (IsModuleInstalled('xmpp') ? 'true' : 'false') . ",\n\t\t\t\t\t\t'notify' : {},\n\t\t\t\t\t\t'users' : {},\n\t\t\t\t\t\t'userId': " . $USER->GetID() . ",\n\t\t\t\t\t\t'userEmail': '" . CUtil::JSEscape($USER->GetEmail()) . "',\n\n\t\t\t\t\t\t'openMessenger' : " . (isset($_GET['IM_DIALOG']) ? "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_DIALOG'])) . "'" : 'false') . ",\n\t\t\t\t\t\t'openHistory' : " . (isset($_GET['IM_HISTORY']) ? "'" . CUtil::JSEscape(htmlspecialcharsbx($_GET['IM_HISTORY'])) . "'" : 'false') . ",\n\t\t\t\t\t\t'openSettings' : " . (isset($_GET['IM_SETTINGS']) && $_GET['IM_SETTINGS'] == 'Y' ? "'true'" : 'false') . ",\n\n\t\t\t\t\t\t'disk': {'enable' : '" . ($diskStatus ? 'true' : 'false') . "'},\n\t\t\t\t\t\t'path' : {'profile' : '" . $arTemplate['PATH_TO_USER_PROFILE'] . "', 'profileTemplate' : '" . $arTemplate['PATH_TO_USER_PROFILE_TEMPLATE'] . "', 'mail' : '" . $arTemplate['PATH_TO_USER_MAIL'] . "'}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t";
     }
     return $sJS;
 }