mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 11:11:39 +09:00
썸네일 만드는 로직을 변경하여 한번에 썸네일을 만들 수 있도록 수정. 썸네일 크기보다 작은 외부 링크 이미지는 무시하도록 변경
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4369 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
e8d0fc5101
commit
1e69961d55
2 changed files with 52 additions and 31 deletions
|
|
@ -258,10 +258,10 @@
|
|||
|
||||
// 이미지 정보가 정해진 크기보다 크면 크기를 바꿈 (%를 구해서 처리)
|
||||
if($resize_width > 0 && $width >= $resize_width) $width_per = $resize_width / $width;
|
||||
else $width_per = $width / $resize_width;
|
||||
else $width_per = 1;
|
||||
|
||||
if($resize_height>0 && $height >= $resize_height) $height_per = $resize_height / $height;
|
||||
else $height_per = $height / $resize_height;
|
||||
else $height_per = 1;
|
||||
|
||||
if($thumbnail_type == 'ratio') {
|
||||
if($width_per>$height_per) $per = $height_per;
|
||||
|
|
@ -309,10 +309,6 @@
|
|||
return;
|
||||
}
|
||||
|
||||
// 디렉토리 생성
|
||||
$path = preg_replace('/\/([^\.^\/]*)\.(gif|png|jpg|jpeg|bmp|wbmp)$/i','',$target_file);
|
||||
FileHandler::makeDir($path);
|
||||
|
||||
// 원본 이미지의 크기를 조절해서 임시 이미지에 넣음
|
||||
$new_width = (int)($width * $per);
|
||||
$new_height = (int)($height * $per);
|
||||
|
|
@ -328,7 +324,11 @@
|
|||
if($source) {
|
||||
if(function_exists('imagecopyresampled')) @imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
||||
else @imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
||||
}
|
||||
} else return false;
|
||||
|
||||
// 디렉토리 생성
|
||||
$path = dirname($target_file);
|
||||
if(!is_dir($path)) FileHandler::makeDir($path);
|
||||
|
||||
// 파일을 쓰고 끝냄
|
||||
switch($target_type) {
|
||||
|
|
@ -348,8 +348,10 @@
|
|||
break;
|
||||
}
|
||||
|
||||
if(!$output) return false;
|
||||
@imagedestroy($thumb);
|
||||
@imagedestroy($source);
|
||||
|
||||
if(!$output) return false;
|
||||
@chmod($target_file, 0644);
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -459,12 +459,15 @@
|
|||
$modified_time = $this->get('last_update');
|
||||
|
||||
// 만약 글의 수정시간보다 이후에 만들어진 썸네일이라면 썸네일 크기에 따라서 경로 또는 빈 문자열을 return
|
||||
if($modified_time < $file_created_time) return filesize($thumbnail_file)>0?$thumbnail_url:'';
|
||||
if($modified_time < $file_created_time && filesize($thumbnail_file)>0) return $thumbnail_url;
|
||||
else return false;
|
||||
}
|
||||
|
||||
FileHandler::writeFile($thumbnail_file, '','w');
|
||||
// 대상 파일
|
||||
$source_file = null;
|
||||
$is_tmp_file = false;
|
||||
|
||||
// 문서에 첨부된 파일이 있으면 첫번째 멀티미디어 파일을 구함
|
||||
// 첨부된 파일중 이미지 파일이 있으면 찾음
|
||||
if($this->hasUploadedFiles()) {
|
||||
$file_list = $this->getUploadedFiles();
|
||||
if(count($file_list)) {
|
||||
|
|
@ -472,33 +475,49 @@
|
|||
if($file->direct_download!='Y') continue;
|
||||
if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$file->source_filename)) continue;
|
||||
|
||||
$filename = $file->uploaded_filename;
|
||||
if(!file_exists($filename)) continue;
|
||||
|
||||
if(FileHandler::createImageFile($filename, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type)) return Context::getRequestUri().$thumbnail_file;
|
||||
$source_file = $file->uploaded_filename;
|
||||
if(!file_exists($source_file)) continue;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 첨부된 파일이 없으면 내용중 이미지 파일을 구함
|
||||
$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++) {
|
||||
$target_src = $matches[$i][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;
|
||||
$tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111,999999).$this->document_srl));
|
||||
FileHandler::getRemoteFile($target_src, $tmp_file);
|
||||
if(!file_exists($tmp_file)) continue;
|
||||
$output = FileHandler::createImageFile($tmp_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
|
||||
FileHandler::removeFile($tmp_file);
|
||||
if($output) return Context::getRequestUri().$thumbnail_file;
|
||||
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++) {
|
||||
$target_src = $matches[$i][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;
|
||||
$tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111,999999).$this->document_srl));
|
||||
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) continue;
|
||||
|
||||
$source_file = $tmp_file;
|
||||
$is_tmp_file = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
|
||||
|
||||
if($is_tmp_file) FileHandler::removeFile($source_file);
|
||||
|
||||
// 썸네일 생성 성공시 경로 return
|
||||
if($output) return $thumbnail_url;
|
||||
|
||||
// 차후 다시 썸네일 생성을 시도하지 않기 위해 빈 파일을 생성
|
||||
else FileHandler::writeFile($thumbnail_file, '','w');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -530,7 +549,7 @@
|
|||
preg_match_all('!<img([^>]*?)>!is', $content, $matches);
|
||||
$cnt = count($matches[0]);
|
||||
for($i=0;$i<$cnt;$i++) {
|
||||
if(preg_match('/src=("|\'|\.|\/)*(common|modules|widgets|layouts)/i', $matches[0][$i])) continue;
|
||||
if(preg_match('/src=("|\'|\.|\/)*(common|modules|widgets|addons|layouts)/i', $matches[0][$i])) continue;
|
||||
$buffs[] = "image";
|
||||
$check_files = true;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue