4use \Bitrix\Main\Web\DOM;
5use \Bitrix\Landing\Manager;
6use \Bitrix\Landing\File;
13 const ACTION_DOWNLOAD_FILE =
'/bitrix/tools/disk/uf.php?attachedId=#attachedId#&action=download&ncc=1';
22 static $parser =
null;
26 $parser = new \CTextParser;
27 $parser->allow[
'SMILES'] =
'N';
31 $text = preg_replace(
'#\[P\]\s*\[VIDEO#s',
'[VIDEO', $text);
32 $text = preg_replace(
'#\[/VIDEO\]\s*\[/P\]#s',
'[/VIDEO]', $text);
34 $text = $parser->convertText($text);
37 $text = preg_replace(
'#<p>\s*</p>#s',
'<br/>', $text);
49 if (preg_match(
'#^//www.youtube.com/embed/([^?]+)#i', $videoSrc, $matches))
51 $ytCode = $matches[1];
55 'source' =>
'https://www.youtube.com/watch?v=' . $ytCode,
56 'preview' =>
'//img.youtube.com/vi/' .$ytCode .
'/sddefault.jpg'
69 protected static function getImgContent($attacheId, array $files = []): ?array
71 if (isset($files[$attacheId]))
73 $fileItem = $files[$attacheId];
74 $file = \CFile::getFileArray($fileItem[
'file_id']);
75 if (strpos($file[
'CONTENT_TYPE'],
'image/') === 0)
77 $fileIO = new \Bitrix\Main\IO\File(
80 if ($fileIO->isExists())
83 $fileItem[
'file_name'],
84 base64_encode($fileIO->getContents())
89 'id' => $newFile[
'ID'],
110 foreach ($files as $fId => $item)
114 $actionUrl = str_replace(
117 self::ACTION_DOWNLOAD_FILE
119 $replace[
'[DISK FILE ID=' . $fId .
']'] =
120 '<a href="' . $actionUrl .
'" target="_blank">' .
129 array_keys($replace),
130 array_values($replace),
147 $content = $node->getOuterHTML();
148 $attrs = $node->getAttributes();
151 if (isset($attrs[
'class']) && in_array($attrs[
'class']->getValue(), [
'quote',
'code']))
153 $type = $attrs[
'class']->getValue();
154 $regExp =
'#^<div class="' . $type .
'">\s*<table class="' . $type .
'"><tr><td>' .
155 '(.*?)</td></tr></table></div>$#is';
156 if (preg_match($regExp, $content, $matches))
158 $content = $matches[1];
160 if ($type ==
'code' && preg_match(
'#^<pre>(.*?)</pre>$#is', $content, $matches))
162 $content = $matches[1];
166 else if (isset($attrs[
'class']) && $attrs[
'class']->getValue() ==
'data-table')
171 else if (($node->getNodeName() ==
'IFRAME') && isset($attrs[
'src']))
175 $attrs[
'src']->getValue()
179 else if (preg_match(
'/^\[DISK FILE ID=([^\]]+)\]/is', trim($content), $matches))
188 isset($params[
'files']) &&
189 is_array($params[
'files'])
199 'content' => $content
212 public static function textToBlocks(
string $text, array $params = []): array
217 $dom =
new DOM\Document;
219 $dom->loadHTML($text);
221 foreach ($dom->getChildNodesArray() as $child)
228 $bewBlock[
'type'] ==
'text' &&
229 $blocks[$count][
'type'] ==
'text'
232 $blocks[$count][
'content'] .= $bewBlock[
'content'];
237 $blocks[] = $bewBlock;
243 foreach ($blocks as $key => $item)
245 if ($item[
'type'] ==
'text')
247 if (!trim(str_replace([
'<br />',
'<br/>'],
'', $item[
'content'])))
249 unset($blocks[$key]);
254 return array_values($blocks);
static getFilePath($fileId)
static savePicture($file, $ext=false, $params=array())
static replaceFilesInContent(string $text, array $files=[])
static getVideoContent(string $videoSrc)
static convertText(string $text)
static getImgContent($attacheId, array $files=[])
static textToBlocks(string $text, array $params=[])
static getBlockFromNode(\Bitrix\Main\Web\DOM\Node $node, array $params=[])
const ACTION_DOWNLOAD_FILE