PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_MULTI_STATEMENTS => false
);
$pdo = new PDO('mysql:charset=utf8mb4;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',
]);
setcookie('username', $username,[
'expires' => time() + 60 * 60 * 24 * 14,
'path' => '/',
'samesite' => 'lax',
]);
setcookie('loginid', $res["loginid"],[
'expires' => time() + 60 * 60 * 24 * 14,
'path' => '/',
'samesite' => 'lax',
]);
setcookie('admin_login', true,[
'expires' => time() + 60 * 60 * 24 * 14,
'path' => '/',
'samesite' => 'lax',
]);
}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',
]);
setcookie('username', $username,[
'expires' => time() + 60 * 60 * 24 * 14,
'path' => '/',
'samesite' => 'lax',
]);
setcookie('loginid', $res["loginid"],[
'expires' => time() + 60 * 60 * 24 * 14,
'path' => '/',
'samesite' => 'lax',
]);
setcookie('admin_login', true,[
'expires' => time() + 60 * 60 * 24 * 14,
'path' => '/',
'samesite' => 'lax',
]);
}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;
}
$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'];
function customStripTags($html, $allowedTags) {
$allowedTagsString = '<' . implode('><', $allowedTags) . '>';
return strip_tags($html, $allowedTagsString);
}
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font');
if( !empty($pdo) ) {
// データベース接続の設定
$dbh = new PDO('mysql:charset=utf8mb4;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,
));
$uwuzuid2 = htmlentities(str_replace('@', '', $_GET['uwuzuid']));
$uwuzuid = htmlentities(str_replace('@'.$domain, '', $uwuzuid2));
// ユーズ内の絵文字を画像に置き換える
function replaceEmojisWithImages($postText) {
// ユーズ内で絵文字名(:emoji:)を検出して画像に置き換える
$emojiPattern = '/:(\w+):/';
$postTextWithImages = preg_replace_callback($emojiPattern, function($matches) {
$emojiName = $matches[1];
return "
";
}, $postText);
// @username を検出してリンクに置き換える
$usernamePattern = '/@(\w+)/';
$postTextWithImagesAndUsernames = preg_replace_callback($usernamePattern, function($matches) {
$username = $matches[1];
$dbh = new PDO('mysql:charset=utf8mb4;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,
));
$mentionsuserQuery = $dbh->prepare("SELECT username, userid FROM account WHERE userid = :userid");
$mentionsuserQuery->bindValue(':userid', $username);
$mentionsuserQuery->execute();
$mentionsuserData = $mentionsuserQuery->fetch();
if(empty($mentionsuserData)){
return "@$username";
}else{
return "@".$mentionsuserData["username"]."";
}
}, $postTextWithImages);
$hashtagsPattern = '/#([\p{Han}\p{Hiragana}\p{Katakana}A-Za-z0-9_]+)/u';
$postTextWithHashtags = preg_replace_callback($hashtagsPattern, function($matches) {
$hashtags = $matches[1];
return "".'#'.$hashtags."";
}, $postTextWithImagesAndUsernames);
return $postTextWithHashtags;
}
function replaceURLsWithLinks($postText) {
// URLを正規表現を使って検出
$pattern = '/(https:\/\/[^\s<>\[\]\'"]+)/'; // 改良された正規表現
preg_match_all($pattern, $postText, $matches);
// 検出したURLごとに処理を行う
foreach ($matches[0] as $url) {
// ドメイン部分を抽出
$parsedUrl = parse_url($url);
if (!isset($parsedUrl['path'])) {
$parsedUrl['path'] = '';
}
$domain = $parsedUrl['host'].(strlen($parsedUrl['path']) > 24 ? substr($parsedUrl['path'], 0, 24) . '...' : $parsedUrl['path']);
// 不要な文字を削除してaタグを生成
$urlWithoutSpaces = preg_replace('/\s+/', '', $url);
$link = "$domain";
// URLをドメインのみを表示するaタグで置き換え
$postText = preg_replace('/' . preg_quote($url, '/') . '/', $link, $postText);
}
return $postText;
}
$userQuery = $dbh->prepare("SELECT username, userid, profile, role, follower, blocklist FROM account WHERE userid = :userid");
$userQuery->bindValue(':userid', $uwuzuid);
$userQuery->execute();
$userData = $userQuery->fetch();
if(!empty($userData["userid"])){
$roles = explode(',', $userData["role"]); // カンマで区切られたロールを配列に分割
$rerole = $dbh->prepare("SELECT follow, follower,blocklist, username, userid, password, mailadds, profile, iconname, headname, role, datetime FROM account WHERE userid = :userid");
$rerole->bindValue(':userid', $uwuzuid);
// SQL実行
$rerole->execute();
$userdata = $rerole->fetch(); // ここでデータベースから取得した値を $role に代入する
$roleDataArray = array();
foreach ($roles as $roleId) {
$rerole = $dbh->prepare("SELECT rolename, roleauth, rolecolor FROM role WHERE roleidname = :role");
$rerole->bindValue(':role', $roleId);
$rerole->execute();
$roleDataArray[$roleId] = $rerole->fetch();
}
//-------フォロー数---------
$follow = $userdata['follow']; // コンマで区切られたユーザーIDを含む変数
// コンマで区切って配列に分割し、要素数を数える
$followIds = explode(',', $follow);
$followCount = count($followIds)-1;
$follow_on_me = array_search($userid, $followIds);
if ($follow_on_me !== false) {
$follow_yes = "フォローされています"; // worldを含む:6
}else{
$follow_yes = ""; // worldを含む:6
}
//-------フォロワー数---------
$follower = $userdata['follower']; // コンマで区切られたユーザーIDを含む変数
// コンマで区切って配列に分割し、要素数を数える
$followerIds = explode(',', $follower);
$followerCount = count($followerIds)-1;
$profileText = htmlentities($userData['profile'], ENT_QUOTES, 'UTF-8');
$allueuse = $dbh->prepare("SELECT account FROM ueuse WHERE account = :userid");
$allueuse->bindValue(':userid', $uwuzuid);
$allueuse->execute();
$ueuse_cnt = $allueuse->rowCount();
//-------フォロワー取得---------
// フォロワーのユーザーIDを $follower_userids 配列に追加
foreach ($followerIds as $follower_userid) {
$follower_userids[] = $follower_userid;
}
// フォロワーのユーザー情報を取得
$follower_userdata = array();
foreach ($follower_userids as $follower_userid) {
$follower_userQuery = $pdo->prepare("SELECT username, userid, iconname, headname, sacinfo FROM account WHERE userid = :userid");
$follower_userQuery->bindValue(':userid', $follower_userid);
$follower_userQuery->execute();
$follower_userinfo = $follower_userQuery->fetch();
if ($follower_userinfo) {
// フォロワーのユーザー情報を $follower_userdata 配列に追加
$follower_userdata[] = $follower_userinfo;
}
}
//-------フォロー取得---------
foreach ($followIds as $follow_userid) {
$follow_userids[] = $follow_userid;
}
$follow_userdata = array();
foreach ($follow_userids as $follow_userid) {
$follow_userQuery = $pdo->prepare("SELECT username, userid, iconname, headname, sacinfo FROM account WHERE userid = :userid");
$follow_userQuery->bindValue(':userid', $follow_userid);
$follow_userQuery->execute();
$follow_userinfo = $follow_userQuery->fetch();
if ($follow_userinfo) {
// フォロワーのユーザー情報を $follower_userdata 配列に追加
$follow_userdata[] = $follow_userinfo;
}
}
}else{
$userData["userid"] = "none";
$userData['username'] = "ゆーざーなし";
$ueuse_cnt = "zero";
$followCount = "zero";
$followerCount = "zero";
}
}
if (!empty($_POST['follow'])) {
// フォローボタンが押された場合の処理
$followerList = explode(',', $userdata['follower']);
if (!(in_array($userid, $followerList))) {
// 自分が相手をフォローしていない場合、相手のfollowerカラムと自分のfollowカラムを更新
$followerList[] = $userid;
$newFollowerList = implode(',', $followerList);
// UPDATE文を実行してフォロー情報を更新
$updateQuery = $pdo->prepare("UPDATE account SET follower = :follower WHERE userid = :userid");
$updateQuery->bindValue(':follower', $newFollowerList, PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userData['userid'], PDO::PARAM_STR);
$res = $updateQuery->execute();
// 自分のfollowカラムを更新
$updateQuery = $pdo->prepare("UPDATE account SET follow = CONCAT_WS(',', follow, :follow) WHERE userid = :userid");
$updateQuery->bindValue(':follow', $userData["userid"], PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userid, PDO::PARAM_STR);
$res_follow = $updateQuery->execute();
$datetime = date("Y-m-d H:i:s");
$pdo->beginTransaction();
try {
$touserid = $userData["userid"];
$datetime = date("Y-m-d H:i:s");
$msg = "".$userid."さんにフォローされました。";
$title = "🎉".$userid."さんにフォローされました!🎉";
$url = "/@" . $userid . "";
$userchk = 'none';
// 通知用SQL作成
$stmt = $pdo->prepare("INSERT INTO notification (touserid, msg, url, datetime, userchk, title) VALUES (:touserid, :msg, :url, :datetime, :userchk, :title)");
$stmt->bindParam(':touserid', htmlentities($touserid), PDO::PARAM_STR);
$stmt->bindParam(':msg', htmlentities($msg), PDO::PARAM_STR);
$stmt->bindParam(':url', htmlentities($url), PDO::PARAM_STR);
$stmt->bindParam(':userchk', htmlentities($userchk), PDO::PARAM_STR);
$stmt->bindParam(':title', htmlentities($title), PDO::PARAM_STR);
$stmt->bindParam(':datetime', htmlentities($datetime), PDO::PARAM_STR);
// SQLクエリの実行
$res = $stmt->execute();
// コミット
$res = $pdo->commit();
} catch(Exception $e) {
// エラーが発生した時はロールバック
$pdo->rollBack();
}
if ($res && $res_follow) {
$url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("Location:" . $url);
exit;
} else {
$error_message[] = '更新に失敗しました。';
}
}
} elseif (!empty($_POST['unfollow'])) {
// フォロー解除ボタンが押された場合の処理
$followerList = explode(',', $userdata['follower']);
if (in_array($userid, $followerList)) {
// 自分が相手をフォローしている場合、相手のfollowerカラムと自分のfollowカラムを更新
$followerList = array_diff($followerList, array($userid));
$newFollowerList = implode(',', $followerList);
// UPDATE文を実行してフォロー情報を更新
$updateQuery = $pdo->prepare("UPDATE account SET follower = :follower WHERE userid = :userid");
$updateQuery->bindValue(':follower', $newFollowerList, PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userData['userid'], PDO::PARAM_STR);
$res = $updateQuery->execute();
$myflwlist = explode(',', $myfollowlist);
$delfollowList = array_diff($myflwlist, array($userData['userid']));
$deluserid = implode(',', $delfollowList);
// 自分のfollowカラムから相手のユーザーIDを削除
$updateQuery = $pdo->prepare("UPDATE account SET follow = :follow WHERE userid = :userid");
$updateQuery->bindValue(':follow', $deluserid, PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userid, PDO::PARAM_STR);
$res_follow = $updateQuery->execute();
if ($res && $res_follow) {
$url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("Location:" . $url);
exit;
} else {
$error_message[] = '更新に失敗しました。';
}
$stmt = null;
}
}
if (!empty($_POST['send_block_submit'])) {
$updateQuery = $pdo->prepare("UPDATE account SET blocklist = CONCAT_WS(',', blocklist, :blocklist) WHERE userid = :userid");
$updateQuery->bindValue(':blocklist', $userData["userid"], PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userid, PDO::PARAM_STR);
$res_block = $updateQuery->execute();
// フォロー解除ボタンが押された場合の処理
$followerList = explode(',', $userdata['follower']);
if (in_array($userid, $followerList)) {
// 自分が相手をフォローしている場合、相手のfollowerカラムと自分のfollowカラムを更新
$followerList = array_diff($followerList, array($userid));
$newFollowerList = implode(',', $followerList);
// UPDATE文を実行してフォロー情報を更新
$updateQuery = $pdo->prepare("UPDATE account SET follower = :follower WHERE userid = :userid");
$updateQuery->bindValue(':follower', $newFollowerList, PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userData['userid'], PDO::PARAM_STR);
$res = $updateQuery->execute();
$myflwlist = explode(',', $myfollowlist);
$delfollowList = array_diff($myflwlist, array($userData['userid']));
$deluserid = implode(',', $delfollowList);
// 自分のfollowカラムから相手のユーザーIDを削除
$updateQuery = $pdo->prepare("UPDATE account SET follow = :follow WHERE userid = :userid");
$updateQuery->bindValue(':follow', $deluserid, PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userid, PDO::PARAM_STR);
$res_follow = $updateQuery->execute();
if ($res && $res_follow) {
$url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("Location:" . $url);
exit;
} else {
$error_message[] = '更新に失敗しました。';
}
$stmt = null;
}
if ($res_block) {
$url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("Location:" . $url);
exit;
} else {
$error_message[] = '更新に失敗しました。';
}
} elseif (!empty($_POST['send_un_block_submit'])) {
$myblklist = explode(',', $myBlocklist);
$delblkList = array_diff($myblklist, array($userData['userid']));
$deluserid = implode(',', $delblkList);
// 自分のfollowカラムから相手のユーザーIDを削除
$updateQuery = $pdo->prepare("UPDATE account SET blocklist = :blocklist WHERE userid = :userid");
$updateQuery->bindValue(':blocklist', $deluserid, PDO::PARAM_STR);
$updateQuery->bindValue(':userid', $userid, PDO::PARAM_STR);
$res_block = $updateQuery->execute();
if ($res_block) {
$url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("Location:" . $url);
exit;
} else {
$error_message[] = '更新に失敗しました。';
}
}
require('../logout/logout.php');
// データベースの接続を閉じる
$pdo = null;
?>
さんのプロフィール -
🦖💨 インターネットへの接続が切断されました...
紀元前3000年からuwuzuを利用しています。いるわけねぇだろ()
@
ブロックしているためプロフィールは表示されません。
🤔
さんをブロックしているため投稿の閲覧は出来ません。
エラー
サーバーの応答がなかったか不完全だったようです。
ネットワークの接続が正常かを確認の上再読み込みしてください。
さんをフォローしているユーザー
";
echo "
.)
";
echo "
";
echo "
";
echo "
";
echo "
";
echo "
";
}
}
}else{
echo "
".htmlentities($userData["username"], ENT_QUOTES, 'UTF-8')."さんは誰にもフォローされていません。
";
}
?>
さんがフォローしているユーザー
";
echo "
.)
";
echo "
";
echo "
";
echo "
";
echo "
";
echo "
";
}
}
}else{
echo "
".htmlentities($userData["username"], ENT_QUOTES, 'UTF-8')."さんは誰もフォローしていません。
";
}
?>