mirror of
https://github.com/Daichimarukana/uwuzu.git
synced 2026-06-04 19:14:41 +00:00
458 lines
14 KiB
PHP
458 lines
14 KiB
PHP
<?php
|
|
|
|
$serversettings_file = "../server/serversettings.ini";
|
|
$serversettings = parse_ini_file($serversettings_file, true);
|
|
|
|
function createUniqId(){
|
|
list($msec, $sec) = explode(" ", microtime());
|
|
$hashCreateTime = $sec.floor($msec*1000000);
|
|
|
|
$hashCreateTime = strrev($hashCreateTime);
|
|
|
|
return base_convert($hashCreateTime,10,36);
|
|
}
|
|
|
|
require('../db.php');
|
|
//関数呼び出し
|
|
//- EXIF
|
|
require('../function/function.php');
|
|
|
|
// 変数の初期化
|
|
$datetime = array();
|
|
$user_name = null;
|
|
$message = array();
|
|
$message_data = null;
|
|
$error_message = array();
|
|
$pdo = null;
|
|
$stmt = null;
|
|
$res = null;
|
|
$option = null;
|
|
|
|
session_name('uwuzu_s_id');
|
|
session_set_cookie_params(0, '', '', true, true);
|
|
session_start();
|
|
session_regenerate_id(true);
|
|
|
|
try {
|
|
|
|
$option = array(
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::MYSQL_ATTR_MULTI_STATEMENTS => false
|
|
);
|
|
$pdo = new PDO('mysql:charset=UTF8;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option);
|
|
|
|
} catch(PDOException $e) {
|
|
|
|
// 接続エラーのときエラー内容を取得する
|
|
$error_message[] = $e->getMessage();
|
|
}
|
|
|
|
if(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] == true) {
|
|
|
|
$passQuery = $pdo->prepare("SELECT username,userid,loginid,follow,admin,role,sacinfo,blocklist FROM account WHERE userid = :userid");
|
|
$passQuery->bindValue(':userid', htmlentities($_SESSION['userid']));
|
|
$passQuery->execute();
|
|
$res = $passQuery->fetch();
|
|
if(empty($res["userid"])){
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}elseif($_SESSION['loginid'] === $res["loginid"] && $_SESSION['userid'] == $res["userid"]){
|
|
// セッションに値をセット
|
|
$userid = htmlentities($res['userid']); // セッションに格納されている値をそのままセット
|
|
$username = htmlentities($res['username']); // セッションに格納されている値をそのままセット
|
|
$loginid = htmlentities($res["loginid"]);
|
|
$role = htmlentities($res["role"]);
|
|
$sacinfo = htmlentities($res["sacinfo"]);
|
|
$myblocklist = htmlentities($res["blocklist"]);
|
|
$myfollowlist = htmlentities($res["follow"]);
|
|
$_SESSION['admin_login'] = true;
|
|
$_SESSION['userid'] = $userid;
|
|
$_SESSION['username'] = $username;
|
|
$_SESSION['loginid'] = $res["loginid"];
|
|
setcookie('userid', $userid, [
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
setcookie('username', $username,[
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
setcookie('loginid', $res["loginid"],[
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
setcookie('admin_login', true,[
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
}else{
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}
|
|
|
|
|
|
} elseif (isset($_COOKIE['admin_login']) && $_COOKIE['admin_login'] == true) {
|
|
|
|
$passQuery = $pdo->prepare("SELECT username,userid,loginid,follow,admin,role,sacinfo,blocklist FROM account WHERE userid = :userid");
|
|
$passQuery->bindValue(':userid', htmlentities($_COOKIE['userid']));
|
|
$passQuery->execute();
|
|
$res = $passQuery->fetch();
|
|
if(empty($res["userid"])){
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}elseif($_COOKIE['loginid'] === $res["loginid"] && $_COOKIE['userid'] == $res["userid"]){
|
|
// セッションに値をセット
|
|
$userid = htmlentities($res['userid']); // クッキーから取得した値をセット
|
|
$username = htmlentities($res['username']); // クッキーから取得した値をセット
|
|
$loginid = htmlentities($res["loginid"]);
|
|
$role = htmlentities($res["role"]);
|
|
$sacinfo = htmlentities($res["sacinfo"]);
|
|
$myblocklist = htmlentities($res["blocklist"]);
|
|
$myfollowlist = htmlentities($res["follow"]);
|
|
$_SESSION['admin_login'] = true;
|
|
$_SESSION['userid'] = $userid;
|
|
$_SESSION['username'] = $username;
|
|
$_SESSION['loginid'] = $res["loginid"];
|
|
setcookie('userid', $userid,[
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
setcookie('username', $username,[
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
setcookie('loginid', $res["loginid"],[
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
setcookie('admin_login', true,[
|
|
'expires' => time() + 60 * 60 * 24 * 14,
|
|
'path' => '/',
|
|
'samesite' => 'lax',
|
|
'secure' => true,
|
|
'httponly' => true,
|
|
]);
|
|
}else{
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}
|
|
|
|
|
|
} else {
|
|
// ログインが許可されていない場合、ログインページにリダイレクト
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}
|
|
if(empty($userid)){
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}
|
|
if(empty($username)){
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}
|
|
|
|
if(!($res["admin"] === "yes")){
|
|
header("Location: ../login.php");
|
|
exit;
|
|
}
|
|
$notiQuery = $pdo->prepare("SELECT COUNT(*) as notification_count FROM notification WHERE touserid = :userid AND userchk = 'none'");
|
|
$notiQuery->bindValue(':userid', $userid);
|
|
$notiQuery->execute();
|
|
$notiData = $notiQuery->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$notificationcount = $notiData['notification_count'];
|
|
|
|
if( !empty($pdo) ) {
|
|
|
|
// データベース接続の設定
|
|
$dbh = new PDO('mysql:charset=UTF8;dbname='.DB_NAME.';host='.DB_HOST, DB_USER, DB_PASS, array(
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
|
));
|
|
|
|
$userQuery = $dbh->prepare("SELECT username, userid, profile, role FROM account WHERE userid = :userid");
|
|
$userQuery->bindValue(':userid', $userid);
|
|
$userQuery->execute();
|
|
$userData = $userQuery->fetch();
|
|
|
|
$role = $userData["role"];
|
|
|
|
$dbh = new PDO('mysql:charset=UTF8;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option);
|
|
|
|
$rerole = $dbh->prepare("SELECT username, userid, password, mailadds, profile, iconname, headname, role, datetime FROM account WHERE userid = :userid");
|
|
|
|
$rerole->bindValue(':userid', $userid);
|
|
// SQL実行
|
|
$rerole->execute();
|
|
|
|
$userdata = $rerole->fetch(); // ここでデータベースから取得した値を $role に代入する
|
|
|
|
|
|
}
|
|
|
|
if( !empty($_POST['btn_submit']) ) {
|
|
$emojiname = $_POST['emojiname'];
|
|
$emojiinfo = $_POST['emojiinfo'];
|
|
|
|
if (!empty($_FILES['image']['name'])) {
|
|
// アップロードされたファイル情報
|
|
$uploadedFile = $_FILES['image'];
|
|
|
|
if(check_mime($uploadedFile['tmp_name'])){
|
|
// アップロードされたファイルの拡張子を取得
|
|
$extension = pathinfo($uploadedFile['name'], PATHINFO_EXTENSION);
|
|
|
|
// 新しいファイル名を生成(uniqid + 拡張子)
|
|
$newFilename = uniqid() . '.' . $extension;
|
|
|
|
// 保存先のパスを生成
|
|
$uploadedPath = 'emojiimage/' . $newFilename;
|
|
|
|
// EXIF削除
|
|
delete_exif($extension2, $uploadedFile['tmp_name']);
|
|
|
|
// ファイルを移動
|
|
$result = move_uploaded_file($uploadedFile['tmp_name'], '../'.$uploadedPath);
|
|
|
|
if ($result) {
|
|
$emoji_path = $uploadedPath; // 保存されたファイルのパスを使用
|
|
} else {
|
|
$errnum = $uploadedFile['error'];
|
|
if($errnum === 1){$errcode = "FILE_DEKASUGUI_PHP_INI_KAKUNIN";}
|
|
if($errnum === 2){$errcode = "FILE_DEKASUGUI_HTML_KAKUNIN";}
|
|
if($errnum === 3){$errcode = "FILE_SUKOSHIDAKE_UPLOAD";}
|
|
if($errnum === 4){$errcode = "FILE_UPLOAD_DEKINAKATTA";}
|
|
if($errnum === 6){$errcode = "TMP_FOLDER_NAI";}
|
|
if($errnum === 7){$errcode = "FILE_KAKIKOMI_SIPPAI";}
|
|
if($errnum === 8){$errcode = "PHPINFO()_KAKUNIN";}
|
|
$error_message[] = 'アップロード失敗!(2)エラーコード:' .$errcode.'';
|
|
}
|
|
}else{
|
|
$error_message[] = "使用できない画像形式です。(FILE_UPLOAD_DEKINAKATTA)";
|
|
}
|
|
}else{
|
|
$error_message[] = '画像を選択してください';
|
|
}
|
|
|
|
|
|
|
|
$options = array(
|
|
// SQL実行失敗時に例外をスルー
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
// デフォルトフェッチモードを連想配列形式に設定
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
// バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減)
|
|
// SELECTで得た結果に対してもrowCountメソッドを使えるようにする
|
|
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
|
);
|
|
|
|
$dbh = new PDO('mysql:charset=UTF8;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option);
|
|
|
|
|
|
$query = $dbh->prepare('SELECT * FROM emoji WHERE emojiname = :emojiname limit 1');
|
|
|
|
$query->execute(array(':emojiname' => $emojiname));
|
|
|
|
$result = $query->fetch();
|
|
|
|
// IDの入力チェック
|
|
if( empty($emojiname) ) {
|
|
$error_message[] = '絵文字IDを入力してください!(EMOJI_ID_INPUT_PLEASE)';
|
|
} else {
|
|
|
|
// 文字数を確認
|
|
if( 20 < mb_strlen($emojiname, 'UTF-8') ) {
|
|
$error_message[] = 'IDは20文字以内で入力してください。(EMOJI_ID_OVER_MAX_COUNT)';
|
|
}
|
|
|
|
if($result > 0){
|
|
$error_message[] = 'このID('.$emojiname.')は既に使用されています。他のIDを作成してください。(EMOJI_ID_SHIYOUZUMI)'; //このE-mailは既に使用されています。
|
|
}
|
|
|
|
}
|
|
|
|
if( empty($error_message) ) {
|
|
|
|
// 書き込み日時を取得
|
|
$datetime = date("Y-m-d H:i:s");
|
|
|
|
// トランザクション開始
|
|
$pdo->beginTransaction();
|
|
|
|
try {
|
|
|
|
// SQL作成
|
|
$stmt = $pdo->prepare("INSERT INTO emoji (emojifile, emojiname, emojiinfo, emojidate) VALUES ( :emojifile, :emojiname, :emojiinfo, :emojidate)");
|
|
|
|
$stmt->bindValue(':emojifile', $emoji_path, PDO::PARAM_STR);
|
|
|
|
// 値をセット
|
|
$stmt->bindParam( ':emojiname', $emojiname, PDO::PARAM_STR);
|
|
$stmt->bindParam( ':emojiinfo', $emojiinfo, PDO::PARAM_STR);
|
|
|
|
$stmt->bindParam( ':emojidate', $datetime, PDO::PARAM_STR);
|
|
|
|
// SQLクエリの実行
|
|
$res = $stmt->execute();
|
|
|
|
// コミット
|
|
$res = $pdo->commit();
|
|
|
|
} catch(Exception $e) {
|
|
|
|
// エラーが発生した時はロールバック
|
|
$pdo->rollBack();
|
|
}
|
|
|
|
if( $res ) {
|
|
$url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|
header("Location:".$url."");
|
|
exit;
|
|
} else {
|
|
$error_message[] = '登録に失敗しました。(REGISTERED_DAME)';
|
|
}
|
|
|
|
// プリペアドステートメントを削除
|
|
$stmt = null;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
require('../logout/logout.php');
|
|
|
|
|
|
|
|
// データベースの接続を閉じる
|
|
$pdo = null;
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="ja">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<link rel="stylesheet" href="../css/home.css">
|
|
<script src="../js/unsupported.js"></script>
|
|
<script src="../js/console_notice.js"></script>
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<script src="../js/jquery-min.js"></script>
|
|
<link rel="apple-touch-icon" type="image/png" href="../favicon/apple-touch-icon-180x180.png">
|
|
<link rel="icon" type="image/png" href="../favicon/icon-192x192.png">
|
|
<title>絵文字登録 - <?php echo htmlentities($serversettings["serverinfo"]["server_name"], ENT_QUOTES, 'UTF-8');?></title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
<?php require('../require/leftbox.php');?>
|
|
<main>
|
|
<div class="admin_settings">
|
|
<?php require('settings_left_menu.php');?>
|
|
|
|
<div class="admin_right">
|
|
|
|
<?php if( !empty($error_message) ): ?>
|
|
<ul class="errmsg">
|
|
<?php foreach( $error_message as $value ): ?>
|
|
<p>・ <?php echo $value; ?></p>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
|
|
<form class="formarea" enctype="multipart/form-data" method="post">
|
|
|
|
<h1>絵文字登録</h1>
|
|
|
|
<p>絵文字登録です。</p>
|
|
<div class="p2">
|
|
注意 : uwuzuで表示されるカスタム絵文字の最大の大きさは縦64pxです。<br>
|
|
縦64px以上のカスタム絵文字を登録しても縮小されて表示されます。<br>
|
|
また、縦64px以上の画像をアップロードすると、uwuzuの動作が遅くなる恐れがあるため、絵文字の画像サイズは縦64pxを推奨します。</div>
|
|
|
|
<div id="wrap">
|
|
|
|
<label class="irobutton" for="file_upload">ファイル選択
|
|
<input type="file" id="file_upload" name="image" >
|
|
</label>
|
|
</div>
|
|
|
|
<!--ユーザーネーム関係-->
|
|
<div>
|
|
<p>EmojiID</p>
|
|
<input id="username" onInput="checkForm(this)" placeholder="kusa" class="inbox" type="text" name="emojiname" value="<?php if( !empty($_SESSION['emojiname']) ){ echo htmlentities( $_SESSION['emojiname'], ENT_QUOTES, 'UTF-8'); } ?>">
|
|
</div>
|
|
|
|
<div>
|
|
<p>この絵文字について</p>
|
|
<input id="username" placeholder="くさデス" class="inbox" type="text" name="emojiinfo" value="<?php if( !empty($_SESSION['emojiinfo']) ){ echo htmlentities( $_SESSION['emojiinfo'], ENT_QUOTES, 'UTF-8'); } ?>">
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<input type="submit" class = "irobutton" name="btn_submit" value="登録">
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php require('../require/rightbox.php');?>
|
|
<?php require('../require/botbox.php');?>
|
|
<?php require('../require/noscript_modal.php');?>
|
|
</body>
|
|
|
|
<script type="text/javascript">
|
|
function checkForm(inputElement) {
|
|
var str = inputElement.value;
|
|
while (str.match(/[^A-Za-z\d_]/)) {
|
|
str = str.replace(/[^A-Za-z\d_]/, "");
|
|
}
|
|
inputElement.value = str;
|
|
}
|
|
|
|
window.addEventListener('DOMContentLoaded', function(){
|
|
|
|
// ファイルが選択されたら実行
|
|
document.getElementById("file_upload").addEventListener('change', function(e){
|
|
|
|
var file_reader = new FileReader();
|
|
|
|
// ファイルの読み込みを行ったら実行
|
|
file_reader.addEventListener('load', function(e) {
|
|
console.log(e.target.result);
|
|
const element = document.querySelector('#wrap');
|
|
const createElement = '<p>画像を選択しました。</p>';
|
|
element.insertAdjacentHTML('afterend', createElement);
|
|
});
|
|
|
|
file_reader.readAsText(e.target.files[0]);
|
|
});
|
|
});
|
|
</script>
|
|
</html>
|