Skip to content

Commit 9804859

Browse files
committed
live refresh back again
1 parent 71e0742 commit 9804859

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

messages.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22
session_start();
33
require_once "pdo.php";
4-
if (!isset($_SESSION["email"])) {
4+
/*if (!isset($_SESSION["email"])) {
55
echo "<p class='die-msg'>PLEASE LOGIN</p>";
66
echo '<link rel="stylesheet" href="./style.css?v=<?php echo time(); ?>">';
77
echo "<br />";
88
echo "<p class='die-msg'>Redirecting in 3 seconds</p>";
99
header("refresh:3;url=index.php");
1010
die();
11-
}
11+
}*/
1212
require_once "pdo.php";
1313
function loadChat($pdo)
1414
{
@@ -20,7 +20,7 @@ function loadChat($pdo)
2020
echo "<p style='text-align:center;color: #ffa500;'>This is the start of all messages</p>";
2121
foreach ($rows as $row) {
2222
$pfpsrc = './img/default-pfp.png';
23-
$user = "<a href='./profile.php?user={$row['account']}' class='account rainbow_text_animated'>" . $row['account'] . "</a>";
23+
$user = "<a href='./profile.php?user={$row['user_id']}' class='account rainbow_text_animated'>" . $row['account'] . "</a>";
2424

2525
$stmta = $pdo->prepare("SELECT pfp FROM account WHERE name=?");
2626
$stmta->execute([$row['account']]);
@@ -31,10 +31,16 @@ function loadChat($pdo)
3131
$pfpsrc = $test['pfp'];
3232
}
3333
}
34-
$pfp = "<a class='pfp-link' href='./profile.php?user={$row['account']}'><img class='profile-image' src='$pfpsrc'></a>";
34+
$pfp = "<a class='pfp-link' href='./profile.php?user={$row['user_id']}'><img class='profile-image' src='$pfpsrc'></a>";
3535

3636

37-
$message = htmlentities($row["message"]);
37+
$pattern = "/@" . $_SESSION['name'] . "/i";
38+
if (preg_match($pattern, $row["message"])) {
39+
$message = "<span class='user-ping'>" . htmlentities($row["message"]) . "</span>";
40+
} else {
41+
$message = htmlentities($row["message"]);
42+
}
43+
3844
if (isset($_COOKIE['timezone'])) {
3945

4046
//might break the chat
@@ -50,8 +56,12 @@ function loadChat($pdo)
5056
}
5157
$msg_parent_id = $row['message_id'] . "parent";
5258
$info = "<p class='stats'>{$user} ({$stamp})</p>";
53-
$editBtn = "<button class='btn' onclick='handleEdit({$row['message_id']})'>Edit {$row['message_id']}</button>";
54-
$msg = "<p class='msg' id='{$msg_parent_id}'><span id='{$row['message_id']}'>{$message}</span> {$editBtn}</p>";
59+
if ($row['user_id'] == $_SESSION['user_id']) {
60+
$editBtn = "<button class='chat-btn' onclick='handleEdit({$row['message_id']})'>Edit</button>";
61+
} else {
62+
$editBtn = "";
63+
}
64+
$msg = "<p class='msg' id='{$msg_parent_id}'><span id='{$row['message_id']}'>{$message}</span>" . $editBtn . "</p>";
5565
echo $pfp;
5666
echo "<div style='margin-left: 10px;margin-top: 18px;'>{$info}{$msg}</div>";
5767
}

0 commit comments

Comments
 (0)