Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mailhandler.php
1<?php
2
4
11
12Loc::loadMessages(__FILE__);
13
20final class MailHandler
21{
28 public static function handleReplyReceivedLogEntry(\Bitrix\Main\Event $event)
29 {
30 global $USER, $DB;
31
32 $logEntryId = intval($event->getParameter('entity_id'));
33 $userId = intval($event->getParameter('from'));
34 $message = trim($event->getParameter('content'));
35 $attachments = $event->getParameter('attachments');
36
37 $commentId = false;
38
39 if (
40 $message == ''
41 && count($attachments) > 0
42 )
43 {
44 $message = Loc::getMessage('SONET_MAILHANDLER_ATTACHMENTS');
45 }
46
47 if (
48 $logEntryId <= 0
49 || $userId <= 0
50 || $message == ''
51 )
52 {
53 return false;
54 }
55
56 $res = \CSocNetLog::getList(
57 array(),
58 array(
59 "ID" => $logEntryId
60 ),
61 false,
62 false,
63 array("ID", "ENTITY_TYPE", "ENTITY_ID", "EVENT_ID", "USER_ID", "SOURCE_ID")
64 );
65
66 if (!($logEntry = $res->fetch()))
67 {
68 return false;
69 }
70
71 $siteId = \Bitrix\Socialnetwork\Util::getSiteIdByLogId($logEntry["ID"]);
72 $res = \CSite::getByID($siteId);
73 $site = $res->fetch();
74
75 $pathToUser = Config\Option::get("main", "TOOLTIP_PATH_TO_USER", false, $siteId);
76 $pathToSmile = Config\Option::get("socialnetwork", "smile_page", false, $siteId);
77
78 $commentEvent = \CSocNetLogTools::findLogCommentEventByLogEventID($logEntry["EVENT_ID"]);
79 if (is_array($commentEvent))
80 {
81 if (\Bitrix\Socialnetwork\ComponentHelper::canAddComment($logEntry, $commentEvent))
82 {
83 $fields = array(
84 "ENTITY_TYPE" => $logEntry["ENTITY_TYPE"],
85 "ENTITY_ID" => $logEntry["ENTITY_ID"],
86 "EVENT_ID" => $commentEvent["EVENT_ID"],
87 "=LOG_DATE" => $DB->currentTimeFunction(),
88 "MESSAGE" => $message,
89 "TEXT_MESSAGE" => $message,
90 "MODULE_ID" => false,
91 "LOG_ID" => $logEntry["ID"],
92 "USER_ID" => $userId,
93 "CURRENT_USER_ID" => $userId
94 );
95
96 $ufCode = (
97 ModuleManager::isModuleInstalled("webdav")
98 || ModuleManager::isModuleInstalled("disk")
99 ? "UF_SONET_COM_DOC"
100 : "UF_SONET_COM_FILE"
101 );
102 $fields[$ufCode] = array();
103
104 $type = false;
105 $attachmentRelations = array();
106
107 foreach ($attachments as $key => $attachedFile)
108 {
109 $resultId = \CSocNetLogComponent::saveFileToUF($attachedFile, $type, $userId);
110 if ($resultId)
111 {
112 $fields[$ufCode][] = $resultId;
113 $attachmentRelations[$key] = $resultId;
114 }
115 }
116
117 $fields["MESSAGE"] = preg_replace_callback(
118 "/\[ATTACHMENT\s*=\s*([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER,
119 function ($matches) use ($attachmentRelations)
120 {
121 if (isset($attachmentRelations[$matches[1]]))
122 {
123 return "[DISK FILE ID=".$attachmentRelations[$matches[1]]."]";
124 }
125 },
126 $fields["MESSAGE"]
127 );
128
129 if (Loader::includeModule('disk'))
130 {
131 \Bitrix\Disk\Uf\FileUserType::setValueForAllowEdit("SONET_COMMENT", true);
132 }
133
134 $commentId = \CSocNetLogComments::add($fields, true, false);
135
136 if (
137 is_array($commentId)
138 || !$commentId
139 )
140 {
141 return false;
142 }
143
144 foreach (EventManager::getInstance()->findEventHandlers('socialnetwork', 'OnAfterSocNetLogEntryCommentAdd') as $handler)
145 {
146 ExecuteModuleEventEx($handler, array($logEntry, array(
147 "SITE_ID" => $siteId,
148 "COMMENT_ID" => $commentId
149 )));
150 }
151
152 $skipCounterIncrement = false;
153 foreach (EventManager::getInstance()->findEventHandlers('socialnetwork', 'OnBeforeSocNetLogCommentCounterIncrement') as $handler)
154 {
155 if (ExecuteModuleEventEx($handler, array($logEntry)) === false)
156 {
157 $skipCounterIncrement = true;
158 break;
159 }
160 }
161
162 if (!$skipCounterIncrement)
163 {
164 \CSocNetLog::counterIncrement(
165 $commentId,
166 false,
167 false,
168 "LC",
169 \CSocNetLogRights::checkForUserAll($logEntry["ID"])
170 );
171 }
172
173 if ($comment = \CSocNetLogComments::getByID($commentId))
174 {
175 \Bitrix\Socialnetwork\ComponentHelper::addLiveComment(
176 $comment,
177 $logEntry,
178 $commentEvent,
179 array(
180 "ACTION" => 'ADD',
181 "SOURCE_ID" => 0,
182 "TIME_FORMAT" => \CSite::getTimeFormat(),
183 "PATH_TO_USER" => $pathToUser,
184 "NAME_TEMPLATE" => \CSite::getNameFormat(null, $site["ID"]),
185 "SHOW_LOGIN" => "N",
186 "AVATAR_SIZE" => 100,
187 "PATH_TO_SMILE" => $pathToSmile,
188 "LANGUAGE_ID" => $site["LANGUAGE_ID"],
189 "SITE_ID" => $site["ID"],
190 "PULL" => "Y"
191 )
192 );
193 }
194 }
195 }
196
197 return $commentId;
198 }
199}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static canAddComment($logEntry=array(), $commentEvent=array())
static handleReplyReceivedLogEntry(\Bitrix\Main\Event $event)