BOARD

팁·활용

그누보드 내용 관리 페이지 모바일 상단 및 하단 파일 별도 설정 방법

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 6회 작성일 26-10-09 15:35

본문

그누보드 내용 관리 페이지 모바일 상단 및 하단 파일 별도 설정 방법

그누보드 내용 관리 페이지에서 PC와 모바일 환경을 분리하여 모바일 전용 상단 및 하단 파일을 별도로 설정하고 관리하는 방법을 알아봅니다.

그누보드 내용 관리 페이지에서 모바일 전용 상단 및 하단 파일 경로를 설정하기 위해서는 데이터베이스의 g5_content 테이블에 관련 필드를 추가해야 합니다. 기본적으로 내용 관리 기능에는 모바일 전용 경로 설정 필드가 포함되어 있지 않기 때문입니다.

데이터베이스 필드 추가

g5_content 테이블에 다음 두 개의 필드를 추가하십시오.

  • co_mobile_include_head: 모바일 상단 파일 경로 저장용
  • co_mobile_include_tail: 모바일 하단 파일 경로 저장용

이후 관리자 페이지의 내용 관리 폼(adm/contentform.php)과 업데이트 처리 파일(adm/contentformupdate.php), 그리고 실제 모바일 출력 파일(mobile/content.php)을 수정하여 해당 필드를 연동해야 합니다.

adm/contentform.php 파일 수정 방법

관리자 페이지 내용 관리 입력 폼에서 모바일 상단 및 하단 파일 경로를 직접 입력할 수 있는 입력 상자를 노출하려면 adm/contentform.php 파일에 관련 입력 필드 코드를 추가해야 합니다.

수정 위치 및 코드 추가

adm/contentform.php 파일 내에서 PC 상단 및 하단 파일 경로 입력 항목 주변을 찾아, 아래와 같이 모바일 상단 파일 경로와 모바일 하단 파일 경로를 입력받는 행(<tr>) 코드를 추가합니다.

<tr>
 <th scope="row"><label for="co_mobile_include_head">모바일 상단 파일 경로</label></th>
 <td>
 <?php echo help("설정값이 없으면 기본 상단 파일을 사용합니다.");?>
 <input type="text" name="co_mobile_include_head" value="<?php echo $co['co_mobile_include_head'];?>" id="co_mobile_include_head" class="frm_input" size="60">
 </td>
</tr>
<tr>
 <th scope="row"><label for="co_mobile_include_tail">모바일 하단 파일 경로</label></th>
 <td>
 <?php echo help("설정값이 없으면 기본 상단 파일을 사용합니다.");?>
 <input type="text" name="co_mobile_include_tail" value="<?php echo $co['co_mobile_include_tail'];?>" id="co_mobile_include_tail" class="frm_input" size="60">
 </td>
</tr>

다음 단계 및 확인

코드를 수정한 후 관리자 페이지의 내용 관리 입력/수정 화면으로 이동하여 '모바일 상단 파일 경로'와 '모바일 하단 파일 경로' 입력 상자가 정상적으로 노출되는지 확인합니다. 값이 정상적으로 저장되도록 하려면 데이터베이스 g5_content 테이블 필드 추가 및 adm/contentformupdate.php, mobile/content.php 파일 수정 작업을 함께 진행해야 합니다.

adm/contentformupdate.php 파일 수정 방법

내용 관리 페이지에서 입력한 모바일 상단 및 하단 파일 경로의 유효성을 검증하고 데이터베이스에 안전하게 저장하려면 adm/contentformupdate.php 파일을 아래와 같이 수정해야 합니다.

1. 파일 확장자 검증 코드 추가

기존의 PC 하단 파일 경로 검증 코드 하단에 모바일 상단 및 하단 파일 경로에 대한 확장자 검증 코드를 추가합니다. 허용되는 확장자는 php, html입니다.

if( $co_mobile_include_head ){
 $purl = parse_url($co_mobile_include_head);
 $file = $purl['path'];
 if (!preg_match("/\.(php|htm['l']?)$/i", $file)) {
 alert('모바일 상단 파일 경로의 확장자는 php, html 만 허용합니다.');
 }
}
if( $co_mobile_include_tail ){
 $purl = parse_url($co_mobile_include_tail);
 $file = $purl['path'];
 if (!preg_match("/\.(php|htm['l']?)$/i", $file)) {
 alert('모바일 하단 파일 경로의 확장자는 php, html 만 허용합니다.');
 }
}

2. 보안 경로 체크 코드 추가

허용되지 않는 경로(/data/file/ 또는 /data/editor/)가 포함되었는지 확인하는 is_include_path_check 검증 로직을 추가합니다.

