Fix thumbnails for external URLs with no extension

This commit is contained in:
Kijin Sung 2016-01-26 11:13:57 +09:00
parent 9704cc9a66
commit 2f64a4ce8f
3 changed files with 34 additions and 30 deletions

View file

@ -571,6 +571,7 @@ class FileHandler
}
}
$url = str_replace('&', '&', $url);
$response = Requests::request($url, $request_headers, $body ?: $post_data, $method, $request_options);
if(count($response->cookies))

View file

@ -654,46 +654,41 @@ class commentItem extends Object
// get an image file from the doc content if no file attached.
if(!$source_file)
{
$content = $this->get('content');
$target_src = NULL;
preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER);
$cnt = count($matches);
for($i = 0; $i < $cnt; $i++)
preg_match_all("!<img\s[^>]*?src=(\"|')([^\"' ]*?)(\"|')!is", $this->get('content'), $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$target_src = $matches[$i][2];
$target_src = htmlspecialchars_decode(trim($match[2]));
if(preg_match('/\/(common|modules|widgets|addons|layouts)\//i', $target_src))
{
continue;
}
else
{
if(!preg_match('/^(http|https):\/\//i', $target_src))
if(!preg_match('/^https?:\/\//i',$target_src))
{
$target_src = Context::getRequestUri() . $target_src;
$target_src = Context::getRequestUri().$target_src;
}
$tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->comment_srl));
FileHandler::makeDir('./files/cache/tmp');
if(!is_dir('./files/cache/tmp'))
{
FileHandler::makeDir('./files/cache/tmp');
}
FileHandler::getRemoteFile($target_src, $tmp_file);
if(!file_exists($tmp_file))
{
continue;
}
else
{
list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file);
if($_w < $width || $_h < $height)
if($is_img = @getimagesize($tmp_file))
{
list($_w, $_h, $_t, $_a) = $is_img;
}
else
{
continue;
}
$source_file = $tmp_file;
$is_tmp_file = TRUE;
break;

View file

@ -925,22 +925,31 @@ class documentItem extends Object
// If not exists, file an image file from the content
if(!$source_file)
{
$target_src = null;
preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER);
$cnt = count($matches);
for($i=0;$i<$cnt;$i++)
preg_match_all("!<img\s[^>]*?src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$target_src = trim($matches[$i][2]);
if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$target_src)) continue;
if(preg_match('/\/(common|modules|widgets|addons|layouts)\//i', $target_src)) continue;
$target_src = htmlspecialchars_decode(trim($match[2]));
if(preg_match('/\/(common|modules|widgets|addons|layouts)\//i', $target_src))
{
continue;
}
else
{
if(!preg_match('/^(http|https):\/\//i',$target_src)) $target_src = Context::getRequestUri().$target_src;
if(!preg_match('/^https?:\/\//i',$target_src))
{
$target_src = Context::getRequestUri().$target_src;
}
$tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111,999999).$this->document_srl));
if(!is_dir('./files/cache/tmp')) FileHandler::makeDir('./files/cache/tmp');
if(!is_dir('./files/cache/tmp'))
{
FileHandler::makeDir('./files/cache/tmp');
}
FileHandler::getRemoteFile($target_src, $tmp_file);
if(!file_exists($tmp_file)) continue;
if(!file_exists($tmp_file))
{
continue;
}
else
{
if($is_img = @getimagesize($tmp_file))
@ -951,7 +960,6 @@ class documentItem extends Object
{
continue;
}
$source_file = $tmp_file;
$is_tmp_file = true;
break;