1
0
mirror of https://github.com/Daichimarukana/uwuzu.git synced 2026-06-05 03:24:41 +00:00

uwuzu version 1.2.13

This commit is contained in:
daichimarukana
2023-08-30 00:05:18 +09:00
parent ae8e000360
commit 70560ecab7
210 changed files with 21107 additions and 50 deletions
+110
View File
@@ -0,0 +1,110 @@
<?php
function createUniqId() {
list($msec, $sec) = explode(" ", microtime());
$hashCreateTime = $sec . floor($msec * 1000000);
$hashCreateTime = strrev($hashCreateTime);
return base_convert($hashCreateTime, 10, 36);
}
require('../db.php');
require('view.php');
// データベースに接続
try {
$option = array(
PDO::ATTR_ERRMODE => 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();
}
$userid = htmlentities($_GET['userid']);
$itemsPerPage = 30; // 1ページあたりのユーズ数
$pageNumber = htmlentities(isset($_GET['page'])) ? htmlentities(intval($_GET['page'])) : 1;
$offset = ($pageNumber - 1) * $itemsPerPage;
$messages = array();
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,
));
// フォローしているユーザーIDを取得し、カンマで区切る
$followQuery = $dbh->prepare("SELECT follow FROM account WHERE userid = :userid");
$followQuery->bindValue(':userid', $userid);
$followQuery->execute();
$followData = $followQuery->fetch();
$follow = $followData['follow'];
$followList = explode(',', $follow);
// フォローしているユーザーの投稿を取得し、日時順に並び替える
$messages = array(); // 初期化
foreach ($followList as $followUserId) {
$sql = "SELECT account, username, uniqid, rpuniqid, ueuse, datetime, photo1, photo2, video1, favorite, abi, abidate FROM ueuse WHERE rpuniqid = '' AND account = :follow_account ORDER BY datetime DESC LIMIT $offset, $itemsPerPage";
$stmt = $dbh->prepare($sql);
$stmt->bindValue(':follow_account', $followUserId, PDO::PARAM_STR);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$messages[] = $row;
}
}
// ユーザー情報を取得して、$messages内のusernameをuserDataのusernameに置き換える
foreach ($messages as &$message) {
$userQuery = $pdo->prepare("SELECT username, userid, profile, role, iconname, headname FROM account WHERE userid = :userid");
$userQuery->bindValue(':userid', $message["account"]);
$userQuery->execute();
$userData = $userQuery->fetch();
if ($userData) {
$message['iconname'] = $userData['iconname'];
$message['headname'] = $userData['headname'];
$message['username'] = $userData['username'];
$message['role'] = $userData['role'];
}
$rpQuery = $pdo->prepare("SELECT COUNT(*) as reply_count FROM ueuse WHERE rpuniqid = :rpuniqid");
$rpQuery->bindValue(':rpuniqid', $message['uniqid']);
$rpQuery->execute();
$rpData = $rpQuery->fetch(PDO::FETCH_ASSOC);
if ($rpData){
$message['reply_count'] = $rpData['reply_count'];
}
}
if(!empty($messages)){
foreach ($messages as $value) {
$fav = $value['favorite']; // コンマで区切られたユーザーIDを含む変数
// コンマで区切って配列に分割し、要素数を数える
$favIds = explode(',', $fav);
$value["favcnt"] = count($favIds)-1;
$messageDisplay = new MessageDisplay($value, $userid); // $userid をコンストラクタに渡す
$messageDisplay->display();
}
}else{
echo '<div class="tokonone" id="noueuse"><p>ユーズがありません</p></div>';
}
$pdo = null;
}
?>
+18 -5
View File
@@ -38,11 +38,24 @@ if (!empty($pdo)) {
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
));
$messageQuery = $dbh->prepare("SELECT account,username,ueuse,uniqid,rpuniqid,datetime,photo1,photo2,video1,favorite, abi, abidate FROM ueuse WHERE ueuse LIKE :keyword OR abi LIKE :keyword ORDER BY datetime DESC");
$messageQuery->bindValue(':keyword', '%' . $keyword . '%', PDO::PARAM_STR);
$messageQuery->execute();
$message_array = $messageQuery->fetchAll();
$keywordPattern = '/from:@(\w+)\s+(.+)/';
if (preg_match($keywordPattern, $keyword, $matches)) {
$username = $matches[1];
$searchKeyword = $matches[2];
$messageQuery = $dbh->prepare("SELECT account,username,ueuse,uniqid,rpuniqid,datetime,photo1,photo2,video1,favorite, abi, abidate FROM ueuse WHERE account = :username AND (ueuse LIKE :searchKeyword OR abi LIKE :searchKeyword) ORDER BY datetime DESC");
$messageQuery->bindValue(':username', $username, PDO::PARAM_STR);
$messageQuery->bindValue(':searchKeyword', '%' . $searchKeyword . '%', PDO::PARAM_STR);
$messageQuery->execute();
$message_array = $messageQuery->fetchAll();
} else {
$messageQuery = $dbh->prepare("SELECT account,username,ueuse,uniqid,rpuniqid,datetime,photo1,photo2,video1,favorite, abi, abidate FROM ueuse WHERE ueuse LIKE :keyword OR abi LIKE :keyword ORDER BY datetime DESC");
$messageQuery->bindValue(':keyword', '%' . $keyword . '%', PDO::PARAM_STR);
$messageQuery->execute();
$message_array = $messageQuery->fetchAll();
}
$messages = array();
foreach ($message_array as $row) {
+14 -5
View File
@@ -10,13 +10,16 @@ function processMarkdownAndWrapEmptyLines($markdownText){
$markdownText = preg_replace('/^#img (.+)/m', '<img src="$1">', $markdownText);
// タイトル(#、##、###)をHTMLのhタグに変換
$markdownText = preg_replace('/^# (.+)/m', '<h2>$1</h2>', $markdownText);
$markdownText = preg_replace('/^## (.+)/m', '<h3>$1</h3>', $markdownText);
$markdownText = preg_replace('/^### (.+)/m', '<h4>$1</h4>', $markdownText);
$markdownText = preg_replace('/^# (.+)/m', '<h1>$1</h1>', $markdownText);
$markdownText = preg_replace('/^## (.+)/m', '<h2>$1</h2>', $markdownText);
$markdownText = preg_replace('/^### (.+)/m', '<h3>$1</h3>', $markdownText);
// 箇条書き(-)をHTMLのul/liタグに変換
$markdownText = preg_replace('/^- (.+)/m', '<ul><li>$1</li></ul>', $markdownText);
// 空行の前に何もない行をHTMLのpタグに変換
$markdownText = preg_replace('/(^\s*)(?!\s)(.*)/m', '$1<p>$2</p>', $markdownText);
return $markdownText;
}
@@ -26,7 +29,7 @@ function replaceEmojisWithImages($postText) {
$emojiPattern = '/:(\w+):/';
$postTextWithImages = preg_replace_callback($emojiPattern, function($matches) {
$emojiName = $matches[1];
return "<img src='../emoji/emojiimage.php?emoji=" . urlencode($emojiName) . "' alt='$emojiName'>";
return "<img src='../emoji/emojiimage.php?emoji=" . urlencode($emojiName) . "' alt=':$emojiName:' title=':$emojiName:'>";
}, $postText);
// @username を検出してリンクに置き換える
@@ -52,7 +55,13 @@ function replaceEmojisWithImages($postText) {
}
}, $postTextWithImages);
return $postTextWithImagesAndUsernames;
$hashtagsPattern = '/#([\p{Han}\p{Hiragana}\p{Katakana}A-Za-z0-9_]+)/u';
$postTextWithHashtags = preg_replace_callback($hashtagsPattern, function($matches) {
$hashtags = $matches[1];
return "<a class = 'hashtags' href='/search?q=".urlencode('#').$hashtags."'>".'#'.$hashtags."</a>";
}, $postTextWithImagesAndUsernames);
return $postTextWithHashtags;
}
function replaceURLsWithLinks($postText) {