Merge pull request #10207 from annando/simplify
Replace "curl" calls with centralized "head" function
This commit is contained in:
commit
536582305a
1 changed files with 14 additions and 25 deletions
|
@ -1104,20 +1104,14 @@ class BBCode
|
||||||
$text = DI::cache()->get($cache_key);
|
$text = DI::cache()->get($cache_key);
|
||||||
|
|
||||||
if (is_null($text)) {
|
if (is_null($text)) {
|
||||||
$a = DI::app();
|
$curlResult = DI::httpRequest()->head($match[1], ['timeout' => DI::config()->get('system', 'xrd_timeout')]);
|
||||||
|
if ($curlResult->isSuccess()) {
|
||||||
|
$mimetype = $curlResult->getHeader('Content-Type');
|
||||||
|
} else {
|
||||||
|
$mimetype = '';
|
||||||
|
}
|
||||||
|
|
||||||
$stamp1 = microtime(true);
|
if (substr($mimetype, 0, 6) == 'image/') {
|
||||||
|
|
||||||
$ch = @curl_init($match[1]);
|
|
||||||
@curl_setopt($ch, CURLOPT_NOBODY, true);
|
|
||||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
@curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
|
|
||||||
@curl_exec($ch);
|
|
||||||
$curl_info = @curl_getinfo($ch);
|
|
||||||
|
|
||||||
DI::profiler()->saveTimestamp($stamp1, "network");
|
|
||||||
|
|
||||||
if (substr($curl_info['content_type'], 0, 6) == 'image/') {
|
|
||||||
$text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
|
$text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
|
||||||
} else {
|
} else {
|
||||||
$text = "[url=" . $match[2] . ']' . $match[2] . "[/url]";
|
$text = "[url=" . $match[2] . ']' . $match[2] . "[/url]";
|
||||||
|
@ -1181,20 +1175,15 @@ class BBCode
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only fetch the header, not the content
|
$curlResult = DI::httpRequest()->head($match[1], ['timeout' => DI::config()->get('system', 'xrd_timeout')]);
|
||||||
$stamp1 = microtime(true);
|
if ($curlResult->isSuccess()) {
|
||||||
|
$mimetype = $curlResult->getHeader('Content-Type');
|
||||||
$ch = @curl_init($match[1]);
|
} else {
|
||||||
@curl_setopt($ch, CURLOPT_NOBODY, true);
|
$mimetype = '';
|
||||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
}
|
||||||
@curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
|
|
||||||
@curl_exec($ch);
|
|
||||||
$curl_info = @curl_getinfo($ch);
|
|
||||||
|
|
||||||
DI::profiler()->saveTimestamp($stamp1, "network");
|
|
||||||
|
|
||||||
// if its a link to a picture then embed this picture
|
// if its a link to a picture then embed this picture
|
||||||
if (substr($curl_info['content_type'], 0, 6) == 'image/') {
|
if (substr($mimetype, 0, 6) == 'image/') {
|
||||||
$text = '[img]' . $match[1] . '[/img]';
|
$text = '[img]' . $match[1] . '[/img]';
|
||||||
} else {
|
} else {
|
||||||
if (!empty($match[3])) {
|
if (!empty($match[3])) {
|
||||||
|
|
Loading…
Reference in a new issue