그누보드 5.4에서 썸네일을 선택적으로 불러오고 싶습니다.

그누보드 5.4에서 썸네일을 선택적으로 불러오고 싶습니다.

QA

그누보드 5.4에서 썸네일을 선택적으로 불러오고 싶습니다.

답변 1

본문

안녕하세요. 그누보드 5.4를 사용중에 5.3과는 많이 다르다 보니

참고할 만한게 없어서 짜깁기가 너무 어려워서

프로그램을 잘 아시는 고수분들에게 도움 좀 요청드립니다.

(내용이 좀 깁니다. ㅠ_ㅠ)

 

원하는 것은 게시판에 포함된 이미지파일을 썸네일로 뽑아올 때, 

기본으로 첫번쨰 파일만 썸네일로 뽑아 오는데 이것을 원하는 것으로 뽑아오고 싶습니다.

 

썸네일로 뽑아 오는 것은 보통

 

게시판의 list.skin.php 파일에서

$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true) 

를 이용하고

 

최근게시물의 latest.skin.php 에서도 

$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);

를 써서 뽑아오는데 

같은 함수인 get_list_thumbnail 를 이용합니다.

 

 

저는 원하는 순번의 이미지 파일을 뽑아올 수 있도록 아래처럼 작업했습니다. (이거저거 눈대중으로 짜깁기 해봤습니다.)

 

만약 2번째 이미지파일을 뽑아오려면 get_list_thumbnail 함수를 아래처럼 사용하려고 합니다.

 $thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true, '', '', '', '2');

 

즉 get_list_thumbnail 함수를 수정하여 마지막에 값을 넣으면 2번째 파일이 추출되도록 하고 싶습니다.

 

그래서 아래처럼 작업했습니다.

 

1. thumbnail.lib.php. 파일 수정

(빨간색으로 된 $option 을 추가했습니다.)

 

<?php
if (!defined('_GNUBOARD_')) exit;

@ini_set('memory_limit', '-1');

// 게시글리스트 썸네일 생성
function get_list_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_create=false, $is_crop=false, $crop_mode='center', $is_sharpen=false, $um_value='80/0.5/3', $option='0')
{
    global $g5, $config;
    $filename = $alt = "";
    $edt = false;

    $row = get_thumbnail_find_cache($bo_table, $wr_id, 'file', $option);

    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', $option);
        $edt = true;
        
        if( $matches = get_editor_image($write['wr_content'], false) ){
            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;
                }
            }   //end for
        }   //end if
    }

    if(!$filename)
        return false;

    $tname = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value, $option);

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

 

 

.

.

.

.

.

.

function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height, $is_create, $is_crop=false, $crop_mode='center', $is_sharpen=false, $um_value='80/0.5/3', $option='0')
{

 

 

2. get_data.lib.php 수정

 

// 게시판 첨부파일 테이블에서 하나의 행을 읽음
function get_board_file_db($bo_table, $wr_id, $fields='*', $add_where='', $option='0', $is_cache=false)
{
    global $g5;

    static $cache = array();

    $wr_id = (int) $wr_id;
    $key = md5($bo_table.'|'.$wr_id.$fields.$add_where. $option);

    if( $is_cache && isset($cache[$key]) ){
        return $cache[$key];
    }

    $sql = " select $fields from {$g5['board_file_table']}
                where bo_table = '$bo_table' and wr_id = '$wr_id' $add_where order by bf_no limit $option, 1 ";

    $cache[$key] = sql_fetch($sql);

    return $cache[$key];
}

 

.

.

.

.

function get_thumbnail_find_cache($bo_table, $wr_id, $wr_key, $option){
    global $g5;

    if( $cache_content = g5_latest_cache_data($bo_table, array(), $wr_id) ){
        if( $wr_key === 'content' ){
            return $cache_content;
        } else if ( $wr_key === 'file' && isset($cache_content['first_file_thumb']) ){
            return $cache_content['first_file_thumb'];
        }
    }

    if( $wr_key === 'content' ){
        $write_table = $g5['write_prefix'].$bo_table;
        return get_write($write_table, $wr_id, true);
    }

    return get_board_file_db($bo_table, $wr_id, 'bf_file, bf_content', "and bf_type between '1' and '3'", $option, true);
}

 

===============================

 

위처럼 했더니 게시판의 list.skin.php 파일에서는 원하는 순서로 썸네일을 뽑을 수 있게 되었습니다.

 

$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true, '', '', '', '0');

 

뒤에 숫자를 바꾸면 원하는 이미지가 추출되어 나옵니다.


 

최근게시물에서는 아래처럼 사용하려 합니다.

<?php  echo latest('theme/gallery', 'photo', 12, 25, 0, 2);?>

 

이렇게 뒤에 숫자를 옵션으로 지정하여 그 번호의 이미지가 나오게 하려고 합니다만

최근게시물에서는 전혀 동작하지 않습니다.

 

 

3. latest.lib.php 수정

 

// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $option='')
{

 

.

.

.

$list[$i]['first_file_thumb'] = (isset($row['wr_file']) && $row['wr_file']) ? get_board_file_db($bo_table, $row['wr_id'], 'bf_file, bf_content', "and bf_type between '1' and '3'", $option, true) : array('bf_file'=>'', 'bf_content'=>'');
            $list[$i]['bo_table'] = $bo_table;
            // 썸네일 추가
            if($options && is_string($options)) {
                $options_arr = explode(',', $options);
                $thumb_width = $options_arr[0];
                $thumb_height = $options_arr[1];
                $thumb = get_list_thumbnail($bo_table, $row['wr_id'], $thumb_width, $thumb_height, false, true, '', '', '', $option);
                // 이미지 썸네일
                if($thumb['src']) {
                    $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'">';
                    $list[$i]['img_thumbnail'] = '<a href="'.$list[$i]['href'].'" class="lt_img">'.$img_content.'</a>';
 

 

 

 

위 처럼 작업한 상태입니다.

 

최근게시물에서도 제가 원하는 방향으로 썸네일을 추출하려면 어떻게 해야 할까요?

대략적인 감으로는 제가 수정한 latest.skin.php 가 틀려서 그런 것 같은데

프로그램을 몰라서 어디가 어떻게 틀렸는지 전혀 감을 못잡고 있습니다.

 

앞으로 5.4 유저분들도 많이 늘어 날테고 저와 같은 작업이 필요한 분들도 계실테니

다가올 초보를 위해서라도 좀 도움을 부탁드립니다 ^^;;

 

열심히 작성한 성의를 쫌만 봐서라도...ㅠ_ㅠ 도움 좀 주세요 (제발 ㅠㅠ)

 

감사합니다.

 

 

 

 

 

이 질문에 댓글 쓰기 :

답변 1

헐 자문자답입니다.

 

3. latest.lib.php 수정

 

// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $option='0')
{

 

$option='0' 으로 바꾸고

 

    if(G5_USE_CACHE) {
        $cache_file_name = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-{$option}-".g5_cache_secret_key();
        $caches = g5_get_cache($cache_file_name);
        $cache_list = isset($caches['list']) ? $caches['list'] : array();
        g5_latest_cache_data($bo_table, $cache_list);
    }

 

{$option}- 이 부분 추가하니 잘 나옵니다.;;

 

 

진짜로 잘 된건지는 시간이 지나봐야 알것 같습니다.

소 뒷발에 쥐잡기..ㅠ-ㅠ

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 129,114
© SIRSOFT
현재 페이지 제일 처음으로