fix 8.3 redis error, htmlprocess add features

This commit is contained in:
Amberstone 2025-11-15 14:27:06 +09:00
parent 98b6c95c89
commit adf8c56665
Signed by: amber
GPG key ID: 094B0E55F98D8BF1
5 changed files with 127 additions and 47 deletions

View file

@ -2,10 +2,62 @@
if (!defined('_GNUBOARD_')) if (!defined('_GNUBOARD_'))
exit; exit;
function getFontCSSWithCache()
{
global $g5;
$cache_key = 'font_css_cache';
$cache_duration = 300;
if (USE_REDIS && class_exists('Redis')) {
try {
$redis = new Redis();
$redis->connect('localhost', 6379);
$cached_css = $redis->get($cache_key);
if ($cached_css !== false) {
$redis->close();
return $cached_css;
}
$css_content = generateFontCSS($g5);
$redis->setex($cache_key, $cache_duration, $css_content);
$redis->close();
return $css_content;
} catch (Exception $e) {
error_log("Redis 연결 실패: " . $e->getMessage());
}
}
return getFontCSSWithFileCache($g5, $cache_duration);
}
function getFontCSSWithFileCache($g5, $cache_duration)
{
$cache_file = G5_DATA_PATH . '/cache/font_css_cache.txt';
$cache_dir = dirname($cache_file);
if (!is_dir($cache_dir)) {
@mkdir($cache_dir, 0755, true);
}
if (file_exists($cache_file) && (time() - filemtime($cache_file)) < $cache_duration) {
return file_get_contents($cache_file);
}
$css_content = generateFontCSS($g5);
@file_put_contents($cache_file, $css_content, LOCK_EX);
return $css_content;
}
function generateFontCSS($g5)
{
$font_sql = "SELECT * FROM {$g5['font_table']} ORDER BY font_name ASC"; $font_sql = "SELECT * FROM {$g5['font_table']} ORDER BY font_name ASC";
$font_result = sql_query($font_sql); $font_result = sql_query($font_sql);
$css_content = "<style id=\"extra_font\">";
echo "<style id=\"extra_font\">";
while ($row = sql_fetch_array($font_result)) { while ($row = sql_fetch_array($font_result)) {
$font_family = $row['font_family']; $font_family = $row['font_family'];
$font_url = stripslashes($row['font_url']); $font_url = stripslashes($row['font_url']);
@ -13,14 +65,19 @@ while ($row = sql_fetch_array($font_result)) {
$font_style = $row['font_style']; $font_style = $row['font_style'];
if (strpos($font_url, '@import') !== false) { if (strpos($font_url, '@import') !== false) {
echo "{$font_url}\n\n"; $css_content .= "{$font_url}\n\n";
} else { } else {
echo "@font-face {\n"; $css_content .= "@font-face {\n";
echo " font-family: '{$font_family}';\n"; $css_content .= " font-family: '{$font_family}';\n";
echo " src: {$font_url};\n"; $css_content .= " src: {$font_url};\n";
echo " font-weight: {$font_weight};\n"; $css_content .= " font-weight: {$font_weight};\n";
echo " font-style: {$font_style};\n"; $css_content .= " font-style: {$font_style};\n";
echo "}\n\n"; $css_content .= "}\n\n";
} }
} }
echo "</style>";
$css_content .= "</style>";
return $css_content;
}
echo getFontCSSWithCache();

View file

@ -6,30 +6,12 @@ $css_sql = sql_query("SELECT * FROM {$g5['css_table']}");
$css = []; $css = [];
for ($i = 0; $cs = sql_fetch_array($css_sql); $i++) { for ($i = 0; $cs = sql_fetch_array($css_sql); $i++) {
$css[$cs['cs_name']][0] = $cs['cs_value']; $css[$cs['cs_name']][0] = $cs['cs_value'];
$css[$cs['cs_name']][1] = $cs['cs_etc_1']; for ($j = 1; $j <= 20; $j++) {
$css[$cs['cs_name']][2] = $cs['cs_etc_2']; $css[$cs['cs_name']][$j] = $cs["cs_etc_$j"];
$css[$cs['cs_name']][3] = $cs['cs_etc_3']; }
$css[$cs['cs_name']][4] = $cs['cs_etc_4'];
$css[$cs['cs_name']][5] = $cs['cs_etc_5'];
$css[$cs['cs_name']][6] = $cs['cs_etc_6'];
$css[$cs['cs_name']][7] = $cs['cs_etc_7'];
$css[$cs['cs_name']][8] = $cs['cs_etc_8'];
$css[$cs['cs_name']][9] = $cs['cs_etc_9'];
$css[$cs['cs_name']][10] = $cs['cs_etc_10'];
$css[$cs['cs_name']][11] = $cs['cs_etc_11'];
$css[$cs['cs_name']][12] = $cs['cs_etc_12'];
$css[$cs['cs_name']][13] = $cs['cs_etc_13'];
$css[$cs['cs_name']][14] = $cs['cs_etc_14'];
$css[$cs['cs_name']][15] = $cs['cs_etc_15'];
$css[$cs['cs_name']][16] = $cs['cs_etc_16'];
$css[$cs['cs_name']][17] = $cs['cs_etc_17'];
$css[$cs['cs_name']][18] = $cs['cs_etc_18'];
$css[$cs['cs_name']][19] = $cs['cs_etc_19'];
$css[$cs['cs_name']][20] = $cs['cs_etc_20'];
} }
$tab_width = 1024;
$tab_width = 1024;
$is_item_area = false; $is_item_area = false;
$is_comment_area = false; $is_comment_area = false;

View file

@ -4,6 +4,9 @@ class html_process
protected $latecss = []; protected $latecss = [];
protected $css = []; protected $css = [];
protected $js = []; protected $js = [];
protected $beforeBuffer = "";
protected $afterBuffer = "";
protected $replacer = [];
private function updateLoginTable() private function updateLoginTable()
{ {
@ -188,9 +191,24 @@ class html_process
}*/ }*/
} }
public function appendHtml($html)
{
$this->afterBuffer .= $html;
}
public function prependHtml($html)
{
$this->beforeBuffer .= $html;
}
public function addRegexReplace($pattern, $replace)
{
$this->replacer[] = [$pattern, $replace];
}
public function run() public function run()
{ {
global $config, $g5, $member; global $config;
$this->updateLoginTable(); $this->updateLoginTable();
$this->cleanOldLoginRecords($config['cf_login_minutes']); $this->cleanOldLoginRecords($config['cf_login_minutes']);
@ -203,6 +221,13 @@ class html_process
$buffer = $this->injectStyles($buffer, $stylesheet, $latestylesheet); $buffer = $this->injectStyles($buffer, $stylesheet, $latestylesheet);
$buffer = $this->injectJavascript($buffer, $javascript); $buffer = $this->injectJavascript($buffer, $javascript);
foreach($this->replacer as $v) {
$buffer = preg_replace($v[0], $v[1], $buffer);
}
$buffer = preg_replace('#(</head>[^<]*<body[^>]*>)#', "$1{$this->beforeBuffer}", $buffer);
$buffer = preg_replace('#</(?:\s+)?body>#', "</body>" . $this->afterBuffer, $buffer);
if (class_exists("EventHandler")) { if (class_exists("EventHandler")) {
EventHandler::triggerEvent("amber.renderhtml_before_print", $buffer); EventHandler::triggerEvent("amber.renderhtml_before_print", $buffer);
} }

View file

@ -1,4 +1,8 @@
<?php <?php
/**
* @suppress PHP0419
* @suppress PHP6405
*/
/******************************************************************************* /*******************************************************************************
** 공통 변수, 상수, 코드 ** 공통 변수, 상수, 코드
*******************************************************************************/ *******************************************************************************/
@ -487,12 +491,15 @@ if (!defined('G5_IS_ADMIN')) {
@ini_set("session.use_trans_sid", 0); // PHPSESSID를 자동으로 넘기지 않음 @ini_set("session.use_trans_sid", 0); // PHPSESSID를 자동으로 넘기지 않음
@ini_set("url_rewriter.tags", ""); // 링크에 PHPSESSID가 따라다니는것을 무력화함 (해뜰녘님께서 알려주셨습니다.) @ini_set("url_rewriter.tags", ""); // 링크에 PHPSESSID가 따라다니는것을 무력화함 (해뜰녘님께서 알려주셨습니다.)
if (USE_REDIS && extension_loaded('redis')) {
ini_set('session.save_path', 'tcp://localhost:6379');
} else {
session_save_path(G5_SESSION_PATH); session_save_path(G5_SESSION_PATH);
if (isset($SESSION_CACHE_LIMITER)) if (isset($SESSION_CACHE_LIMITER))
@session_cache_limiter($SESSION_CACHE_LIMITER); @session_cache_limiter($SESSION_CACHE_LIMITER);
else else
@session_cache_limiter("no-cache, must-revalidate"); @session_cache_limiter("no-cache, must-revalidate");
}
ini_set("session.cache_expire", 180); // 세션 캐쉬 보관시간 (분) ini_set("session.cache_expire", 180); // 세션 캐쉬 보관시간 (분)
ini_set("session.gc_maxlifetime", 10800); // session data의 garbage collection 존재 기간을 지정 (초) ini_set("session.gc_maxlifetime", 10800); // session data의 garbage collection 존재 기간을 지정 (초)

View file

@ -2,6 +2,15 @@
/** /**
* @suppress PHP0419 * @suppress PHP0419
*/ */
// if you want use redis-session, enable it (change to true)
define('USE_REDIS', false);
if (USE_REDIS) {
ini_set('session.save_handler', 'redis');
} else {
ini_set('session.save_handler', 'files');
}
/******************** /********************
상수 선언 상수 선언
********************/ ********************/