Make getMarketplaceIcons.php and uploadMarketplaceIcon.php work with new db method
This commit is contained in:
@@ -1,74 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
require __DIR__ . '/../incl/util.php';
|
require __DIR__ . '/../incl/util.php';
|
||||||
setPlainHeader();
|
setPlainHeader();
|
||||||
$conn = newConnection();
|
$conn0 = newConnection(0);
|
||||||
|
$conn1 = newConnection(1);
|
||||||
|
|
||||||
$post = getPostData();
|
$post = getPostData();
|
||||||
$userId = (int)$post['userId'] ?? 0;
|
$userId = (int) $post['userId'] ?? 0;
|
||||||
$sortBy = (int)$post['sortBy'] ?? 2;
|
$sortBy = (int) $post['sortBy'] ?? 2;
|
||||||
$priceRangeEnabled = isset($post['priceRangeEnabled']) ? (string)$post['priceRangeEnabled'] == 'False' ? false : true : false;
|
$priceRangeEnabled = isset($post['priceRangeEnabled']) ? (string) $post['priceRangeEnabled'] == 'False' ? false : true : false;
|
||||||
$priceRangeMin = (int)$post['priceRangeMin'] ?? 10;
|
$priceRangeMin = (int) $post['priceRangeMin'] ?? 10;
|
||||||
$priceRangeMax = (int)$post['priceRangeMax'] ?? 250;
|
$priceRangeMax = (int) $post['priceRangeMax'] ?? 250;
|
||||||
$searchForEnabled = isset($post['searchForEnabled']) ? (string)$post['searchForEnabled'] == 'False' ? false : true : false;
|
$searchForEnabled = isset($post['searchForEnabled']) ? (string) $post['searchForEnabled'] == 'False' ? false : true : false;
|
||||||
$searchForValue = (string)$post['searchForValue'] ?? '';
|
$searchForValue = (string) $post['searchForValue'] ?? '';
|
||||||
$onlyShowEnabled = isset($post['onlyShowEnabled']) ? (string)$post['onlyShowEnabled'] == 'False' ? false : true : false;
|
$onlyShowEnabled = isset($post['onlyShowEnabled']) ? (string) $post['onlyShowEnabled'] == 'False' ? false : true : false;
|
||||||
$onlyShowValue = (string)$post['onlyShowValue'] ?? '';
|
$onlyShowValue = (string) $post['onlyShowValue'] ?? '';
|
||||||
$currentIcons = json_decode(base64_decode((string)($post['currentIcons'] ?? 'W10K')));
|
$currentIcons = json_decode(base64_decode((string) ($post['currentIcons'] ?? 'W10K')));
|
||||||
|
|
||||||
$where = ["u.banned = 0", "(c.state = 1 OR c.state = 2)"];
|
$where = ["(state = 1 OR state = 2)"];
|
||||||
$params = [];
|
$params = [];
|
||||||
$types = "";
|
$types = "";
|
||||||
$order = match($sortBy) {
|
$order = match ($sortBy) {
|
||||||
1 => "ORDER BY c.price ASC",
|
1 => "ORDER BY price ASC",
|
||||||
2 => "ORDER BY c.id ASC",
|
2 => "ORDER BY id ASC",
|
||||||
3 => "ORDER BY c.id DESC",
|
3 => "ORDER BY id DESC",
|
||||||
default => "ORDER BY c.price DESC",
|
default => "ORDER BY price DESC",
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($priceRangeEnabled) {
|
if ($priceRangeEnabled) {
|
||||||
$where[] = "c.price BETWEEN ? AND ?";
|
$where[] = "price BETWEEN ? AND ?";
|
||||||
$params[] = $priceRangeMin;
|
$params[] = $priceRangeMin;
|
||||||
$params[] = $priceRangeMax;
|
$params[] = $priceRangeMax;
|
||||||
$types .= "ii";
|
$types .= "ii";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($searchForEnabled && $searchForValue !== '') {
|
if ($searchForEnabled && $searchForValue !== '') {
|
||||||
$where[] = "FROM_BASE64(c.name) LIKE ?";
|
$where[] = "FROM_BASE64(name) LIKE ?";
|
||||||
$params[] = "%$searchForValue%";
|
$params[] = "%$searchForValue%";
|
||||||
$types .= "s";
|
$types .= "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($onlyShowEnabled) {
|
if ($onlyShowEnabled) {
|
||||||
if ($onlyShowValue === '0') {
|
if ($onlyShowValue === '0') {
|
||||||
$where[] = "c.userId = ?";
|
$where[] = "userId = ?";
|
||||||
$params[] = $userId;
|
$params[] = $userId;
|
||||||
$types .= "i";
|
$types .= "i";
|
||||||
} elseif ($onlyShowValue === '1') {
|
} elseif ($onlyShowValue === '1') {
|
||||||
$where[] = "c.userId != ?";
|
$where[] = "userId != ?";
|
||||||
$params[] = $userId;
|
$params[] = $userId;
|
||||||
$types .= "i";
|
$types .= "i";
|
||||||
} elseif ($onlyShowValue === '2') {
|
} elseif ($onlyShowValue === '2') {
|
||||||
$placeholders = implode(',', array_fill(0, count($currentIcons), '?'));
|
$placeholders = implode(',', array_fill(0, count($currentIcons), '?'));
|
||||||
$where[] = "c.uuid IN ($placeholders)";
|
$where[] = "uuid IN ($placeholders)";
|
||||||
$params = array_merge($params, $currentIcons);
|
$params = array_merge($params, $currentIcons);
|
||||||
$types .= str_repeat('s', count($currentIcons));
|
$types .= str_repeat('s', count($currentIcons));
|
||||||
} elseif ($onlyShowValue === '3') {
|
} elseif ($onlyShowValue === '3') {
|
||||||
$placeholders = implode(',', array_fill(0, count($currentIcons), '?'));
|
$placeholders = implode(',', array_fill(0, count($currentIcons), '?'));
|
||||||
$where[] = "c.uuid NOT IN ($placeholders)";
|
$where[] = "uuid NOT IN ($placeholders)";
|
||||||
$params = array_merge($params, $currentIcons);
|
$params = array_merge($params, $currentIcons);
|
||||||
$types .= str_repeat('s', count($currentIcons));
|
$types .= str_repeat('s', count($currentIcons));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT c.data, u.username, u.id, c.price, c.name, c.uuid, c.state
|
SELECT data, price, name, uuid, state, userId
|
||||||
FROM marketplaceicons c
|
FROM marketplaceicons
|
||||||
JOIN users u ON c.userId = u.id
|
|
||||||
WHERE " . implode(" AND ", $where) . "
|
WHERE " . implode(" AND ", $where) . "
|
||||||
$order
|
$order
|
||||||
";
|
";
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn1->prepare($sql);
|
||||||
|
|
||||||
if (!empty($params)) {
|
if (!empty($params)) {
|
||||||
$stmt->bind_param($types, ...$params);
|
$stmt->bind_param($types, ...$params);
|
||||||
@@ -77,6 +77,27 @@ if (!empty($params)) {
|
|||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
echo encrypt(json_encode(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['id'], 'data' => $row['data'], 'uuid' => $row['uuid'], 'price' => (int)$row['state'] == 2 ? 100000000 : $row['price'], 'name' => base64_decode($row['name'])], $result->fetch_all(MYSQLI_ASSOC))));
|
echo encrypt(json_encode(array_map(
|
||||||
|
function ($row) {
|
||||||
|
global $conn0;
|
||||||
|
|
||||||
$conn->close();
|
$stmt2 = $conn0->prepare("SELECT username FROM users WHERE id = ?");
|
||||||
|
$stmt2->bind_param("i", $row['userId']);
|
||||||
|
$stmt2->execute();
|
||||||
|
$result2 = $stmt2->get_result();
|
||||||
|
$row2 = $result2->fetch_assoc();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'username' => $row2['username'] ?? 'Unknown',
|
||||||
|
'userid' => $row['userId'],
|
||||||
|
'data' => $row['data'],
|
||||||
|
'uuid' => $row['uuid'],
|
||||||
|
'price' => (int) $row['state'] == 2 ? 100000000 : $row['price'],
|
||||||
|
'name' => base64_decode($row['name'])
|
||||||
|
];
|
||||||
|
},
|
||||||
|
$result->fetch_all(MYSQLI_ASSOC)
|
||||||
|
)));
|
||||||
|
|
||||||
|
$conn0->close();
|
||||||
|
$conn1->close();
|
||||||
@@ -19,23 +19,32 @@ if (strlen($decoded) > 1024 * 1024) exitWithMessage(json_encode(["success" => fa
|
|||||||
$info = getimagesizefromstring($decoded);
|
$info = getimagesizefromstring($decoded);
|
||||||
if (!$info) exitWithMessage(json_encode(["success" => false, "message" => "Invalid image uploaded"]));
|
if (!$info) exitWithMessage(json_encode(["success" => false, "message" => "Invalid image uploaded"]));
|
||||||
if ($info[2] !== IMAGETYPE_PNG) exitWithMessage(json_encode(["success" => false, "message" => "Image must be a PNG"]));
|
if ($info[2] !== IMAGETYPE_PNG) exitWithMessage(json_encode(["success" => false, "message" => "Image must be a PNG"]));
|
||||||
if ($info[0] !== 128 || $info[1] !== 128) exitWithMessage(json_encode(["success" => false, "message" => "Invalid has to be 128x128"]));
|
if ($info[0] !== 128 || $info[1] !== 128) exitWithMessage(json_encode(["success" => false, "message" => "Image has to be 128x128"]));
|
||||||
|
|
||||||
$conn = newConnection();
|
$conn0 = newConnection(0);
|
||||||
|
$conn1 = newConnection(1);
|
||||||
|
|
||||||
$stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
|
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?");
|
||||||
$stmt->bind_param("ss", $token, $username);
|
$stmt->bind_param("s", $username);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
$row = $result->fetch_assoc();
|
$row = $result->fetch_assoc();
|
||||||
if (!$row) exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
|
if (!$row) exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
|
|
||||||
$id = $row["id"];
|
$id = $row["id"];
|
||||||
|
|
||||||
|
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE token = ? AND id = ?");
|
||||||
|
$stmt2->bind_param("si", $token, $id);
|
||||||
|
$stmt2->execute();
|
||||||
|
$result2 = $stmt2->get_result();
|
||||||
|
$row2 = $result2->fetch_assoc();
|
||||||
|
if (!$row2) exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
|
||||||
|
$stmt2->close();
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
$hash = hash('sha512', base64_decode($filecontent));
|
$hash = hash('sha512', base64_decode($filecontent));
|
||||||
|
|
||||||
$stmt = $conn->prepare("SELECT id FROM marketplaceicons WHERE hash = ?");
|
$stmt = $conn1->prepare("SELECT id FROM marketplaceicons WHERE hash = ?");
|
||||||
$stmt->bind_param("s", $hash);
|
$stmt->bind_param("s", $hash);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
@@ -47,12 +56,13 @@ $stmt->close();
|
|||||||
|
|
||||||
$uuid = uuidv4();
|
$uuid = uuidv4();
|
||||||
|
|
||||||
$stmt = $conn->prepare("INSERT INTO marketplaceicons (uuid, userId, data, hash, price, name, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
$stmt = $conn1->prepare("INSERT INTO marketplaceicons (uuid, userId, data, hash, price, name, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||||
$stmt->bind_param("sissisi", $uuid, $id, $filecontent, $hash, $price, $name, $time);
|
$stmt->bind_param("sissisi", $uuid, $id, $filecontent, $hash, $price, $name, $time);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$insertId = $conn->insert_id;
|
$insertId = $conn1->insert_id;
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
|
|
||||||
echo encrypt(json_encode(["success" => true, "message" => "Icon uploaded successfully! It will be reviewed and accepted or denied soon"]));
|
echo encrypt(json_encode(["success" => true, "message" => "Icon uploaded successfully! It will be reviewed and accepted or denied soon"]));
|
||||||
|
|
||||||
$conn->close();
|
$conn0->close();
|
||||||
|
$conn1->close();
|
||||||
Reference in New Issue
Block a user