-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
232 lines (202 loc) · 10.3 KB
/
index.php
File metadata and controls
232 lines (202 loc) · 10.3 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<div class="container-sm" style="height: 100px;">
<?php
/**
* renders the homepage together
* with the chat block(user list)
*/
require_once dirname(__FILE__) . '/bootstrap.php';
$me = [];
$users = [];
// $fake = new \Nick\PhpSse\BlogFactory();
// $fake->initGenerate();
// $fake->generateFakeMessages();
$dbConn = new \Nick\PhpSse\DbConn();
$renderer = new \Nick\PhpSse\Renderer();
$entityManager = $dbConn->entityManager;
$uid = (int) $_GET["me"];
$userQb = $entityManager->createQueryBuilder();
$usersQb = $entityManager->createQueryBuilder();
$user = $userQb->select('u.id', 'u.email', 'u.username')
->from(\Nick\PhpSse\Entity\User::class, 'u')
->where('u.id = :uid')
->setParameter('uid', $uid)
->getQuery()
->getResult();
if (isset($user[0]['id'])) {
$me['id'] = $user[0]['id'];
$me['username'] = $user[0]['username'];
$me['email'] = $user[0]['email'];
$users = $usersQb->select('u.id', 'u.username')
->from(\Nick\PhpSse\Entity\User::class, 'u')
//->where($usersQb->expr()->not($usersQb->expr()->eq('u.id', ':uid')))
->where('u.id != :uid')
->orderBy('u.id', 'ASC')
->setParameter('uid', $uid)
->getQuery()
->getArrayResult();
}
if (empty($me)) {
header("Location: /login.php");
exit();
?>
<?php
}
if (!empty($me)){
?>
<span>
<h1>Me</h1>
<pre>
id: <?php echo($me['id']);?>
username: <?php echo($me['username']);?>
email: <?php echo($me['email']);?>
</pre>
</span>
<h1>Live Chat with Server sent events in PHP!</h1>
<!--- @todo start here --->
<div class="row g-2" style="height: 500px;">
<!-- Chat messages -->
<div class="col h-100 bg-secondary overflow-scroll">
<div class="p-3 border">Messages</div>
<?php
// load fake template for now
?>
<div class="card">
<div class="card-body">
<div class="d-flex flex-row justify-content-start">
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava3-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
<div>
<p class="small p-2 ms-3 mb-1 rounded-3" style="background-color: #f5f6f7;">Hi</p>
<p class="small p-2 ms-3 mb-1 rounded-3" style="background-color: #f5f6f7;">How are you ...???
</p>
<p class="small p-2 ms-3 mb-1 rounded-3" style="background-color: #f5f6f7;">What are you doing
tomorrow? Can we come up a bar?</p>
<p class="small ms-3 mb-3 rounded-3 text-muted">23:58</p>
</div>
</div>
<div class="divider d-flex align-items-center mb-4">
<p class="text-center mx-3 mb-0" style="color: #a2aab7;">Today</p>
</div>
<div class="d-flex flex-row justify-content-end mb-4 pt-1">
<div>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">Hiii, I'm good.</p>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">How are you doing?</p>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">Long time no see! Tomorrow
office. will
be free on sunday.</p>
<p class="small me-3 mb-3 rounded-3 text-muted d-flex justify-content-end">00:06</p>
</div>
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava4-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
</div>
<div class="d-flex flex-row justify-content-start mb-4">
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava3-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
<div>
<p class="small p-2 ms-3 mb-1 rounded-3" style="background-color: #f5f6f7;">Okay</p>
<p class="small p-2 ms-3 mb-1 rounded-3" style="background-color: #f5f6f7;">We will go on
Sunday?</p>
<p class="small ms-3 mb-3 rounded-3 text-muted">00:07</p>
</div>
</div>
<div class="d-flex flex-row justify-content-end mb-4">
<div>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">That's awesome!</p>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">I will meet you Sandon Square
sharp at
10 AM</p>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">Is that okay?</p>
<p class="small me-3 mb-3 rounded-3 text-muted d-flex justify-content-end">00:09</p>
</div>
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava4-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
</div>
<div class="d-flex flex-row justify-content-start mb-4">
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava3-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
<div>
<p class="small p-2 ms-3 mb-1 rounded-3" style="background-color: #f5f6f7;">Okay i will meet
you on
Sandon Square</p>
<p class="small ms-3 mb-3 rounded-3 text-muted">00:11</p>
</div>
</div>
<div class="d-flex flex-row justify-content-end mb-4">
<div>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">Do you have pictures of Matley
Marriage?</p>
<p class="small me-3 mb-3 rounded-3 text-muted d-flex justify-content-end">00:11</p>
</div>
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava4-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
</div>
<div class="d-flex flex-row justify-content-start mb-4">
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava3-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
<div>
<p class="small p-2 ms-3 mb-1 rounded-3" style="background-color: #f5f6f7;">Sorry I don't
have. i
changed my phone.</p>
<p class="small ms-3 mb-3 rounded-3 text-muted">00:13</p>
</div>
</div>
<div class="d-flex flex-row justify-content-end">
<div>
<p class="small p-2 me-3 mb-1 text-white rounded-3 bg-primary">Okay then see you on sunday!!
</p>
<p class="small me-3 mb-3 rounded-3 text-muted d-flex justify-content-end">00:15</p>
</div>
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava4-bg.webp"
alt="avatar 1" style="width: 45px; height: 100%;">
</div>
</div>
<div class="card-footer text-muted d-flex justify-content-start align-items-center p-3">
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava3-bg.webp"
alt="avatar 3" style="width: 40px; height: 100%;">
<input type="text" class="form-control form-control-lg" id="exampleFormControlInput1"
placeholder="Type message">
<a class="ms-1 text-muted" href="#!"><i class="fas fa-paperclip"></i></a>
<a class="ms-3 text-muted" href="#!"><i class="fas fa-smile"></i></a>
<a class="ms-3" href="#!"><i class="fas fa-paper-plane"></i></a>
</div>
</div>
</div>
<!-- users list -->
<div class="col-4 h-100 text-center overflow-scroll">
<div class="p-2 border">
<div class="card-body">
<h5 class="card-title">Users</h5>
</div>
<div class="card w-100">
<?php echo $renderer->renderList($users); ?>
</div>
</div>
</div>
<script>
// withCredentials=true: pass the cross-domain cookies to server-side
const source = new EventSource('http://localhost:8080/sse.php', {withCredentials: true});
source.addEventListener('news', function (event) {
console.log(event.data);
// source.close(); // disconnect stream
}, false);
</script>
</div>
<?php
}
?>
</div>
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>