[Embed] Use Formatting utilities rather than substr and such

This commit is contained in:
Hugo Sales 2021-04-29 12:53:42 +00:00
parent 9008bee558
commit ced610d942
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -364,8 +364,8 @@ END, ['embed' => $embed, 'attributes' => $attributes]);
$url = $attachment->getRemoteUrl(); $url = $attachment->getRemoteUrl();
if (substr($url, 0, 7) == 'file://') { if (Formatting::startsWith($url, 'file://')) {
$filename = substr($url, 7); $filename = Formatting::removePrefix($url, 'file://');
$info = getimagesize($filename); $info = getimagesize($filename);
$filename = basename($filename); $filename = basename($filename);
$width = $info[0]; $width = $info[0];
@ -446,7 +446,7 @@ END, ['embed' => $embed, 'attributes' => $attributes]);
$metadata['provider_url'] = $info->providerUrl; $metadata['provider_url'] = $info->providerUrl;
if (!is_null($info->image)) { if (!is_null($info->image)) {
if (substr($info->image, 0, 4) === 'data') { if (Formatting::startsWith($info->image, 'data')) {
// Inline image // Inline image
$imgData = base64_decode(substr($info->image, stripos($info->image, 'base64,') + 7)); $imgData = base64_decode(substr($info->image, stripos($info->image, 'base64,') + 7));
[$filepath, $width, $height, $original_name, $mimetype] = $this->validateAndWriteImage($imgData); [$filepath, $width, $height, $original_name, $mimetype] = $this->validateAndWriteImage($imgData);