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 ":$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 ":$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 "@".replaceProfileEmojiImages(htmlentities($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; } class MessageDisplay { private $value; public function __construct($value) { $this->value = $value; } public function display() { if($this->value['userchk'] === "none"){ echo '
'; }else{ echo '
'; } echo '
'; echo '
'; $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 '
'; echo '
'; // 投稿内のHTMLコードを表示する部分 echo '

' . replaceEmojisWithImages($this->value['title']) . '

'; echo '

' . replaceEmojisWithImages(nl2br($this->value['msg'])) . '

'; echo ' 詳細をみる'; echo '
'; } } ?>