4use Bitrix\Tasks\Item\Task;
14 if (is_null($user_id))
17 $this->user_id = intval(
$USER->GetID());
21 $this->user_id = intval($user_id);
34 $joinUsers = Array($this->user_id);
35 if (!\
Bitrix\Im\User::getInstance(
$message[
'AUTHOR_ID'])->isExtranet())
37 $joinUsers[] = (int)
$message[
'AUTHOR_ID'];
40 $chat =
new CIMChat($this->user_id);
41 $chatId = $chat->Add(Array(
42 'USERS' => $joinUsers,
43 'ENTITY_TYPE' =>
'THREAD',
44 'SKIP_ADD_MESSAGE' =>
'Y',
50 'CHAT_LAST_DATE' =>
new \
Bitrix\Main\Type\DateTime(),
51 'CHAT_USER' => array_unique($joinUsers),
57 $sendMessage .=
$message[
'MESSAGE'].
"\n";
60 $files = CIMMessageParam::Get(
$messageId,
'FILE_ID');
63 foreach ($files as $fileId)
65 $sendMessage .=
" [DISK={$fileId}]";
71 $dialogId = $this->user_id;
73 foreach ($relations as $relation)
75 if ($relation[
'USER_ID'] != $this->user_id)
77 $dialogId = $relation[
'USER_ID'];
84 $chatLink =
'[CHAT='.$parentChatId.
']'.
$message[
'CHAT_TITLE'].
"[/CHAT]";
87 $message[
'MESSAGE'] = trim($sendMessage);
91 $noticeMessage =
GetMessage(
'IM_SHARE_CHAT_CHAT_WELCOME', Array(
94 $pinMessageId = $this->SendMessage(
'', $noticeMessage,
$message);
96 \Bitrix\Im\Model\ChatTable::update($chatId, Array(
97 'PARENT_ID' => $parentChatId,
98 'PARENT_MID' => $parentMessageId,
99 'PIN_MESSAGE_ID' => $pinMessageId,
107 if (!CModule::IncludeModule(
"tasks"))
118 $taskTitle = mb_substr(trim(preg_replace(
119 [
"/\n+/isu",
'/\s+/isu'],
127 $fields[
'RESPONSIBLE_ID'] = $this->user_id;
131 && !\
Bitrix\Im\User::getInstance(
$message[
'AUTHOR_ID'])->isExtranet()
138 $fields[
'CREATED_BY'] = $this->user_id;
142 $diskUf = \Bitrix\Tasks\Integration\Disk\UserField::getMainSysUFCode();
143 $fields[$diskUf] = array_map(
function($value){
return 'n'.$value;}, array_keys(
$message[
'FILES']));
146 $messageParams = Array();
149 $messageParams = Array(
'LINK_ACTIVE' => Array((
string)$this->user_id, (
string)
$message[
'AUTHOR_ID']));
153 $chat = \Bitrix\Im\Model\ChatTable::getById(
$message[
'CHAT_ID'])->fetch();
154 if ($chat[
'ENTITY_TYPE'] ==
'LINES' && CModule::IncludeModule(
'crm'))
156 $fieldData = explode(
"|", $chat[
'ENTITY_DATA_1']);
157 if (isset($fieldData[0]) && $fieldData[0] ==
'Y' && isset($fieldData[1]) && isset($fieldData[2]))
159 $crmType = \CCrmOwnerTypeAbbr::ResolveByTypeID(\CCrmOwnerType::ResolveID($fieldData[1]));
160 $fields[
'UF_CRM_TASK'] = [$crmType .
'_' . $fieldData[2]];
163 if ($chat[
'ENTITY_TYPE'] ==
'SONET_GROUP')
165 $fields[
'GROUP_ID'] = $chat[
'ENTITY_ID'];
167 else if ($chat[
'ENTITY_TYPE'] !=
'SONET_GROUP')
169 $messageParams = Array(
'LINK_ACTIVE' => Array((
string)$this->user_id, (
string)
$message[
'AUTHOR_ID']));
173 $date = intval($date);
181 if (!empty($results))
183 $fields[
'DEADLINE'] = $results[0]->getDate();
184 $userOffset = CTimeZone::GetOffset();
185 if ($userOffset != 0)
187 $fields[
'DEADLINE']->add(($userOffset*-1).
' SECONDS');
194 $handler = new \Bitrix\Tasks\Control\Task($this->user_id);
197 $task = $handler->add(
$fields);
199 catch (Exception $exception)
201 \Bitrix\Tasks\Internals\Log\LogFacade::logThrowable($exception);
205 $taskItem = new \Bitrix\Im\V2\Link\Task\TaskItem();
207 ->setEntityId($task->getId())
210 ->setAuthorId($this->user_id)
214 $link = CTaskNotifications::getNotificationPath(
array(
'ID' => $this->user_id), $task->getId());
216 $this->SendMessage(
'',
GetMessage(
'IM_SHARE_CHAT_TASK', Array(
'#LINK#' => $link)),
$message, $messageParams,
true);
223 if (!CModule::IncludeModule(
"calendar"))
233 $dateFrom->add(
'1 DAY');
235 $date = intval($date);
243 if (!empty($results))
245 $dateFrom = $results[0]->getDate();
249 $userOffset = CTimeZone::GetOffset();
250 if ($userOffset != 0)
252 $dateFrom->add(($userOffset*-1).
' SECONDS');
255 $dateTo = clone $dateFrom;
256 $dateTo->add(
'30 MINUTES');
258 $eventId = CCalendar::SaveEvent(
array(
260 'CAL_TYPE' =>
'user',
261 'OWNER_ID' => $this->user_id,
263 'DESCRIPTION' => self::PrepareText(
$message),
264 'SKIP_TIME' =>
false,
265 'DATE_FROM' => $dateFrom,
266 'DATE_TO' => $dateTo,
268 'userId' => $this->user_id,
269 'autoDetectSection' =>
true,
270 'autoCreateSection' =>
true
280 $messageParams = Array(
'LINK_ACTIVE' => Array((
string)$this->user_id));
282 $this->SendMessage(
'',
GetMessage(
'IM_SHARE_CHAT_CALEND', Array(
'#LINK#' => $link)),
$message, $messageParams,
true);
290 if (!CModule::IncludeModule(
"socialnetwork") || !CModule::IncludeModule(
"blog"))
298 $pathToPost = COption::GetOptionString(
"socialnetwork",
"userblogpost_page",
"/company/personal/user/#user_id#/blog/#post_id#/",
SITE_ID);
299 $pathToSmile = COption::GetOptionString(
"socialnetwork",
"smile_page",
false,
SITE_ID);
300 $blogGroupID = COption::GetOptionString(
"socialnetwork",
"userbloggroup_id",
false,
SITE_ID);
304 $blog = $this->SonetPostCreateBlog($this->user_id, $blogGroupID,
SITE_ID);
306 $title = trim(preg_replace(
307 array(
"/\n+/isu",
'/\s+/isu'),
315 $sonetRights = Array();
316 $messageParams = Array();
317 if (
$message[
'CHAT_ID'] == CIMChat::GetGeneralChatId())
319 if (!\
Bitrix\Socialnetwork\ComponentHelper::getAllowToAllDestination($this->user_id))
321 $sonetRights[] =
"U".$this->user_id;
322 $messageParams = Array(
'LINK_ACTIVE' => Array((
string)$this->user_id));
329 $chat = \Bitrix\Im\Model\ChatTable::getById(
$message[
'CHAT_ID'])->fetch();
331 $chat[
'ENTITY_TYPE'] ===
'SONET_GROUP'
332 && \
Bitrix\Main\Loader::includeModule(
'socialnetwork')
336 CSocNetFeaturesPerms::canPerformOperation($this->user_id,
SONET_ENTITY_GROUP, $chat[
'ENTITY_ID'],
'blog',
'write_post')
337 || CSocNetFeaturesPerms::canPerformOperation($this->user_id,
SONET_ENTITY_GROUP, $chat[
'ENTITY_ID'],
'blog',
'moderate_post')
338 || CSocNetFeaturesPerms::canPerformOperation($this->user_id,
SONET_ENTITY_GROUP, $chat[
'ENTITY_ID'],
'blog',
'full_post')
341 $sonetRights =
array(
'SG' . $chat[
'ENTITY_ID']);
351 if (empty($sonetRights))
353 $relations = CIMChat::GetRelationById(
$message[
'CHAT_ID'],
false,
true,
false);
355 foreach ($relations as $relation)
357 if (\
Bitrix\Im\User::getInstance($relation[
'USER_ID'])->isActive())
359 $sonetRights[] =
"U".$relation[
'USER_ID'];
366 'DETAIL_TEXT' => $messagePost,
367 'DETAIL_TEXT_TYPE' =>
'text',
368 '=DATE_PUBLISH' =>
$DB->CurrentTimeFunction(),
371 'PATH' => CComponentEngine::MakePathFromTemplate($pathToPost,
array(
"post_id" =>
"#post_id#",
"user_id" => $this->user_id)),
372 'URL' => $blog[
'URL'],
373 'PERMS_POST' =>
array(),
374 'PERMS_COMMENT' =>
array(),
376 'SOCNET_RIGHTS' => $sonetRights,
377 '=DATE_CREATE' =>
$DB->CurrentTimeFunction(),
378 'AUTHOR_ID' => $this->user_id,
379 'BLOG_ID' => $blog[
'ID'],
383 "HAS_SOCNET_ALL" =>
"N",
384 "SEARCH_GROUP_ID" => $blogGroupID,
385 "UF_BLOG_POST_FILE" =>
$message[
'FILES']? array_map(
function($value){
return 'n'.$value;}, array_keys(
$message[
'FILES'])): Array()
388 $newId = CBlogPost::add($postFields);
392 $postFields[
"ID"] = $newId;
394 $arParamsNotify = Array(
396 "UserID" => $this->user_id,
397 "allowVideo" => COption::GetOptionString(
"blog",
"allow_video",
"Y"),
398 "PATH_TO_SMILE" => $pathToSmile,
399 "PATH_TO_POST" => $pathToPost,
400 "user_id" => $this->user_id,
401 "NAME_TEMPLATE" => CSite::GetNameFormat(
false),
408 $link = str_replace(
array(
"#post_id#",
"#user_id#"), Array($postFields[
"ID"], $this->user_id), $pathToPost);
411 $this->SendMessage(
'',
GetMessage(
'IM_SHARE_CHAT_POST_2', Array(
'#LINK#' => $processed[
"URLS"][
"BLOG"])),
$message, $messageParams);
416 private function SonetPostCreateBlog(
$userId, $blogGroupId,
$siteId)
420 "=DATE_UPDATE" =>
$DB->CurrentTimeFunction(),
421 "GROUP_ID" => $blogGroupId,
423 "ENABLE_COMMENTS" =>
"Y",
424 "ENABLE_IMG_VERIF" =>
"Y",
425 "EMAIL_NOTIFY" =>
"Y",
428 "ENABLE_TRACKBACK" =>
"N",
429 "SEARCH_INDEX" =>
"Y",
431 "=DATE_CREATE" =>
$DB->CurrentTimeFunction(),
432 "PERMS_POST" => Array(
435 "PERMS_COMMENT" => Array(
441 $rsUser = CUser::GetByID(
$userId);
442 $arUser = $rsUser->Fetch();
443 if($arUser[
"NAME"].
"".$arUser[
"LAST_NAME"] ==
'')
449 $arFields[
"NAME"] =
GetMessage(
"SNBPA_BLOG_NAME").
" ".$arUser[
"NAME"].
" ".$arUser[
"LAST_NAME"];
452 $arFields[
"URL"] = str_replace(
" ",
"_", $arUser[
"LOGIN"]).
"-blog-".
$siteId;
455 $urlCheck = preg_replace(
"/[^a-zA-Z0-9_-]/is",
"",
$arFields[
"URL"]);
490 $popupOptions = CTasksTools::getPopupOptions();
492 'ALLOW_CHANGE_DEADLINE' =>
true,
493 'MATCH_WORK_TIME' =>
false,
494 'TASK_CONTROL' => ($popupOptions[
'task_control'] ===
'Y'),
495 'ALLOW_TIME_TRACKING' => ($popupOptions[
'time_tracking'] ===
'Y'),
497 $formStateOptions = Util\Type::unSerializeArray(Util\User::getOption(
'task_edit_form_state'));
499 if (is_array($formStateOptions) && array_key_exists(
'FLAGS', $formStateOptions))
501 $flags = array_merge($flags, $formStateOptions[
'FLAGS']);
504 foreach ($flags as
$name => $value)
514 $quoteMessage[
'MESSAGE'] = preg_replace(
"/\[SEND(?:=(.+?))?\](.+?)?\[\/SEND\]/i",
"$2", $quoteMessage[
'MESSAGE']);
515 $quoteMessage[
'MESSAGE'] = preg_replace(
"/\[PUT(?:=(.+?))?\](.+?)?\[\/PUT\]/i",
"$2", $quoteMessage[
'MESSAGE']);
516 $quoteMessage[
'MESSAGE'] = preg_replace(
"/\[CALL(?:=(.+?))?\](.+?)?\[\/CALL\]/i",
"$2", $quoteMessage[
'MESSAGE']);
518 $quoteMessage[
'MESSAGE'] = preg_replace(
"/(?:-{54}\n)(.[^\[\n]+)(?:.[^\n]*)?(.+?)(?:-{54})/s",
'[QUOTE][B]$1[/B]$2[/QUOTE]', $quoteMessage[
'MESSAGE']);
523 $chat = \Bitrix\Im\Model\ChatTable::getById($quoteMessage[
'CHAT_ID'])->fetch();
526 $url = $chat[
'ENTITY_TYPE'] ==
'LINES'?
'imol|'.$chat[
'ENTITY_ID']:
'chat'.$chat[
'ID'];
527 $messageContext = isset($quoteMessage[
'MESSAGE_ID']) ?
'&IM_MESSAGE=' . (int)$quoteMessage[
'MESSAGE_ID'] :
'';
528 $result .=
"[B]".GetMessage(
'IM_SHARE_CHAT').
":[/B] [URL=/online/?IM_DIALOG=".
$url.$messageContext.
"]".$chat[
'TITLE'].
"[/URL]\n";
533 $result .=
"[B]".$userName.
"[/B]\n";
536 if (!empty($quoteMessage[
'FILES']))
538 foreach ($quoteMessage[
'FILES'] as $file)
540 $result .=
"[".GetMessage(
"IM_SHARE_FILE").
": ".$file[
'name'].
"]\n";
548 private function SendMessage($startText, $endText, $quoteMessage, $messageParams = Array(),
bool $skipUrlIndex =
false)
551 $messageDate =
FormatDate(
'X', $quoteMessage[
'DATE_CREATE'], time() + CTimeZone::GetOffset());
554 $sendMessage = $startText;
555 $sendMessage .=
"------------------------------------------------------\n";
556 $sendMessage .=
$userName.
" [".$messageDate.
"]\n";
557 if (trim($quoteMessage[
'MESSAGE']))
559 $sendMessage .= $quoteMessage[
'MESSAGE'].
"\n";
561 if (!empty($quoteMessage[
'FILES']))
563 foreach ($quoteMessage[
'FILES'] as $fileId => $file)
565 $sendMessage .=
"[".GetMessage(
"IM_SHARE_FILE").
": ".$file[
'name'].
"]\n";
568 $sendMessage .=
"------------------------------------------------------\n";
569 $sendMessage .= $endText;
571 $messageParams[
'CLASS'] =
"bx-messenger-content-item-system";
575 if ($quoteMessage[
'AUTHOR_ID'] == $this->user_id)
577 $relation = \Bitrix\Im\Model\RelationTable::getList(Array(
578 'select' => Array(
'USER_ID'),
580 '=CHAT_ID' => $quoteMessage[
'CHAT_ID'],
581 '!=USER_ID' => $quoteMessage[
'AUTHOR_ID'],
586 $quoteMessage[
'AUTHOR_ID'] = $relation[
'USER_ID'];
591 'FROM_USER_ID' => $this->user_id,
592 'TO_USER_ID' => $quoteMessage[
'AUTHOR_ID'],
593 'MESSAGE' => $sendMessage,
594 'PARAMS' => $messageParams,
595 'URL_PREVIEW' =>
'N',
596 'SKIP_CONNECTOR' =>
'Y',
597 'SKIP_COMMAND' =>
'Y',
598 'SILENT_CONNECTOR' =>
'Y',
599 'SKIP_URL_INDEX' => $skipUrlIndex ?
'Y' :
'N',
604 $chat = \Bitrix\Im\Model\ChatTable::getById($quoteMessage[
'CHAT_ID'])->fetch();
605 if ($chat[
'ENTITY_TYPE'] ===
'ANNOUNCEMENT')
608 'FROM_USER_ID' => $this->user_id,
609 'TO_USER_ID' => $this->user_id,
610 'MESSAGE' => $sendMessage,
611 'PARAMS' => $messageParams,
612 'URL_PREVIEW' =>
'N',
613 'SKIP_CONNECTOR' =>
'Y',
614 'SKIP_COMMAND' =>
'Y',
615 'SILENT_CONNECTOR' =>
'Y',
616 'SKIP_URL_INDEX' => $skipUrlIndex ?
'Y' :
'N',
622 'TO_CHAT_ID' => $quoteMessage[
'CHAT_ID'],
623 'MESSAGE' => $sendMessage,
624 'PARAMS' => $messageParams,
626 'URL_PREVIEW' =>
'N',
627 'SKIP_CONNECTOR' =>
'Y',
628 'SKIP_COMMAND' =>
'Y',
629 'SILENT_CONNECTOR' =>
'Y',
630 'SKIP_URL_INDEX' => $skipUrlIndex ?
'Y' :
'N',
const BLOG_PUBLISH_STATUS_PUBLISH
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getRelation($chatId, $params=[])
static getInstance($userId=null)
static decode($text, $limit=0)
static createFromTimestamp($timestamp)
static GetByOwnerID($ID, $arGroup=Array())
static GetByUrl($BLOG_URL, $arGroup=Array())
static Notify($arPost, $arBlog, $arParams)
static GetOperationPerm($type, $id, $feature, $operation)
static AddSocnetRead($ID)
static urlAddParams($url, $add_params, $options=[])
static AddMessage($arFields)
static PrepareText($quoteMessage)
Task($messageId, $date='')
Calendar($messageId, $date='')
__construct($user_id=null)
static clearAllTags($text)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
HTMLToTxt($str, $strSiteUrl="", $aDelete=[], $maxlen=70)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
BXClearCache($full=false, $initdir='')
const SONET_RELATIONS_TYPE_ALL