그누보드 모바일 게시판 상하단 파일 개별 지정 방법
페이지 정보

본문
그누보드 모바일 환경에서 게시판별로 상단 및 하단 파일을 개별 설정하여 관리하려는 운영자·개발자를 위해, 여분 필드(bo1, bo2)를 활용해 코어와 관리자 파일을 수정하고 파일 경로와 확장자를 검증하는 구체적인 적용 절차를 안내합니다.
모바일 환경 게시판 상·하단 파일 경로 지정 코어 파일 수정 방법
그누보드 모바일 환경에서는 기본적으로 게시판 설정의 상단 및 하단 파일 설정을 무시하도록 되어 있습니다. 이를 해결하기 위해 게시판 설정 여분 필드인 bo_1(모바일 상단)과 bo_2(모바일 하단)를 활용하여 경로 파일을 인클루드하도록 bbs/board_head.php와 bbs/board_tail.php 코어를 수정해야 합니다.
1. bbs/board_head.php 수정
모바일 접속(G5_IS_MOBILE) 시 기존 설정을 따르지 않던 기존 코드를 찾아 아래와 같이 수정합니다.
기존 코드:
if (G5_IS_MOBILE) {
// 모바일의 경우 설정을 따르지 않는다.
include_once(G5_BBS_PATH.'/_head.php');
echo html_purifier(stripslashes($board['bo_mobile_content_head']));
} else {
수정 후 코드:
if (G5_IS_MOBILE) {
if(is_include_path_check($board['bo_1'])) { //파일경로 체크
@include ($board['bo_1']);
} else { //파일경로가 올바르지 않으면 기본파일을 가져옴
include_once(G5_BBS_PATH.'/_head.php');
}
echo html_purifier(stripslashes($board['bo_mobile_content_head']));
} else {
2. bbs/board_tail.php 수정
하단 파일 출력을 제어하기 위해 모바일 조건문 영역을 다음과 같이 수정합니다.
기존 코드:
if (G5_IS_MOBILE) {
echo html_purifier(stripslashes($board['bo_mobile_content_tail']));
// 모바일의 경우 설정을 따르지 않는다.
include_once(G5_BBS_PATH.'/_tail.php');
} else {
수정 후 코드:
if (G5_IS_MOBILE) {
echo html_purifier(stripslashes($board['bo_mobile_content_tail']));
if(is_include_path_check($board['bo_2'])) { //파일경로 체크
@include ($board['bo_2']);
} else { //파일경로가 올바르지 않으면 기본파일을 가져옴
include_once(G5_BBS_PATH.'/_tail.php');
}
} else {
관리자 설정 및 유효성 검증 추가 방법
관리자 게시판 설정 화면(adm/board_form.php)과 업데이트 처리 파일(adm/board_form_update.php)에 모바일 상단 및 하단 파일 경로를 입력할 수 있는 폼과 보안 검증 로직을 추가하여 여분 필드(bo_1, bo_2)로 관리할 수 있습니다.
1. adm/board_form.php 수정
1-1. 초기값 설정 부분에서 아래 코드를 찾은 뒤 여분 필드 기본값을 추가합니다.
$board['bo_include_head'] = '_head.php';
$board['bo_include_tail'] = '_tail.php';
$board['bo_1'] = '_head.php';
$board['bo_2'] = '_tail.php';
1-2. 게시판 상단 및 하단 파일 경로 설정 항목 아래에 모바일 상단/하단 파일 경로 입력 폼을 추가합니다.
<tr>
<th scope="row"><label for="bo_1">모바일 상단 파일 경로</label></th>
<td>
<input type="text" name="bo_1" value="<?php echo $board['bo_1']?>" id="bo_1" class="frm_input" size="50">
</td>
<td class="td_grpset">
<input type="checkbox" name="chk_grp_mobile_include_head" value="1" id="chk_grp_mobile_include_head">
<label for="chk_grp_mobile_include_head">그룹적용</label>
<input type="checkbox" name="chk_all_mobile_include_head" value="1" id="chk_all_mobile_include_head">
<label for="chk_all_mobile_include_head">전체적용</label>
</td>
</tr>
<tr>
<th scope="row"><label for="bo_2">모바일 하단 파일 경로</label></th>
<td>
<input type="text" name="bo_2" value="<?php echo $board['bo_2']?>" id="bo_2" class="frm_input" size="50">
</td>
<td class="td_grpset">
<input type="checkbox" name="chk_grp_mobile_include_tail" value="1" id="chk_grp_mobile_include_tail">
<label for="chk_grp_mobile_include_tail">그룹적용</label>
<input type="checkbox" name="chk_all_mobile_include_tail" value="1" id="chk_all_mobile_include_tail">
<label for="chk_all_mobile_include_tail">전체적용</label>
</td>
</tr>
1-3. 하단의 여분 필드 반복문 설정 부분이 $i=3부터 시작하도록 수정합니다.
<?php for ($i=3; $i<=10; $i++) {?>
2. adm/boardformupdate.php 수정
2-1. bo_1과 bo_2 입력값을 정제하고 확장자(php, htm, html) 및 허용되지 않는 문자열 검증 로직을 추가합니다.
$bo_1 = isset($_POST['bo_1'])? preg_replace(array("#[\\\]+$#", "#(<\?php|<\?)#i"), "", substr($_POST['bo_1'], 0, 255)): '';
$bo_2 = isset($_POST['bo_2'])? preg_replace(array("#[\\\]+$#", "#(<\?php|<\?)#i"), "", substr($_POST['bo_2'], 0, 255)): '';
if ($file = $bo_1) {
$file_ext = pathinfo($file, PATHINFO_EXTENSION);
if(! $file_ext ||! in_array($file_ext, array('php', 'htm', 'html')) ||! preg_match('/^.*\.(php|htm|html)$/i', $file) ) {
alert('모바일 상단 파일 경로의 확장자는 php, htm, html 만 허용합니다.');
}
$_POST['bo_1'] = $file;
}
if ($file = $bo_2) {
$file_ext = pathinfo($file, PATHINFO_EXTENSION);
if(! $file_ext ||! in_array($file_ext, array('php', 'htm', 'html')) ||! preg_match('/^.*\.(php|htm|html)$/i', $file) ) {
alert('모바일 하단 파일 경로의 확장자는 php, htm, html 만 허용합니다.');
}
$_POST['bo_2'] = $file;
}
if(!is_include_path_check($bo_1, 1)) {
alert('모바일 상단 파일 경로에 포함시킬수 없는 문자열이 있습니다.');
}
if(!is_include_path_check($bo_2, 1)) {
alert('모바일 하단 파일 경로에 포함시킬수 없는 문자열이 있습니다.');
}
2-2. 그룹적용 및 전체적용 처리 구간에 모바일 상·하단 여분 필드(bo_1, bo_2) 설정을 반영하도록 코드를 추가합니다.
- 그룹적용 구간:
if (is_checked('chk_grp_mobile_include_head')) $grp_fields.= ", bo_1 = '{$bo_1}' ";
if (is_checked('chk_grp_mobile_include_tail')) $grp_fields.= ", bo_2 = '{$bo_2}' ";
- 전체적용 구간:
if (is_checked('chk_all_mobile_include_head')) $all_fields.= ", bo_1 = '{$bo_1}' ";
if (is_checked('chk_all_mobile_include_tail')) $all_fields.= ", bo_2 = '{$bo_2}' ";
기존 게시판 모바일 상하단 파일 경로 일괄 적용 방법
이미 생성된 게시판이 많아 개별 설정이 번거로울 경우, 관리자 페이지의 그룹적용 또는 전체적용 기능을 활용하여 모바일 상단 및 하단 파일 경로를 효율적으로 일괄 반영할 수 있습니다.
1. 사전 확인 사항
- 모바일 상하단 파일 경로 설정을 위해
adm/board_form.php및adm/board_form_update.php파일에 관련 입력 폼과 쿼리 반영 로직이 사전에 수정·적용되어 있어야 합니다.
2. 일괄 적용 절차
- 관리자 계정으로 로그인 후, 게시판 관리 메뉴에서 설정을 변경할 대상 게시판 중 하나의 수정 화면으로 이동합니다.
- 모바일 상단 파일 경로(
bo_1) 및 모바일 하단 파일 경로(bo_2) 입력란에 원하는 파일 경로를 입력합니다. - 입력란 우측에 있는 그룹적용 또는 전체적용 체크박스를 선택합니다.
- 설정을 저장하면 선택한 범위(그룹 또는 전체 게시판)의 여분 필드에 해당 경로가 일괄 적용됩니다.
※ 참고: 게시판을 새로 생성할 때는 기본값이 자동으로 입력되지만, 기존에 이미 생성된 게시판들은 위와 같이 별도로 직접 입력하거나 일괄 적용 기능을 사용해야 합니다.
상황별 판단 및 행동 가이드
| 내 상황 | 선택 기준 | 다음 행동 |
|---|---|---|
| 모바일 게시판별 상·하단 파일을 별도로 지정하고 싶을 때 | bbs/board_head.php와 bbs/board_tail.php의 G5_IS_MOBILE 조건문 수정 필요 | 여분 필드 bo_1, bo_2를 활용한 경로 인클루드 코드로 수정 후 관리자 설정 폼 추가 |
| 기존 게시판에 설정을 일괄 적용해야 할 때 | adm/board_form.php와 board_form_update.php의 그룹·전체적용 로직 반영 여부 | 관리자 설정에서 모바일 상·하단 경로 입력 후 그룹적용 또는 전체적용 체크박스 선택 후 저장 |
| 파일 경로 입력 후 화면에 반영되지 않거나 오류 발생 시 | board_form_update.php의 경로 검증 로직 및 확장자 제한 확인 | is_include_path_check 함수 적용 여부 및 허용 확장자(php, htm, html) 준수 여부 점검 |
실전 FAQ
Q. 지정 가능한 파일 확장자가 제한적인 이유는 무엇인가요?
- 예외 및 대안:
adm/board_form_update.php에서 보안을 위해php,htm,html외의 확장자를 차단합니다. 다른 형식의 파일을 사용하려면 해당 검증 로직을 수정해야 하나, 보안 취약점 발생 가능성이 있으므로 권장하지 않습니다.
Q. 게시판 생성 시 기본 경로를 변경하고 싶습니다.
- 막히는 점:
adm/board_form.php의 초기값 설정 부분($board['bo_1'] = '_head.php';등)을 수정하면 신규 게시판 생성 시 기본값을 변경할 수 있습니다. 기존 게시판은 일괄 적용 기능을 활용하십시오.
함께 보면 좋은 글
참고자료
기타 참고자료
- 이전글그누보드 게시판 여분 필드 10개 이상 일괄 확장 방법 26.10.03
- 다음글그누보드 특정 게시판 내 카테고리(분류)별 PC 및 모바일 스킨 다르게 적용하는 방법 26.10.03
댓글목록
등록된 댓글이 없습니다.