갤러리 썸네일이 첨부파일이 아닌 에디터 이미지로 나오는 방법

갤러리 썸네일이 첨부파일이 아닌 에디터 이미지로 나오는 방법

QA

갤러리 썸네일이 첨부파일이 아닌 에디터 이미지로 나오는 방법

본문

그누5 5.3.1.9 버전 적용하였습니다.

 

lib/thumbnail.lib.php 에서 갤러리 썸네일이 첨부파일이 먼저 나오고 첨부파일이 없다면 에디터 이미지로 나오는 함수가 있습니다.

 

어떤분께서 함수에서 if와 elso 순서를 바꾸면 나온다고 하셨는데 적용해보니 나오긴하는데 이상하게 나옴.

 

소스보면서 설명드릴께요.

 

먼저 원본 소스입니다.


if($row['bf_file']) {
        $filename = $row['bf_file'];
        $filepath = G5_DATA_PATH.'/file/'.$bo_table;
        $alt = get_text($row['bf_content']);
    } else {
        $write_table = $g5['write_prefix'].$bo_table;
        $sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
        $write = sql_fetch($sql);
        $matches = get_editor_image($write['wr_content'], false);
        $edt = true;
        for($i=0; $i<count($matches[1]); $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;
            }
        }
    }

 

아래것은 에디터 이미지를 if로 첨부파일을 elso로 바꾼소스입니다.


if($row['bf_file']) {
        $write_table = $g5['write_prefix'].$bo_table;
        $sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
        $write = sql_fetch($sql);
        $matches = get_editor_image($write['wr_content'], false);
        $edt = true;
        for($i=0; $i<count($matches[1]); $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;
            }
        }
    } else {
        $filename = $row['bf_file'];
        $filepath = G5_DATA_PATH.'/file/'.$bo_table;
        $alt = get_text($row['bf_content']);
        
    }

 

이렇게 순서를 바꾸었을때 파일첨부 이미지보다 에디터 이미지가 썸네일로 나오긴합니다.

 

하지만 문제는 첨부파일에 이미지를 첨부하지않고 그냥 에디터에만 이미지를 넣었을때는 썸네일이 아예 나오지 않습니다.

 

쉽게 설명해 첨부파일과 에디터 둘다 이미지가 있다면 썸네일이 에디터의 첫번째 이미지로 출력됩니다.

하지만 에디터만 이미지 등록하면 썸네일이 'no image'로 나옵니다.

 

어느 구문을 수정해야될까요???

이 질문에 댓글 쓰기 :

답변 1


$write_table = $g5['write_prefix'].$bo_table;
$sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
$write = sql_fetch($sql);
$matches = get_editor_image($write['wr_content'], false);
$edt = true;
for($i=0; $i<count($matches[1]); $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;
    }
}
if(!$filename) {
    $filename = $row['bf_file'];
    $filepath = G5_DATA_PATH.'/file/'.$bo_table;
    $alt = get_text($row['bf_content']);    
}
답변을 작성하시기 전에 로그인 해주세요.
전체 12
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT