최신글 여러게시판 함수 > 그누보드5 팁자료실

그누보드5 팁자료실

최신글 여러게시판 함수 정보

최신글 여러게시판 함수

본문

그누보드의 새글테이블을 사용하는 함수랑 union으로 묶는 함수 두가지입니다. 새글 테이블 사용시 환경설정에서 새글 삭제기간을 0으로 두셔야합니다.



if(!function_exists('wv_latest_group_cache_name')){
    function wv_latest_group_cache_name($bo_tables){
        $arr = array();
        foreach ($bo_tables as $bo_table){
            $arr[] = $bo_table.'__group';
        }
        return implode('-',$arr);
    }
}
if(!function_exists('wv_latest_group_from_new')){
    function wv_latest_group_from_new($skin_dir='', $gr_id, $rows=10, $subject_len=40, $cache_time=1, $options='')
    {
        global $g5;

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

        $time_unit = 3600;  // 1시간으로 고정

        $row = sql_fetch("SELECT GROUP_CONCAT(bo_table SEPARATOR ',') as bo_tables FROM {$g5['board_table']} WHERE gr_id='{$gr_id}'");
        $bo_tables = explode(',',$row['bo_tables']);
        $cache_title = wv_latest_group_cache_name($bo_tables);

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

        $caches = false;

        if(G5_USE_CACHE) {
            $cache_file_name = "latest-{$cache_title}-{$skin_dir}-{$rows}-{$subject_len}-".g5_cache_secret_key();
            $caches = g5_get_cache($cache_file_name, (int) $time_unit * (int) $cache_time);
            $cache_list = isset($caches['list']) ? $caches['list'] : array();
        }

        if( $caches === false ){

            $list = array();



            $sql_common = " from {$g5['board_new_table']} a, {$g5['board_table']} b, {$g5['group_table']} c where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = 1 ";
            $sql_common .= " and b.gr_id = '$gr_id' ";
            $sql_common .= " and a.wr_id = a.wr_parent ";
            $sql_order = " order by a.bn_id desc ";
            $sql = " select a.*, b.*, c.gr_subject, c.gr_id {$sql_common} {$sql_order} limit 0, {$rows}";

            $result = sql_query($sql,1);

            for ($i=0; $row=sql_fetch_array($result); $i++) {



                $bo_subject = get_text($row['bo_subject']);
                $gr_subject = $row['gr_subject'];

                $row2 = get_write($g5['write_prefix'].$row['bo_table'],$row['wr_id']);

                try {
                    unset($row2['wr_password']);     //패스워드 저장 안함( 아예 삭제 )
                } catch (Exception $e) {
                }
                $row2['wr_email'] = '';              //이메일 저장 안함
                if (strstr($row2['wr_option'], 'secret')){           // 비밀글일 경우 내용, 링크, 파일 저장 안함
                    $row2['wr_content'] = $row2['wr_link1'] = $row2['wr_link2'] = '';
                    $row2['file'] = array('count'=>0);
                }
                $list[$i] = get_list($row2, $row, $latest_skin_url, $subject_len);

                $list[$i]['first_file_thumb'] = (isset($row2['wr_file']) && $row2['wr_file']) ? get_board_file_db($row2['bo_table'], $row2['wr_id'], 'bf_file, bf_content', "and bf_type in (1, 2, 3, 18) ", true) : array('bf_file'=>'', 'bf_content'=>'');
                $list[$i]['bo_table'] = $row['bo_table'];

                // 썸네일 추가
                if($options && is_string($options)) {

                    $options_arr = explode(',', $options);
                    $thumb_width = $options_arr[0];
                    $thumb_height = $options_arr[1];
                    $thumb = get_list_thumbnail($row2['bo_table'], $row2['wr_id'], $thumb_width, $thumb_height, false, true);
                    // 이미지 썸네일
                    if($thumb['src']) {
                        $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'">';
                        $list[$i]['img_thumbnail'] = '<a href="'.$list[$i]['href'].'" class="lt_img">'.$img_content.'</a>';
                        // } else {
                        //     $img_content = '<img src="'. G5_IMG_URL.'/no_img.png'.'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'" class="no_img">';
                    }
                }

                if(! isset($list[$i]['icon_file'])) $list[$i]['icon_file'] = '';
            }




            if(G5_USE_CACHE) {

                $caches = array(
                    'list' => $list,
                    'gr_subject' => sql_escape_string($gr_subject),
                );

                g5_set_cache($cache_file_name, $caches, (int) $time_unit * (int) $cache_time);
            }
        } else {
            $list = $cache_list;
            $gr_subject = (is_array($caches) && isset($caches['gr_subject'])) ? $caches['gr_subject'] : '';
        }

        ob_start();
        include $latest_skin_path.'/latest.skin.php';
        $content = ob_get_contents();
        ob_end_clean();

        return $content;
    }
}
if(!function_exists('wv_latest_group_from_union')){
    function wv_latest_group_from_union($skin_dir='', $bo_tables, $rows=10, $subject_len=40, $cache_time=1, $options='')
    {
        global $g5;

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

        $time_unit = 3600;  // 1시간으로 고정

        if(is_string($bo_tables)){
            $row = sql_fetch("SELECT GROUP_CONCAT(bo_table SEPARATOR ',') as bo_tables FROM {$g5['board_table']} WHERE gr_id='{$bo_tables}'");
            $bo_tables = explode(',',$row['bo_tables']);
        }

        $cache_title = wv_latest_group_cache_name($bo_tables);


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

        $caches = false;

        if(G5_USE_CACHE) {
            $cache_file_name = "latest-{$cache_title}-{$skin_dir}-{$rows}-{$subject_len}-".g5_cache_secret_key();
            $caches = g5_get_cache($cache_file_name, (int) $time_unit * (int) $cache_time);
            $cache_list = isset($caches['list']) ? $caches['list'] : array();
        }

        if( $caches === false ){

            $list = $tmp_list = array();




            if (is_array($bo_tables)) {
                foreach ($bo_tables as $key => $bo_table) {
                    $board = get_board_db($bo_table, true);
                    $tmp_write_table = $g5['write_prefix'] . $bo_table;
                    $sql = " select * from {$tmp_write_table} where wr_is_comment = '0' order by wr_num limit 0, {$rows} ";
                    $result = sql_query($sql);
                    while($row = sql_fetch_array($result)) {
                        $row['bo_table'] = $bo_table;
                        $row['board'] = $board;
                        $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;
                }

                try {
                    unset($row['wr_password']);     //패스워드 저장 안함( 아예 삭제 )
                } catch (Exception $e) {
                }
                $row['wr_email'] = '';              //이메일 저장 안함
                if (strstr($row['wr_option'], 'secret')){           // 비밀글일 경우 내용, 링크, 파일 저장 안함
                    $row['wr_content'] = $row['wr_link1'] = $row['wr_link2'] = '';
                    $row['file'] = array('count'=>0);
                }
                $list[$i] = get_list($row, $row['board'], $latest_skin_url, $subject_len);

                $list[$i]['first_file_thumb'] = (isset($row['wr_file']) && $row['wr_file']) ? get_board_file_db($row['bo_table'], $row['wr_id'], 'bf_file, bf_content', "and bf_type in (1, 2, 3, 18) ", true) : array('bf_file'=>'', 'bf_content'=>'');

                // 썸네일 추가
                if($options && is_string($options)) {
                    $options_arr = explode(',', $options);
                    $thumb_width = $options_arr[0];
                    $thumb_height = $options_arr[1];
                    $thumb = get_list_thumbnail($row['bo_table'], $row['wr_id'], $thumb_width, $thumb_height, false, true);
                    // 이미지 썸네일
                    if($thumb['src']) {
                        $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'">';
                        $list[$i]['img_thumbnail'] = '<a href="'.$list[$i]['href'].'" class="lt_img">'.$img_content.'</a>';
                        // } else {
                        //     $img_content = '<img src="'. G5_IMG_URL.'/no_img.png'.'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'" class="no_img">';
                    }
                }

                if(! isset($list[$i]['icon_file'])) $list[$i]['icon_file'] = '';

                $i++;

            }


            if(G5_USE_CACHE) {

                $caches = array(
                    'list' => $list,
                );

                g5_set_cache($cache_file_name, $caches, (int) $time_unit * (int) $cache_time);
            }
        } else {
            $list = $cache_list;
        }

        ob_start();
        include $latest_skin_path.'/latest.skin.php';
        $content = ob_get_contents();
        ob_end_clean();

        return $content;
    }
}

추천
2

댓글 2개

전체 2,638 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT