[G5] 최신글 공지글/일반글 랜덤 추출 > 기술자료 | 해피정닷컴

[G5] 최신글 공지글/일반글 랜덤 추출 > 기술자료

본문 바로가기

사이트 내 전체검색

[G5] 최신글 공지글/일반글 랜덤 추출 > 기술자료

그누보드 [G5] 최신글 공지글/일반글 랜덤 추출

페이지 정보


본문

2017-06-08 기능에 문제가 확인되어 수정작업후 다시 올리겠습니다.
2017-06-12 수정 재등록
2018-05-23 적용사례를 추가
2018-07-06 랜덤추출에서 공지글 존재여부 체크로직에 심각한 오류가 발견되어 수정했습니다.


공지글만 추출하거나,  공지가 아닌 글을 체크하기 위해 코드를 만들었습니다.

1. 그누보드5 / lib / latest_noticeRand.lib.php  파일을 생성해서 아래 내용을 저장

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

// 최신글 공지글 랜덤 추출
// $cache_time 캐시 갱신시간
function latest_noticeRand($skin_dir='', $bo_table, $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;
        }
    }

    $list = array();

    $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
    $board = sql_fetch($sql);
    $bo_subject = get_text($board['bo_subject']);

    $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름 

    $arr_notice = preg_replace("/\n/",',', trim($board['bo_notice'])); 
    if(!$arr_notice) $arr_notice=0; 

    $sql = " select * from {$tmp_write_table} where wr_id IN({$arr_notice}) and wr_is_comment = 0 order by rand() limit 0, {$rows} ";
    $result = sql_query($sql);
    
    for ($i=0; $row = sql_fetch_array($result); $i++) {
        $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
    }

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


// 최신글 공지글 제외글 랜덤 추출
// $cache_time 캐시 갱신시간
function latest_NoNoticeRand($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
    //echo "latest_NoNoticeRand<br>";
    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;
        }
    }
    
    $list = array();
    
    $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
    $board = sql_fetch($sql);

    // 답변글 출력제외 
    //$subqry = "&& wr_reply = ''";
    
    // 공지사항 출력제외 
    $arr_notice = preg_replace("/\n/",',', trim($board['bo_notice']));
    
    if($arr_notice) {  // 2018-07-06  해피정닷컴 수정
        $subqry = $subqry." && wr_id Not in ({$arr_notice}) ";
    }
    
    $bo_subject = get_text($board['bo_subject']);

    $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름

    $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 {$subqry} order by rand() limit 0, {$rows} ";
    $result = sql_query($sql);
    
    for ($i=0; $row = sql_fetch_array($result); $i++) {
        $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
    }

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


2. 적용코드
최신글 - 공지글 포함 랜덤 추출
<?php include_once G5_LIB_PATH."/latest_noticeRand.lib.php"; ?>
<?php echo latest_noticeRand('basic', '게시판이름', 6, 40); ?>

최신글 - 공지글 제외 랜덤 추출
<?php include_once G5_LIB_PATH."/latest_noticeRand.lib.php"; ?>
<?php echo latest_NoNoticeRand('basic', '게시판이름', 6, 40); ?>


3. 적용샘플
https://www.happyjung.com/demo/latest_noticeRand/

댓글목록

등록된 댓글이 없습니다.


Total 2,633건 1 페이지
  • RSS
기술자료 목록
2633
MySQL   165  2024-03-29 14:14 ~ 2024-03-29 14:14  
2632
그누보드   486  2024-02-23 18:40 ~ 2024-02-24 06:13  
2631
JavaScript   465  2024-02-16 18:50 ~ 2024-02-16 20:37  
2630
Java   390  2024-02-06 16:49  
2629
PHP   592  2024-02-06 16:42  
2628
호스팅   558  2024-01-29 12:54  
2627
PHP   580  2024-01-26 11:04 ~ 2024-01-26 11:13  
2626
MySQL   906  2024-01-08 17:37 ~ 2024-03-14 16:00  
2625
SQL   841  2024-01-08 12:36  
2624
영카트   1056  2024-01-04 14:57  
2623
일반   1849  2023-12-15 18:33  
2622
Android   1524  2023-11-30 18:48 ~ 2023-11-30 19:41  
2621
전자결제   2589  2023-11-23 19:53  
2620
PHP   1924  2023-11-20 10:56 ~ 2023-11-20 11:14  
2619
Linux   1777  2023-11-09 19:55  
2618
그누보드   1846  2023-11-06 20:38  
2617
Linux   1808  2023-11-01 21:41 ~ 2023-11-02 10:30  
2616
영카트   1912  2023-10-07 23:31  
2615
SNS   2883  2023-09-24 17:56  
2614
ClassicASP   2588  2023-09-14 08:38  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: 서울센터 (08393) 서울시 구로구 디지털로32가길 16 파트너스타워2차 1206-280호
        대전센터 (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 지원1동 205호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 2014-서울구로-0074 [사업자등록확인]  
Copyright 2001~2024 해피정닷컴. All Rights Reserved.