PageRenderTime 61ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/lists/classes/general/livefeed.php

https://gitlab.com/alexprowars/bitrix
PHP | 906 lines | 791 code | 99 blank | 16 comment | 102 complexity | 7983827987c40812a994ffbbd4936184 MD5 | raw file
  1. <?php
  2. use Bitrix\Main\Loader;
  3. use Bitrix\Main\Localization\Loc;
  4. Loc::loadMessages(__FILE__);
  5. class CListsLiveFeed
  6. {
  7. public static function setMessageLiveFeed($users, $elementId, $workflowId, $flagCompleteProcess)
  8. {
  9. $elementId = intval($elementId);
  10. $elementObject = CIBlockElement::getList(
  11. array(),
  12. array('ID' => $elementId),
  13. false,
  14. false,
  15. array('ID', 'CREATED_BY', 'IBLOCK_NAME', 'NAME', 'IBLOCK_ID', 'LANG_DIR', 'IBLOCK_CODE')
  16. );
  17. $element = $elementObject->fetch();
  18. if(!CLists::getLiveFeed($element["IBLOCK_ID"]))
  19. return false;
  20. $listSystemIblockCode = array(
  21. 'bitrix_holiday',
  22. 'bitrix_invoice',
  23. 'bitrix_trip',
  24. 'bitrix_cash',
  25. 'bitrix_incoming_doc',
  26. 'bitrix_outgoing_doc'
  27. );
  28. $params = serialize(array("ELEMENT_NAME" => $element['NAME']));
  29. $element['NAME'] = htmlspecialcharsbx($element['NAME']);
  30. if (in_array($element['IBLOCK_CODE'], $listSystemIblockCode))
  31. {
  32. $element['NAME'] = preg_replace_callback(
  33. '#^[^\[\]]+?\[(\d+)\]#i',
  34. function ($matches)
  35. {
  36. $userId = $matches[1];
  37. $db = CUser::GetByID($userId);
  38. if ($ar = $db->GetNext())
  39. {
  40. $ix = randString(5);
  41. return '<a class="feed-post-user-name" href="/company/personal/user/'.$userId.'/"
  42. bx-post-author-id="'.$userId.'" bx-post-author-gender="'.$ar['PERSONAL_GENDER'].'" bx-tooltip-user-id="'.$userId.'">'.CUser::FormatName(CSite::GetNameFormat(false), $ar, true, false).'</a>';
  43. }
  44. return $matches[0];
  45. },
  46. $element['NAME']
  47. );
  48. }
  49. $path = rtrim($element['LANG_DIR'], '/');
  50. $urlElement = $path.COption::GetOptionString('lists', 'livefeed_url').'?livefeed=y&list_id='.$element["IBLOCK_ID"].'&element_id='.$elementId;
  51. $createdBy = $element['CREATED_BY'];
  52. if(!Loader::includeModule('socialnetwork') || $createdBy <= 0)
  53. return false;
  54. $sourceId = CBPStateService::getWorkflowIntegerId($workflowId);
  55. $logId = 0;
  56. $userObject = CUser::getByID($createdBy);
  57. $siteId = array();
  58. $siteObject = CSite::getList("sort", "desc", array("ACTIVE" => "Y"));
  59. while ($site = $siteObject->fetch())
  60. $siteId[] = $site['LID'];
  61. if ($userObject->fetch())
  62. {
  63. global $DB;
  64. $soFields = Array(
  65. 'ENTITY_TYPE' => SONET_LISTS_NEW_POST_ENTITY,
  66. 'EVENT_ID' => 'lists_new_element',
  67. 'ENTITY_ID' => 1,
  68. '=LOG_UPDATE' => $DB->currentTimeFunction(),
  69. 'SOURCE_ID' => $sourceId,
  70. 'USER_ID' => $createdBy,
  71. 'MODULE_ID' => 'lists',
  72. 'TITLE_TEMPLATE' => $urlElement,
  73. 'TITLE' => $element['IBLOCK_NAME'],
  74. 'PARAMS' => $params,
  75. 'MESSAGE' => $workflowId,
  76. 'CALLBACK_FUNC' => false,
  77. 'SITE_ID' => $siteId,
  78. 'ENABLE_COMMENTS' => 'Y',
  79. 'RATING_TYPE_ID' => 'LISTS_NEW_ELEMENT',
  80. 'RATING_ENTITY_ID' => $sourceId,
  81. 'URL' => '#SITE_DIR#'.COption::GetOptionString('socialnetwork', 'user_page', false, SITE_ID).'log/'
  82. );
  83. $logObject = CSocNetLog::getList(array(), array(
  84. 'ENTITY_TYPE' => $soFields['ENTITY_TYPE'],
  85. 'ENTITY_ID' => $soFields['ENTITY_ID'],
  86. 'EVENT_ID' => $soFields['EVENT_ID'],
  87. 'SOURCE_ID' => $soFields['SOURCE_ID'],
  88. ));
  89. $iblockPicture = CIBlock::getArrayByID($element['IBLOCK_ID'], 'PICTURE');
  90. $imageFile = CFile::getFileArray($iblockPicture);
  91. if($imageFile !== false)
  92. {
  93. $imageFile = CFile::ResizeImageGet(
  94. $imageFile,
  95. array("width" => 36, "height" => 30),
  96. BX_RESIZE_IMAGE_PROPORTIONAL,
  97. false
  98. );
  99. }
  100. if(empty($imageFile['src']))
  101. $imageFile['src'] = '/bitrix/images/lists/default.png';
  102. $soFields['TEXT_MESSAGE'] = '
  103. <span class="bp-title-desc">
  104. <span class="bp-title-desc-icon">
  105. <img src="'.$imageFile['src'].'" width="36" height="30" border="0" />
  106. </span>
  107. '.$element['NAME'].'
  108. </span>
  109. ';
  110. if($log = $logObject->fetch())
  111. {
  112. if (intval($log['ID']) > 0)
  113. {
  114. if(empty($users))
  115. {
  116. CSocNetLog::update($log['ID'], $soFields);
  117. }
  118. else
  119. {
  120. $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
  121. $rights = self::getRights($activeUsers, $log['ID'], $createdBy, 'post');
  122. $usersRight = self::getUserIdForRight($rights);
  123. self::setSocnetFollow($usersRight, $log['ID'], 'Y', true);
  124. /* Recipients tasks bp */
  125. CSocNetLog::update($log['ID'], $soFields);
  126. /* Increment the counter for participants */
  127. CSocNetLogRights::deleteByLogID($log['ID']);
  128. $rightsCounter = self::getRights($users, $log['ID'], $createdBy, 'counter');
  129. CSocNetLogRights::add($log['ID'], $rightsCounter, false, false);
  130. CSocNetLog::counterIncrement($log['ID'], $soFields['EVENT_ID'], false, 'L', false);
  131. /* Return previous state rights */
  132. CSocNetLogRights::deleteByLogID($log['ID']);
  133. CSocNetLogRights::add($log['ID'], $rights, false, false);
  134. self::setSocnetFollow($users, $log['ID'], 'Y');
  135. self::setSocnetFollow($users, $log['ID'], 'N');
  136. }
  137. /* Completion of the process for the author */
  138. if ($flagCompleteProcess)
  139. {
  140. $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
  141. $rights = self::getRights($activeUsers, $log['ID'], $createdBy, 'post');
  142. $usersRight = self::getUserIdForRight($rights);
  143. /* Increment the counter for author */
  144. $users[] = $createdBy;
  145. CSocNetLogRights::deleteByLogID($log['ID']);
  146. $rightsCounter = self::getRights($users, $log['ID'], $createdBy, 'counter');
  147. CSocNetLogRights::add($log['ID'], $rightsCounter, false, false);
  148. CSocNetLog::counterIncrement($log['ID'], $soFields['EVENT_ID'], false, 'L', false);
  149. /* Return previous state rights */
  150. CSocNetLogRights::deleteByLogID($log['ID']);
  151. CSocNetLogRights::add($log['ID'], $rights, false, false);
  152. self::setSocnetFollow($users, $log['ID'], 'Y');
  153. self::setSocnetFollow($usersRight, $log['ID'], 'N');
  154. }
  155. }
  156. }
  157. else
  158. {
  159. $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
  160. $soFields['=LOG_DATE'] = $DB->currentTimeFunction();
  161. $logId = CSocNetLog::add($soFields, false);
  162. if (intval($logId) > 0)
  163. {
  164. $rights = self::getRights($activeUsers, $logId, $createdBy, 'post');
  165. CSocNetLogRights::add($logId, $rights, false, false);
  166. $usersRight = self::getUserIdForRight($rights);
  167. self::setSocnetFollow($usersRight, $logId, 'N');
  168. }
  169. CSocNetLog::counterIncrement($logId, $soFields['EVENT_ID'], false, 'L', false);
  170. }
  171. }
  172. return $logId;
  173. }
  174. public static function onFillSocNetAllowedSubscribeEntityTypes(&$socnetEntityTypes)
  175. {
  176. $socnetEntityTypes[] = SONET_LISTS_NEW_POST_ENTITY;
  177. global $arSocNetAllowedSubscribeEntityTypesDesc;
  178. $arSocNetAllowedSubscribeEntityTypesDesc[SONET_LISTS_NEW_POST_ENTITY] = array(
  179. 'USE_CB_FILTER' => 'Y',
  180. 'TITLE_LIST' => '',
  181. 'TITLE_ENTITY' => ''
  182. );
  183. }
  184. public static function onFillSocNetLogEvents(&$socnetLogEvents)
  185. {
  186. $socnetLogEvents['lists_new_element'] = array(
  187. 'ENTITIES' => array(
  188. SONET_LISTS_NEW_POST_ENTITY => array(),
  189. ),
  190. 'FORUM_COMMENT_ENTITY' => 'WF',
  191. 'CLASS_FORMAT' => 'CListsLiveFeed',
  192. 'METHOD_FORMAT' => 'formatListsElement',
  193. 'HAS_CB' => 'Y',
  194. 'FULL_SET' => array('lists_new_element', 'lists_new_element_comment'),
  195. 'COMMENT_EVENT' => array(
  196. 'MODULE_ID' => 'lists_new_element',
  197. 'EVENT_ID' => 'lists_new_element_comment',
  198. 'OPERATION' => 'view',
  199. 'OPERATION_ADD' => 'log_rights',
  200. 'ADD_CALLBACK' => array('CListsLiveFeed', 'addCommentLists'),
  201. 'UPDATE_CALLBACK' => array('CSocNetLogTools', 'UpdateComment_Forum'),
  202. 'DELETE_CALLBACK' => array('CSocNetLogTools', 'DeleteComment_Forum'),
  203. 'CLASS_FORMAT' => 'CSocNetLogTools',
  204. 'METHOD_FORMAT' => 'FormatComment_Forum',
  205. "RATING_TYPE_ID" => "FORUM_POST"
  206. )
  207. );
  208. }
  209. public static function formatListsElement($fields, $params, $mail = false)
  210. {
  211. global $CACHE_MANAGER;
  212. $element = array(
  213. 'EVENT' => $fields,
  214. 'CREATED_BY' => array(),
  215. 'ENTITY' => array(),
  216. 'EVENT_FORMATTED' => array(),
  217. );
  218. $userObject = CUser::getByID($fields['ENTITY_ID']);
  219. $user = $userObject->fetch();
  220. if ($user)
  221. {
  222. if(!$mail)
  223. {
  224. global $APPLICATION;
  225. $rights = array();
  226. $rightsQuery = CSocNetLogRights::getList(array(), array('LOG_ID' => $fields['ID']));
  227. while ($right = $rightsQuery->fetch())
  228. {
  229. $rights[] = $right['GROUP_CODE'];
  230. }
  231. if(defined('BX_COMP_MANAGED_CACHE'))
  232. {
  233. $CACHE_MANAGER->registerTag('LISTS_ELEMENT_LIVE_FEED');
  234. }
  235. $componentResult = $APPLICATION->includeComponent(
  236. 'bitrix:bizproc.workflow.livefeed',
  237. '',
  238. Array(
  239. 'WORKFLOW_ID' => $fields['MESSAGE'],
  240. 'SITE_TEMPLATE_ID' => (isset($params['SITE_TEMPLATE_ID']) ? $params['SITE_TEMPLATE_ID'] : '')
  241. ),
  242. null,
  243. array('HIDE_ICONS' => 'Y')
  244. );
  245. $siteDir = rtrim(SITE_DIR, '/');
  246. $url = CSocNetLogTools::formatEvent_GetURL($fields, true);
  247. $url = str_replace('#SITE_DIR#', $siteDir, $url);
  248. $url .= ''.$fields['ID'].'/';
  249. $element = array(
  250. 'EVENT' => $fields,
  251. 'EVENT_FORMATTED' => array(
  252. 'TITLE_24' => '<a href="'.$fields['TITLE_TEMPLATE'].'" class="bx-lists-live-feed-title-link">'.$fields['TITLE'].'</a>',
  253. 'MESSAGE' => $fields['TEXT_MESSAGE'].$componentResult['MESSAGE'],
  254. 'IS_IMPORTANT' => false,
  255. 'STYLE' => 'new-employee',
  256. 'AVATAR_STYLE' => 'avatar-info',
  257. 'DESTINATION' => CSocNetLogTools::formatDestinationFromRights($rights, array_merge($params, array('CREATED_BY' => $fields['USER_ID']))),
  258. 'URL' => $url
  259. ),
  260. 'CREATED_BY' => CSocNetLogTools::formatEvent_GetCreatedBy($fields, $params, $mail),
  261. 'AVATAR_SRC' => CSocNetLog::formatEvent_CreateAvatar($fields, $params),
  262. 'CACHED_JS_PATH' => $componentResult['CACHED_JS_PATH'],
  263. 'CACHED_CSS_PATH' => $componentResult['CACHED_CSS_PATH']
  264. );
  265. if ($params['MOBILE'] == 'Y')
  266. {
  267. $element['EVENT_FORMATTED']['TITLE_24'] = Loc::getMessage('LISTS_LF_MOBILE_DESTINATION');
  268. $element['EVENT_FORMATTED']['TITLE_24_2'] = $fields['TITLE'];
  269. unset($element['CACHED_CSS_PATH']);
  270. }
  271. if (CModule::IncludeModule('bizproc'))
  272. {
  273. $workflowId = \CBPStateService::getWorkflowByIntegerId($element['EVENT']['SOURCE_ID']);
  274. }
  275. if ($workflowId)
  276. {
  277. $element['EVENT']['SOURCE_ID'] = $workflowId;
  278. }
  279. }
  280. return $element;
  281. }
  282. }
  283. public static function addCommentLists($fields)
  284. {
  285. global $DB, $USER_FIELD_MANAGER;
  286. if (!CModule::IncludeModule('forum') || !CModule::IncludeModule('bizproc'))
  287. return false;
  288. $ufFileId = array();
  289. $ufDocId = array();
  290. $fieldsMessage = array();
  291. $messageId = array();
  292. $error = array();
  293. $note = array();
  294. $sonetLogQuery = CSocNetLog::GetList(
  295. array(),
  296. array('ID' => $fields['LOG_ID']),
  297. false,
  298. false,
  299. array('ID', 'SOURCE_ID', 'SITE_ID', 'MESSAGE', 'USER_ID')
  300. );
  301. if($sonetLog = $sonetLogQuery->fetch())
  302. {
  303. $users = CBPTaskService::getWorkflowParticipants($sonetLog['MESSAGE'], CBPTaskUserStatus::Waiting);
  304. if(preg_match_all("/(?<=\[USER=)(?P<id>[0-9]+)(?=\])/", $fields['TEXT_MESSAGE'], $matches))
  305. $users = array_unique(array_merge($users, $matches['id']));
  306. $users[] = $sonetLog['USER_ID'];
  307. self::setSocnetFollow($users, $sonetLog['ID'], 'Y', false, true);
  308. $forumId = CBPHelper::getForumId();
  309. if($forumId)
  310. {
  311. $topicQuery = CForumTopic::GetList(array(), array('FORUM_ID' => $forumId, 'XML_ID' => 'WF_'.$sonetLog['MESSAGE']));
  312. if ($topicQuery && ($topic = $topicQuery->fetch()))
  313. {
  314. $topicId = $topic['ID'];
  315. }
  316. else
  317. {
  318. $dataTopic = array(
  319. 'AUTHOR_ID' => 0,
  320. 'TITLE' => 'WF_'.$sonetLog['MESSAGE'],
  321. 'TAGS' => '',
  322. 'MESSAGE' => 'WF_'.$sonetLog['MESSAGE'],
  323. 'XML_ID' => 'WF_'.$sonetLog['MESSAGE']
  324. );
  325. $userStart = array(
  326. "ID" => $dataTopic["AUTHOR_ID"],
  327. "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]
  328. );
  329. $DB->StartTransaction();
  330. $topicFields = Array(
  331. "TITLE" => $dataTopic["TITLE"],
  332. "TAGS" => $dataTopic["TAGS"],
  333. "FORUM_ID" => $forumId,
  334. "USER_START_ID" => $userStart["ID"],
  335. "USER_START_NAME" => $userStart["NAME"],
  336. "LAST_POSTER_NAME" => $userStart["NAME"],
  337. "XML_ID" => $dataTopic["XML_ID"],
  338. "APPROVED" => "Y",
  339. "PERMISSION_EXTERNAL" =>'Q',
  340. "PERMISSION" => 'Y',
  341. );
  342. $topicId = CForumTopic::Add($topicFields);
  343. if (intval($topicId) > 0)
  344. {
  345. $dataTopic['MESSAGE'] = strip_tags($dataTopic['MESSAGE']);
  346. $dataFields = Array(
  347. "POST_MESSAGE" => $dataTopic['MESSAGE'],
  348. "AUTHOR_ID" => $userStart["ID"],
  349. "AUTHOR_NAME" => $userStart["NAME"],
  350. "FORUM_ID" => $forumId,
  351. "TOPIC_ID" => $topicId,
  352. "APPROVED" => "Y",
  353. "NEW_TOPIC" => "Y",
  354. "PARAM1" => "WF",
  355. "PARAM2" => 0,
  356. "PERMISSION_EXTERNAL" => 'Q',
  357. "PERMISSION" => 'Y',
  358. );
  359. $startMessageId = CForumMessage::Add($dataFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
  360. if (intval($startMessageId) <= 0)
  361. {
  362. CForumTopic::Delete($topicId);
  363. $topicId = 0;
  364. }
  365. }
  366. if (intval($topicId) <= 0)
  367. {
  368. $DB->Rollback();
  369. }
  370. else
  371. {
  372. $DB->Commit();
  373. }
  374. }
  375. if ($topicId)
  376. {
  377. $fieldsMessage = array(
  378. 'POST_MESSAGE' => $fields['TEXT_MESSAGE'],
  379. 'USE_SMILES' => 'Y',
  380. 'PERMISSION_EXTERNAL' => 'Q',
  381. 'PERMISSION' => 'Y',
  382. 'APPROVED' => 'Y'
  383. );
  384. $tmp = false;
  385. $USER_FIELD_MANAGER->editFormAddFields('SONET_COMMENT', $tmp);
  386. if (is_array($tmp))
  387. {
  388. if (array_key_exists('UF_SONET_COM_DOC', $tmp))
  389. {
  390. $GLOBALS['UF_FORUM_MESSAGE_DOC'] = $tmp['UF_SONET_COM_DOC'];
  391. }
  392. elseif (array_key_exists('UF_SONET_COM_FILE', $tmp))
  393. {
  394. $fieldsMessage['FILES'] = array();
  395. foreach($tmp['UF_SONET_COM_FILE'] as $fileId)
  396. {
  397. $fieldsMessage['FILES'][] = array('FILE_ID' => $fileId);
  398. }
  399. }
  400. if (array_key_exists("UF_SONET_COM_URL_PRV", $tmp))
  401. {
  402. $GLOBALS["UF_FORUM_MES_URL_PRV"] = $tmp["UF_SONET_COM_URL_PRV"];
  403. }
  404. }
  405. $messageId = ForumAddMessage("REPLY", $forumId, $topicId, 0, $fieldsMessage, $error, $note);
  406. if ($messageId > 0)
  407. {
  408. $addedMessageFilesQuery = CForumFiles::getList(array('ID' => 'ASC'), array('MESSAGE_ID' => $messageId));
  409. while ($addedMessageFiles = $addedMessageFilesQuery->fetch())
  410. {
  411. $ufFileId[] = $addedMessageFiles['FILE_ID'];
  412. }
  413. $ufDocId = $USER_FIELD_MANAGER->getUserFieldValue('FORUM_MESSAGE', 'UF_FORUM_MESSAGE_DOC', $messageId, LANGUAGE_ID);
  414. $ufUrlPreview = $USER_FIELD_MANAGER->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MES_URL_PRV", $messageId, LANGUAGE_ID);
  415. }
  416. }
  417. }
  418. }
  419. if (!$messageId)
  420. {
  421. $error = Loc::getMessage('LISTS_LF_ADD_COMMENT_SOURCE_ERROR');
  422. }
  423. return array(
  424. 'SOURCE_ID' => $messageId,
  425. 'MESSAGE' => ($fieldsMessage ? $fieldsMessage['POST_MESSAGE'] : false),
  426. 'RATING_TYPE_ID' => 'FORUM_POST',
  427. 'RATING_ENTITY_ID' => $messageId,
  428. 'ERROR' => $error,
  429. 'NOTES' => $note,
  430. 'UF' => array(
  431. 'FILE' => $ufFileId,
  432. 'DOC' => $ufDocId,
  433. 'URL_PREVIEW' => $ufUrlPreview
  434. )
  435. );
  436. }
  437. protected static function getRights($users, $logId, $createdBy, $method)
  438. {
  439. $rights = array();
  440. $rights[] = 'SA'; //socnet admin
  441. if(!empty($users))
  442. {
  443. if($method == 'post')
  444. $users[] = $createdBy;
  445. foreach($users as $userId)
  446. {
  447. $rights[] = 'U'.$userId;
  448. }
  449. }
  450. $rights = array_unique($rights);
  451. return $rights;
  452. }
  453. protected static function getUserIdForRight($rights)
  454. {
  455. $users = array();
  456. foreach($rights as $user)
  457. {
  458. if($user != 'SA')
  459. {
  460. $users[] = mb_substr($user, 1);
  461. }
  462. }
  463. return $users;
  464. }
  465. protected static function setSocnetFollow($users = array(), $logId, $type, $manualMode = false, $addingComment = false)
  466. {
  467. if($manualMode)
  468. {
  469. foreach($users as $userId)
  470. {
  471. $logFollowObject = CSocNetLogFollow::getList(
  472. array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF', 'TYPE'));
  473. $logFollow = $logFollowObject->fetch();
  474. if(!empty($logFollow) && $logFollow['TYPE'] == 'Y' && !$logFollow['BY_WF'])
  475. {
  476. CSocNetLogFollow::delete($userId, 'L'.$logId, false);
  477. CSocNetLogFollow::set($userId, 'L'.$logId, $type,
  478. ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID), SITE_ID, true);
  479. if (
  480. $type == 'Y'
  481. && method_exists('\Bitrix\Socialnetwork\ComponentHelper','userLogSubscribe')
  482. )
  483. {
  484. \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe(array(
  485. 'logId' => $logId,
  486. 'userId' => $userId,
  487. 'typeList' => array(
  488. 'COUNTER_COMMENT_PUSH'
  489. )
  490. ));
  491. }
  492. }
  493. }
  494. }
  495. else
  496. {
  497. if($type == 'Y')
  498. {
  499. foreach($users as $userId)
  500. {
  501. $logFollowObject = CSocNetLogFollow::getList(
  502. array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF'));
  503. $logFollow = $logFollowObject->fetch();
  504. if(
  505. empty($logFollow)
  506. || ($logFollow['BY_WF'] == 'Y' || $addingComment)
  507. )
  508. {
  509. CSocNetLogFollow::delete($userId, 'L'.$logId, false);
  510. if (method_exists('\Bitrix\Socialnetwork\ComponentHelper','userLogSubscribe'))
  511. {
  512. \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe(array(
  513. 'logId' => $logId,
  514. 'userId' => $userId,
  515. 'typeList' => array(
  516. 'FOLLOW',
  517. 'COUNTER_COMMENT_PUSH'
  518. ),
  519. 'followDate' => 'CURRENT',
  520. 'followByWF' => true
  521. ));
  522. }
  523. else
  524. {
  525. CSocNetLogFollow::set($userId, 'L'.$logId, 'Y',
  526. ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID), SITE_ID, true);
  527. }
  528. }
  529. }
  530. }
  531. else
  532. {
  533. foreach($users as $userId)
  534. {
  535. $logFollowObject = CSocNetLogFollow::getList(
  536. array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF'));
  537. $logFollow = $logFollowObject->fetch();
  538. if(
  539. empty($logFollow)
  540. || $logFollow['BY_WF'] == 'Y'
  541. )
  542. {
  543. CSocNetLogFollow::set($userId, 'L'.$logId, 'N', false, SITE_ID, true);
  544. }
  545. }
  546. }
  547. }
  548. }
  549. protected static function getSiteName()
  550. {
  551. return COption::getOptionString('main', 'site_name', '');
  552. }
  553. public static function BeforeIndexSocNet($bxSocNetSearch, $fields)
  554. {
  555. static $bizprocForumId = false;
  556. if (!$bizprocForumId)
  557. {
  558. $bizprocForumId = intval(COption::GetOptionString('bizproc', 'forum_id'));
  559. }
  560. if(
  561. $fields['ENTITY_TYPE_ID'] == 'FORUM_POST'
  562. && intval($fields['PARAM1']) == $bizprocForumId
  563. && !empty($fields['PARAM2'])
  564. && !empty($bxSocNetSearch->_params["PATH_TO_WORKFLOW"])
  565. && CModule::IncludeModule("forum")
  566. && CModule::IncludeModule("bizproc")
  567. )
  568. {
  569. $topic = CForumTopic::GetByID($fields['PARAM2']);
  570. if (
  571. !empty($topic)
  572. && is_array($topic)
  573. && !empty($topic["XML_ID"])
  574. )
  575. {
  576. if (preg_match('/^WF_([0-9a-f\.]+)/', $topic["XML_ID"], $match))
  577. {
  578. $workflowId = $match[1];
  579. $state = CBPStateService::GetStateDocumentId($workflowId);
  580. if (
  581. $state[0] == 'lists'
  582. && $state[1] == 'BizprocDocument'
  583. && CModule::IncludeModule('iblock')
  584. && (intval($state[2]) > 0)
  585. )
  586. {
  587. $iblockElementQuery = CIBlockElement::GetList(
  588. array(),
  589. array(
  590. "ID" => intval($state[2])
  591. ),
  592. false,
  593. false,
  594. array("ID", "IBLOCK_ID")
  595. );
  596. if ($iblockElement = $iblockElementQuery->Fetch())
  597. {
  598. $listId = $iblockElement["IBLOCK_ID"];
  599. $fields["URL"] = $bxSocNetSearch->Url(
  600. str_replace(
  601. array("#list_id#", "#workflow_id#"),
  602. array($listId, urlencode($workflowId)),
  603. $bxSocNetSearch->_params["PATH_TO_WORKFLOW"]
  604. ),
  605. array(
  606. "MID" => $fields["ENTITY_ID"]
  607. ),
  608. "message".$fields["ENTITY_ID"]
  609. );
  610. if (
  611. !empty($fields["LID"])
  612. && is_array($fields["LID"])
  613. )
  614. {
  615. foreach ($fields["LID"] as $siteId => $url)
  616. {
  617. $fields["LID"][$siteId] = $fields["URL"];
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. }
  625. return $fields;
  626. }
  627. /**
  628. * Called from LiveFeed
  629. * @param array $comment
  630. */
  631. public static function OnAfterSonetLogEntryAddComment($comment)
  632. {
  633. if ($comment["EVENT_ID"] != "lists_new_element_comment")
  634. {
  635. return;
  636. }
  637. $logQuery = CSocNetLog::getList(
  638. array(),
  639. array(
  640. "ID" => $comment["LOG_ID"],
  641. "EVENT_ID" => "lists_new_element"
  642. ),
  643. false,
  644. false,
  645. array("SOURCE_ID", "URL", "TITLE", "USER_ID", "PARAMS")
  646. );
  647. if (($log = $logQuery->fetch()) && (intval($log["SOURCE_ID"]) > 0))
  648. {
  649. $params = unserialize($log["PARAMS"]);
  650. $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
  651. CListsLiveFeed::notifyComment(
  652. array(
  653. "LOG_ID" => $comment["LOG_ID"],
  654. "MESSAGE_ID" => $comment["SOURCE_ID"],
  655. "TO_USER_ID" => $log["USER_ID"],
  656. "FROM_USER_ID" => $comment["USER_ID"],
  657. "URL" => $log["URL"],
  658. "TITLE" => $title
  659. )
  660. );
  661. }
  662. }
  663. /**
  664. * Called from popup
  665. * @param string $entityType
  666. * @param int $entityId
  667. * $param array $comment
  668. */
  669. public static function OnForumCommentIMNotify($entityType, $entityId, $comment)
  670. {
  671. if ($entityType != "WF")
  672. return;
  673. $logQuery = CSocNetLog::getList(
  674. array(),
  675. array(
  676. "ID" => $comment["LOG_ID"],
  677. "EVENT_ID" => "lists_new_element"
  678. ),
  679. false,
  680. false,
  681. array("ID", "SOURCE_ID", "URL", "TITLE", "USER_ID", "PARAMS")
  682. );
  683. if (($log = $logQuery->fetch()) && (intval($log["SOURCE_ID"]) > 0))
  684. {
  685. $params = unserialize($log["PARAMS"]);
  686. $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
  687. CListsLiveFeed::notifyComment(
  688. array(
  689. "LOG_ID" => $log["ID"],
  690. "MESSAGE_ID" => $comment["MESSAGE_ID"],
  691. "TO_USER_ID" => $log["USER_ID"],
  692. "FROM_USER_ID" => $comment["USER_ID"],
  693. "URL" => $log["URL"],
  694. "TITLE" => $title
  695. )
  696. );
  697. }
  698. }
  699. public static function NotifyComment($comment)
  700. {
  701. if (!Loader::includeModule("im"))
  702. return;
  703. if($comment["TO_USER_ID"] == $comment["FROM_USER_ID"])
  704. return;
  705. $siteDir = rtrim(SITE_DIR, '/');
  706. $url = str_replace('#SITE_DIR#', $siteDir, $comment["URL"]);
  707. $url .= ''.$comment['LOG_ID'].'/';
  708. $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD",
  709. array("#PROCESS#" => '<a href="'.$url.'" class="bx-notifier-item-action">'.$comment["TITLE"].'</a>'));
  710. $userQuery = CUser::getList(
  711. "id",
  712. "asc",
  713. array("ID_EQUAL_EXACT" => intval($comment["FROM_USER_ID"])),
  714. array("FIELDS" => array("PERSONAL_GENDER"))
  715. );
  716. if ($user = $userQuery->fetch())
  717. {
  718. switch ($user["PERSONAL_GENDER"])
  719. {
  720. case "F":
  721. case "M":
  722. $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD" . '_' . $user["PERSONAL_GENDER"],
  723. array("#PROCESS#" => '<a href="'.$url.'" class="bx-notifier-item-action">'.$comment["TITLE"].'</a>'));
  724. break;
  725. default:
  726. break;
  727. }
  728. }
  729. $messageFields = array(
  730. "TO_USER_ID" => $comment["TO_USER_ID"],
  731. "FROM_USER_ID" => $comment["FROM_USER_ID"],
  732. "NOTIFY_TYPE" => IM_NOTIFY_FROM,
  733. "NOTIFY_MODULE" => "lists",
  734. "NOTIFY_TAG" => "SONET|EVENT|".$comment["LOG_ID"],
  735. "NOTIFY_SUB_TAG" => "FORUM|COMMENT|".$comment["MESSAGE_ID"]."|".$comment["TO_USER_ID"],
  736. "NOTIFY_EVENT" => "event_lists_comment_add",
  737. "NOTIFY_MESSAGE" => $messageAddComment
  738. );
  739. CIMNotify::Add($messageFields);
  740. }
  741. public static function OnSendMentionGetEntityFields($commentFields)
  742. {
  743. if (!in_array($commentFields["EVENT_ID"], array("lists_new_element_comment")))
  744. {
  745. return false;
  746. }
  747. if (!CModule::IncludeModule("socialnetwork"))
  748. {
  749. return true;
  750. }
  751. $dbLog = CSocNetLog::GetList(
  752. array(),
  753. array(
  754. "ID" => $commentFields["LOG_ID"],
  755. ),
  756. false,
  757. false,
  758. array("ID", "TITLE", "SOURCE_ID", "PARAMS")
  759. );
  760. if ($log = $dbLog->GetNext())
  761. {
  762. $genderSuffix = "";
  763. $dbUser = CUser::GetByID($commentFields["USER_ID"]);
  764. if($user = $dbUser->Fetch())
  765. {
  766. $genderSuffix = $user["PERSONAL_GENDER"];
  767. }
  768. $params = unserialize($log["~PARAMS"]);
  769. $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
  770. $entityName = GetMessage("LISTS_LF_COMMENT_MENTION_TITLE", Array("#PROCESS#" => $title));
  771. $notifyMessage = GetMessage("LISTS_LF_COMMENT_MENTION" . ($genderSuffix <> '' ? "_" . $genderSuffix : ""), Array("#title#" => "<a href=\"#url#\" class=\"bx-notifier-item-action\">".$entityName."</a>"));
  772. $notifyMessageOut = GetMessage("LISTS_LF_COMMENT_MENTION" . ($genderSuffix <> '' ? "_" . $genderSuffix : ""), Array("#title#" => $entityName)) . " (" . "#server_name##url#)";
  773. $strPathToLogEntry = str_replace("#log_id#", $log["ID"], COption::GetOptionString("socialnetwork", "log_entry_page", "/company/personal/log/#log_id#/", SITE_ID));
  774. $strPathToLogEntryComment = $strPathToLogEntry . (mb_strpos($strPathToLogEntry, "?") !== false ? "&" : "?") . "commentID=" . $commentFields["ID"] . "#com" . $commentFields["ID"];
  775. $return = array(
  776. "URL" => $strPathToLogEntryComment,
  777. "NOTIFY_MODULE" => "lists",
  778. "NOTIFY_TAG" => "LISTS|COMMENT_MENTION|".$commentFields["ID"],
  779. "NOTIFY_MESSAGE" => $notifyMessage,
  780. "NOTIFY_MESSAGE_OUT" => $notifyMessageOut
  781. );
  782. return $return;
  783. }
  784. else
  785. {
  786. return false;
  787. }
  788. }
  789. public static function OnSocNetGroupDelete($groupId)
  790. {
  791. $iblockIdList = array();
  792. $res = \CIBlock::getList(array(), array("SOCNET_GROUP_ID" => $groupId));
  793. while($iblock = $res->fetch())
  794. {
  795. $iblockIdList[] = $iblock["ID"];
  796. }
  797. if (empty($iblockIdList))
  798. {
  799. return true;
  800. }
  801. foreach($iblockIdList as $iblockId)
  802. {
  803. CIBlock::Delete($iblockId);
  804. }
  805. return true;
  806. }
  807. }