30 $siteId = intval($event->getParameter(
'site_id'));
31 $postId = intval($event->getParameter(
'entity_id'));
32 $userId = intval($event->getParameter(
'from'));
33 $message = trim($event->getParameter(
'content'));
34 $attachments = $event->getParameter(
'attachments');
38 && count($attachments) > 0
53 $res = \CBlogPost::getList(
60 array(
"BLOG_ID",
"AUTHOR_ID",
"BLOG_OWNER_ID")
63 if (!($blogPost = $res->fetch()))
68 $perm = BLOG_PERMS_DENY;
70 if ($blogPost[
"AUTHOR_ID"] == $userId)
72 $perm = BLOG_PERMS_FULL;
76 $postPerm = \CBlogPost::getSocNetPostPerms($postId,
false, $userId, $blogPost[
"AUTHOR_ID"]);
79 $perm = \CBlogComment::getSocNetUserPerms($postId, $blogPost[
"AUTHOR_ID"], $userId);
88 if (!\
Bitrix\
Blog\Item\Comment::checkDuplicate(array(
89 'MESSAGE' => $message,
90 'BLOG_ID' => $blogPost[
"BLOG_ID"],
92 'AUTHOR_ID' => $userId,
100 "BLOG_ID" => $blogPost[
"BLOG_ID"],
102 "POST_TEXT" => $message,
103 "AUTHOR_ID" => $userId,
104 "DATE_CREATE" => convertTimeStamp(time() + \CTimeZone::getOffset(),
"FULL")
109 $fields[
"SEARCH_GROUP_ID"] = \Bitrix\Main\Config\Option::get(
"socialnetwork",
"userbloggroup_id",
false, $siteId);
114 $fields[
"PUBLISH_STATUS"] = BLOG_PUBLISH_STATUS_READY;
118 isModuleInstalled(
"webdav")
119 || isModuleInstalled(
"disk")
120 ?
"UF_BLOG_COMMENT_FILE"
121 :
"UF_BLOG_COMMENT_DOC"
123 $fields[$ufCode] = array();
126 $attachmentRelations = array();
128 foreach ($attachments as $key => $attachedFile)
130 $resultId = \CSocNetLogComponent::saveFileToUF($attachedFile, $type, $userId);
133 $fields[$ufCode][] = $resultId;
134 $attachmentRelations[$key] = $resultId;
138 $fields[
"POST_TEXT"] = preg_replace_callback(
139 "/\[ATTACHMENT\s*=\s*([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER,
140 function ($matches) use ($attachmentRelations)
142 if (isset($attachmentRelations[$matches[1]]))
144 return "[DISK FILE ID=".$attachmentRelations[$matches[1]].
"]";
150 if (Loader::includeModule(
'disk'))
152 \Bitrix\Disk\Uf\FileUserType::setValueForAllowEdit(
"BLOG_COMMENT",
true);
155 $commentId = \CBlogComment::add($fields);
159 \Bitrix\Blog\Item\Comment::actionsAfter(array(
160 'MESSAGE' => $message,
161 'BLOG_ID' => $blogPost[
"BLOG_ID"],
162 'BLOG_OWNER_ID' => $blogPost[
"BLOG_OWNER_ID"],
163 'POST_ID' => $postId,
164 'POST_TITLE' => htmlspecialcharsBack($blogPost[
"TITLE"]),
165 'POST_AUTHOR_ID' => $blogPost[
"AUTHOR_ID"],
166 'COMMENT_ID' => $commentId,
167 'AUTHOR_ID' => $userId,
181 $userId = intval($event->getParameter(
'from'));
182 $message = trim($event->getParameter(
'content'));
183 $subject = trim($event->getParameter(
'subject'));
184 $attachments = $event->getParameter(
'attachments');
185 $siteId = $event->getParameter(
'site_id');
189 && count($attachments) > 0
204 if (!Loader::includeModule(
'socialnetwork'))
209 $pathToPost = Config\Option::get(
"socialnetwork",
"userblogpost_page",
'', $siteId);
213 "GROUP_ID" =>
Config\Option::get(
"socialnetwork",
"userbloggroup_id",
false, $siteId),
214 "SITE_ID" => $siteId,
215 "USER_ID" => $userId,
224 $connection = \Bitrix\Main\Application::getConnection();
225 $helper = $connection->getSqlHelper();
228 "BLOG_ID" => $blog[
"ID"],
229 "AUTHOR_ID" => $userId,
230 "=DATE_CREATE" => $helper->getCurrentDateTimeFunction(),
231 "=DATE_PUBLISH" => $helper->getCurrentDateTimeFunction(),
234 "DETAIL_TEXT" => $message,
235 "DETAIL_TEXT_TYPE" =>
"text",
236 "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH,
239 "HAS_SOCNET_ALL" =>
"N",
240 "SOCNET_RIGHTS" => array(
"U".$userId)
243 if ($fields[
"TITLE"] ==
'')
245 $fields[
"MICRO"] =
"Y";
246 $fields[
"TITLE"] = preg_replace(
"/\[ATTACHMENT\s*=\s*[^\]]*\]/is".BX_UTF_PCRE_MODIFIER,
"", \blogTextParser::killAllTags($fields[
"DETAIL_TEXT"]));
247 $fields[
"TITLE"] = TruncateText(trim(preg_replace(array(
"/\n+/is".BX_UTF_PCRE_MODIFIER,
"/\s+/is".BX_UTF_PCRE_MODIFIER),
" ", $fields[
"TITLE"])), 100);
248 if($fields[
"TITLE"] ==
'')
250 $fields[
"TITLE"] =
Loc::getMessage(
"BLOG_MAILHANDLER_EMPTY_TITLE_PLACEHOLDER");
255 isModuleInstalled(
"webdav")
256 || isModuleInstalled(
"disk")
257 ?
"UF_BLOG_POST_FILE"
260 $fields[$ufCode] = array();
263 $attachmentRelations = array();
265 foreach ($attachments as $key => $attachedFile)
267 $resultId = \CSocNetLogComponent::saveFileToUF($attachedFile, $type, $userId);
270 $fields[$ufCode][] = $resultId;
271 $attachmentRelations[$key] = $resultId;
275 $fields[
"HAS_PROPS"] = (!empty($attachmentRelations) ?
"Y" :
"N");
277 $fields[
"DETAIL_TEXT"] = preg_replace_callback(
278 "/\[ATTACHMENT\s*=\s*([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER,
279 function ($matches) use ($attachmentRelations)
282 isset($attachmentRelations[$matches[1]])
283 ?
"[DISK FILE ID=".$attachmentRelations[$matches[1]].
"]"
287 $fields[
"DETAIL_TEXT"]
290 if (Loader::includeModule(
'disk'))
292 \Bitrix\Disk\Uf\FileUserType::setValueForAllowEdit(
"BLOG_POST",
true);
295 $postId = \CBlogPost::add($fields);
302 BXClearCache(
true,
"/".$siteId.
"/blog/last_messages_list/");
304 $fields[
"ID"] = $postId;
305 $paramsNotify = array(
309 "PATH_TO_SMILE" =>
Config\Option::get(
"socialnetwork",
"smile_page",
'', $siteId),
310 "PATH_TO_POST" => $pathToPost,
311 "user_id" => $userId,
312 "NAME_TEMPLATE" => \CSite::getNameFormat(
null, $siteId),
314 "SEND_COUNTER_TO_AUTHOR" =>
"Y"
316 \CBlogPost::notify($fields, $blog, $paramsNotify);
318 if (Loader::includeModule(
'im'))
320 $postUrl = \CComponentEngine::makePathFromTemplate($pathToPost, array(
321 "post_id" => $postId,
325 $processedPathData = \CSocNetLogTools::processPath(array(
"POST_URL" => $postUrl), $userId, $siteId);
326 $serverName = $processedPathData[
"SERVER_NAME"];
327 $postUrl = $processedPathData[
"URLS"][
"POST_URL"];
329 \CIMNotify::add(array(
330 "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
331 "NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
332 "NOTIFY_MODULE" =>
"blog",
333 "NOTIFY_EVENT" =>
"post_mail",
334 "NOTIFY_TAG" =>
"BLOG|POST|".$postId,
335 "TO_USER_ID" => $userId,
336 "NOTIFY_MESSAGE" =>
Loc::getMessage(
"BLOG_MAILHANDLER_NEW_POST", array(
337 "#TITLE#" =>
"<a href=\"".$postUrl.
"\">".$fields[
"TITLE"].
"</a>"
339 "NOTIFY_MESSAGE_OUT" =>
Loc::getMessage(
"BLOG_MAILHANDLER_NEW_POST", array(
340 "#TITLE#" => $fields[
"TITLE"]
341 )).
' '.$serverName.$postUrl
345 $categoryIdList = \Bitrix\Socialnetwork\Component\BlogPostEdit\Tag::parseTagsFromFields([
346 'postFields' => $fields,
347 'blogId' => $blog[
'ID'],
349 if (!empty($categoryIdList))
351 foreach ($categoryIdList as $categoryId)
353 \CBlogPostCategory::add([
354 'BLOG_ID' => $fields[
'BLOG_ID'],
355 'POST_ID' => $postId,
356 'CATEGORY_ID' => $categoryId
363 'CATEGORY_ID' => implode(
',', $categoryIdList),