리스트화면 N번째 이미지 가져오기 정보
리스트화면 N번째 이미지 가져오기본문
5.4기준입니다...만 5.3이하에서도 hook와 캐쉬 부분만 코어의 함수와 비교해서 수정하시면 사용하실 수 있습니다.
게시판 리스트 화면에서 원하는 N번째 이미지를 불러오는 내용입니다.
extend에 파일로 넣으셔도 되고 lib.php 파일로 불러와서 사용하셔도 됩니다.
코어의 thumbnail.lib.php가 꼭 필요합니다.
1. 코어의 게시판스킨 > list.skin.php 에서
$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_mobile_gallery_width'], $board['bo_mobile_gallery_height']);
부분
$thumb = mwb_get_list_thumbnail_nth(숫자, $board['bo_table'], $list[$i]['wr_id'], $board['bo_mobile_gallery_width'], $board['bo_mobile_gallery_height']);
변경
2. $nth에 불러오기를 원하는 n번째 숫자를 넣으면 됩니다.
3. 해당 게시판의 첨부파일 갯수보다 높은 숫자를 넣을 경우 기본 get_list_thumbnail처럼 첫번째 이미지를 불러옵니다. (n번째 이미지를 불어오는 경우 대부분이 첨부파일 이미지를 불러오는 경우가 더 많을 것 같아 숫자의 제한을 첨부파일의 개수를 기준으로 맞췄습니다.)
4. 오류를 최대한 줄이기 위해 $nth부분에 음수를 사용하면 이 역시 첫번째 이미지를 불러옵니다.
알려진 버그(?)
1. 첨부파일 이미지가 아니라 내용에 포함된 이미지를 불러오는 경우 wr_content에서 이미지 태그를 추출하여 n번째 이미지를 불어오는 방식을 그대로 사용하기 때문에(common.lib.php의 get_editor_image 함수 참고) 원하는 이미지를 불러오지 못할 수도 있습니다. (예. 내용에 들어간 이모티콘, 도형 등)
2. 코어의 thumbnail.lib.php의 원코드격인 get_list_thmbnail에서 hook부분 충돌 방지를 위해 run_replace 부분을 변경하였습니다. 대부분 사용하지 않지만 원치 않는 에러가 있을 수 있습니다.
큰 도움이 될 내용도 아닌데 읽어주셔서 감사합니다 :)
function mwb_get_list_thumbnail_nth($nth, $bo_table, $wr_id, $thumb_width, $thumb_height, $is_create=false, $is_crop=true, $crop_mode='center', $is_sharpen=false, $um_value='80/0.5/3')
{
global $g5, $config, $board;
$filename = $alt = $data_path = '';
$edt = false;
$nth = preg_replace("/[^0-9]*/s", "", $nth);
$nth = $nth - 1 ;
$nth = ($nth < $board['bo_upload_count'] && $nth >= 0) ? $nth : 0;
$sql = " SELECT bf_file, bf_content FROM {$g5['board_file_table']}
WHERE bo_table = '$bo_table' AND wr_id = '$wr_id' AND bf_type BETWEEN '1' AND '3' ORDER BY bf_no LIMIT {$nth}, 1 ";
$row = sql_fetch($sql);
if($row['bf_file']) {
$filename = $row['bf_file'];
$filepath = G5_DATA_PATH.'/file/'.$bo_table;
$alt = get_text($row['bf_content']);
} else {
$write = get_thumbnail_find_cache($bo_table, $wr_id, 'content');
$edt = true;
$nth_end = $nth + 1;
if( $matches = get_editor_image($write['wr_content'], false) ){
for($i=$nth; $i<$nth_end; $i++)
{
// 이미지 path 구함
$p = parse_url($matches[1][$i]);
if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)
$data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);
else
$data_path = $p['path'];
$srcfile = G5_PATH.$data_path;
if(preg_match("/\.({$config['cf_image_extension']})$/i", $srcfile) && is_file($srcfile)) {
$size = @getimagesize($srcfile);
if(empty($size))
continue;
$filename = basename($srcfile);
$filepath = dirname($srcfile);
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
$alt = get_text($malt[1]);
break;
}
$filename = run_replace('mwb_get_editor_filename', $filename, $p);
}
}
}
if(!$filename)
return false;
if( $thumbnail_info = run_replace('mwb_get_list_thumbnail_info', array(), array('bo_table'=>$bo_table, 'wr_id'=>$wr_id, 'data_path'=>$data_path, 'edt'=>$edt, 'filename'=>$filename, 'filepath'=>$filepath, 'thumb_width'=>$thumb_width, 'thumb_height'=>$thumb_height, 'is_create'=>$is_create, 'is_crop'=>$is_crop, 'crop_mode'=>$crop_mode, 'is_sharpen'=>$is_sharpen, 'um_value'=>$um_value)) ){
return $thumbnail_info;
}
$tname = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);
if($tname) {
if($edt) {
// 오리지날 이미지
$ori = G5_URL.$data_path;
// 썸네일 이미지
$src = G5_URL.str_replace($filename, $tname, $data_path);
} else {
$ori = G5_DATA_URL.'/file/'.$bo_table.'/'.$filename;
$src = G5_DATA_URL.'/file/'.$bo_table.'/'.$tname;
}
} else {
return false;
}
$thumb = array("src"=>$src, "ori"=>$ori, "alt"=>$alt);
return $thumb;
}
2
댓글 6개
3번 라인을
global $g5, $config;
으로 수정하고 아래에
$board = get_board_db($bo_table);
를 추가하면 해결됩니다.
좋은 지적 감사합니다 ^^
http는 Nginx (80) > Apache (8181)
https는 Nginx (443) --> Apache (8181)
이렇게 넘겨서 사용하는 경우가 많지요.
리버스 프록시의 경우 vanish를 사용하게 되면
http는 Nginx (80) > Varnish (82) > Apache (8181)
https는 Nginx (443) > Varnish (82) > Apache (8181)
이렇게 넘겨서 사용하게 될테구요.
저도 서버에 대해 많이 알지 못하니 이 부분은
https://sir.kr/so_server
에 질문하시면 더 전문적인 대답을 얻을 수 있을 것 같네요.