-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat_r.php
111 lines (90 loc) · 2.96 KB
/
chat_r.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
require_once("./php/htmlHelper.php");
require_once("./php/sql.php");
$pdo = GetPDO();
RequireLogin();
$chan = $_GET["chan"];
if (str_starts_with($chan, "#")) {
$req = $pdo->prepare("SELECT 1 FROM ultraverse.channels WHERE name = :name;");
$req->execute([":name" => $chan]);
$req->fetchAll();
if ($req->rowCount() == 0) {
http_response_code(404);
echo render_php("404.php");
die();
}
else {
GenerateHeader("register.jpg", "Chat > ".$chan , 150);
}
}
elseif (str_starts_with($chan, "~")) {
http_response_code(404);
echo render_php("404.php");
die();
}
elseif (is_numeric($chan)) {
if (!GetUserData($chan)) {
http_response_code(404);
echo render_php("404.php");
die();
}
else {
GenerateHeader("register.jpg", "Chat > ".GetUserData($chan)["username"] , 150);
}
}
else {
http_response_code(404);
echo render_php("404.php");
die();
}
if (isset($_POST['chat'])) {
$message= nl2br(htmlspecialchars($_POST['chat']));
$inserer_message = $pdo->prepare('INSERT INTO messages (message, uid, channel) VALUES(?, ?, ?)');
$inserer_message->execute(array(htmlspecialchars($message, ENT_QUOTES), GetID(), $chan));
die();
}
?>
<div id="chatdiv" style="height: 72%;overflow: scroll;">
<div id="message"></div>
</div>
<form id="chat" class="ui form" method="post" action="<?= $_SERVER['REQUEST_URI'] ?>" >
<div class="field">
<input id type="text" name="chat" placeholder="send message" required id="messageInput">
</div>
<section id="message">
</section>
<script>
var lastMSGID = 0;
setInterval('load_message()',1000);
function load_message() {
$('#message').load('/load_chat.php?chan=<?= urlencode($chan) ?>');
/*
*/
let t = $('div.channel-message-tab:last').attr("id");
if (t != lastMSGID) {
lastMSGID = t
$('#chatdiv').animate({
scrollTop: 90000
},0);
}
}
let form = $("#chat")
form.submit(function(){
$.post($(this).attr('action'), $(this).serialize(), function(response){},'json');
console.log("A");
setTimeout(() => {
$("#messageInput").val('')
form.removeClass("loading");
}, 1000);
return false;
});
function delete_msg(id) {
$.post("/api/message_delete?id="+id);
}
function edit_msg(id) {
$msg = prompt("Edit your message", $("#msg-"+id).attr("cont"))
$.post("/api/edit?id="+id+"&msg="+$msg);
}
</script>
</form>
<?php GenerateFooter(); ?>