동영상 강좌는 유튜브 채널 '웹학교'를 이용하시기 바랍니다.
list.php는 단독으로 사용되는 화일이 아닙니다.
board.php에서 게시판 글목록을 불러올때 php에서 include하여 사용하는 파일입니다.
위치 : /bbs
목록을 불러올 때 글에 대한 권한 및 조건 등은 board.php화일에서 이미 체크를 한 상태입니다.
list.php는 실제적으로 목록을 보여줄 내용에 집중되고 있습니다.
1. 분류를 사용하는 게시판인지 확인하고
2. 검색을 통해 보여주는 목록인지 확인후 게시판 전체 글 수를 구합니다.
$sql_search = get_sql_search($sca, $sfl, $stx, $sop);
// 가장 작은 번호를 얻어서 변수에 저장 (하단의 페이징에서 사용)
$sql = " select MIN(wr_num) as min_wr_num from {$write_table} ";
$row = sql_fetch($sql);
$min_spt = (int)$row['min_wr_num'];
if (!$spt) $spt = $min_spt;
$sql_search .= " and (wr_num between {$spt} and ({$spt} + {$config['cf_search_part']})) ";
// 원글만 얻는다. (코멘트의 내용도 검색하기 위함)
// 라엘님 제안 코드로 대체 http://sir.kr/g5_bug/2922
$sql = " SELECT COUNT(DISTINCT `wr_parent`) AS `cnt` FROM {$write_table} WHERE {$sql_search} ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
관리자 게시판 설정에서 결정한 모바일/PC 페이지 정보를 구합니다.
if(G5_IS_MOBILE) {
$page_rows = $board['bo_mobile_page_rows'];
$list_page_rows = $board['bo_mobile_page_rows'];
} else {
$page_rows = $board['bo_page_rows'];
$list_page_rows = $board['bo_page_rows'];
}
3. 공지글인지 확인
if (!$sca && !$stx) {
$arr_notice = explode(',', trim($board['bo_notice']));
$from_notice_idx = ($page - 1) * $page_rows;
if($from_notice_idx < 0)
$from_notice_idx = 0;
$board_notice_count = count($arr_notice);
for ($k=0; $k<$board_notice_count; $k++) {
if (trim($arr_notice[$k]) == '') continue;
$row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' ");
if (!$row['wr_id']) continue;
$notice_array[] = $row['wr_id'];
if($k < $from_notice_idx) continue;
$list[$i] = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
$list[$i]['is_notice'] = true;
$i++;
$notice_count++;
if($notice_count >= $list_page_rows)
break;
}
}
4. 전체페이지 및 시작열 구하기
$total_page = ceil($total_count / $page_rows); // 전체 페이지 계산
$from_record = ($page - 1) * $page_rows; // 시작 열을 구함
5. 목록가져오기
목록은 lib/common.lib.php 안에 있는 함수 get_list()로 가져옵니다.
function get_list($write_row, $board, $skin_url, $subject_len=40)
{
global $g5, $config;
global $qstr, $page;
//$t = get_microtime();
// 배열전체를 복사
$list = $write_row;
unset($write_row);
$board_notice = array_map('trim', explode(',', $board['bo_notice']));
$list['is_notice'] = in_array($list['wr_id'], $board_notice);
if ($subject_len)
$list['subject'] = conv_subject($list['wr_subject'], $subject_len, '…');
else
$list['subject'] = conv_subject($list['wr_subject'], $board['bo_subject_len'], '…');
// 목록에서 내용 미리보기 사용한 게시판만 내용을 변환함 (속도 향상) : kkal3(커피)님께서 알려주셨습니다.
if ($board['bo_use_list_content'])
{
$html = 0;
if (strstr($list['wr_option'], 'html1'))
$html = 1;
else if (strstr($list['wr_option'], 'html2'))
$html = 2;
$list['content'] = conv_content($list['wr_content'], $html);
}
$list['comment_cnt'] = '';
if ($list['wr_comment'])
$list['comment_cnt'] = "".$list['wr_comment']."";
// 당일인 경우 시간으로 표시함
$list['datetime'] = substr($list['wr_datetime'],0,10);
$list['datetime2'] = $list['wr_datetime'];
if ($list['datetime'] == G5_TIME_YMD)
$list['datetime2'] = substr($list['datetime2'],11,5);
else
$list['datetime2'] = substr($list['datetime2'],5,5);
// 4.1
$list['last'] = substr($list['wr_last'],0,10);
$list['last2'] = $list['wr_last'];
if ($list['last'] == G5_TIME_YMD)
$list['last2'] = substr($list['last2'],11,5);
else
$list['last2'] = substr($list['last2'],5,5);
$list['wr_homepage'] = get_text($list['wr_homepage']);
$tmp_name = get_text(cut_str($list['wr_name'], $config['cf_cut_name'])); // 설정된 자리수 만큼만 이름 출력
$tmp_name2 = cut_str($list['wr_name'], $config['cf_cut_name']); // 설정된 자리수 만큼만 이름 출력
if ($board['bo_use_sideview'])
$list['name'] = get_sideview($list['mb_id'], $tmp_name2, $list['wr_email'], $list['wr_homepage']);
else
$list['name'] = ''.$tmp_name.'';
$reply = $list['wr_reply'];
$list['reply'] = strlen($reply)*20;
$list['icon_reply'] = '';
if ($list['reply'])
$list['icon_reply'] = '';
$list['icon_link'] = '';
if ($list['wr_link1'] || $list['wr_link2'])
$list['icon_link'] = ' ';
// 분류명 링크
$list['ca_name_href'] = G5_BBS_URL.'/board.php?bo_table='.$board['bo_table'].'&sca='.urlencode($list['ca_name']);
$list['href'] = G5_BBS_URL.'/board.php?bo_table='.$board['bo_table'].'&wr_id='.$list['wr_id'].$qstr;
$list['comment_href'] = $list['href'];
$list['icon_new'] = '';
if ($board['bo_new'] && $list['wr_datetime'] >= date("Y-m-d H:i:s", G5_SERVER_TIME - ($board['bo_new'] * 3600)))
$list['icon_new'] = ' ';
$list['icon_hot'] = '';
if ($board['bo_hot'] && $list['wr_hit'] >= $board['bo_hot'])
$list['icon_hot'] = ' ';
$list['icon_secret'] = '';
if (strstr($list['wr_option'], 'secret'))
$list['icon_secret'] = ' ';
// 링크
for ($i=1; $i<=G5_LINK_COUNT; $i++) {
$list['link'][$i] = set_http(get_text($list["wr_link{$i}"]));
$list['link_href'][$i] = G5_BBS_URL.'/link.php?bo_table='.$board['bo_table'].'&wr_id='.$list['wr_id'].'&no='.$i.$qstr;
$list['link_hit'][$i] = (int)$list["wr_link{$i}_hit"];
}
// 가변 파일
if ($board['bo_use_list_file'] || ($list['wr_file'] && $subject_len == 255) /* view 인 경우 */) {
$list['file'] = get_file($board['bo_table'], $list['wr_id']);
} else {
$list['file']['count'] = $list['wr_file'];
}
if ($list['file']['count'])
$list['icon_file'] = ' ';
return $list;
}
가져온 목록은 $list 배열에 담아 스킨화일로 넘겨줍니다.
6. 목록을 화면에 뿌려줄 스킨 불러오기
include_once($board_skin_path.'/list.skin.php');
등록된 댓글이 없습니다.