AvocadoAmber/AvocadoEdition_Light/classes/htmlprocess/htmlprocess.class.php

122 lines
3.3 KiB
PHP

<?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);
if (class_exists("EventHandler")) {
EventHandler::triggerEvent("amber.renderhtml_before_print", $buffer);
}
return $buffer;
}
}