17 public static function sanitizeContent(
string $content, ?
string $oldContent =
null,
bool &$replaced =
false): string
19 if (!\
Bitrix\Main\Loader::includeModule(
'disk'))
28 if (preg_match_all(
'/' . self::FILE_MASK_HREF .
'/i', $oldContent, $matches))
30 foreach ($matches[2] as $objectId)
32 $existsFiles[] = $objectId;
37 if (preg_match_all(
'/' . self::FILE_MASK_HREF .
'/i', $content, $matches))
39 foreach ($matches[2] as $i => $objectId)
41 if ($oldContent && in_array($objectId, $existsFiles))
46 $file = \Bitrix\Disk\BaseObject::loadById($objectId);
49 $securityContext = $file->getStorage()->getCurrentUserSecurityContext();
50 if ($file->canRead($securityContext))
57 $content = str_replace($matches[0][$i],
'""', $content);
72 public static function getFileInfo(
int $objectId,
bool $checkRights =
true,
bool $copyInLocalStorage =
false): ?array
74 if ($objectId && \
Bitrix\Main\Loader::includeModule(
'disk'))
76 $file = \Bitrix\Disk\BaseObject::loadById($objectId);
81 $securityContext = $file->getStorage()->getCurrentUserSecurityContext();
82 if (!$file->canRead($securityContext))
88 if ($copyInLocalStorage)
90 $currentUserId = \Bitrix\Landing\Manager::getUserId();
91 $userStorage = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($currentUserId);
97 $folder = $userStorage->getFolderForSavedFiles();
104 $file->getStorageId() !== $userStorage->getId() ||
105 (
int)$file->getCreateUser()->getId() !== $currentUserId
108 $newFile = $file->getRealObject()->copyTo($folder, $currentUserId,
true);
109 if ($file->getRealObject()->getName() != $file->getName())
111 $newFile->renameInternal($file->getName(),
true);
119 'ID' => $newFile->getRealObject()->getFileId(),
120 'OBJECT_ID' => $newFile->getId(),
121 'NAME' => $newFile->getName()
127 'ID' => $file->getRealObject()->getFileId(),
128 'OBJECT_ID' => $file->getId(),
129 'NAME' => $file->getName()