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

정보공유

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

 

여러 게시판의 최신글을 한곳에서 보여주고자 한다면 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 436건 1 페이지
번호 제목 글쓴이 날짜 조회
436 안드로이드 스튜디오 프로젝트 복사해서 사용하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-23 52408
435 그누보드에 nginx fastcgi_cache 적용하기 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-20 51131
434 PHPExcelReader 사용할때 php number_format 사용하지 않고 숫자형 처리 하는 법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-26 50267
433 Google 지도가 제대로 로드되지 않았습니다 - 구글 맵 키 받기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-25 50179
432 [다음 지도 api] 클러스터러 + 인포윈도우 + 사용자콘트롤박스 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-21 50173
431 jquery 드롭다운메뉴 모음. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-28 49982
430 영카트5 재고량 정해져 있을경우 주문된 건만 재고에서 차감처리 하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-29 49542
429 윈도우 환경에서 LESS 파일 컴파일 설정 방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-22 49017
428 카텍좌표값 을 WGS84로 변환하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-11 48978
427 페이팔 테스트계정 생성방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-23 48038
426 한국수출입은행 환율 API 신청방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-13 48021
425 카카오톡 나에게 보내기 API 키 설정 및 메시지 아이디 설정 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-01 47691
424 jquery 로 비동기식 ul li 추가/삭제 할 경우. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-16 47603
423 KISA 암호이용활성화 사이트 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-08 47109
422 SNS LINK 공유 링크. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-19 46970