Merge pull request #169 from kijin/pr/fix-external-thumbnails

#55 #56 외부이미지 섬네일 생성 개선
This commit is contained in:
BJRambo 2016-01-26 13:24:39 +09:00
commit 0d36d0402e
3 changed files with 35 additions and 31 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

@ -860,7 +860,7 @@ class documentItem extends Object
$config = $oDocumentModel->getDocumentConfig();
$GLOBALS['__document_config__'] = $config;
}
$thumbnail_type = $config->thumbnail_type;
$thumbnail_type = $config->thumbnail_type ?: 'crop';
}
// Define thumbnail information
@ -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;