public static function addSignature(&$message, $contentType = 0) { if (!Bitrix24Manager::isEnabled()) { return false; } self::includeLangFile(); $text = ''; if (!Bitrix24Manager::isPaidAccount()) { $text = GetMessage('CRM_B24_EMAIL_FREE_LICENSE_SIGNATURE'); } elseif (self::isSignatureEnabled()) { $text = GetMessage('CRM_B24_EMAIL_PAID_LICENSE_SIGNATURE'); } if ($text === '') { return false; } if (!\CCrmContentType::IsDefined($contentType)) { $contentType = \CCrmContentType::PlainText; } if ($contentType === \CCrmContentType::BBCode) { $message .= "\n\n" . $text; } elseif ($contentType === \CCrmContentType::Html) { //Convert BBCODE to HTML $parser = new \CTextParser(); $message .= "<br/><br/>" . $parser->convertText($text); } elseif ($contentType === \CCrmContentType::PlainText) { $message .= "\n\n" . preg_replace('/\\[[^\\]]+\\]/', '', $text); } return true; }
/** * Method will be invoked after new database record inserted. * * @param array $newRecord All fields of inserted record. * * @return void */ public function afterInsertTrigger(array $newRecord) { $id = intval($newRecord['MESSAGE_ID']); if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } $message = \CIMMessenger::GetById($id, array('WITH_FILES' => 'Y')); if (!$message) { return; } if ($newRecord['PARAM_NAME'] === 'LIKE' && $newRecord["PARAM_VALUE"]) { $like = $message['PARAMS']['LIKE']; $result = \Bitrix\IM\ChatTable::getList(array('filter' => array('=ID' => $message['CHAT_ID']))); $chat = $result->fetch(); $relations = \CIMMessenger::GetRelationById($id); if (!isset($relations[$newRecord["PARAM_VALUE"]])) { return; } if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $newRecord["PARAM_VALUE"]) { $CCTP = new \CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->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"); $message['MESSAGE'] = str_replace('<br />', ' ', $CCTP->convertText($message['MESSAGE'])); $message['MESSAGE'] = preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/\\[[bui]\\](.*?)\\[\\/[bui]\\]/i", "\$1", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", "\$2", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [" . GetMessage('IM_QUOTE') . "] ", str_replace(array("#BR#"), array(" "), $message['MESSAGE'])); if (count($message['FILES']) > 0 && strlen($message['MESSAGE']) < 200) { foreach ($message['FILES'] as $file) { $file = " [" . GetMessage('IM_MESSAGE_FILE') . ": " . $file['name'] . "]"; if (strlen($message['MESSAGE'] . $file) > 200) { break; } $message['MESSAGE'] .= $file; } $message['MESSAGE'] = trim($message['MESSAGE']); } $isChat = $chat && strlen($chat['TITLE']) > 0; $dot = strlen($message['MESSAGE']) >= 200 ? '...' : ''; $message['MESSAGE'] = substr($message['MESSAGE'], 0, 199) . $dot; $message['MESSAGE'] = strlen($message['MESSAGE']) > 0 ? $message['MESSAGE'] : '-'; $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $message['AUTHOR_ID'], "FROM_USER_ID" => $newRecord["PARAM_VALUE"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|IM|" . ($isChat ? 'G' : 'P') . "|" . ($isChat ? $chat['ID'] : $newRecord["PARAM_VALUE"]) . "|" . $id, "NOTIFY_MESSAGE" => GetMessage($isChat ? 'IM_MESSAGE_LIKE' : 'IM_MESSAGE_LIKE_PRIVATE', array('#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $chat['TITLE']))); \CIMNotify::Add($arMessageFields); } $arPullMessage = array('id' => $id, 'chatId' => $relations[$newRecord["PARAM_VALUE"]]['CHAT_ID'], 'senderId' => $newRecord["PARAM_VALUE"], 'users' => $like); foreach ($relations as $rel) { \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage)); } } }
public static function convertHtmlToBbCode($html) { $html = strval($html); if ($html === '') { return ''; } $eventManager = \Bitrix\Main\EventManager::getInstance(); $eventKey = $eventManager->addEventHandlerCompatible("main", "TextParserBeforeTags", array("\\Bitrix\\Crm\\Format\\TextHelper", "onTextParserBeforeTags")); $textParser = new \CTextParser(); $textParser->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "Y", "TABLE" => "Y", "CUT_ANCHOR" => "Y", "ALIGN" => "Y"); $result = $textParser->convertText($html); $result = htmlspecialcharsback($result); $result = preg_replace("/\\<br\\s*\\/*\\>/is" . BX_UTF_PCRE_MODIFIER, "\n", $result); $result = preg_replace("/ /is" . BX_UTF_PCRE_MODIFIER, "", $result); $result = preg_replace("/\\<([^>]*?)>/is" . BX_UTF_PCRE_MODIFIER, "", $result); $result = htmlspecialcharsbx($result); $eventManager->removeEventHandler("main", "TextParserBeforeTags", $eventKey); return $result; }
public function SendUnreadMessages($receiverJId, $domain = "") { $receiverJId = trim($receiverJId); if (strlen($receiverJId) <= 0) { return false; } $receiver = CXMPPUtility::GetUserByJId($receiverJId, $domain); if (!$receiver) { return false; } $factory = CXMPPFactory::GetFactory(); if (IsModuleInstalled("im") && CModule::IncludeModule("im")) { $CIMMessage = new CIMMessage($receiverJId, array('hide_link' => true)); $arMessage = $CIMMessage->GetUnreadMessage(array('SPEED_CHECK' => 'N', 'ORDER' => 'ASC', 'USE_SMILES' => 'N', 'USER_LOAD' => 'N', 'LOAD_DEPARTMENT' => 'N')); if ($arMessage['result']) { foreach ($arMessage['message'] as $id => $arMessage) { $factory->__SendMessage($arMessage["senderId"], $arMessage["recipientId"], $arMessage["id"], IM_MESSAGE_PRIVATE, htmlspecialcharsbx(CTextParser::convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", $arMessage["text"]))), $domain); } } // Notify $CIMNotify = new CIMNotify($receiverJId); $arNotify = $CIMNotify->GetUnreadNotify(array('SPEED_CHECK' => 'N', 'ORDER' => 'ASC')); if ($arNotify['result']) { foreach ($arNotify['original_notify'] as $id => $arNotify) { if (isset($arNotify["NOTIFY_MODULE"]) && isset($arNotify["NOTIFY_EVENT"]) && !CIMSettings::GetNotifyAccess($arNotify["TO_USER_ID"], $arNotify["NOTIFY_MODULE"], $arNotify["NOTIFY_EVENT"], CIMSettings::CLIENT_XMPP)) { continue; } if ($arNotify["MESSAGE_OUT"] == IM_MAIL_SKIP) { $arNotify["MESSAGE_OUT"] = ''; } $factory->__SendMessage($arNotify["FROM_USER_ID"], $arNotify["TO_USER_ID"], $arNotify["ID"], IM_MESSAGE_SYSTEM, htmlspecialcharsbx(CTextParser::convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", strlen($arNotify["MESSAGE_OUT"]) > 0 ? $arNotify["MESSAGE_OUT"] : $arNotify["MESSAGE"]))), $domain); } } } else { $parser = new CSocNetTextParser(); $dbMessages = CSocNetMessages::GetList(array("DATE_CREATE" => "ASC"), array("TO_USER_ID" => $receiver["ID"], "DATE_VIEW" => "", "TO_DELETED" => "N", "IS_LOG_ALL" => "Y"), false, false, array("ID", "FROM_USER_ID", "TO_USER_ID", "MESSAGE", "DATE_VIEW", "MESSAGE_TYPE", "FROM_DELETED", "TO_DELETED", "IS_LOG")); while ($arMessage = $dbMessages->Fetch()) { $factory->__SendMessage($arMessage["IS_LOG"] == "Y" ? -5 : $arMessage["FROM_USER_ID"], $arMessage["TO_USER_ID"], $arMessage["ID"], $arMessage["MESSAGE_TYPE"], htmlspecialcharsbx($parser->convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", $arMessage["MESSAGE"]))), $domain); } } return true; }
public static function GetRecentList($arParams = Array()) { global $DB, $USER; $bLoadUnreadMessage = isset($arParams['LOAD_UNREAD_MESSAGE']) && $arParams['LOAD_UNREAD_MESSAGE'] == 'Y'? true: false; $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N'? false: true; $bSmiles = isset($arParams['USE_SMILES']) && $arParams['USE_SMILES'] == 'N'? false: true; $nameTemplate = COption::GetOptionString("im", "user_name_template", "#LAST_NAME# #NAME#", SITE_ID); $nameTemplateSite = CSite::GetNameFormat(false); $nameOfSite = CModule::IncludeModule('extranet') && !CExtranet::IsIntranetUser()? "ex": false; $bIntranetEnable = IsModuleInstalled('intranet') && CModule::IncludeModule('intranet')? true: false; $arRecent = Array(); $arUsers = Array(); $cache_ttl = 2592000; $cache_id = $GLOBALS['USER']->GetID(); $cache_dir = '/bx/imc/rec'.CIMMessenger::GetCachePath($cache_id); $obCache = new CPHPCache(); if($obCache->InitCache($cache_ttl, $cache_id, $cache_dir)) { $ar = $obCache->GetVars(); $arRecent = $ar['recent']; $arUsers = $ar['users']; } else { if (!$bTimeZone) CTimeZone::Disable(); $strSql = " SELECT R.ITEM_TYPE, R.ITEM_ID, R.ITEM_MID M_ID, M.AUTHOR_ID M_AUTHOR_ID, M.MESSAGE M_MESSAGE, ".$DB->DatetimeToTimestampFunction('M.DATE_CREATE')." M_DATE_CREATE, C.TITLE C_TITLE, C.AUTHOR_ID C_OWNER_ID, U.LOGIN, U.NAME, U.LAST_NAME, U.PERSONAL_PHOTO, U.SECOND_NAME, U.PERSONAL_BIRTHDAY, U.PERSONAL_GENDER FROM b_im_recent R LEFT JOIN b_user U ON R.ITEM_TYPE = '".IM_MESSAGE_PRIVATE."' AND R.ITEM_ID = U.ID LEFT JOIN b_im_chat C ON R.ITEM_TYPE = '".IM_MESSAGE_GROUP."' AND R.ITEM_ID = C.ID LEFT JOIN b_im_message M ON R.ITEM_MID = M.ID WHERE R.USER_ID = ".$USER->GetId(); if (!$bTimeZone) CTimeZone::Enable(); $toDelete = Array(); $CCTP = new CTextParser(); $CCTP->MaxStringLen = 255; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "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"); $dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); while ($arRes = $dbRes->GetNext(true, false)) { $arRes['ITEM_TYPE'] = trim($arRes['ITEM_TYPE']); if ($arRes['M_DATE_CREATE']+2592000 < time()) { $toDelete[$arRes['ITEM_TYPE']][] = $arRes['ITEM_ID']; continue; } $itemId = $arRes['ITEM_ID']; $item = Array( 'TYPE' => $arRes['ITEM_TYPE'], 'MESSAGE' => Array( 'id' => $arRes['M_ID'], 'senderId' => $arRes['M_AUTHOR_ID'], 'date' => $arRes['M_DATE_CREATE'], 'text' => $CCTP->convertText(preg_replace("/\[s\].*?\[\/s\]/i", "", $arRes['M_MESSAGE'])) ) ); $item['MESSAGE']['text'] = preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [".GetMessage('IM_QUOTE')."] ", strip_tags(str_replace(array("<br>","<br/>","<br />", "#BR#"), Array(" "," ", " ", " "), $item['MESSAGE']['text']), "<img>")); if ($arRes['ITEM_TYPE'] == IM_MESSAGE_PRIVATE) { $arUsers[] = $arRes['ITEM_ID']; $arFileTmp = CFile::ResizeImageGet( $arRes["PERSONAL_PHOTO"], array('width' => 58, 'height' => 58), BX_RESIZE_IMAGE_EXACT, false ); $item['USER'] = Array( 'id' => $arRes['ITEM_ID'], 'name' => CUser::FormatName($nameTemplateSite, $arRes, true, false), 'nameList' => CUser::FormatName($nameTemplate, $arRes, true, false), 'avatar' => empty($arFileTmp['src'])? '/bitrix/js/im/images/blank.gif': $arFileTmp['src'], 'gender' => $arRes['PERSONAL_GENDER'] == 'F'? 'F': 'M', 'status' => 'offline', 'birthday' => $arRes['PERSONAL_BIRTHDAY'], 'profile' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('im', 'path_to_user_profile', "", $nameOfSite), array("user_id" => $arRes["ITEM_ID"])) ); } else { $itemId = 'chat'.$itemId; $item['CHAT'] = Array( 'id' => $arRes['ITEM_ID'], 'name' => $arRes["C_TITLE"], 'owner' => $arRes["C_OWNER_ID"], ); } $arRecent[$itemId] = $item; } // remove old entity if (!empty($toDelete)) { if (isset($toDelete[IM_MESSAGE_PRIVATE])) self::DeleteRecent($toDelete[IM_MESSAGE_PRIVATE]); if (isset($toDelete[IM_MESSAGE_GROUP])) self::DeleteRecent($toDelete[IM_MESSAGE_GROUP], true); } if($obCache->StartDataCache()) $obCache->EndDataCache(Array('recent' => $arRecent, 'users' => $arUsers)); } $arOnline = self::GetStatus(Array('ID' => array_values($arUsers))); foreach ($arRecent as $key => $value) { if ($value['TYPE'] != IM_MESSAGE_PRIVATE) continue; $arRecent[$key]['USER']['birthday'] = $bIntranetEnable? CIntranetUtils::IsToday($value['USER']['birthday']): false; $arRecent[$key]['USER']['status'] = isset($arOnline['users'][$value['USER']['id']])? 'online': 'offline'; } if ($bLoadUnreadMessage) { $CIMMessage = new CIMMessage(false, Array( 'hide_link' => true )); $ar = $CIMMessage->GetUnreadMessage(Array( 'LOAD_DEPARTMENT' => 'N', 'ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USE_TIME_ZONE' => $bTimeZone? 'Y': 'N', 'USE_SMILES' => $bSmiles? 'Y': 'N' )); foreach ($ar['message'] as $data) { if (!isset($arRecent[$data['senderId']])) { $arRecent[$data['senderId']] = Array( 'TYPE' => IM_MESSAGE_PRIVATE, 'USER' => $ar['users'][$data['senderId']] ); } $arRecent[$data['senderId']]['MESSAGE'] = Array( 'id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [".GetMessage('IM_QUOTE')."] ", strip_tags(str_replace(array("<br>","<br/>","<br />", "#BR#"), Array(" ", " ", " ", " "), $data['text']), "<img>")) ); $arRecent[$data['senderId']]['COUNTER'] = $data['counter']; } $CIMChat = new CIMChat(false, Array( 'hide_link' => true )); $ar = $CIMChat->GetUnreadMessage(Array( 'ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USER_LOAD' => 'N', 'USE_SMILES' => $bSmiles? 'Y': 'N', 'USE_TIME_ZONE' => $bTimeZone? 'Y': 'N' )); foreach ($ar['message'] as $data) { if (!isset($arRecent['chat'.$data['recipientId']])) { $arRecent['chat'.$data['recipientId']] = Array( 'TYPE' => IM_MESSAGE_GROUP, 'CHAT' => $ar['chat'] ); } $arRecent['chat'.$data['recipientId']]['MESSAGE'] = Array( 'id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => $data['text'] ); $arRecent['chat'.$data['recipientId']]['COUNTER'] = $data['counter']; } } if (!empty($arRecent)) { sortByColumn( $arRecent, array( 'COUNTER' => array(SORT_NUMERIC, SORT_DESC), 'MESSAGE' => array(SORT_NUMERIC, SORT_DESC) ), array( 'COUNTER' => function($counter){ return !is_null($counter); }, 'MESSAGE' => function($recent){ return $recent['date']; } ), null, true ); } return $arRecent; }
public function getDescription($format = self::DESCR_FORMAT_HTML) { $rc = null; $format = intval($format); CTaskAssert::assert(in_array($format, array(self::DESCR_FORMAT_RAW, self::DESCR_FORMAT_HTML, self::DESCR_FORMAT_PLAIN_TEXT), true)); $arTask = $this->getData($bSpecialChars = false); $description = $arTask['DESCRIPTION']; if ($format === self::DESCR_FORMAT_RAW) { return $description; } // Now, convert description to HTML if ($arTask['DESCRIPTION_IN_BBCODE'] === 'Y') { $parser = new CTextParser(); $description = str_replace("\t", ' ', $parser->convertText($description)); } else { $description = CTasksTools::SanitizeHtmlDescriptionIfNeed($description); } if ($format === self::DESCR_FORMAT_HTML) { $rc = $description; } elseif ($format === self::DESCR_FORMAT_PLAIN_TEXT) { $rc = strip_tags(str_replace(array('<br>', '<br/>', '<br />'), "\n", $description)); } else { CTaskAssert::log('CTaskItem->getTaskDescription(): unexpected format: ' . $format, CTaskAssert::ELL_ERROR); CTaskAssert::assert(false); } return $rc; }
if ('Y' == $arParams['CONVERT_CURRENCY']) { if (!CModule::IncludeModule('currency')) { $arParams['CONVERT_CURRENCY'] = 'N'; $arParams['CURRENCY_ID'] = ''; } else { $arCurrencyInfo = CCurrency::GetByID($arParams['CURRENCY_ID']); if (!(is_array($arCurrencyInfo) && !empty($arCurrencyInfo))) { $arParams['CONVERT_CURRENCY'] = 'N'; $arParams['CURRENCY_ID'] = ''; } else { $arParams['CURRENCY_ID'] = $arCurrencyInfo['CURRENCY']; $arConvertParams['CURRENCY_ID'] = $arCurrencyInfo['CURRENCY']; } } } $obParser = new CTextParser(); if (is_array($arParams["PRICE_CODE"])) { $arResult["PRICES"] = CIBlockPriceTools::GetCatalogPrices(0, $arParams["PRICE_CODE"]); } else { $arResult["PRICES"] = array(); } $arSelect = array("ID", "IBLOCK_ID", "PREVIEW_TEXT", "PREVIEW_PICTURE", "DETAIL_PICTURE"); $arFilter = array("IBLOCK_LID" => SITE_ID, "IBLOCK_ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y", "MIN_PERMISSION" => "R"); foreach ($arResult["PRICES"] as $value) { $arSelect[] = $value["SELECT"]; $arFilter["CATALOG_SHOP_QUANTITY_" . $value["ID"]] = 1; } $arFilter["=ID"] = $arResult["ELEMENTS"]; $rsElements = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect); while ($arElement = $rsElements->Fetch()) { $arElement["PRICES"] = CIBlockPriceTools::GetItemPrices($arElement["IBLOCK_ID"], $arResult["PRICES"], $arElement, $arParams['PRICE_VAT_INCLUDE'], $arConvertParams);
public static function killAllTags($text) { if (method_exists("CTextParser", "clearAllTags")) { return CTextParser::clearAllTags($text); } $text = strip_tags($text); $text = preg_replace("#<(/?)quote(.*?)>#is", "", $text); $text = preg_replace("#<(/?)code(.*?)>#is", "", $text); $text = preg_replace("#\\[(/?)(b|u|i|list|code|quote|url|img)(.*?)\\]#is", "", $text); $text = preg_replace("/^(\r|\n)+?(.*)\$/", "\\2", $text); $text = preg_replace("/^<br>+?(.*)\$/", "\\2", $text); return $text; }
public static function GetFormatNotify($arFields) { $CCTP = new CTextParser(); if (isset($arFields['HIDE_LINK']) && $arFields['HIDE_LINK'] == 'Y') $CCTP->allow["ANCHOR"] = "N"; $CCTP->link_target = "_self"; $arNotify = Array( 'id' => $arFields['ID'], 'type' => $arFields['NOTIFY_TYPE'], 'date' => $arFields['DATE_CREATE'], 'silent' => $arFields['NOTIFY_SILENT']? 'Y': 'N', 'text' => str_replace('#BR#', '<br>', $CCTP->convertText($arFields['MESSAGE'])), 'tag' => strlen($arFields['NOTIFY_TAG'])>0? md5($arFields['NOTIFY_TAG']): '', 'original_tag' => $arFields['NOTIFY_TAG'], 'settingName' => $arFields['NOTIFY_MODULE'].'|'.$arFields['NOTIFY_EVENT'] ); if (!isset($arFields["FROM_USER_DATA"])) { $arUsers = CIMContactList::GetUserData(Array('ID' => $arFields['FROM_USER_ID'], 'DEPARTMENT' => 'N', 'USE_CACHE' => 'Y', 'CACHE_TTL' => 86400)); $arFields["FROM_USER_DATA"] = $arUsers['users']; } $arNotify['userId'] = $arFields["FROM_USER_ID"]; $arNotify['userName'] = $arFields["FROM_USER_DATA"][$arFields["FROM_USER_ID"]]['name']; $arNotify['userAvatar'] = $arFields["FROM_USER_DATA"][$arFields["FROM_USER_ID"]]['avatar']; $arNotify['userLink'] = $arFields["FROM_USER_DATA"][$arFields["FROM_USER_ID"]]['profile']; if ($arFields['NOTIFY_TYPE'] == IM_NOTIFY_CONFIRM) { $arNotify['buttons'] = unserialize($arFields['NOTIFY_BUTTONS']); } else { $arNotify['title'] = htmlspecialcharsbx($arFields['NOTIFY_TITLE']); } return $arNotify; }
public static function GetRecentList($arParams = array()) { global $DB, $USER; $bLoadUnreadMessage = isset($arParams['LOAD_UNREAD_MESSAGE']) && $arParams['LOAD_UNREAD_MESSAGE'] == 'Y' ? true : false; $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N' ? false : true; $bSmiles = isset($arParams['USE_SMILES']) && $arParams['USE_SMILES'] == 'N' ? false : true; $userId = isset($arParams['USER_ID']) ? $arParams['USER_ID'] : $USER->GetId(); $nameTemplate = self::GetUserNameTemplate(SITE_ID); $nameTemplateSite = CSite::GetNameFormat(false); $bIntranetEnable = IsModuleInstalled('intranet') && CModule::IncludeModule('intranet') ? true : false; $arRecent = array(); $arUsers = array(); $bColorEnabled = IM\Color::isEnabled(); $cache_ttl = 2592000; $cache_id = 'im_recent_v8_' . $userId . '_' . $bColorEnabled; $cache_dir = '/bx/imc/recent' . CIMMessenger::GetCachePath($userId); $obCache = new CPHPCache(); if ($obCache->InitCache($cache_ttl, $cache_id, $cache_dir)) { $ar = $obCache->GetVars(); $arRecent = $ar['recent']; $arUsers = $ar['users']; } else { if (!$bTimeZone) { CTimeZone::Disable(); } $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tR.ITEM_TYPE, R.ITEM_ID,\n\t\t\t\t\tR.ITEM_MID M_ID, M.AUTHOR_ID M_AUTHOR_ID, M.ID M_ID, M.CHAT_ID M_CHAT_ID, M.MESSAGE M_MESSAGE, " . $DB->DatetimeToTimestampFunction('M.DATE_CREATE') . " M_DATE_CREATE,\n\t\t\t\t\tC.TITLE C_TITLE, C.AUTHOR_ID C_OWNER_ID, C.ENTITY_TYPE C_ENTITY_TYPE, C.AVATAR C_AVATAR, C.CALL_NUMBER C_CALL_NUMBER, C.EXTRANET CHAT_EXTRANET, C.COLOR CHAT_COLOR, C.TYPE CHAT_TYPE,\n\t\t\t\t\tU.LOGIN, U.NAME, U.LAST_NAME, U.PERSONAL_PHOTO, U.SECOND_NAME, U.PERSONAL_BIRTHDAY, U.PERSONAL_GENDER, U.EXTERNAL_AUTH_ID, U.WORK_POSITION,\n\t\t\t\t\tC1.USER_ID RID\n\t\t\t\tFROM\n\t\t\t\tb_im_recent R\n\t\t\t\tLEFT JOIN b_user U ON R.ITEM_TYPE = '" . IM_MESSAGE_PRIVATE . "' AND R.ITEM_ID = U.ID\n\t\t\t\tLEFT JOIN b_im_chat C ON R.ITEM_TYPE != '" . IM_MESSAGE_PRIVATE . "' AND R.ITEM_ID = C.ID\n\t\t\t\tLEFT JOIN b_im_message M ON R.ITEM_MID = M.ID\n\t\t\t\tLEFT JOIN b_im_relation C1 ON C1.CHAT_ID = C.ID AND C1.USER_ID = " . $userId . "\n\t\t\t\tWHERE R.USER_ID = " . $userId; if (!$bTimeZone) { CTimeZone::Enable(); } $toDelete = array(); $arMessageId = array(); $CCTP = new CTextParser(); $CCTP->MaxStringLen = 255; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "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"); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->GetNext(true, false)) { $arRes['ITEM_TYPE'] = trim($arRes['ITEM_TYPE']); if ($arRes['ITEM_TYPE'] == IM_MESSAGE_OPEN) { if (intval($arRes['RID']) <= 0 && IM\User::getInstance($userId)->isExtranet()) { continue; } } else { if ($arRes['ITEM_TYPE'] == IM_MESSAGE_CHAT) { if (intval($arRes['RID']) <= 0) { continue; } } } $arMessageId[] = $arRes['M_ID']; if ($arRes['M_DATE_CREATE'] + 2592000 < time()) { $toDelete[$arRes['ITEM_TYPE']][] = $arRes['ITEM_ID']; continue; } $itemId = $arRes['ITEM_ID']; $item = array('TYPE' => $arRes['ITEM_TYPE'], 'MESSAGE' => array('id' => $arRes['M_ID'], 'chatId' => $arRes['M_CHAT_ID'], 'senderId' => $arRes['M_AUTHOR_ID'], 'date' => $arRes['M_DATE_CREATE'], 'text' => $CCTP->convertText(preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $arRes['M_MESSAGE'])))); $item['MESSAGE']['text'] = preg_replace('#\\-{54}.+?\\-{54}#s', " [" . GetMessage('IM_QUOTE') . "] ", strip_tags(str_replace(array("<br>", "<br/>", "<br />", "#BR#"), array(" ", " ", " ", " "), $item['MESSAGE']['text']), "<img>")); if ($arRes['ITEM_TYPE'] == IM_MESSAGE_PRIVATE) { $arUsers[] = $arRes['ITEM_ID']; $arFileTmp = CFile::ResizeImageGet($arRes["PERSONAL_PHOTO"], array('width' => 58, 'height' => 58), BX_RESIZE_IMAGE_EXACT, false, false, true); $item['USER'] = array('id' => $arRes['ITEM_ID'], 'name' => CUser::FormatName($nameTemplateSite, $arRes, true, false), 'nameList' => CUser::FormatName($nameTemplate, $arRes, true, false), 'workPosition' => $arRes['WORK_POSITION'], 'color' => self::GetUserColor($arRes["ID"], $arRes['PERSONAL_GENDER'] == 'M' ? 'M' : 'F'), 'avatar' => empty($arFileTmp['src']) ? '/bitrix/js/im/images/blank.gif' : $arFileTmp['src'], 'status' => 'offline', 'birthday' => $arRes['PERSONAL_BIRTHDAY'], 'gender' => $arRes['PERSONAL_GENDER'] == 'F' ? 'F' : 'M', 'extranet' => false, 'network' => $arRes['EXTERNAL_AUTH_ID'] == self::NETWORK_AUTH_ID, 'phoneDevice' => false, 'profile' => CIMContactList::GetUserPath($arRes["ITEM_ID"])); } else { $chatType = $arRes["ITEM_TYPE"] == IM_MESSAGE_OPEN ? 'open' : 'chat'; if ($arRes["C_ENTITY_TYPE"] == 'CALL') { $chatType = 'call'; } $itemId = 'chat' . $itemId; $item['CHAT'] = array('id' => $arRes['ITEM_ID'], 'name' => $arRes["C_TITLE"], 'color' => $arRes["CHAT_COLOR"] == "" ? IM\Color::getColorByNumber($arRes['ITEM_ID']) : IM\Color::getColor($arRes['CHAT_COLOR']), 'avatar' => CIMChat::GetAvatarImage($arRes["C_AVATAR"]), 'extranet' => $arRes["CHAT_EXTRANET"] == "" ? "" : ($arRes["CHAT_EXTRANET"] == "Y" ? true : false), 'owner' => $arRes["C_OWNER_ID"], 'type' => $chatType, 'messageType' => $arRes['CHAT_TYPE'], 'call_number' => $arRes["C_CALL_NUMBER"]); } $arRecent[$itemId] = $item; } $params = CIMMessageParam::Get($arMessageId); foreach ($arRecent as $key => $value) { if (isset($params[$value['MESSAGE']['id']])) { if (count($params[$value['MESSAGE']['id']]['FILE_ID']) > 0 && strlen(trim($arRecent[$key]['MESSAGE']['text'])) <= 0) { $arRecent[$key]['MESSAGE']['text'] = "[" . GetMessage('IM_FILE') . "]"; } $arRecent[$key]['MESSAGE']['params'] = $params[$value['MESSAGE']['id']]; } } if (!empty($toDelete)) { if (isset($toDelete[IM_MESSAGE_PRIVATE])) { self::DeleteRecent($toDelete[IM_MESSAGE_PRIVATE]); } if (isset($toDelete[IM_MESSAGE_CHAT])) { self::DeleteRecent($toDelete[IM_MESSAGE_CHAT], true); } if (isset($toDelete[IM_MESSAGE_OPEN])) { self::DeleteRecent($toDelete[IM_MESSAGE_OPEN], true); } } $bExtranetEnable = IsModuleInstalled('extranet'); $bVoximplantEnable = IsModuleInstalled('voximplant'); if ($bExtranetEnable || $bVoximplantEnable) { $arUserPhone = array(); $arUserDepartment = array(); $arSelectParams = array(); if ($bExtranetEnable) { $arSelectParams[] = 'UF_DEPARTMENT'; } if ($bVoximplantEnable) { $arSelectParams[] = 'UF_VI_PHONE'; } $dbUsers = CUser::GetList($sort_by = array('last_name' => 'asc'), $dummy = '', array('ID' => $userId . "|" . implode('|', $arUsers)), array('FIELDS' => array("ID"), 'SELECT' => $arSelectParams)); while ($arUser = $dbUsers->GetNext(true, false)) { $arUserPhone[$arUser['ID']] = $arUser['UF_VI_PHONE'] == 'Y'; $arUserDepartment[$arUser['ID']] = self::IsExtranet($arUser); } foreach ($arRecent as $key => $value) { if (isset($value['USER'])) { $arRecent[$key]['USER']['extranet'] = $arUserDepartment[$value['USER']['id']]; $arRecent[$key]['USER']['phoneDevice'] = $arUserPhone[$value['USER']['id']]; } } } if ($obCache->StartDataCache()) { $obCache->EndDataCache(array('recent' => $arRecent, 'users' => $arUsers)); } } $arOnline = CIMStatus::GetList(array('ID' => array_values($arUsers), 'GET_OFFLINE' => 'Y')); foreach ($arRecent as $key => $value) { if ($value['TYPE'] != IM_MESSAGE_PRIVATE) { continue; } $arRecent[$key]['USER']['birthday'] = $bIntranetEnable ? CIntranetUtils::IsToday($value['USER']['birthday']) : false; $arRecent[$key]['USER']['status'] = isset($arOnline['users'][$value['USER']['id']]) ? $arOnline['users'][$value['USER']['id']]['status'] : 'offline'; $arRecent[$key]['USER']['idle'] = isset($arOnline['users'][$value['USER']['id']]) ? $arOnline['users'][$value['USER']['id']]['idle'] : 0; $arRecent[$key]['USER']['mobileLastDate'] = isset($arOnline['users'][$value['USER']['id']]) ? $arOnline['users'][$value['USER']['id']]['mobileLastDate'] : 0; if ($arOnline['users'][$value['USER']['id']]['color']) { $arRecent[$key]['USER']['color'] = $arOnline['users'][$value['USER']['id']]['color']; } } if ($bLoadUnreadMessage) { $CIMMessage = new CIMMessage(false, array('HIDE_LINK' => 'Y')); $ar = $CIMMessage->GetUnreadMessage(array('LOAD_DEPARTMENT' => 'N', 'ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USE_TIME_ZONE' => $bTimeZone ? 'Y' : 'N', 'USE_SMILES' => $bSmiles ? 'Y' : 'N')); foreach ($ar['message'] as $data) { if (!isset($arRecent[$data['senderId']])) { $arRecent[$data['senderId']] = array('TYPE' => IM_MESSAGE_PRIVATE, 'USER' => $ar['users'][$data['senderId']]); } $arRecent[$data['senderId']]['MESSAGE'] = array('id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => preg_replace('#\\-{54}.+?\\-{54}#s', " [" . GetMessage('IM_QUOTE') . "] ", strip_tags(str_replace(array("<br>", "<br/>", "<br />", "#BR#"), array(" ", " ", " ", " "), $data['text']), "<img>"))); $arRecent[$data['senderId']]['COUNTER'] = $data['counter']; } $CIMChat = new CIMChat(false, array('HIDE_LINK' => 'Y')); $ar = $CIMChat->GetUnreadMessage(array('ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USER_LOAD' => 'N', 'FILE_LOAD' => 'N', 'USE_SMILES' => $bSmiles ? 'Y' : 'N', 'USE_TIME_ZONE' => $bTimeZone ? 'Y' : 'N')); foreach ($ar['message'] as $data) { if (!isset($arRecent['chat' . $data['recipientId']])) { $arRecent['chat' . $data['recipientId']] = array('TYPE' => $ar['messageType'] ? $ar['messageType'] : IM_MESSAGE_CHAT, 'CHAT' => $ar['chat']); } $arRecent['chat' . $data['recipientId']]['MESSAGE'] = array('id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => $data['text']); $arRecent['chat' . $data['recipientId']]['COUNTER'] = $data['counter']; } } if (!empty($arRecent)) { sortByColumn($arRecent, array('COUNTER' => array(SORT_NUMERIC, SORT_DESC), 'MESSAGE' => array(SORT_NUMERIC, SORT_DESC)), array('COUNTER' => array(__CLASS__, 'GetRecentListSortCounter'), 'MESSAGE' => array(__CLASS__, 'GetRecentListSortMessage')), null, true); } return $arRecent; }
CIMContactList::SetOnline(); CIMMessenger::SetCurrentTab($_POST['TAB']); } else if ($_POST['IM_EDIT_MESSAGE'] == 'Y') { CUtil::decodeURIComponent($_POST); if(!CIMMessenger::Update($_POST['ID'], $_POST['MESSAGE'])) { $arResult = Array( 'ERROR' => 'CANT_EDIT_MESSAGE' ); } else { $CCTP = new CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $userTzOffset = isset($_POST['USER_TZ_OFFSET'])? intval($_POST['USER_TZ_OFFSET']): CTimeZone::GetOffset(); $arResult = Array( 'ID' => $insertID, 'MESSAGE' => $CCTP->convertText(htmlspecialcharsbx($_POST['MESSAGE'])), 'DATE' => time()+$userTzOffset, 'ERROR' => '' ); } echo CUtil::PhpToJsObject($arResult); }
/** * [ID] => 2 [UF_CODE] => pena-dney-20160409004500-0300 [UF_DATE_START] => 09.04.2016 00:45:00 [UF_DATE_END] => 09.04.2016 03:10:00 [UF_DATE] => 09.04.2016 [UF_CHANNEL_ID] => 30 [UF_PROG_ID] => 2 [UF_TITLE] => Пена дней [UF_SUB_TITLE] => [UF_IMG_PATH] => /upload/epg_original/48870.jpg [UF_RATING] => [DATE_START] => 09.04.2016 00:45:00 [DATE_END] => 09.04.2016 03:10:00 [DATE] => 09.04.2016 [PROG_ID] => 2 [DETAIL_PAGE_URL] => /channels/1tv/pena-dney-20160409004500-0300/ [UF_HD] => 1 */ public static function getProgInfoChannel($arProg, $arParams) { if ($arProg["CLASS"] == "one") { $arProg["PICTURE"]["SRC"] = \Hawkart\Megatv\CFile::getCropedPath($arProg["UF_IMG_PATH"], array(600, 550)); } if ($arProg["CLASS"] == "half") { $arProg["PICTURE"]["SRC"] = \Hawkart\Megatv\CFile::getCropedPath($arProg["UF_IMG_PATH"], array(300, 550)); } $start = $arProg["DATE_START"]; $end = $arProg["DATE_END"]; $arStatus = self::status($arProg); $status = $arStatus["status"]; $status_icon = $arStatus["status-icon"]; $datetime = $arParams["DATETIME"]["SERVER_DATETIME_WITH_OFFSET"]; $time_pointer = false; if (\CTimeEx::dateDiff($start, $datetime) && \CTimeEx::dateDiff($datetime, $end)) { $time_pointer = true; } ob_start(); ?> <div class="item<?php if ($status) { ?> status-<?php echo $status; } if ($time_pointer && $arParams["NEED_POINTER"]) { ?> js-time-pointer<?php } if (empty($arProg["PICTURE"]["SRC"])) { ?> is-noimage<?php } if ($arProg["CLASS"] == "double") { ?> double-item<?php } ?> " data-type="broadcast" data-broadcast-id="<?php echo $arProg["ID"]; ?> " > <div class="item-image-holder"> <img data-src="<?php echo $arProg["PICTURE"]["SRC"]; ?> " alt=""> </div> <?php if ($time_pointer) { ?> <span class="badge" data-channel-id="<?php echo $arProg["UF_CHANNEL_ID"]; ?> ">в эфире</span> <?php } ?> <?php echo $status_icon; ?> <?php echo self::driveNotifyMessage(); ?> <div class="item-header"> <time><?php echo substr($arProg["DATE_START"], 11, 5); ?> </time> <a href="<?php echo $arProg["DETAIL_PAGE_URL"]; ?> "> <?php echo self::cutName(\Hawkart\Megatv\ProgTable::getName($arProg)); ?> </a> </div> <div class="item-header"> <?php if (\CTimeEx::dateDiff($start, $datetime) && \CTimeEx::dateDiff($datetime, $end)) { ?> <?php $allSecs = strtotime($end) - strtotime($start); $secs = strtotime($datetime) - strtotime($start); $proc = ceil($secs / ($allSecs / 100)); $duration = \CTimeEx::secToStr($secs); ?> <div class="timeline" data-progress="<?php echo $proc; ?> "> <span class="progress-bg"></span> <span>прошло <?php echo $duration; ?> </span> </div> <?php } ?> <span class="descr-trigger" data-type="descr-trigger"><span>×</span></span> <time><?php echo substr($arProg["DATE_START"], 11, 5); ?> </time> <a href="<?php echo $arProg["DETAIL_PAGE_URL"]; ?> "> <?php echo self::cutName(\Hawkart\Megatv\ProgTable::getName($arProg)); ?> </a> <div class="item-descr"> <?php $obParser = new \CTextParser(); ?> <p><?php echo $obParser->html_cut($arProg["UF_DESC"], 600); ?> </p> </div> </div> </div> <?php $content = ob_get_contents(); ob_end_clean(); return $content; }
/** * WARNING! This method is transitional and can be changed without * any notifications! Don't use it. * * @deprecated */ public static function __deprecated_Add($commentText, $forumTopicId, $forumId, $nameTemplate, $arTask, $permissions, $commentId, $givenUserId, $imageWidth, $imageHeight, $arSmiles, $arForum, $messagesPerPage, $arUserGroupArray, $backPage, $strMsgAddComment, $strMsgEditComment, $strMsgNewTask, $componentName, &$outForumTopicId, &$arErrorCodes, &$outStrUrl, $arFieldsAdditional) { global $DB; if (is_array($arTask)) { if (!array_key_exists('~TITLE', $arTask)) { $arTmpTask = $arTask; foreach ($arTmpTask as $key => $value) { if (substr($key, 0, 1) !== '~') { $arTask['~' . $key] = $arTmpTask[$key]; } } } } $MID = 0; $TID = 0; if ($forumTopicId > 0 && CForumTopic::GetByID($forumTopicId) === false) { $forumTopicId = false; } if ($forumTopicId <= 0) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim(CUser::FormatName($nameTemplate, $res)) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arFields = array("TITLE" => $arTask["~TITLE"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions, "NAME_TEMPLATE" => $nameTemplate, 'XML_ID' => 'TASK_' . $arTask['ID']); $TID = CForumTopic::Add($arFields); if (intVal($TID) <= 0) { $arErrorCodes[] = array('code' => 'topic is not created'); } else { $arFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arFields); } if (!empty($arErrorCodes)) { $DB->Rollback(); return false; } else { $DB->Commit(); } } $arFieldsG = array("POST_MESSAGE" => $commentText, "AUTHOR_NAME" => '', "AUTHOR_EMAIL" => $GLOBALS['USER']->GetEmail(), "USE_SMILES" => NULL, "PARAM2" => $arTask['ID'], "TITLE" => $arTask["~TITLE"], "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions); // UF_* forwarding if (is_array($arFieldsAdditional)) { foreach ($arFieldsAdditional as $field => $value) { if (strlen($field) && substr($field, 0, 3) == 'UF_') { $arFieldsG[$field] = $value; $GLOBALS[$field] = $value; // strange behaviour required for ForumMessageAdd() to handle UF_* properly } } } if (!empty($_FILES["REVIEW_ATTACH_IMG"])) { $arFieldsG["ATTACH_IMG"] = $_FILES["REVIEW_ATTACH_IMG"]; } else { $arFiles = array(); if (!empty($_REQUEST["FILES"])) { foreach ($_REQUEST["FILES"] as $key) { $arFiles[$key] = array("FILE_ID" => $key); if (!in_array($key, $_REQUEST["FILES_TO_UPLOAD"])) { $arFiles[$key]["del"] = "Y"; } } } if (!empty($_FILES)) { $res = array(); foreach ($_FILES as $key => $val) { if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) { $arFiles[] = $_FILES[$key]; } } } if (!empty($arFiles)) { $arFieldsG["FILES"] = $arFiles; } } $TOPIC_ID = $forumTopicId > 0 ? $forumTopicId : $TID; $MESSAGE_ID = 0; $MESSAGE_TYPE = $TOPIC_ID > 0 ? "REPLY" : "NEW"; if (COption::GetOptionString("tasks", "task_comment_allow_edit") && ($MESSAGE_ID = intval($commentId))) { $MESSAGE_TYPE = "EDIT"; } $strErrorMessage = ''; $strOKMessage = ''; $MID = ForumAddMessage($MESSAGE_TYPE, $forumId, $TOPIC_ID, $MESSAGE_ID, $arFieldsG, $strErrorMessage, $strOKMessage, false, $_POST["captcha_word"], 0, $_POST["captcha_code"], $nameTemplate); if ($MID <= 0 || !empty($strErrorMessage)) { $arErrorCodes[] = array('code' => 'message is not added 2', 'title' => empty($strErrorMessage) ? NULL : $strErrorMessage); } else { $arMessage = CForumMessage::GetByID($MID); if ($forumTopicId <= 0) { $forumTopicId = $TID = intVal($arMessage["TOPIC_ID"]); } $outForumTopicId = intVal($forumTopicId); if ($componentName !== null) { ForumClearComponentCache($componentName); } // NOTIFICATION $arTask["ACCOMPLICES"] = $arTask["AUDITORS"] = array(); $rsMembers = CTaskMembers::GetList(array(), array("TASK_ID" => $arTask["ID"])); while ($arMember = $rsMembers->Fetch()) { if ($arMember["TYPE"] == "A") { $arTask["ACCOMPLICES"][] = $arMember["USER_ID"]; } elseif ($arMember["TYPE"] == "U") { $arTask["AUDITORS"][] = $arMember["USER_ID"]; } } $arEmailUserIDs = array($arTask["RESPONSIBLE_ID"], $arTask["CREATED_BY"]); $arEmailUserIDs = array_unique(array_merge($arEmailUserIDs, $arTask["ACCOMPLICES"], $arTask["AUDITORS"])); $currentUserPos = array_search($givenUserId, $arEmailUserIDs); if ($currentUserPos !== false) { unset($arEmailUserIDs[$currentUserPos]); } $parser = new CTextParser(); $parser->imageWidth = $imageWidth; $parser->imageHeight = $imageHeight; $parser->smiles = $arSmiles; $parser->allow = array("HTML" => $arForum["ALLOW_HTML"], "ANCHOR" => $arForum["ALLOW_ANCHOR"], "BIU" => $arForum["ALLOW_BIU"], "IMG" => "N", "VIDEO" => "N", "LIST" => $arForum["ALLOW_LIST"], "QUOTE" => $arForum["ALLOW_QUOTE"], "CODE" => $arForum["ALLOW_CODE"], "FONT" => $arForum["ALLOW_FONT"], "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => $arForum["ALLOW_NL2BR"], "TABLE" => "Y"); $arAllow = NULL; $MESSAGE = HTMLToTxt($parser->convertText($commentText, $arAllow)); // remove [ url] for socialnetwork log $MESSAGE = preg_replace("/(\\s\\[\\s(http:\\/\\/|https:\\/\\/|ftp:\\/\\/))(.*?)(\\s\\])/is", "", $MESSAGE); $parser->allow = array("HTML" => 'Y', "ANCHOR" => 'Y', "BIU" => 'Y', "IMG" => "Y", "VIDEO" => "Y", "LIST" => 'N', "QUOTE" => 'Y', "CODE" => 'Y', "FONT" => 'Y', "SMILES" => "N", "UPLOAD" => 'N', "NL2BR" => 'N', "TABLE" => "Y"); $message_notify = $parser->convertText($commentText); $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); // Instant Messages if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { $pageNumber = CForumMessage::GetMessagePage($MID, $messagesPerPage, $arUserGroupArray); // There are different links for extranet users $isExtranetEnabled = false; if (CModule::IncludeModule("extranet")) { $isExtranetEnabled = true; } if ($isExtranetEnabled) { $arSites = array(); $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { if (strlen(trim($arSite["DIR"])) > 0) { $arSites[$arSite['ID']]['DIR'] = $arSite['DIR']; } else { $arSites[$arSite['ID']]['DIR'] = '/'; } if (strlen(trim($arSite["SERVER_NAME"])) > 0) { $arSites[$arSite['ID']]['SERVER_NAME'] = $arSite["SERVER_NAME"]; } else { $arSites[$arSite['ID']]['SERVER_NAME'] = COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"]); } $arSites[$arSite['ID']]['urlPrefix'] = $arSites[$arSite['ID']]['SERVER_NAME'] . $arSites[$arSite['ID']]['DIR']; // remove last '/' if (strlen($arSites[$arSite['ID']]['urlPrefix']) > 0 && substr($arSites[$arSite['ID']]['urlPrefix'], -1) === '/') { $arSites[$arSite['ID']]['urlPrefix'] = substr($arSites[$arSite['ID']]['urlPrefix'], 0, -1); } } $extranet_site_id = CExtranet::GetExtranetSiteID(); $intranet_site_id = CSite::GetDefSite(); $arIntranetUsers = CExtranet::GetIntranetUsers(); } else { if ($arTask["GROUP_ID"]) { $pathTemplateWoExtranet = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"])); } else { $pathTemplateWoExtranet = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"]); } } foreach ($arRecipientsIDs as $userID) { $urlPrefixForUser = tasksServerName(); if ($isExtranetEnabled) { if (!in_array($userID, $arIntranetUsers) && $extranet_site_id) { $userSiteId = $extranet_site_id; } else { $userSiteId = $intranet_site_id; } if (isset($arSites[$userSiteId]['SERVER_NAME'])) { $urlPrefixForUser = tasksServerName($arSites[$userSiteId]['SERVER_NAME']); } if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace('#group_id#', $arTask['GROUP_ID'], CTasksTools::GetOptionPathTaskGroupEntry($userSiteId, '')); } else { $pathTemplate = CTasksTools::GetOptionPathTaskUserEntry($userSiteId, ''); } } else { $pathTemplate = $pathTemplateWoExtranet; } $NOTIFY_MESSAGE_TITLE_TEMPLATE = ''; $messageUrl = ''; if (strlen($pathTemplate) > 0) { $groupId = 0; if (isset($arTask['GROUP_ID'])) { $groupId = (int) $arTask['GROUP_ID']; } $messageUrl = $urlPrefixForUser . CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $userID, "task_id" => $arTask["ID"], "action" => "view", "USER_ID" => $userID, "TASK_ID" => $arTask["ID"], "ACTION" => "view", 'GROUP_ID' => $groupId, 'group_id' => $groupId)); if ($pageNumber > 1) { $messageUrl .= (strpos($messageUrl, "?") === false ? "?" : "&") . "MID=" . $MID; } $NOTIFY_MESSAGE_TITLE_TEMPLATE = '[URL=' . $messageUrl . "#message" . $MID . ']' . $arTask["~TITLE"] . '[/URL]'; } else { $NOTIFY_MESSAGE_TITLE_TEMPLATE = $arTask["~TITLE"]; } $MESSAGE_SITE = trim(htmlspecialcharsbx(strip_tags(str_replace(array("\r\n", "\n", "\r"), ' ', htmlspecialcharsback($message_notify))))); $MESSAGE_EMAIL = $MESSAGE_SITE; // full message to email if (strlen($MESSAGE_SITE) >= 100) { $dot = '...'; $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99); if (($lastLinkPosition = strrpos($MESSAGE_SITE, 'http://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'https://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftp://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftps://')) !== false) { if (strpos($MESSAGE_SITE, ' ', $lastLinkPosition) === false) { $MESSAGE_SITE = substr($MESSAGE_SITE, 0, $lastLinkPosition); } } $MESSAGE_SITE .= $dot; } $arMessageFields = array("TO_USER_ID" => $userID, "FROM_USER_ID" => $givenUserId, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($NOTIFY_MESSAGE_TITLE_TEMPLATE, '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($arTask["~TITLE"], $MESSAGE_EMAIL . ' #BR# ' . $messageUrl . "#message" . $MID . ' '), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment)); CIMNotify::Add($arMessageFields); } } $strURL = !empty($backPage) ? $backPage : $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result")); $strURL = ForumAddPageParams($strURL, array("MID" => $MID, "result" => $arForum["MODERATION"] != "Y" || CForumNew::CanUserModerateForum($forumId, $arUserGroupArray) ? "reply" : "not_approved"), false, false); $outStrUrl = $strURL; // sonet log if (CModule::IncludeModule("socialnetwork")) { $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID")); if ($arRes = $dbRes->Fetch()) { $log_id = $arRes["TMP_ID"]; $entity_type = $arRes["ENTITY_TYPE"]; $entity_id = $arRes["ENTITY_ID"]; } else { $entity_type = $arTask["GROUP_ID"] ? SONET_ENTITY_GROUP : SONET_ENTITY_USER; $entity_id = $arTask["GROUP_ID"] ? $arTask["GROUP_ID"] : $arTask["CREATED_BY"]; $rsUser = CUser::GetByID($arTask["CREATED_BY"]); if ($arUser = $rsUser->Fetch()) { $arSoFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks", "LOG_DATE" => $arTask["CREATED_DATE"], "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => htmlspecialcharsBack($arTask["~TITLE"]), "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $arTask["ID"], "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]), "PARAMS" => serialize(array("TYPE" => "create"))); $log_id = CSocNetLog::Add($arSoFields, false); if (intval($log_id) > 0) { CSocNetLog::Update($log_id, array("TMP_ID" => $log_id)); $arRights = CTaskNotifications::__UserIDs2Rights(CTaskNotifications::GetRecipientsIDs($arTask, false)); if ($arTask["GROUP_ID"]) { $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"]; } CSocNetLogRights::Add($log_id, $arRights); } } } if (intval($log_id) > 0) { $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]; CSocNetLog::Update($log_id, array('PARAMS' => serialize(array('TYPE' => 'comment')))); $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "tasks", "SOURCE_ID" => $MID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $MID); if ($MESSAGE_TYPE == "EDIT") { $dbRes = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => array("tasks_comment"), "SOURCE_ID" => $MID), false, false, array("ID")); while ($arRes = $dbRes->Fetch()) { CSocNetLogComments::Update($arRes["ID"], $arFieldsForSocnet); } } else { $arFieldsForSocnet['USER_ID'] = $givenUserId; $arFieldsForSocnet['=LOG_DATE'] = $GLOBALS['DB']->CurrentTimeFunction(); $ufFileID = array(); $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $MID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } if (count($ufFileID) > 0) { $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $MID, LANGUAGE_ID); if ($ufDocID) { $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID; } $ufDocVer = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_VER", $MID, LANGUAGE_ID); if ($ufDocVer) { $arFieldsForSocnet["UF_SONET_COM_VER"] = $ufDocVer; } $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); CSocNetLog::CounterIncrement($comment_id, false, false, "LC"); } } } $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $arMessage["AUTHOR_ID"] ? $arMessage["AUTHOR_ID"] : 1; } // Tasks log $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arMessage["EDIT_DATE"] ? ConvertTimeStamp(MakeTimeStamp($arMessage["EDIT_DATE"], CSite::GetDateFormat()), "FULL") : $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $MID); $log = new CTaskLog(); $log->Add($arLogFields); } return $MID; // Message id }
$arResult["FIELDS_FORMATTED"][$key] = $oFormat->showField($arField); } } $arResult["DATE_WEEK_DAY"] = FormatDate("D", MakeTimeStamp($arParams["~ACTIVITY"]["START_END_TIME"])); $arResult["DATE_MONTH_DAY"] = FormatDate("j", MakeTimeStamp($arParams["~ACTIVITY"]["START_END_TIME"])); $arResult["IS_COMPLETED"] = $arParams["~ACTIVITY"]["COMPLETED"] == "Y"; if (!empty($arParams["ACTIVITY"]["DESCRIPTION"])) { switch ($arParams["ACTIVITY"]["DESCRIPTION_TYPE"]) { case CCrmContentType::BBCode: $arResult["DESCRIPTION"] = CCrmLiveFeedComponent::ParseText(htmlspecialcharsback($arParams["ACTIVITY"]["DESCRIPTION"]), array(), array()); break; case CCrmContentType::Html: $convertedText = htmlspecialcharsback($arParams["ACTIVITY"]["DESCRIPTION"]); $convertedText = preg_replace('/<br\\s*\\/*>/i', '#TMPBR#', $convertedText); $convertedText = preg_replace('/<\\/p>/i', '#TMPBR#', $convertedText); $convertedText = CTextParser::clearAllTags($convertedText); $convertedText = str_replace('#TMPBR#', '<br>', $convertedText); $arResult["DESCRIPTION"] = $convertedText; break; default: $arResult["DESCRIPTION"] = $arParams["ACTIVITY"]["DESCRIPTION"]; } } else { $arResult["DESCRIPTION"] = $arParams["ACTIVITY"]["DESCRIPTION"]; } if (count($arActivity["COMMUNICATIONS"]) > 1) { $arResult["COMMUNICATION_MORE_CNT"] = count($arActivity["COMMUNICATIONS"]) - 1; $arResult["CLIENTS_FOR_JS"] = array(); $i = 0; foreach ($arActivity["COMMUNICATIONS"] as $arCommunication) { $i++;
function __getRow($arRes, $listName, &$last_change) { global $APPLICATION, $USER; static $tzOffset = null; if ($tzOffset === null) { $tzOffset = CTasksTools::getTimeZoneOffset(); } // Make correct unix timestamp $change = MakeTimeStamp($arRes['CHANGED_DATE']) - $tzOffset; if ($last_change < $change) { $last_change = $change; } $obRow = new CXMLCreator('z:row'); $obRow->setAttribute('ows_ID', $arRes['ID']); $version = $arRes['OUTLOOK_VERSION'] ? $arRes['OUTLOOK_VERSION'] : 1; if (is_array($arRes['FILES']) && count($arRes['FILES']) > 0) { $obRow->setAttribute('ows_Attachments', 1); } else { $obRow->setAttribute('ows_Attachments', 0); } $obRow->setAttribute('ows_owshiddenversion', $version); $obRow->setAttribute('ows_MetaInfo_vti_versionhistory', md5($arRes['ID']) . ':' . $version); $obRow->setAttribute('ows_Created', $this->__makeDateTime(MakeTimeStamp($arRes['CREATED_DATE']) - $tzOffset)); $obRow->setAttribute('ows_Modified', $this->__makeDateTime($change)); $obRow->setAttribute('ows_Title', $arRes['TITLE']); if ($arRes['DESCRIPTION_IN_BBCODE'] === 'Y') { $parser = new CTextParser(); $obRow->setAttribute('ows_Body', str_replace("\t", ' ', $parser->convertText($arRes['DESCRIPTION']))); } else { $obRow->setAttribute('ows_Body', $arRes['DESCRIPTION']); } if ($arRes['START_DATE_PLAN']) { $obRow->setAttribute('ows_StartDate', $this->__makeDateTime(MakeTimeStamp($arRes['START_DATE_PLAN']), true)); } if ($arRes['DEADLINE']) { $obRow->setAttribute('ows_DueDate', $this->__makeDateTime(MakeTimeStamp($arRes['DEADLINE']), true)); } if ($arRes['RESPONSIBLE_ID'] > 0) { $obRow->setAttribute('ows_AssignedTo', $this->__makeUser($arRes['RESPONSIBLE_ID'])); } $obRow->setAttribute('ows_Editor', $this->__makeUser($arRes['CHANGED_BY'] ? $arRes['CHANGED_BY'] : $arRes['CREATED_BY'])); $obRow->setAttribute('ows_Priority', $arRes["PRIORITY"]); $obRow->setAttribute('ows_Status', in_array($arRes["REAL_STATUS"], $this->arNotChoiceStatuses) ? GetMessage("TASKS_STATUS_" . $arRes["REAL_STATUS"]) : $arRes["REAL_STATUS"]); $obRow->setAttribute('ows_MetaInfo_DateComplete', $this->__makeDateTime(MakeTimeStamp($arRes['CLOSED_DATE']))); $obRow->setAttribute('ows_MetaInfo_TotalWork', $arRes['DURATION_PLAN'] * 60); $obRow->setAttribute('ows_MetaInfo_ActualWork', $arRes['DURATION_FACT'] * 60); $obRow->setAttribute('ows_UniqueId', $arRes['ID'] . ';#' . $listName); $obRow->setAttribute('ows_FSObjType', $arRes['ID'] . ';#0'); $obRow->setAttribute('ows_PermMask', '0x7fffffffffffffff'); $obRow->setAttribute('ows_ContentTypeId', '0x0108001E749911F9D25F4D90C446E16EEB2C0E'); return $obRow; }
public static function TrySendEmail($ID, &$arFields, &$arErrors) { global $APPLICATION; if (!CModule::IncludeModule('subscribe')) { $arErrors[] = array('CODE' => self::ERR_CANT_LOAD_SUBSCRIBE); return false; } $ID = intval($ID); if ($ID <= 0 && isset($arFields['ID'])) { $ID = intval($arFields['ID']); } if ($ID <= 0 || !is_array($arFields)) { $arErrors[] = array('CODE' => self::ERR_INVALID_DATA); return false; } $typeID = isset($arFields['TYPE_ID']) ? intval($arFields['TYPE_ID']) : CCrmActivityType::Undefined; if ($typeID !== CCrmActivityType::Email) { $arErrors[] = array('CODE' => self::ERR_INVALID_DATA); return false; } $urn = CCrmActivity::PrepareUrn($arFields); if (!($urn !== '' && CCrmActivity::Update($ID, array('URN' => $urn), false, false))) { $arErrors[] = array('CODE' => self::ERR_CANT_UPDATE_ACTIVITY); return false; } $settings = isset($arFields['SETTINGS']) && is_array($arFields['SETTINGS']) ? $arFields['SETTINGS'] : array(); // Creating Email --> $crmEmail = CCrmMailHelper::ExtractEmail(COption::GetOptionString('crm', 'mail', '')); $from = isset($settings['MESSAGE_FROM']) ? trim(strval($settings['MESSAGE_FROM'])) : ''; if ($from === '') { if ($crmEmail !== '') { $from = $crmEmail; } else { $arErrors[] = array('CODE' => self::ERR_CANT_FIND_EMAIL_FROM); } } elseif (!check_email($from)) { $arErrors[] = array('CODE' => self::ERR_INVALID_EMAIL, 'DATA' => array('EMAIL' => $from)); } //Save user email in settings --> if ($from !== CUserOptions::GetOption('crm', 'activity_email_addresser', '')) { CUserOptions::SetOption('crm', 'activity_email_addresser', $from); } //<-- Save user email in settings $to = array(); $commData = isset($arFields['COMMUNICATIONS']) ? $arFields['COMMUNICATIONS'] : array(); foreach ($commData as &$commDatum) { $commType = isset($commDatum['TYPE']) ? strtoupper(strval($commDatum['TYPE'])) : ''; $commValue = isset($commDatum['VALUE']) ? strval($commDatum['VALUE']) : ''; if ($commType !== 'EMAIL' || $commValue === '') { continue; } if (!check_email($commValue)) { $arErrors[] = array('CODE' => self::ERR_INVALID_EMAIL, 'DATA' => array('EMAIL' => $commValue)); continue; } $to[] = strtolower(trim($commValue)); } unset($commDatum); if (count($to) == 0) { $arErrors[] = array('CODE' => self::ERR_CANT_FIND_EMAIL_TO); } if (!empty($arErrors)) { return false; } // Try to resolve posting charset --> $postingCharset = ''; $siteCharset = defined('LANG_CHARSET') ? LANG_CHARSET : (defined('SITE_CHARSET') ? SITE_CHARSET : 'windows-1251'); $arSupportedCharset = explode(',', COption::GetOptionString('subscribe', 'posting_charset')); if (count($arSupportedCharset) === 0) { $postingCharset = $siteCharset; } else { foreach ($arSupportedCharset as $curCharset) { if (strcasecmp($curCharset, $siteCharset) === 0) { $postingCharset = $curCharset; break; } } if ($postingCharset === '') { $postingCharset = $arSupportedCharset[0]; } } //<-- Try to resolve posting charset $subject = isset($arFields['SUBJECT']) ? $arFields['SUBJECT'] : ''; $description = isset($arFields['DESCRIPTION']) ? $arFields['DESCRIPTION'] : ''; $descriptionType = isset($arFields['DESCRIPTION_TYPE']) ? intval($arFields['DESCRIPTION_TYPE']) : CCrmContentType::PlainText; $descriptionHtml = ''; if ($descriptionType === CCrmContentType::Html) { $descriptionHtml = $description; } elseif ($descriptionType === CCrmContentType::BBCode) { $parser = new CTextParser(); $descriptionHtml = $parser->convertText($description); } elseif ($descriptionType === CCrmContentType::PlainText) { $descriptionHtml = htmlspecialcharsbx($description); } $postingData = array('STATUS' => 'D', 'FROM_FIELD' => $from, 'TO_FIELD' => $from, 'BCC_FIELD' => implode(',', $to), 'SUBJECT' => $subject, 'BODY_TYPE' => 'html', 'BODY' => $descriptionHtml, 'DIRECT_SEND' => 'Y', 'SUBSCR_FORMAT' => 'html', 'CHARSET' => $postingCharset); CCrmActivity::InjectUrnInMessage($postingData, $urn, CCrmEMailCodeAllocation::GetCurrent()); $posting = new CPosting(); $postingID = $posting->Add($postingData); if ($postingID === false) { $arErrors[] = array('CODE' => self::ERR_CANT_ADD_POSTING, 'MESSAGE' => $posting->LAST_ERROR); return false; } $arUpdateFields = array('COMPLETED' => 'Y', 'ASSOCIATED_ENTITY_ID' => $postingID, 'SETTINGS' => $settings); $fromEmail = strtolower(trim(CCrmMailHelper::ExtractEmail($from))); if ($crmEmail !== '' && $fromEmail !== $crmEmail) { $arUpdateFields['SETTINGS']['MESSAGE_HEADERS'] = array('Reply-To' => "<{$fromEmail}>, <{$crmEmail}>"); } $arUpdateFields['SETTINGS']['IS_MESSAGE_SENT'] = true; if (!CCrmActivity::Update($ID, $arUpdateFields, false, false)) { $arErrors[] = array('CODE' => self::ERR_CANT_UPDATE_ACTIVITY); return false; } // <-- Creating Email // Attaching files --> $storageTypeID = isset($arFields['STORAGE_TYPE_ID']) ? intval($arFields['STORAGE_TYPE_ID']) : StorageType::Undefined; $storageElementsID = isset($arFields['STORAGE_ELEMENT_IDS']) && is_array($arFields['STORAGE_ELEMENT_IDS']) ? $arFields['STORAGE_ELEMENT_IDS'] : array(); $arRawFiles = StorageManager::makeFileArray($storageElementsID, $storageTypeID); foreach ($arRawFiles as &$arRawFile) { if (!$posting->SaveFile($postingID, $arRawFile)) { $arErrors[] = array('CODE' => self::ERR_CANT_SAVE_POSTING_FILE, 'MESSAGE' => $posting->LAST_ERROR); return false; } } unset($arRawFile); // <-- Attaching files // Sending Email --> if ($posting->ChangeStatus($postingID, 'P')) { $rsAgents = CAgent::GetList(array('ID' => 'DESC'), array('MODULE_ID' => 'subscribe', 'NAME' => 'CPosting::AutoSend(' . $postingID . ',%')); if (!$rsAgents->Fetch()) { CAgent::AddAgent('CPosting::AutoSend(' . $postingID . ',true);', 'subscribe', 'N', 0); } } // Try add event to entity $CCrmEvent = new CCrmEvent(); $ownerID = isset($arFields['OWNER_ID']) ? intval($arFields['OWNER_ID']) : 0; $ownerTypeID = isset($arFields['OWNER_TYPE_ID']) ? intval($arFields['OWNER_TYPE_ID']) : 0; if ($ownerID > 0 && $ownerTypeID > 0) { $eventText = ''; $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_SUBJECT') . ': ' . $subject . "\n\r"; $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_FROM') . ': ' . $from . "\n\r"; $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_TO') . ': ' . implode(',', $to) . "\n\r\n\r"; $eventText .= $description; // Register event only for owner $CCrmEvent->Add(array('ENTITY' => array($ownerID => array('ENTITY_TYPE' => CCrmOwnerType::ResolveName($ownerTypeID), 'ENTITY_ID' => $ownerID)), 'EVENT_ID' => 'MESSAGE', 'EVENT_TEXT_1' => $eventText, 'FILES' => $arRawFiles)); } // <-- Sending Email return true; }
function GetMoreChatMessage($pageId, $chatId, $bTimeZone = true) { global $DB; $iNumPage = 1; if (intval($pageId) > 0) { $iNumPage = intval($pageId); } $chatId = IntVal($chatId); $limitById = ''; $ar = \CIMChat::GetRelationById($chatId, $this->user_id); if ($ar && $ar['START_ID'] > 0) { $limitById = 'AND M.ID >= ' . intval($ar['START_ID']); } $strSql = "\n\t\t\tSELECT COUNT(M.ID) as CNT\n\t\t\tFROM b_im_message M\n\t\t\tINNER JOIN b_im_relation R1 ON M.CHAT_ID = R1.CHAT_ID\n\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . " " . $limitById . "\n\t\t"; $res_cnt = $DB->Query($strSql); $res_cnt = $res_cnt->Fetch(); $cnt = $res_cnt["CNT"]; $arMessages = array(); $arMessageFiles = array(); $arMessageId = array(); $usersMessage = array(); if ($cnt > 0 && ceil($cnt / 20) >= $iNumPage) { 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->DatetimeToTimestampFunction('M.DATE_CREATE') . " DATE_CREATE,\n\t\t\t\t\tM.AUTHOR_ID\n\t\t\t\tFROM b_im_message M\n\t\t\t\tINNER JOIN b_im_relation R1 ON M.CHAT_ID = R1.CHAT_ID\n\t\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . " " . $limitById . "\n\t\t\t\tORDER BY M.DATE_CREATE DESC, M.ID DESC\n\t\t\t"; if (!$bTimeZone) { CTimeZone::Enable(); } $dbRes = new CDBResult(); $dbRes->NavQuery($strSql, $cnt, array('iNumPage' => $iNumPage, 'nPageSize' => 20)); $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()) { $arMessages[$arRes['ID']] = array('id' => $arRes['ID'], 'chatId' => $arRes['CHAT_ID'], 'senderId' => $arRes['AUTHOR_ID'], 'recipientId' => $arRes['CHAT_ID'], 'date' => $arRes['DATE_CREATE'], 'system' => $arRes['AUTHOR_ID'] > 0 ? 'N' : 'Y', 'text' => $CCTP->convertText(htmlspecialcharsbx($arRes['MESSAGE']))); $usersMessage[$arRes['CHAT_ID']][] = $arRes['ID']; $arMessageId[] = $arRes['ID']; } $params = CIMMessageParam::Get($arMessageId); $arFiles = array(); foreach ($params as $messageId => $param) { $arMessages[$messageId]['params'] = $param; if (isset($param['FILE_ID'])) { foreach ($param['FILE_ID'] as $fileId) { $arFiles[$fileId] = $fileId; } } } $arMessageFiles = CIMDisk::GetFiles($chatId, $arFiles); } return array('chatId' => $chatId, 'message' => $arMessages, 'usersMessage' => $usersMessage, 'files' => $arMessageFiles); }
public static function onAfterCommentAdd($entityType, $entityId, $arData) { global $USER; // 'TK' is our entity type if ($entityType !== 'TK' || intval($entityId) <= 0 || !CModule::IncludeModule('tasks') || !CModule::IncludeModule('socialnetwork')) { return; } $taskId = (int) $entityId; $messageId = $arData['MESSAGE_ID']; $parser = new CTextParser(); $messageAuthorId = null; if (array_key_exists('AUTHOR_ID', $arData['PARAMS']) && array_key_exists('EDIT_DATE', $arData['PARAMS']) && array_key_exists('POST_DATE', $arData['PARAMS'])) { $messageAuthorId = $arData['PARAMS']['AUTHOR_ID']; } else { $arMessage = CForumMessage::GetByID($messageId); $messageAuthorId = $arMessage['AUTHOR_ID']; } $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $messageAuthorId ? $messageAuthorId : 1; } $rsTask = CTasks::GetList(false, array('ID' => $taskId), array('UF_CRM_TASK')); $arTask = $rsTask->GetNext(); if (!isset($arTask) || !isset($arTask['UF_CRM_TASK']) || is_array($arTask['UF_CRM_TASK']) && (!isset($arTask['UF_CRM_TASK'][0]) || strlen($arTask['UF_CRM_TASK'][0]) <= 0) || !is_array($arTask['UF_CRM_TASK']) && strlen($arTask['UF_CRM_TASK']) <= 0) { return; } $dbCrmActivity = CCrmActivity::GetList(array(), array('TYPE_ID' => CCrmActivityType::Task, 'ASSOCIATED_ENTITY_ID' => $taskId, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID')); $arCrmActivity = $dbCrmActivity->Fetch(); if (!$arCrmActivity) { return; } $crmActivityId = $arCrmActivity['ID']; // sonet log $dbLog = CSocNetLog::GetList(array(), array("EVENT_ID" => "crm_activity_add", "ENTITY_ID" => $crmActivityId), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID")); if ($arLog = $dbLog->Fetch()) { $log_id = $arLog["ID"]; $entity_type = $arLog["ENTITY_TYPE"]; $entity_id = $arLog["ENTITY_ID"]; $strURL = $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result")); $strURL = ForumAddPageParams($strURL, array("MID" => $messageId, "result" => "reply"), false, false); $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]; $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "crm_activity_add_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "crm", "SOURCE_ID" => $messageId, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageId); $arFieldsForSocnet["USER_ID"] = $occurAsUserId; $arFieldsForSocnet["=LOG_DATE"] = $GLOBALS['DB']->CurrentTimeFunction(); $ufFileID = array(); $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageId)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } if (count($ufFileID) > 0) { $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageId, LANGUAGE_ID); if ($ufDocID) { $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID; } $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); CSocNetLog::CounterIncrement($comment_id, false, false, "LC"); } }
$bEdit = $_REQUEST['gdhtml'] == $id && $_REQUEST['edit'] == 'true' && $arParams["PERMISSION"] > "R"; if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_REQUEST['gdhtmlform'] == 'Y' && $_REQUEST['gdhtml'] == $id) { $arGadget["USERDATA"] = array("content" => $_POST["html_content"]); $arGadget["FORCE_REDIRECT"] = true; } $arData = $arGadget["USERDATA"]; $content = $arData["content"]; ?> <?php if (!$bEdit) { ?> <?php if ($content) { $parser = new CTextParser(); $parser->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N", "TABLE" => "Y", "CUT_ANCHOR" => "N", "ALIGN" => "Y"); $parser->parser_nofollow = "Y"; echo $parser->convertText($content); } else { if ($arParams["PERMISSION"] > "R") { echo GetMessage("GD_HTML_AREA_NO_CONTENT"); } } ?> <?php if ($arParams["PERMISSION"] > "R") { ?> <div class="gdhtmlareach" style="padding-top: 10px;"><a class="gdhtmlareachlink" href="<?php echo $GLOBALS["APPLICATION"]->GetCurPageParam("gdhtml=" . $id . "&edit=true", array("gdhtml", "edit"));
function GetMoreChatMessage($pageId, $chatId, $bTimeZone = true) { global $DB; $iNumPage = 1; if (intval($pageId) > 0) { $iNumPage = intval($pageId); } $chatId = IntVal($chatId); $strSql = "\n\t\t\tSELECT COUNT(M.ID) as CNT\n\t\t\tFROM b_im_message M\n\t\t\tINNER JOIN b_im_relation R1 ON M.ID >= R1.START_ID AND M.CHAT_ID = R1.CHAT_ID\n\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . "\n\t\t"; $res_cnt = $DB->Query($strSql); $res_cnt = $res_cnt->Fetch(); $cnt = $res_cnt["CNT"]; $arMessages = array(); $usersMessage = array(); if ($cnt > 0 && ceil($cnt / 20) >= $iNumPage) { 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\tFROM b_im_message M\n\t\t\t\tINNER JOIN b_im_relation R1 ON M.ID >= R1.START_ID AND M.CHAT_ID = R1.CHAT_ID\n\t\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . "\n\t\t\t\tORDER BY M.DATE_CREATE DESC, ID DESC\n\t\t\t"; if (!$bTimeZone) { CTimeZone::Enable(); } $dbRes = new CDBResult(); $dbRes->NavQuery($strSql, $cnt, array('iNumPage' => $iNumPage, 'nPageSize' => 20)); $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"); while ($arRes = $dbRes->Fetch()) { $arMessages[$arRes['ID']] = array('id' => $arRes['ID'], 'senderId' => $arRes['AUTHOR_ID'], 'recipientId' => $arRes['CHAT_ID'], 'date' => MakeTimeStamp($arRes['DATE_CREATE']), 'text' => $CCTP->convertText(htmlspecialcharsbx($arRes['MESSAGE']))); $usersMessage[$arRes['CHAT_ID']][] = $arRes['ID']; } } return array('message' => $arMessages, 'usersMessage' => $usersMessage); }
public static function GetFormatMessage($arParams) { $arParams['ID'] = intval($arParams['ID']); $arParams['TO_USER_ID'] = isset($arParams['TO_CHAT_ID'])? intval($arParams['TO_CHAT_ID']): intval($arParams['TO_USER_ID']); $arParams['FROM_USER_ID'] = intval($arParams['FROM_USER_ID']); $arParams['MESSAGE'] = trim($arParams['MESSAGE']); $arParams['DATE_CREATE'] = intval($arParams['DATE_CREATE']); $arParams['PARAMS'] = empty($arParams['PARAMS'])? Array(): $arParams['PARAMS']; $arUsers = CIMContactList::GetUserData(Array('ID' => isset($arParams['TO_CHAT_ID'])? $arParams['FROM_USER_ID']: Array($arParams['TO_USER_ID'], $arParams['FROM_USER_ID']))); $arChat = Array(); if (isset($arParams['TO_CHAT_ID'])) { $arChat = CIMChat::GetChatData(array( 'ID' => $arParams['TO_USER_ID'], 'USE_CACHE' => 'N' )); } $CCTP = new CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $text = $CCTP->convertText(htmlspecialcharsbx($arParams['MESSAGE'])); $text_mobile = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\[s\].*?\[\/s\]/i", "", $arParams['MESSAGE'])))) , '<br>'); return Array( 'CHAT_ID' => $arParams['CHAT_ID'], 'CHAT' => isset($arChat['chat'])? $arChat['chat']: Array(), 'USER_IN_CHAT' => isset($arChat['userInChat'])? $arChat['userInChat']: Array(), 'USER_BLOCK_CHAT' => $arChat['userChatBlockStatus'], 'USERS' => $arUsers['users'], 'MESSAGE' => Array( 'id' => $arParams['ID'], 'chatId' => $arParams['CHAT_ID'], 'senderId' => $arParams['FROM_USER_ID'], 'recipientId' => isset($arParams['TO_CHAT_ID'])? 'chat'.$arParams['TO_USER_ID']: $arParams['TO_USER_ID'], 'system' => $arParams['SYSTEM'] == 'Y'? 'Y': 'N', 'date' => $arParams['DATE_CREATE'], 'text' => $text, 'text_mobile' => $text_mobile, 'params' => $arParams['PARAMS'] ), 'FILES' => isset($arParams['FILES'])? $arParams['FILES']: Array(), ); }
/** * WARNING! This method is transitional and can be changed without * any notifications! Don't use it. * * @deprecated */ public static function __deprecated_Add($commentText, $forumTopicId, $forumId, $nameTemplate, $arTask, $permissions, $commentId, $givenUserId, $imageWidth, $imageHeight, $arSmiles, $arForum, $messagesPerPage, $arUserGroupArray, $backPage, $strMsgAddComment, $strMsgEditComment, $strMsgNewTask, $componentName, &$outForumTopicId, &$arErrorCodes, &$outStrUrl, $arFieldsAdditional = array()) { global $DB; if (is_array($arTask)) { if (!array_key_exists('~TITLE', $arTask)) { $arTmpTask = $arTask; foreach ($arTmpTask as $key => $value) { if (substr($key, 0, 1) !== '~') { $arTask['~' . $key] = $arTmpTask[$key]; } } } } $MID = 0; $TID = 0; if ($forumTopicId > 0 && CForumTopic::GetByID($forumTopicId) === false) { $forumTopicId = false; } if ($forumTopicId <= 0) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim(CUser::FormatName($nameTemplate, $res)) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arFields = array("TITLE" => $arTask["~TITLE"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions, "NAME_TEMPLATE" => $nameTemplate, 'XML_ID' => 'TASK_' . $arTask['ID']); $TID = CForumTopic::Add($arFields); if (intVal($TID) <= 0) { $arErrorCodes[] = array('code' => 'topic is not created'); } else { $arFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arFields); } if (!empty($arErrorCodes)) { $DB->Rollback(); return false; } else { $DB->Commit(); } } $arFieldsG = array("POST_MESSAGE" => $commentText, "AUTHOR_NAME" => '', "AUTHOR_EMAIL" => $GLOBALS['USER']->GetEmail(), "USE_SMILES" => NULL, "PARAM2" => $arTask['ID'], "TITLE" => $arTask["~TITLE"], "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions); // UF_* forwarding if (is_array($arFieldsAdditional)) { foreach ($arFieldsAdditional as $field => $value) { if (strlen($field) && substr($field, 0, 3) == 'UF_') { $arFieldsG[$field] = $value; $GLOBALS[$field] = $value; // strange behaviour required for ForumMessageAdd() to handle UF_* properly } } } if (!empty($_FILES["REVIEW_ATTACH_IMG"])) { $arFieldsG["ATTACH_IMG"] = $_FILES["REVIEW_ATTACH_IMG"]; } else { $arFiles = array(); if (!empty($_REQUEST["FILES"])) { foreach ($_REQUEST["FILES"] as $key) { $arFiles[$key] = array("FILE_ID" => $key); if (!in_array($key, $_REQUEST["FILES_TO_UPLOAD"])) { $arFiles[$key]["del"] = "Y"; } } } if (!empty($_FILES)) { $res = array(); foreach ($_FILES as $key => $val) { if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) { $arFiles[] = $_FILES[$key]; } } } if (!empty($arFiles)) { $arFieldsG["FILES"] = $arFiles; } } $TOPIC_ID = $forumTopicId > 0 ? $forumTopicId : $TID; $MESSAGE_ID = 0; $MESSAGE_TYPE = $TOPIC_ID > 0 ? "REPLY" : "NEW"; if (COption::GetOptionString("tasks", "task_comment_allow_edit") && ($MESSAGE_ID = intval($commentId))) { $MESSAGE_TYPE = "EDIT"; } $strErrorMessage = ''; $strOKMessage = ''; $MID = ForumAddMessage($MESSAGE_TYPE, $forumId, $TOPIC_ID, $MESSAGE_ID, $arFieldsG, $strErrorMessage, $strOKMessage, false, $_POST["captcha_word"], 0, $_POST["captcha_code"], $nameTemplate); if ($MID <= 0 || !empty($strErrorMessage)) { $arErrorCodes[] = array('code' => 'message is not added 2', 'title' => empty($strErrorMessage) ? NULL : $strErrorMessage); } else { $arMessage = CForumMessage::GetByID($MID); if ($forumTopicId <= 0) { $forumTopicId = $TID = intVal($arMessage["TOPIC_ID"]); } $outForumTopicId = intVal($forumTopicId); if ($componentName !== null) { ForumClearComponentCache($componentName); } // NOTIFICATION $arTask["ACCOMPLICES"] = $arTask["AUDITORS"] = array(); $rsMembers = CTaskMembers::GetList(array(), array("TASK_ID" => $arTask["ID"])); while ($arMember = $rsMembers->Fetch()) { if ($arMember["TYPE"] == "A") { $arTask["ACCOMPLICES"][] = $arMember["USER_ID"]; } elseif ($arMember["TYPE"] == "U") { $arTask["AUDITORS"][] = $arMember["USER_ID"]; } } $arEmailUserIDs = array($arTask["RESPONSIBLE_ID"], $arTask["CREATED_BY"]); $arEmailUserIDs = array_unique(array_merge($arEmailUserIDs, $arTask["ACCOMPLICES"], $arTask["AUDITORS"])); $currentUserPos = array_search($givenUserId, $arEmailUserIDs); if ($currentUserPos !== false) { unset($arEmailUserIDs[$currentUserPos]); } $parser = new CTextParser(); $parser->imageWidth = $imageWidth; $parser->imageHeight = $imageHeight; $parser->smiles = $arSmiles; $parser->allow = array("HTML" => $arForum["ALLOW_HTML"], "ANCHOR" => $arForum["ALLOW_ANCHOR"], "BIU" => $arForum["ALLOW_BIU"], "IMG" => "N", "VIDEO" => "N", "LIST" => $arForum["ALLOW_LIST"], "QUOTE" => $arForum["ALLOW_QUOTE"], "CODE" => $arForum["ALLOW_CODE"], "FONT" => $arForum["ALLOW_FONT"], "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => $arForum["ALLOW_NL2BR"], "TABLE" => "Y"); $arAllow = NULL; $MESSAGE = HTMLToTxt($parser->convertText($commentText, $arAllow)); // remove [ url] for socialnetwork log $MESSAGE = preg_replace("/(\\s\\[\\s(http:\\/\\/|https:\\/\\/|ftp:\\/\\/))(.*?)(\\s\\])/is", "", $MESSAGE); $parser->allow = array("HTML" => 'Y', "ANCHOR" => 'Y', "BIU" => 'Y', "IMG" => "Y", "VIDEO" => "Y", "LIST" => 'N', "QUOTE" => 'Y', "CODE" => 'Y', "FONT" => 'Y', "SMILES" => "N", "UPLOAD" => 'N', "NL2BR" => 'N', "TABLE" => "Y"); $message_notify = $parser->convertText($commentText); $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); // Instant Messages if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { // this entire class is deprecated. disable edit message, add only here if ($MESSAGE_TYPE != 'EDIT') { CTaskComments::sendAddMessage(array('ID' => $MID, 'POST_MESSAGE' => $message_notify), $arTask, $givenUserId, $arRecipientsIDs, array()); } } $strURL = !empty($backPage) ? $backPage : $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result")); $strURL = ForumAddPageParams($strURL, array("MID" => $MID, "result" => $arForum["MODERATION"] != "Y" || CForumNew::CanUserModerateForum($forumId, $arUserGroupArray) ? "reply" : "not_approved"), false, false); $outStrUrl = $strURL; // sonet log if (CModule::IncludeModule("socialnetwork")) { $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID")); if ($arRes = $dbRes->Fetch()) { $log_id = $arRes["TMP_ID"]; $entity_type = $arRes["ENTITY_TYPE"]; $entity_id = $arRes["ENTITY_ID"]; } else { $entity_type = $arTask["GROUP_ID"] ? SONET_ENTITY_GROUP : SONET_ENTITY_USER; $entity_id = $arTask["GROUP_ID"] ? $arTask["GROUP_ID"] : $arTask["CREATED_BY"]; $rsUser = CUser::GetByID($arTask["CREATED_BY"]); if ($arUser = $rsUser->Fetch()) { $arSoFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks", "LOG_DATE" => $arTask["CREATED_DATE"], "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => htmlspecialcharsBack($arTask["~TITLE"]), "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $arTask["ID"], "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]), "PARAMS" => serialize(array("TYPE" => "create"))); $log_id = CSocNetLog::Add($arSoFields, false); if (intval($log_id) > 0) { CSocNetLog::Update($log_id, array("TMP_ID" => $log_id)); $arRights = CTaskNotifications::__UserIDs2Rights(CTaskNotifications::GetRecipientsIDs($arTask, false)); if ($arTask["GROUP_ID"]) { $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"]; } CSocNetLogRights::Add($log_id, $arRights); } } } if (intval($log_id) > 0) { $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]; CSocNetLog::Update($log_id, array('PARAMS' => serialize(array('TYPE' => 'comment')))); $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "tasks", "SOURCE_ID" => $MID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $MID); if ($MESSAGE_TYPE == "EDIT") { $dbRes = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => array("tasks_comment"), "SOURCE_ID" => $MID), false, false, array("ID")); while ($arRes = $dbRes->Fetch()) { CSocNetLogComments::Update($arRes["ID"], $arFieldsForSocnet); } } else { $arFieldsForSocnet['USER_ID'] = $givenUserId; $arFieldsForSocnet['=LOG_DATE'] = $GLOBALS['DB']->CurrentTimeFunction(); $ufFileID = array(); $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $MID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } if (count($ufFileID) > 0) { $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $MID, LANGUAGE_ID); if ($ufDocID) { $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID; } $ufDocVer = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_VER", $MID, LANGUAGE_ID); if ($ufDocVer) { $arFieldsForSocnet["UF_SONET_COM_VER"] = $ufDocVer; } if (isset($arFieldsAdditional["ANCILLARY"]) && $arFieldsAdditional["ANCILLARY"]) { CSocNetLogComments::Add($arFieldsForSocnet, false, false, false); } else { $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); CSocNetLog::CounterIncrement($comment_id, false, false, "LC"); } } } } $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $arMessage["AUTHOR_ID"] ? $arMessage["AUTHOR_ID"] : 1; } // Tasks log $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arMessage["EDIT_DATE"] ? ConvertTimeStamp(MakeTimeStamp($arMessage["EDIT_DATE"], CSite::GetDateFormat()), "FULL") : $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $MID); $log = new CTaskLog(); $log->Add($arLogFields); } return $MID; // Message id }
public static function Like($id, $action = 'auto') { global $USER; if (!CModule::IncludeModule('pull')) return false; $action = in_array($action, Array('plus', 'minus'))? $action: 'auto'; $message = self::GetById($id, Array('WITH_FILES' => 'Y')); if (!$message) return false; $relations = CIMMessenger::GetRelationById($id); if (!isset($relations[$USER->GetId()])) return false; $isLike = false; if (isset($message['PARAMS']['LIKE'])) { $isLike = in_array($USER->GetId(), $message['PARAMS']['LIKE']); } if ($isLike && $action == 'plus') { return false; } else if (!$isLike && $action == 'minus') { return false; } $isLike = true; if (isset($message['PARAMS']['LIKE'])) { $like = $message['PARAMS']['LIKE']; $selfLike = array_search($USER->GetId(), $like); if ($selfLike !== false) { $isLike = false; unset($like[$selfLike]); } else { $like[] = $USER->GetId(); } } else { $like = Array($USER->GetId()); } sort($like); CIMMessageParam::Set($id, Array('LIKE' => $like)); $result = IM\ChatTable::getList(Array( 'filter'=>Array( '=ID' => $message['CHAT_ID'] ) )); $chat = $result->fetch(); if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $USER->GetId() && $isLike) { $CCTP = new CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->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"); $message['MESSAGE'] = str_replace('<br />', ' ', $CCTP->convertText($message['MESSAGE'])); if (count($message['FILES']) > 0 && strlen($message['MESSAGE']) < 200) { foreach ($message['FILES'] as $file) { $file = " [".GetMessage('IM_MESSAGE_FILE').": ".$file['name']."]"; if (strlen($message['MESSAGE'].$file) > 200) break; $message['MESSAGE'] .= $file; } $message['MESSAGE'] = trim($message['MESSAGE']); } $isChat = $chat && strlen($chat['TITLE']) > 0; $arMessageFields = array( "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $message['AUTHOR_ID'], "FROM_USER_ID" => $USER->GetId(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|IM|".($isChat? 'G':'P')."|".($isChat? $chat['ID']: $USER->GetId())."|".$id, "NOTIFY_MESSAGE" => GetMessage($isChat? 'IM_MESSAGE_LIKE': 'IM_MESSAGE_LIKE_PRIVATE', Array( '#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $chat['TITLE'] )) ); CIMNotify::Add($arMessageFields); } $arPullMessage = Array( 'id' => $id, 'chatId' => $relations[$USER->GetId()]['CHAT_ID'], 'senderId' => $USER->GetId(), 'users' => $like ); foreach ($relations as $rel) { CPullStack::AddByUser($rel['USER_ID'], Array( 'module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage )); } return $like; }
public function getIBlockItems($IBLOCK_ID) { $items = array(); foreach (CIBlockSectionPropertyLink::GetArray($IBLOCK_ID, $this->SECTION_ID) as $PID => $arLink) { if ($arLink["SMART_FILTER"] !== "Y") { continue; } if ($arLink['FILTER_HINT'] != '') { $arLink['FILTER_HINT'] = CTextParser::closeTags($arLink['FILTER_HINT']); } $rsProperty = CIBlockProperty::GetByID($PID); $arProperty = $rsProperty->Fetch(); if ($arProperty) { $items[$arProperty["ID"]] = array("ID" => $arProperty["ID"], "IBLOCK_ID" => $arProperty["IBLOCK_ID"], "CODE" => $arProperty["CODE"], "NAME" => $arProperty["NAME"], "PROPERTY_TYPE" => $arProperty["PROPERTY_TYPE"], "USER_TYPE" => $arProperty["USER_TYPE"], "USER_TYPE_SETTINGS" => $arProperty["USER_TYPE_SETTINGS"], "DISPLAY_TYPE" => $arLink["DISPLAY_TYPE"], "DISPLAY_EXPANDED" => $arLink["DISPLAY_EXPANDED"], "FILTER_HINT" => $arLink["FILTER_HINT"], "VALUES" => array()); if ($arProperty["PROPERTY_TYPE"] == "N" || $arLink["DISPLAY_TYPE"] == "U") { $minID = $this->SAFE_FILTER_NAME . '_' . $arProperty['ID'] . '_MIN'; $maxID = $this->SAFE_FILTER_NAME . '_' . $arProperty['ID'] . '_MAX'; $items[$arProperty["ID"]]["VALUES"] = array("MIN" => array("CONTROL_ID" => $minID, "CONTROL_NAME" => $minID), "MAX" => array("CONTROL_ID" => $maxID, "CONTROL_NAME" => $maxID)); } } } return $items; }
function killAllTags($text) { if (method_exists("CTextParser", "clearAllTags")) { return CTextParser::clearAllTags($text); } $text = strip_tags($text); $text = preg_replace(array("/\\<(\\/?)(quote|code|font|color|video|disk)([^\\>]*)\\>/is" . BX_UTF_PCRE_MODIFIER, "/\\[(\\/?)(b|u|i|s|list|code|quote|font|color|url|img|video|disk)([^\\]]*)\\]/is" . BX_UTF_PCRE_MODIFIER), "", $text); return $text; }
/** * Method will be invoked after an database record updated. * * @param array $oldRecord All fields before update. * @param array $newRecord All fields after update. * * @return void */ public function afterUpdateTrigger(array $oldRecord, array $newRecord) { if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } $arFields = \CIMMessenger::GetById($newRecord['ID'], array('WITH_FILES' => 'Y')); if (!$arFields) { return; } $arFields['DATE_MODIFY'] = time() + \CTimeZone::GetOffset(); $CCTP = new \CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $pullMessage = $CCTP->convertText(htmlspecialcharsbx($arFields['MESSAGE'])); $relations = \CIMChat::GetRelationById($arFields['CHAT_ID']); $arPullMessage = array('id' => $arFields['ID'], 'type' => $arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE ? 'private' : 'chat', 'text' => $pullMessage, 'date' => $arFields['DATE_MODIFY']); if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) { $arFields['FROM_USER_ID'] = $arFields['AUTHOR_ID']; foreach ($relations as $rel) { if ($rel['USER_ID'] != $arFields['AUTHOR_ID']) { $arFields['TO_USER_ID'] = $rel['USER_ID']; } } $arPullMessage['fromUserId'] = $arFields['FROM_USER_ID']; $arPullMessage['toUserId'] = $arFields['TO_USER_ID']; } else { $arPullMessage['chatId'] = $arFields['CHAT_ID']; $arPullMessage['senderId'] = $arFields['AUTHOR_ID']; } \CPullStack::AddByUsers(array_keys($relations), $p = array('module_id' => 'im', 'command' => $arFields['PARAMS']['IS_DELETED'] === 'Y' ? 'messageDelete' : 'messageUpdate', 'params' => $arPullMessage)); foreach ($relations as $rel) { $obCache = new \CPHPCache(); $obCache->CleanDir('/bx/imc/recent' . \CIMMessenger::GetCachePath($rel['USER_ID'])); } if ($newRecord['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) { \CPullWatch::AddToStack('IM_PUBLIC_' . $arFields['CHAT_ID'], array('module_id' => 'im', 'command' => $arFields['PARAMS']['IS_DELETED'] === 'Y' ? 'messageDelete' : 'messageUpdate', 'params' => $arPullMessage)); } foreach (\GetModuleEvents("im", "OnAfterMessagesUpdate", true) as $arEvent) { \ExecuteModuleEventEx($arEvent, array(intval($newRecord['ID']), $arFields)); } }
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; }
public static function ParseHTMLToBB($html = "") { $id = AddEventHandler("main", "TextParserBeforeTags", array("CCalendar", "_ParseHack")); $TextParser = new CTextParser(); $TextParser->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "Y", "TABLE" => "Y", "CUT_ANCHOR" => "Y", "ALIGN" => "Y"); $html = $TextParser->convertText($html); $html = htmlspecialcharsback($html); // Replace BR $html = preg_replace("/\\<br\\s*\\/*\\>/is" . BX_UTF_PCRE_MODIFIER, "\n", $html); // Kill $html = preg_replace("/ /is" . BX_UTF_PCRE_MODIFIER, "", $html); // Kill tags $html = preg_replace("/\\<([^>]*?)>/is" . BX_UTF_PCRE_MODIFIER, "", $html); $html = htmlspecialcharsbx($html); RemoveEventHandler("main", "TextParserBeforeTags", $id); return $html; }
$arResult["SECTION_TITLE"] = ""; $arResult["SECTION_DESCRIPTION"] = ""; if ($this->SECTION_ID > 0) { $arSelect = array("ID", "IBLOCK_ID", "LEFT_MARGIN", "RIGHT_MARGIN"); if ($arParams["SECTION_TITLE"] !== "") { $arSelect[] = $arParams["SECTION_TITLE"]; } if ($arParams["SECTION_DESCRIPTION"] !== "") { $arSelect[] = $arParams["SECTION_DESCRIPTION"]; } $sectionList = CIBlockSection::GetList(array(), array("=ID" => $this->SECTION_ID, "IBLOCK_ID" => $this->IBLOCK_ID), false, $arSelect); $arResult["SECTION"] = $sectionList->GetNext(); if ($arResult["SECTION"]) { $arResult["SECTION_TITLE"] = $arResult["SECTION"][$arParams["SECTION_TITLE"]]; if ($arParams["SECTION_DESCRIPTION"] !== "") { $obParser = new CTextParser(); $arResult["SECTION_DESCRIPTION"] = $obParser->html_cut($arResult["SECTION"][$arParams["SECTION_DESCRIPTION"]], 200); } } } } $this->EndResultCache(); } else { $this->facet->setPrices($arResult["PRICES"]); $this->facet->setSectionId($this->SECTION_ID); } /*Handle checked for checkboxes and html control value for numbers*/ if (isset($_REQUEST["ajax"]) && $_REQUEST["ajax"] === "y") { $_CHECK =& $_REQUEST; } elseif (isset($_REQUEST["del_filter"])) { $_CHECK = array();
$tmpID = $_POST['ID']; if ($_POST['CHAT'] == 'Y') { $ar = array("FROM_USER_ID" => intval($USER->GetID()), "TO_CHAT_ID" => intval(substr($_POST['RECIPIENT_ID'], 4)), "MESSAGE" => $_POST['MESSAGE'], "MESSAGE_TYPE" => IM_MESSAGE_GROUP); } else { $ar = array("FROM_USER_ID" => intval($USER->GetID()), "TO_USER_ID" => intval($_POST['RECIPIENT_ID']), "MESSAGE" => $_POST['MESSAGE']); } $errorMessage = ""; if (!($insertID = CIMMessage::Add($ar))) { if ($e = $GLOBALS["APPLICATION"]->GetException()) { $errorMessage = $e->GetString(); } if (StrLen($errorMessage) == 0) { $errorMessage = GetMessage('UNKNOWN_ERROR'); } } $CCTP = new CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => isset($_POST['MOBILE']) ? "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"); $userTzOffset = isset($_POST['USER_TZ_OFFSET']) ? intval($_POST['USER_TZ_OFFSET']) : CTimeZone::GetOffset(); $arResult = array('TMP_ID' => $tmpID, 'ID' => $insertID, 'SEND_DATE' => time() + $userTzOffset, 'SEND_MESSAGE' => $CCTP->convertText(htmlspecialcharsbx($ar['MESSAGE'])), 'SENDER_ID' => intval($USER->GetID()), 'RECIPIENT_ID' => $_POST['CHAT'] == 'Y' ? htmlspecialcharsbx($_POST['RECIPIENT_ID']) : intval($_POST['RECIPIENT_ID']), 'ERROR' => $errorMessage); if (isset($_POST['MOBILE'])) { $arFormat = array("today" => "today, " . GetMessage('IM_MESSAGE_FORMAT_TIME'), "" => GetMessage('IM_MESSAGE_FORMAT_DATE')); $arResult['SEND_DATE_FORMAT'] = FormatDate($arFormat, time() + $userTzOffset); } echo CUtil::PhpToJsObject($arResult); CIMContactList::SetOnline(null, true); CIMMessenger::SetCurrentTab(intval($_POST['TAB'])); } else { if ($_POST['IM_READ_MESSAGE'] == 'Y') { $errorMessage = ""; if (substr($_POST['USER_ID'], 0, 4) == 'chat') {