move html_process

This commit is contained in:
Amberstone 2024-10-02 09:08:18 +09:00
parent 795ce82b35
commit da84fbbad1
Signed by: amber
GPG key ID: 094B0E55F98D8BF1
2 changed files with 117 additions and 140 deletions

View file

@ -0,0 +1,117 @@
<?php
class html_process
{
protected $css = [];
protected $js = [];
function merge_stylesheet($stylesheet, $order)
{
$links = $this->css;
$is_merge = true;
foreach ($links as $link) {
if ($link[1] == $stylesheet) {
$is_merge = false;
break;
}
}
if ($is_merge)
$this->css[] = [$order, $stylesheet];
}
function merge_javascript($javascript, $order)
{
$scripts = $this->js;
$is_merge = true;
foreach ($scripts as $script) {
if ($script[1] == $javascript) {
$is_merge = false;
break;
}
}
if ($is_merge)
$this->js[] = [$order, $javascript];
}
function run()
{
global $config, $g5, $member;
$tmp_sql = "SELECT count(*) as cnt FROM {$g5['login_table']} where lo_ip = '{$_SERVER['REMOTE_ADDR']}' ";
$tmp_row = sql_fetch($tmp_sql);
if ($tmp_row['cnt']) {
$tmp_sql = "UPDATE {$g5['login_table']} SET mb_id = '{$member['mb_id']}', lo_datetime = '" . G5_TIME_YMDHIS . "', lo_location = '{$g5['lo_location']}', lo_url = '{$g5['lo_url']}' where lo_ip = '{$_SERVER['REMOTE_ADDR']}' ";
sql_query($tmp_sql, FALSE);
} else {
$tmp_sql = "INSERT INTO {$g5['login_table']} ( lo_ip, mb_id, lo_datetime, lo_location, lo_url ) values ( '{$_SERVER['REMOTE_ADDR']}', '{$member['mb_id']}', '" . G5_TIME_YMDHIS . "', '{$g5['lo_location']}', '{$g5['lo_url']}' ) ";
sql_query($tmp_sql, FALSE);
sql_query(" delete from {$g5['login_table']} where lo_datetime < '" . date("Y-m-d H:i:s", G5_SERVER_TIME - (60 * $config['cf_login_minutes'])) . "' ");
// 부담(overhead)이 있다면 테이블 최적화
//$row = sql_fetch(" SHOW TABLE STATUS FROM `$mysql_db` LIKE '$g5['login_table']' ");
//if ($row['Data_free'] > 0) sql_query(" OPTIMIZE TABLE $g5['login_table'] ");
}
$buffer = ob_get_contents();
ob_end_clean();
$stylesheet = '';
$links = $this->css;
if (!empty($links)) {
foreach ($links as $key => $row) {
$order[$key] = $row[0];
$index[$key] = $key;
$style[$key] = $row[1];
}
array_multisort($order, SORT_ASC, $index, SORT_ASC, $links);
foreach ($links as $link) {
if (!trim($link[1]))
continue;
$link[1] = preg_replace('#\.css([\'\"]?>)$#i', '.css?ver=' . G5_CSS_VER . '$1', $link[1]);
$stylesheet .= PHP_EOL . $link[1];
}
}
$javascript = '';
$scripts = $this->js;
$php_eol = '';
unset($order);
unset($index);
if (!empty($scripts)) {
foreach ($scripts as $key => $row) {
$order[$key] = $row[0];
$index[$key] = $key;
$script[$key] = $row[1];
}
array_multisort($order, SORT_ASC, $index, SORT_ASC, $scripts);
foreach ($scripts as $js) {
if (!trim($js[1]))
continue;
$js[1] = preg_replace('#\.js([\'\"]?>)$#i', '.js?ver=' . G5_JS_VER . '$1', $js[1]);
$javascript .= $php_eol . $js[1];
$php_eol = PHP_EOL;
}
}
$buffer = preg_replace('#(</title>[^<]*<link[^>]+>)#', "$1$stylesheet", $buffer);
$nl = '';
if ($javascript)
$nl = "\n";
$buffer = preg_replace('#(</head>[^<]*<body[^>]*>)#', "$javascript{$nl}$1", $buffer);
return $buffer;
}
}

View file

