G4 용 그룹최신글 (코멘트 시 최신글 목록에 반영기능 추가) > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

G4 용 그룹최신글 (코멘트 시 최신글 목록에 반영기능 추가) 정보

G4 용 그룹최신글 (코멘트 시 최신글 목록에 반영기능 추가)

본문

http://www.sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=11335
의 기능에 코멘트 추가 시 최신글의 상단으로 올라가도록 기능을 추가하였습니다.
 
latest_group 함수 제일 끝에 $with_comment 변수를 기본값 true 로 추가하였습니다.
기본값인 true 인 상태에서는 예전 글이라도 최근에 코멘트가 추가되었다면 최신글 목록에 출력되게 됩니다.
출력 순서는 코멘트가 달린 날짜와 관계되어 출려되도록 되어 있습니다.
 
$with_comment 변수를 false 로 잡아주면, 기존과 같이 코멘트는 무시되게 됩니다.
다른 부분은 수정하지 않고 그대로 두었습니다.
 
** latest_group.lib.php **
<?
if (!defined('_GNUBOARD_')) exit;
// 함수 정의 시작
function _latest_group_hasText($arrRecentContents, $row) {
        if(!sizeof($arrRecentContents)) return false;
        while(list(,$val) = each($arrRecentContents)) {
                if($val[bo_table] == $row[bo_table] && $val[wr_id] == $row[wr_id]) {
                        return true;
                }
        }
        return false;
}
// 최신글 추출 - 선택한 그룹별로 원하는 게시판을 제외하고 원하는 수만큼 보여줌
function latest_group($skin_dir="", $gr_id, $rows=10, $subject_len=40, $no_table="", $category="", $orderby="", $with_comment=true)
{
        global $config;
        global $g4;
        $list = array(); $limitrows = $rows;
        $sqlgroup = " select bo_table, bo_subject from $g4[board_table] where gr_id = '$gr_id' ";
        // 제거할 테이블들
        if ($no_table) {
                $t_flag = serialize($no_table);
                if ($t_flag[0] == "a") {        //Array이면
                        for ($ic=0; $ic<count($no_table); $ic++) {
                                $sqlgroup .= " and bo_table != '$no_table[$ic]' ";
                        }
                } else if ($t_flag[0] == "s") { //String이면
                        $sqlgroup .= " and bo_table != '$no_table' ";
                }
        }
        $sqlgroup .= " and bo_use_search=1 order by bo_order_search ";
        $rsgroup = sql_query($sqlgroup);
        if ($skin_dir)
                $latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
        else
                $latest_skin_path = "$g4[path]/skin/latest/$config[cf_latest_skin]";
        for ($j=0, $k=0; $rowgroup=sql_fetch_array($rsgroup); $j++) {
                $bo_table = $rowgroup[bo_table];
                // 테이블 이름구함
                $sql = " select * from {$g4[board_table]} where bo_table = '$bo_table'";
                $board = sql_fetch($sql);
                $tmp_write_table = $g4[write_prefix] . $bo_table; // 게시판 테이블 실제이름
                // 옵션에 따라 정렬
                $sql_postfix = (!$category) ? "" : " and ca_name = '$category' ";
                $sql_postfix .= " order by wr_is_comment desc ".((!$orderby)?", wr_id desc " : " , $orderby desc, wr_id desc ");
                $sql_postfix .= " limit $limitrows";
                if($with_comment) {
                        // 코멘트 글 우선 추출
                        $result = sql_query("select * from $tmp_write_table where wr_is_comment = 1 $sql_postfix");
                        while($row = sql_fetch_array($result)) $allResults[] = $row;
                }
                // 정상 글 추출
                $result = sql_query("select * from $tmp_write_table where wr_is_comment = 0 $sql_postfix");
                while($row = sql_fetch_array($result)) $allResults[] = $row;
                for ($i=0; is_array($allResults) && list(, $row)= each($allResults); $i++, $k++) {
                        if($row[wr_is_comment])
                                $row = sql_fetch_array(sql_query("select *, '{$row[wr_datetime]}' as wr_datetime from $tmp_write_table where wr_id = '".$row[wr_parent]."'"));
                        $row[bo_table] = $board[bo_table];
                        if(_latest_group_hasText($list, $row)) continue;
                        if(!$orderby) $op_list[$k] = $row[wr_datetime];
                        else  {
                                $op_list[$k] = is_string($row[$orderby]) ? sprintf("%-256s", $row[$orderby]) : sprintf("%016d", $row[$orderby]);
                                $op_list[$k] .= $row[wr_datetime];
                        }
                        $list[$k] = get_list($row, $board, $latest_skin_path, $subject_len);
                        $list[$k][bo_table] = $board[bo_table];
                        $list[$k][bo_subject] = $board[bo_subject];
                        $list[$k][bo_wr_subject] = cut_str($board[bo_subject] . $list[$k][wr_subject], $subject_len);
                }
        }
        if($k>0) array_multisort($op_list, SORT_DESC, $list);
        if($k>$rows) array_splice($list, $rows);
        ob_start();
        include "$latest_skin_path/latest.skin.php";
        $content = ob_get_contents();
        ob_end_clean();
        return $content;
}
/// 함수 정의 끝
?>
추천
1
  • 복사

댓글 0개

© SIRSOFT
현재 페이지 제일 처음으로