그누보드 최신버전 (5.1.0) 살펴보기 - common.php (7)
common.php 그누보드에서 가장 기본이 되는 파일이라고 볼수 있습니다.
모든 파일에 기본적으로 인클루드 되어서 사용됩니다.
에러출력 설정, 보안적인 처리, 기본적인 경로 설정, 디비연결, 세션 설정및 시작, 공용변수의 초기화 및 재설정, 기타 확장 등의 내용으로 이루어져 있습니다.
337라인부터 461라인까지는 별다른 설명이 필요없어서 생략합니다.
if(defined('_THEME_PREVIEW_') && _THEME_PREVIEW_ === true)
$config['cf_theme'] = trim($_GET['theme']);
_THEME_PREVIEW_ 이 상수는 config.php 에 정의되어 있지 않습니다.
테마 미리 보기를 사용 할경우
config.php 이 상수를 true 로 정의 하면 됩니다.
$config['cf_theme'] = trim($_GET['theme']);
이 부부은 넘어온 theme 변수가 있으면 기본 테마를 그 변수값으로 설정하겠다는 것인데
if (isset($GET['theme']) && strlen(preg_replace("`\s`", '', $GET['theme'])) > 0)
$config['cf_theme'] = preg_replace("`\s`", '', $_GET['theme']);
이렇게 하는 것이 더 좋아보입니다.
if(isset($config['cf_theme']) && trim($config['cf_theme'])) {
$theme_path = G5_PATH.'/'.G5_THEME_DIR.'/'.$config['cf_theme'];
if(is_dir($theme_path)) {
define('G5_THEME_PATH', $theme_path);
define('G5_THEME_URL', G5_URL.'/'.G5_THEME_DIR.'/'.$config['cf_theme']);
define('G5_THEME_MOBILE_PATH', $theme_path.'/'.G5_MOBILE_DIR);
define('G5_THEME_LIB_PATH', $theme_path.'/'.G5_LIB_DIR);
define('G5_THEME_CSS_URL', G5_THEME_URL.'/'.G5_CSS_DIR);
define('G5_THEME_IMG_URL', G5_THEME_URL.'/'.G5_IMG_DIR);
define('G5_THEME_JS_URL', G5_THEME_URL.'/'.G5_JS_DIR);
}
unset($theme_path);
}
if(isset($config['cf_theme']) && trim($config['cf_theme'])) {
이것은 $config['cf_theme'] 가 정의 되어잇고 값이 있을때 실행하겟다는 내용인데
$config['cf_theme'] 에 0 이 들어가 있으면 실행안될수 있을것 같습니다.
물론 테마이름에 0을 설정하긴 드물겟지만.......
if (isset($config['cf_theme'])) {
$config['cf_theme'] = preg_replace("`\s`", '', $_GET['theme']);
if(strlen($config['cf_theme']) > 0) {
이렇게 하는 것이 더 좋아보입니다.
// 테마 설정 로드
if(is_file(G5_THEME_PATH.'/theme.config.php'))
include_once(G5_THEME_PATH.'/theme.config.php');
테마의 환경설정 파일을 인클루드 합니다.
해당파일에는 테마가 지원하는 장치 설정 및 사용될 스킨과 몇몇 환경설정값이 $theme_config 에 정의 됩니다.
$is_mobile = false;
$set_device = true;
if(defined('G5_THEME_DEVICE') && G5_THEME_DEVICE != '') {
switch(G5_THEME_DEVICE) {
case 'pc':
$is_mobile = false;
$set_device = false;
break;
case 'mobile':
$is_mobile = true;
$set_device = false;
break;
default:
break;
}
}
현재 출력될 페이지를 pc용으로 출력할것인지 mobile 용으로 출력할것인지 체크하는 부분입니다.
테마 환경설정에서 G5_THEME_DEVICE 빈값이 아닌 pc, mobile 로 설정하였다면 그 설정에 따릅니다.
그리고 $set_device = false; 를 통해 pc와 모바일 전환이 불가능하도록 합니다.
if(defined('G5_SET_DEVICE') && $set_device) {
switch(G5_SET_DEVICE) {
case 'pc':
$is_mobile = false;
$set_device = false;
break;
case 'mobile':
$is_mobile = true;
$set_device = false;
break;
default:
break;
}
}
G5_THEME_DEVICE 이 빈값일 경우 G5_SET_DEVICE 에 설정된 값에 따라 pc용인지 모바일용인지 체크합니다.
config.php 에서는
define('G5_SET_DEVICE', 'both'); 와 같이 설정되어있는데
both 라는 값은 무의미 해보입니다.
pc 또는 mobile 또는 빈값으로 설정가능합니다.
역시 마찬가지로 빈값이 아닐경우에는 $set_device = false; 를 통해 pc와 모바일 전환이 불가능하도록 합니다.
if (G5_USE_MOBILE && $set_device) {
if ($_REQUEST['device']=='pc')
$is_mobile = false;
else if ($_REQUEST['device']=='mobile')
$is_mobile = true;
else if (isset($_SESSION['ss_is_mobile']))
$is_mobile = $_SESSION['ss_is_mobile'];
else if (is_mobile())
$is_mobile = true;
} else {
$set_device = false;
}
config.php 에서 정의 된 G5_USE_MOBILE 을 사용합니다.
define('G5_USE_MOBILE', true); // 모바일 홈페이지를 사용하지 않을 경우 false 로 설정
이렇게 설명되어져 있습니다
G5_THEME_DEVICE 와 G5_SET_DEVICE 가 둘다 빈값일 때만 모바일 사용유무를 결정할수 있습니다.
if ($_REQUEST['device']=='pc')
$is_mobile = false;
else if ($_REQUEST['device']=='mobile')
$is_mobile = true;
조건절내에 isset($_REQUEST['device']) && 가 들어가는 것이 좋아 보입니다.
아무튼 $_REQUEST['device'] 가 존재하고 그 값이 pc나 모바일이면 그걸 우선으로 결정하고
그다음 세션, 세션도 없다면 이 접속환경이 모바일인지 체크하여 결정합니다.
$_SESSION['ss_is_mobile'] = $is_mobile;
결정된 출력환경을 세션에 저장합니다.
define('G5_IS_MOBILE', $is_mobile);
결정된 출력 환경을 상수에도 정의합니다.
define('G5_DEVICE_BUTTON_DISPLAY', $set_device);
pc 모바일 전환 가능 여부를 상수에 정의합니다.
if (G5_IS_MOBILE) {
$g5['mobile_path'] = G5_PATH.'/'.$g5['mobile_dir'];
}
모바일이라면 기본 모바일 경로를 설정합니다.
if (G5_IS_MOBILE) {
$board_skin_path = get_skin_path('board', $board['bo_mobile_skin']);
$board_skin_url = get_skin_url('board', $board['bo_mobile_skin']);
$member_skin_path = get_skin_path('member', $config['cf_mobile_member_skin']);
$member_skin_url = get_skin_url('member', $config['cf_mobile_member_skin']);
$new_skin_path = get_skin_path('new', $config['cf_mobile_new_skin']);
$new_skin_url = get_skin_url('new', $config['cf_mobile_new_skin']);
$search_skin_path = get_skin_path('search', $config['cf_mobile_search_skin']);
$search_skin_url = get_skin_url('search', $config['cf_mobile_search_skin']);
$connect_skin_path = get_skin_path('connect', $config['cf_mobile_connect_skin']);
$connect_skin_url = get_skin_url('connect', $config['cf_mobile_connect_skin']);
$faq_skin_path = get_skin_path('faq', $config['cf_mobile_faq_skin']);
$faq_skin_url = get_skin_url('faq', $config['cf_mobile_faq_skin']);
} else {
$board_skin_path = get_skin_path('board', $board['bo_skin']);
$board_skin_url = get_skin_url('board', $board['bo_skin']);
$member_skin_path = get_skin_path('member', $config['cf_member_skin']);
$member_skin_url = get_skin_url('member', $config['cf_member_skin']);
$new_skin_path = get_skin_path('new', $config['cf_new_skin']);
$new_skin_url = get_skin_url('new', $config['cf_new_skin']);
$search_skin_path = get_skin_path('search', $config['cf_search_skin']);
$search_skin_url = get_skin_url('search', $config['cf_search_skin']);
$connect_skin_path = get_skin_path('connect', $config['cf_connect_skin']);
$connect_skin_url = get_skin_url('connect', $config['cf_connect_skin']);
$faq_skin_path = get_skin_path('faq', $config['cf_faq_skin']);
$faq_skin_url = get_skin_url('faq', $config['cf_faq_skin']);
}
출력환경에 따른 기본 스킨 경로를 설정합니다.
$extend_file = array();
$tmp = dir(G5_EXTEND_PATH);
while ($entry = $tmp->read()) {
// php 파일만 include 함
if (preg_match("/(\.php)$/i", $entry))
$extend_file[] = $entry;
}
if(!empty($extend_file) && is_array($extend_file)) {
natsort($extend_file);
foreach($extend_file as $file) {
include_once(G5_EXTEND_PATH.'/'.$file);
}
}
unset($extend_file);
extend 하위에 확장자가 php 인 파일들을 넣어서 common.php를 직접 수정하는 경우가 없도록 하는 경우입니다.
일종의 hook 개념으로 볼수 있습니다.
natsort 은 자연정렬을 의미합니다.
일반적인 sort 는 문자열로 취급하여 정렬시키나 natsort 는 숫자도 따져서 정렬합니다.
본래의 의도와는 다르게 인클루드 순서가 꼬이는 것을 방지하기 위한 조치라고 볼수 있습니다.
ob_start();
출력버퍼를 켭니다.
즉, 지금 부터 출력되는 헤더를 제외한 모든것을 메모리에 담아두고 실제로는 아무 전송을 하지 않는다는 의미입니다.
header('Content-Type: text/html; charset=utf-8');
$gmnow = gmdate('D, d M Y H:i:s') . ' GMT';
header('Expires: 0'); // rfc2616 - Section 14.21
header('Last-Modified: ' . $gmnow);
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Pragma: no-cache'); // HTTP/1.0
헤더 출력을 합니다.
윗 부분
session_cache_limiter("no-cache, must-revalidate");
에서
nocache 로 제대로 설정하였다면
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Pragma: no-cache'); // HTTP/1.0
이 부분은 필요없을것 같습니다.
$html_process = new html_process();
이 클래스에 대해서는 나중에 설명하도록 하겠습니다.
대략적으로 css 나 js 의 위치를 출력때 바로 잡아주기 위한 정도로 일단 생각하면 될것같습니다.
댓글 8개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8130 | 9년 전 | 517 | ||
| 8129 |
|
9년 전 | 654 | |
| 8128 | 9년 전 | 521 | ||
| 8127 |
|
9년 전 | 576 | |
| 8126 | 9년 전 | 508 | ||
| 8125 | 9년 전 | 766 | ||
| 8124 |
|
9년 전 | 520 | |
| 8123 | 9년 전 | 504 | ||
| 8122 | 9년 전 | 437 | ||
| 8121 | 9년 전 | 538 | ||
| 8120 | 9년 전 | 467 | ||
| 8119 | 9년 전 | 549 | ||
| 8118 |
|
9년 전 | 632 | |
| 8117 |
|
9년 전 | 402 | |
| 8116 |
PASKRAN
|
9년 전 | 469 | |
| 8115 | 9년 전 | 460 | ||
| 8114 |
kiplayer
|
9년 전 | 598 | |
| 8113 | 9년 전 | 449 | ||
| 8112 |
|
9년 전 | 558 | |
| 8111 | 9년 전 | 410 | ||
| 8110 | 9년 전 | 445 | ||
| 8109 | 9년 전 | 372 | ||
| 8108 |
|
9년 전 | 543 | |
| 8107 |
|
9년 전 | 439 | |
| 8106 |
|
9년 전 | 439 | |
| 8105 | 9년 전 | 476 | ||
| 8104 |
|
9년 전 | 429 | |
| 8103 |
|
9년 전 | 432 | |
| 8102 |
|
9년 전 | 398 | |
| 8101 |
snshero
|
9년 전 | 784 | |
| 8100 | 9년 전 | 839 | ||
| 8099 | 9년 전 | 813 | ||
| 8098 | 9년 전 | 714 | ||
| 8097 | 9년 전 | 521 | ||
| 8096 | 9년 전 | 713 | ||
| 8095 | 9년 전 | 845 | ||
| 8094 | 9년 전 | 517 | ||
| 8093 | 9년 전 | 801 | ||
| 8092 | 9년 전 | 760 | ||
| 8091 | 9년 전 | 1144 | ||
| 8090 | 9년 전 | 767 | ||
| 8089 | 9년 전 | 978 | ||
| 8088 | 9년 전 | 646 | ||
| 8087 | 9년 전 | 766 | ||
| 8086 | 9년 전 | 524 | ||
| 8085 | 9년 전 | 487 | ||
| 8084 | 9년 전 | 609 | ||
| 8083 | 9년 전 | 582 | ||
| 8082 | 9년 전 | 755 | ||
| 8081 | 9년 전 | 472 | ||
| 8080 | 9년 전 | 572 | ||
| 8079 | 9년 전 | 523 | ||
| 8078 | 9년 전 | 453 | ||
| 8077 | 9년 전 | 533 | ||
| 8076 | 9년 전 | 409 | ||
| 8075 | 9년 전 | 444 | ||
| 8074 | 9년 전 | 401 | ||
| 8073 | 9년 전 | 453 | ||
| 8072 | 9년 전 | 448 | ||
| 8071 |
o1o111
|
9년 전 | 897 | |
| 8070 | 9년 전 | 403 | ||
| 8069 | 9년 전 | 339 | ||
| 8068 | 9년 전 | 591 | ||
| 8067 | 9년 전 | 391 | ||
| 8066 | 9년 전 | 428 | ||
| 8065 | 9년 전 | 382 | ||
| 8064 | 9년 전 | 369 | ||
| 8063 | 9년 전 | 340 | ||
| 8062 | 9년 전 | 312 | ||
| 8061 | 9년 전 | 352 | ||
| 8060 | 9년 전 | 393 | ||
| 8059 | 9년 전 | 327 | ||
| 8058 | 9년 전 | 257 | ||
| 8057 | 9년 전 | 386 | ||
| 8056 | 9년 전 | 311 | ||
| 8055 | 9년 전 | 354 | ||
| 8054 | 9년 전 | 365 | ||
| 8053 | 9년 전 | 416 | ||
| 8052 | 9년 전 | 294 | ||
| 8051 | 9년 전 | 335 | ||
| 8050 | 9년 전 | 394 | ||
| 8049 | 9년 전 | 323 | ||
| 8048 | 9년 전 | 437 | ||
| 8047 | 9년 전 | 360 | ||
| 8046 | 9년 전 | 309 | ||
| 8045 | 9년 전 | 260 | ||
| 8044 | 9년 전 | 347 | ||
| 8043 | 9년 전 | 294 | ||
| 8042 | 9년 전 | 296 | ||
| 8041 | 9년 전 | 353 | ||
| 8040 | 9년 전 | 275 | ||
| 8039 | 9년 전 | 321 | ||
| 8038 | 9년 전 | 271 | ||
| 8037 | 9년 전 | 409 | ||
| 8036 | 9년 전 | 485 | ||
| 8035 | 9년 전 | 436 | ||
| 8034 | 9년 전 | 393 | ||
| 8033 | 9년 전 | 352 | ||
| 8032 | 9년 전 | 444 | ||
| 8031 | 9년 전 | 354 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기