From eb231bc548d93540fa7b1516cabb95cce3994ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 22 Jun 2022 17:09:20 +0200 Subject: [PATCH 1/4] Fixed: ?? didn't work here as bool won't be seen as null --- src/Util/Images.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/Images.php b/src/Util/Images.php index c36ce2689..4fa2eda04 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -247,7 +247,7 @@ class Images $data['size'] = $filesize; } - return $data ?? []; + return is_array($data) ? $data : []; } /** From b996712ef72e106c6735b8720c52bb3f2cc87dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 22 Jun 2022 17:18:39 +0200 Subject: [PATCH 2/4] Images::getInfoFromURL[Cached]() will both return empty arrays on error and that needs to be reflected here, too. --- src/Content/Text/BBCode.php | 4 ++-- src/Protocol/OStatus.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b4b8e4819..1c6f11c2f 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -111,7 +111,7 @@ class BBCode $picturedata = Images::getInfoFromURLCached($matches[1]); - if ($picturedata) { + if (!empty($picturedata)) { if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) { $post['image'] = $matches[1]; } else { @@ -320,7 +320,7 @@ class BBCode $post['text'] = trim(str_replace($pictures[0][0], '', $body)); } else { $imgdata = Images::getInfoFromURLCached($pictures[0][1]); - if ($imgdata && substr($imgdata['mime'], 0, 6) == 'image/') { + if (!empty($imgdata) && substr($imgdata['mime'], 0, 6) == 'image/') { $post['type'] = 'photo'; $post['image'] = $pictures[0][1]; $post['preview'] = $pictures[0][2]; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index d410fa4f7..be86c13be 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1377,7 +1377,7 @@ class OStatus case 'photo': if (!empty($siteinfo['image'])) { $imgdata = Images::getInfoFromURLCached($siteinfo['image']); - if ($imgdata) { + if (!empty($imgdata)) { $attributes = [ 'rel' => 'enclosure', 'href' => $siteinfo['image'], @@ -1388,6 +1388,7 @@ class OStatus } } break; + case 'video': $attributes = [ 'rel' => 'enclosure', @@ -1398,13 +1399,15 @@ class OStatus ]; XML::addElement($doc, $root, 'link', '', $attributes); break; + default: + Logger::warning('Unsupported type', ['type' => $siteinfo['type'], 'url' => $siteinfo['url']]); break; } if (!DI::config()->get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) { $imgdata = Images::getInfoFromURLCached($siteinfo['image']); - if ($imgdata) { + if (!empty($imgdata)) { $attributes = [ 'rel' => 'enclosure', 'href' => $siteinfo['image'], From 15d8341d9a8d384520331ec30e7991cb74d6c8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 22 Jun 2022 18:06:04 +0200 Subject: [PATCH 3/4] Converted multiple single-comment (//) to multi-line comment block (/* */) --- src/Util/ParseUrl.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 9f0fd8a9b..f86a6480b 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -543,8 +543,11 @@ class ParseUrl { if (!empty($siteinfo['images'])) { array_walk($siteinfo['images'], function (&$image) use ($page_url) { - // According to the specifications someone could place a picture url into the content field as well. - // But this doesn't seem to happen in the wild, so we don't cover it here. + /* + * According to the specifications someone could place a picture + * URL into the content field as well. But this doesn't seem to + * happen in the wild, so we don't cover it here. + */ if (!empty($image['url'])) { $image['url'] = self::completeUrl($image['url'], $page_url); $photodata = Images::getInfoFromURLCached($image['url']); From 7eefb9aed85dafa266aae0f8d5d019a35fc05853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 22 Jun 2022 18:56:08 +0200 Subject: [PATCH 4/4] Changed: - empty() is maybe superflous here, still I would prefer a code style that is written explicitly and not rely on "magic casting" --- src/Content/Text/BBCode.php | 4 ++-- src/Model/Post/Media.php | 4 ++-- src/Protocol/OStatus.php | 4 ++-- src/Util/ParseUrl.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 1c6f11c2f..c3e255a4d 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -111,7 +111,7 @@ class BBCode $picturedata = Images::getInfoFromURLCached($matches[1]); - if (!empty($picturedata)) { + if ($picturedata) { if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) { $post['image'] = $matches[1]; } else { @@ -320,7 +320,7 @@ class BBCode $post['text'] = trim(str_replace($pictures[0][0], '', $body)); } else { $imgdata = Images::getInfoFromURLCached($pictures[0][1]); - if (!empty($imgdata) && substr($imgdata['mime'], 0, 6) == 'image/') { + if (($imgdata) && substr($imgdata['mime'], 0, 6) == 'image/') { $post['type'] = 'photo'; $post['image'] = $pictures[0][1]; $post['preview'] = $pictures[0][2]; diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index 2b17614e8..3b23e5d0f 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -192,7 +192,7 @@ class Media if (($media['type'] == self::IMAGE) || ($filetype == 'image')) { $imagedata = Images::getInfoFromURLCached($media['url']); - if (!empty($imagedata)) { + if ($imagedata) { $media['mimetype'] = $imagedata['mime']; $media['size'] = $imagedata['size']; $media['width'] = $imagedata[0]; @@ -202,7 +202,7 @@ class Media } if (!empty($media['preview'])) { $imagedata = Images::getInfoFromURLCached($media['preview']); - if (!empty($imagedata)) { + if ($imagedata) { $media['preview-width'] = $imagedata[0]; $media['preview-height'] = $imagedata[1]; } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index be86c13be..ddc55a2c5 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1377,7 +1377,7 @@ class OStatus case 'photo': if (!empty($siteinfo['image'])) { $imgdata = Images::getInfoFromURLCached($siteinfo['image']); - if (!empty($imgdata)) { + if ($imgdata) { $attributes = [ 'rel' => 'enclosure', 'href' => $siteinfo['image'], @@ -1407,7 +1407,7 @@ class OStatus if (!DI::config()->get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) { $imgdata = Images::getInfoFromURLCached($siteinfo['image']); - if (!empty($imgdata)) { + if ($imgdata) { $attributes = [ 'rel' => 'enclosure', 'href' => $siteinfo['image'], diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index f86a6480b..ee171ea04 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -551,7 +551,7 @@ class ParseUrl if (!empty($image['url'])) { $image['url'] = self::completeUrl($image['url'], $page_url); $photodata = Images::getInfoFromURLCached($image['url']); - if (!empty($photodata) && ($photodata[0] > 50) && ($photodata[1] > 50)) { + if (($photodata) && ($photodata[0] > 50) && ($photodata[1] > 50)) { $image['src'] = $image['url']; $image['width'] = $photodata[0]; $image['height'] = $photodata[1];