1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mailhandler.php
См. документацию.
1<?php
2
3namespace Bitrix\Blog\Internals;
4
5use Bitrix\Blog\Item\Blog;
6use Bitrix\Main;
7use Bitrix\Main\Loader;
8use Bitrix\Main\Localization\Loc;
9use Bitrix\Main\Config;
10use Bitrix\Blog\Item\Permissions;
11
12Loc::loadMessages(__FILE__);
13
20final class MailHandler
21{
29 {
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');
35
36 if (
37 $message == ''
38 && count($attachments) > 0
39 )
40 {
41 $message = Loc::getMessage('BLOG_MAILHANDLER_ATTACHMENTS');
42 }
43
44 if (
45 $postId <= 0
46 || $userId <= 0
47 || $message == ''
48 )
49 {
50 return false;
51 }
52
53 $res = \CBlogPost::getList(
54 array(),
55 array(
56 "ID" => $postId
57 ),
58 false,
59 false,
60 array("BLOG_ID", "AUTHOR_ID", "BLOG_OWNER_ID")
61 );
62
63 if (!($blogPost = $res->fetch()))
64 {
65 return false;
66 }
67
69
70 if ($blogPost["AUTHOR_ID"] == $userId)
71 {
73 }
74 else
75 {
76 $postPerm = \CBlogPost::getSocNetPostPerms($postId, false, $userId, $blogPost["AUTHOR_ID"]);
77 if ($postPerm > Permissions::DENY)
78 {
79 $perm = \CBlogComment::getSocNetUserPerms($postId, $blogPost["AUTHOR_ID"], $userId);
80 }
81 }
82
84 {
85 return false;
86 }
87
88 if (!\Bitrix\Blog\Item\Comment::checkDuplicate(array(
89 'MESSAGE' => $message,
90 'BLOG_ID' => $blogPost["BLOG_ID"],
91 'POST_ID' => $postId,
92 'AUTHOR_ID' => $userId,
93 )))
94 {
95 return false;
96 }
97
98 $fields = Array(
99 "POST_ID" => $postId,
100 "BLOG_ID" => $blogPost["BLOG_ID"],
101 "TITLE" => '',
102 "POST_TEXT" => $message,
103 "AUTHOR_ID" => $userId,
104 "DATE_CREATE" => convertTimeStamp(time() + \CTimeZone::getOffset(), "FULL")
105 );
106
107 if (!empty($siteId))
108 {
109 $fields["SEARCH_GROUP_ID"] = \Bitrix\Main\Config\Option::get("socialnetwork", "userbloggroup_id", false, $siteId);
110 }
111
113 {
114 $fields["PUBLISH_STATUS"] = BLOG_PUBLISH_STATUS_READY;
115 }
116
117 $ufCode = (
118 isModuleInstalled("webdav")
119 || isModuleInstalled("disk")
120 ? "UF_BLOG_COMMENT_FILE"
121 : "UF_BLOG_COMMENT_DOC"
122 );
123 $fields[$ufCode] = array();
124
125 $type = false;
126 $attachmentRelations = array();
127
128 foreach ($attachments as $key => $attachedFile)
129 {
130 $resultId = \CSocNetLogComponent::saveFileToUF($attachedFile, $type, $userId);
131 if ($resultId)
132 {
133 $fields[$ufCode][] = $resultId;
134 $attachmentRelations[$key] = $resultId;
135 }
136 }
137
138 $fields["POST_TEXT"] = preg_replace_callback(
139 "/\[ATTACHMENT\s*=\s*([^\]]*)\]/isu",
140 function ($matches) use ($attachmentRelations)
141 {
142 if (isset($attachmentRelations[$matches[1]]))
143 {
144 return "[DISK FILE ID=".$attachmentRelations[$matches[1]]."]";
145 }
146 },
147 $fields["POST_TEXT"]
148 );
149
150 if (Loader::includeModule('disk'))
151 {
152 \Bitrix\Disk\Uf\FileUserType::setValueForAllowEdit("BLOG_COMMENT", true);
153 }
154
155 $commentId = \CBlogComment::add($fields);
156
157 if ($commentId)
158 {
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,
168 ));
169 }
170
171 return $commentId;
172 }
173
180 {
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');
186
187 if (
188 $message == ''
189 && count($attachments) > 0
190 )
191 {
192 $message = Loc::getMessage('BLOG_MAILHANDLER_ATTACHMENTS');
193 }
194
195 if (
196 $userId <= 0
197 || $message == ''
198 || $siteId == ''
199 )
200 {
201 return false;
202 }
203
204 if (!Loader::includeModule('socialnetwork'))
205 {
206 throw new Main\SystemException("Could not load 'socialnetwork' module.");
207 }
208
209 $pathToPost = Config\Option::get("socialnetwork", "userblogpost_page", '', $siteId);
210 $postId = false;
211
212 $blog = Blog::getByUser(array(
213 "GROUP_ID" => Config\Option::get("socialnetwork", "userbloggroup_id", false, $siteId),
214 "SITE_ID" => $siteId,
215 "USER_ID" => $userId,
216 "CREATE" => "Y",
217 ));
218
219 if (!$blog)
220 {
221 return $postId;
222 }
223
225 $helper = $connection->getSqlHelper();
226
227 $fields = Array(
228 "BLOG_ID" => $blog["ID"],
229 "AUTHOR_ID" => $userId,
230 "=DATE_CREATE" => $helper->getCurrentDateTimeFunction(),
231 "=DATE_PUBLISH" => $helper->getCurrentDateTimeFunction(),
232 "MICRO" => "N",
233 "TITLE" => $subject,
234 "DETAIL_TEXT" => $message,
235 "DETAIL_TEXT_TYPE" => "text",
236 "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH,
237 "HAS_IMAGES" => "N",
238 "HAS_TAGS" => "N",
239 "HAS_SOCNET_ALL" => "N",
240 "SOCNET_RIGHTS" => array("U".$userId)
241 );
242
243 if ($fields["TITLE"] == '')
244 {
245 $fields["MICRO"] = "Y";
246 $fields["TITLE"] = preg_replace("/\[ATTACHMENT\s*=\s*[^\]]*\]/isu", "", \blogTextParser::killAllTags($fields["DETAIL_TEXT"]));
247 $fields["TITLE"] = TruncateText(trim(preg_replace(array("/\n+/isu", "/\s+/isu"), " ", $fields["TITLE"])), 100);
248 if($fields["TITLE"] == '')
249 {
250 $fields["TITLE"] = Loc::getMessage("BLOG_MAILHANDLER_EMPTY_TITLE_PLACEHOLDER");
251 }
252 }
253
254 $ufCode = (
255 isModuleInstalled("webdav")
256 || isModuleInstalled("disk")
257 ? "UF_BLOG_POST_FILE"
258 : "UF_BLOG_POST_DOC"
259 );
260 $fields[$ufCode] = array();
261
262 $type = false;
263 $attachmentRelations = array();
264
265 foreach ($attachments as $key => $attachedFile)
266 {
267 $resultId = \CSocNetLogComponent::saveFileToUF($attachedFile, $type, $userId);
268 if ($resultId)
269 {
270 $fields[$ufCode][] = $resultId;
271 $attachmentRelations[$key] = $resultId;
272 }
273 }
274
275 $fields["HAS_PROPS"] = (!empty($attachmentRelations) ? "Y" :"N");
276
277 $fields["DETAIL_TEXT"] = preg_replace_callback(
278 "/\[ATTACHMENT\s*=\s*([^\]]*)\]/isu",
279 function ($matches) use ($attachmentRelations)
280 {
281 return (
282 isset($attachmentRelations[$matches[1]])
283 ? "[DISK FILE ID=".$attachmentRelations[$matches[1]]."]"
284 : ""
285 );
286 },
287 $fields["DETAIL_TEXT"]
288 );
289
290 if (Loader::includeModule('disk'))
291 {
292 \Bitrix\Disk\Uf\FileUserType::setValueForAllowEdit("BLOG_POST", true);
293 }
294
295 $postId = \CBlogPost::add($fields);
296
297 if (!$postId)
298 {
299 return $postId;
300 }
301
302 BXClearCache(true, "/".$siteId."/blog/last_messages_list/");
303
304 $fields["ID"] = $postId;
305 $paramsNotify = array(
306 "bSoNet" => true,
307 "UserID" => $userId,
308 "allowVideo" => "N",
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),
313 "SHOW_LOGIN" => "Y",
314 "SEND_COUNTER_TO_AUTHOR" => "Y"
315 );
316 \CBlogPost::notify($fields, $blog, $paramsNotify);
317
318 if (Loader::includeModule('im'))
319 {
320 $postUrl = \CComponentEngine::makePathFromTemplate($pathToPost, array(
321 "post_id" => $postId,
322 "user_id" => $userId
323 ));
324
325 $processedPathData = \CSocNetLogTools::processPath(array("POST_URL" => $postUrl), $userId, $siteId);
326 $serverName = $processedPathData["SERVER_NAME"];
327 $postUrl = $processedPathData["URLS"]["POST_URL"];
328
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" => fn (?string $languageId = null) => Loc::getMessage(
337 "BLOG_MAILHANDLER_NEW_POST",
338 array(
339 "#TITLE#" => "<a href=\"".$postUrl."\">".$fields["TITLE"]."</a>",
340 ),
341 $languageId
342 ),
343 "NOTIFY_MESSAGE_OUT" => fn (?string $languageId = null) => Loc::getMessage(
344 "BLOG_MAILHANDLER_NEW_POST",
345 array(
346 "#TITLE#" => $fields["TITLE"]
347 ),
348 $languageId
349 ) .' '.$serverName.$postUrl
350 ));
351 }
352
354 'postFields' => $fields,
355 'blogId' => $blog['ID'],
356 ]);
357 if (!empty($categoryIdList))
358 {
359 foreach ($categoryIdList as $categoryId)
360 {
361 \CBlogPostCategory::add([
362 'BLOG_ID' => $fields['BLOG_ID'],
363 'POST_ID' => $postId,
364 'CATEGORY_ID' => $categoryId
365 ]);
366 }
367
368 \CBlogPost::update(
369 $postId,
370 [
371 'CATEGORY_ID' => implode(',', $categoryIdList),
372 'HAS_TAGS' => 'Y',
373 ]
374 );
375 }
376
377 return $postId;
378 }
379}
$connection
Определения actionsdefinitions.php:38
$type
Определения options.php:106
const BLOG_PUBLISH_STATUS_READY
Определения include.php:46
const BLOG_PERMS_DENY
Определения include.php:5
const BLOG_PERMS_FULL
Определения include.php:10
const BLOG_PUBLISH_STATUS_PUBLISH
Определения include.php:47
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static handleReplyReceivedBlogPost(\Bitrix\Main\Event $event)
Определения mailhandler.php:28
static handleForwardReceivedBlogPost(\Bitrix\Main\Event $event)
Определения mailhandler.php:179
Определения blog.php:17
static getByUser(array $params)
Определения blog.php:18
static actionsAfter(array $params)
Определения comment.php:153
const PREMODERATE
Определения permissions.php:14
static getConnection($name="")
Определения application.php:638
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения event.php:5
static parseTagsFromFields(array $params=[])
Определения tag.php:67
static makePathFromTemplate($template, $arParams=array())
Определения component_engine.php:355
static killAllTags($text)
Определения functions.php:473
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$perm
Определения options.php:169
const IM_MESSAGE_SYSTEM
Определения include.php:21
const IM_NOTIFY_SYSTEM
Определения include.php:38
$siteId
Определения ajax.php:8
BXClearCache($full=false, $initdir='')
Определения tools.php:5150
TruncateText($strText, $intLen)
Определения tools.php:2185
Определения blog.php:8
$message
Определения payment.php:8
$event
Определения prolog_after.php:141
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$matches
Определения index.php:22
$fields
Определения yandex_run.php:501