if( $co_mobile_include_head &&! is_include_path_check($co_mobile_include_head) ){
 $co_mobile_include_head = '';
 $error_msg = '/data/file/ 또는 /data/editor/ 포함된 문자를 상단 파일 경로에 포함시킬수 없습니다.';
}
if( $co_mobile_include_tail &&! is_include_path_check($co_mobile_include_tail) ){
 $co_mobile_include_tail = '';
 $error_msg = '/data/file/ 또는 /data/editor/ 포함된 문자를 하단 파일 경로에 포함시킬수 없습니다.';
}

3. SQL 업데이트 구문 수정

데이터베이스에 저장될 쿼리문($sql_common)에 모바일 관련 필드 값을 추가합니다.

co_mobile_include_head = '$co_mobile_include_head',
co_mobile_include_tail = '$co_mobile_include_tail',

모바일 내용 관리 페이지 전용 상단 및 하단 파일 출력 설정

그누보드 내용 관리 페이지에서 모바일 접속 시 설정된 전용 상단 및 하단 파일이 실제로 출력되도록 하려면 mobile/content.php 파일을 수정해야 합니다.

mobile/content.php 파일 수정 방법

파일 내에서 기존의 기본 헤더와 푸터 파일을 호출하는 코드를 찾아 조건문으로 변경합니다.

  1. 상단 파일 출력 부분 수정
    • 기존 코드:
    include_once('./_head.php');
    • 수정 코드:
    if ($co['co_mobile_include_head'] && is_include_path_check($co['co_mobile_include_head'])) @include_once($co['co_mobile_include_head']);
    else include_once('./_head.php');
  2. 하단 파일 출력 부분 수정
    • 기존 코드:
    include_once('./_tail.php');
    • 수정 코드:
    if ($co['co_mobile_include_tail'] && is_include_path_check($co['co_mobile_include_tail'])) @include_once($co['co_mobile_include_tail']);
    else include_once('./_tail.php');

다음 행동 및 확인 방법

  • 코드를 수정한 뒤 관리자 페이지의 내용 관리 설정에서 모바일 상단 및 하단 파일 경로가 올바르게 입력되어 있는지 확인합니다.
  • 모바일 기기나 브라우저의 모바일 에뮬레이터를 통해 해당 내용 관리 페이지에 접속하여, 지정한 모바일 전용 상·하단 파일이 정상적으로 출력되는지 점검합니다.

그누보드 내용 관리 페이지 모바일 상단 및 하단 파일 별도 설정 방법

그누보드 기본 내용 관리 페이지는 게시판과 달리 모바일 상단 및 하단 파일을 별도로 설정할 수 있는 필드가 기본 누락되어 있습니다. PC와 모바일을 분리하여 모바일 전용 상단 및 하단 파일을 관리하려면 데이터베이스 테이블 확장 및 관련 파일 수정 작업을 진행해야 합니다.

1. 데이터베이스 테이블 필드 추가

내용 관리를 위한 g5_content 테이블에 모바일 상단/하단 파일 경로를 저장할 아래 두 개의 필드를 직접 추가합니다.

  • co_mobile_include_head
  • co_mobile_include_tail

2. 관리자 화면 입력폼 수정 (adm/contentform.php)

관리자 페이지 내용 입력 및 수정 폼에서 모바일 상단/하단 파일 경로를 입력받을 수 있도록 아래 코드를 적절한 위치에 추가합니다.

<tr>
 <th scope="row"><label for="co_mobile_include_head">모바일 상단 파일 경로</label></th>
 <td>
 <?php echo help("설정값이 없으면 기본 상단 파일을 사용합니다.");?>
 <input type="text" name="co_mobile_include_head" value="<?php echo $co['co_mobile_include_head'];?>" id="co_mobile_include_head" class="frm_input" size="60">
 </td>
</tr>
<tr>
 <th scope="row"><label for="co_mobile_include_tail">모바일 하단 파일 경로</label></th>
 <td>
 <?php echo help("설정값이 없으면 기본 하단 파일을 사용합니다.");?>
 <input type="text" name="co_mobile_include_tail" value="<?php echo $co['co_mobile_include_tail'];?>" id="co_mobile_include_tail" class="frm_input" size="60">
 </td>
</tr>

3. 업데이트 처리 파일 수정 (adm/contentformupdate.php)

입력된 모바일 파일 경로의 확장자 검증, 보안 경로 체크, 데이터베이스 저장 처리를 위해 adm/contentformupdate.php 파일을 수정합니다.

  • 확장자 검증 추가 ($co_include_tail 관련 유효성 검증 코드 하단에 추가):
