위토즈 - 개발자프로그램판매공간

정보공유

[그누보드팁] 그누보드 최신글 그룹형 처리 방법.

 

여러 게시판의 최신글을 한곳에서 보여주고자 한다면 union 을 사용할수 있습니다.

 

그러나 그누보드에서는 union 을 기본적으로 차단하고 있습니다.

 

common.lib.php 파일의 sql_query 함수.

 

$sql = preg_replace("#^select.*from.*[\s\(]+union[\s\)]+.*#i ", "select 1", $sql); 

 

 

 

 

그룹형 최신글을 사용하기 위해서 아래와 같이 코드를 직접 만들어보았습니다.

 

/lib/latest.lib.php 파일에 아래 함수를 추가합니다.

 

 

function latest_group($skin_dir='', $bo_tables, $rows=10, $subject_len=40, $cache_time=1, $options='')

{

    global $g5;

 

    if (!$skin_dir) $skin_dir = 'basic';

 

    if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {

        if (G5_IS_MOBILE) {

            $latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];

            if(!is_dir($latest_skin_path))

                $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];

            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);

        } else {

            $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];

            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);

        }

        $skin_dir = $match[1];

    } else {

        if(G5_IS_MOBILE) {

            $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;

            $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;

        } else {

            $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;

            $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;

        }

    }

 

    $cache_fwrite = false;

    if(G5_USE_CACHE) {

        $cache_file = G5_DATA_PATH."/cache/latest-group-".implode('-', $bo_tables)."-{$skin_dir}-{$rows}-{$subject_len}.php";

 

        if(!file_exists($cache_file)) {

            $cache_fwrite = true;

        } else {

            if($cache_time > 0) {

                $filetime = filemtime($cache_file);

                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {

                    @unlink($cache_file);

                    $cache_fwrite = true;

                }

            }

 

            if(!$cache_fwrite)

                include($cache_file);

        }

    }

 

    if(!G5_USE_CACHE || $cache_fwrite) {

        $list = $tmp_list = array();

   

        if (is_array($bo_tables)) { 

    

             foreach ($bo_tables as $key => $bo_table) { 

 

                $tmp_write_table = $g5['write_prefix'] . $bo_table;

                $sql = " select  ";

                $sql .= "    '{$bo_table}' as bo_table, ";

                $sql .= "    wr_id, wr_num, wr_subject, wr_option, wr_content, wr_comment, wr_datetime, wr_last, wr_homepage, wr_name, mb_id, wr_email, wr_reply, wr_link1, wr_link2, ca_name, wr_hit, wr_file ";

                $sql .= " from {$tmp_write_table} where wr_is_comment = '0' order by wr_num limit 0, {$rows} ";

                $res = sql_query($sql);

                while($row = sql_fetch_array($res)) {

                    $tmp_list[] = $row;

                }

            }

        } 

 

        foreach ($tmp_list as $key => $record) { 

            $cols[$key] = $record['wr_datetime'];

        } 

        array_multisort($cols, SORT_DESC, $tmp_list);

        

        $i=0;

        foreach ($tmp_list as $key => $row) { 

            if ($rows < $i) { 

                break;

            } 

            $sql = " select * from {$g5['board_table']} where bo_table = '{$row['bo_table']}' ";

            $board = sql_fetch($sql);

            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);  

            $i++;

        } 

 

        if($cache_fwrite) {

            $handle = fopen($cache_file, 'w');

            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject='".$bo_subject."';\n\$list=".var_export($list, true)."?>";

            fwrite($handle, $cache_content);

            fclose($handle);

        }

    }

 

    ob_start();

    include $latest_skin_path.'/latest.skin.php';

    $content = ob_get_contents();

    ob_end_clean();

 

    return $content;

}

 

 

 

 

 

메인화면에서 사용은 아래와 같이 합니다.

 

<?php echo latest_group('theme/package', array('notice', 'gallery', 'webzine'), 3, 25);?> 

 

 

 

 

정보공유
Total 60건 1 페이지
번호 제목 글쓴이 날짜 조회
60 그누보드에 nginx fastcgi_cache 적용하기 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-20 51386
59 영카트5 재고량 정해져 있을경우 주문된 건만 재고에서 차감처리 하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-29 49764
58 게시판 목록에서 원하는 데이터만 출력이 가능하게.. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-14 46154
57 그누보드5 에 Daum 우편번호 찾기 API 연동 하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-28 44501
56 그누보드4 에 Daum 우편번호 찾기 API 연동 하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-28 44241
55 그누보드5 모바일에 레이어로 Daum 우편번호 찾기 API 연동 하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-04 44041
54 그누보드에서 map 태그 및 iframe 사용하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-22 43105
53 capcha 캡챠 스팸방지 코드 오류, 깨짐, 엑박 뜰경우. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-23 42966
열람중 그누보드 최신글 그룹형 처리 방법. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-03 42812
51 add_stylesheet 함수가 안먹힐경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-08 41490
50 그누보드 버전확인하는 방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-25 41224
49 스마트 에디터 반응형에서 가로사이즈 맞게 출력시키기 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-04 40871
48 스마트에디터 사진 첨부시 절대경로를 상대경로로 변경하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-21 40275
47 그누보드 데이터 이전후 data 폴더내 이미지 파일들이 깨질경우. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-14 39483
46 그누보드5, 영카트5의 에디터 플러그인을 사용하는데 에디터에 사진 이미지가 들어가지 않을경우. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-22 39242