mirror of
https://github.com/Daichimarukana/uwuzu.git
synced 2026-06-05 03:24:41 +00:00
uwuzu version 1.2.28
This commit is contained in:
@@ -1,4 +1,59 @@
|
||||
<?php
|
||||
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='/@".$mentionsuserData["userid"]."'>@".$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;
|
||||
|
||||
@@ -26,8 +81,8 @@ class MessageDisplay {
|
||||
echo ' </div>';
|
||||
|
||||
// 投稿内のHTMLコードを表示する部分
|
||||
echo ' <h3>' . $this->value['title'] . '</h3>';
|
||||
echo ' <p>' . nl2br($this->value['msg']) . '</p>';
|
||||
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>';
|
||||
|
||||
Reference in New Issue
Block a user