From 13f58abe05f72832a7910e43fd20c931d4cc7b0f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 24 Mar 2018 20:03:28 -0400 Subject: [PATCH 1/2] Add parameter check in Image::getInfoFromURL --- src/Object/Image.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Object/Image.php b/src/Object/Image.php index 2f4d55dc0..9692b8471 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -771,6 +771,10 @@ class Image { $data = []; + if (empty($url)) { + return $data; + } + $data = Cache::get($url); if (is_null($data) || !$data || !is_array($data)) { From 09f04c19856d4e17a757927c9bb3a03566da54d4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 24 Mar 2018 20:03:55 -0400 Subject: [PATCH 2/2] Add Image::getInfoFromURL return check --- src/Content/Text/BBCode.php | 12 +++++++----- src/Protocol/OStatus.php | 26 +++++++++++++++----------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index ebaef2b29..7d1c42976 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -76,10 +76,12 @@ class BBCode extends BaseObject $picturedata = Image::getInfoFromURL($matches[1]); - if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) { - $post["image"] = $matches[1]; - } else { - $post["preview"] = $matches[1]; + if ($picturedata) { + if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) { + $post["image"] = $matches[1]; + } else { + $post["preview"] = $matches[1]; + } } } @@ -266,7 +268,7 @@ class BBCode extends BaseObject $post["text"] = str_replace($pictures[0][0], "", $body); } else { $imgdata = Image::getInfoFromURL($pictures[0][1]); - if (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/Protocol/OStatus.php b/src/Protocol/OStatus.php index 602d178bc..8b6939214 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1313,7 +1313,7 @@ class OStatus } /** - * @brief Adds attachement data to the XML document + * @brief Adds attachment data to the XML document * * @param object $doc XML document * @param object $root XML root element where the hub links are added @@ -1328,11 +1328,13 @@ class OStatus switch ($siteinfo["type"]) { case 'photo': $imgdata = Image::getInfoFromURL($siteinfo["image"]); - $attributes = ["rel" => "enclosure", - "href" => $siteinfo["image"], - "type" => $imgdata["mime"], - "length" => intval($imgdata["size"])]; - XML::addElement($doc, $root, "link", "", $attributes); + if ($imgdata) { + $attributes = ["rel" => "enclosure", + "href" => $siteinfo["image"], + "type" => $imgdata["mime"], + "length" => intval($imgdata["size"])]; + XML::addElement($doc, $root, "link", "", $attributes); + } break; case 'video': $attributes = ["rel" => "enclosure", @@ -1348,12 +1350,14 @@ class OStatus if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) { $imgdata = Image::getInfoFromURL($siteinfo["image"]); - $attributes = ["rel" => "enclosure", - "href" => $siteinfo["image"], - "type" => $imgdata["mime"], - "length" => intval($imgdata["size"])]; + if ($imgdata) { + $attributes = ["rel" => "enclosure", + "href" => $siteinfo["image"], + "type" => $imgdata["mime"], + "length" => intval($imgdata["size"])]; - XML::addElement($doc, $root, "link", "", $attributes); + XML::addElement($doc, $root, "link", "", $attributes); + } } $arr = explode('[/attach],', $item['attach']);