-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetFiles.php
More file actions
executable file
·89 lines (78 loc) · 3.31 KB
/
getFiles.php
File metadata and controls
executable file
·89 lines (78 loc) · 3.31 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
<?php
$time_start = microtime(true);
require_once("util.php");
if (!isset($_GET["page"]) || (isset($_GET["page"]) && $_GET["page"] == 1))
$page = 0;
else
$page = $_GET["page"] - 1;
$numFiles = 20;
$offset = $page * $numFiles;
$sql = SQLCon::getSQL();
//$userGroup = currentLogin();
$userGroup = currentLogin();
$currentUserID = getCurrentUserID();
$queryString = "SELECT File_ID, FilePath, User_ID, Type, CreatedTime, MinGroup, Unlisted, OtherPerms, NSFW, Description, t.Username
FROM Files JOIN UserData t on Files.User_ID = t.ID
WHERE MinGroup <= '$userGroup' AND (Unlisted = 0 OR (User_ID = '$currentUserID' && Unlisted = 1))";
if ($currentUserID == 80) {
$queryString .= " AND User_ID != 99";
}
$queryString .= " ORDER BY File_ID DESC";
if ($page != -1) {
$queryString .= " LIMIT " . $offset . "," . $numFiles;
}
$result = $sql->sQuery($queryString)->fetchAll();
if (count($result) == 0)
{
ob_clean();
header("HTTP/1.0 404 Not Found");
echo "-1";
exit();
}
$files = array();
for ($i = 0; $i < count($result); $i++)
{
$file = array();
for ($j = 0; $j < count($result[0]); $j++) //j here is less than 5 because 5 column, 5 details from mysql
{
$refOpen = "<a href='/view.php?name=".$result[$i][1]."'>";
$refClose = "</a>";
if ($j == 0)
array_push($file, $result[$i][0]);
else if ($j == 1)
array_push($file, $refOpen . $result[$i][9] . $refClose);
else if ($j == 2)
{
if (in_array(getExtension($result[$i][1]), File::$pictureEXTs) && $result[$i][8] != 1)
array_push($file, $refOpen . "<img src='file.php?name=".htmlspecialchars($result[$i][1], ENT_QUOTES)."&t' style='max-width:128px' alt='".htmlspecialchars($result[$i][9], ENT_QUOTES)." thumbnail'/>" . $refClose);
else if ($result[$i][8] == 1)
array_push($file, "Sp00ky NSFW");
}
else if ($j == 3)
array_push($file, $result[$i][10]);
else if ($j == 4)
array_push($file, $result[$i][3]);
else if ($j == 5)
{
$completeFilePath = Constants::DEFAULT_FILE_STORAGE_PATH . $result[$i]["FilePath"];
$bytes = filesize($completeFilePath);
$decimals = 2;
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
array_push($file, sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor]);
}
else if ($j == 6)
array_push($file, $result[$i][4]);
}
if ($result[$i][6] == "1")
array_push($file, "unlisted");
array_push($files, $file);
}
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
//array_push($files, $execution_time);
$json = json_encode($files, JSON_PRETTY_PRINT);
ob_clean();
header("Content-Type: application/javascript");
echo $json;
?>