@ -2508,19 +2508,16 @@ if (!function_exists('file_put_contents')) {
} }
} }
// HTML 마지막 처리 // HTML 마지막 처리
function html_end() function html_end()
{ {
global $html_process; global $html_process;
return $html_process->run(); return $html_process->run();
} }
function add_stylesheet($stylesheet, $order = 0) function add_stylesheet($stylesheet, $order = 0)
{ {
global $html_process; global $html_process;
if (trim($stylesheet)) if (trim($stylesheet))
$html_process->merge_stylesheet($stylesheet, $order); $html_process->merge_stylesheet($stylesheet, $order);
} }
@ -2528,145 +2525,10 @@ function add_stylesheet($stylesheet, $order = 0)
function add_javascript($javascript, $order = 0) function add_javascript($javascript, $order = 0)
{ {
global $html_process; global $html_process;
if (trim($javascript)) if (trim($javascript))
$html_process->merge_javascript($javascript, $order); $html_process->merge_javascript($javascript, $order);
} }
class html_process
{
protected $css = [];
protected $js = [];
function merge_stylesheet($stylesheet, $order)
{
$links = $this->css;
$is_merge = true;
foreach ($links as $link) {
if ($link[1] == $stylesheet) {
$is_merge = false;
break;
}
}
if ($is_merge)
$this->css[] = array($order, $stylesheet);
}
function merge_javascript($javascript, $order)
{
$scripts = $this->js;
$is_merge = true;
foreach ($scripts as $script) {
if ($script[1] == $javascript) {
$is_merge = false;
break;
}
}
if ($is_merge)
$this->js[] = array($order, $javascript);
}
function run()
{
global $config, $g5, $member;
// 현재접속자 처리
$tmp_sql = "SELECT count(*) as cnt FROM {$g5['login_table']} where lo_ip = '{$_SERVER['REMOTE_ADDR']}' ";
$tmp_row = sql_fetch($tmp_sql);
if ($tmp_row['cnt']) {
$tmp_sql = "UPDATE {$g5['login_table']} SET mb_id = '{$member['mb_id']}', lo_datetime = '" . G5_TIME_YMDHIS . "', lo_location = '{$g5['lo_location']}', lo_url = '{$g5['lo_url']}' where lo_ip = '{$_SERVER['REMOTE_ADDR']}' ";
sql_query($tmp_sql, FALSE);
} else {
$tmp_sql = "INSERT INTO {$g5['login_table']} ( lo_ip, mb_id, lo_datetime, lo_location, lo_url ) values ( '{$_SERVER['REMOTE_ADDR']}', '{$member['mb_id']}', '" . G5_TIME_YMDHIS . "', '{$g5['lo_location']}', '{$g5['lo_url']}' ) ";
sql_query($tmp_sql, FALSE);
// 시간이 지난 접속은 삭제한다
sql_query(" delete from {$g5['login_table']} where lo_datetime < '" . date("Y-m-d H:i:s", G5_SERVER_TIME - (60 * $config['cf_login_minutes'])) . "' ");
// 부담(overhead)이 있다면 테이블 최적화
//$row = sql_fetch(" SHOW TABLE STATUS FROM `$mysql_db` LIKE '$g5['login_table']' ");
//if ($row['Data_free'] > 0) sql_query(" OPTIMIZE TABLE $g5['login_table'] ");
}
$buffer = ob_get_contents();
ob_end_clean();
$stylesheet = '';
$links = $this->css;
if (!empty($links)) {
foreach ($links as $key => $row) {
$order[$key] = $row[0];
$index[$key] = $key;
$style[$key] = $row[1];
}
array_multisort($order, SORT_ASC, $index, SORT_ASC, $links);
foreach ($links as $link) {
if (!trim($link[1]))
continue;
$link[1] = preg_replace('#\.css([\'\"]?>)$#i', '.css?ver=' . G5_CSS_VER . '$1', $link[1]);
$stylesheet .= PHP_EOL . $link[1];
}
}
$javascript = '';
$scripts = $this->js;
$php_eol = '';
unset($order);
unset($index);
if (!empty($scripts)) {
foreach ($scripts as $key => $row) {
$order[$key] = $row[0];
$index[$key] = $key;
$script[$key] = $row[1];
}
array_multisort($order, SORT_ASC, $index, SORT_ASC, $scripts);
foreach ($scripts as $js) {
if (!trim($js[1]))
continue;
$js[1] = preg_replace('#\.js([\'\"]?>)$#i', '.js?ver=' . G5_JS_VER . '$1', $js[1]);
$javascript .= $php_eol . $js[1];
$php_eol = PHP_EOL;
}
}
/*
</title>
<link rel="stylesheet" href="default.css">
밑으로 스킨의 스타일시트가 위치하도록 하게 한다.
*/
$buffer = preg_replace('#(</title>[^<]*<link[^>]+>)#', "$1$stylesheet", $buffer);
/*
</head>
<body>
전에 스킨의 자바스크립트가 위치하도록 하게 한다.
*/
$nl = '';
if ($javascript)
$nl = "\n";
$buffer = preg_replace('#(</head>[^<]*<body[^>]*>)#', "$javascript{$nl}$1", $buffer);
return $buffer;
}
}
// 휴대폰번호의 숫자만 취한 후 중간에 하이픈(-)을 넣는다. // 휴대폰번호의 숫자만 취한 후 중간에 하이픈(-)을 넣는다.
function hyphen_hp_number($hp) function hyphen_hp_number($hp)
{ {
@ -2674,7 +2536,6 @@ function hyphen_hp_number($hp)
return preg_replace("/([0-9]{3})([0-9]{3,4})([0-9]{4})$/", "\\1-\\2-\\3", $hp); return preg_replace("/([0-9]{3})([0-9]{3,4})([0-9]{4})$/", "\\1-\\2-\\3", $hp);
} }
// 로그인 후 이동할 URL // 로그인 후 이동할 URL
function login_url($url = '') function login_url($url = '')
{ {
@ -2684,7 +2545,6 @@ function login_url($url = '')
return urlencode(clean_xss_tags(urldecode($url))); return urlencode(clean_xss_tags(urldecode($url)));
} }
// $dir 을 포함하여 https 또는 http 주소를 반환한다. // $dir 을 포함하여 https 또는 http 주소를 반환한다.
function https_url($dir, $https = true) function https_url($dir, $https = true)
{ {