Merge pull request 'ローカルルールの文字化けを修正、!addコマンドの文字数上限を追加' (#32) from konkon-fox/delightly-v2fork:main into main

Reviewed-on: #32
This commit is contained in:
統計部員2 2023-10-20 17:38:20 +09:00
commit cc3d29bac6
5 changed files with 93 additions and 50 deletions

View File

@ -24,23 +24,35 @@ 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('response 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);
document.getElementById(targetId).innerHTML += 'ファイルの取得に失敗しました。';
}
}
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

@ -84,7 +84,7 @@ function escapePostData(&$postData, $keepNewLine){
$postData = preg_replace('/&#[xX]0*[aAdD];/', ' ', $postData);
// 改行コードをエスケープ ※本文のみ<br>に変換
$newLineChar = $keepNewLine ? '<br>' : ' ';
$postData = preg_replace('/(\r\n|\r|\n)/', $newLineChar, $postData);
$postData = str_replace(array("\r\n","\r","\n"), $newLineChar, $postData);
// trim
$postData = trim($postData);
}
@ -325,7 +325,7 @@ if (!$newthread && !$tlonly && $reload) {
$fp = '';
foreach($LOG as $tmp) $fp .= $tmp;
file_put_contents($THREADFILE, $fp, LOCK_EX);
$shiftJisDat = mb_convert_encoding(implode($LOG,''), "SJIS-win", "UTF-8");
$shiftJisDat = mb_convert_encoding(implode('', $LOG), "SJIS-win", "UTF-8");
file_put_contents($DATFILE, $shiftJisDat, LOCK_EX);
}
@ -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 = str_replace(array("\r\n","\r","\n"), '', $headText);
$kokutiText = file_get_contents($PATH."kokuti.txt");
$kokutiText = str_replace(array("\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,38 @@ 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('response 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);
document.getElementById(targetId).innerHTML += 'ファイルの取得に失敗しました。';
}
}
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

@ -48,9 +48,18 @@ if ($supervisor || $admin) {
if (strpos($_POST['comment'], "!") !== false) $reload = true;
if (strpos($_POST['comment'], '!stop') !== false) $stop = true;
// 追記
if (preg_match("/\!add(.*)/", $_POST['comment'], $match) && $number != 1) {
$message .="<br><font class=\"add\" color=\"red\">※追記 {$DATE}</font>{$match[1]}";
}
if (preg_match("/\!add(.*)/", $_POST['comment'], $addMatches) && $number != 1) {
$commentMax = $authorized ? $SETTING['BBS_MESSAGE_COUNT'] * 3 : $SETTING['BBS_MESSAGE_COUNT'];
$addComment = $addMatches[1];
if(mb_strlen($message, 'UTF-8') + mb_strlen($addComment, 'UTF-8') > $commentMax){
if(strpos($_POST['comment'], '<hr>') === false) $_POST['comment'] .= '<hr>';
$_POST['comment'] .= '★追記できる文字数を超えています。<br>';
}else{
$messageParts = explode('<hr>', $message);
$messageParts[0] .="<br><font class=\"add\" color=\"red\">※追記 {$DATE}</font>{$addComment}";
$message = implode('<hr>', $messageParts);
}
}
// 部分削除
if (preg_match_all("/!saku:(.*?)(\s| |<br>)/", $_POST['comment'], $sakus, PREG_SET_ORDER)) {
foreach ($sakus as $sakujyo) {

View File

@ -1,10 +1,14 @@
<?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']);
mb_substitute_character('entity');
$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 +26,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>