Add Image::getInfoFromURL return check

This commit is contained in:
Hypolite Petovan 2018-03-24 20:03:55 -04:00
parent 13f58abe05
commit 09f04c1985
2 changed files with 22 additions and 16 deletions

View File

@ -76,12 +76,14 @@ class BBCode extends BaseObject
$picturedata = Image::getInfoFromURL($matches[1]); $picturedata = Image::getInfoFromURL($matches[1]);
if ($picturedata) {
if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) { if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) {
$post["image"] = $matches[1]; $post["image"] = $matches[1];
} else { } else {
$post["preview"] = $matches[1]; $post["preview"] = $matches[1];
} }
} }
}
if (preg_match("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) { if (preg_match("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) {
$post["url"] = $matches[1]; $post["url"] = $matches[1];
@ -266,7 +268,7 @@ class BBCode extends BaseObject
$post["text"] = str_replace($pictures[0][0], "", $body); $post["text"] = str_replace($pictures[0][0], "", $body);
} else { } else {
$imgdata = Image::getInfoFromURL($pictures[0][1]); $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["type"] = "photo";
$post["image"] = $pictures[0][1]; $post["image"] = $pictures[0][1];
$post["preview"] = $pictures[0][2]; $post["preview"] = $pictures[0][2];

View File

@ -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 $doc XML document
* @param object $root XML root element where the hub links are added * @param object $root XML root element where the hub links are added
@ -1328,11 +1328,13 @@ class OStatus
switch ($siteinfo["type"]) { switch ($siteinfo["type"]) {
case 'photo': case 'photo':
$imgdata = Image::getInfoFromURL($siteinfo["image"]); $imgdata = Image::getInfoFromURL($siteinfo["image"]);
if ($imgdata) {
$attributes = ["rel" => "enclosure", $attributes = ["rel" => "enclosure",
"href" => $siteinfo["image"], "href" => $siteinfo["image"],
"type" => $imgdata["mime"], "type" => $imgdata["mime"],
"length" => intval($imgdata["size"])]; "length" => intval($imgdata["size"])];
XML::addElement($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
}
break; break;
case 'video': case 'video':
$attributes = ["rel" => "enclosure", $attributes = ["rel" => "enclosure",
@ -1348,6 +1350,7 @@ class OStatus
if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) { if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
$imgdata = Image::getInfoFromURL($siteinfo["image"]); $imgdata = Image::getInfoFromURL($siteinfo["image"]);
if ($imgdata) {
$attributes = ["rel" => "enclosure", $attributes = ["rel" => "enclosure",
"href" => $siteinfo["image"], "href" => $siteinfo["image"],
"type" => $imgdata["mime"], "type" => $imgdata["mime"],
@ -1355,6 +1358,7 @@ class OStatus
XML::addElement($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
} }
}
$arr = explode('[/attach],', $item['attach']); $arr = explode('[/attach],', $item['attach']);
if (count($arr)) { if (count($arr)) {