Fix missing error message when embedding fails

This commit is contained in:
Trevor Slocum 2020-11-30 17:25:48 -08:00
parent 74540e68b3
commit 91c137b264
2 changed files with 18 additions and 4 deletions

View File

@ -338,8 +338,9 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name'])
if (!TINYIB_UPLOADVIAURL) {
fancyDie(sprintf(__('Invalid embed URL. Only %s URLs are supported.'), implode('/', array_keys($tinyib_embeds))));
}
$headers = get_headers(trim($_POST['embed']), true);
if (TINYIB_MAXKB > 0 && intval($headers['Content-Length']) > (TINYIB_MAXKB * 1024)) {
if (TINYIB_MAXKB > 0 && isset($headers['Content-Length']) && intval($headers['Content-Length']) > (TINYIB_MAXKB * 1024)) {
fancyDie(sprintf(__('That file is larger than %s.'), TINYIB_MAXKBDESC));
}
@ -348,6 +349,10 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name'])
fancyDie(__('Failed to download file at specified URL.'));
}
if (TINYIB_MAXKB > 0 && strlen($data) > (TINYIB_MAXKB * 1024)) {
fancyDie(sprintf(__('That file is larger than %s.'), TINYIB_MAXKBDESC));
}
$filepath = 'src/' . time() . substr(microtime(), 2, 3) . rand(1000, 9999) . '.txt';
if (!file_put_contents($filepath, $data)) {
@unlink($filepath);

View File

@ -574,9 +574,15 @@ function url_get_contents($url) {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$responsecode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (intval($responsecode) != 200) {
return '';
}
return $output;
}
@ -589,11 +595,14 @@ function getEmbed($url) {
global $tinyib_embeds;
foreach ($tinyib_embeds as $service => $service_url) {
$service_url = str_ireplace("TINYIBEMBED", urlencode($url), $service_url);
$result = json_decode(url_get_contents($service_url), true);
$data = url_get_contents($service_url);
if ($data != '') {
$result = json_decode($data, true);
if (!empty($result)) {
return array($service, $result);
}
}
}
return array('', array());
}