-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhashtable.php
executable file
·166 lines (152 loc) · 5.84 KB
/
hashtable.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
<?php
include 'config/memberTop.php';
include_once 'config/uploadDBconfig.php';
$user = htmlspecialchars($_SESSION['username']);
// add playlist column if non-existant.
if($playlistCheck = $link->query("SELECT playlist FROM '".$user."'")) {
echo '';
} else {
$addPlaylist = "ALTER TABLE ".$_SESSION['username']." ADD playlist TINYINT(1);";
$link->query($addPlaylist);
}
//Check for deletion
if (!empty($_GET['delete'])) {
$sqlDelete = "DELETE FROM ".$user." WHERE id='".$_GET["delete"]."'";
$delRun = mysqli_query($link, $sqlDelete);
$rm = shell_exec(escapeshellcmd("rm uploads/".$_GET['delete']));
}
// Check for add to playlist
if (!empty($_GET['addPlay'])) {
$sqlAddPlay = "UPDATE ".$user." SET playlist = 1, date = date WHERE id='".$_GET['addPlay']."'";
$runAddPlay = mysqli_query($link, $sqlAddPlay);
}
// Check for removal from playlist
if (!empty($_GET['delPlay'])) {
$sqlDelPlay = "UPDATE ".$user." SET playlist = 0, date = date WHERE id='".$_GET['delPlay']."'";
$runDelPlay = mysqli_query($link, $sqlDelPlay);
}
// query user data
$sql = "SELECT * FROM ".$user." ORDER BY date DESC;";
$result = mysqli_query($link, $sql);
$resultCheck = mysqli_num_rows($result);
?>
<h3>Your personal Nebulus Database! </h3>
</div>
<div class="d-flex flex-column align-items-center">
<?php
if ($resultCheck > 0) {
// loop through users' table and output into html table body
while ($row = mysqli_fetch_assoc($result)) {
$playlist = $row["playlist"];
$fileName = $row["file_name"];
$hash = $row["hash"];
$fileSize = round(($row["file_size"]/1000000), 2);
$id = $row["id"];
// already escaped on upload to server
$title = $row["title"];
$des = $row["des"];
// if user playlist column for the content is '0'
// show the add button else show the remove button.
if ($playlist == 0) {
$onList = '
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Add to</button>
<div class="dropdown-menu">
<a class="dropdown-item" name="addPlay" href="?addPlay='.$id.'">Yes, add to playlist.</a>
</div>
</div>';
} else {
$onList = '
<div class="btn-group">
<button type="button" class="btn btn-warning dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Remove</button>
<div class="dropdown-menu">
<a class="dropdown-item" name="delPlay" href="?delPlay='.$id.'">Yes, remove from playlist.</a>
</div>
</div>';
}
// set up for content display
$fileExt = explode('.', $id);
$ext = strtolower(end($fileExt));
$images = array('jpg', 'jpeg', 'png');
$audios = array('mp3', 'wav');
$videos = array('mp4', 'm4v', 'webm');
// determine how to show the content
if (in_array($ext, $images)){
$display = '
<div class="card-img-top" style="width:100%">
<img src="uploads/'.$id.'" style="width:100%" />
</div>';
} else if (in_array($ext, $audios)){
$display = '
<div class="card-img-top" style="width:100%">
<audio controls style="width:100%">
<source src="uploads/'.$id.'" type="audio/'.$ext.'">
Your browser does not support the audio tag.
</audio>
</div>';
} else if (in_array($ext, $videos)){
$display = '
<div class="card-img-top" style="width:100%">
<video style="width:100%" controls>
<source src="uploads/'.$id.'" type="video/'.$ext.'">
Your browser does not support the video tag.
</video>
</div>';
} else {
$display = '<h5 style="text-align:center;padding:15px;">The '.$ext.
' media format is not currently supported.</h5>';
}
// echo out content cards for users to see the uploaded file, add a title,
// add a description, grad the link, add to their playlist,
// and delete the content from the server.
echo '
<div class="card mb-3" style="min-width:100%" >
'.$display.'
<div class="card-body text-dark">
<h3 class="card-title">'.$fileName.'</h3>
<p class="card-text">
<form enctype="multipart/form-data" action="execs/rssMeta.php" method="POST">
<span style="font-weight: bold">Title:</span>
<input name="title" type="text" class="form-control" placeholder="'
.$title.'"><br />
<span style="font-weight: bold">Description:</span>
<textarea name="des" class="form-control" rows="3" placeholder="'
.$des.'"></textarea><br />
<input type="hidden" name="rowID" value="'.$id.'">
<button type="submit" class="btn btn-primary">Submit</button>
</form><br />
<strong>File Type: </strong>'.$ext.'<br />
<strong>IPFS Link: </strong>
<a href="https://ipfs.io/ipfs/'.$hash.'" target="_blank">'.$hash.'</a><br />
<strong>Size: </strong>'.$fileSize.' MB
</p>
<div class="row">
<div class="col d-flex justify-content-start">
<span style="font-weight: bold">Playlist:</span>
</div>
<div class="col d-flex justify-content-end">
<span style="font-weight: bold"></span>
</div>
</div>
<div class="row">
<div class="col d-flex justify-content-start">'.$onList.'</div>
<div class="col d-flex justify-content-end">
<div class="btn-group">
<button type="button" class="btn btn-danger dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Delete</button>
<div class="dropdown-menu">
<a class="dropdown-item" name="id" href="?delete='.$id.'">Yes, delete forever.</a>
</div>
</div><!-- delete button group -->
</div><!-- column for button group -->
</div><!-- class row -->
</div><!-- card body -->
</div><!-- card -->';
}
}
?>
</div>
<?php include 'config/bottom.html'; ?>