-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
390 lines (365 loc) · 12 KB
/
index.php
File metadata and controls
390 lines (365 loc) · 12 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
$dbFile = __DIR__ . '/metadata.sqlite';
$db = new PDO('sqlite:' . $dbFile);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Create the table if it doesn't exist.
$db->exec("
CREATE TABLE IF NOT EXISTS files (
file_name TEXT PRIMARY KEY,
display_name TEXT,
description TEXT
)
");
// Check if the "hidden" column exists; if not, add it.
$columns = $db->query("PRAGMA table_info(files)")->fetchAll(PDO::FETCH_ASSOC);
$hasHidden = false;
foreach ($columns as $col) {
if ($col['name'] === 'hidden') {
$hasHidden = true;
break;
}
}
if (!$hasHidden) {
$db->exec("ALTER TABLE files ADD COLUMN hidden INTEGER DEFAULT 0");
}
} catch (Exception $e) {
die("Database error: " . $e->getMessage());
}
// Process form submissions (POST)
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$itemName = $_POST['file'] ?? '';
$display_name = $_POST['display_name'] ?? '';
$description = $_POST['description'] ?? '';
$hidden = isset($_POST['hidden']) ? 1 : 0;
if ($itemName && $display_name) {
$stmt = $db->prepare("
INSERT OR REPLACE INTO files (file_name, display_name, description, hidden)
VALUES (?, ?, ?, ?)
");
$stmt->execute([$itemName, $display_name, $description, $hidden]);
}
$redirect = $_SERVER['PHP_SELF'];
if (isset($_GET['show_hidden'])) {
$redirect .= '?show_hidden=' . $_GET['show_hidden'];
}
header("Location: $redirect");
exit;
}
// Check whether hidden items should be shown
$show_hidden = (isset($_GET['show_hidden']) && $_GET['show_hidden'] == '1');
// Scan the current directory, ignoring this PHP file and the database file
$ignoreList = [
'.', '..', basename(__FILE__), basename($dbFile)
];
$allItems = array_diff(scandir(__DIR__), $ignoreList);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Florian's File Manager Tool (FFMT)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.container-root {
display: flex;
flex-direction: column;
align-items: center;
background: #ffffff;
min-height: 100vh;
padding: 20px;
box-sizing: border-box;
}
.header {
text-align: center;
margin-bottom: 20px;
}
.header-title {
font-family: sans-serif;
font-size: 28px;
font-weight: bold;
margin: 0;
padding: 0;
}
.tabs-container {
border-bottom: 1px solid rgba(0,0,0,0.12);
margin-bottom: 20px;
width: 100%;
max-width: 800px;
display: flex;
justify-content: space-evenly;
}
.tab-btn {
padding: 10px 20px;
cursor: pointer;
text-align: center;
}
.tab-btn .highlight {
border-bottom: 2px solid #4e3cdb;
font-weight: bold;
color: #4e3cdb;
}
.item-row {
border-bottom: 1px solid rgba(0,0,0,0.12);
padding: 10px 0;
width: 100%;
max-width: 800px;
display: flex;
justify-content: space-between;
align-items: center;
}
.item-info {
display: flex;
flex-direction: column;
}
.item-info a {
text-decoration: none;
color: #000;
}
.item-title {
font-weight: bold;
font-size: 18px;
margin: 0;
padding: 0;
display: flex;
align-items: center;
gap: 8px;
}
.item-desc {
font-size: 14px;
margin: 0;
padding: 0;
}
.icon-file {
width: 16px;
height: 16px;
display: inline-block;
}
.icon-folder {
width: 16px;
height: 16px;
display: inline-block;
}
.edit-icon {
cursor: pointer;
width: 24px;
height: 24px;
}
.edit-form {
display: none;
padding: 10px 0;
background: #f7f7f7;
border-top: 1px solid rgba(0,0,0,0.12);
}
.edit-form input[type="text"] {
width: 100%;
margin-bottom: 10px;
padding: 6px;
border: 1px solid #ccc;
border-radius: 4px;
}
.edit-form button {
padding: 6px 12px;
background: #4e3cdb;
color: #fff;
border: none;
border-radius: 4px;
}
.fab-container {
margin-top: 20px;
width: 100%;
max-width: 800px;
display: flex;
justify-content: flex-end;
}
.fab {
background: #4e3cdb;
color: #fff;
border-radius: 30px;
padding: 12px 20px;
cursor: pointer;
display: inline-flex;
align-items: center;
font-weight: bold;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.fab svg {
width: 24px;
height: 24px;
margin-right: 8px;
}
.footer {
margin-top: 40px;
text-align: center;
color: #888;
}
.extension-pill,
.extension-pill * {
box-sizing: border-box;
}
.extension-pill {
background: #4e3cdb;
border-radius: 360px;
padding: 2px 9px;
display: inline-flex;
flex-direction: row;
gap: 4px;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
}
.extension-pill-text {
color: #ffffff;
font-family: 'DmSans-Bold', sans-serif;
font-size: 14px;
line-height: 135%;
font-weight: 700;
display: flex;
align-items: center;
justify-content: flex-start;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div class="container-root">
<div class="header">
<h1 class="header-title">Florian's File Manager Tool (FFMT)</h1>
</div>
<!-- Tabs: normal items vs. hidden items -->
<div class="tabs-container">
<div class="tab-btn" onclick="window.location.href='<?php echo $_SERVER['PHP_SELF']; ?>'">
<?php if (!$show_hidden) { ?>
<span class="highlight">Files & Folders</span>
<?php } else { ?>
<span>Files & Folders</span>
<?php } ?>
</div>
<div class="tab-btn" onclick="window.location.href='<?php echo $_SERVER['PHP_SELF']; ?>?show_hidden=1'">
<?php if ($show_hidden) { ?>
<span class="highlight">Hidden</span>
<?php } else { ?>
<span>Hidden</span>
<?php } ?>
</div>
</div>
<?php
foreach ($allItems as $item) {
// Fetch metadata (display_name, description, hidden)
$stmt = $db->prepare("SELECT display_name, description, hidden FROM files WHERE file_name = ?");
$stmt->execute([$item]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$displayName = $row ? $row['display_name'] : $item;
$description = $row ? $row['description'] : '';
$isHidden = ($row && $row['hidden'] == 1);
// If hidden and not showing hidden, skip
if ($isHidden && !$show_hidden) {
continue;
}
// Distinguish file vs. directory
$isDir = is_dir(__DIR__ . '/' . $item);
// The link
$openLink = $item;
if ($isDir && substr($openLink, -1) !== '/') {
$openLink .= '/';
}
// Icon for file vs folder
if ($isDir) {
// Folder icon
$typeIcon = '<svg class="icon-folder" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 4H10L12 6H21C21.5523 6 22 6.44772 22 7V19C22 19.5523 21.5523 20 21 20H3C2.44772 20 2 19.5523 2 19V5C2 4.44772 2.44772 4 3 4Z" fill="#4e3cdb"/>
</svg>';
} else {
// File icon
$typeIcon = '<svg class="icon-file" viewBox="0 0 24 24" fill="#4e3cdb" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H7C5.89543 2 5 2.89543 5 4V20C5 21.1046 5.89543 22 7 22H17C18.1046 22 19 21.1046 19 20V8L14 2Z"></path>
</svg>';
}
// If it's a file, detect the extension
$fileExt = '';
if (!$isDir) {
$ext = pathinfo($item, PATHINFO_EXTENSION);
if (!empty($ext)) {
$fileExt = $ext; // e.g. 'csv', 'pdf', etc.
}
}
?>
<div class="item-row">
<div class="item-info">
<a href="<?php echo htmlspecialchars($openLink); ?>" target="_blank">
<p class="item-title">
<!-- Show the folder/file icon before the text -->
<?php echo $typeIcon; ?>
<!-- Display name -->
<?php echo htmlspecialchars($displayName); ?>
<?php if ($isDir) {
// Optionally show slash
echo '/';
} else {
// If it's a file, show extension pill if extension is found
if ($fileExt) {
?>
<span class="extension-pill">
<span class="extension-pill-text">.<?php echo htmlspecialchars($fileExt); ?></span>
</span>
<?php
}
} ?>
</p>
<p class="item-desc"><?php echo htmlspecialchars($description); ?></p>
</a>
</div>
<div class="edit-icon" onclick="toggleEditForm('<?php echo md5($item); ?>')">
<svg fill="#4e3cdb" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 25">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M16.8388 4.83187L3.58486 18.0858C2.80381 18.8668 2 22.5 2 22.5C2 22.5 5.63224 21.6953 6.41329 20.9142L19.6672 7.6603L16.8388 4.83187ZM20.7931 6.53439L21.4133 5.91421C22.1943 5.13317 22.1943 3.86684 21.4133 3.08579C20.6322 2.30474 19.3659 2.30474 18.5849 3.08579L17.9647 3.70596L20.7931 6.53439Z"/>
</svg>
</div>
</div>
<div class="edit-form" id="edit-<?php echo md5($item); ?>">
<form method="post">
<input type="hidden" name="file" value="<?php echo htmlspecialchars($item); ?>">
<input type="text" name="display_name" placeholder="Display Name" value="<?php echo htmlspecialchars($displayName); ?>">
<input type="text" name="description" placeholder="Description" value="<?php echo htmlspecialchars($description); ?>">
<div style="margin-bottom:8px;">
<label>
<input type="checkbox" name="hidden" value="1" <?php if ($isHidden) echo 'checked'; ?>>
Hide item
</label>
</div>
<button type="submit">Save</button>
</form>
</div>
<?php } // end foreach ?>
<div class="fab-container">
<div class="fab" onclick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . ($show_hidden ? '' : '?show_hidden=1'); ?>'">
<svg viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M3.09771 12.7056C3.04645 12.603 3.02156 12.5359 3.00968 12.5C3.02156 12.4641 3.04645 12.397 3.09771 12.2944C3.19644 12.0968 3.35667 11.8395 3.58396 11.5384C4.03725 10.938 4.71133 10.2241 5.55749 9.54026C7.26277 8.16211 9.54678 7 12 7C14.4532 7 16.7372 8.16211 18.4425 9.54026C19.2887 10.2241 19.9627 10.938 20.416 11.5384C20.6433 11.8395 20.8036 12.0968 20.9023 12.2944C20.9535 12.397 20.9784 12.4641 20.9903 12.5C20.9784 12.5359 20.9535 12.603 20.9023 12.7056C20.8036 12.9032 20.6433 13.1605 20.416 13.4616C19.9627 14.062 19.2887 14.7759 18.4425 15.4597C16.7372 16.8379 14.4532 18 12 18C9.54678 18 7.26277 16.8379 5.55749 15.4597C4.71133 14.7759 4.03725 14.062 3.58396 13.4616C3.35667 13.1605 3.19644 12.9032 3.09771 12.7056Z"
fill="white"/>
</svg>
<?php echo $show_hidden ? 'Hide Hidden' : 'Show All'; ?>
</div>
</div>
<div class="footer">
© <?php echo date('Y'); ?> florian stravock
</div>
</div>
<script>
function toggleEditForm(id) {
var form = document.getElementById('edit-' + id);
if (form.style.display === 'block') {
form.style.display = 'none';
} else {
form.style.display = 'block';
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>