PageRenderTime 574ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/components/bitrix/socialnetwork.log.entry.mail/class.php

https://gitlab.com/alexprowars/bitrix
PHP | 446 lines | 370 code | 56 blank | 20 comment | 36 complexity | 54b954c5c80ef114fabe6bb7933fac73 MD5 | raw file
  1. <?php
  2. /**
  3. * Bitrix Framework
  4. * @package bitrix
  5. * @subpackage socialnetwork
  6. * @copyright 2001-2015 Bitrix
  7. */
  8. use Bitrix\Main;
  9. use Bitrix\Main\Config;
  10. use Bitrix\Main\Localization;
  11. use Bitrix\Main\Loader;
  12. use Bitrix\Socialnetwork\ComponentHelper;
  13. use Bitrix\Socialnetwork\Helper\Mention;
  14. use Bitrix\Socialnetwork\Helper\Path;
  15. if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
  16. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/components/bitrix/socialnetwork.log.entry/include.php");
  17. class CBitrixSocialnetworkLogEntryMailComponent extends CBitrixComponent
  18. {
  19. const E_SOCIALNETWORK_MODULE_NOT_INSTALLED = 10001;
  20. const E_COMMENT_NOT_FOUND = 10002;
  21. const E_LOG_ENTRY_NOT_FOUND = 10003;
  22. /**
  23. * Variable contains comments data
  24. *
  25. * @var array[] array
  26. */
  27. protected $logEntryId = false;
  28. protected $authorIdList = array();
  29. /**
  30. * Function implements all the life cycle of the component
  31. * @return void
  32. */
  33. public function executeComponent()
  34. {
  35. $this->checkRequiredModules();
  36. $this->arResult = array(
  37. "SITE" => false,
  38. "AUTHORS" => array(),
  39. "COMMENTS" => array(),
  40. "LOG_ENTRY" => array(),
  41. "LOG_ENTRY_URL" => ""
  42. );
  43. try
  44. {
  45. $this->obtainDataLogEntry();
  46. $this->obtainDataDestinations();
  47. $this->obtainDataComments();
  48. $this->obtainLogEntryUrl();
  49. }
  50. catch(Exception $e)
  51. {
  52. }
  53. Loader::includeModule('mail');
  54. $this->includeComponentTemplate();
  55. }
  56. public function __construct($component = null)
  57. {
  58. parent::__construct($component);
  59. Localization\Loc::loadMessages(__FILE__);
  60. }
  61. /**
  62. * Function checks if required modules installed. If not, throws an exception
  63. * @throws Main\SystemException
  64. * @return void
  65. */
  66. protected function checkRequiredModules()
  67. {
  68. if (!Loader::includeModule('socialnetwork'))
  69. {
  70. throw new Main\SystemException(Localization\Loc::getMessage("SLEM_SOCIALNETWORK_MODULE_NOT_INSTALLED"), self::E_SOCIALNETWORK_MODULE_NOT_INSTALLED);
  71. }
  72. }
  73. public function onPrepareComponentParams($arParams): array
  74. {
  75. $arParams["RECIPIENT_ID"] = (isset($arParams["RECIPIENT_ID"]) ? intval($arParams["RECIPIENT_ID"]) : 0);
  76. $arParams["COMMENT_ID"] = (isset($arParams["COMMENT_ID"]) ? intval($arParams["COMMENT_ID"]) : 0);
  77. $arParams["LOG_ENTRY_ID"] = (int)($arParams["LOG_ENTRY_ID"] ?? 0);
  78. $arParams["AVATAR_SIZE"] = (
  79. isset($arParams["AVATAR_SIZE"])
  80. && intval($arParams["AVATAR_SIZE"]) > 0
  81. ? intval($arParams["AVATAR_SIZE"])
  82. : 100
  83. );
  84. $arParams["AVATAR_SIZE_COMMENT"] = (
  85. isset($arParams["AVATAR_SIZE_COMMENT"])
  86. && intval($arParams["AVATAR_SIZE_COMMENT"]) > 0
  87. ? intval($arParams["AVATAR_SIZE_COMMENT"])
  88. : 100
  89. );
  90. $arParams["COMMENTS_COUNT"] = (
  91. isset($arParams["COMMENTS_COUNT"])
  92. && intval($arParams["COMMENTS_COUNT"]) > 0
  93. ? intval($arParams["COMMENTS_COUNT"])
  94. : 3
  95. );
  96. $arParams["URL"] = (
  97. isset($arParams["URL"])
  98. && $arParams["URL"] <> ''
  99. ? $arParams["URL"]
  100. : CComponentEngine::MakePathFromTemplate(
  101. '/pub/log_entry.php?log_id=#log_id#',
  102. array(
  103. "log_id"=> $arParams["LOG_ENTRY_ID"]
  104. )
  105. )
  106. );
  107. $this->logEntryId = $arParams["LOG_ENTRY_ID"];
  108. return $arParams;
  109. }
  110. private function obtainDataLogEntry()
  111. {
  112. static $logEntriesCache = array();
  113. static $sitesCache = array();
  114. $arResult =& $this->arResult;
  115. if ($this->logEntryId > 0)
  116. {
  117. if (isset($sitesCache[$this->logEntryId]))
  118. {
  119. $arResult["SITE"] = $sitesCache[$this->logEntryId];
  120. }
  121. else
  122. {
  123. $siteId = \Bitrix\Socialnetwork\Util::getSiteIdByLogId($this->logEntryId);
  124. $res = CSite::GetByID($siteId);
  125. $arResult["SITE"] = $sitesCache[$this->logEntryId] = $res->fetch();
  126. }
  127. $arResult["PATH_TO_USER"] = Config\Option::get("main", "TOOLTIP_PATH_TO_USER", false, $arResult["SITE"]["ID"]);
  128. $arResult["PATH_TO_GROUP"] = Config\Option::get("socialnetwork", "workgroups_page", false, $arResult["SITE"]["ID"])."group/#group_id#/";
  129. $arResult["PATH_TO_CONPANY_DEPARTMENT"] = Path::get('department_path_template', $arResult['SITE']['ID']);
  130. if (isset($logEntriesCache[$this->logEntryId]))
  131. {
  132. $arResult["LOG_ENTRY"] = $logEntriesCache[$this->logEntryId];
  133. }
  134. else
  135. {
  136. $arResult["LOG_ENTRY"] = __SLEGetLogRecord(
  137. $this->logEntryId,
  138. array(
  139. "AVATAR_SIZE" => $this->arParams["AVATAR_SIZE"],
  140. "NAME_TEMPLATE" => CSite::getNameFormat(false, $arResult["SITE"]["ID"]),
  141. "SHOW_LOGIN" => "Y",
  142. "DATE_TIME_FORMAT" => CSite::GetDateFormat("FULL", $arResult["SITE"]["ID"]),
  143. "PATH_TO_USER" => Config\Option::get("main", "TOOLTIP_PATH_TO_USER", false, $arResult["SITE"]["ID"]),
  144. "PATH_TO_GROUP" => Config\Option::get("socialnetwork", "workgroups_page", false, $arResult["SITE"]["ID"])."group/#group_id#/",
  145. "PATH_TO_CONPANY_DEPARTMENT" => Path::get('department_path_template', $arResult['SITE']['ID']),
  146. ),
  147. false
  148. );
  149. $arResult["LOG_ENTRY"]["ATTACHMENTS"] = array();
  150. if (
  151. !empty($arResult["LOG_ENTRY"]["EVENT_FORMATTED"])
  152. && !empty($arResult["LOG_ENTRY"]["EVENT_FORMATTED"]["UF"])
  153. && !empty($arResult["LOG_ENTRY"]["EVENT_FORMATTED"]["UF"]["UF_SONET_LOG_DOC"])
  154. && !empty($arResult["LOG_ENTRY"]["EVENT_FORMATTED"]["UF"]["UF_SONET_LOG_DOC"]["VALUE"])
  155. )
  156. {
  157. $arResult["LOG_ENTRY"]["ATTACHMENTS"] = ComponentHelper::getAttachmentsData($arResult["LOG_ENTRY"]["EVENT_FORMATTED"]["UF"]["UF_SONET_LOG_DOC"]["VALUE"], $arResult["SITE"]["ID"]);
  158. }
  159. $arResult["LOG_ENTRY"]["EVENT"]["MESSAGE"] = ComponentHelper::convertDiskFileBBCode(
  160. $arResult["LOG_ENTRY"]["EVENT"]["MESSAGE"],
  161. 'SONET_LOG',
  162. $this->logEntryId,
  163. $arResult["LOG_ENTRY"]["EVENT"]["USER_ID"],
  164. $arResult["LOG_ENTRY"]["ATTACHMENTS"]
  165. );
  166. $arResult["LOG_ENTRY"]["EVENT"]["MESSAGE_FORMATTED"] = preg_replace(
  167. array(
  168. '|\[DISK\sFILE\sID=[n]*\d+\]|',
  169. '|\[DOCUMENT\sID=[n]*\d+\]|'
  170. ),
  171. '',
  172. $arResult["LOG_ENTRY"]["EVENT"]["MESSAGE"]
  173. );
  174. $arResult['LOG_ENTRY']['EVENT']['MESSAGE_FORMATTED'] = Mention::clear($arResult['LOG_ENTRY']['EVENT']['MESSAGE_FORMATTED']);
  175. $arResult["LOG_ENTRY"]["EVENT"]["MESSAGE_FORMATTED"] = $this->parseText($arResult["LOG_ENTRY"]["EVENT"]["MESSAGE_FORMATTED"]);
  176. }
  177. }
  178. if (empty($arResult["LOG_ENTRY"]))
  179. {
  180. throw new Main\SystemException(str_replace("#ID#", $this->logEntryId, Localization\Loc::getMessage("SLEM_NO_LOG_ENTRY")), self::E_LOG_ENTRY_NOT_FOUND);
  181. }
  182. }
  183. private function obtainDataComments()
  184. {
  185. global $USER_FIELD_MANAGER;
  186. static $commentListsCache = array();
  187. static $commentsAllCountCache = array();
  188. $arResult =& $this->arResult;
  189. if (
  190. $this->logEntryId > 0
  191. && !empty($this->arParams["COMMENT_ID"])
  192. && intval($this->arParams["COMMENT_ID"]) > 0
  193. )
  194. {
  195. if (isset($commentListsCache[$this->logEntryId]))
  196. {
  197. $arResult["COMMENTS"] = $commentListsCache[$this->logEntryId];
  198. }
  199. else
  200. {
  201. $arUFMeta = $USER_FIELD_MANAGER->GetUserFields("SONET_COMMENT", 0, $arResult["SITE"]["LANGUAGE_ID"]);
  202. $arAssets = array();
  203. $arResult["COMMENTS"] = array();
  204. $dbComments = CSocNetLogComments::GetList(
  205. array("LOG_DATE" => "DESC"), // revert then
  206. array(
  207. "LOG_ID" => $this->logEntryId
  208. ),
  209. false,
  210. array(
  211. "nTopCount" => $this->arParams["COMMENTS_COUNT"]
  212. ),
  213. array(
  214. "ID", "LOG_ID", "SOURCE_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "EVENT_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID",
  215. "CREATED_BY_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LOGIN", "CREATED_BY_PERSONAL_PHOTO", "CREATED_BY_PERSONAL_GENDER",
  216. "LOG_SITE_ID", "LOG_SOURCE_ID",
  217. "UF_*"
  218. ),
  219. array(
  220. "USE_SUBSCRIBE" => "N",
  221. "CHECK_RIGHTS" => "N"
  222. )
  223. );
  224. while($comment = $dbComments->getNext())
  225. {
  226. $comment["UF"] = $arUFMeta;
  227. foreach($arUFMeta as $field_name => $arUF)
  228. {
  229. if (array_key_exists($field_name, $comment))
  230. {
  231. $comment["UF"][$field_name]["VALUE"] = $comment[$field_name];
  232. $comment["UF"][$field_name]["ENTITY_VALUE_ID"] = $comment["ID"];
  233. }
  234. }
  235. if (isset($comment["UF"]["UF_SONET_COM_URL_PRV"]))
  236. {
  237. unset($comment["UF"]["UF_SONET_COM_URL_PRV"]);
  238. }
  239. $commentFormatted = \Bitrix\Socialnetwork\Component\LogEntry::getLogCommentRecord($comment, array(
  240. "MAIL" => "Y",
  241. "AVATAR_SIZE" => $this->arParams["AVATAR_SIZE_COMMENT"],
  242. "NAME_TEMPLATE" => CSite::getNameFormat(false, $arResult["SITE"]["ID"]),
  243. "SHOW_LOGIN" => "Y",
  244. "DATE_TIME_FORMAT" => CSite::GetDateFormat("FULL", $arResult["SITE"]["ID"]),
  245. "PATH_TO_USER" => $arResult["PATH_TO_USER"],
  246. "PATH_TO_GROUP" => $arResult["PATH_TO_GROUP"],
  247. "PATH_TO_CONPANY_DEPARTMENT" => $arResult["PATH_TO_CONPANY_DEPARTMENT"],
  248. ), $arAssets);
  249. $commentFormatted["ATTACHMENTS"] = array();
  250. if (
  251. !empty($commentFormatted)
  252. && !empty($commentFormatted["UF"])
  253. && !empty($commentFormatted["UF"]["UF_SONET_COM_DOC"])
  254. && !empty($commentFormatted["UF"]["UF_SONET_COM_DOC"]["VALUE"])
  255. )
  256. {
  257. $commentFormatted["ATTACHMENTS"] = ComponentHelper::getAttachmentsData($commentFormatted["UF"]["UF_SONET_COM_DOC"]["VALUE"], $arResult["SITE"]["ID"]);
  258. }
  259. $commentFormatted["EVENT"]["MESSAGE"] = ComponentHelper::convertDiskFileBBCode(
  260. $commentFormatted["EVENT"]["MESSAGE"],
  261. 'SONET_COMMENT',
  262. $commentFormatted["EVENT"]["ID"],
  263. $commentFormatted["EVENT"]["USER_ID"],
  264. $commentFormatted["ATTACHMENTS"]
  265. );
  266. $commentFormatted["EVENT"]["MESSAGE_FORMATTED"] = preg_replace(
  267. array(
  268. '|\[DISK\sFILE\sID=[n]*\d+\]|',
  269. '|\[DOCUMENT\sID=[n]*\d+\]|'
  270. ),
  271. '',
  272. $commentFormatted["EVENT"]["MESSAGE"]
  273. );
  274. $commentFormatted['EVENT']['MESSAGE_FORMATTED'] = Mention::clear($commentFormatted['EVENT']['MESSAGE_FORMATTED']);
  275. $commentFormatted["EVENT"]["MESSAGE_FORMATTED"] = $this->parseText($commentFormatted["EVENT"]["MESSAGE_FORMATTED"]);
  276. $arResult["COMMENTS"][$comment["ID"]] = $commentFormatted;
  277. }
  278. $commentListsCache[$this->logEntryId] = $arResult["COMMENTS"];
  279. }
  280. if (isset($commentsAllCountCache[$this->logEntryId]))
  281. {
  282. $arResult["COMMENTS_ALL_COUNT"] = $commentsAllCountCache[$this->logEntryId];
  283. }
  284. else
  285. {
  286. $arResult["COMMENTS_ALL_COUNT"] = $commentsAllCountCache[$this->logEntryId] = intval(CSocNetLogComments::GetList(
  287. array("LOG_DATE" => "DESC"),
  288. array(
  289. "LOG_ID" => $this->logEntryId
  290. ),
  291. array(),
  292. false,
  293. array("ID"),
  294. array(
  295. "USE_SUBSCRIBE" => "N",
  296. "CHECK_RIGHTS" => "N"
  297. )
  298. ));
  299. }
  300. }
  301. }
  302. private function obtainDataDestinations()
  303. {
  304. $arResult =& $this->arResult;
  305. $arResult["DESTINATIONS"] = array();
  306. if (
  307. isset($arResult["LOG_ENTRY"]["EVENT_FORMATTED"])
  308. && isset($arResult["LOG_ENTRY"]["EVENT_FORMATTED"]["DESTINATION"])
  309. && !empty($arResult["LOG_ENTRY"]["EVENT_FORMATTED"]["DESTINATION"])
  310. )
  311. {
  312. foreach ($arResult["LOG_ENTRY"]["EVENT_FORMATTED"]["DESTINATION"] as $destination)
  313. {
  314. if (mb_strpos($destination["TYPE"], "CRM") !== 0)
  315. {
  316. $arResult["DESTINATIONS"][] = $destination;
  317. }
  318. }
  319. }
  320. }
  321. private function obtainLogEntryUrl()
  322. {
  323. $arResult =& $this->arResult;
  324. $arResult["LOG_ENTRY_URL"] = $this->arParams["URL"];
  325. if (
  326. isset($this->arParams["RECIPIENT_ID"])
  327. && intval($this->arParams["RECIPIENT_ID"]) > 0
  328. )
  329. {
  330. $backUrl = ComponentHelper::getReplyToUrl($arResult["LOG_ENTRY_URL"], intval($this->arParams["RECIPIENT_ID"]), 'LOG_ENTRY', $arResult["LOG_ENTRY"]["EVENT"]["ID"], $arResult["SITE"]["ID"]);
  331. if ($backUrl)
  332. {
  333. $arResult["LOG_ENTRY_URL"] = $backUrl;
  334. }
  335. }
  336. }
  337. private function parseText($text)
  338. {
  339. static $parser = false;
  340. $arResult =& $this->arResult;
  341. if (!$parser)
  342. {
  343. if (Loader::includeModule('forum'))
  344. {
  345. $parser = new forumTextParser($arResult["SITE"]["LANGUAGE_ID"]);
  346. }
  347. else
  348. {
  349. $parser = new logTextParser($arResult["SITE"]["LANGUAGE_ID"]);
  350. }
  351. }
  352. if (Loader::includeModule('forum'))
  353. {
  354. $result = $parser->convert(
  355. $text,
  356. array(
  357. "HTML" => "N",
  358. "ALIGN" => "Y",
  359. "ANCHOR" => "Y", "BIU" => "Y",
  360. "IMG" => "Y", "QUOTE" => "Y",
  361. "CODE" => "Y", "FONT" => "Y",
  362. "LIST" => "Y", "SMILES" => "Y",
  363. "NL2BR" => "Y", "MULTIPLE_BR" => "N",
  364. "VIDEO" => "Y", "LOG_VIDEO" => "N",
  365. "SHORT_ANCHOR" => "Y",
  366. ),
  367. "html"
  368. );
  369. }
  370. else
  371. {
  372. $result = $parser->convert(
  373. $text,
  374. array(),
  375. array(
  376. "HTML" => "N",
  377. "ALIGN" => "Y",
  378. "ANCHOR" => "Y", "BIU" => "Y",
  379. "IMG" => "Y", "QUOTE" => "Y",
  380. "CODE" => "Y", "FONT" => "Y",
  381. "LIST" => "Y", "SMILES" => "Y",
  382. "NL2BR" => "Y", "MULTIPLE_BR" => "N",
  383. "VIDEO" => "Y", "LOG_VIDEO" => "N",
  384. "SHORT_ANCHOR" => "Y",
  385. )
  386. );
  387. }
  388. return $result;
  389. }
  390. }