-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhistory.php
246 lines (210 loc) · 9.01 KB
/
history.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
session_start();
include('config.php');
$langrow = $defaultLang;
include('lang.php');
if ($useSQL == true) {
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("SELECT * FROM login WHERE username = ?");
$stmt->bind_param("s", $_SESSION['logged_in_user']);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc())
{
$pwrow = $row['password'];
$customthemehomerow = $row['customtheme_home_url'];
$langrow = $row['lang'];
}
if ($_SESSION['hashed_pass'] == $pwrow) {
} else {
session_destroy();
}
} else {
session_destroy();
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Liberatube · <?php echo $translations[$langrow]['watch_history']; ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="Liberatube">
<link rel="apple-touch-icon" href="favicon.ico">
<link rel="stylesheet" href="/styles/-w3.css">
<link rel="stylesheet" href="/styles/-bootstrap.min.css">
<?php
$dbsenduser = $_SESSION['logged_in_user'];
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_SESSION['logged_in_user']))
{
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("SELECT * FROM login WHERE username = ?");
$stmt->bind_param("s", $_SESSION['logged_in_user']);
$stmt->execute();
$result = $stmt->get_result();
$numrows = $result->num_rows;
while ($row = $result->fetch_assoc())
{
$themerow = $row['theme'];
}
$numrows = $result->num_rows;
}
if(strcmp($themerow, 'blue') == 0) {
echo '<link rel="stylesheet" href="../styles/homeblue.css">';
} elseif(strcmp($themerow, 'ultra-dark') == 0) {
echo '<link rel="stylesheet" href="../styles/homeultra-dark.css">';
} elseif ($themerow == "custom") {
echo '<link rel="stylesheet" href="'.$customthemehomerow.'">';
} else {
echo '<link rel="stylesheet" href="../styles/home'.$defaultTheme.'.css">';
}
?>
<body>
<div class="w3-sidebar w3-bar-block w3-collapse w3-card sidebar" style="width:55px;" id="mySidebar">
<button class="w3-bar-item w3-button w3-large w3-hide-large" onclick="w3_close()">×</button>
<a href="/" class="w3-bar-item sidebarbtn awhitesidebar"><span class="material-symbols-outlined">home</span><span class="tooltiptext"><?php echo $translations[$langrow]['home']; ?></span></a>
<a href="/history.php" class="w3-bar-item sidebarbtn awhitesidebar sidebarbtn-selected"><span class="material-symbols-outlined">history</span><span class="tooltiptext"><?php echo $translations[$langrow]['watch_history']; ?></span></a>
<a href="/playlist/playlists.php" class="w3-bar-item sidebarbtn awhitesidebar"><span class="material-symbols-outlined">list_alt</span><span class="tooltiptext"><?php echo $translations[$langrow]['playlists']; ?></span></a>
<a href="/subscriptions.php" class="w3-bar-item sidebarbtn awhitesidebar"><span class="material-symbols-outlined">subscriptions</span><span class="tooltiptext"><?php echo $translations[$langrow]['subscriptions']; ?></span></a>
<a href="/settings.php" class="w3-bar-item sidebarbtn awhitesidebar"><span class="material-symbols-outlined">settings</span><span class="tooltiptext"><?php echo $translations[$langrow]['settings']; ?></span></a>
</div>
<div class="w3-main" style="margin-left:55px">
<div class="w3-tssseal">
<button class="w3-button w3-darkgrey w3-xlarge w3-hide-large" onclick="w3_open()">☰</button>
<div class="w3-container">
<div class="topbar">
<div class="topbarelements topbarelements-center">
<h3 class="title-top topbarelements"><?php echo $translations[$langrow]['watch_history']; ?></h3>
</div>
<div class="topbarelements topbarelements-right">
<h4> <?php echo $_SESSION['logged_in_user']; ?>
<?php if(isset($_SESSION['logged_in_user']))
{
echo '<a class="button awhite login-item" href="/auth/logout.php"><span class="material-symbols-outlined login-item-icon">logout</span><h5 class="login-item-text">'.$translations[$langrow]['logout'].'</h5></a>';
}
else
{
echo '<a class="button awhite login-item" href="/auth/login.html"><span class="material-symbols-outlined login-item-icon">login</span><h5 class="login-item-text">'.$translations[$langrow]['login-signup'].'</h5></a>';
}
?>
</div>
</div>
</div>
<script src="/scripts/sidebar.js"></script>
<div class="tenborder">
<?php
if(isset($_SESSION['logged_in_user'])) { ?>
<div style="text-align: center;">
<?php
if ($useSQL == true) {
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_POST['remove-vid'] && $_POST['timestamp']) {
$videoIdToRemove = $_POST['remove-vid'];
$timestampToRemove = $_POST['timestamp'];
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("SELECT * FROM login WHERE username = ?");
$stmt->bind_param("s", $_SESSION['logged_in_user']);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$watchHistory = json_decode($row['watch_history'], true);
// Filter out the video with matching video_id and timestamp
$watchHistory = array_filter($watchHistory, function($item) use ($videoIdToRemove, $timestampToRemove) {
return $item['video_id'] !== $videoIdToRemove || $item['timestamp'] !== $timestampToRemove;
});
// Reindex array
$watchHistory = array_values($watchHistory);
$updatedWatchHistory = json_encode($watchHistory);
$updateStmt = $conn->prepare("UPDATE login SET watch_history = ? WHERE username = ?");
$updateStmt->bind_param("ss", $updatedWatchHistory, $_SESSION['logged_in_user']);
$updateStmt->execute();
$updateStmt->close();
}
}
$stmt = $conn->prepare("SELECT watch_history FROM login WHERE username = ?");
$stmt->bind_param("s", $_SESSION['logged_in_user']);
$stmt->execute();
$result = $stmt->get_result();
$watchHistory = [];
while ($row = $result->fetch_assoc()) {
$watchHistory = json_decode($row['watch_history'], true);
}
$stmt->close();
$conn->close();
if (!is_array($watchHistory)) {
$watchHistory = [];
} else {
$watchHistory = array_reverse($watchHistory);
}
$groupedWatchHistory = [];
foreach ($watchHistory as $item) {
$date = (new DateTime($item['timestamp']))->format('d M Y');
$time = (new DateTime($item['timestamp']))->format('H:i:s');
$item['time'] = $time;
if (!isset($groupedWatchHistory[$date])) {
$groupedWatchHistory[$date] = [];
}
$groupedWatchHistory[$date][] = $item;
}
}
if (count($groupedWatchHistory) > 0) {
foreach ($groupedWatchHistory as $date => $videos) { ?>
<h3><?php echo htmlspecialchars($date); ?></h3>
<?php foreach ($videos as $item) {
$title = htmlspecialchars($item['title']);
$author = htmlspecialchars($item['author']);
$videoId = htmlspecialchars($item['video_id']);
$time = htmlspecialchars($item['time']);
$timestamp = htmlspecialchars($item['timestamp']); // Assume 'timestamp' exists in the watch history
echo <<<HTML
<a class="awhite" href="/watch/?v={$videoId}">
<div class="video-tile w3-animate-left">
<div class="videoDiv">
<img src="http://i.ytimg.com/vi/{$videoId}/mqdefault.jpg" width="256px">
<div class="button-on-vid">
<form method="POST" action="" style="display:inline;">
<input type="hidden" name="remove-vid" value="{$videoId}">
<input type="hidden" name="timestamp" value="{$timestamp}">
<button type="submit" class="remove-button"><span class="material-symbols-outlined">delete</span></button>
</form></div>
</div>
<div class="videoInfo">
<div class="videoTitle">
<b>{$title}</b><br>{$author} <div style="float: right;">{$time}</div>
</div>
</div>
</div>
</a>
HTML;
} ?>
<?php }
} ?>
<?php } else { ?>
<h4 style="text-align: center;">You are not logged in.</h4>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>