1
0
mirror of https://github.com/Daichimarukana/uwuzu.git synced 2026-06-05 03:24:41 +00:00
Files
uwuzu-mirror/nextpage/notificationview.php
T
2023-12-21 20:29:41 +09:00

117 lines
4.9 KiB
PHP

<?php
//Profile
function replaceProfileEmojiImages($postText) {
// プロフィール名で絵文字名(:emoji:)を検出して画像に置き換える
$emojiPattern = '/:(\w+):/';
$postTextWithImages = preg_replace_callback($emojiPattern, function($matches) {
$emojiName = $matches[1];
//絵文字path取得
$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,
));
$emoji_Query = $dbh->prepare("SELECT emojifile, emojiname FROM emoji WHERE emojiname = :emojiname");
$emoji_Query->bindValue(':emojiname', $emojiName);
$emoji_Query->execute();
$emoji_row = $emoji_Query->fetch();
if(empty($emoji_row["emojifile"])){
$emoji_path = "img/sysimage/errorimage/emoji_404.png";
}else{
$emoji_path = $emoji_row["emojifile"];
}
return "<img src='../".$emoji_path."' alt=':$emojiName:' title=':$emojiName:'>";
}, $postText);
return $postTextWithImages;
}
function replaceEmojisWithImages($postText) {
// ユーズ内で絵文字名(:emoji:)を検出して画像に置き換える
$emojiPattern = '/:(\w+):/';
$postTextWithImages = preg_replace_callback($emojiPattern, function($matches) {
$emojiName = $matches[1];
//絵文字path取得
$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,
));
$emoji_Query = $dbh->prepare("SELECT emojifile, emojiname FROM emoji WHERE emojiname = :emojiname");
$emoji_Query->bindValue(':emojiname', $emojiName);
$emoji_Query->execute();
$emoji_row = $emoji_Query->fetch();
if(empty($emoji_row["emojifile"])){
$emoji_path = "img/sysimage/errorimage/emoji_404.png";
}else{
$emoji_path = $emoji_row["emojifile"];
}
return "<img src='../".$emoji_path."' alt=':$emojiName:' title=':$emojiName:'>";
}, $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 "<a class = 'mta' href='/@".htmlentities($mentionsuserData["userid"])."'>@".replaceProfileEmojiImages(htmlentities($mentionsuserData["username"]))."</a>";
}
}, $postTextWithImages);
$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;
}
class MessageDisplay {
private $value;
public function __construct($value) {
$this->value = $value;
}
public function display() {
if($this->value['userchk'] === "none"){
echo '<div class="notification2">';
}else{
echo '<div class="notification">';
}
echo ' <div class="flebox">';
echo ' <div class="time">';
$day = date("Ymd", strtotime(htmlentities($this->value['datetime'])));
if ($day == date("Ymd")) {
echo date("今日 H:i", strtotime(htmlentities($this->value['datetime'])));
} else {
echo date("Y年m月d日 H:i", strtotime(htmlentities($this->value['datetime'])));
}
echo ' </div>';
echo ' </div>';
// 投稿内のHTMLコードを表示する部分
echo ' <h3>' . replaceEmojisWithImages($this->value['title']) . '</h3>';
echo ' <p>' . replaceEmojisWithImages(nl2br($this->value['msg'])) . '</p>';
echo ' <a href="' . htmlentities($this->value['url']) . '">詳細をみる</a>';
echo '</div>';
}
}
?>