AvocadoAmber/AvocadoEdition_Light/common.php

852 lines
27 KiB
PHP
Raw Normal View History

2022-09-17 20:50:50 +09:00
<?php
/*******************************************************************************
2024-09-19 20:36:07 +09:00
** 공통 변수, 상수, 코드
*******************************************************************************/
2024-09-22 11:23:47 +09:00
error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_PARSE | E_USER_ERROR);
2022-09-17 20:50:50 +09:00
// 보안설정이나 프레임이 달라도 쿠키가 통하도록 설정
header('P3P: CP="ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC OTC"');
if (!defined('G5_SET_TIME_LIMIT')) {
2024-09-19 20:36:07 +09:00
define('G5_SET_TIME_LIMIT', 0);
}
2024-09-21 10:14:04 +09:00
2022-09-17 20:50:50 +09:00
@set_time_limit(G5_SET_TIME_LIMIT);
define("__ADVDIR__", __DIR__);
2022-09-17 20:50:50 +09:00
/**
* func(...$args) 지원을 위해 최소 버전이 gnuboard5 최소인 5.2.17 보다 높게 설정되었습니다.
* 5.6.x 지원종료된지 한참 되었는데 굳이 구버전을 사용할 이유가 있다면
* 구버전에서만 동작하는 코드가 있기 때문이겠지요...
*/
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
echo "<h1>php 버전이 지원하는 버전보다 낮습니다.</h1>" . PHP_EOL;
echo "<p>지원하는 최소 php 버전은 5.6.0 이상입니다.</p>" . PHP_EOL;
echo "<p>현재 php 버전은 <b>" . PHP_VERSION . "</b> 입니다.</p>" . PHP_EOL;
exit();
}
include_once __DIR__ . "/classes/event_handler.php";
2024-09-28 13:03:15 +09:00
$extra_headers = [
'HTTP_X_REAL_IP',
'HTTP_X_FORWARDED_HOST',
'HTTP_X_FORWARDED_PROTO',
'HTTP_X_FORWARDED_SSL',
];
2024-09-21 10:14:04 +09:00
// filter for dynamic variables
$var_filter = [
2024-09-19 20:36:07 +09:00
'PHP_SELF',
'_ENV',
'_GET',
'_POST',
'_FILES',
'_SERVER',
'_COOKIE',
'_SESSION',
'_REQUEST',
'HTTP_ENV_VARS',
'HTTP_GET_VARS',
'HTTP_POST_VARS',
'HTTP_POST_FILES',
'HTTP_SERVER_VARS',
'HTTP_COOKIE_VARS',
'HTTP_SESSION_VARS',
'GLOBALS'
2024-09-28 13:03:15 +09:00
];
foreach ($var_filter as $val) {
if (array_key_exists($val, $_GET) && isset($_GET[$val])) {
unset($_GET[$val]);
}
if (array_key_exists($val, $_POST) && isset($_POST[$val])) {
unset($_POST[$val]);
}
2022-09-17 20:50:50 +09:00
}
2024-09-21 10:14:04 +09:00
/**
2024-09-28 13:03:15 +09:00
* Load require class and others
2024-09-21 10:14:04 +09:00
* @param mixed $base_dir
* @throws \Exception
* @return string[]
*/
2024-09-28 13:16:29 +09:00
function load_libs($base_dir, $load_type = "class")
2024-09-21 10:14:04 +09:00
{
$base_path = realpath($base_dir);
if ($base_path === false) {
throw new Exception("지정된 기본 디렉토리를 찾을 수 없습니다: $base_dir");
}
2024-09-28 13:03:15 +09:00
2024-09-21 10:14:04 +09:00
$loaded_files = [];
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($base_path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
2024-09-28 13:03:15 +09:00
2024-09-21 10:14:04 +09:00
foreach ($iterator as $file) {
2024-09-28 13:03:15 +09:00
try {
if ($file->isDir()) {
$parent_folder_name = $file->getFilename();
2024-09-28 13:16:29 +09:00
$class_file = $file->getPathname() . DIRECTORY_SEPARATOR . "{$parent_folder_name}.{$load_type}.php";
2024-09-28 13:03:15 +09:00
if (file_exists($class_file)) {
require_once $class_file;
$loaded_files[] = $class_file;
}
2024-09-21 10:14:04 +09:00
}
} catch (Exception $x) {
2024-09-28 13:03:15 +09:00
2024-09-21 10:14:04 +09:00
}
}
2024-09-28 13:03:15 +09:00
2024-09-21 10:14:04 +09:00
return $loaded_files;
}
2024-09-28 13:03:15 +09:00
/**
* custom function from arcturus
* https://info.drk.st/about
* @param string $currentDir
* @return string
*/
function get_url_path_from_root($currentDir = __DIR__)
{
$documentRoot = rtrim($_SERVER["DOCUMENT_ROOT"], '/');
$relativePath = str_replace($documentRoot, '', $currentDir);
$urlPath = str_replace(DIRECTORY_SEPARATOR, '/', $relativePath);
return rtrim($urlPath, '/');
}
/**
* custom function from arcturus
* https://info.drk.st/about
* @param string $type
* @param string $path
* @param array $args
* @return string|void
*/
function get_embed_file($type, $path, ...$args)
{
if (file_exists($path)) {
$full_path = "";
if (strstr($path, $_SERVER["DOCUMENT_ROOT"])) {
$full_path = $path;
$path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path);
} else {
$full_path = $_SERVER["DOCUMENT_ROOT"] . $path;
}
$url_path = get_url_path_from_root(dirname($full_path));
$url = $url_path . '/' . basename($path);
switch ($type) {
case "script":
return "<script src=\"" . $url . "?t=" . filemtime($full_path) . "\"></script>";
case "css":
case "stylesheet":
return "<link href=\"" . $url . "?t=" . filemtime($full_path) . "\" rel=\"stylesheet\">";
}
}
}
2024-09-21 10:14:04 +09:00
$_system = new stdClass;
2024-09-28 13:16:29 +09:00
$_system->classes = load_libs(__DIR__ . "/classes", "class");
$_system->addons = load_libs(__DIR__ . "/addons", "addon");
2024-09-28 13:03:15 +09:00
// $_system->modules = load_libs(__DIR__ . "/modules", "model");
// $_system->modules = load_libs(__DIR__ . "/modules");
// arc: 이 이벤트는 before 가 없습니다.
EventHandler::triggerEvent("gnuboard.loadlibs.after", $_system);
2022-09-17 20:50:50 +09:00
function g5_path()
{
2024-09-19 20:36:07 +09:00
$result['path'] = str_replace('\\', '/', dirname(__FILE__));
$tilde_remove = preg_replace('/^\/\~[^\/]+(.*)$/', '$1', $_SERVER['SCRIPT_NAME']);
$document_root = str_replace($tilde_remove, '', $_SERVER['SCRIPT_FILENAME']);
$root = str_replace($document_root, '', $result['path']);
$port = $_SERVER['SERVER_PORT'] != 80 ? ':' . $_SERVER['SERVER_PORT'] : '';
$http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
$user = str_replace(str_replace($document_root, '', $_SERVER['SCRIPT_FILENAME']), '', $_SERVER['SCRIPT_NAME']);
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
if (isset($_SERVER['HTTP_HOST']) && preg_match('/:[0-9]+$/', $host))
$host = preg_replace('/:[0-9]+$/', '', $host);
$host = preg_replace("/[\<\>\'\"\\\'\\\"\%\=\(\)\/\^\*]/", '', $host);
$result['url'] = $http . $host . $port . $user . $root;
return $result;
2022-09-17 20:50:50 +09:00
}
$g5_path = g5_path();
2024-09-28 13:03:15 +09:00
include_once $g5_path['path'] . '/config.php'; // 설정 파일
2022-09-17 20:50:50 +09:00
unset($g5_path);
// Cloudflare 환경을 고려한 https 사용여부
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === "https") {
$_SERVER['HTTPS'] = 'on';
}
2022-09-17 20:50:50 +09:00
// multi-dimensional array에 사용자지정 함수적용
function array_map_deep($fn, $array)
{
2024-09-19 20:36:07 +09:00
if (is_array($array)) {
foreach ($array as $key => $value) {
2024-09-28 13:03:15 +09:00
$array[$key] = is_array($value) ? array_map_deep($fn, $value) : call_user_func($fn, $value);
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
} else {
$array = call_user_func($fn, $array);
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:36:07 +09:00
return $array;
2022-09-17 20:50:50 +09:00
}
// SQL Injection 대응 문자열 필터링
function sql_escape_string($str)
{
2024-09-19 20:36:07 +09:00
if (defined('G5_ESCAPE_PATTERN') && defined('G5_ESCAPE_REPLACE')) {
$pattern = G5_ESCAPE_PATTERN;
$replace = G5_ESCAPE_REPLACE;
2022-09-17 20:50:50 +09:00
2024-09-19 20:36:07 +09:00
if ($pattern)
$str = preg_replace($pattern, $replace, $str);
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:36:07 +09:00
$str = call_user_func('addslashes', $str);
2022-09-17 20:50:50 +09:00
2024-09-19 20:36:07 +09:00
return $str;
2022-09-17 20:50:50 +09:00
}
//==============================================================================
// SQL Injection 등으로 부터 보호를 위해 sql_escape_string() 적용
//------------------------------------------------------------------------------
2024-09-23 11:07:19 +09:00
function strip_slashes_deep($value)
{
return is_array($value) ? array_map('strip_slashes_deep', $value) : stripslashes($value);
}
2022-09-17 20:50:50 +09:00
// magic_quotes_gpc 에 의한 backslashes 제거
2024-09-23 11:07:19 +09:00
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
2024-09-28 13:03:15 +09:00
if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
2024-09-23 11:07:19 +09:00
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$_POST = array_map('strip_slashes_deep', $_POST);
$_GET = array_map('strip_slashes_deep', $_GET);
$_COOKIE = array_map('strip_slashes_deep', $_COOKIE);
$_REQUEST = array_map('strip_slashes_deep', $_REQUEST);
}
} else {
die("php 버전이 너무 낮습니다.");
2024-09-23 11:07:19 +09:00
}
2022-09-17 20:50:50 +09:00
}
// sql_escape_string 적용
2024-09-19 20:36:07 +09:00
$_POST = array_map_deep(G5_ESCAPE_FUNCTION, $_POST);
$_GET = array_map_deep(G5_ESCAPE_FUNCTION, $_GET);
$_COOKIE = array_map_deep(G5_ESCAPE_FUNCTION, $_COOKIE);
$_REQUEST = array_map_deep(G5_ESCAPE_FUNCTION, $_REQUEST);
2022-09-17 20:50:50 +09:00
//==============================================================================
// PHP 4.1.0 부터 지원됨
// php.ini 의 register_globals=off 일 경우
@extract($_GET);
@extract($_POST);
@extract($_SERVER);
// 완두콩님이 알려주신 보안관련 오류 수정
// $member 에 값을 직접 넘길 수 있음
2024-09-23 09:37:13 +09:00
$config = [];
2024-09-27 17:11:41 +09:00
$member = [
'mb_id' => '',
'mb_level' => 1,
'mb_name' => '',
'mb_point' => 0,
'mb_certify' => '',
'mb_email' => '',
'mb_open' => '',
'mb_homepage' => '',
'mb_tel' => '',
'mb_hp' => '',
'mb_zip1' => '',
'mb_zip2' => '',
'mb_addr1' => '',
'mb_addr2' => '',
'mb_addr3' => '',
'mb_addr_jibeon' => '',
'mb_signature' => '',
'mb_profile' => ''
];
$board = [
'bo_table' => '',
'bo_skin' => '',
'bo_mobile_skin' => '',
'bo_upload_count' => 0,
'bo_use_dhtml_editor' => '',
'bo_subject' => '',
'bo_image_width' => 0
];
$group = [
'gr_device' => '',
'gr_subject' => ''
];
2024-09-23 09:37:13 +09:00
$article = [];
$g5 = [];
2024-09-27 17:11:41 +09:00
if (version_compare(phpversion(), '8.0.0', '>=')) {
$g5 = ['title' => ''];
}
$qaconfig = [];
$g5_debug = [
'php' => [],
'sql' => []
];
include_once G5_LIB_PATH . '/hook.lib.php';
include_once G5_LIB_PATH . '/get_data.lib.php';
include_once G5_LIB_PATH . '/cache.lib.php';
include_once G5_LIB_PATH . '/url.lib.php';
2022-09-17 20:50:50 +09:00
$g5_object = new G5_object_cache();
2022-09-17 20:50:50 +09:00
//==============================================================================
// 공통
//------------------------------------------------------------------------------
2024-09-19 20:36:07 +09:00
$dbconfig_file = G5_DATA_PATH . '/' . G5_DBCONFIG_FILE;
2022-09-17 20:50:50 +09:00
if (file_exists($dbconfig_file)) {
2024-09-22 11:23:47 +09:00
include_once $dbconfig_file;
include_once G5_LIB_PATH . '/common.lib.php'; // 공통 라이브러리
2024-09-22 13:51:59 +09:00
$g5["font_table"] = G5_TABLE_PREFIX . "editor_fonts";
2024-09-19 20:36:07 +09:00
$connect_db = sql_connect(G5_MYSQL_HOST, G5_MYSQL_USER, G5_MYSQL_PASSWORD) or die('MySQL Connect Error!!!');
$select_db = sql_select_db(G5_MYSQL_DB, $connect_db) or die('MySQL DB Error!!!');
2022-09-17 20:50:50 +09:00
2024-09-19 20:36:07 +09:00
// mysql connect resource $g5 배열에 저장 - 명랑폐인님 제안
$g5['connect_db'] = $connect_db;
2022-09-17 20:50:50 +09:00
2024-09-19 20:36:07 +09:00
sql_set_charset('utf8', $connect_db);
if (defined('G5_MYSQL_SET_MODE') && G5_MYSQL_SET_MODE)
sql_query("SET SESSION sql_mode = ''");
if (defined('G5_TIMEZONE'))
sql_query(" set time_zone = '" . G5_TIMEZONE . "'");
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 21:03:48 +09:00
?><!doctype html>
2024-09-23 11:07:19 +09:00
<html lang="ko">
2024-09-19 20:36:07 +09:00
<head>
<meta charset="utf-8">
<title>오류! <?php echo G5_VERSION ?> 설치하기</title>
<link rel="stylesheet" href="install/install.css">
</head>
2024-09-23 11:07:19 +09:00
2024-09-19 20:36:07 +09:00
<body>
<div id="ins_bar">
<span id="bar_img">AVOCADO EDITION</span>
<span id="bar_txt">Message</span>
</div>
<h1>아보카도 에디션을 먼저 설치해주십시오.</h1>
<div class="ins_inner">
<p>다음 파일을 찾을 없습니다.</p>
<ul>
<li><strong><?php echo G5_DATA_DIR . '/' . G5_DBCONFIG_FILE ?></strong></li>
</ul>
<p>아보카도 에디션 설치 다시 실행하시기 바랍니다.</p>
<div class="inner_btn">
2022-09-17 20:50:50 +09:00
<a href="<?php echo G5_URL; ?>/install/"><?php echo G5_VERSION ?> 설치하기</a>
2024-09-19 20:36:07 +09:00
</div>
</div>
<div id="ins_ft">
<strong>AVOCADO EDITION</strong>
<p>GPL! OPEN SOURCE GNUBOARD</p>
2022-09-17 20:50:50 +09:00
</div>
2024-09-19 20:36:07 +09:00
</body>
2024-09-23 11:07:19 +09:00
</html><?php
2024-09-19 20:36:07 +09:00
exit;
2022-09-17 20:50:50 +09:00
}
//==============================================================================
// 디자인 미설치
//------------------------------------------------------------------------------
2024-09-19 20:36:07 +09:00
if (strstr($url, 'adm')) {
define('G5_IS_ADMIN', true);
}
if (!defined('G5_IS_ADMIN')) {
$cssconfig_file = G5_DATA_PATH . '/css/_design.config.css';
if (!file_exists($cssconfig_file)) {
?>
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>오류! <?php echo G5_VERSION ?> 설치하기</title>
<link rel="stylesheet" href="<?= G5_URL ?>/install/install.css">
</head>
<body>
<div id="ins_bar">
<span id="bar_img">AVOCADO EDITION</span>
<span id="bar_txt">Message</span>
</div>
<h1>아보카도 에디션 설정을 완료해주십시오.</h1>
<br />
<div class="ins_inner">
<p>아보카도 에디션 라이트 설치가 완료 되었습니다.</p>
<p>하지만, 아보카도 에디션의 디자인 설정이 완료되지 않았습니다.</p>
<p>사이트 관리 화면에서 디자인 설정을 완료하여 주시길 바랍니다. (최소 1 이상 저장 필요)</p>
<div class="inner_btn">
<a href="<?php echo G5_URL; ?>/adm/"><?php echo G5_VERSION ?> 관리자 바로가기</a>
</div>
</div>
<div id="ins_ft">
<strong>AVOCADO EDITION : AMBER</strong>
2024-09-19 20:36:07 +09:00
<p>GPL! OPEN SOURCE GNUBOARD</p>
</div>
</body>
</html>
<?php exit;
}
2022-09-17 20:50:50 +09:00
}
//==============================================================================
// SESSION 설정
//------------------------------------------------------------------------------
@ini_set("session.use_trans_sid", 0); // PHPSESSID를 자동으로 넘기지 않음
2024-09-19 20:36:07 +09:00
@ini_set("url_rewriter.tags", ""); // 링크에 PHPSESSID가 따라다니는것을 무력화함 (해뜰녘님께서 알려주셨습니다.)
2022-09-17 20:50:50 +09:00
session_save_path(G5_SESSION_PATH);
if (isset($SESSION_CACHE_LIMITER))
2024-09-19 20:36:07 +09:00
@session_cache_limiter($SESSION_CACHE_LIMITER);
2022-09-17 20:50:50 +09:00
else
2024-09-19 20:36:07 +09:00
@session_cache_limiter("no-cache, must-revalidate");
2022-09-17 20:50:50 +09:00
ini_set("session.cache_expire", 180); // 세션 캐쉬 보관시간 (분)
ini_set("session.gc_maxlifetime", 10800); // session data의 garbage collection 존재 기간을 지정 (초)
ini_set("session.gc_probability", 1); // session.gc_probability는 session.gc_divisor와 연계하여 gc(쓰레기 수거) 루틴의 시작 확률을 관리합니다. 기본값은 1입니다. 자세한 내용은 session.gc_divisor를 참고하십시오.
ini_set("session.gc_divisor", 100); // session.gc_divisor는 session.gc_probability와 결합하여 각 세션 초기화 시에 gc(쓰레기 수거) 프로세스를 시작할 확률을 정의합니다. 확률은 gc_probability/gc_divisor를 사용하여 계산합니다. 즉, 1/100은 각 요청시에 GC 프로세스를 시작할 확률이 1%입니다. session.gc_divisor의 기본값은 100입니다.
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
session_set_cookie_params(0, '/', null, true, true);
} else {
session_set_cookie_params(0, '/', null, false, true);
}
2022-09-17 20:50:50 +09:00
ini_set("session.cookie_domain", G5_COOKIE_DOMAIN);
@session_start();
//==============================================================================
// 공용 변수
//------------------------------------------------------------------------------
// 기본환경설정
// 기본적으로 사용하는 필드만 얻은 후 상황에 따라 필드를 추가로 얻음
$config = sql_fetch(" select * from {$g5['config_table']} ");
$article = sql_fetch("select * from {$g5['article_default_table']}");
2024-09-19 20:36:07 +09:00
define('G5_HTTP_BBS_URL', https_url(G5_BBS_DIR, false));
2022-09-17 20:50:50 +09:00
define('G5_HTTPS_BBS_URL', https_url(G5_BBS_DIR, true));
if ($config['cf_editor'])
2024-09-19 20:36:07 +09:00
define('G5_EDITOR_LIB', G5_EDITOR_PATH . "/{$config['cf_editor']}/editor.lib.php");
2022-09-17 20:50:50 +09:00
else
2024-09-19 20:36:07 +09:00
define('G5_EDITOR_LIB', G5_LIB_PATH . "/editor.lib.php");
2022-09-17 20:50:50 +09:00
// 4.00.03 : [보안관련] PHPSESSID 가 틀리면 로그아웃한다.
if (isset($_REQUEST['PHPSESSID']) && $_REQUEST['PHPSESSID'] != session_id())
2024-09-19 20:36:07 +09:00
goto_url(G5_BBS_URL . '/logout.php');
2022-09-17 20:50:50 +09:00
// QUERY_STRING
$qstr = '';
2024-09-19 20:36:07 +09:00
if (isset($_REQUEST['sca'])) {
$sca = clean_xss_tags(trim($_REQUEST['sca']));
if ($sca) {
$sca = preg_replace("/[\<\>\'\"\\\'\\\"\%\=\(\)\/\^\*]/", "", $sca);
$qstr .= '&amp;sca=' . urlencode($sca);
}
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$sca = '';
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
if (isset($_REQUEST['sfl'])) {
$sfl = trim($_REQUEST['sfl']);
$sfl = preg_replace("/[\<\>\'\"\\\'\\\"\%\=\(\)\/\^\*\s\#]/", "", $sfl);
2024-09-19 20:36:07 +09:00
if ($sfl)
$qstr .= '&amp;sfl=' . urlencode($sfl); // search field (검색 필드)
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$sfl = '';
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
if (isset($_REQUEST['stx'])) { // search text (검색어)
$stx = get_search_string(trim($_REQUEST['stx']));
if ($stx || $stx === '0')
2024-09-19 20:36:07 +09:00
$qstr .= '&amp;stx=' . urlencode(cut_str($stx, 20, ''));
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$stx = '';
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
if (isset($_REQUEST['sst'])) {
$sst = trim($_REQUEST['sst']);
$sst = preg_replace("/[\<\>\'\"\\\'\\\"\%\=\(\)\/\^\*\s]/", "", $sst);
if ($sst)
$qstr .= '&amp;sst=' . urlencode($sst); // search sort (검색 정렬 필드)
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$sst = '';
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
if (isset($_REQUEST['sod'])) { // search order (검색 오름, 내림차순)
$sod = preg_match("/^(asc|desc)$/i", $sod) ? $sod : '';
if ($sod)
$qstr .= '&amp;sod=' . urlencode($sod);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$sod = '';
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
if (isset($_REQUEST['sop'])) { // search operator (검색 or, and 오퍼레이터)
$sop = preg_match("/^(or|and)$/i", $sop) ? $sop : '';
if ($sop)
$qstr .= '&amp;sop=' . urlencode($sop);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$sop = '';
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
if (isset($_REQUEST['spt'])) { // search part (검색 파트[구간])
$spt = (int) $spt;
if ($spt)
$qstr .= '&amp;spt=' . urlencode($spt);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$spt = '';
2022-09-17 20:50:50 +09:00
}
if (isset($_REQUEST['page'])) { // 리스트 페이지
2024-09-19 20:36:07 +09:00
$page = (int) $_REQUEST['page'];
if ($page)
$qstr .= '&amp;page=' . urlencode($page);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$page = '';
2022-09-17 20:50:50 +09:00
}
if (isset($_REQUEST['w'])) {
2024-09-19 20:36:07 +09:00
$w = substr($w, 0, 2);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$w = '';
2022-09-17 20:50:50 +09:00
}
/** @var int $wr_id 게시판 글의 ID */
2022-09-17 20:50:50 +09:00
if (isset($_REQUEST['wr_id'])) {
2024-09-19 20:36:07 +09:00
$wr_id = (int) $_REQUEST['wr_id'];
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$wr_id = 0;
2022-09-17 20:50:50 +09:00
}
if (isset($_REQUEST['bo_table']) && !is_array($_REQUEST['bo_table'])) {
2024-09-19 20:36:07 +09:00
$bo_table = preg_replace('/[^a-z0-9_]/i', '', trim($_REQUEST['bo_table']));
$bo_table = substr($bo_table, 0, 20);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$bo_table = '';
2022-09-17 20:50:50 +09:00
}
// URL ENCODING
if (isset($_REQUEST['url'])) {
$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', trim($_REQUEST['url']));
2024-09-19 20:36:07 +09:00
$urlencode = urlencode($url);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$url = '';
$urlencode = urlencode($_SERVER['REQUEST_URI']);
2024-09-27 15:47:15 +09:00
if (defined("G5_DOMAIN")) {
$p = @parse_url(G5_DOMAIN ?? "");
$p['path'] = isset($p['path']) ? $p['path'] : '/';
2024-09-19 20:36:07 +09:00
$urlencode = G5_DOMAIN . urldecode(preg_replace("/^" . urlencode($p['path']) . "/", "", $urlencode));
}
2022-09-17 20:50:50 +09:00
}
if (isset($_REQUEST['gr_id'])) {
2024-09-19 20:36:07 +09:00
if (!is_array($_REQUEST['gr_id'])) {
$gr_id = preg_replace('/[^a-z0-9_]/i', '', trim($_REQUEST['gr_id']));
}
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$gr_id = '';
2022-09-17 20:50:50 +09:00
}
//===================================
// 자동로그인 부분에서 첫로그인에 포인트 부여하던것을 로그인중일때로 변경하면서 코드도 대폭 수정하였습니다.
if ($_SESSION['ss_mb_id']) { // 로그인중이라면
2024-09-19 20:36:07 +09:00
$member = get_member($_SESSION['ss_mb_id']);
// 차단된 회원이면 ss_mb_id 초기화
if ($member['mb_intercept_date'] && $member['mb_intercept_date'] <= date("Ymd", G5_SERVER_TIME)) {
set_session('ss_mb_id', '');
2024-09-23 09:37:13 +09:00
$member = [];
2024-09-19 20:36:07 +09:00
} else {
// 오늘 처음 로그인 이라면
if (substr($member['mb_today_login'], 0, 10) != G5_TIME_YMD) {
// 첫 로그인 포인트 지급
insert_point($member['mb_id'], $config['cf_login_point'], G5_TIME_YMD . ' 첫로그인', '@login', $member['mb_id'], G5_TIME_YMD);
// 오늘의 로그인이 될 수도 있으며 마지막 로그인일 수도 있음
// 해당 회원의 접근일시와 IP 를 저장
$sql = " update {$g5['member_table']} set mb_today_login = '" . G5_TIME_YMDHIS . "', mb_login_ip = '{$_SERVER['REMOTE_ADDR']}' where mb_id = '{$member['mb_id']}' ";
sql_query($sql);
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
}
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
// 자동로그인 ---------------------------------------
// 회원아이디가 쿠키에 저장되어 있다면 (3.27)
if ($tmp_mb_id = get_cookie('ck_mb_id')) {
$tmp_mb_id = substr(preg_replace("/[^a-zA-Z0-9_]*/", "", $tmp_mb_id), 0, 20);
// 최고관리자는 자동로그인 금지
if (strtolower($tmp_mb_id) != strtolower($config['cf_admin'])) {
$sql = " select mb_password, mb_intercept_date, mb_leave_date, mb_email_certify from {$g5['member_table']} where mb_id = '{$tmp_mb_id}' ";
$row = sql_fetch($sql);
$key = md5($_SERVER['SERVER_ADDR'] . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . $row['mb_password']);
// 쿠키에 저장된 키와 같다면
$tmp_key = get_cookie('ck_auto');
if ($tmp_key == $key && $tmp_key) {
// 차단, 탈퇴가 아니고 메일인증이 사용이면서 인증을 받았다면
if (
$row['mb_intercept_date'] == '' &&
$row['mb_leave_date'] == '' &&
(!$config['cf_use_email_certify'] || preg_match('/[1-9]/', $row['mb_email_certify']))
) {
// 세션에 회원아이디를 저장하여 로그인으로 간주
set_session('ss_mb_id', $tmp_mb_id);
// 페이지를 재실행
echo "<script type='text/javascript'> window.location.reload(); </script>";
exit;
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
}
// $row 배열변수 해제
unset($row);
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
}
// 자동로그인 end ---------------------------------------
2022-09-17 20:50:50 +09:00
}
2024-09-23 09:37:13 +09:00
$write = [];
2022-09-17 20:50:50 +09:00
$write_table = "";
if ($bo_table) {
2024-09-19 20:36:07 +09:00
$board = sql_fetch(" select * from {$g5['board_table']} where bo_table = '$bo_table' ");
if ($board['bo_table']) {
set_cookie("ck_bo_table", $board['bo_table'], 86400 * 1);
$gr_id = $board['gr_id'];
$write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
//$comment_table = $g5['write_prefix'] . $bo_table . $g5['comment_suffix']; // 코멘트 테이블 전체이름
if (isset($wr_id) && $wr_id)
$write = sql_fetch(" select * from {$write_table} where wr_id = '$wr_id' ");
}
2022-09-17 20:50:50 +09:00
}
if ($gr_id) {
2024-09-19 20:36:07 +09:00
$group = sql_fetch(" select * from {$g5['group_table']} where gr_id = '$gr_id' ");
2022-09-17 20:50:50 +09:00
}
// 회원, 비회원 구분
$is_member = $is_guest = false;
$is_admin = '';
if ($member['mb_id']) {
2024-09-19 20:36:07 +09:00
$is_member = true;
$is_admin = is_admin($member['mb_id']);
$member['mb_dir'] = substr($member['mb_id'], 0, 2);
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$is_guest = true;
$member['mb_id'] = '';
$member['mb_level'] = 1; // 비회원의 경우 회원레벨을 가장 낮게 설정
2022-09-17 20:50:50 +09:00
}
if ($is_admin != 'super') {
2024-09-28 13:03:15 +09:00
/*
// 접근가능 IP
$cf_possible_ip = trim($config['cf_possible_ip']);
if ($cf_possible_ip) {
$is_possible_ip = false;
$pattern = explode("\n", $cf_possible_ip);
for ($i=0; $i<count($pattern); $i++) {
$pattern[$i] = trim($pattern[$i]);
if (empty($pattern[$i]))
continue;
$pattern[$i] = str_replace(".", "\.", $pattern[$i]);
$pattern[$i] = str_replace("+", "[0-9\.]+", $pattern[$i]);
$pat = "/^{$pattern[$i]}$/";
$is_possible_ip = preg_match($pat, $_SERVER['REMOTE_ADDR']);
if ($is_possible_ip)
break;
}
if (!$is_possible_ip)
die ("접근이 가능하지 않습니다.");
}
2024-09-19 20:36:07 +09:00
*/
// 접근차단 IP
$is_intercept_ip = false;
$pattern = explode("\n", trim($config['cf_intercept_ip']));
for ($i = 0; $i < count($pattern); $i++) {
$pattern[$i] = trim($pattern[$i]);
if (empty($pattern[$i]))
continue;
$pattern[$i] = str_replace(".", "\.", $pattern[$i]);
$pattern[$i] = str_replace("+", "[0-9\.]+", $pattern[$i]);
$pat = "/^{$pattern[$i]}$/";
$is_intercept_ip = preg_match($pat, $_SERVER['REMOTE_ADDR']);
if ($is_intercept_ip)
die("접근 불가합니다.");
}
2022-09-17 20:50:50 +09:00
}
// 테마경로
2024-09-19 20:36:07 +09:00
if (defined('_THEME_PREVIEW_') && _THEME_PREVIEW_ === true)
$config['cf_theme'] = trim($_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);
2022-09-17 20:50:50 +09:00
}
// 테마 설정 로드
2024-09-19 20:36:07 +09:00
if (defined('G5_THEME_PATH') && is_file(G5_THEME_PATH . '/theme.config.php'))
include_once G5_THEME_PATH . '/theme.config.php';
2024-09-19 20:36:07 +09:00
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;
}
2022-09-17 20:50:50 +09:00
}
//==============================================================================
//==============================================================================
// Mobile 모바일 설정
// 쿠키에 저장된 값이 모바일이라면 브라우저 상관없이 모바일로 실행
// 그렇지 않다면 브라우저의 HTTP_USER_AGENT 에 따라 모바일 결정
// G5_MOBILE_AGENT : config.php 에서 선언
//------------------------------------------------------------------------------
if (G5_USE_MOBILE && $set_device) {
2024-09-19 20:36:07 +09:00
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;
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:36:07 +09:00
$set_device = false;
2022-09-17 20:50:50 +09:00
}
// php 에서 장치 구분은 amber 에서 추후 비권장으로 변경됩니다.
2022-09-17 20:50:50 +09:00
$_SESSION['ss_is_mobile'] = $is_mobile;
2022-09-17 20:50:50 +09:00
define('G5_IS_MOBILE', $is_mobile);
define('G5_DEVICE_BUTTON_DISPLAY', $set_device);
2022-09-17 20:50:50 +09:00
if (G5_IS_MOBILE) {
2024-09-19 20:36:07 +09:00
$g5['mobile_path'] = G5_PATH . '/' . $g5['mobile_dir'];
2022-09-17 20:50:50 +09:00
}
//==============================================================================
2024-09-19 20:36:07 +09:00
$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']);
2022-09-17 20:50:50 +09:00
//==============================================================================
// 방문자수의 접속을 남김
include_once G5_BBS_PATH . '/visit_insert.inc.php';
2022-09-17 20:50:50 +09:00
// 일정 기간이 지난 DB 데이터 삭제 및 최적화
include_once G5_BBS_PATH . '/db_table.optimize.php';
2022-09-17 20:50:50 +09:00
// common.php 파일을 수정할 필요가 없도록 확장합니다.
2024-09-23 09:37:13 +09:00
$extend_file = [];
2022-09-17 20:50:50 +09:00
$tmp = dir(G5_EXTEND_PATH);
while ($entry = $tmp->read()) {
2024-09-19 20:36:07 +09:00
// php 파일만 include 함
if (preg_match("/(\.php)$/i", $entry))
$extend_file[] = $entry;
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:36:07 +09:00
if (!empty($extend_file) && is_array($extend_file)) {
natsort($extend_file);
2022-09-17 20:50:50 +09:00
2024-09-19 20:36:07 +09:00
foreach ($extend_file as $file) {
include_once G5_EXTEND_PATH . '/' . $file;
2024-09-19 20:36:07 +09:00
}
2022-09-17 20:50:50 +09:00
}
unset($extend_file);
// ----- 테마 추가기능 불러오기 (확장)
2024-09-19 20:36:07 +09:00
if (defined('G5_THEME_PATH')) {
2024-09-23 09:37:13 +09:00
$extend_file = [];
2024-09-19 20:36:07 +09:00
$tmp = dir(G5_THEME_PATH . '/' . G5_EXTEND_DIR);
2024-09-19 20:36:07 +09:00
while ($entry = $tmp->read()) {
// php 파일만 include 함
if (preg_match("/(\.php)$/i", $entry))
$extend_file[] = $entry;
}
2024-09-19 20:36:07 +09:00
if (!empty($extend_file) && is_array($extend_file)) {
natsort($extend_file);
foreach ($extend_file as $file) {
include_once G5_THEME_PATH . '/' . G5_EXTEND_DIR . "/" . $file;
2024-09-19 20:36:07 +09:00
}
}
unset($extend_file);
2022-09-17 20:50:50 +09:00
}
ob_start();
$gmnow = gmdate('D, d M Y H:i:s') . ' GMT';
2024-09-19 21:03:48 +09:00
header('Content-Type: text/html; charset=utf-8');
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
2022-09-17 20:50:50 +09:00
2024-09-28 13:03:15 +09:00
EventHandler::triggerEvent("gnuboard.htmlprocess.before");
2022-09-17 20:50:50 +09:00
$html_process = new html_process();
2024-09-28 13:03:15 +09:00
EventHandler::triggerEvent("gnuboard.htmlprocess.after", $html_process);