fix 8.3 redis error, htmlprocess add features
This commit is contained in:
parent
98b6c95c89
commit
e976f3bc05
5 changed files with 636 additions and 829 deletions
|
|
@ -2,25 +2,82 @@
|
||||||
if (!defined('_GNUBOARD_'))
|
if (!defined('_GNUBOARD_'))
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
$font_sql = "SELECT * FROM {$g5['font_table']} ORDER BY font_name ASC";
|
function getFontCSSWithCache()
|
||||||
$font_result = sql_query($font_sql);
|
{
|
||||||
|
global $g5;
|
||||||
|
$cache_key = 'font_css_cache';
|
||||||
|
$cache_duration = 300;
|
||||||
|
|
||||||
echo "<style id=\"extra_font\">";
|
if (USE_REDIS && class_exists('Redis')) {
|
||||||
while ($row = sql_fetch_array($font_result)) {
|
try {
|
||||||
$font_family = $row['font_family'];
|
$redis = new Redis();
|
||||||
$font_url = stripslashes($row['font_url']);
|
$redis->connect('localhost', 6379);
|
||||||
$font_weight = $row['font_weight'];
|
|
||||||
$font_style = $row['font_style'];
|
|
||||||
|
|
||||||
if (strpos($font_url, '@import') !== false) {
|
$cached_css = $redis->get($cache_key);
|
||||||
echo "{$font_url}\n\n";
|
if ($cached_css !== false) {
|
||||||
} else {
|
$redis->close();
|
||||||
echo "@font-face {\n";
|
return $cached_css;
|
||||||
echo " font-family: '{$font_family}';\n";
|
}
|
||||||
echo " src: {$font_url};\n";
|
|
||||||
echo " font-weight: {$font_weight};\n";
|
$css_content = generateFontCSS($g5);
|
||||||
echo " font-style: {$font_style};\n";
|
$redis->setex($cache_key, $cache_duration, $css_content);
|
||||||
echo "}\n\n";
|
$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
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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가 따라다니는것을 무력화함 (해뜰녘님께서 알려주셨습니다.)
|
||||||
|
|
||||||
session_save_path(G5_SESSION_PATH);
|
if (USE_REDIS && extension_loaded('redis')) {
|
||||||
|
ini_set('session.save_path', 'tcp://localhost:6379');
|
||||||
if (isset($SESSION_CACHE_LIMITER))
|
} else {
|
||||||
@session_cache_limiter($SESSION_CACHE_LIMITER);
|
session_save_path(G5_SESSION_PATH);
|
||||||
else
|
if (isset($SESSION_CACHE_LIMITER))
|
||||||
@session_cache_limiter("no-cache, must-revalidate");
|
@session_cache_limiter($SESSION_CACHE_LIMITER);
|
||||||
|
else
|
||||||
|
@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 존재 기간을 지정 (초)
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
|
}
|
||||||
|
|
||||||
/********************
|
/********************
|
||||||
상수 선언
|
상수 선언
|
||||||
********************/
|
********************/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue