fix 8.3 redis error, htmlprocess add features

This commit is contained in:
Amberstone 2025-11-15 13:01:14 +09:00
parent 98b6c95c89
commit e976f3bc05
Signed by: amber
GPG key ID: 094B0E55F98D8BF1
5 changed files with 636 additions and 829 deletions

View file

@ -2,25 +2,82 @@
if (!defined('_GNUBOARD_'))
exit;
$font_sql = "SELECT * FROM {$g5['font_table']} ORDER BY font_name ASC";
$font_result = sql_query($font_sql);
function getFontCSSWithCache()
{
global $g5;
$cache_key = 'font_css_cache';
$cache_duration = 300;
echo "<style id=\"extra_font\">";
while ($row = sql_fetch_array($font_result)) {
$font_family = $row['font_family'];
$font_url = stripslashes($row['font_url']);
$font_weight = $row['font_weight'];
$font_style = $row['font_style'];
if (USE_REDIS && class_exists('Redis')) {
try {
$redis = new Redis();
$redis->connect('localhost', 6379);
if (strpos($font_url, '@import') !== false) {
echo "{$font_url}\n\n";
} else {
echo "@font-face {\n";
echo " font-family: '{$font_family}';\n";
echo " src: {$font_url};\n";
echo " font-weight: {$font_weight};\n";
echo " font-style: {$font_style};\n";
echo "}\n\n";
$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);
}
echo "</style>";
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_result = sql_query($font_sql);
$css_content = "<style id=\"extra_font\">";
while ($row = sql_fetch_array($font_result)) {
$font_family = $row['font_family'];
$font_url = stripslashes($row['font_url']);
$font_weight = $row['font_weight'];
$font_style = $row['font_style'];
if (strpos($font_url, '@import') !== false) {
$css_content .= "{$font_url}\n\n";
} else {
$css_content .= "@font-face {\n";
$css_content .= " font-family: '{$font_family}';\n";
$css_content .= " src: {$font_url};\n";
$css_content .= " font-weight: {$font_weight};\n";
$css_content .= " font-style: {$font_style};\n";
$css_content .= "}\n\n";
}
}
$css_content .= "</style>";
return $css_content;
}
echo getFontCSSWithCache();

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,9 @@ class html_process
protected $latecss = [];
protected $css = [];
protected $js = [];
protected $beforeBuffer = "";
protected $afterBuffer = "";
protected $replacer = [];
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()
{
global $config, $g5, $member;
global $config;
$this->updateLoginTable();
$this->cleanOldLoginRecords($config['cf_login_minutes']);
@ -203,6 +221,13 @@ class html_process
$buffer = $this->injectStyles($buffer, $stylesheet, $latestylesheet);
$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")) {
EventHandler::triggerEvent("amber.renderhtml_before_print", $buffer);
}

View file

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

View file

@ -2,6 +2,15 @@
/**
* @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');
}
/********************
상수 선언
********************/