ローカルルールの文字化けを修正

This commit is contained in:
konkon-fox 2023-10-16 17:56:20 +09:00
parent 39014c72d2
commit c661f2e0a3
4 changed files with 76 additions and 45 deletions

View File

@ -24,23 +24,34 @@ kokutifile = '/'+bbs+'/kokuti.txt';
}
}
}
if (document.getElementById('rule')) {
const lroad = new XMLHttpRequest();
lroad.open('get', rulefile);
lroad.send();
lroad.onreadystatechange = function() {
if(lroad.readyState === 4 && lroad.status === 200) {
document.getElementById('rule').innerHTML += this.responseText;
if (document.getElementById('rule')) {
getLocalHtml('rule', rulefile, true);
}
if (document.getElementById('kokuti')) {
getLocalHtml('kokuti', kokutifile, false);
}
async function getLocalHtml (targetId, targetFile, isShiftJIS) {
try{
const response = await fetch(targetFile, {cache: 'no-store'});
if(!response.ok) throw new Error();
if(isShiftJIS){
const arrayBuffer = await response.arrayBuffer();
const utf8Text = arrayBufferToUtf8(arrayBuffer);
document.getElementById(targetId).innerHTML += utf8Text;
}else{
const utf8Text = await response.text();
document.getElementById(targetId).innerHTML += utf8Text;
}
}catch(e){
console.error(e);
}
}
if (document.getElementById('kokuti')) {
const kroad = new XMLHttpRequest();
kroad.open('get', kokutifile);
kroad.send();
kroad.onreadystatechange = function() {
if(kroad.readyState === 4 && kroad.status === 200) {
document.getElementById('kokuti').innerHTML += this.responseText;
}
}
}
}
function arrayBufferToUtf8 (arrayBuffer) {
const textDecoder = new TextDecoder('sjis');
const rawUtf8Text = textDecoder.decode(arrayBuffer);
const utf8Text = rawUtf8Text.replace(/(\r\n|\r|\n)/g, '');
return utf8Text;
}

View File

@ -984,10 +984,13 @@ if (!$tlonly) {
}
file_put_contents($LTLFILE, json_encode($LTL, JSON_UNESCAPED_UNICODE), LOCK_EX);
$TTL = array_reverse($LTL);
$text = str_replace(array("\r\n","\r","\n"), '', file_get_contents($PATH."head.txt"));
$text2 = str_replace(array("\r\n","\r","\n"), '', file_get_contents($PATH."kokuti.txt"));
$fp = "ローカルルール<><>99/01/01 00:00:00 <>".$text."<>TL\n";
$fp .= "告知欄<><>99/01/01 00:00:00 <>".$text2."<>\n";
$headText = file_get_contents($PATH."head.txt");
$headText = mb_convert_encoding($headText, 'UTF-8', 'SJIS-win');
$headText = preg_replace('/(\r\n|\r|\n)/', '', $headText);
$kokutiText = file_get_contents($PATH."kokuti.txt");
$kokutiText = preg_replace('/(\r\n|\r|\n)/', '', $kokutiText);
$fp = "ローカルルール<><>99/01/01 00:00:00 <>".$headText."<>TL\n";
$fp .= "告知欄<><>99/01/01 00:00:00 <>".$kokutiText."<>\n";
foreach ($TTL as $tmp) {
if (isset($tmp['thread'])) $tt = "<br><hr>".$tmp["title"]."<br>http://".$_SERVER['HTTP_HOST']."/test/read.cgi/".$_POST['board']."/".$tmp['thread']."/";
else $tt = "";

View File

@ -75,26 +75,37 @@ kokutifile = '/'+bbs+'/kokuti.txt';
}
}
}
if (document.getElementById('rule')) {
const lroad = new XMLHttpRequest();
lroad.open('get', rulefile);
lroad.send();
lroad.onreadystatechange = function() {
if(lroad.readyState === 4 && lroad.status === 200) {
document.getElementById('rule').innerHTML += this.responseText;
getLocalHtml('rule', rulefile, true);
}
if (document.getElementById('kokuti')) {
getLocalHtml('kokuti', kokutifile, false);
}
async function getLocalHtml (targetId, targetFile, isShiftJIS) {
try{
const response = await fetch(targetFile, {cache: 'no-store'});
if(!response.ok) throw new Error();
if(isShiftJIS){
const arrayBuffer = await response.arrayBuffer();
const utf8Text = arrayBufferToUtf8(arrayBuffer);
document.getElementById(targetId).innerHTML += utf8Text;
}else{
const utf8Text = await response.text();
document.getElementById(targetId).innerHTML += utf8Text;
}
}catch(e){
console.error(e);
}
}
if (document.getElementById('kokuti')) {
const kroad = new XMLHttpRequest();
kroad.open('get', kokutifile);
kroad.send();
kroad.onreadystatechange = function() {
if(kroad.readyState === 4 && kroad.status === 200) {
document.getElementById('kokuti').innerHTML += this.responseText;
}
}
}
}
function arrayBufferToUtf8 (arrayBuffer) {
const textDecoder = new TextDecoder('sjis');
const rawUtf8Text = textDecoder.decode(arrayBuffer);
const utf8Text = rawUtf8Text.replace(/(\r\n|\r|\n)/g, '');
return utf8Text;
}
function l(e){
var N=getCookie("NAME"),M=getCookie("MAIL"),i;

View File

@ -1,10 +1,13 @@
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['edit'] == "yes") {
file_put_contents($PATH."head.txt", $_POST['head']);
file_put_contents($PATH."kokuti.txt", $_POST['head2']);
$newHeadText = mb_convert_encoding($_POST['head'], 'SJIS-win', 'UTF-8');
file_put_contents($PATH."head.txt", $newHeadText);
$newKokutiText = $_POST['head2'];
file_put_contents($PATH."kokuti.txt", $newKokutiText);
}
$text = implode('', file($PATH."head.txt"));
$text2 = implode('', file($PATH."kokuti.txt"));
$headText = file_get_contents($PATH."head.txt");
$headText = mb_convert_encoding($headText, 'UTF-8', 'SJIS-win');
$kokutiText = file_get_contents($PATH."kokuti.txt");
?>
<!DOCTYPE html>
<html lang="ja">
@ -22,10 +25,13 @@ $text2 = implode('', file($PATH."kokuti.txt"));
<input type="hidden" name="password" value="<?=$_REQUEST['password']?>">
<input type="hidden" name="edit" value="yes">
<div class="back"><a href="./admin.php"> 管理ページへ戻る</a></div>
<p>
htmlタグが利用可能です。
</p>
<div><b>ヘッダー</b></div>
<div><textarea style="font-size:9pt" rows="10" cols="70" name="head" wrap="OFF"><?=$text?></textarea></div>
<div><textarea style="font-size:9pt" rows="10" cols="70" name="head" wrap="OFF"><?=$headText?></textarea></div>
<div><b>告知欄</b></div>
<div><textarea style="font-size:9pt" rows="10" cols="70" name="head2" wrap="OFF"><?=$text2?></textarea></div>
<div><textarea style="font-size:9pt" rows="10" cols="70" name="head2" wrap="OFF"><?=$kokutiText?></textarea></div>
<hr><div class="contents"><input type="submit" name="Submit" class="btn btn-primary btn-block" value="適用"></div>
</form>
</div>