Use file_get_contents if cURL isn't installed

This commit is contained in:
Trevor Slocum 2017-12-14 14:36:57 -08:00
parent 6a26e32594
commit ddcacf46b0
3 changed files with 28 additions and 29 deletions

View File

@ -28,10 +28,10 @@ Features
Installing Installing
------------ ------------
1. Verify the following requirements are met: 1. Verify the following are installed:
- [PHP](http://php.net) 4 or higher is installed. - [PHP 4.3+](http://php.net)
- [GD Image Processing Library](http://php.net/gd) is installed. - [GD Image Processing Library](http://php.net/gd)
- This library is installed by default on most hosts. - This library is usually installed by default.
- If you plan on disabling image uploads to use TinyIB as a text board only, this library is not required. - If you plan on disabling image uploads to use TinyIB as a text board only, this library is not required.
2. CD to the directory you wish to install TinyIB. 2. CD to the directory you wish to install TinyIB.
3. Run the command: 3. Run the command:
@ -112,7 +112,9 @@ If there was a warning about AUTO_INCREMENT not being updated, you'll need to up
Support Support
------------ ------------
Contact tslocum@gmail.com 1. Ensure you are running the latest version of TinyIB.
2. Review the [open issues](https://github.com/tslocum/TinyIB/issues).
3. Open a [new issue](https://github.com/tslocum/TinyIB/issues/new).
Contributing Contributing
------------ ------------

View File

@ -108,19 +108,6 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
$post['file_hex'] = $service; $post['file_hex'] = $service;
$temp_file = time() . substr(microtime(), 2, 3); $temp_file = time() . substr(microtime(), 2, 3);
$file_location = "thumb/" . $temp_file; $file_location = "thumb/" . $temp_file;
function url_get_contents ($url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
file_put_contents($file_location, url_get_contents($embed['thumbnail_url'])); file_put_contents($file_location, url_get_contents($embed['thumbnail_url']));
$file_info = getimagesize($file_location); $file_info = getimagesize($file_location);

View File

@ -529,6 +529,21 @@ function strallpos($haystack, $needle, $offset = 0) {
return $result; return $result;
} }
function url_get_contents($url) {
if (!function_exists('curl_init')) {
return file_get_contents($url);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function isEmbed($file_hex) { function isEmbed($file_hex) {
global $tinyib_embeds; global $tinyib_embeds;
return in_array($file_hex, array_keys($tinyib_embeds)); return in_array($file_hex, array_keys($tinyib_embeds));
@ -538,12 +553,7 @@ function getEmbed($url) {
global $tinyib_embeds; global $tinyib_embeds;
foreach ($tinyib_embeds as $service => $service_url) { foreach ($tinyib_embeds as $service => $service_url) {
$service_url = str_ireplace("TINYIBEMBED", urlencode($url), $service_url); $service_url = str_ireplace("TINYIBEMBED", urlencode($url), $service_url);
$curl = curl_init($service_url); $result = json_decode(url_get_contents($service_url), true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$return = curl_exec($curl);
curl_close($curl);
$result = json_decode($return, true);
if (!empty($result)) { if (!empty($result)) {
return array($service, $result); return array($service, $result);
} }