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

정보공유

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

 

여러 게시판의 최신글을 한곳에서 보여주고자 한다면 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 437건 4 페이지
번호 제목 글쓴이 날짜 조회
열람중 그누보드 최신글 그룹형 처리 방법. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-03 42837
391 결제 대행 PG사 모음. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-15 42808
390 페이스북 GRAPH API & IFRAME BASE FACEBOOK APPLICATION DEVELOPMENT 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-03 42654
389 국외 해외 소셜 솔루션 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-10 42494
388 크롬 개발자도구의 다양한 기능. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-20 42247
387 jquery 심플 챠트 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-31 42198
386 무료 네트워크 트래픽 모니터링 툴. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-21 42133
385 VR 동영상 업로드 사이트 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-20 41932
384 KUTE.js 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-24 41894
383 페이스북 글 가져오기 (페이지) 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-05 41644
382 bash 관련 보안 취약점 중요 패치. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-26 41633
381 add_stylesheet 함수가 안먹힐경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-08 41514
380 Minify 를 이용한 JavaScript, CSS 압축 전송 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-09 41415
379 jquery 레이아웃 플러그인. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-21 41388
378 짧은주소. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-22 41318