11use CIMMessageParamAttach;
15 protected string $url =
'';
33 $metadata = static::$staticMetadataCache[$this->
getUrl()] ??
null;
34 if ($metadata ===
null && $withFetchMetadata)
47 if ($metadata !==
false &&
$metadata !==
null)
64 $metadata = UrlPreview::getMetadataAndHtmlByIds([$previewUrlId]);
68 $metadata = UrlPreview::getMetadataByIds([$previewUrlId]);
75 return static::initByMetadata(
$metadata[$previewUrlId]);
89 $textParser = static::getTextParser();
90 $text = $textParser->convertText($text);
92 $text = preg_replace(
'/-{54}.+?-{54}/s'.BX_UTF_PCRE_MODIFIER,
"", $text);
93 $text = preg_replace(
'/\[CODE](.*?)\[\/CODE]/si'.BX_UTF_PCRE_MODIFIER,
"", $text);
95 preg_replace_callback(
96 '/^(>>(.*)(\n)?)/mi'.BX_UTF_PCRE_MODIFIER,
97 static fn() =>
" XXX",
102 preg_replace_callback(
103 '/\[url(=(?P<URL>[^\]]+))?](?P<TEXT>.*?)\[\/url]/i'.BX_UTF_PCRE_MODIFIER,
104 static function (array $matches) use (&$result) {
105 $link = !empty($matches[
'URL'])? $matches[
'URL']: $matches[
'TEXT'];
108 $link = static::normalizeUrl($link);
109 if (static::isUrlValid($link))
130 if ($firstUrl ===
null)
135 return new self($firstUrl);
140 if (isset($this->richData))
147 return $metadata[
'ID'] ??
null;
153 'source' => $this->
getUrl(),
154 'richData' => $this->
getRichData()->toRestFormat(),
160 $textParser = new \CTextParser();
162 $textParser->anchorType =
'bbcode';
164 foreach ($textParser->allow as $tag => $value)
166 $textParser->allow[$tag] =
'N';
168 $textParser->allow[
'HTML'] =
'Y';
169 $textParser->allow[
'ANCHOR'] =
'Y';
170 $textParser->allow[
'TEXT_ANCHOR'] =
'Y';
178 if ($uri->getHost() ===
'')
183 return $uri->getUri();
189 !($parsedUrl = \parse_url(
$url))
190 || empty($parsedUrl[
'host'])
191 || strpos($parsedUrl[
'host'],
'.') ===
false
192 || preg_match(
"/[\s]+/", $parsedUrl[
'host'])
193 || (!empty($parsedUrl[
'port']) && !is_numeric($parsedUrl[
'port']))
207 if (static::isUrlValid(
$url))
241 if (isset($this->richData))
255 if (
$metadata[
'TYPE'] === UrlMetadataTable::TYPE_STATIC)
259 elseif (
$metadata[
'TYPE'] === UrlMetadataTable::TYPE_DYNAMIC)
269 return $this->richData->setId(
$metadata[
'ID']);
280 return !empty($this->metadata);
285 if ($this->urlAttach ===
null)
289 $this->urlAttach = \CIMMessageLink::formatAttach($this->
getMetadata()) ?:
null;
static initByAttach(?\CIMMessageParamAttach $attach)
static getRestEntityName()
setUrlAttach(?CIMMessageParamAttach $urlAttach)
static normalizeUrl(string $url)
toRestFormat(array $option=[])
static initByPreviewUrlId(int $previewUrlId, bool $withHtml=true)
setMetadata(array $metadata)
__construct(?string $url=null, bool $withFetchMetadata=true)
static initByMetadata(array $metadata)
static array $staticMetadataCache
setRichData(?RichData $richData)
static getUrlsFromText(?string $text)
CIMMessageParamAttach $urlAttach
static getFirstUrlFromText(?string $text)
static isUrlValid(string $url)
static getByMessage(Message $message)