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

정보공유

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

 

여러 게시판의 최신글을 한곳에서 보여주고자 한다면 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 Click jacking, Frame sniffing 등과 같은 Frame을 이용한 공격 방어 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-05 3691
59 쿠키 Secure 속성 옵션 추가. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-05 3625
58 쿠키 하이젝킹 방지(cookie hijacking) HttpOnly, 쿠키 HttpOnly 속성 누락. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-05 3712
57 SQL 인젝션 막기를 위한 php 코드 수정. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-08 3836
56 그누보드 clean_xss_tags 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-28 4449
55 예약업 플러그인 이니시스 결제모듈 설치 안내 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-03 8150
54 예약업 플러그인 KCP 결제모듈 설치 안내 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-03 7680
53 목록화면 기본 코드 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-04 8228
52 그누보드, 영카트 다음API 우편번호 오류 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-16 12037
51 아이코드 예약 문자발송시 오류 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-10 9938
50 랜덤 아이디 문자열 생성 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-13 12671
49 스마트에디터 배경 색상변경방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-08 12983
48 글 정렬을 날짜순으로 했더니 답글 순서가 안맞는경우. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-18 18169
47 크롬에서 결제만 되고 정상적으로 처리가 되지 않는 경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-14 24346
46 그누보드 휴대폰관리에서 전체선택을 해도 전체목록이 나오지 않는 문제 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-25 14149