17 "forum.message.user.get" =>
array(
'callback' =>
array(__CLASS__,
'getUserMessage'),
'options' =>
array(
'private' =>
true)),
18 "forum.message.delete" =>
array(__CLASS__,
"deleteMessage")
30 'MESSAGES' =>
array(),
68 if (intval(
$options[
'FIRST_ID']) > 0)
83 $res = Bitrix\Forum\MessageTable::getList(
array(
86 'ID',
'POST_DATE',
'POST_MESSAGE',
'UF_FORUM_MESSAGE_DOC'
92 $attachedIdList =
array();
93 $messageAttachedList =
array();
101 'MESSAGE' => ($otherUserMode ?
'' : (
string)
$messageFields[
'POST_MESSAGE']),
120 if (!empty($attached))
122 $attachedIdList = array_merge($attachedIdList, $attached);
129 $attachedObjectList =
array();
132 !empty($attachedIdList)
133 && Loader::includeModule(
'disk')
136 $res = Bitrix\Disk\AttachedObject::getList(
array(
138 '@ID' => array_unique($attachedIdList)
140 'select' =>
array(
'ID',
'OBJECT_ID')
142 while($attachedObjectFields =
$res->fetch())
144 $diskObjectId = $attachedObjectFields[
'OBJECT_ID'];
146 if ($fileData = self::getFileData($diskObjectId))
148 $attachedObjectList[$attachedObjectFields[
'ID']] = $diskObjectId;
149 $result[
'FILES'][$diskObjectId] = $fileData;
156 if ($value[
'DATE'] instanceof \
Bitrix\Main\Type\DateTime)
158 $result[
'MESSAGES'][
$key][
'DATE'] = date(
'c', $value[
'DATE']->getTimestamp());
161 if (!empty($messageAttachedList[
$key]))
163 foreach($messageAttachedList[
$key] as $attachedId)
165 if (!empty($attachedObjectList[$attachedId]))
167 $result[
'MESSAGES'][
$key][
'ATTACH'][] = $attachedObjectList[$attachedId];
184 static $obCache =
null;
190 throw new Exception(
'Wrong message ID');
201 $arMessage = self::getForumMessageFields(
$messageId);
202 if (empty($arMessage))
204 throw new Exception(
'No message found');
207 $currentUserPerm = self::getForumMessagePerm(
array(
208 'USER_ID' => $currentUserId,
212 if ($currentUserPerm < self::PERM_WRITE)
214 throw new Exception(
'No write perms');
219 && Loader::includeModule(
'socialnetwork')
222 $logIdList =
array();
227 '@EVENT_ID' =>
array(
'forum')
229 'select' =>
array(
'ID')
231 while ($logFields =
$res->fetch())
233 if (CSocNetLog::delete($logFields[
'ID']))
235 $logIdList[] = intval($logFields[
'ID']);
239 if (empty($logIdList))
244 '@EVENT_ID' =>
array(
'forum',
'tasks_comment',
'calendar_comment',
'timeman_entry_comment',
'report_comment',
'photo_comment',
'wiki_comment',
'lists_new_element_comment')
246 'select' =>
array(
'ID',
'LOG_ID')
248 while ($logCommentFields =
$res->fetch())
250 if (CSocNetLogComments::delete($logCommentFields[
'ID']))
252 $logIdList[] = intval($logFields[
'LOG_ID']);
257 if (!empty($logIdList))
259 foreach($logIdList as $logId)
261 if ($obCache ===
null)
265 $obCache->CleanDir(
"/sonet/log/".intval($logId / 1000).
"/".$logId.
"/comments/");
273 private static function getForumMessagePerm(
$arFields)
289 $arMessage = self::getForumMessageFields(
$messageId);
290 if (empty($arMessage))
296 $arMessage[
"AUTHOR_ID"] == $currentUserId
298 Loader::includeModule(
'socialnetwork')
299 && CSocNetUser::isUserModuleAdmin($currentUserId,
SITE_ID)
309 private static function getForumMessageFields(
$messageId)
313 $res = \Bitrix\Forum\MessageTable::getList(
array(
317 'select' =>
array(
'*')
326 private static function isAdmin()
332 Loader::includeModule(
'bitrix24')
333 && \CBitrix24::isPortalAdmin(
$USER->getId())
338 private static function getFileData($diskObjectId)
342 $diskObjectId = intval($diskObjectId);
343 if ($diskObjectId <= 0)
348 if ($fileModel = \Bitrix\Disk\File::getById($diskObjectId))
352 $imageParams =
false;
353 if (\Bitrix\Disk\TypeFile::isImage($fileModel))
356 $params = $fileModel->getFile();
357 $imageParams = Array(
358 'width' => (
int)
$params[
'WIDTH'],
359 'height' => (
int)
$params[
'HEIGHT'],
362 else if (\Bitrix\Disk\TypeFile::isVideo($fileModel->getName()))
365 $params = $fileModel->getView()->getPreviewData();
366 $imageParams = Array(
367 'width' => (
int)
$params[
'WIDTH'],
368 'height' => (
int)
$params[
'HEIGHT'],
372 $isImage = \Bitrix\Disk\TypeFile::isImage($fileModel);
373 $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
376 'id' => (
int)$fileModel->getId(),
377 'date' => $fileModel->getCreateTime(),
379 'name' => $fileModel->getName(),
380 'size' => (
int)$fileModel->getSize(),
381 'image' => $imageParams,
382 'authorId' => (
int)$fileModel->getCreatedBy(),
383 'authorName' => CUser::FormatName(CSite::getNameFormat(
false), $fileModel->getCreateUser(),
true,
true),
385 $fileModel->getPreviewId()
386 ? $urlManager->getUrlForShowPreview($fileModel, [
'width' => 640,
'height' => 640])
389 ? $urlManager->getUrlForShowFile($fileModel, [
'width' => 640,
'height' => 640])
393 'urlShow' => ($isImage ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlForDownloadFile($fileModel)),
394 'urlDownload' => $urlManager->getUrlForDownloadFile($fileModel)
401 private static function convertFileData($fileData)
403 if (!is_array($fileData))
408 foreach ($fileData as
$key => $value)
410 if ($value[
'date'] instanceof \Bitrix\Main\Type\DateTime)
415 foreach ([
'urlPreview',
'urlShow',
'urlDownload'] as $field)
418 if (is_string(
$url) &&
$url && mb_strpos(
$url,
'http') !== 0)
420 $fileData[
$key][$field] = self::getPublicDomain().$url;
428 private static function getPublicDomain()
433 $result = (\Bitrix\Main\Context::getCurrent()->getRequest()->isHttps() ?
"https" :
"http").
"://".((defined(
"SITE_SERVER_NAME") && SITE_SERVER_NAME <>
'') ? SITE_SERVER_NAME : \Bitrix\Main\Config\Option::get(
"main",
"server_name",
$_SERVER[
'SERVER_NAME']));
static getList(array $parameters=array())
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)