if( $co_mobile_include_head ){
 $purl = parse_url($co_mobile_include_head);
 $file = $purl['path'];
 if (!preg_match("/\.(php|htm['l']?)$/i", $file)) {
 alert('모바일 상단 파일 경로의 확장자는 php, html 만 허용합니다.');
 }
}
if( $co_mobile_include_tail ){
 $purl = parse_url($co_mobile_include_tail);
 $file = $purl['path'];
 if (!preg_match("/\.(php|htm['l']?)$/i", $file)) {
 alert('모바일 하단 파일 경로의 확장자는 php, html 만 허용합니다.');
 }
}
  • 경로 보안 검증 추가 (is_include_path_check 검증 코드 하단에 추가):
if( $co_mobile_include_head &&! is_include_path_check($co_mobile_include_head) ){
 $co_mobile_include_head = '';
 $error_msg = '/data/file/ 또는 /data/editor/ 포함된 문자를 상단 파일 경로에 포함시킬수 없습니다.';
}
if( $co_mobile_include_tail &&! is_include_path_check($co_mobile_include_tail) ){
 $co_mobile_include_tail = '';
 $error_msg = '/data/file/ 또는 /data/editor/ 포함된 문자를 하단 파일 경로에 포함시킬수 없습니다.';
}
  • SQL 저장 구문 수정 ($sql_common 정의 부분에 추가):
co_mobile_include_head = '$co_mobile_include_head',
co_mobile_include_tail = '$co_mobile_include_tail',

4. 모바일 뷰 파일 수정 (mobile/content.php)

모바일 접속 시 설정된 파일이 존재할 경우 해당 파일을 불러오도록 수정합니다.

  • 상단 파일 출력 부분 수정 (include_once('./_head.php'); 대신 변경):
if ($co['co_mobile_include_head'] && is_include_path_check($co['co_mobile_include_head'])) 
 @include_once($co['co_mobile_include_head']); 
else 
 include_once('./_head.php');
  • 하단 파일 출력 부분 수정 (include_once('./_tail.php'); 대신 변경):
if ($co['co_mobile_include_tail'] && is_include_path_check($co['co_mobile_include_tail'])) 
 @include_once($co['co_mobile_include_tail']); 
else 
 include_once('./_tail.php');

5. 주의사항 및 버전 차이 안내

그누보드 버전(5.2 ~ 5.4 등)에 따라 코어 파일의 라인 위치나 변수 처리에 일부 차이가 있을 수 있습니다. 팁에 기재된 소스코드를 그대로 붙여넣기보다 사용 중인 그누보드 원본 코드의 형태를 참고하여 일치하는 위치에 정확히 반영해야 합니다.

상황별 판단 및 다음 행동

내 상황우선할 판단다음 행동
내용 관리 페이지에서 모바일 상단·하단 파일을 별도로 지정하고 싶으나 입력 필드가 없음데이터베이스 g5_content 테이블에 모바일 상단/하단 경로 필드 추가 및 관련 관리자·모바일 파일 수정 필요g5_content 테이블에 co_mobile_include_head, co_mobile_include_tail 필드를 추가한 뒤 adm/contentform.php, adm/contentformupdate.php, mobile/content.php 파일을 수정하여 연동합니다.
코드 수정 후 내용 추가나 수정 시 등록된 자료가 없습니다 에러가 발생함사용 중인 그누보드 버전(5.2~5.4 등)과 팁 코드의 라인 매칭 차이 또는 서버 설정 환경 확인팁에 제시된 코드를 무조건 복사하지 말고 운영 중인 그누보드 버전의 원본 파일 구조와 라인을 참고하여 정확한 위치에 반영합니다.

실전 FAQ

Q. 내용 관리 페이지 모바일 파일 경로 입력 시 허용되는 확장자와 제한 사항은 무엇인가요?

  • 예외 및 대안: 확장자는 php와 html만 허용되며, 보안상 취약할 수 있는 /data/file/ 또는 /data/editor/ 경로 문자가 포함된 경우 시스템에서 경로를 강제로 초기화하거나 에러를 발생시키므로 안전한 하위 디렉토리 경로를 지정해야 합니다.

Q. 그누보드 원본 코드를 직접 수정하는 것이 부담될 경우 다른 대안이 있나요?

  • 예외 및 대안: adm이나 모바일 코어 파일을 직접 수정하지 않고 테마 내 mobile/head.php와 mobile/tail.php 파일에 $co_id 조건을 활용하여 모바일 상하단 파일을 직접 인클루드하는 간러스한 방식을 적용할 수도 있습니다.

함께 보면 좋은 글

참고자료

기타 참고자료

댓글목록

등록된 댓글이 없습니다.