229 public static function send($params): bool
232 !Loader::includeModule(
'intranet')
233 || !Loader::includeModule(
'pull')
240 empty($params[
'ENTITY_TYPE'])
241 || $params[
'ENTITY_TYPE'] !==
'POST'
242 || empty($params[
'ENTITY_ID'])
243 || empty($params[
'AUTHOR_ID'])
244 || empty($params[
'URL'])
245 || empty($params[
'SOCNET_RIGHTS'])
246 || !is_array($params[
'SOCNET_RIGHTS'])
252 if (empty($params[
'SITE_ID']))
254 $params[
'SITE_ID'] = SITE_ID;
257 $res = Main\UserTable::getList([
259 '=ID' => (
int)$params[
'AUTHOR_ID'],
261 'select' => [
'ID',
'PERSONAL_GENDER',
'NAME',
'LAST_NAME',
'SECOND_NAME',
'LOGIN' ],
264 if ($author = $res->fetch())
266 $author[
'NAME_FORMATTED'] = \CUser::formatName(\CSite::getNameFormat(
null, $params[
'SITE_ID']), $author,
true);
267 switch($author[
'PERSONAL_GENDER'])
270 $authorSuffix =
'_M';
273 $authorSuffix =
'_F';
284 $params[
'SOCNET_RIGHTS'] = array_map(
static function ($right) {
285 return ($right ===
'G2' ?
'UA' : $right);
286 }, $params[
'SOCNET_RIGHTS']);
289 !empty($params[
'SOCNET_RIGHTS_OLD'])
290 && is_array($params[
'SOCNET_RIGHTS_OLD'])
294 foreach ($params[
'SOCNET_RIGHTS_OLD'] as $entities)
296 foreach ($entities as $rightsList)
298 foreach ($rightsList as $right)
300 $rightsOld[] = ($right ===
'G2' ?
'UA' : $right);
304 $params[
'SOCNET_RIGHTS'] = array_diff($params[
'SOCNET_RIGHTS'], $rightsOld);
310 'SKIP' => (int)$params[
'AUTHOR_ID'],
314 foreach ($params[
'SOCNET_RIGHTS'] as $right)
321 $userListParams[
'SITE_ID'] = $params[
'SITE_ID'];
324 elseif (preg_match(
'/^DR(\d+)$/', $right, $matches))
326 $userListParams[
'DEPARTMENTS'][] = $matches[1];
333 $userList = \Bitrix\Intranet\Util::getEmployeesList($userListParams);
336 if (empty($userList))
342 $params[
'ENTITY_TYPE'] ===
'POST'
343 && ($post = \CBlogPost::getById($params[
'ENTITY_ID']))
344 && !empty($post[
'PUBLISH_STATUS'])
345 && ($post[
'PUBLISH_STATUS'] === BLOG_PUBLISH_STATUS_PUBLISH)
348 $titleTmp = str_replace([
"\r\n",
"\n" ],
' ', $post[
'TITLE']);
349 $title = truncateText($titleTmp, 100);
350 $titleEmail = ($post[
'MICRO'] !==
'Y' ? truncateText($titleTmp, 255) :
'');
352 $titleEmpty = (trim($title,
" \t\n\r\0\x0B\xA0" ) ===
'');
355 'BLOG_BROADCAST_PUSH_POST' . ($titleEmpty ?
'A' :
'') . $authorSuffix,
357 '#author#' => $author[
'NAME_FORMATTED'],
362 $userIdList = array_keys($userList);
364 !empty($params[
'EXCLUDE_USERS'])
365 && is_array($params[
'EXCLUDE_USERS'])
368 $userIdList = array_diff($userIdList, $params[
'EXCLUDE_USERS']);
371 if (!empty($userIdList))
375 \Bitrix\Pull\Push::add($userIdListPush, [
376 'module_id' =>
'blog',
378 'message' => $message,
381 'TAG' =>
'BLOG|POST|' . $params[
'ENTITY_ID']
383 'tag' =>
'BLOG|POST|' . $params[
'ENTITY_ID'],
384 'send_immediately' =>
'Y',
388 $offlineUserIdList = [];
392 $deviceInfo = \CPushManager::getDeviceInfo($mailRecipients);
393 if (is_array($deviceInfo))
395 foreach ($deviceInfo as $userId => $info)
400 \CPushManager::SEND_DEFERRED,
401 \CPushManager::RECORD_NOT_FOUND,
406 $offlineUserIdList[] = $userId;
411 if (!empty($offlineUserIdList))
413 $res = Main\UserTable::getList([
415 '=SEND_EMAIL' =>
'Y',
416 '@ID' => $offlineUserIdList,
419 new Main\
Entity\
ExpressionField(
'SEND_EMAIL',
'CASE WHEN LAST_ACTIVITY_DATE IS NOT NULL AND LAST_ACTIVITY_DATE > ' . Main\
Application::getConnection()->getSqlHelper()->addSecondsToDateTime(
'-' . (60*60*24*90)) .
" THEN 'Y' ELSE 'N' END"),
421 'select' => [
'ID' ],
424 $offlineUserIdList = [];
425 while ($ar = $res->fetch())
427 $offlineUserIdList[] = $ar[
'ID'];
431 if (!empty($offlineUserIdList))
435 $res = \CSite::getByID($params[
'SITE_ID']);
436 if ($site = $res->fetch())
438 $serverName = $site[
'SERVER_NAME'];
440 if (empty($serverName))
443 defined(
'SITE_SERVER_NAME')
444 && SITE_SERVER_NAME <>
''
446 : Option::get(
'main',
'server_name', $_SERVER[
'SERVER_NAME'])
450 $serverName = (\CMain::isHTTPS() ?
'https' :
'http') .
'://' . $serverName;
452 $textEmail = $post[
'DETAIL_TEXT'];
453 if ($post[
'DETAIL_TEXT_TYPE'] ===
'html')
455 $textEmail = HTMLToTxt($textEmail);
460 $parserBlog = new \blogTextParser();
461 $textEmail = $parserBlog->convert4mail($textEmail, $imageList);
463 foreach ($offlineUserIdList as $userId)
465 if (!empty($userList[$userId][
'EMAIL']))
468 'BLOG_POST_BROADCAST',
471 'EMAIL_TO' => (!empty($userList[$userId][
'NAME_FORMATTED']) ?
'' . $userList[$userId][
'NAME_FORMATTED'] .
' <' . $userList[$userId][
'EMAIL'] .
'>' : $userList[$userId][
'EMAIL']),
472 'AUTHOR' => $author[
'NAME_FORMATTED'],
473 'MESSAGE_TITLE' => $titleEmail,
474 'MESSAGE_TEXT' => $textEmail,
475 'MESSAGE_PATH' => $serverName . $params[
'URL'],