테스트 사이트 - 개발 중인 베타 버전입니다

리스트화면 N번째 이미지 가져오기

· 5년 전 · 4924 · 6

5.4기준입니다...만 5.3이하에서도 hook와 캐쉬 부분만 코어의 함수와 비교해서 수정하시면 사용하실 수 있습니다.

 

게시판 리스트 화면에서 원하는 N번째 이미지를 불러오는 내용입니다.

 

extend에 파일로 넣으셔도 되고 lib.php 파일로 불러와서 사용하셔도 됩니다.

코어의 thumbnail.lib.php가 꼭 필요합니다.

 

1. 코어의 게시판스킨 > list.skin.php 에서

[code]

$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_mobile_gallery_width'], $board['bo_mobile_gallery_height']);

[/code]

부분

[code]

$thumb = mwb_get_list_thumbnail_nth(숫자, $board['bo_table'], $list[$i]['wr_id'], $board['bo_mobile_gallery_width'], $board['bo_mobile_gallery_height']);

[/code]

변경

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 부분을 변경하였습니다. 대부분 사용하지 않지만 원치 않는 에러가 있을 수 있습니다.

 

큰 도움이 될 내용도 아닌데 읽어주셔서 감사합니다 :)

 

[code]

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;
}

[/code]

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 6개

8번 라인에서 bo_upload_count를 가져오지 못해서 무조건 0이 반환되는 현상이 있습니다.

3번 라인을
global $g5, $config;
으로 수정하고 아래에
$board = get_board_db($bo_table);
를 추가하면 해결됩니다.
제가 사용할 때에는 이런 문제가 없었는데 선행파일에서 해결이 되었나봅니다.
좋은 지적 감사합니다 ^^
@무와보 선생님 안녕하세요. nginx를 apache앞단에 리버스 프록시 구성하는것 질문있습니다. 한 컴퓨터에 nginx와 apache를 다 설치하신건가요~?
@칭따오 두개 모두 설치 가능한 것으로 알고 있습니다.
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
에 질문하시면 더 전문적인 대답을 얻을 수 있을 것 같네요.
@무와보 네네 무와보님께서 2018년도에 올리신 리버스프록시 구성 질문글을 보고 여기까지 찾아오게 되었네요 ㅎㅎ
@무와보 답변 감사드립니다!

게시글 목록

번호 제목
24318
24317
24315
24309
24294
24293
24277
24262
24260
24253
24251
24236
24233
24228
24226
24221
24214
24203
24201
24199
24196
24195
24194
24192
24191
24187
24185
24183
24172
24168