Some more improvements for posts with shares

This commit is contained in:
Michael 2022-10-26 17:00:55 +00:00
parent db82bdfc44
commit c65fff6f93
10 changed files with 100 additions and 99 deletions

View file

@ -1070,6 +1070,30 @@ class BBCode
return $attributes;
}
/**
* Checks, if the provided body contains a native reshare
*
* @param string $body
* @return boolean
*/
public static function isNativeReshare(string $body): bool
{
$shared = BBCode::fetchShareAttributes($body);
return !empty($shared['guid'] ?? '');
}
/**
* Checks if the provided body contains a "share" element
*
* @param string $body
* @return boolean
*/
public static function existsShare(string $body): bool
{
$shared = BBCode::fetchShareAttributes($body);
return !empty($shared['link'] ?? '');
}
/**
* Replace the share block with a link
*
@ -1094,7 +1118,7 @@ class BBCode
*/
public static function removeSharedData(string $body): string
{
return preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
return trim(preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body));
}
/**