mirror of
https://github.com/Daichimarukana/uwuzu.git
synced 2026-06-05 03:24:41 +00:00
uwuzuのコードです
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<?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 = $_GET['userid'];
|
||||
|
||||
$itemsPerPage = 30; // 1ページあたりのユーズ数
|
||||
$pageNumber = isset($_GET['page']) ? intval($_GET['page']) : 1;
|
||||
$offset = ($pageNumber - 1) * $itemsPerPage;
|
||||
|
||||
$messages = array();
|
||||
|
||||
if (!empty($pdo)) {
|
||||
|
||||
function customStripTags($html, $allowedTags) {
|
||||
$allowedTagString = implode('|', $allowedTags);
|
||||
$pattern = "/<(?!$allowedTagString)[^>]+>/";
|
||||
return preg_replace($pattern, '', $html);
|
||||
}
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font');
|
||||
|
||||
// ユーズ内の絵文字を画像に置き換える
|
||||
function replaceEmojisWithImages($postText) {
|
||||
// ユーズ内で絵文字名(:emoji:)を検出して画像に置き換える
|
||||
$pattern = '/:(\w+):/';
|
||||
$postTextWithImages = preg_replace_callback($pattern, function($matches) {
|
||||
$emojiName = $matches[1];
|
||||
return "<img src='../emoji/emojiimage.php?emoji=" . urlencode($emojiName) . "' alt='$emojiName'>";
|
||||
}, $postText);
|
||||
return $postTextWithImages;
|
||||
}
|
||||
|
||||
function replaceURLsWithLinks($postText) {
|
||||
// URLを正規表現を使って検出
|
||||
$pattern = '/(https?:\/\/[^\s]+)/';
|
||||
preg_match_all($pattern, $postText, $matches);
|
||||
|
||||
// 検出したURLごとに処理を行う
|
||||
foreach ($matches[0] as $url) {
|
||||
// ドメイン部分を抽出
|
||||
$parsedUrl = parse_url($url);
|
||||
$domain = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
|
||||
|
||||
// ドメインのみを表示するaタグを生成
|
||||
$link = "<a href='$url' target='_blank'>$domain</a>";
|
||||
|
||||
// URLをドメインのみを表示するaタグで置き換え
|
||||
$postText = str_replace($url, $link, $postText);
|
||||
}
|
||||
|
||||
return $postText;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT account, username, uniqid, rpuniqid, ueuse, datetime, photo1, photo2, video1, favorite, abi, abidate FROM ueuse WHERE rpuniqid = '' ORDER BY datetime DESC LIMIT $offset, $itemsPerPage";
|
||||
$message_array = $pdo->query($sql);
|
||||
|
||||
while ($row = $message_array->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
$messages[] = $row;
|
||||
}
|
||||
|
||||
// ユーザー情報を取得して、$messages内のusernameをuserDataのusernameに置き換える
|
||||
foreach ($messages as &$message) {
|
||||
$userQuery = $pdo->prepare("SELECT username, userid, profile, role FROM account WHERE userid = :userid");
|
||||
$userQuery->bindValue(':userid', $message["account"]);
|
||||
$userQuery->execute();
|
||||
$userData = $userQuery->fetch();
|
||||
|
||||
if ($userData) {
|
||||
$message['username'] = $userData['username'];
|
||||
}
|
||||
}
|
||||
|
||||
// ユーズ内のHTMLコードに指定のタグを有効化する関数
|
||||
function replaceUnescapedHTMLTags($html) {
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font'); // 有効化するタグ
|
||||
return customStripTags($html, $allowedTags);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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('notificationview.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 = $_GET['userid'];
|
||||
|
||||
$itemsPerPage = 30; // 1ページあたりの投稿数
|
||||
$pageNumber = isset($_GET['page']) ? 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,
|
||||
));
|
||||
|
||||
$messageQuery = $dbh->prepare("SELECT title,msg,url,datetime,userchk FROM notification WHERE touserid = :userid ORDER BY datetime DESC LIMIT $offset, $itemsPerPage");
|
||||
$messageQuery->bindValue(':userid', $userid);
|
||||
$messageQuery->execute();
|
||||
$message_array = $messageQuery->fetchAll();
|
||||
|
||||
if (!empty($message_array)) {
|
||||
foreach ($message_array as $value) {
|
||||
$messageDisplay = new MessageDisplay($value); // userid を渡さない
|
||||
$messageDisplay->display();
|
||||
}
|
||||
} else {
|
||||
echo '<div class="tokonone" id="noueuse"><p>通知はありません</p></div>';
|
||||
}
|
||||
|
||||
|
||||
$pdo = null;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
class MessageDisplay {
|
||||
private $value;
|
||||
|
||||
public function __construct($value) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function display() {
|
||||
echo '<div class="notification">';
|
||||
echo ' <div class="flebox">';
|
||||
|
||||
echo ' <div class="time">';
|
||||
$day = date("Ymd", strtotime(htmlspecialchars($this->value['datetime'])));
|
||||
if ($day == date("Ymd")) {
|
||||
echo date("今日 H:i", strtotime(htmlspecialchars($this->value['datetime'])));
|
||||
} else {
|
||||
echo date("Y年m月d日 H:i", strtotime(htmlspecialchars($this->value['datetime'])));
|
||||
}
|
||||
echo ' </div>';
|
||||
|
||||
echo ' </div>';
|
||||
|
||||
// 投稿内のHTMLコードを表示する部分
|
||||
echo ' <h3>' . htmlspecialchars($this->value['title']) . '</h3>';
|
||||
echo ' <p>' . htmlspecialchars($this->value['msg']) . '</p>';
|
||||
echo ' <a href="' . htmlspecialchars($this->value['url']) . '">続きをみる</a>';
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,131 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
|
||||
$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
|
||||
$userid = $_GET['userid'];
|
||||
|
||||
$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,
|
||||
));
|
||||
|
||||
$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();
|
||||
|
||||
function customStripTags($html, $allowedTags) {
|
||||
$allowedTagString = implode('|', $allowedTags);
|
||||
$pattern = "/<(?!$allowedTagString)[^>]+>/";
|
||||
return preg_replace($pattern, '', $html);
|
||||
}
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font');
|
||||
|
||||
// ユーズ内の絵文字を画像に置き換える
|
||||
function replaceEmojisWithImages($postText) {
|
||||
// ユーズ内で絵文字名(:emoji:)を検出して画像に置き換える
|
||||
$pattern = '/:(\w+):/';
|
||||
$postTextWithImages = preg_replace_callback($pattern, function($matches) {
|
||||
$emojiName = $matches[1];
|
||||
return "<img src='../emoji/emojiimage.php?emoji=" . urlencode($emojiName) . "' alt='$emojiName'>";
|
||||
}, $postText);
|
||||
return $postTextWithImages;
|
||||
}
|
||||
|
||||
function replaceURLsWithLinks($postText) {
|
||||
// URLを正規表現を使って検出
|
||||
$pattern = '/(https?:\/\/[^\s]+)/';
|
||||
preg_match_all($pattern, $postText, $matches);
|
||||
|
||||
// 検出したURLごとに処理を行う
|
||||
foreach ($matches[0] as $url) {
|
||||
// ドメイン部分を抽出
|
||||
$parsedUrl = parse_url($url);
|
||||
$domain = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
|
||||
|
||||
// ドメインのみを表示するaタグを生成
|
||||
$link = "<a href='$url' target='_blank'>$domain</a>";
|
||||
|
||||
// URLをドメインのみを表示するaタグで置き換え
|
||||
$postText = str_replace($url, $link, $postText);
|
||||
}
|
||||
|
||||
return $postText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$messages = array();
|
||||
foreach ($message_array as $row) {
|
||||
$messages[] = $row;
|
||||
}
|
||||
// ユーザー情報を取得して、$messages内のusernameをuserDataのusernameに置き換える
|
||||
foreach ($messages as &$message) {
|
||||
$userQuery = $pdo->prepare("SELECT username, userid, profile, role FROM account WHERE userid = :userid");
|
||||
$userQuery->bindValue(':userid', $message["account"]);
|
||||
$userQuery->execute();
|
||||
$userData = $userQuery->fetch();
|
||||
|
||||
if ($userData) {
|
||||
$message['username'] = $userData['username'];
|
||||
}
|
||||
}
|
||||
|
||||
// ユーズ内のHTMLコードに指定のタグを有効化する関数
|
||||
function replaceUnescapedHTMLTags($html) {
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font'); // 有効化するタグ
|
||||
return customStripTags($html, $allowedTags);
|
||||
}
|
||||
|
||||
if(!empty($messages)){
|
||||
foreach ($messages as $value) {
|
||||
|
||||
$fav = $value['favorite']; // コンマで区切られたユーザーIDを含む変数
|
||||
|
||||
// コンマで区切って配列に分割し、要素数を数える
|
||||
$favIds = explode(',', $fav);
|
||||
$value["favcnt"] = count($favIds)-1;
|
||||
|
||||
$messageDisplay = new MessageDisplay($value, $userid);
|
||||
$messageDisplay->display();
|
||||
}
|
||||
}else{
|
||||
echo '<div class="tokonone" id="noueuse"><p>ユーズがありません</p></div>';
|
||||
}
|
||||
|
||||
$pdo = null;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,139 @@
|
||||
<?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 = $_GET['userid'];
|
||||
|
||||
$ueuseid = isset($_GET['id']) ? $_GET['id'] : '';
|
||||
|
||||
$itemsPerPage = 30; // 1ページあたりの投稿数
|
||||
$pageNumber = isset($_GET['page']) ? 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,
|
||||
));
|
||||
|
||||
|
||||
|
||||
function customStripTags($html, $allowedTags) {
|
||||
$allowedTagString = implode('|', $allowedTags);
|
||||
$pattern = "/<(?!$allowedTagString)[^>]+>/";
|
||||
return preg_replace($pattern, '', $html);
|
||||
}
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font');
|
||||
// 投稿内の絵文字を画像に置き換える
|
||||
function replaceEmojisWithImages($postText) {
|
||||
// 投稿内で絵文字名(:emoji:)を検出して画像に置き換える
|
||||
$pattern = '/:(\w+):/';
|
||||
$postTextWithImages = preg_replace_callback($pattern, function($matches) {
|
||||
$emojiName = $matches[1];
|
||||
return "<img src='../emoji/emojiimage.php?emoji=" . urlencode($emojiName) . "' alt='$emojiName'>";
|
||||
}, $postText);
|
||||
return $postTextWithImages;
|
||||
}
|
||||
|
||||
function replaceURLsWithLinks($postText) {
|
||||
// URLを正規表現を使って検出
|
||||
$pattern = '/(https?:\/\/[^\s]+)/';
|
||||
preg_match_all($pattern, $postText, $matches);
|
||||
|
||||
// 検出したURLごとに処理を行う
|
||||
foreach ($matches[0] as $url) {
|
||||
// ドメイン部分を抽出
|
||||
$parsedUrl = parse_url($url);
|
||||
$domain = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
|
||||
|
||||
// ドメインのみを表示するaタグを生成
|
||||
$link = "<a href='$url' target='_blank'>$domain</a>";
|
||||
|
||||
// URLをドメインのみを表示するaタグで置き換え
|
||||
$postText = str_replace($url, $link, $postText);
|
||||
}
|
||||
|
||||
return $postText;
|
||||
}
|
||||
|
||||
// 投稿内容の取得(新しい順に取得)
|
||||
$messageQuery = $dbh->prepare("SELECT account, username, ueuse, uniqid, rpuniqid, datetime, photo1, photo2, video1, favorite, abi, abidate FROM ueuse WHERE uniqid = :ueuseid OR rpuniqid = :rpueuseid ORDER BY datetime ASC LIMIT $offset, $itemsPerPage");
|
||||
$messageQuery->bindValue(':ueuseid', $ueuseid);
|
||||
$messageQuery->bindValue(':rpueuseid', $ueuseid);
|
||||
$messageQuery->execute();
|
||||
$message_array = $messageQuery->fetchAll();
|
||||
|
||||
$messages = array();
|
||||
|
||||
|
||||
|
||||
foreach ($message_array as $row) {
|
||||
$messages[] = $row;
|
||||
}
|
||||
// ユーザー情報を取得して、$messages内のusernameをuserDataのusernameに置き換える
|
||||
foreach ($messages as &$message) {
|
||||
$userQuery = $pdo->prepare("SELECT username, userid, profile, role FROM account WHERE userid = :userid");
|
||||
$userQuery->bindValue(':userid', $message["account"]);
|
||||
$userQuery->execute();
|
||||
$userData = $userQuery->fetch();
|
||||
|
||||
if ($userData) {
|
||||
$message['username'] = $userData['username'];
|
||||
}
|
||||
}
|
||||
|
||||
// 投稿内のHTMLコードに指定のタグを有効化する関数
|
||||
function replaceUnescapedHTMLTags($html) {
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font'); // 有効化するタグ
|
||||
return customStripTags($html, $allowedTags);
|
||||
}
|
||||
|
||||
if(!empty($messages)){
|
||||
foreach ($messages as $value) {
|
||||
$fav = $value['favorite']; // コンマで区切られたユーザーIDを含む変数
|
||||
|
||||
// コンマで区切って配列に分割し、要素数を数える
|
||||
$favIds = explode(',', $fav);
|
||||
$value["favcnt"] = count($favIds)-1;
|
||||
|
||||
$messageDisplay = new MessageDisplay($value, $userid);
|
||||
$messageDisplay->display();
|
||||
}
|
||||
}else{
|
||||
echo '<div class="tokonone" id="noueuse"><p>投稿がありません</p></div>';
|
||||
}
|
||||
|
||||
$pdo = null;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,140 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
|
||||
$uwuzuid = isset($_GET['id']) ? $_GET['id'] : '';
|
||||
$userid = $_GET['userid'];
|
||||
|
||||
$itemsPerPage = 30; // 1ページあたりのユーズ数
|
||||
$pageNumber = isset($_GET['page']) ? 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,
|
||||
));
|
||||
|
||||
$userQuery = $dbh->prepare("SELECT username, userid, profile, role, follower FROM account WHERE userid = :userid");
|
||||
$userQuery->bindValue(':userid', $uwuzuid);
|
||||
$userQuery->execute();
|
||||
$userData = $userQuery->fetch();
|
||||
|
||||
$messageQuery = $dbh->prepare("SELECT account,username,ueuse,uniqid,rpuniqid,datetime,photo1,photo2,video1,favorite, abi, abidate FROM ueuse WHERE account = :userid AND rpuniqid = ''ORDER BY datetime DESC LIMIT $offset, $itemsPerPage");
|
||||
$messageQuery->bindValue(':userid', $uwuzuid);
|
||||
$messageQuery->execute();
|
||||
$message_array = $messageQuery->fetchAll();
|
||||
|
||||
function customStripTags($html, $allowedTags) {
|
||||
$allowedTagString = implode('|', $allowedTags);
|
||||
$pattern = "/<(?!$allowedTagString)[^>]+>/";
|
||||
return preg_replace($pattern, '', $html);
|
||||
}
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font');
|
||||
|
||||
// ユーズ内の絵文字を画像に置き換える
|
||||
function replaceEmojisWithImages($postText) {
|
||||
// ユーズ内で絵文字名(:emoji:)を検出して画像に置き換える
|
||||
$pattern = '/:(\w+):/';
|
||||
$postTextWithImages = preg_replace_callback($pattern, function($matches) {
|
||||
$emojiName = $matches[1];
|
||||
return "<img src='../emoji/emojiimage.php?emoji=" . urlencode($emojiName) . "' alt='$emojiName'>";
|
||||
}, $postText);
|
||||
return $postTextWithImages;
|
||||
}
|
||||
|
||||
function replaceURLsWithLinks($postText) {
|
||||
// URLを正規表現を使って検出
|
||||
$pattern = '/(https?:\/\/[^\s]+)/';
|
||||
preg_match_all($pattern, $postText, $matches);
|
||||
|
||||
// 検出したURLごとに処理を行う
|
||||
foreach ($matches[0] as $url) {
|
||||
// ドメイン部分を抽出
|
||||
$parsedUrl = parse_url($url);
|
||||
$domain = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
|
||||
|
||||
// ドメインのみを表示するaタグを生成
|
||||
$link = "<a href='$url' target='_blank'>$domain</a>";
|
||||
|
||||
// URLをドメインのみを表示するaタグで置き換え
|
||||
$postText = str_replace($url, $link, $postText);
|
||||
}
|
||||
|
||||
return $postText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$messages = array();
|
||||
foreach ($message_array as $row) {
|
||||
$messages[] = $row;
|
||||
}
|
||||
// ユーザー情報を取得して、$messages内のusernameをuserDataのusernameに置き換える
|
||||
foreach ($messages as &$message) {
|
||||
$userQuery = $pdo->prepare("SELECT username, userid, profile, role FROM account WHERE userid = :userid");
|
||||
$userQuery->bindValue(':userid', $message["account"]);
|
||||
$userQuery->execute();
|
||||
$userData = $userQuery->fetch();
|
||||
|
||||
if ($userData) {
|
||||
$message['username'] = $userData['username'];
|
||||
}
|
||||
}
|
||||
|
||||
// ユーズ内のHTMLコードに指定のタグを有効化する関数
|
||||
function replaceUnescapedHTMLTags($html) {
|
||||
$allowedTags = array('h1', 'h2', 'h3', 'center', 'font'); // 有効化するタグ
|
||||
return customStripTags($html, $allowedTags);
|
||||
}
|
||||
|
||||
if(!empty($messages)){
|
||||
foreach ($messages as $value) {
|
||||
|
||||
$fav = $value['favorite']; // コンマで区切られたユーザーIDを含む変数
|
||||
|
||||
// コンマで区切って配列に分割し、要素数を数える
|
||||
$favIds = explode(',', $fav);
|
||||
$value["favcnt"] = count($favIds)-1;
|
||||
|
||||
$messageDisplay = new MessageDisplay($value, $userid);
|
||||
$messageDisplay->display();
|
||||
}
|
||||
}else{
|
||||
echo '<div class="tokonone" id="noueuse"><p>ユーズがありません</p></div>';
|
||||
}
|
||||
|
||||
$pdo = null;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
<?php
|
||||
class MessageDisplay {
|
||||
private $value;
|
||||
private $userid;
|
||||
|
||||
public function __construct($value, $userid) {
|
||||
$this->value = $value;
|
||||
$this->userid = $userid;
|
||||
}
|
||||
|
||||
public function display() {
|
||||
if (empty($this->value)) {
|
||||
echo '<div class="tokonone" id="noueuse"><p>ユーズがありません</p></div>';
|
||||
} else {
|
||||
echo '<div class="ueuse">';
|
||||
if(!empty($this->value['rpuniqid'])){
|
||||
echo '<div class="rp"><p>┗━ 一番上のユーズに返信</p></div>';
|
||||
}
|
||||
echo ' <div class="flebox">';
|
||||
|
||||
echo ' <a href="/@' . htmlspecialchars($this->value['account']) . '"><img src="../home/tlimage.php?account=' . urlencode($this->value['account']) . '"></a>';
|
||||
echo ' <a href="/@' . htmlspecialchars($this->value['account']) . '">' . htmlspecialchars($this->value['username']) . '</a>';
|
||||
echo ' <div class="idbox">';
|
||||
echo ' <a href="/@' . htmlspecialchars($this->value['account']) . '">@' . htmlspecialchars($this->value['account']) . '</a>';
|
||||
echo ' </div>';
|
||||
echo ' <div class="time">';
|
||||
$day = date("Ymd", strtotime(htmlspecialchars($this->value['datetime'])));
|
||||
if ($day == date("Ymd")) {
|
||||
echo date("今日 H:i", strtotime(htmlspecialchars($this->value['datetime'])));
|
||||
} else {
|
||||
echo date("Y年m月d日 H:i", strtotime(htmlspecialchars($this->value['datetime'])));
|
||||
}
|
||||
echo ' </div>';
|
||||
|
||||
echo ' </div>';
|
||||
|
||||
echo ' <p>' . replaceEmojisWithImages(replaceURLsWithLinks(nl2br(replaceUnescapedHTMLTags($this->value['ueuse'])))) . '</h1></h2></h3></font></center></p>';
|
||||
|
||||
if (!empty($this->value['photo2']) && $this->value['photo2'] !== 'none') {
|
||||
echo ' <div class="photo2">';
|
||||
echo ' <img src="' . htmlspecialchars($this->value['photo1']) . '" alt="画像">';
|
||||
echo ' <img src="' . htmlspecialchars($this->value['photo2']) . '" alt="画像">';
|
||||
echo ' </div>';
|
||||
} elseif (!empty($this->value['photo1']) && $this->value['photo1'] !== 'none') {
|
||||
echo ' <div class="photo1">';
|
||||
echo ' <img src="' . htmlspecialchars($this->value['photo1']) . '" alt="画像">';
|
||||
echo ' </div>';
|
||||
}
|
||||
if (!empty($this->value['video1']) && $this->value['video1'] !== 'none') {
|
||||
echo ' <div class="video1">';
|
||||
echo ' <video controls src="' . htmlspecialchars($this->value['video1']) . '"></video>';
|
||||
echo ' </div>';
|
||||
}
|
||||
|
||||
if(!($this->value['abi'] == "none")){
|
||||
echo '<div class="abi">';
|
||||
echo ' <div class="back">';
|
||||
echo '<h1>' . htmlspecialchars($this->value['username']) . 'さんが追記しました</h1>';
|
||||
echo ' </div>';
|
||||
echo '<p>'. htmlspecialchars($this->value['abi']) . '</p>';
|
||||
echo '<h3>追記日時 : '. date("Y年m月d日 H:i", strtotime(htmlspecialchars($this->value['abidate']))) . '</h3>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<hr>';
|
||||
echo '<div class="favbox">';
|
||||
if (false !== strstr($this->value['favorite'], $this->userid)) {
|
||||
echo '<button class="favbtn favbtn_after" id="favbtn" data-uniqid="' . htmlspecialchars($this->value['uniqid']) . '" data-userid2="' . htmlspecialchars($this->value['account']) . '"><img src="../img/sysimage/favorite_2.svg" alt="いいね" /> <span class="like-count">' . htmlspecialchars($this->value['favcnt']) . '</span></button>';
|
||||
}else{
|
||||
echo '<button class="favbtn" id="favbtn" data-uniqid="' . htmlspecialchars($this->value['uniqid']) . '" data-userid2="' . htmlspecialchars($this->value['account']) . '"><img src="../img/sysimage/favorite_1.svg" alt="いいね" /> <span class="like-count">' . htmlspecialchars($this->value['favcnt']) . '</span></button>';
|
||||
}
|
||||
echo '<a href="/!'.htmlspecialchars($this->value['uniqid']). '~' . htmlspecialchars($this->value['account']) . '" class="tuduki">返信をみる&する</a>';
|
||||
if($this->value['account'] === $this->userid){
|
||||
if($this->value['abi'] === "none"){
|
||||
echo '<input type="submit" name="addabi" id="addabi" data-uniqid2="' . htmlspecialchars($this->value['uniqid']) . '" class="addabi" value="追記する">';
|
||||
}
|
||||
echo '<input type="submit" name="delueuse" id="uniqid2" data-uniqid2="' . htmlspecialchars($this->value['uniqid']) . '" class="delbtn" value="削除">';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user